Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


        //request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,
        // stack);
        //Moved to WebWorkPortlet doService()

        VelocityManager velocityManager = VelocityManager.getInstance();
        Context resultContext = velocityManager.createContext(stack, request, response);

        response.setContentType("text/html");

        try {
            String location = (String) ActionContext.getContext().get("template");
View Full Code Here


    private void applyDecoratorUsingVelocity(HttpServletRequest request, Page page, HttpServletResponse response, Decorator decorator)
            throws IOException {
        try {
            request.setAttribute("__sitemesh__page", page);
            Context context = VelocityManager.getInstance().createContext(ActionContext.getContext().getValueStack(), request, response);

            context.put("textUtils", TEXT_UTILS);
            context.put("fileUtil", FILE_UTILS);
            context.put("generalUtil", GENERAL_UTIL);

            context.put("page", page);
            context.put("title", page.getTitle());

            StringWriter buffer = new StringWriter();
            page.writeBody(OutputConverter.getWriter(buffer));
            context.put("body", buffer.toString());

            if (page instanceof HTMLPage) {
                HTMLPage htmlPage = (HTMLPage) page;
                buffer = new StringWriter();
                htmlPage.writeHead(OutputConverter.getWriter(buffer));
                context.put("head", buffer.toString());
            }

            //Rendering the content
            VelocityEngine velocityEngine = VelocityManager.getInstance().getVelocityEngine();
View Full Code Here

            Factory factory = PortletContext.getContext().getSiteMeshFactory();
            Decorator decorator = factory.getDecoratorMapper().getNamedDecorator(request, decoratorName);
            if (decorator != null) {
                com.opensymphony.module.sitemesh.PageParser parser = factory.getPageParser("text/html");
                HTMLPage page = (HTMLPage) ((FastPageParser) parser).parse(new StringReader(bodyContent.toString()));
                Context context = VelocityManager.getInstance()
                        .createContext(ActionContext.getContext().getValueStack(), request, response);
                context.put("page", page);
                if (node.jjtGetNumChildren() == 3)
                    context.put("title", (String) node.jjtGetChild(1).value(adapter));
                else
                    context.put("title", page.getTitle());
                StringWriter buffer = new StringWriter();
                page.writeBody(OutputConverter.getWriter(buffer));
                context.put("body", buffer.toString());
                buffer = new StringWriter();
                page.writeHead(OutputConverter.getWriter(buffer));
                context.put("head", buffer.toString());
                context.put("params", params);
                writer.write(VelocityUtils.getRenderedTemplate(decorator.getPage(), context));
            } else {
                throw new IOException("could not find decorator with name: " + decoratorName);
            }
            flag = true;
View Full Code Here

            _log.debug( "merge(" + path + ", context=" + context + ")" );
        }

        try
        {
            Context  ctx = createContext( request, response, context );

            Template template = _engine.getTemplate( path );
            template.merge( ctx, response.getWriter(  ) );
        }
        catch ( ParseErrorException p )
View Full Code Here

   */
  public void render(Renderer renderer, StringOutput target, Component source, URLBuilder ubu, Translator translator,
      RenderResult renderResult, String[] args) {
    VelocityContainer vc = (VelocityContainer) source;
    String pagePath = vc.getPage();
    Context ctx = vc.getContext();
   
    // the component id of the urlbuilder  will be overwritten by the recursive render call for
    // subcomponents (see Renderer)
    Renderer fr = Renderer.getInstance(vc, translator, ubu, renderResult, renderer.getGlobalSettings());
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(fr, vc);     
    ctx.put("r", vrdec);
    VelocityHelper vh = VelocityHelper.getInstance();
    String mm = vh.mergeContent(pagePath, ctx, theme);
   
    // experimental!!!
    // surround with red border if recording mark indicates so.
View Full Code Here

      // language iteration below
      Translator pageTranslator = new PackageTranslator(bundleName, I18nModule.getDefaultLocale());
      // Open velocity page for this help page
      String pagePath = bundleName.replace('.', '/') + ContextHelpModule.CHELP_DIR + page;
      VelocityContainer container =  new VelocityContainer("contextHelpPageVC", pagePath, pageTranslator, null);         
      Context ctx = container.getContext();   
      GlobalSettings globalSettings = new GlobalSettings() {
        public int getFontSize() { return 100;}
        public AJAXFlags getAjaxFlags() { return new EmptyAJAXFlags();}
        public ComponentRenderer getComponentRendererFor(Component source) {
          return null;
        }
        public boolean isIdDivsForced() { return false; }
      };
      Renderer renderer = Renderer.getInstance(container, pageTranslator, new EmptyURLBuilder(), null, globalSettings);
      // Add render decorator with helper methods
      VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, container);     
      ctx.put("r", vrdec);
      // Add empty static dir url - only used to not generate error messages
      ctx.put("chelpStaticDirUrl", "");
      // Create document for each language using the velocity context
      for (String langCode : languages) {
        Locale locale = I18nManager.getInstance().getLocaleOrNull(langCode);
        String relPagePath = langCode + "/" + bundleName + "/" + page;
        if (log.isDebug()) log.debug("Indexing help page with path::" + relPagePath);
View Full Code Here

      int i = 0;
     
      for (Iterator<MultipleSelectionElement> iterator = checkBoxes.iterator(); iterator.hasNext();) {
        MultipleSelectionElement checkbox = iterator.next();
        if (checkbox.isSelected(0)) {
          Context vcContext = ubcMan.getDemoContext(getTranslator(), isAdministrativeUser);
          validChange = true;
          FormItem formItem = formItems.get(i);
          if (formItem instanceof TextElement) {
            TextElement propertyField = (TextElement) formItem;
            String inputFieldValue = propertyField.getValue();
View Full Code Here

  private String getConfirmation(UserRequest ureq, String filename) {
    // grab standard text
    String confirmation = translate("conf.stdtext");
    config.set(TACourseNode.CONF_DROPBOX_CONFIRMATION, confirmation);
   
    Context c = new VelocityContext();
    Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
    c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
    c.put("email", identity.getUser().getProperty(UserConstants.EMAIL, getLocale()));
    c.put("filename", filename);
    Date now = new Date();
    Formatter f = Formatter.getInstance(ureq.getLocale());
    c.put("date", f.formatDate(now));
    c.put("time", f.formatTime(now));
   
    // update attempts counter for this user: one file - one attempts
    AssessableCourseNode acn = (AssessableCourseNode) node;
    acn.incrementUserAttempts(userCourseEnv);
       
View Full Code Here

          }
        } else {
          userDataArray.add(userLanguage);
        }

        Context vcContext = new VelocityContext();
        // set all properties as context
        ubcMan.setUserContext(identity, vcContext, isAdministrativeUser);
        // loop for each property configured in
        // src/serviceconfig/org/olat/_spring/olat_userconfig.xml -> Key:
        // org.olat.admin.user.bulkChange.UserBulkChangeStep00
View Full Code Here

          preferences.setLanguage(inputLanguage);
          user.setPreferences(preferences);
        }
      }

      Context vcContext = new VelocityContext();
      // set all properties as context
      setUserContext(identity, vcContext, isAdministrativeUser);
      // loop for each property configured in
      // src/serviceconfig/org/olat/_spring/olat_userconfig.xml -> Key:
      // org.olat.admin.user.bulkChange.UserBulkChangeStep00
View Full Code Here

TOP

Related Classes of org.apache.velocity.context.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.