/** * Compile the script */ private void compileScriptAndKeep() { XMLParser parser = new XMLParser(); parser.setContext(m_context); m_scriptCompiled = false; try { m_script = parser.parse(m_inputStream); m_script = m_script.compile(); m_scriptCompiled = true; } catch (IOException e) { m_scriptCompilationException = e; } catch (SAXException e) { m_scriptCompilationException = e; } catch (Exception e) { m_scriptCompilationException = e; } }
/** * Adds the text to the current script block parsing any embedded * expressions inot ExpressionScript objects. */ protected void addTextScript(String text) throws JellyException { Expression expression = CompositeExpression.parse(text, getExpressionFactory()); addExpressionScript(script, expression); }
/** * If this object has not been configured then register the default * namespaces */ private void ensureConfigured() { if (!configured) { configure(); configured = true; } }
/** * Factory method to create a new Jelly parser * @return XMLParser */ protected XMLParser createJellyParser() { XMLParser answer = new XMLParser(); answer.setContext(context); return answer; } }
XMLParser parser = new XMLParser(); try { parser.setContext(getJellyContext()); } catch (MalformedURLException e) { throw new JellyException(e.toString()); parser.setDefaultNamespaceURI(this.defaultNamespaceURI); parser.setValidating(this.validateXML); script = parser.parse(getUrl()); script = script.compile(); if (log.isDebugEnabled()) {
Class taglibClass = getClassLoader().loadClass(uri); taglib = (TagLibrary) taglibClass.newInstance(); context.registerTagLibrary(namespaceURI, taglib); throw createSAXException("Could not load class: " + uri + " so taglib instantiation failed", e); throw createSAXException("Constructor for class is not accessible: " + uri + " so taglib instantiation failed",e); throw createSAXException("Class could not be instantiated: " + uri + " so taglib instantiation failed",e); throw createSAXException("Class is not a TagLibrary: " + uri + " so taglib instantiation failed",e); TagScript script = taglib.createTagScript(localName, list); if ( script != null ) { configureTagScript(script); Expression expression = taglib.createExpression( getExpressionFactory(), script, attributeName, attributeValue); if (expression == null) { expression = createConstantExpression(localName, attributeName, attributeValue); "Could not create taglib or URI: " + namespaceURI + " tag name: " + localName, e); throw createSAXException(e);
/** * Attempts to parse the script from the given InputSource using the * {@link #getResource} method then returns the compiled script. */ public Script compileScript(InputSource source) throws JellyException { XMLParser parser = getXMLParser(); parser.setContext(this); Script script = null; try { script = parser.parse(source); } catch (IOException e) { throw new JellyException(JellyContext.BAD_PARSE+" : "+source.getSystemId(), e); } catch (SAXException e) { throw new JellyException(JellyContext.BAD_PARSE+" : "+source.getSystemId(), e); } return script.compile(); }
TagScript newTagScript = createTag(namespaceURI, localName, list); if (newTagScript == null) { newTagScript = createStaticTag(namespaceURI, localName, qName, list); addTextScript(textBuffer.toString(),true); textBuffer.setLength(0); throw createSAXException( "Runtime Exception: " + e, e );
factory.setNamespaceAware( true ); XMLReader reader = factory.newSAXParser().getXMLReader(); XMLParser parser = new XMLParser( reader ); parser.setContext( context ); parser.setClassLoader( context.getClassLoader() ); script = parser.parse( source );
/** * Factory method to create a static Tag that represents some static content. * * <p> * Note that to if you use jelly:define taglib, these tags might turn out to be non-static * during the runtime. */ protected TagScript createStaticTag( final String namespaceURI, final String localName, final String qName, Attributes list) throws SAXException { try { StaticTagScript script = new StaticTagScript(); configureTagScript(script); configureStaticTagAttributes(script,list); return script; } catch (Exception e) { log.warn( "Could not create static tag for URI: " + namespaceURI + " tag name: " + localName, e); throw createSAXException(e); } }
public void testArgs() throws Exception { InputStream in = new FileInputStream("src/test/org/apache/commons/jelly/test_args.jelly"); XMLParser parser = new XMLParser(); Script script = parser.parse(in); script = script.compile(); log.debug("Found: " + script); assertTrue("Parsed a Script", script instanceof Script); String[] args = { "one", "two", "three" }; JellyContext context = new JellyContext(); context.setVariable("args", args); StringWriter buffer = new StringWriter(); script.run(context, XMLOutput.createXMLOutput(buffer)); String text = buffer.toString().trim(); if (log.isDebugEnabled()) { log.debug("Evaluated script as..."); log.debug(text); } assertEquals("Produces the correct output", "one two three", text); }
configureTagScript(script); String attributeValue = list.getValue(i); Expression expression = CompositeExpression.parse( attributeValue, getExpressionFactory() ); String attrQName = list.getQName(i); + localName, e); throw createSAXException(e);
TagScript newTagScript = createTag(namespaceURI, localName, list); if (newTagScript == null) { newTagScript = createStaticTag(namespaceURI, localName, qName, list); addTextScript(textBuffer.toString()); textBuffer.setLength(0);
/** * Create a SAX exception which also understands about the location in * the digester file where the exception occurs * * @return the new exception */ protected SAXException createSAXException(String message) { return createSAXException(message, null); } }
tagScript = (TagScript) tagScriptStack.remove(tagScriptStack.size() - 1); if (textBuffer.length() > 0) { addTextScript(textBuffer.toString(),false); textBuffer.setLength(0); } catch (Exception e) { log.error( "Caught exception: " + e, e ); throw createSAXException( "Runtime Exception: " + e, e );
/** * Parse the content of the specified file using this XMLParser. Returns * the root element from the object stack (if any). * * @param file File containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Script parse(File file) throws IOException, SAXException { return parse(file.toURL()); }
/** * Factory method to allow JellyContext implementations to overload how an XMLParser * is created - such as to overload what the default ExpressionFactory should be. */ protected XMLParser createXMLParser() { return new XMLParser(allowDtdToCallExternalEntities); }
@Override protected void addExpressionScript(ScriptBlock script, Expression exp) { try { if (exp instanceof InternationalizedStringExpression && escapeByDefaultField.getBoolean(this)) { script.addScript(new ExpressionScript(((InternationalizedStringExpression) exp).escape())); return; // stick with our escaped+internationalized script } } catch (Exception e) { // fall back to original behaviour... } super.addExpressionScript(script, exp); }
/** * Adds the given Expression object to the current Script. */ protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); } } else if ( expression instanceof CompositeExpression ) { CompositeTextScriptBlock newBlock = new CompositeTextScriptBlock(); script.addScript(newBlock); CompositeExpression compositeExpression = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); } } else { if (escapeByDefault) expression = createEscapingExpression(expression); script.addScript(new ExpressionScript(expression)); } }
/** @return the expression factory used to evaluate tag attributes */ public ExpressionFactory getExpressionFactory() { if (expressionFactory == null) { expressionFactory = createExpressionFactory(); } return expressionFactory; }