Example usage for org.apache.commons.jelly JellyContext registerTagLibrary

List of usage examples for org.apache.commons.jelly JellyContext registerTagLibrary

Introduction

In this page you can find the example usage for org.apache.commons.jelly JellyContext registerTagLibrary.

Prototype

public void registerTagLibrary(String namespaceURI, String className) 

Source Link

Document

Registers the given tag library class name against the given namespace URI.

Usage

From source file:com.cyclopsgroup.waterview.navigator.impl.DefaultNavigatorHome.java

/**
 * Overwrite or implement method in DefaultNavigatorHome
 *
 * @see org.apache.avalon.framework.activity.Initializable#initialize()
 *//*from w  w  w .  j a v a  2  s.  c om*/
public void initialize() throws Exception {
    pathIndex = new Hashtable();
    parentPathIndex = new MultiHashMap();
    pageIndex = new Hashtable();

    rootNode = new DefaultNavigatorNode(this, "/", null);
    rootNode.getAttributes().set(DefaultNavigatorNode.PAGE_NAME, "/Index.jelly");
    rootNode.getAttributes().set(DefaultNavigatorNode.TITLE_NAME, "Start");
    addNode(rootNode);

    JellyContext jc = new JellyContext();
    jc.setVariable(getClass().getName(), this);
    jc.registerTagLibrary("http://waterview.cyclopsgroup.com/navigator", new NavigatorTagLibrary());
    for (Enumeration en = getClass().getClassLoader()
            .getResources("META-INF/cyclopsgroup/waterview-navigation.xml"); en.hasMoreElements();) {
        URL resource = (URL) en.nextElement();
        getLogger().info("Reading navigation from " + resource);
        jc.runScript(resource, XMLOutput.createDummyXMLOutput());
    }
    populateNode(rootNode);
}

From source file:com.cyclopsgroup.waterview.navigator.impl.DefaultNavigatorService.java

/**
 * Overwrite or implement method in DefaultNavigatorHome
 *
 * @see org.apache.avalon.framework.activity.Initializable#initialize()
 *//*  w ww. java  2 s . c o  m*/
public void initialize() throws Exception {
    pathIndex = new Hashtable();
    parentPathIndex = new MultiHashMap();
    pageIndex = new Hashtable();

    rootNode = new DefaultNavigatorNode(this, "/", null);
    rootNode.getAttributes().set(DefaultNavigatorNode.PAGE_NAME, "/Index.jelly");
    rootNode.getAttributes().set(DefaultNavigatorNode.TITLE_NAME, "%waterview.navigation.start");
    addNode(rootNode);

    JellyContext jc = new JellyContext();
    jc.setVariable(DefaultNavigatorService.class.getName(), this);
    jc.registerTagLibrary("http://waterview.cyclopsgroup.com/navigator", new NavigatorTagLibrary());
    for (Enumeration en = getClass().getClassLoader().getResources(path); en.hasMoreElements();) {
        URL resource = (URL) en.nextElement();
        getLogger().info("Reading navigation from " + resource);
        jc.runScript(resource, XMLOutput.createDummyXMLOutput());
    }
    populateNode(rootNode);
}

From source file:com.cyclopsgroup.waterview.jelly.JellyEngine.java

/**
 * Init global context//www. j a v a2s . c  om
 *
 * @throws Exception Throw it out
 */
private void initGlobalContext() throws Exception {
    JellyContext jc = new JellyContext();
    jc.setVariable(SERVICE_MANAGER, serviceManager);
    jc.setVariable(ROLE, this);
    TagLibrary deftaglib = new TagLibrary();
    deftaglib.registerPackage((TagPackage) Class.forName(DEFINITION_TAG_PACKAGE).newInstance());
    jc.registerTagLibrary(DEFINITION_TAGLIB_URL, deftaglib);

    Enumeration e = getClass().getClassLoader().getResources("META-INF/cyclopsgroup/waterview.xml");
    while (e.hasMoreElements()) {
        URL resource = (URL) e.nextElement();
        getLogger().info("Load definition from " + resource);
        jc.runScript(resource, XMLOutput.createDummyXMLOutput());
    }

    globalContext = new JellyContext();
    globalContext.setVariables(initProperties);
    for (Iterator i = tagLibraries.keySet().iterator(); i.hasNext();) {
        String uri = (String) i.next();
        TagLibrary taglib = (TagLibrary) tagLibraries.get(uri);
        globalContext.registerTagLibrary(uri, taglib);
    }
    globalContext.setVariable(SERVICE_MANAGER, serviceManager);
    globalContext.setVariable(ROLE, this);
}

From source file:org.codehaus.nanning.definition.AspectRepository.java

/**
 * Merges all defined aspect-repositories of the xml-file into this one, at least one needs to be defined.
 *
 * @param resource/*w  w w .j  ava  2s.  co  m*/
 * @throws org.codehaus.nanning.definition.ConfigureException
 */
public void configure(URL resource) throws ConfigureException {
    JellyContext context = new JellyContext();
    try {
        context.registerTagLibrary(AspectTagLibrary.TAG_LIBRARY_URI, new AspectTagLibrary());
        context.registerTagLibrary("", new AspectTagLibrary());
        XMLOutput xmlOutput = XMLOutput.createXMLOutput(new ByteArrayOutputStream());
        context.runScript(resource, xmlOutput);
    } catch (Exception e) {
        throw new ConfigureException(e);
    }

    Collection aspectRepositories = AspectTagLibrary.findDefinedRepositories(context);
    Iterator iterator = aspectRepositories.iterator();
    if (!iterator.hasNext()) {
        throw new ConfigureException("No aspect-repository defined.");
    }
    while (iterator.hasNext()) {
        AspectRepository configuredRepository = (AspectRepository) iterator.next();
        this.interceptorDefinitions.putAll(configuredRepository.interceptorDefinitions);
        this.aspectClasses.putAll(configuredRepository.aspectClasses);
        this.aspectDefinitions.putAll(configuredRepository.aspectDefinitions);
    }
}