All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.template.xhtml.HrefOperator Maven / Gradle / Ivy

Go to download

Reference implementation for j(s)-lib template API, declarative, natural and based on X(HT)ML language.

The newest version!
package js.template.xhtml;

import java.net.URL;

import js.converter.ConverterRegistry;
import js.dom.Element;
import js.template.TemplateException;

/**
 * Set href attribute value.
 * 
 * 
 *  <a data-href="url">Follow the link...</a>
 * 
* * Operand is the property path used to get content value. * * @author Iulian Rotaru */ final class HrefOperator extends Operator { /** Dynamic content reference. */ private Content content; /** * Construct HREF operator instance. * * @param content dynamic content. */ HrefOperator(Content content) { this.content = content; } /** * Execute HREF operator. Uses property path to extract content value, convert it to string and set href 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); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy