@Override public void addAttribute(String name, Expression expression) { allAttributesAreConstant &= expression instanceof ConstantExpression; super.addAttribute(name, expression); }
/** Creates a new script to execute the given tag name and attributes */ public TagScript createTagScript(String name, Attributes attributes) throws JellyException { Object value = tags.get(name); if (value instanceof Class) { Class type = (Class) value; return TagScript.newInstance(type); } else if (value instanceof TagFactory) { return new TagScript( (TagFactory) value ); } return null; }
/** * A helper method to handle this Jelly exception. * This method adorns the JellyException with location information * such as adding line number information etc. */ protected void handleException(JellyTagException e) throws JellyTagException { if (log.isTraceEnabled()) { log.trace( "Caught exception: " + e, e ); } applyLocation(e); throw e; }
/** * @return the tag to be evaluated, creating it lazily if required. */ public Tag getTag(JellyContext context) throws JellyException { Thread t = Thread.currentThread(); Tag tag = (Tag) threadLocalTagCache.get(t); if ( tag == null ) { tag = createTag(); if ( tag != null ) { threadLocalTagCache.put(t,tag); configureTag(tag,context); } } return tag; }
tagScript.setLocator(locator); tagScript.setFileName(fileName); tagScript.setElementName(qName); tagScript.setNsUri(namespaceURI); tagScript.setLocalName(localName); tagScript.setTagBody(script);
script.setSaxAttributes(new AttributesImpl(list)); expression = createConstantExpression(localName, attributeName, attributeValue); script.addAttribute(attributeName, expression);
/** * 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); } }
URL currentURL = context.getCurrentURL(); if ( ! context.isCacheTags() ) { clearTag(); Tag tag = getTag(context); if ( tag == null ) { return; setContextURLs(context); handleException(e); } catch (JellyException e) { handleException(e); } catch (IOException e) { handleException(e); } catch (RuntimeException e) { handleException(e); handleException(e); } finally { context.setRootURL(rootURL);
tagScript.addAttribute(e.getKey().asJavaString(), new ConstantExpression(e.getValue())); final Ruby runtime = ((IRubyObject)rcon).getRuntime(); tagScript.setTagBody(new Script() { public Script compile() throws JellyException { return this; tagScript.run(context, output);
URL currentURL = context.getCurrentURL(); try { Tag tag = getTag(context); if ( tag == null ) { return; setContextURLs(context); handleException(e); } catch (JellyException e) { handleException(e); } catch (IOException e) { handleException(e); } catch (RuntimeException e) { handleException(e); handleException(e); } finally { context.setRootURL(rootURL);
/** * Returns the namespace context of this tag. This is all the prefixes * in scope in the document where this tag is used which are mapped to * their namespace URIs. * * @return a Map with the keys are namespace prefixes and the values are * namespace URIs. */ public synchronized Map getNamespaceContext() { if (namespaceContext == null) { if (parent != null) { namespaceContext = getParent().getNamespaceContext(); if (tagNamespacesMap != null && !tagNamespacesMap.isEmpty()) { // create a new child context Hashtable newContext = new Hashtable(namespaceContext.size()+1); newContext.putAll(namespaceContext); newContext.putAll(tagNamespacesMap); namespaceContext = newContext; } } else { namespaceContext = tagNamespacesMap; if (namespaceContext == null) { namespaceContext = new Hashtable(); } } } return namespaceContext; }
/** Creates a new script to execute the given tag name and attributes */ public TagScript createTagScript(final String name, final Attributes attributes) throws JellyException { return new TagScript( new TagFactory() { public Tag createTag(String name, Attributes attributes) throws JellyException { return DynamicTagLibrary.this.createTag(name, attributes); } } ); }
/** * 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); } }
body = new TextScript(innerText); tagScript.setTagBody(body); tagScript.run(context,output); return;
/** * Sets the Jelly file which caused the problem */ public void setFileName(String fileName) { this.fileName = fileName; try { this.scriptURL = getJellyContextURL(new URL(fileName)); } catch (MalformedURLException e) { log.debug("error setting script url", e); } }
public XPathExpression(String text, Expression xpathExpr, TagScript tagScript) { this.text = text; this.xpathExpr = xpathExpr; Map namespaceContext = tagScript.getNamespaceContext(); this.uris = createUriMap(namespaceContext); }
/** Create a <code>TagScript</code> based upon an element's * name and attributes. * * @param name The name. * @param attrs The attributes. * @return Generated <code>TagScript</code> from an elements * name and attributes. * * @throws JellyException If an error occurs while attempting to * create the script. */ public TagScript createTagScript( String name, Attributes attrs ) throws JellyException { if ( "goal".equals( name ) ) { return TagScript.newInstance( MavenGoalTag.class ); } else if ( "attainGoal".equals( name ) ) { return TagScript.newInstance( MavenAttainGoalTag.class ); } // Otherwise, act like nothing is different. return super.createTagScript( name, attrs ); } }
/** * Helper method to run any nested param tags * * @param output The destination for any SAX output (not actually used) */ private void doNestedParamTag(XMLOutput output) throws JellyTagException { // find any nested param tags and run them Script bodyScript = this.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 TagScript) { Tag tag = null; try { tag = ((TagScript) script).getTag(getContext()); } catch (JellyException e) { throw new JellyTagException(e); } if (tag instanceof ParamTag) { script.run(context, output); } } } } }
tagScript.setLocator(locator); tagScript.setFileName(fileName); tagScript.setElementName(qName); tagScript.setNsUri(namespaceURI); tagScript.setLocalName(localName); tagScript.setTagBody(script);
script.setSaxAttributes(new AttributesImpl(list)); expression = createConstantExpression(localName, attributeName, attributeValue); script.addAttribute(attributeName, expression);