private static IStandardExpression parseAttributeExpression(final ITemplateContext context, final String attributeValue) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); return expressionParser.parseExpression(context, attributeValue); }
@Override protected void writeUnresolved(final Writer writer) throws IOException { this.context.getConfiguration().getTemplateManager().process(this.templateModel, this.context, writer); }
@Override protected IInliner getInliner(final ITemplateContext context, final StandardInlineMode inlineMode) { switch (inlineMode) { case NONE: return NoOpInliner.INSTANCE; case HTML: return new StandardHTMLInliner(context.getConfiguration()); case TEXT: return new StandardTextInliner(context.getConfiguration()); case JAVASCRIPT: return new StandardJavaScriptInliner(context.getConfiguration()); case CSS: return new StandardCSSInliner(context.getConfiguration()); default: throw new TemplateProcessingException( "Invalid inline mode selected: " + inlineMode + ". Allowed inline modes in template mode " + getTemplateMode() + " are: " + "\"" + StandardInlineMode.HTML + "\", \"" + StandardInlineMode.TEXT + "\", " + "\"" + StandardInlineMode.JAVASCRIPT + "\", \"" + StandardInlineMode.CSS + "\" and " + "\"" + StandardInlineMode.NONE + "\""); } }
@Override protected IInliner getInliner(final ITemplateContext context, final StandardInlineMode inlineMode) { switch (inlineMode) { case NONE: return NoOpInliner.INSTANCE; case XML: return new StandardXMLInliner(context.getConfiguration()); case TEXT: return new StandardTextInliner(context.getConfiguration()); default: throw new TemplateProcessingException( "Invalid inline mode selected: " + inlineMode + ". Allowed inline modes in template mode " + getTemplateMode() + " are: " + "\"" + StandardInlineMode.XML + "\", \"" + StandardInlineMode.TEXT + "\", " + "\"" + StandardInlineMode.NONE + "\""); } }
@Override protected String resolveText() { final Writer stringWriter = new FastStringWriter(); this.context.getConfiguration().getTemplateManager().process(this.templateModel, this.context, stringWriter); return stringWriter.toString(); }
@Override protected IInliner getInliner(final ITemplateContext context, final StandardInlineMode inlineMode) { final TemplateMode templateMode = getTemplateMode(); switch (inlineMode) { case NONE: return NoOpInliner.INSTANCE; case TEXT: if (templateMode == TemplateMode.TEXT) { return new StandardTextInliner(context.getConfiguration()); } break; // will output exception case JAVASCRIPT: if (templateMode == TemplateMode.JAVASCRIPT) { return new StandardJavaScriptInliner(context.getConfiguration()); } break; // will output exception case CSS: if (templateMode == TemplateMode.CSS) { return new StandardCSSInliner(context.getConfiguration()); } break; // will output exception } throw new TemplateProcessingException( "Invalid inline mode selected: " + inlineMode + ". Allowed inline modes in template mode " + getTemplateMode() + " are: \"" + getTemplateMode() + "\" and " + "\"" + StandardInlineMode.NONE + "\""); }
text = new LazyEscapingCharSequence(context.getConfiguration(), templateMode, input); } else { text = new LazyEscapingCharSequence(context.getConfiguration(), templateMode, expressionResult);
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); final Object value = expression.execute(context); return EvaluationUtils.evaluateAsBoolean(value); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression switchExpression = expressionParser.parseExpression(context, attributeValue); structureHandler.setLocalVariable(SWITCH_VARIABLE_NAME, new SwitchStructure(switchExpression)); }
@Override protected boolean isVisible( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); final Object value = expression.execute(context); return !EvaluationUtils.evaluateAsBoolean(value); }
@Override protected final void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration()); final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue); validateSelectionValue(context, tag, attributeName, attributeValue, expression); final Object newSelectionTarget = expression.execute(context); final Map<String,Object> additionalLocalVariables = computeAdditionalLocalVariables(context, tag, attributeName, attributeValue, expression); if (additionalLocalVariables != null && additionalLocalVariables.size() > 0) { for (final Map.Entry<String,Object> variableEntry : additionalLocalVariables.entrySet()) { structureHandler.setLocalVariable(variableEntry.getKey(), variableEntry.getValue()); } } structureHandler.setSelectionTarget(newSelectionTarget); }
@Override public void doProcessTemplateStart( final ITemplateContext context, final ITemplateStart templateStart, final ITemplateBoundariesStructureHandler structureHandler) { switch (getTemplateMode()) { case HTML: structureHandler.setInliner(new StandardHTMLInliner(context.getConfiguration())); break; case XML: structureHandler.setInliner(new StandardXMLInliner(context.getConfiguration())); break; case TEXT: structureHandler.setInliner(new StandardTextInliner(context.getConfiguration())); break; case JAVASCRIPT: structureHandler.setInliner(new StandardJavaScriptInliner(context.getConfiguration())); break; case CSS: structureHandler.setInliner(new StandardCSSInliner(context.getConfiguration())); break; case RAW: // No inliner for RAW template mode. We could use the Raw, but anyway it would be of no use // because in RAW mode the text processor that looks for the inliner to apply does not exist... structureHandler.setInliner(null); break; default: throw new TemplateProcessingException( "Unrecognized template mode: " + getTemplateMode() + ", cannot initialize inlining!"); } }
Validate.notNull(this.context.getTemplateMode(), "Template Mode returned by context cannot be null"); this.configuration = context.getConfiguration(); Validate.notNull(this.configuration, "Engine Configuration returned by context cannot be null"); Validate.notNull(this.configuration.getElementDefinitions(), "Element Definitions returned by the Engine Configuration cannot be null");
private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final IText text) { final TemplateManager templateManager = context.getConfiguration().getTemplateManager(); final TemplateModel templateModel = templateManager.parseString( context.getTemplateData(), text.getText(), text.getLine(), text.getCol(), this.templateMode, true); if (!this.writeTextsToOutput) { final Writer stringWriter = new FastStringWriter(50); templateManager.process(templateModel, context, stringWriter); return stringWriter.toString(); } // If we can directly write to output (and text is an IText), we will use a LazyProcessingCharSequence return new LazyProcessingCharSequence(context, templateModel); }
private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final ICDATASection cdataSection) { final TemplateManager templateManager = context.getConfiguration().getTemplateManager(); /* * Notice we are ONLY processing the contents of the CDATA, because we know the target inlining * mode will not understand the CDATA (it will be textual) and we don't want it to mess around with * the CDATA's prefix and suffix. * * Note this will only be executed in markup modes (textual modes never fire "handleCDATASection" events), * so we are safe assuming the sizes of CDATA prefixes and suffixes in HTML/XML. */ final TemplateModel templateModel = templateManager.parseString( context.getTemplateData(), cdataSection.getContent(), cdataSection.getLine(), cdataSection.getCol() + 9, // +9 because of the prefix this.templateMode, true); final Writer stringWriter = new FastStringWriter(50); templateManager.process(templateModel, context, stringWriter); return stringWriter.toString(); }
private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final IComment comment) { final TemplateManager templateManager = context.getConfiguration().getTemplateManager(); /* * Notice we are ONLY processing the contents of the Comment, because we know the target inlining * mode will not understand the Comment (it will be textual) and we don't want it to mess around with * the Comment's prefix and suffix. * * Note this will only be executed in markup modes (textual modes never fire "handleComment" events), * so we are safe assuming the sizes of Comment prefixes and suffixes in HTML/XML. */ final TemplateModel templateModel = templateManager.parseString( context.getTemplateData(), comment.getContent(), comment.getLine(), comment.getCol() + 4, // +4 because of the prefix this.templateMode, true); final Writer stringWriter = new FastStringWriter(50); templateManager.process(templateModel, context, stringWriter); return stringWriter.toString(); }
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration());
final TemplateManager templateManager = context.getConfiguration().getTemplateManager();
private static Object computeFragment(final ITemplateContext context, final String input) { final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(context.getConfiguration());
final TemplateManager templateManager = context.getConfiguration().getTemplateManager();