Example usage for java.lang Helper Helper

List of usage examples for java.lang Helper Helper

Introduction

In this page you can find the example usage for java.lang Helper Helper.

Prototype

Helper

Source Link

Usage

From source file:org.omnaest.utils.xml.XMLNestedMapConverter.java

/**
 * @param nestedMap//from  w w  w. java2 s .c o m
 *          {@link Map}
 * @param outputStream
 *          {@link OutputStream}
 * @param includeDocumentHeader
 *          if true a xml document header is written out additionally
 */
private <K> void toXML(Map<K, Object> nestedMap, OutputStream outputStream,
        final ElementConverter<K, QName> keyElementConverter, boolean includeDocumentHeader) {
    //
    if (nestedMap != null && keyElementConverter != null && outputStream != null) {
        //
        try {
            //
            final XMLOutputFactory xmlOutputFactory = this.xmlInstanceContextFactory.newXmlOutputFactory();
            final XMLEventFactory xmlEventFactory = this.xmlInstanceContextFactory.newXmlEventFactory();
            Assert.isNotNull(xmlOutputFactory, "xmlOutputFactory must not be null");
            Assert.isNotNull(xmlEventFactory, "xmlEventFactory must not be null");

            //
            final XMLEventWriter xmlEventWriter = xmlOutputFactory.createXMLEventWriter(outputStream,
                    this.encoding);
            final ExceptionHandler exceptionHandler = this.exceptionHandler;

            //
            try {
                //
                class Helper {
                    /* ********************************************** Variables ********************************************** */
                    private List<String> namespaceStack = new ArrayList<String>();

                    /* ********************************************** Methods ********************************************** */

                    @SuppressWarnings("unchecked")
                    public void write(Map<K, Object> map) {
                        if (map != null) {
                            for (K key : map.keySet()) {
                                //
                                final QName tagName = keyElementConverter.convert(key);
                                final Object value = map.get(key);

                                //
                                if (value instanceof String) {
                                    //
                                    this.writeStartTag(tagName);

                                    //
                                    final String text = (String) value;
                                    this.writeText(text);

                                    //
                                    this.writeEndTag(tagName);
                                } else if (value instanceof Map) {
                                    //
                                    this.writeStartTag(tagName);

                                    //
                                    final Map<K, Object> subMap = (Map<K, Object>) value;
                                    this.write(subMap);

                                    //
                                    this.writeEndTag(tagName);
                                } else if (value instanceof List) {
                                    //
                                    final List<Object> valueList = (List<Object>) value;
                                    this.write(tagName, valueList);
                                }
                            }
                        }
                    }

                    /**
                     * @param tagName
                     */
                    private void writeStartTag(QName tagName) {
                        //
                        try {
                            //
                            final String namespaceURI = tagName.getNamespaceURI();

                            //            
                            final Iterator<?> attributes = null;
                            final Iterator<?> namespaces = StringUtils.isNotBlank(namespaceURI) && !StringUtils
                                    .equals(namespaceURI, ListUtils.lastElement(this.namespaceStack))
                                            ? IteratorUtils.valueOf(
                                                    xmlEventFactory.createNamespace(namespaceURI))
                                            : null;
                            StartElement startElement = xmlEventFactory.createStartElement(tagName, attributes,
                                    namespaces);
                            xmlEventWriter.add(startElement);

                            //
                            this.namespaceStack.add(namespaceURI);
                        } catch (Exception e) {
                            exceptionHandler.handleException(e);
                        }
                    }

                    /**
                     * @param tagName
                     */
                    private void writeEndTag(QName tagName) {
                        //
                        try {
                            //            
                            final Iterator<?> namespaces = null;
                            EndElement endElement = xmlEventFactory.createEndElement(tagName, namespaces);
                            xmlEventWriter.add(endElement);

                            //
                            ListUtils.removeLast(this.namespaceStack);
                        } catch (Exception e) {
                            exceptionHandler.handleException(e);
                        }
                    }

                    /**
                     * @param text
                     */
                    private void writeText(String text) {
                        //
                        try {
                            //            
                            final Characters characters = xmlEventFactory.createCharacters(text);
                            xmlEventWriter.add(characters);
                        } catch (Exception e) {
                            exceptionHandler.handleException(e);
                        }
                    }

                    /**
                     * @param tagName
                     * @param valueList
                     */
                    @SuppressWarnings("unchecked")
                    private void write(QName tagName, List<Object> valueList) {
                        if (valueList != null) {
                            for (Object value : valueList) {
                                //
                                if (value != null) {
                                    //
                                    this.writeStartTag(tagName);

                                    //
                                    if (value instanceof Map) {
                                        //
                                        final Map<K, Object> map = (Map<K, Object>) value;
                                        this.write(map);
                                    } else if (value instanceof String) {
                                        //
                                        final String text = (String) value;
                                        this.writeText(text);
                                    }

                                    //
                                    this.writeEndTag(tagName);
                                }
                            }
                        }
                    }
                }

                //
                if (includeDocumentHeader) {
                    xmlEventWriter.add(xmlEventFactory.createStartDocument());
                }

                //
                new Helper().write(nestedMap);

                //
                xmlEventWriter.add(xmlEventFactory.createEndDocument());
            } finally {
                xmlEventWriter.close();
                outputStream.flush();
            }
        } catch (Exception e) {
            if (this.exceptionHandler != null) {
                this.exceptionHandler.handleException(e);
            }
        }
    }
}

From source file:org.omnaest.utils.reflection.ReflectionUtils.java

/**
 * Returns as {@link Set} of assignable types which are implemented by the given type. This includes inherited types if the
 * respective parameter is set to true. The given type is returned within the result {@link Set} if it is compliant to the
 * onlyReturnInterfaces flag./*from  w w  w.  j a v  a 2s.  c  o  m*/
 * 
 * @param type
 * @param inherited
 * @param onlyReturnInterfaces
 * @return
 */
public static Set<Class<?>> assignableTypeSet(Class<?> type, boolean inherited, boolean onlyReturnInterfaces) {
    //    
    final Set<Class<?>> retset = new LinkedHashSet<Class<?>>();

    //
    if (type != null) {
        //
        final Set<Class<?>> remainingTypeSet = new LinkedHashSet<Class<?>>();

        //
        class Helper {
            public void addNewInterfaceTypes(Class<?> type) {
                Class<?>[] interfaces = type.getInterfaces();
                if (interfaces != null) {
                    for (Class<?> interfaceType : interfaces) {
                        if (!retset.contains(interfaceType)) {
                            remainingTypeSet.add(interfaceType);
                        }
                    }
                }
            }
        }

        //
        if (!onlyReturnInterfaces || type.isInterface()) {
            retset.add(type);
        }

        //
        if (inherited) {
            remainingTypeSet.addAll(supertypeSet(type));
        }

        //
        Helper helper = new Helper();
        helper.addNewInterfaceTypes(type);

        //
        while (!remainingTypeSet.isEmpty()) {
            //
            Iterator<Class<?>> iterator = remainingTypeSet.iterator();
            Class<?> remainingType = iterator.next();
            iterator.remove();

            //
            if (!onlyReturnInterfaces || remainingType.isInterface()) {
                retset.add(remainingType);
            }

            //
            if (inherited) {
                //
                helper.addNewInterfaceTypes(remainingType);
            }

        }
    }

    //
    return retset;
}

From source file:GUI.MainWindow.java

private void doImport() {
    // Get the file selector popup
    int returnVal = this.fileChooser.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        // Clear previous importing list
        this.importingListModel = new DefaultListModel();
        File[] importing_files = fileChooser.getSelectedFiles();
        for (File file : importing_files) {
            ImportFile impFile = new ImportFile(file.getAbsolutePath());

            this.properties.setProperty("Last_Accessed_Directory", impFile.getParent());
            System.out.println("Last_Accessed_Directory Updated: " + impFile.getParent());

            DefaultListModel dlm = new DefaultListModel();
            dlm.addElement(impFile);//ww  w  . j  a v a  2  s. co  m
            ImportFile.setModel(dlm);
            String fileType = universal_file_importer.getFileType(file);
            if (fileType.equalsIgnoreCase("Unknown")) {
                String message = "Did not understand that file type, cannot import that.";
                String title = "Cannot Import File";

                JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
                System.out.println(title);
                System.out.println("User informed by popup, cleanly ignoring the file");
            } else {
                FileType.setText(fileType);
                FileSize.setText("" + new Helper().getFileSizeInMB(impFile));
                ImportScanScreen.setLocationRelativeTo(this);
                ImportScanScreen.setVisible(true);
            }
        }

    }
}

From source file:org.sakaiproject.calendar.tool.CalendarAction.java

