private void displayMainAdminPage(HttpServletRequest request, HttpServletResponse response) { Template template = velocityEngine.getTemplate("templates/admin.vm"); VelocityContext context = new VelocityContext(); EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeHtmlReference()); ec.attachToContext(context); context.put("version", NcwmsApplicationServlet.getVersion()); context.put("catalogue", catalogue); context.put("config", catalogue.getConfig()); context.put("TimeUtils", TimeUtils.class); try { template.merge(context, response.getWriter()); } catch (Exception e) { e.printStackTrace(); } }
private void displayStatusPage(HttpServletRequest request, HttpServletResponse response) { String datasetId = request.getParameter("dataset"); if (StringUtils.isBlank(datasetId)) { throw new IllegalArgumentException( "Must supply the \"dataset\" parameter to view status"); } DatasetConfig dataset = catalogue.getConfig().getDatasetInfo(datasetId); Template template = velocityEngine.getTemplate("templates/dataset_status.vm"); VelocityContext context = new VelocityContext(); EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeHtmlReference()); ec.attachToContext(context); context.put("dataset", dataset); try { template.merge(context, response.getWriter()); } catch (Exception e) { e.printStackTrace(); } }
private void displayEditVariablesPage(HttpServletRequest request, HttpServletResponse response) { String datasetId = request.getParameter("dataset"); if (StringUtils.isBlank(datasetId)) { throw new IllegalArgumentException( "Must supply the \"dataset\" parameter to edit variables"); } DatasetConfig dataset = catalogue.getConfig().getDatasetInfo(datasetId); Template template = velocityEngine.getTemplate("templates/edit_variables.vm"); VelocityContext context = new VelocityContext(); EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeHtmlReference()); ec.attachToContext(context); context.put("dataset", dataset); context.put("paletteNames", ColourPalette.getPredefinedPalettes()); try { template.merge(context, response.getWriter()); } catch (Exception e) { e.printStackTrace(); } }
private Set<String> prepareVelocityTemplate(String template) throws PIPException { VelocityContext vctx = new VelocityContext(); EventCartridge vec = new EventCartridge(); VelocityParameterReader reader = new VelocityParameterReader(); vec.addEventHandler(reader); vec.attachToContext(vctx); try { Velocity.evaluate(vctx, new StringWriter(), "LdapResolver", template); } catch (ParseErrorException pex) { throw new PIPException("Velocity template preparation failed", pex); } catch (MethodInvocationException mix) { throw new PIPException("Velocity template preparation failed", mix); } catch (ResourceNotFoundException rnfx) { throw new PIPException("Velocity template preparation failed", rnfx); } if (this.logger.isTraceEnabled()) { this.logger.trace("(" + id + ") " + template + " with parameters " + reader.parameters); } return reader.parameters; }
private String evaluateVelocityTemplate(String template, final Map<String, PIPRequest> templateParameters, final PIPFinder pipFinder) throws PIPException { StringWriter out = new StringWriter(); VelocityContext vctx = new VelocityContext(); EventCartridge vec = new EventCartridge(); VelocityParameterWriter writer = new VelocityParameterWriter(pipFinder, templateParameters); vec.addEventHandler(writer); vec.attachToContext(vctx); try { Velocity.evaluate(vctx, out, "LdapResolver", template); } catch (ParseErrorException pex) { throw new PIPException("Velocity template evaluation failed", pex); } catch (MethodInvocationException mix) { throw new PIPException("Velocity template evaluation failed", mix); } catch (ResourceNotFoundException rnfx) { throw new PIPException("Velocity template evaluation failed", rnfx); } this.logger.warn("(" + id + ") " + " template yields " + out.toString()); return out.toString(); }
private void writeContentFromTemplate(final Writer writer) { // to escape java final EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeJavaReference()); final VelocityContext context = new VelocityContext(); context.attachEventCartridge(ec); context.put("strict", overriddenParameters.isStrict()); context.put("featureFile", featureFileLocation); context.put("plugins", createPluginStrings()); context.put("tags", overriddenParameters.getTags()); context.put("monochrome", overriddenParameters.isMonochrome()); context.put("cucumberOutputDir", normalizePathSeparator(config.getCucumberOutputDir())); context.put("glue", overriddenParameters.getGlue()); context.put("className", FilenameUtils.removeExtension(outputFileName)); context.put("packageName", config.getPackageName()); context.put("feature",parsedFeature); velocityTemplate.merge(context, writer); }
private void writeContentFromTemplate(final Writer writer) { // to escape java final EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeJavaReference()); final VelocityContext context = new VelocityContext(); context.attachEventCartridge(ec); context.put("strict", overriddenParameters.isStrict()); context.put("featureFile", featureFileLocation); context.put("plugins", createPluginStrings()); context.put("tags", overriddenParameters.getTags()); context.put("monochrome", overriddenParameters.isMonochrome()); context.put("cucumberOutputDir", normalizePathSeparator(config.getCucumberOutputDir())); context.put("glue", overriddenParameters.getGlue()); context.put("className", FilenameUtils.removeExtension(outputFileName)); context.put("packageName", config.getPackageName()); context.put("feature", parsedFeature); context.put("scenario", parsedScenario); velocityTemplate.merge(context, writer); }
@Override public void run() { Template template = TemplateLoader.getInstance().getTemplate( templateType); VelocityContext velocityContext = new VelocityContext(); velocityContext.put(templateType.getContextName(), context); try { EventCartridge cartridge = new EventCartridge(); cartridge.addEventHandler(new EscapeXmlReference()); cartridge.attachToContext(velocityContext); Writer writer = new OutputStreamWriter(new FileOutputStream( file), ENCODING); template.merge(velocityContext, writer); writer.flush(); writer.close(); XmlFormatter formatter = new XmlFormatter(); formatter.format(file); } catch (Exception e) { e.printStackTrace(); } }
/** * This method is requesting the front page since that is all this servlet * does (apart from config initialisation and sharing). Return it here. */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { /* HTTP 1.1 */ response.setHeader("Cache-Control", "no-cache"); /* HTTP 1.0 */ response.setHeader("Pragma", "no-cache"); /* Prevents caching at the proxy server */ response.setDateHeader("Expires", 0); /* * Just return the front page. If we want some more (dynamic) web pages * available here, we need to do some extra handling of what the URL * actually says */ Template template = velocityEngine.getTemplate("templates/index.vm"); VelocityContext context = new VelocityContext(); EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeHtmlReference()); ec.attachToContext(context); context.put("version", getVersion()); context.put("catalogue", catalogue); context.put("config", catalogue.getConfig()); context.put("GISUtils", GISUtils.class); context.put("supportedImageFormats", ImageFormat.getSupportedMimeTypes()); template.merge(context, response.getWriter()); }
@Override public void run() { Template template = TemplateLoader.getInstance().getTemplate( templateType); VelocityContext velocityContext = new VelocityContext(); velocityContext.put(templateType.getContextName(), context); try { EventCartridge cartridge = new EventCartridge(); cartridge.addEventHandler(new EscapeXmlReference()); cartridge.attachToContext(velocityContext); // write the context to a cache StringWriter cacheWriter = new StringWriter(); template.merge(velocityContext, cacheWriter); cacheWriter.flush(); cacheWriter.close(); StringReader cacheReader = new StringReader(cacheWriter .toString()); // write the formatted output from the cache XmlFormatter formatter = new XmlFormatter(); formatter.format(cacheReader, writer); } catch (Exception e) { e.printStackTrace(); } }
private Set<String> prepareVelocityTemplate(String template) throws PIPException { VelocityContext vctx = new VelocityContext(); EventCartridge vec = new EventCartridge(); VelocityParameterReader reader = new VelocityParameterReader(); vec.addEventHandler(reader); vec.attachToContext(vctx); try { Velocity.evaluate(vctx, new StringWriter(), "LdapResolver", template); } catch (ParseErrorException pex) { throw new PIPException( "Velocity template preparation failed",pex); } catch (MethodInvocationException mix) { throw new PIPException( "Velocity template preparation failed",mix); } catch (ResourceNotFoundException rnfx) { throw new PIPException( "Velocity template preparation failed",rnfx); } if (this.logger.isTraceEnabled()) { this.logger.trace("(" + id + ") " + template + " with parameters " + reader.parameters); } return reader.parameters; }
private String evaluateVelocityTemplate(String template, final Map<String,PIPRequest> templateParameters, final PIPEngine pipEngine, final PIPFinder pipFinder) throws PIPException { StringWriter out = new StringWriter(); VelocityContext vctx = new VelocityContext(); EventCartridge vec = new EventCartridge(); VelocityParameterWriter writer = new VelocityParameterWriter( pipEngine, pipFinder, templateParameters); vec.addEventHandler(writer); vec.attachToContext(vctx); try { Velocity.evaluate(vctx, out, "LdapResolver", template); } catch (ParseErrorException pex) { throw new PIPException( "Velocity template evaluation failed",pex); } catch (MethodInvocationException mix) { throw new PIPException( "Velocity template evaluation failed",mix); } catch (ResourceNotFoundException rnfx) { throw new PIPException( "Velocity template evaluation failed",rnfx); } this.logger.warn("(" + id + ") " + " template yields " + out.toString()); return out.toString(); }
/** * Wraps {@link EdalException}s in an XML wrapper and returns them. * * @param exception * The exception to handle * @param httpServletResponse * The {@link HttpServletResponse} object to write to * @param v130 * Whether this should be handled as a WMS v1.3.0 exception * @throws IOException * If there is a problem writing to the output stream */ protected void handleWmsException(EdalException exception, HttpServletResponse httpServletResponse, boolean v130) throws IOException { if (exception instanceof EdalLayerNotFoundException) { httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); } httpServletResponse.setContentType("text/xml"); StackTraceElement[] stackTrace = exception.getStackTrace(); StackTraceElement element = stackTrace[0]; StringBuilder warningMessage = new StringBuilder( "Wms Exception caught: \"" + exception.getMessage() + "\" from:" + element.getClassName() + ":" + element.getLineNumber()); if (exception.getCause() != null) { Throwable cause = exception.getCause(); warningMessage.append(" Cause: " + cause.getMessage()); } log.warn(warningMessage.toString()); VelocityContext context = new VelocityContext(); EventCartridge ec = new EventCartridge(); ec.addEventHandler(new EscapeXmlReference()); ec.attachToContext(context); context.put("exception", exception); if (exception.getCause() != null) { context.put("cause", exception.getCause()); } Template template; if (v130) { template = velocityEngine.getTemplate("templates/exception-1.3.0.vm"); } else { template = velocityEngine.getTemplate("templates/exception-1.1.1.vm"); } template.merge(context, httpServletResponse.getWriter()); }
public void listenToContext(Context ctx) { EventCartridge ec = new EventCartridge(); ec.addEventHandler(this); ec.attachToContext(ctx); }