Example usage for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY

List of usage examples for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY

Introduction

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

Prototype

String THEME_DISPLAY

To view the source code for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY.

Click Source Link

Usage

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

public void updateSchedulerCalendarBooking(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long calendarBookingId = ParamUtil.getLong(actionRequest, "calendarBookingId");

    CalendarBooking calendarBooking = _calendarBookingService.fetchCalendarBooking(calendarBookingId);

    long calendarId = ParamUtil.getLong(actionRequest, "calendarId");

    Calendar calendar = _calendarService.getCalendar(calendarId);

    long[] childCalendarIds = {};
    Map<Locale, String> titleMap = new HashMap<>();
    Map<Locale, String> descriptionMap = new HashMap<>();
    String location = null;/*from w w  w  . j  a v  a 2s.c  o  m*/
    java.util.Calendar startTimeJCalendar = getJCalendar(actionRequest, "startTime");
    java.util.Calendar endTimeJCalendar = getJCalendar(actionRequest, "endTime");
    boolean allDay = ParamUtil.getBoolean(actionRequest, "allDay");

    TimeZone timeZone = getTimeZone(actionRequest);

    Recurrence recurrence = RecurrenceSerializer.deserialize(ParamUtil.getString(actionRequest, "recurrence"),
            timeZone);

    long[] reminders = { 0, 0 };
    String[] remindersType = { "email", "email" };
    int instanceIndex = ParamUtil.getInteger(actionRequest, "instanceIndex");
    boolean updateInstance = ParamUtil.getBoolean(actionRequest, "updateInstance");
    boolean allFollowing = ParamUtil.getBoolean(actionRequest, "allFollowing");

    if (calendarBooking != null) {
        childCalendarIds = _calendarBookingLocalService.getChildCalendarIds(calendarBookingId, calendarId);
        titleMap = calendarBooking.getTitleMap();
        descriptionMap = calendarBooking.getDescriptionMap();
        location = calendarBooking.getLocation();
        reminders = new long[] { calendarBooking.getFirstReminder(), calendarBooking.getSecondReminder() };
        remindersType = new String[] { calendarBooking.getFirstReminderType(),
                calendarBooking.getSecondReminderType() };
    }

    String title = ParamUtil.getString(actionRequest, "title");

    titleMap.put(themeDisplay.getLocale(), title);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(CalendarBooking.class.getName(),
            actionRequest);

    calendarBooking = updateCalendarBooking(calendarBookingId, calendar, childCalendarIds, titleMap,
            descriptionMap, location, startTimeJCalendar.getTimeInMillis(), endTimeJCalendar.getTimeInMillis(),
            allDay, recurrence, reminders, remindersType, instanceIndex, updateInstance, allFollowing,
            serviceContext);

    JSONObject jsonObject = CalendarUtil.toCalendarBookingJSONObject(themeDisplay, calendarBooking, timeZone);

    writeJSON(actionRequest, actionResponse, jsonObject);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void addCalendar(PortletRequest portletRequest, Set<Calendar> calendarsSet, long classNameId,
        long classPK) throws PortalException {

    CalendarResource calendarResource = CalendarResourceUtil.getCalendarResource(portletRequest, classNameId,
            classPK);/* ww  w. j a  v a2  s  .c o m*/

    if (calendarResource == null) {
        return;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    List<Calendar> calendars = _calendarLocalService.getCalendarResourceCalendars(calendarResource.getGroupId(),
            calendarResource.getCalendarResourceId());

    for (Calendar calendar : calendars) {
        if (!CalendarPermission.contains(permissionChecker, calendar, ActionKeys.VIEW)) {

            continue;
        }

        calendarsSet.add(calendar);
    }
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected String getEditCalendarURL(ActionRequest actionRequest, ActionResponse actionResponse,
        Calendar calendar) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String editCalendarURL = getRedirect(actionRequest, actionResponse);

    if (Validator.isNull(editCalendarURL)) {
        editCalendarURL = _portal.getLayoutFullURL(themeDisplay);
    }//w  w  w  . j  a v  a 2  s  . com

    String namespace = actionResponse.getNamespace();

    editCalendarURL = HttpUtil.setParameter(editCalendarURL, "p_p_id", themeDisplay.getPpid());
    editCalendarURL = HttpUtil.setParameter(editCalendarURL, namespace + "mvcPath",
            templatePath + "edit_calendar.jsp");
    editCalendarURL = HttpUtil.setParameter(editCalendarURL, namespace + "redirect",
            getRedirect(actionRequest, actionResponse));
    editCalendarURL = HttpUtil.setParameter(editCalendarURL, namespace + "backURL",
            ParamUtil.getString(actionRequest, "backURL"));
    editCalendarURL = HttpUtil.setParameter(editCalendarURL, namespace + "calendarId",
            calendar.getCalendarId());

    return editCalendarURL;
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected TimeZone getTimeZone(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean allDay = ParamUtil.getBoolean(portletRequest, "allDay");

    if (allDay) {
        return TimeZoneUtil.getTimeZone(StringPool.UTC);
    }// w ww .  ja  v  a 2  s. c o  m

    PortletPreferences preferences = portletRequest.getPreferences();

    User user = themeDisplay.getUser();

    String timeZoneId = preferences.getValue("timeZoneId", user.getTimeZoneId());

    if (Validator.isNull(timeZoneId)) {
        timeZoneId = user.getTimeZoneId();
    }

    return TimeZone.getTimeZone(timeZoneId);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected String getViewCalendarBookingURL(ActionRequest actionRequest, CalendarBooking calendarBooking)
        throws WindowStateException {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletURL redirectURL = PortletURLFactoryUtil.create(actionRequest, themeDisplay.getPpid(),
            themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

    redirectURL.setParameter("mvcPath", "/view_calendar_booking.jsp");
    redirectURL.setParameter("calendarBookingId", String.valueOf(calendarBooking.getCalendarBookingId()));
    redirectURL.setParameter("instanceIndex", "0");
    redirectURL.setWindowState(LiferayWindowState.POP_UP);

    return redirectURL.toString();
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCalendar(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long calendarId = ParamUtil.getLong(resourceRequest, "calendarId");

    Calendar calendar = _calendarService.getCalendar(calendarId);

    JSONObject jsonObject = CalendarUtil.toCalendarJSONObject(themeDisplay, calendar);

    writeJSON(resourceRequest, resourceResponse, jsonObject);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCalendarBookingInvitees(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long parentCalendarBookingId = ParamUtil.getLong(resourceRequest, "parentCalendarBookingId");

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<CalendarBooking> childCalendarBookings = _calendarBookingService
            .getChildCalendarBookings(parentCalendarBookingId);

    Collection<CalendarResource> calendarResources = CalendarUtil.getCalendarResources(childCalendarBookings);

    for (CalendarResource calendarResource : calendarResources) {
        JSONObject jsonObject = CalendarUtil.toCalendarResourceJSONObject(themeDisplay, calendarResource);

        jsonArray.put(jsonObject);//from   w  w  w .jav a 2s .c o m
    }

    writeJSON(resourceRequest, resourceResponse, jsonArray);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCalendarBookings(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] calendarIds = ParamUtil.getLongValues(resourceRequest, "calendarIds");
    java.util.Calendar endTimeJCalendar = getJCalendar(resourceRequest, "endTime");
    java.util.Calendar startTimeJCalendar = getJCalendar(resourceRequest, "startTime");
    int[] statuses = ParamUtil.getIntegerValues(resourceRequest, "statuses");

    List<CalendarBooking> calendarBookings = Collections.<CalendarBooking>emptyList();

    if (!ArrayUtil.isEmpty(calendarIds)) {
        calendarBookings = _calendarBookingService.search(themeDisplay.getCompanyId(), new long[0], calendarIds,
                new long[0], -1, null, startTimeJCalendar.getTimeInMillis(), endTimeJCalendar.getTimeInMillis(),
                true, statuses, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                new CalendarBookingStartTimeComparator(true));

        int eventsPerPage = ParamUtil.getInteger(resourceRequest, "eventsPerPage");

        if ((eventsPerPage > 0) && (eventsPerPage < calendarBookings.size())) {

            calendarBookings = calendarBookings.subList(0, eventsPerPage);
        }//from   w w w.  j av  a  2 s  . co m
    }

    JSONArray jsonArray = CalendarUtil.toCalendarBookingsJSONArray(themeDisplay, calendarBookings,
            getTimeZone(resourceRequest));

    writeJSON(resourceRequest, resourceResponse, jsonArray);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCalendarBookingsRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    PortletPreferences portletPreferences = resourceRequest.getPreferences();

    boolean enableRss = GetterUtil.getBoolean(portletPreferences.getValue("enableRss", null), true);

    if (!_portal.isRSSFeedsEnabled() || !enableRss) {
        _portal.sendRSSFeedsDisabledError(resourceRequest, resourceResponse);

        return;/*from   w w  w  .j ava2  s  .  com*/
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long calendarId = ParamUtil.getLong(resourceRequest, "calendarId");

    long timeInterval = GetterUtil.getLong(portletPreferences.getValue("rssTimeInterval", StringPool.BLANK),
            RSSUtil.TIME_INTERVAL_DEFAULT);

    long startTime = System.currentTimeMillis();

    long endTime = startTime + timeInterval;

    int max = GetterUtil.getInteger(portletPreferences.getValue("rssDelta", StringPool.BLANK),
            SearchContainer.DEFAULT_DELTA);

    String rssFeedType = portletPreferences.getValue("rssFeedType", RSSUtil.FORMAT_DEFAULT);

    String type = RSSUtil.getFormatType(rssFeedType);
    double version = RSSUtil.getFeedTypeVersion(rssFeedType);

    String displayStyle = portletPreferences.getValue("rssDisplayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String rss = _calendarBookingService.getCalendarBookingsRSS(calendarId, startTime, endTime, max, type,
            version, displayStyle, themeDisplay);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, null, rss.getBytes(),
            ContentTypes.TEXT_XML_UTF8);
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCalendarRenderingRules(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] calendarIds = ParamUtil.getLongValues(resourceRequest, "calendarIds");
    int[] statuses = { CalendarBookingWorkflowConstants.STATUS_APPROVED,
            CalendarBookingWorkflowConstants.STATUS_MAYBE, CalendarBookingWorkflowConstants.STATUS_PENDING };
    long startTime = ParamUtil.getLong(resourceRequest, "startTime");
    long endTime = ParamUtil.getLong(resourceRequest, "endTime");
    String ruleName = ParamUtil.getString(resourceRequest, "ruleName");

    if (calendarIds.length > 0) {
        JSONObject jsonObject = CalendarUtil.getCalendarRenderingRules(themeDisplay, calendarIds, statuses,
                startTime, endTime, ruleName, getTimeZone(resourceRequest));

        writeJSON(resourceRequest, resourceResponse, jsonObject);
    }//from w  w w.  ja v  a  2  s.c o m
}