List of usage examples for com.liferay.portal.kernel.util StringUtil trim
public static String trim(String s)
From source file:com.beorn.onlinepayment.geoip.GeoIpUtil.java
License:Open Source License
/** * Geolocalize an ip using a json service. * // w ww .j a v a 2s. c o m * The url defined in the porlet.properties by geoip.url will be called, * replacing the {0} marker by the ip, and the * geoip.response.country-code-parameter key of the returned json response * will be extracted and returned as the country code. * * @param ip * the ip to geolocalize * @return a country code corresponding to the ip parameter * @throws IOException * when there is an error calling the json service * @throws JSONException * when the response isn't a valid json string */ public static String geolocalizeIp(String ip) throws IOException, JSONException { ip = StringUtil.trim(ip); String key = ip; String countryCode = (String) _portalCache.get(key); if (countryCode == null) { Options options = new Options(); options.setLocation(MessageFormat.format(PropsValues.GEOIP_URL, ip)); String response = HttpUtil.URLtoString(options); JSONObject jsonResponse = new JSONObject(response); countryCode = jsonResponse.getString(PropsValues.GEOIP_RESPONSE_COUNTRY_CODE_PARAMETER); _log.info("Found country code " + countryCode + " for ip " + ip); _portalCache.put(key, countryCode); } return countryCode; }
From source file:com.idetronic.subur.service.impl.ExpertiseLocalServiceImpl.java
License:Open Source License
@Override public Expertise addExpertise(long userId, String name, ServiceContext serviceContext) throws SystemException, PortalException { User user = userPersistence.findByPrimaryKey(userId); long groupId = serviceContext.getScopeGroupId(); Date now = new Date(); long expertiseId = CounterLocalServiceUtil.increment(Expertise.class.getName()); Expertise expertise = expertisePersistence.create(expertiseId); expertise.setGroupId(groupId);/*from w w w .j av a 2 s . c o m*/ expertise.setCompanyId(user.getCompanyId()); expertise.setUserId(userId); ; expertise.setCreateDate(now); expertise.setModifiedDate(now); name = StringUtil.trim(name); validate(name); expertise.setName(name); expertise.setIndexedName(StringUtil.toLowerCase(name)); expertisePersistence.update(expertise); return expertise; }
From source file:com.idetronic.subur.service.impl.ResearchInterestLocalServiceImpl.java
License:Open Source License
@Override public ResearchInterest addResearchInterest(long userId, String name, ServiceContext serviceContext) throws SystemException, PortalException { User user = userPersistence.findByPrimaryKey(userId); long groupId = serviceContext.getScopeGroupId(); Date now = new Date(); long researchInterestId = CounterLocalServiceUtil.increment(ResearchInterest.class.getName()); ResearchInterest researchInterest = researchInterestPersistence.create(researchInterestId); researchInterest.setGroupId(groupId); researchInterest.setCompanyId(user.getCompanyId()); researchInterest.setUserId(userId);// w ww . j av a 2 s .com ; researchInterest.setCreateDate(now); researchInterest.setModifiedDate(now); name = StringUtil.trim(name); validate(name); researchInterest.setName(name); researchInterest.setIndexedName(StringUtil.toLowerCase(name)); researchInterestPersistence.update(researchInterest); return researchInterest; }
From source file:com.liferay.alloy.util.DefaultValueUtil.java
License:Open Source License
public static boolean isValidStringValue(String value) { value = StringUtil.trim(GetterUtil.getString(value)); if (Validator.isNull(value)) { return false; }/* ww w . ja v a2s .c o m*/ if (StringUtils.isAlpha(value) || (!StringUtils.containsIgnoreCase(value, _GENERATED) && !StringUtils.isAlpha(value.substring(0, 1)) && !StringUtils.endsWith(value, StringPool.PERIOD))) { return true; } return false; }
From source file:com.liferay.blogs.internal.exportimport.data.handler.test.BlogsEntryStagedModelDataHandlerTest.java
License:Open Source License
@Override protected void validateImportedStagedModel(StagedModel stagedModel, StagedModel importedStagedModel) throws Exception { super.validateImportedStagedModel(stagedModel, importedStagedModel); BlogsEntry entry = (BlogsEntry) stagedModel; BlogsEntry importedEntry = (BlogsEntry) importedStagedModel; Assert.assertEquals(entry.getTitle(), importedEntry.getTitle()); Assert.assertEquals(entry.getSubtitle(), importedEntry.getSubtitle()); Assert.assertEquals(entry.getUrlTitle(), importedEntry.getUrlTitle()); Assert.assertEquals(entry.getDescription(), importedEntry.getDescription()); Calendar displayDateCalendar = Calendar.getInstance(); Calendar importedDisplayDateCalendar = Calendar.getInstance(); displayDateCalendar.setTime(entry.getDisplayDate()); importedDisplayDateCalendar.setTime(importedEntry.getDisplayDate()); displayDateCalendar.set(Calendar.SECOND, 0); displayDateCalendar.set(Calendar.MILLISECOND, 0); importedDisplayDateCalendar.set(Calendar.SECOND, 0); importedDisplayDateCalendar.set(Calendar.MILLISECOND, 0); Assert.assertEquals(displayDateCalendar, importedDisplayDateCalendar); Assert.assertEquals(entry.isAllowPingbacks(), importedEntry.isAllowPingbacks()); Assert.assertEquals(entry.isAllowTrackbacks(), importedEntry.isAllowTrackbacks()); Assert.assertEquals(StringUtil.trim(entry.getTrackbacks()), StringUtil.trim(importedEntry.getTrackbacks())); Assert.assertEquals(entry.getCoverImageCaption(), importedEntry.getCoverImageCaption()); Assert.assertEquals(entry.isSmallImage(), importedEntry.isSmallImage()); }
From source file:com.liferay.calendar.util.CalendarICalDataHandler.java
License:Open Source License
protected void importICalEvent(long calendarId, VEvent vEvent) throws Exception { Calendar calendar = CalendarLocalServiceUtil.getCalendar(calendarId); // Title/*w ww .j ava 2s. c om*/ User user = UserLocalServiceUtil.getUser(calendar.getUserId()); Map<Locale, String> titleMap = new HashMap<Locale, String>(); Summary summary = vEvent.getSummary(); if (summary != null) { String title = ModelHintsUtil.trimString(CalendarBooking.class.getName(), "title", summary.getValue()); titleMap.put(user.getLocale(), title); } // Description Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); Description description = vEvent.getDescription(); if (description != null) { descriptionMap.put(user.getLocale(), description.getValue()); } // Location String locationString = StringPool.BLANK; Location location = vEvent.getLocation(); if (location != null) { locationString = location.getValue(); } // Dates DtStart dtStart = vEvent.getStartDate(); Date startDate = dtStart.getDate(); DtEnd dtEnd = vEvent.getEndDate(); Date endDate = dtEnd.getDate(); // All day boolean allDay = false; if (isICalDateOnly(dtStart)) { allDay = true; long time = endDate.getTime(); endDate.setTime(time - 1); } // Recurrence RRule rrule = (RRule) vEvent.getProperty(Property.RRULE); String recurrence = StringPool.BLANK; if (rrule != null) { recurrence = StringUtil.trim(rrule.toString()); PropertyList propertyList = vEvent.getProperties(Property.EXDATE); if (!propertyList.isEmpty()) { StringBundler sb = new StringBundler(); Iterator<ExDate> iterator = propertyList.iterator(); while (iterator.hasNext()) { ExDate exDate = iterator.next(); DateList dateList = exDate.getDates(); ListIterator<Date> listIterator = dateList.listIterator(); while (listIterator.hasNext()) { Date date = listIterator.next(); java.util.Calendar jCalendar = JCalendarUtil.getJCalendar(date.getTime()); int year = jCalendar.get(java.util.Calendar.YEAR); int month = jCalendar.get(java.util.Calendar.MONTH) + 1; int day = jCalendar.get(java.util.Calendar.DATE); int hour = jCalendar.get(java.util.Calendar.HOUR_OF_DAY); int minute = jCalendar.get(java.util.Calendar.MINUTE); int second = jCalendar.get(java.util.Calendar.SECOND); sb.append(String.format(_EXDATE_FORMAT, year, month, day, hour, minute, second)); if (listIterator.hasNext()) { sb.append(StringPool.COMMA); } } if (iterator.hasNext()) { sb.append(StringPool.COMMA); } } recurrence = recurrence.concat(StringPool.NEW_LINE).concat(_EXDATE).concat(sb.toString()); } } // Reminders ComponentList componentList = vEvent.getAlarms(); long[] reminders = new long[componentList.size()]; String[] reminderTypes = new String[componentList.size()]; int i = 0; for (Iterator<VAlarm> iterator = componentList.iterator(); iterator.hasNext();) { VAlarm vAlarm = iterator.next(); Action action = vAlarm.getAction(); String value = StringUtil.lowerCase(action.getValue()); if (!isActionSupported(value)) { continue; } reminderTypes[i] = value; Trigger trigger = vAlarm.getTrigger(); long time = 0; DateTime dateTime = trigger.getDateTime(); Dur dur = trigger.getDuration(); if ((dateTime == null) && (dur == null)) { continue; } if (dateTime != null) { time = startDate.getTime() - dateTime.getTime(); if (time < 0) { continue; } } else { if (!dur.isNegative()) { continue; } time += dur.getWeeks() * Time.WEEK; time += dur.getDays() * Time.DAY; time += dur.getHours() * Time.HOUR; time += dur.getMinutes() * Time.MINUTE; time += dur.getSeconds() * Time.SECOND; } reminders[i] = time; i++; } long firstReminder = 0; String firstReminderType = null; long secondReminder = 0; String secondReminderType = null; if (i > 0) { firstReminder = reminders[0]; firstReminderType = reminderTypes[0]; } if (i > 1) { secondReminder = reminders[1]; secondReminderType = reminderTypes[1]; } // Attendees PropertyList propertyList = vEvent.getProperties(Property.ATTENDEE); List<Long> childCalendarIds = new ArrayList<Long>(); for (Iterator<Attendee> iterator = propertyList.iterator(); iterator.hasNext();) { Attendee attendee = iterator.next(); URI uri = attendee.getCalAddress(); if (uri == null) { continue; } User attendeeUser = UserLocalServiceUtil.fetchUserByEmailAddress(calendar.getCompanyId(), uri.getSchemeSpecificPart()); if ((attendeeUser == null) || (calendar.getUserId() == attendeeUser.getUserId())) { continue; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(calendar.getCompanyId()); serviceContext.setScopeGroupId(calendar.getGroupId()); CalendarResource calendarResource = CalendarResourceUtil .getUserCalendarResource(attendeeUser.getUserId(), serviceContext); if (calendarResource == null) { continue; } childCalendarIds.add(calendarResource.getDefaultCalendarId()); } long[] childCalendarIdsArray = ArrayUtil .toArray(childCalendarIds.toArray(new Long[childCalendarIds.size()])); // Merge calendar booking CalendarBooking calendarBooking = null; String uuid = null; Uid uid = vEvent.getUid(); if (uid != null) { uuid = uid.getValue(); calendarBooking = CalendarBookingLocalServiceUtil.fetchCalendarBooking(uuid, calendar.getGroupId()); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setAttribute("sendNotification", Boolean.FALSE); serviceContext.setScopeGroupId(calendar.getGroupId()); if (calendarBooking == null) { serviceContext.setUuid(uuid); CalendarBookingServiceUtil.addCalendarBooking(calendarId, childCalendarIdsArray, CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT, titleMap, descriptionMap, locationString, startDate.getTime(), endDate.getTime(), allDay, recurrence, firstReminder, firstReminderType, secondReminder, secondReminderType, serviceContext); } else { CalendarBookingServiceUtil.updateCalendarBooking(calendarBooking.getCalendarBookingId(), calendarId, childCalendarIdsArray, titleMap, descriptionMap, locationString, startDate.getTime(), endDate.getTime(), allDay, recurrence, firstReminder, firstReminderType, secondReminder, secondReminderType, calendarBooking.getStatus(), serviceContext); } }
From source file:com.liferay.document.library.search.test.DLFileEntrySearchTest.java
License:Open Source License
protected BaseModel<?> addBaseModel(String[] keywords, DDMStructure ddmStructure, ServiceContext serviceContext) throws Exception { _ddmStructure = ddmStructure;// w w w . j a v a2 s .co m DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), serviceContext.getScopeGroupId(), "Structure", StringPool.BLANK, new long[] { ddmStructure.getStructureId() }, serviceContext); String content = "Content: Enterprise. Open Source. For Life."; DDMFormValues ddmFormValues = createDDMFormValues( DDMBeanTranslatorUtil.translate(_ddmStructure.getDDMForm())); for (String keyword : keywords) { ddmFormValues.addDDMFormFieldValue(createLocalizedDDMFormFieldValue("name", StringUtil.trim(keyword))); } DLAppTestUtil.populateServiceContext(serviceContext, dlFileEntryType.getFileEntryTypeId()); serviceContext.setAttribute(DDMFormValues.class.getName() + ddmStructure.getStructureId(), ddmFormValues); FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), serviceContext.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Text.txt", ContentTypes.TEXT_PLAIN, RandomTestUtil.randomString(), StringPool.BLANK, StringPool.BLANK, content.getBytes(), serviceContext); return (DLFileEntry) fileEntry.getModel(); }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.impl.internal.DDMFormEvaluatorHelper.java
License:Open Source License
protected boolean isDDMFormFieldValueEmpty(DDMFormField ddmFormField, DDMFormFieldValue ddmFormFieldValue) { Value value = ddmFormFieldValue.getValue(); if (value == null) { return true; }//from ww w.j a v a2s . co m String valueString = value.getString(_locale); if (Validator.isNull(StringUtil.trim(valueString))) { return true; } String dataType = ddmFormField.getDataType(); if (Objects.equals(dataType, "boolean") && Objects.equals(valueString, "false")) { return true; } return false; }
From source file:com.liferay.dynamic.data.mapping.form.field.type.DDMFormFieldValueAccessor.java
License:Open Source License
public default boolean isEmpty(DDMFormFieldValue ddmFormFieldValue, Locale locale) { Value value = ddmFormFieldValue.getValue(); if (value == null) { return true; }/*from w ww. j a v a 2 s.c o m*/ String valueString = StringUtil.trim(value.getString(locale)); return Validator.isNull(valueString); }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java
License:Open Source License
/** * Returns the template matching the group and template key. * * @param groupId the primary key of the group * @param classNameId the primary key of the class name for the template's * related model/*from w w w. j a va2 s .c om*/ * @param templateKey the unique string identifying the template * @return the matching template, or <code>null</code> if a matching * template could not be found */ @Override public DDMTemplate fetchTemplate(long groupId, long classNameId, String templateKey) { templateKey = StringUtil.toUpperCase(StringUtil.trim(templateKey)); return ddmTemplatePersistence.fetchByG_C_T(groupId, classNameId, templateKey); }