Example usage for com.liferay.portal.kernel.util StringPool NEW_LINE

List of usage examples for com.liferay.portal.kernel.util StringPool NEW_LINE

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool NEW_LINE.

Prototype

String NEW_LINE

To view the source code for com.liferay.portal.kernel.util StringPool NEW_LINE.

Click Source Link

Usage

From source file:com.liferay.calendar.internal.security.service.access.policy.CalendarSAPEntryActivator.java

License:Open Source License

protected void addSAPEntry(long companyId) throws PortalException {
    SAPEntry sapEntry = _sapEntryLocalService.fetchSAPEntry(companyId, _SAP_ENTRY_NAME);

    if (sapEntry != null) {
        return;//w w  w.j  ava  2 s. co m
    }

    StringBundler sb = new StringBundler(5);

    sb.append(CalendarBookingService.class.getName());
    sb.append("#search");
    sb.append(StringPool.NEW_LINE);
    sb.append(CalendarBookingService.class.getName());
    sb.append("#searchCount");

    String allowedServiceSignatures = sb.toString();

    ResourceBundleLoader resourceBundleLoader = new AggregateResourceBundleLoader(
            ResourceBundleUtil.getResourceBundleLoader("content.Language",
                    CalendarSAPEntryActivator.class.getClassLoader()),
            LanguageResources.RESOURCE_BUNDLE_LOADER);

    Map<Locale, String> titleMap = ResourceBundleUtil.getLocalizationMap(resourceBundleLoader,
            "service-access-policy-entry-default-calendar-title");

    _sapEntryLocalService.addSAPEntry(_userLocalService.getDefaultUserId(companyId), allowedServiceSignatures,
            true, true, _SAP_ENTRY_NAME, titleMap, new ServiceContext());
}

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

public static Recurrence deserialize(String data) {
    try {//  ww w. j  ava  2 s  . com
        Recurrence recurrence = new Recurrence();

        int index = data.indexOf(StringPool.NEW_LINE);

        if (index != -1) {
            String exceptionDates = data.substring(index + 1, data.length());

            RDateList rDateList = new RDateList(exceptionDates, TimeZone.getTimeZone(StringPool.UTC));

            for (DateValue dateValue : rDateList.getDatesUtc()) {
                Calendar jCalendar = _toJCalendar(dateValue);

                recurrence.addExceptionDate(jCalendar);
            }

            data = data.substring(0, index);
        }

        RRule rRule = new RRule(data);

        recurrence.setCount(rRule.getCount());
        recurrence.setFrequency(Frequency.parse(String.valueOf(rRule.getFreq())));
        recurrence.setInterval(rRule.getInterval());

        DateValue dateValue = rRule.getUntil();

        if (dateValue != null) {
            Calendar jCalendar = _toJCalendar(dateValue);

            recurrence.setUntilJCalendar(jCalendar);
        }

        List<PositionalWeekday> positionalWeekdays = new ArrayList<PositionalWeekday>();

        for (WeekdayNum weekdayNum : rRule.getByDay()) {
            Weekday weekday = Weekday.parse(weekdayNum.wday.toString());

            PositionalWeekday positionalWeekday = new PositionalWeekday(weekday, weekdayNum.num);

            positionalWeekdays.add(positionalWeekday);
        }

        recurrence.setPositionalWeekdays(positionalWeekdays);

        recurrence.setMonths(ListUtil.toList(rRule.getByMonth()));

        return recurrence;
    } catch (ParseException pe) {
        _log.error("Unable to parse data " + data, pe);
    }

    return null;
}

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