/**
 * Build the context for showing revise view
 *///  ww  w . j  a v  a  2s  .c om
protected void buildReviseContext(VelocityPortlet portlet, Context context, RunData runData,
        CalendarActionState state) {
    // to get the content Type Image Service
    context.put("contentTypeImageService", ContentTypeImageService.getInstance());
    context.put("tlang", rb);
    context.put("config", configProps);
    Calendar calendarObj = null;
    CalendarEvent calEvent = null;
    CalendarUtil calObj = new CalendarUtil(); //null;
    MyDate dateObj1 = null;
    dateObj1 = new MyDate();
    boolean getEventsFlag = false;

    List attachments = state.getAttachments();

    String peid = ((JetspeedRunData) runData).getJs_peid();
    SessionState sstate = ((JetspeedRunData) runData).getPortletSessionState(peid);

    Time m_time = TimeService.newTime();
    TimeBreakdown b = m_time.breakdownLocal();
    int stateYear = b.getYear();
    int stateMonth = b.getMonth();
    int stateDay = b.getDay();
    if ((sstate.getAttribute(STATE_YEAR) != null) && (sstate.getAttribute(STATE_MONTH) != null)
            && (sstate.getAttribute(STATE_DAY) != null)) {
        stateYear = ((Integer) sstate.getAttribute(STATE_YEAR)).intValue();
        stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH)).intValue();
        stateDay = ((Integer) sstate.getAttribute(STATE_DAY)).intValue();
    }
    calObj.setDay(stateYear, stateMonth, stateDay);

    dateObj1.setTodayDate(calObj.getMonthInteger(), calObj.getDayOfMonth(), calObj.getYear());
    String calId = state.getPrimaryCalendarReference();
    if (state.getIsNewCalendar() == false) {
        if (CalendarService.allowGetCalendar(calId) == false) {
            context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotallow"));
            return;
        } else {
            try {
                calendarObj = CalendarService.getCalendar(calId);

                if (calendarObj.allowGetEvent(state.getCalendarEventId())) {
                    calEvent = calendarObj.getEvent(state.getCalendarEventId());
                    getEventsFlag = true;
                    context.put("selectedGroupRefsCollection", calEvent.getGroups());

                    // all the groups the user is allowed to do remove from
                    context.put("allowedRemoveGroups",
                            calendarObj.getGroupsAllowRemoveEvent(calEvent.isUserOwner()));
                } else
                    getEventsFlag = false;

                // Add any additional fields in the calendar.
                customizeCalendarPage.loadAdditionalFieldsIntoContextFromCalendar(calendarObj, context);
                context.put("tlang", rb);
                context.put("config", configProps);
                context.put("calEventFlag", "true");
                context.put("new", "false");
                // if from the metadata view of announcement, the message is already the system resource
                if (state.getState().equals("goToReviseCalendar")) {
                    context.put("backToRevise", "false");
                }
                // if from the attachments editing view or preview view of announcement
                else if (state.getState().equals("revise")) {
                    context.put("backToRevise", "true");
                }

                //Vector attachments = state.getAttachments();
                if (attachments != null) {
                    context.put("attachments", attachments);
                } else {
                    context.put("attachNull", "true");
                }

                context.put("fromAttachmentFlag", state.getfromAttachmentFlag());
            } catch (IdUnusedException e) {
                context.put(ALERT_MSG_KEY, rb.getString("java.alert.therenoactv"));
                M_log.debug(".buildReviseContext(): " + e);
                return;
            } catch (PermissionException e) {
                context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotperm"));
                M_log.debug(".buildReviseContext(): " + e);
                return;
            }
        }
    } else {
        // if this a new annoucement, get the subject and body from temparory record
        context.put("new", "true");
        context.put("tlang", rb);
        context.put("config", configProps);
        context.put("attachments", attachments);
        context.put("fromAttachmentFlag", state.getfromAttachmentFlag());
    }

    // Output for recurring events

    // for an existing event
    // if the saved recurring rule equals to string FREQ_ONCE, set it as not recurring
    // if there is a saved recurring rule in sstate, display it
    // otherwise, output the event's rule instead
    if ((((String) sstate.getAttribute(FREQUENCY_SELECT)) != null)
            && (((String) sstate.getAttribute(FREQUENCY_SELECT)).equals(FREQ_ONCE))) {
        context.put("rule", null);
    } else {
        RecurrenceRule rule = (RecurrenceRule) sstate.getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
        if (rule == null) {
            rule = calEvent.getRecurrenceRule();
        } else
            context.put("rule", rule);

        if (rule != null) {
            context.put("freq", rule.getFrequencyDescription());
        } // if (rule != null)
    } //if ((String) sstate.getAttribute(FREQUENCY_SELECT).equals(FREQ_ONCE))

    try {
        calendarObj = CalendarService.getCalendar(calId);

        String scheduleTo = (String) sstate.getAttribute(STATE_SCHEDULE_TO);
        if (scheduleTo != null && scheduleTo.length() != 0) {
            context.put("scheduleTo", scheduleTo);
        } else {
            if (calendarObj.allowAddCalendarEvent()) {
                // default to make site selection
                context.put("scheduleTo", "site");
            } else if (calendarObj.getGroupsAllowAddEvent().size() > 0) {
                // to group otherwise
                context.put("scheduleTo", "groups");
            }
        }

        Collection groups = calendarObj.getGroupsAllowAddEvent();

        // add to these any groups that the message already has
        calEvent = calendarObj.getEvent(state.getCalendarEventId());
        if (calEvent != null) {
            Collection otherGroups = calEvent.getGroupObjects();
            for (Iterator i = otherGroups.iterator(); i.hasNext();) {
                Group g = (Group) i.next();

                if (!groups.contains(g)) {
                    groups.add(g);
                }
            }
        }

        if (groups.size() > 0) {
            context.put("groups", groups);
        }
    } catch (IdUnusedException e) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.thereis"));
        M_log.debug(".buildNewContext(): " + e);
        return;
    } catch (PermissionException e) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.youdont"));
        M_log.debug(".buildNewContext(): " + e);
        return;
    }
    context.put("tlang", rb);
    context.put("config", configProps);
    context.put("event", calEvent);
    context.put("helper", new Helper());
    context.put("message", "revise");
    context.put("savedData", state.getNewData());
    context.put("getEventsFlag", Boolean.valueOf(getEventsFlag));

    if (state.getIsNewCalendar() == true)
        context.put("vmtype", "new");
    else
        context.put("vmtype", "revise");

    context.put("service", contentHostingService);

    // output the real time
    context.put("realDate", TimeService.newTime());

}

