/** * Searches up the parent hierarchy from the given tag * for a Tag of the given type * * @param from the tag to start searching from * @param tagClass the type of the tag to find * @return the tag of the given type or null if it could not be found */ public static Tag findAncestorWithClass(Tag from, Class tagClass) { // we could implement this as // return findAncestorWithClass(from,Collections.singleton(tagClass)); // but this is so simple let's save the object creation for now while (from != null) { if (tagClass.isInstance(from)) { return from; } from = from.getParent(); } return null; }
/** * Actually invoke the tag body to generate the SAX events * * @throws SAXException - * Any SAX exception, possibly wrapping another exception. */ private void doInvokeBody() throws SAXException { try { if (this.shouldParseBody()) { XMLReader anXMLReader = XMLReaderFactory.createXMLReader(); anXMLReader.setContentHandler(this.xmlOutput); anXMLReader.setProperty(LEXICAL_HANDLER_PROPERTY,this.xmlOutput); StringWriter writer = new StringWriter(); this.tag.invokeBody(XMLOutput.createXMLOutput(writer)); Reader reader = new StringReader(writer.toString()); anXMLReader.parse(new InputSource(reader)); } else { this.tag.invokeBody(this.xmlOutput); } } catch (Exception ex) { throw new SAXException(ex); } }
/** * Helper method to determin if nested body needs to be parsed by (an * xml parser, i.e. its only text) to generate SAX events or not * * @return True if tag body should be parsed or false if invoked only * @throws JellyTagException */ private boolean shouldParseBody() throws JellyTagException { boolean result = false; // check to see if we need to parse the body or just invoke it Script bodyScript = this.tag.getBody(); if (bodyScript instanceof ScriptBlock) { ScriptBlock scriptBlock = (ScriptBlock) bodyScript; List scriptList = scriptBlock.getScriptList(); for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) { Script script = (Script) iter.next(); if (script instanceof StaticTagScript) { result = true; break; } } } return result; }
tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output);
/** * Compiles a newly created tag if required, sets its parent and body. */ protected void configureTag(Tag tag, JellyContext context) throws JellyException { if (tag instanceof CompilableTag) { ((CompilableTag) tag).compile(); } Tag parentTag = null; if ( parent != null ) { parentTag = parent.getTag(context); } tag.setParent( parentTag ); tag.setBody( tagBody ); if (tag instanceof NamespaceAwareTag) { NamespaceAwareTag naTag = (NamespaceAwareTag) tag; naTag.setNamespaceContext(getNamespaceContext()); } if (tag instanceof LocationAware) { applyLocation((LocationAware) tag); } }
return; tag.setContext(context); setContextURLs(context); tag.doTag(output); if (output != null) { output.flush();
tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output);
/** * Compiles a newly created tag if required, sets its parent and body. */ protected void configureTag(Tag tag, JellyContext context) throws JellyException { if (tag instanceof CompilableTag) { ((CompilableTag) tag).compile(); } Tag parentTag = null; if ( parent != null ) { parentTag = parent.getTag(context); } tag.setParent( parentTag ); tag.setBody( tagBody ); if (tag instanceof NamespaceAwareTag) { NamespaceAwareTag naTag = (NamespaceAwareTag) tag; naTag.setNamespaceContext(getNamespaceContext()); } if (tag instanceof LocationAware) { applyLocation((LocationAware) tag); } }
return; tag.setContext(context); setContextURLs(context); tag.doTag(output);
tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output);
/** * Compiles a newly created tag if required, sets its parent and body. */ protected void configureTag(Tag tag, JellyContext context) throws JellyException { if (tag instanceof CompilableTag) { ((CompilableTag) tag).compile(); } Tag parentTag = null; if ( parent != null ) { // if the parent script isn't a TagScript, parent is null. parentTag = (Tag)context.getVariable(PARENT_TAG); } tag.setParent( parentTag ); tag.setBody( tagBody ); if (tag instanceof NamespaceAwareTag) { NamespaceAwareTag naTag = (NamespaceAwareTag) tag; naTag.setNamespaceContext(getNamespaceContext()); } if (tag instanceof LocationAware) { applyLocation((LocationAware) tag); } }
return; tag.setContext(context); setContextURLs(context); tag.doTag(output);
/** * Searches up the parent hierarchy from the given tag * for a Tag of the given type * * @param from the tag to start searching from * @param tagClass the type of the tag to find * @return the tag of the given type or null if it could not be found */ public static Tag findAncestorWithClass(Tag from, Class tagClass) { // we could implement this as // return findAncestorWithClass(from,Collections.singleton(tagClass)); // but this is so simple let's save the object creation for now while (from != null) { if (tagClass.isInstance(from)) { return from; } from = from.getParent(); } return null; }
tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output);
/** * Compiles a newly created tag if required, sets its parent and body. */ protected void configureTag(Tag tag, JellyContext context) throws JellyException { if (tag instanceof CompilableTag) { ((CompilableTag) tag).compile(); } Tag parentTag = null; if ( parent != null ) { parentTag = parent.getTag(context); } tag.setParent( parentTag ); tag.setBody( tagBody ); if (tag instanceof NamespaceAwareTag) { NamespaceAwareTag naTag = (NamespaceAwareTag) tag; naTag.setNamespaceContext(getNamespaceContext()); } if (tag instanceof LocationAware) { applyLocation((LocationAware) tag); } }
tag.setContext(context); setContextURLs(context); tag.doTag(output); if (output != null) { output.flush();
/** * Searches up the parent hierarchy from the given tag * for a Tag of the given type * * @param from the tag to start searching from * @param tagClass the type of the tag to find * @return the tag of the given type or null if it could not be found */ public static Tag findAncestorWithClass(Tag from, Class tagClass) { // we could implement this as // return findAncestorWithClass(from,Collections.singleton(tagClass)); // but this is so simple let's save the object creation for now while (from != null) { if (tagClass.isInstance(from)) { return from; } from = from.getParent(); } return null; }
/** * Attempts to find a dynamically created tag that has been created since this * script was compiled */ protected Tag findDynamicTag(JellyContext context, StaticTag tag) throws JellyException { // lets see if there's a tag library for this URI... TagLibrary taglib = context.getTagLibrary( tag.getUri() ); if ( taglib != null ) { Tag newTag = taglib.createTag( tag.getLocalName(), getSaxAttributes() ); if ( newTag != null ) { newTag.setParent( tag.getParent() ); newTag.setBody( tag.getBody() ); return newTag; } } return tag; } }
return; tag.setContext(context); setContextURLs(context); tag.doTag(output); if (output != null) { output.flush();