public static String serialize(Recurrence recurrence) {
    RRule rRule = new RRule();

    List<WeekdayNum> weekdayNums = new ArrayList<WeekdayNum>();

    for (PositionalWeekday positionalWeekday : recurrence.getPositionalWeekdays()) {

        com.google.ical.values.Weekday wday = _weekdaysMap.get(positionalWeekday.getWeekday());

        WeekdayNum weekdayNum = new WeekdayNum(positionalWeekday.getPosition(), wday);

        weekdayNums.add(weekdayNum);/*from  www.j  a va 2 s  .  com*/
    }

    rRule.setByDay(weekdayNums);

    List<Integer> months = recurrence.getMonths();

    if (months != null) {
        rRule.setByMonth(ArrayUtil.toIntArray(months));
    }

    rRule.setCount(recurrence.getCount());

    com.google.ical.values.Frequency frequency = com.google.ical.values.Frequency
            .valueOf(String.valueOf(recurrence.getFrequency()));

    rRule.setFreq(frequency);

    rRule.setInterval(recurrence.getInterval());

    Calendar jCalendar = recurrence.getUntilJCalendar();

    if (jCalendar != null) {
        DateValue dateValue = _toDateValue(jCalendar);

        rRule.setUntil(dateValue);
    }

    String data = rRule.toIcal();

    List<Calendar> exceptionJCalendars = recurrence.getExceptionJCalendars();

    if (!exceptionJCalendars.isEmpty()) {
        DateValue[] dateValues = new DateValue[exceptionJCalendars.size()];

        for (int i = 0; i < exceptionJCalendars.size(); i++) {
            dateValues[i] = _toDateValue(exceptionJCalendars.get(i));
        }

        RDateList rDateList = new RDateList(TimeZone.getTimeZone(StringPool.UTC));

        rDateList.setDatesUtc(dateValues);
        rDateList.setName(_EXDATE);

        data = data.concat(StringPool.NEW_LINE).concat(rDateList.toIcal());
    }

    return data;
}

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/*from   w w w .j a  v a 2s  . c o  m*/

    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.calendar.util.CalendarICalDataHandler.java

License:Open Source License

protected VEvent toICalEvent(CalendarBooking calendarBooking) throws Exception {

    VEvent vEvent = new VEvent();

    PropertyList propertyList = vEvent.getProperties();

    // UID/*ww w  . j a  v  a 2s  .c o m*/

    Uid uid = new Uid(calendarBooking.getUuid());

    propertyList.add(uid);

    // Dates

    if (calendarBooking.isAllDay()) {
        DtStart dtStart = new DtStart(new Date(calendarBooking.getStartTime()));

        propertyList.add(dtStart);

        java.util.Calendar endJCalendar = JCalendarUtil.getJCalendar(calendarBooking.getEndTime());

        endJCalendar.add(java.util.Calendar.DAY_OF_MONTH, 1);

        DtEnd dtEnd = new DtEnd(new Date(endJCalendar.getTime()));

        propertyList.add(dtEnd);
    } else {
        DtStart dtStart = new DtStart(toICalDateTime(calendarBooking.getStartTime()));

        propertyList.add(dtStart);

        DtEnd dtEnd = new DtEnd(toICalDateTime(calendarBooking.getEndTime()));

        propertyList.add(dtEnd);
    }

    // Title

    User user = UserLocalServiceUtil.getUser(calendarBooking.getUserId());

    Summary summary = new Summary(calendarBooking.getTitle(user.getLocale()));

    propertyList.add(summary);

    // Description

    Company company = CompanyLocalServiceUtil.getCompany(calendarBooking.getCompanyId());

    String calendarBookingDescription = StringUtil.replace(calendarBooking.getDescription(user.getLocale()),
            new String[] { "href=\"/", "src=\"/" },
            new String[] { "href=\"" + company.getPortalURL(calendarBooking.getGroupId()) + "/",
                    "src=\"" + company.getPortalURL(calendarBooking.getGroupId()) + "/" });

    Description description = new Description(calendarBookingDescription);

    propertyList.add(description);

    XProperty xProperty = new XProperty("X-ALT-DESC", calendarBookingDescription);

    ParameterList parameters = xProperty.getParameters();

    parameters.add(new XParameter("FMTTYPE", "text/html"));

    propertyList.add(xProperty);

    // Location

    Location location = new Location(calendarBooking.getLocation());

    propertyList.add(location);

    // Recurrence

    if (calendarBooking.isRecurring()) {
        String recurrence = calendarBooking.getRecurrence();

        int index = recurrence.indexOf(StringPool.NEW_LINE);

        if (index > 0) {
            recurrence = recurrence.substring(0, index);
        }

        String value = StringUtil.replace(recurrence, _RRULE, StringPool.BLANK);

        RRule rRule = new RRule(value);

        propertyList.add(rRule);

        ExDate exDate = toICalExDate(calendarBooking.getRecurrenceObj());

        if (exDate != null) {
            propertyList.add(exDate);
        }
    }

    // Reminders

    ComponentList componentList = vEvent.getAlarms();

    long firstReminder = calendarBooking.getFirstReminder();

    if (firstReminder > 0) {
        VAlarm vAlarm = toICalAlarm(calendarBooking.getFirstReminderNotificationType(), firstReminder,
                user.getEmailAddress());

        componentList.add(vAlarm);
    }

    long secondReminder = calendarBooking.getSecondReminder();

    if (secondReminder > 0) {
        VAlarm alarm = toICalAlarm(calendarBooking.getSecondReminderNotificationType(), secondReminder,
                user.getEmailAddress());

        componentList.add(alarm);
    }

    // Attendees

    List<CalendarBooking> childCalendarBookings = calendarBooking.getChildCalendarBookings();

    for (CalendarBooking childCalendarBooking : childCalendarBookings) {
        CalendarResource calResource = childCalendarBooking.getCalendarResource();

        if (!calResource.isUser()
                || (calendarBooking.getCalendarBookingId() == childCalendarBooking.getCalendarBookingId())) {

            continue;
        }

        User calResourceUser = UserLocalServiceUtil.getUser(calResource.getClassPK());

        Attendee attendee = toICalAttendee(calResourceUser.getFullName(), calResourceUser.getEmailAddress(),
                childCalendarBooking.getStatus());

        propertyList.add(attendee);
    }

    return vEvent;
}

From source file:com.liferay.ci.portlet.JenkinsIntegrationPortlet.java

License:Open Source License

protected void buildProjectsStack(RenderRequest request) {
    PortletPreferences portletPreferences = request.getPreferences();

    String jobNamesParam = portletPreferences.getValue("jobnames", StringPool.BLANK);

    String[] jobNames = StringUtil.split(jobNamesParam, StringPool.NEW_LINE);

    AuthConnectionParams connectionParams = getConnectionParams(portletPreferences);

    try {//from   www .j  ava2s.  c  o  m
        JenkinsJob[] lastBuilds = JenkinsConnectUtil.getLastBuilds(connectionParams, jobNames);

        request.setAttribute("JENKINS_JOBS", lastBuilds);
    } catch (IOException ioe) {
        SessionErrors.add(request, ioe.getClass());

        _log.error("The jobs were not available", ioe);
    } catch (JSONException e) {
        _log.error("The jobs are not well-formed", e);
    }
}

From source file:com.liferay.ci.portlet.TravisIntegrationPortlet.java

License:Open Source License

protected ContinuousIntegrationJob[] parseJobNames(String jobNamesParam) {
    String[] jobNames = StringUtil.split(jobNamesParam, StringPool.NEW_LINE);

    ContinuousIntegrationJob[] jobs = new ContinuousIntegrationJob[jobNames.length];

    for (int i = 0; i < jobNames.length; i++) {
        String fullJobName = jobNames[i];

        String[] jobNameArray = fullJobName.split("\\|");

        String jobAccount;//from w w  w .j av a2s .co m
        String jobName;
        String jobAlias;

        if (jobNameArray.length > 3) {
            _log.warn("Job name uses invalid format: " + fullJobName);

            continue;
        } else if (jobNameArray.length == 3) {
            jobAccount = jobNameArray[0];
            jobName = jobNameArray[1];
            jobAlias = jobNameArray[2];
        } else {
            jobAccount = fullJobName;
            jobName = fullJobName;
            jobAlias = fullJobName;
        }

        jobs[i] = new ContinuousIntegrationJob(jobAccount, jobName, jobAlias,
                TravisIntegrationConstants.TRAVIS_BUILD_STATUS_PENDING);
    }

    return jobs;
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getAddresses(User user) throws Exception {
    List<Address> addresses = AddressLocalServiceUtil.getAddresses(user.getCompanyId(), Contact.class.getName(),
            user.getContactId());//from w  ww.  j  av a 2 s  . co  m

    StringBundler sb = new StringBundler(addresses.size() * 19);

    for (Address address : addresses) {
        sb.append("ADR;TYPE=");

        ListType listType = address.getType();

        sb.append(StringUtil.toUpperCase(_getVCardListTypeName(listType)));

        sb.append(StringPool.COLON);
        sb.append(StringPool.SEMICOLON);
        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getStreet1())) {
            sb.append(address.getStreet1());
        }

        if (Validator.isNotNull(address.getStreet2())) {
            sb.append("\\n");
            sb.append(address.getStreet2());
        }

        if (Validator.isNotNull(address.getStreet3())) {
            sb.append("\\n");
            sb.append(address.getStreet3());
        }

        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getCity())) {
            sb.append(address.getCity());
        }

        sb.append(StringPool.SEMICOLON);

        long regionId = address.getRegionId();

        if (regionId > 0) {
            Region region = RegionServiceUtil.getRegion(regionId);

            sb.append(region.getName());
        }

        sb.append(StringPool.SEMICOLON);

        if (Validator.isNotNull(address.getZip())) {
            sb.append(address.getZip());
        }

        sb.append(StringPool.SEMICOLON);

        long countryId = address.getCountryId();

        if (countryId > 0) {
            Country country = CountryServiceUtil.getCountry(countryId);

            sb.append(country.getName());
        }

        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getEmailAddresses(User user) throws Exception {
    List<EmailAddress> emailAddresses = EmailAddressLocalServiceUtil.getEmailAddresses(user.getCompanyId(),
            Contact.class.getName(), user.getContactId());

    StringBundler sb = new StringBundler(3 + (emailAddresses.size() * 5));

    sb.append("EMAIL;TYPE=INTERNET;TYPE=HOME:");
    sb.append(user.getEmailAddress());//from   w  ww  .j  a v a  2  s. c  om
    sb.append(StringPool.NEW_LINE);

    for (EmailAddress emailAddress : emailAddresses) {
        sb.append("EMAIL;TYPE=INTERNET;TYPE=");

        ListType listType = emailAddress.getType();

        sb.append(StringUtil.toUpperCase(listType.getName()));

        sb.append(StringPool.COLON);
        sb.append(emailAddress.getAddress());
        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}

From source file:com.liferay.contacts.util.ContactsUtil.java

License:Open Source License

private static String _getInstantMessaging(Contact contact) {
    StringBundler sb = new StringBundler(18);

    if (Validator.isNotNull(contact.getAimSn())) {
        sb.append("X-AIM;type=OTHER;type=pref:");
        sb.append(contact.getAimSn());//from  w ww  . j a  v a  2 s.  co  m
        sb.append(StringPool.NEW_LINE);
    }

    if (Validator.isNotNull(contact.getIcqSn())) {
        sb.append("X-ICQ;type=OTHER;type=pref:");
        sb.append(contact.getAimSn());
        sb.append(StringPool.NEW_LINE);
    }

    if (Validator.isNotNull(contact.getJabberSn())) {
        sb.append("X-JABBER;type=OTHER;type=pref:");
        sb.append(contact.getJabberSn());
        sb.append(StringPool.NEW_LINE);
    }

    if (Validator.isNotNull(contact.getMsnSn())) {
        sb.append("X-MSN;type=OTHER;type=pref:");
        sb.append(contact.getMsnSn());
        sb.append(StringPool.NEW_LINE);
    }

    if (Validator.isNotNull(contact.getSkypeSn())) {
        sb.append("X-SKYPE;type=OTHER;type=pref:");
        sb.append(contact.getSkypeSn());
        sb.append(StringPool.NEW_LINE);
    }

    if (Validator.isNotNull(contact.getYmSn())) {
        sb.append("X-YM;type=OTHER;type=pref:");
        sb.append(contact.getYmSn());
        sb.append(StringPool.NEW_LINE);
    }

    return sb.toString();
}