/** * Initializes Velocity engine */ private void init() { velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); setLogFile(); DateTool dateTool = new DateTool(); dateTool.configure(this.configMap); MathTool mathTool = new MathTool(); NumberTool numberTool = new NumberTool(); numberTool.configure(this.configMap); SortTool sortTool = new SortTool(); defaultContext = new VelocityContext(); defaultContext.put("dateTool", dateTool); defaultContext.put("dateComparisonTool", new ComparisonDateTool()); defaultContext.put("mathTool", mathTool); defaultContext.put("numberTool", numberTool); defaultContext.put("sortTool", sortTool); // Following tools need VelocityTools version 2.0+ //defaultContext.put("displayTool", new DisplayTool()); //defaultContext.put("xmlTool", new XmlTool()); try { velocityEngine.init(); } catch (Exception e) { throw new VelocityException(e); } }
/** * Custom sort CM collections using properties provided object has getter & setter for * properties in keys and orders * defaults to eid & title if none specified * * @param collection a collection to be sorted * @param keys properties to sort on * @param orders properties on how to sort (asc, dsc) * @return Collection the sorted collection */ private Collection sortCmObject(Collection collection, String[] keys, String[] orders) { if (collection != null && !collection.isEmpty()) { // Add them to a list for the SortTool (they must have the form // "<key:order>" in this implementation) List propsList = new ArrayList(); if (keys == null || orders == null || keys.length == 0 || orders.length == 0) { // No keys are specified, so use the default sort order propsList.add("eid"); propsList.add("title"); } else { // Populate propsList for (int i = 0; i < Math.min(keys.length, orders.length); i++) { String key = keys[i]; String order = orders[i]; propsList.add(key + ":" + order); } } // Sort the collection and return SortTool sort = new SortTool(); return sort.sort(collection, propsList); } return Collections.emptyList(); }
public CourseOfferingObject(CourseOffering offering, List unsortedSections) { List propsList = new ArrayList(); propsList.add("category"); propsList.add("eid"); SortTool sort = new SortTool(); this.sections = new ArrayList(); if (unsortedSections != null) { this.sections = (List) sort.sort(unsortedSections, propsList); } this.eid = offering.getEid(); this.title = offering.getTitle(); }
/** * @param viewName the view name * @param isModal is the view a modal or not * @param options server options */ public CSViewModel(String viewName, boolean isModal, EServerOptions options) { super(viewName); this.isSimpleView = false; this.isModal = isModal; this.addModel("C2InstanceOptions", options); String implementationVersion = this.getClass().getPackage().getImplementationVersion(); this.addModel("C2InstanceVersion", implementationVersion != null ? implementationVersion : "DEV-SNAPSHOT"); this.addModel("VIEWNAME", viewName); this.addModel("dateTool", new DateTool()); this.addModel("sorterTool", new SortTool()); this.addModel("NOW", DateTime.now()); }
/** * @param viewName the view name */ public CSViewModel(String viewName) { super(viewName); String implementationVersion = this.getClass().getPackage().getImplementationVersion(); this.addModel("C2InstanceVersion", implementationVersion != null ? implementationVersion : "DEV-SNAPSHOT"); this.addModel("dateTool", new DateTool()); this.addModel("sorterTool", new SortTool()); this.addModel("NOW", DateTime.now()); }
/** * Creates a message object with a set of standard parameters * @param entityId * @param userId * @return The message object with many useful parameters */ private MessageDTO initializeMessage(Integer entityId, Integer userId) throws SessionInternalError { MessageDTO retValue = new MessageDTO(); try { UserBL user = new UserBL(userId); ContactBL contact = new ContactBL(); // this user's info contact.set(userId); if (contact.getEntity() != null) { retValue.addParameter("contact", contact.getEntity()); retValue.addParameter("first_name", contact.getEntity().getFirstName()); retValue.addParameter("last_name", contact.getEntity().getLastName()); retValue.addParameter("address1", contact.getEntity().getAddress1()); retValue.addParameter("address2", contact.getEntity().getAddress2()); retValue.addParameter("city", contact.getEntity().getCity()); retValue.addParameter("organization_name", contact.getEntity().getOrganizationName()); retValue.addParameter("postal_code", contact.getEntity().getPostalCode()); retValue.addParameter("state_province", contact.getEntity().getStateProvince()); } if (user.getEntity() != null) { retValue.addParameter("user", user.getEntity()); retValue.addParameter("username", user.getEntity().getUserName()); retValue.addParameter("password", user.getEntity().getPassword()); retValue.addParameter("user_id", user.getEntity().getUserId().toString()); } if (user.getCreditCard() != null) { retValue.addParameter("credit_card", user.getCreditCard()); } // the entity info contact.setEntity(entityId); if (contact.getEntity() != null) { retValue.addParameter("company_contact", contact.getEntity()); retValue.addParameter("company_id", entityId.toString()); retValue.addParameter("company_name", contact.getEntity().getOrganizationName()); } //velocity tools retValue.addParameter("tools-date", new DateTool()); retValue.addParameter("tools-math", new MathTool()); retValue.addParameter("tools-number", new NumberTool()); retValue.addParameter("tools-render", new RenderTool()); retValue.addParameter("tools-escape", new EscapeTool()); retValue.addParameter("tools-resource", new ResourceTool()); retValue.addParameter("tools-alternator", new AlternatorTool()); // retValue.addParameter("tools-valueParser", new ValueParser()); retValue.addParameter("tools-list", new ListTool()); retValue.addParameter("tools-sort", new SortTool()); retValue.addParameter("tools-iterator", new IteratorTool()); //Adding a CCF Field to Email Template if (user.getEntity().getCustomer() != null && user.getEntity().getCustomer().getMetaFields() != null) { for (MetaFieldValue metaFieldValue : user.getEntity().getCustomer().getMetaFields()) { retValue.addParameter(metaFieldValue.getField().getName(), metaFieldValue.getValue()); } } LOG.debug("Retvalue >>>> "+retValue.toString()); LOG.debug("Retvalue partameters >>>> "+retValue.getParameters()); } catch (Exception e) { throw new SessionInternalError(e); } return retValue; }