From source file:org.sakaiproject.calendar.tool.CalendarAction.java

/**
 * Build the context for showing day view
 *//* w w w. j a  v a  2s.c o m*/
protected void buildDayContext(VelocityPortlet portlet, Context context, RunData runData,
        CalendarActionState state) {

    Calendar calendarObj = null;
    boolean allowed = false;
    MyDate dateObj1 = null;
    CalendarEventVector CalendarEventVectorObj = null;

    String peid = ((JetspeedRunData) runData).getJs_peid();
    SessionState sstate = ((JetspeedRunData) runData).getPortletSessionState(peid);

    Time m_time = TimeService.newTime();
    TimeBreakdown b = m_time.breakdownLocal();
    int stateYear = b.getYear();
    int stateMonth = b.getMonth();
    int stateDay = b.getDay();
    context.put("todayYear", Integer.valueOf(stateYear));
    context.put("todayMonth", Integer.valueOf(stateMonth));
    context.put("todayDay", Integer.valueOf(stateDay));

    if ((sstate.getAttribute(STATE_YEAR) != null) && (sstate.getAttribute(STATE_MONTH) != null)
            && (sstate.getAttribute(STATE_DAY) != null)) {
        stateYear = ((Integer) sstate.getAttribute(STATE_YEAR)).intValue();
        stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH)).intValue();
        stateDay = ((Integer) sstate.getAttribute(STATE_DAY)).intValue();
    }
    CalendarUtil calObj = new CalendarUtil();
    calObj.setDay(stateYear, stateMonth, stateDay);

    // new objects of myYear, myMonth, myDay, myWeek classes
    dateObj1 = new MyDate();
    dateObj1.setTodayDate(calObj.getMonthInteger(), calObj.getDayOfMonth(), calObj.getYear());

    int year = dateObj1.getYear();
    int month = dateObj1.getMonth();
    int day = dateObj1.getDay();

    Vector eventVector = new Vector();

    String calId = state.getPrimaryCalendarReference();

    if (CalendarService.allowGetCalendar(calId) == false) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotallow"));
        return;
    } else {
        try {
            calendarObj = CalendarService.getCalendar(calId);
            allowed = calendarObj.allowAddEvent();

            CalendarEventVectorObj = CalendarService.getEvents(
                    getCalendarReferenceList(portlet, state.getPrimaryCalendarReference(), isOnWorkspaceTab()),
                    getDayTimeRange(year, month, day));

            String currentPage = state.getCurrentPage();

            // if coming from clicking the the day number in month view, year view or list view
            // select the time slot first, go to the slot containing earliest event on that day

            if (state.getPrevState() != null) {
                if ((state.getPrevState()).equalsIgnoreCase("list")
                        || (state.getPrevState()).equalsIgnoreCase("month")
                        || (state.getPrevState()).equalsIgnoreCase("year")) {
                    CalendarEventVector vec = null;
                    Time timeObj = TimeService.newTimeLocal(year, month, day, FIRST_PAGE_START_HOUR, 00, 00,
                            000);
                    Time timeObj2 = TimeService.newTimeLocal(year, month, day, 7, 59, 59, 000);
                    TimeRange timeRangeObj = TimeService.newTimeRange(timeObj, timeObj2);
                    vec = CalendarService.getEvents(getCalendarReferenceList(portlet,
                            state.getPrimaryCalendarReference(), isOnWorkspaceTab()), timeRangeObj);

                    if (vec.size() > 0)
                        currentPage = "first";
                    else {
                        timeObj = TimeService.newTimeLocal(year, month, day, SECOND_PAGE_START_HOUR, 00, 00,
                                000);
                        timeObj2 = TimeService.newTimeLocal(year, month, day, 17, 59, 59, 000);
                        timeRangeObj = TimeService.newTimeRange(timeObj, timeObj2);
                        vec = CalendarService.getEvents(getCalendarReferenceList(portlet,
                                state.getPrimaryCalendarReference(), isOnWorkspaceTab()), timeRangeObj);

                        if (vec.size() > 0)
                            currentPage = "second";
                        else {
                            timeObj = TimeService.newTimeLocal(year, month, day, THIRD_PAGE_START_HOUR, 00, 00,
                                    000);
                            timeObj2 = TimeService.newTimeLocal(year, month, day, 23, 59, 59, 000);
                            timeRangeObj = TimeService.newTimeRange(timeObj, timeObj2);
                            vec = CalendarService.getEvents(getCalendarReferenceList(portlet,
                                    state.getPrimaryCalendarReference(), isOnWorkspaceTab()), timeRangeObj);

                            if (vec.size() > 0)
                                currentPage = "third";
                            else
                                currentPage = "second";
                        }
                    }
                    state.setCurrentPage(currentPage);
                }
            }

            if (currentPage.equals("third")) {
                eventVector = getNewEvents(year, month, day, state, runData, THIRD_PAGE_START_HOUR, 19, context,
                        CalendarEventVectorObj);
            } else if (currentPage.equals("second")) {
                eventVector = getNewEvents(year, month, day, state, runData, SECOND_PAGE_START_HOUR, 19,
                        context, CalendarEventVectorObj);
            } else {
                eventVector = getNewEvents(year, month, day, state, runData, FIRST_PAGE_START_HOUR, 19, context,
                        CalendarEventVectorObj);
            }

            dateObj1.setEventBerDay(eventVector);
        } catch (IdUnusedException e) {
            context.put(ALERT_MSG_KEY, rb.getString("java.alert.therenoactv"));
            M_log.debug(".buildDayContext(): " + e);
            return;
        } catch (PermissionException e) {
            context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotperm"));
            M_log.debug(".buildDayContext(): " + e);
            return;
        }
    }

    context.put("nameOfMonth", calendarUtilGetMonth(calObj.getMonthInteger()));
    context.put("monthInt", Integer.valueOf(calObj.getMonthInteger()));
    context.put("firstpage", "true");
    context.put("secondpage", "false");
    context.put("page", state.getCurrentPage());
    context.put("date", dateObj1);
    context.put("helper", new Helper());
    context.put("calObj", calObj);
    context.put("tlang", rb);
    context.put("config", configProps);
    state.setState("day");
    context.put("message", state.getState());

    DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL, new ResourceLoader().getLocale());
    try {
        context.put("today", formatter.format(calObj.getTime()));
    } catch (Exception e) {
        context.put("today", calObj.getTodayDate());
    }

    state.setPrevState("");

    buildMenu(portlet, context, runData, state,
            CalendarPermissions.allowCreateEvents(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference()),
            CalendarPermissions.allowDeleteEvent(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference(), state.getCalendarEventId()),
            CalendarPermissions.allowReviseEvents(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference(), state.getCalendarEventId()),
            CalendarPermissions.allowMergeCalendars(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowModifyCalendarProperties(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowImport(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowSubscribe(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowSubscribeThis(state.getPrimaryCalendarReference()));

    context.put("permissionallowed", Boolean.valueOf(allowed));
    context.put("tlang", rb);
    context.put("config", configProps);

    context.put("selectedView", rb.getString("java.byday"));

    context.put("dayName", calendarUtilGetDay(calObj.getDay_Of_Week(true)));

}

From source file:org.sakaiproject.calendar.tool.CalendarAction.java

/**
 * Build the context for showing week view
 *///from w ww. jav a 2s .  co m
protected void buildWeekContext(VelocityPortlet portlet, Context context, RunData runData,
        CalendarActionState state) {
    Calendar calendarObj = null;
    //Time st,et = null;
    //CalendarUtil calObj= null;
    MyYear yearObj = null;
    MyMonth monthObj1 = null;
    MyWeek weekObj = null;
    MyDay dayObj = null;
    MyDate dateObj1, dateObj2 = null;
    int dayofweek = 0;

    // new objects of myYear, myMonth, myDay, myWeek classes
    yearObj = new MyYear();
    monthObj1 = new MyMonth();
    weekObj = new MyWeek();
    dayObj = new MyDay();
    dateObj1 = new MyDate();
    CalendarEventVector CalendarEventVectorObj = null;

    //calObj = state.getCalObj();
    String peid = ((JetspeedRunData) runData).getJs_peid();
    SessionState sstate = ((JetspeedRunData) runData).getPortletSessionState(peid);

    Time m_time = TimeService.newTime();
    TimeBreakdown b = m_time.breakdownLocal();
    int stateYear = b.getYear();
    int stateMonth = b.getMonth();
    int stateDay = b.getDay();
    if ((sstate.getAttribute(STATE_YEAR) != null) && (sstate.getAttribute(STATE_MONTH) != null)
            && (sstate.getAttribute(STATE_DAY) != null)) {
        stateYear = ((Integer) sstate.getAttribute(STATE_YEAR)).intValue();
        stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH)).intValue();
        stateDay = ((Integer) sstate.getAttribute(STATE_DAY)).intValue();
    }

    CalendarUtil calObj = new CalendarUtil();
    calObj.setDay(stateYear, stateMonth, stateDay);
    int iii = 0;

    dateObj1.setTodayDate(calObj.getMonthInteger(), calObj.getDayOfMonth(), calObj.getYear());
    yearObj.setYear(calObj.getYear());
    monthObj1.setMonth(calObj.getMonthInteger());
    dayObj.setDay(calObj.getDayOfMonth());
    String calId = state.getPrimaryCalendarReference();

    // this loop will move the calendar to the begining of the week

    if (CalendarService.allowGetCalendar(calId) == false) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotallow"));
        return;
    } else {
        try {
            calendarObj = CalendarService.getCalendar(calId);
        } catch (IdUnusedException e) {
            try {
                CalendarService.commitCalendar(CalendarService.addCalendar(calId));
                calendarObj = CalendarService.getCalendar(calId);
            } catch (Exception err) {
                context.put(ALERT_MSG_KEY, rb.getString("java.alert.therenoactv"));
                M_log.debug(".buildWeekContext(): " + err);
                return;
            }
        } catch (PermissionException e) {
            context.put(ALERT_MSG_KEY, rb.getString("java.alert.younotperm"));
            M_log.debug(".buildWeekContext(): " + e);
            return;
        }
    }

    if (calendarObj.allowGetEvents() == true) {
        CalendarEventVectorObj = CalendarService.getEvents(
                getCalendarReferenceList(portlet, state.getPrimaryCalendarReference(), isOnWorkspaceTab()),
                getWeekTimeRange(calObj));
    } else {
        CalendarEventVectorObj = new CalendarEventVector();
    }

    calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(), dateObj1.getDay());
    dayofweek = calObj.getDay_Of_Week(true);
    calObj.setPrevDate(dayofweek - 1);

    dayofweek = calObj.getDay_Of_Week(true);

    Time[] pageStartTime = new Time[7];
    Time[] pageEndTime = new Time[7];

    for (int i = 7; i >= dayofweek; i--) {

        Vector eventVector = new Vector();
        Vector eventVector1;
        dateObj2 = new MyDate();
        dateObj2.setTodayDate(calObj.getMonthInteger(), calObj.getDayOfMonth(), calObj.getYear());
        dateObj2.setDayName(calendarUtilGetDay(calObj.getDay_Of_Week(true)));
        dateObj2.setNameOfMonth(calendarUtilGetMonth(calObj.getMonthInteger()));

        if (calObj.getDayOfMonth() == dayObj.getDay())
            dateObj2.setFlag(1);

        if (state.getCurrentPage().equals("third")) {
            eventVector1 = new Vector();
            // JS -- the third page starts at 2PM(14 o'clock), and lasts 20 half-hour
            eventVector = getNewEvents(calObj.getYear(), calObj.getMonthInteger(), calObj.getDayOfMonth(),
                    state, runData, THIRD_PAGE_START_HOUR, 19, context, CalendarEventVectorObj);

            for (int index = 0; index < eventVector1.size(); index++) {
                eventVector.add(eventVector.size(), eventVector1.get(index));
            }

            // Reminder: weekview vm is using 0..6
            pageStartTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), THIRD_PAGE_START_HOUR, 0, 0, 0);
            pageEndTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), 23, 59, 0, 0);

        } else if (state.getCurrentPage().equals("second")) {
            eventVector = getNewEvents(calObj.getYear(), calObj.getMonthInteger(), calObj.getDayOfMonth(),
                    state, runData, SECOND_PAGE_START_HOUR, 19, context, CalendarEventVectorObj);
            // Reminder: weekview vm is using 0..6
            pageStartTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), SECOND_PAGE_START_HOUR, 0, 0, 0);
            pageEndTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), 17, 59, 0, 0);

        } else {
            eventVector1 = new Vector();
            // JS -- the first page starts at 12AM(0 o'clock), and lasts 20 half-hour
            eventVector1 = getNewEvents(calObj.getYear(), calObj.getMonthInteger(), calObj.getDayOfMonth(),
                    state, runData, FIRST_PAGE_START_HOUR, 19, context, CalendarEventVectorObj);

            for (int index = 0; index < eventVector1.size(); index++) {
                eventVector.insertElementAt(eventVector1.get(index), index);
            }

            // Reminder: weekview vm is using 0..6
            pageStartTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), 0, 0, 0, 0);
            pageEndTime[i - 1] = TimeService.newTimeLocal(calObj.getYear(), calObj.getMonthInteger(),
                    calObj.getDayOfMonth(), 9, 59, 0, 0);

        }
        dateObj2.setEventBerWeek(eventVector);
        weekObj.setWeek(7 - i, dateObj2);

        // the purpose of this if condition is to check if we reached day 7 if yes do not
        // call next day.
        if (i > dayofweek)
            calObj.nextDate();
    }

    calObj.setDay(yearObj.getYear(), monthObj1.getMonth(), dayObj.getDay());
    context.put("week", weekObj);
    context.put("helper", new Helper());
    context.put("date", dateObj1);
    context.put("page", state.getCurrentPage());
    state.setState("week");
    context.put("tlang", rb);
    context.put("config", configProps);
    context.put("message", state.getState());

    DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL, new ResourceLoader().getLocale());
    formatter.setTimeZone(TimeService.getLocalTimeZone());
    try {
        context.put("beginWeek", formatter.format(calObj.getPrevTime(calObj.getDay_Of_Week(true) - 1)));
    } catch (Exception e) {
        context.put("beginWeek", calObj.getTodayDate());
    }
    try {
        calObj.setNextWeek();
        context.put("endWeek", formatter.format(calObj.getPrevTime(1)));
    } catch (Exception e) {
        context.put("endWeek", calObj.getTodayDate());
    }

    buildMenu(portlet, context, runData, state,
            CalendarPermissions.allowCreateEvents(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference()),
            CalendarPermissions.allowDeleteEvent(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference(), state.getCalendarEventId()),
            CalendarPermissions.allowReviseEvents(state.getPrimaryCalendarReference(),
                    state.getSelectedCalendarReference(), state.getCalendarEventId()),
            CalendarPermissions.allowMergeCalendars(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowModifyCalendarProperties(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowImport(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowSubscribe(state.getPrimaryCalendarReference()),
            CalendarPermissions.allowSubscribeThis(state.getPrimaryCalendarReference()));

    calObj.setDay(yearObj.getYear(), monthObj1.getMonth(), dayObj.getDay());

    context.put("realDate", TimeService.newTime());
    context.put("tlang", rb);
    context.put("config", configProps);
    Vector vec = new Vector();
    context.put("vec", vec);
    Vector conflictVec = new Vector();
    context.put("conflictVec", conflictVec);
    Vector calVec = new Vector();
    context.put("calVec", calVec);
    HashMap hm = new HashMap();
    context.put("hm", hm);
    Integer intObj = Integer.valueOf(0);
    context.put("intObj", intObj);

    context.put("pageStartTime", pageStartTime);
    context.put("pageEndTime", pageEndTime);

    context.put("selectedView", rb.getString("java.byweek"));

    context.put("dayOfWeekNames", calObj.getCalendarDaysOfWeekNames(false));

}

From source file:org.sakaiproject.calendar.tool.CalendarAction.java

/**
 * Build the context for showing New view
 *///from w w  w.j  a  va  2  s  .c om
protected void buildNewContext(VelocityPortlet portlet, Context context, RunData runData,
        CalendarActionState state) {
    context.put("tlang", rb);
    context.put("config", configProps);
    // to get the content Type Image Service
    context.put("contentTypeImageService", ContentTypeImageService.getInstance());

    MyDate dateObj1 = new MyDate();

    CalendarUtil calObj = new CalendarUtil();

    // set real today's date as default
    Time m_time = TimeService.newTime();
    TimeBreakdown b = m_time.breakdownLocal();
    calObj.setDay(b.getYear(), b.getMonth(), b.getDay());

    dateObj1.setTodayDate(calObj.getMonthInteger(), calObj.getDayOfMonth(), calObj.getYear());

    // get the event id from the CalendarService.
    // send the event to the vm
    dateObj1.setNumberOfDaysInMonth(calObj.getNumberOfDays());
    List attachments = state.getAttachments();
    context.put("attachments", attachments);

    String calId = state.getPrimaryCalendarReference();
    Calendar calendarObj = null;

    try {
        calendarObj = CalendarService.getCalendar(calId);
        Collection groups = calendarObj.getGroupsAllowAddEvent();

        String peid = ((JetspeedRunData) runData).getJs_peid();
        SessionState sstate = ((JetspeedRunData) runData).getPortletSessionState(peid);

        String scheduleTo = (String) sstate.getAttribute(STATE_SCHEDULE_TO);
        if (scheduleTo != null && scheduleTo.length() != 0) {
            context.put("scheduleTo", scheduleTo);
        } else {
            if (calendarObj.allowAddCalendarEvent()) {
                // default to make site selection
                context.put("scheduleTo", "site");
            } else if (groups.size() > 0) {
                // to group otherwise
                context.put("scheduleTo", "groups");
            }
        }

        if (groups.size() > 0) {
            List schToGroups = (List) (sstate.getAttribute(STATE_SCHEDULE_TO_GROUPS));
            context.put("scheduleToGroups", schToGroups);

            context.put("groups", groups);
        }
    } catch (IdUnusedException e) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.thereis"));
        M_log.debug(".buildNewContext(): " + e);
        return;
    } catch (PermissionException e) {
        context.put(ALERT_MSG_KEY, rb.getString("java.alert.youdont"));
        M_log.debug(".buildNewContext(): " + e);
        return;
    }

    // Add any additional fields in the calendar.
    customizeCalendarPage.loadAdditionalFieldsIntoContextFromCalendar(calendarObj, context);

    // Output for recurring events
    String peid = ((JetspeedRunData) runData).getJs_peid();
    SessionState sstate = ((JetspeedRunData) runData).getPortletSessionState(peid);

    // if the saved recurring rule equals to string FREQ_ONCE, set it as not recurring
    // if there is a saved recurring rule in sstate, display it      
    RecurrenceRule rule = (RecurrenceRule) sstate.getAttribute(CalendarAction.SSTATE__RECURRING_RULE);

    if (rule != null) {
        context.put("freq", rule.getFrequencyDescription());

        context.put("rule", rule);
    }

    context.put("date", dateObj1);
    context.put("savedData", state.getNewData());
    context.put("helper", new Helper());
    context.put("realDate", TimeService.newTime());

}