void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) { String logMessage = (utils) ? Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_3, methodName, context.getComponent().getId())) : Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId())); String excMessage = (utils) ? Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_4, new Object[] { methodName, context.getComponent().getId(), e.getCause().getMessage() })) : Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_4a, new Object[] { methodName, context.getComponent().getId(), e.getCause().getMessage() })); MethodCallElement._log.error(logMessage, e); throw new FacesException(excMessage, e); }
private Object getInvokedObject(TemplateContext context) { if (utils) { return context.getRenderer().getUtils(); } else { return context.getRenderer(); } }
@Override public void toDocument(E data, OutputStream out) throws IOException, InvalidTemplateException { prepareDocument(); TemplateContext<E> context = contextFactory.createTemplateContext(this); context.bind(data); document.updateDynamicContent(context); document.writeAsOpenXML(out); }
void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) { MethodCallElement._log.error( Messages.getMessage( Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId()), e); throw new FacesException( Messages.getMessage( Messages.METHOD_CALL_ERROR_4a, new Object[] {methodName, context.getComponent().getId(), e.getCause().getMessage()}), e); }
public static Iterator<?> toIterator(TemplateContext ctx, Object o) { if (o == null) { return IteratorUtils.NULL_ITERATOR; } if (o instanceof Iterator<?>) { return (Iterator<?>) o; } if (o instanceof Iterable<?>) { return ((Iterable<?>) o).iterator(); } if (o instanceof Map<?, ?>) { return IteratorUtils.toIterator((Map<?, ?>) o); } if (isString(ctx, o)) { return IteratorUtils.toIterator(toString(ctx, o)); } if (isArray(ctx, o)) { return IteratorUtils.toIteratorArray(o); } if (o instanceof Enumeration<?>) { return Iterators.forEnumeration((Enumeration<?>) o); } ctx.warn("Cannot iterate over object of type " + o.getClass()); return IteratorUtils.NULL_ITERATOR; }
void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException { MethodCallElement._log.error( Messages.getMessage( Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId())); throw new MethodNotFoundException( Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName)); }
void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException { String logMessage = (utils) ? Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_5, methodName, context.getComponent().getId())) : Messages.getMessage( Messages.getMessage( Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId())); String excMessage = (utils) ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6, methodName)) : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName)); MethodCallElement._log.error(logMessage); throw new FacesException(excMessage); }
/** Coerces the object to the indicated type. */ public static Object coerce(TemplateContext ctx, Class<?> type, final Object o) { Object arg; if (o != null && type == o.getClass()) { arg = o; } else if (type == String.class) { arg = Types.toString(ctx, o); } else if (type == int.class || type == Integer.class) { arg = Types.toInteger(ctx, o); } else if (type == long.class || type == Long.class) { arg = Types.toLong(ctx, o); } else if (type == float.class || type == Float.class || type == double.class || type == Double.class) { arg = Types.toDouble(ctx, o); } else if (type == boolean.class || type == Boolean.class) { arg = Types.toBoolean(ctx, o); } else if (type == Iterator.class) { arg = Types.toIterator(ctx, o); } else { if (o == null) { arg = null; } else { final Converter<Object, Object> converter = ctx.getConverter(o.getClass(), type); if (converter == null) { arg = o; } else { try { arg = converter.convert(o); } catch (ConverterException e) { ctx.warn("Conversion error", e); return null; } } } } return arg; }
@Override @Nullable public Query parse(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); TemplateContext templateContext = parse(parser, QUERY, PARAMS); ExecutableScript executable = this.scriptService.executable( "mustache", templateContext.template(), templateContext.params()); BytesReference querySource = (BytesReference) executable.run(); XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource); try { final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParser); context.reset(qSourceParser); Query result = context.parseInnerQuery(); parser.nextToken(); return result; } finally { qSourceParser.close(); } }
@Override public void processNull( TemplateExecutionEnvironment environment, SNodeReference templateSwitch, TemplateContext context) { SNode generatorMessage = RuleUtil.getSwitch_NullInputMessage(mySwitch); if (generatorMessage != null) { GeneratorUtilEx.processGeneratorMessage( generatorMessage, context.getInput(), templateSwitch.resolve(MPSModuleRepository.getInstance()), null, environment.getGenerator()); } }
public static void setHighlighter(Editor editor, TemplateContext templateContext) { SyntaxHighlighter baseHighlighter = null; for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) { if (templateContext.isEnabled(type)) { baseHighlighter = type.createHighlighter(); if (baseHighlighter != null) break; } } if (baseHighlighter == null) { baseHighlighter = new PlainSyntaxHighlighter(); } SyntaxHighlighter highlighter = createTemplateTextHighlighter(baseHighlighter); ((EditorEx) editor) .setHighlighter( new LexerEditorHighlighter( highlighter, EditorColorsManager.getInstance().getGlobalScheme())); }
public void clearTemplateContext() { templateContext.clearTemplateContext(); }
// verifies that the correct context was popped public void leaveTemplateContextChecked(String s) { templateContext.leaveTemplateContextChecked(s); }
public void leaveTemplateContext() { templateContext.leaveTemplateContext(); }
public void enterTemplateContext(String s) { templateContext.enterTemplateContext(s); }
public String getTemplateContextString() { return templateContext.getTemplateContextString(); }
@Override public Collection<SNode> applyDefault( TemplateExecutionEnvironment environment, SNodeReference templateSwitch, String mappingName, TemplateContext context) throws GenerationException { SNode defaultConsequence = RuleUtil.getSwitchDefaultConsequence(mySwitch); if (defaultConsequence == null) { SNodeReference modifies = getModifiesSwitch(); if (modifies == null) { return null; } TemplateSwitchMapping switchMapping = environment.getGenerator().getSwitch(modifies); if (switchMapping == null) { return null; } return switchMapping.applyDefault(environment, templateSwitch, mappingName, context); } List<SNode> collection = new ArrayList<SNode>(); try { List<Pair<SNode, String>> nodeAndMappingNamePairs = GeneratorUtilEx.getTemplateNodesFromRuleConsequence( defaultConsequence, context.getInput(), templateSwitch.resolve(MPSModuleRepository.getInstance()), environment.getReductionContext(), environment.getGenerator()); if (nodeAndMappingNamePairs == null) { environment .getGenerator() .showErrorMessage( context.getInput(), templateSwitch.resolve(MPSModuleRepository.getInstance()), defaultConsequence, "error processing $SWITCH$/default"); return null; } for (Pair<SNode, String> nodeAndMappingNamePair : nodeAndMappingNamePairs) { SNode altTemplateNode = nodeAndMappingNamePair.o1; String innerMappingName = nodeAndMappingNamePair.o2 != null ? nodeAndMappingNamePair.o2 : mappingName; try { TemplateProcessor templateProcessor = new TemplateProcessor(environment.getGenerator(), environment.getReductionContext()); collection.addAll(templateProcessor.apply(innerMappingName, altTemplateNode, context)); } catch (TemplateProcessingFailureException e) { environment .getGenerator() .showErrorMessage( context.getInput(), templateSwitch.resolve(MPSModuleRepository.getInstance()), "error processing template fragment"); } } } catch (AbandonRuleInputException e) { // it's ok. just ignore } return collection; }
/** * Test that the {@link Accessor} configured for {@link A} will be returned when an accessor for * {@link C} is wanted. */ public void testSuperinterfaceAccessors() { templateContext.addAccessor(A.class, new ReflectionAccessor()); assertEquals("Accessor for A", true, templateContext.getAccessor(C.class) != null); }
public void applyContext(final TemplateContext context) { myTemplateContext = context.createCopy(); }
void update(TemplateContext context, Object[] parameters) { arguments[0] = context.getFacesContext(); arguments[1] = context.getComponent(); System.arraycopy(parameters, 0, arguments, 2, parameters.length); }