/** * An object is <em>strict object</em> if is not value type, that is, there is no converter for it. * * @param object object instance to check. * @return true if <code>object</code> is <em>strict object</em>. */ private boolean isStrictObject(Object object) { return !ConverterRegistry.hasType(object.getClass()); } }
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object.");
/** * Execute TITLE operator. Uses property path to extract content value, convert it to string and set <em>title</em> * attribute. * * @param element context element, unused, * @param scope scope object, * @param propertyPath property path, * @param arguments optional arguments, unused. * @return always returns null for void. * @throws TemplateException if requested content value is undefined. */ @Override protected Object doExec(Element element, Object scope, String propertyPath, Object... arguments) throws TemplateException { if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object."); } Object value = content.getObject(scope, propertyPath); if (value == null) { return null; } if (!(value instanceof String)) { throw new TemplateException("Invalid element |%s|. TITLE operand should be string.", element); } return new AttrImpl("title", (String) value); } }
/** * Execute HREF operator. Uses property path to extract content value, convert it to string and set <em>href</em> attribute. * * @param element context element, unused, * @param scope scope object, * @param propertyPath property path, * @param arguments optional arguments, unused. * @return always returns null for void. * @throws TemplateException if requested content value is undefined. */ @Override protected Object doExec(Element element, Object scope, String propertyPath, Object... arguments) throws TemplateException { if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object."); } Object value = content.getObject(scope, propertyPath); if (value == null) { return null; } if (value instanceof URL) { value = ((URL) value).toExternalForm(); } if (!(value instanceof String)) { throw new TemplateException("Invalid element |%s|. HREF operand should be URL or string.", element); } return new AttrImpl("href", (String) value); } }
return format.format(value); if (!Types.isPrimitiveLike(value) && !ConverterRegistry.hasType(value.getClass())) { throw new TemplateException("Value |%s#%s| should be a primitive like but is |%s|.", scope.getClass(), propertyPath, value.getClass());
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object."); Object object = this.content.getObject(scope, propertyPath); if (object != null) { if (!ConverterRegistry.hasType(object.getClass())) { throw new TemplateException("Invalid element |%s|. Operand for VALUE operator without formatter should be convertible to string.", element);
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object.");
/** * Execute LIST operator. Extract content list then repeat context element first child for every list item. * * @param element context element, * @param scope scope object, * @param propertyPath property path, * @param arguments optional arguments, not used. * @return always returns null to signal full processing. * @throws IOException if underlying writer fails to write. * @throws TemplateException if element has no children or content list is undefined. */ @Override protected Object doExec(Element element, Object scope, String propertyPath, Object... arguments) throws IOException, TemplateException { if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object."); } Element itemTemplate = element.getFirstChild(); if (itemTemplate == null) { throw new TemplateException("Invalid list element |%s|. Missing item template.", element); } for (Object item : content.getIterable(scope, propertyPath)) { serializer.writeItem(itemTemplate, item); } return null; } }
/** * Test if method formal parameters designates a strict object, that is, is not primitive, array, collection or map. * * @param formalParameters method formal parameters list. * @return true if formal parameters designates a strict object. */ private static boolean isObject(Type[] formalParameters) { if (formalParameters.length != 1) { return false; } final Type type = formalParameters[0]; if (!(type instanceof Class)) { return false; } if (Types.isPrimitive(type)) { return false; } if (Types.isArrayLike(type)) { return false; } if (Types.isMap(type)) { return false; } if (ConverterRegistry.hasType(type)) { return false; } return true; }
/** * Execute TEXT operator. Uses property path to extract content value, convert it to string and set element text content. * Note that this operator operates on element without children. Failing to obey this constraint rise templates exception; * anyway, validation tool catches this condition. * * @param element context element, * @param scope scope object, * @param propertyPath property path, * @param arguments optional arguments, {@link Format} instance in this case. * @return always returns null to signal full processing. * @throws IOException if underlying writer fails to write. * @throws TemplateException if context element has children or requested content value is undefined. */ @Override protected Object doExec(Element element, Object scope, String propertyPath, Object... arguments) throws IOException, TemplateException { if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object."); } if (element.hasChildren()) { throw new TemplateException("Illegal TEXT operator on element with children."); } Format format = (Format) arguments[0]; String text = content.getString(scope, propertyPath, format); if (text != null) { serializer.writeTextContent(text); } return null; } }
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object.");
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object.");
if (!propertyPath.equals(".") && ConverterRegistry.hasType(scope.getClass())) { throw new TemplateException("Operand is property path but scope is not an object.");
throw new BugError("Generic value types are not supported."); if (ConverterRegistry.hasType(type)) { return ConverterRegistry.getConverter().asObject(value, (Class<T>) type);
if (value instanceof String || ConverterRegistry.hasType(value.getClass())) { writeString(converter.asString(value)); return;
return new CollectionValue(converter, type); if (type instanceof Class<?> && ConverterRegistry.hasType(type)) { return new PrimitiveValue(converter, (Class<?>) type);