From 44b3d6f0447c4a0365bf0aa85e2d9d656ce1d550 Mon Sep 17 00:00:00 2001 From: Pavan Kumar K Date: Fri, 13 Jun 2025 09:51:43 +0530 Subject: [PATCH 1/3] Fixed the deprecation warnings Deprecation warnings due to recent changes in the dependencies are fixed. Also the duplicate dependencies in core pom.xml are cleaned. --- core/pom.xml | 47 +--- .../java/org/apache/commons/jelly/Jelly.java | 82 +++---- .../apache/commons/jelly/JellyContext.java | 90 ++++---- .../jelly/expression/jexl/JexlExpression.java | 14 +- .../expression/xpath/XPathExpression.java | 15 +- .../apache/commons/jelly/impl/Embedded.java | 6 +- .../commons/jelly/parser/XMLParser.java | 208 +++++++++--------- .../commons/jelly/util/CommandLineParser.java | 38 ++-- .../commons/jelly/xpath/XPathComparator.java | 3 +- .../apache/commons/jelly/task/JellyTask.java | 4 +- .../jelly/tags/http/MultipartPostTag.java | 19 +- .../commons/jelly/tags/http/PostTag.java | 4 +- .../commons/jelly/tags/threads/ThreadTag.java | 2 +- .../commons/jelly/tags/xml/TestXMLTags.java | 30 +-- 14 files changed, 250 insertions(+), 312 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d50506f90..8cc1ed0e0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -16,7 +16,7 @@ limitations under the License. --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 commons-jelly @@ -52,46 +52,11 @@ - - javax.servlet - servlet-api - 2.5 - - - commons-cli - commons-cli - 1.9.0 - commons-lang commons-lang 2.0 - - commons-discovery - commons-discovery - 20030211.213356 - - - forehead - forehead - 1.0-beta-5 - - - javax.servlet - jstl - 1.0.6 - - - junit - junit - 3.8.1 - - - dom4j - dom4j - 1.6.1 - commons-beanutils commons-beanutils @@ -107,15 +72,5 @@ commons-jexl 1.1 - - jaxen - jaxen - 1.1.6 - - - xerces - xercesImpl - 2.12.2 - diff --git a/core/src/main/java/org/apache/commons/jelly/Jelly.java b/core/src/main/java/org/apache/commons/jelly/Jelly.java index 190498784..2fe09f30c 100644 --- a/core/src/main/java/org/apache/commons/jelly/Jelly.java +++ b/core/src/main/java/org/apache/commons/jelly/Jelly.java @@ -33,7 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.xml.sax.SAXException; -/** +/** *

Jelly is a helper class which is capable of * running a Jelly script. This class can be used from the command line * or can be used as the basis of an Ant task.

Command line usage is as follows: @@ -43,18 +43,18 @@ * */ public class Jelly { - + /** The Log to which logging calls will be made. */ private static final Log log = LogFactory.getLog(Jelly.class); - + public static String getJellyBuildDate() { return readBuildTimestampResource("jelly-build-date.txt"); } - + public static String getJellyVersion() { return readBuildTimestampResource("jelly-version.txt"); } - + /** * Usage: jelly [scriptFile] [-script scriptFile -o outputFile -Dsysprop=syspropval] */ @@ -81,7 +81,7 @@ public static void main(String[] args) throws Exception { } } } - + private static String readBuildTimestampResource(String name) { java.io.Reader in = null; try { @@ -107,28 +107,28 @@ private static String readBuildTimestampResource(String name) { /** The URL of the script to execute */ private URL url; - + /** The URL of the root context for other scripts */ private URL rootContext; /** Whether we have loaded the properties yet */ private boolean loadedProperties = false; - - + + /** * whether to override the default namespace */ private String defaultNamespaceURI = null; - + /** * whether or not to validate the Jelly script */ private boolean validateXML = false; - + public Jelly() { } - - + + /** * Compiles the script @@ -164,10 +164,10 @@ public Script compileScript() throws JellyException { return script; } - + // Properties //------------------------------------------------------------------------- - + /** * The context to use */ @@ -181,36 +181,36 @@ public JellyContext getJellyContext() throws MalformedURLException { } return context; } - - /** + + /** * Gets the root context */ public URL getRootContext() throws MalformedURLException { if (rootContext == null) { - rootContext = new File(System.getProperty("user.dir")).toURL(); + rootContext = new File(System.getProperty("user.dir")).toURI().toURL(); } return rootContext; } - + public URL getUrl() { return url; } - + /** * Attempts to load jelly.properties from the current directory, * the users home directory or from the classpath */ protected void loadJellyProperties() { InputStream is = null; - + String userDir = System.getProperty("user.home"); File f = new File(userDir + File.separator + "jelly.properties"); loadProperties(f); - + f = new File("jelly.properties"); loadProperties(f); - - + + is = ClassLoaderUtils.getClassLoader(getClass()).getResourceAsStream("jelly.properties"); if (is != null) { try { @@ -221,7 +221,7 @@ protected void loadJellyProperties() { } } } - + /** * Load properties from a file into the context * @param f @@ -245,10 +245,10 @@ private void loadProperties(File f) { } } } - + /** - * Loads the properties from the given input stream - */ + * Loads the properties from the given input stream + */ protected void loadProperties(InputStream is) throws IOException { JellyContext theContext = getJellyContext(); Properties props = new Properties(); @@ -257,25 +257,25 @@ protected void loadProperties(InputStream is) throws IOException { while (propsEnum.hasMoreElements()) { String key = (String) propsEnum.nextElement(); String value = props.getProperty(key); - + // @todo we should parse the value in case its an Expression theContext.setVariable(key, value); } } - + // Implementation methods - //------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** - * @return the URL for the relative file name or absolute URL + * @return the URL for the relative file name or absolute URL */ protected URL resolveURL(String name) throws MalformedURLException { - + URL resourceUrl = ClassLoaderUtils.getClassLoader(getClass()).getResource(name); if (resourceUrl == null) { File file = new File(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } else { @@ -287,7 +287,7 @@ protected URL resolveURL(String name) throws MalformedURLException { * Sets the jelly namespace to use for unprefixed elements. * Will be overridden by an explicit namespace in the * XML document. - * + * * @param namespace jelly namespace to use (e.g. 'jelly:core') */ public void setDefaultNamespaceURI(String namespace) { @@ -300,24 +300,24 @@ public void setDefaultNamespaceURI(String namespace) { * @param context */ public void setJellyContext(JellyContext context) { - this.context = context; + this.context = context; } - - /** + + /** * Sets the root context */ public void setRootContext(URL rootContext) { this.rootContext = rootContext; } - /** + /** * Sets the script URL to use as an absolute URL or a relative file name */ public void setScript(String script) throws MalformedURLException { setUrl(resolveURL(script)); } - /** + /** * Sets the script URL to use */ public void setUrl(URL url) { @@ -327,7 +327,7 @@ public void setUrl(URL url) { /** * When set to true, the XML parser will attempt to validate * the Jelly XML before converting it into a Script. - * + * * @param validate whether or not to validate */ public void setValidateXML(boolean validate) { diff --git a/core/src/main/java/org/apache/commons/jelly/JellyContext.java b/core/src/main/java/org/apache/commons/jelly/JellyContext.java index 6a65b0388..db6ec6438 100644 --- a/core/src/main/java/org/apache/commons/jelly/JellyContext.java +++ b/core/src/main/java/org/apache/commons/jelly/JellyContext.java @@ -33,8 +33,8 @@ import org.xml.sax.SAXException; /** - *

JellyContext represents the Jelly context.

- */ + *

JellyContext represents the Jelly context.

+ */ public class JellyContext { /** The Log to which logging calls will be made. */ @@ -95,12 +95,12 @@ public class JellyContext { /** Should we cache Tag instances, per thread, to reduce object construction overhead? */ private boolean cacheTags = false; - + /** * True if exceptions should be suppressed; introduced in 1.1 beta and immediately deprecated * because future versions will _never_ suppress exceptions (required here for backwards * compatibility) - * @deprecated after v1.1, exceptions will never be suppressed + * @deprecated after v1.1, exceptions will never be suppressed */ private boolean suppressExpressionExceptions; @@ -176,7 +176,7 @@ public JellyContext(URL rootURL, URL currentURL) { /** Clears variables set by Tags. * @see #clearVariables() - */ + */ public void clear() { clearVariables(); } @@ -269,11 +269,11 @@ protected JellyContext createChildContext() { * @throws MalformedURLException if the URL is invalid. */ protected URL createRelativeURL(URL rootURL, String relativeURI) - throws MalformedURLException { + throws MalformedURLException { URL url = rootURL; if (url == null) { File file = new File(System.getProperty("user.dir")); - url = file.toURL(); + url = file.toURI().toURL(); } String urlText = url.toString() + relativeURI; if ( log.isDebugEnabled() ) { @@ -353,7 +353,7 @@ protected URL getJellyContextURL(InputSource source) throws MalformedURLExceptio } else { return null; } - + } /** @@ -420,13 +420,13 @@ public InputStream getResourceAsStream(String uri) { catch (Exception e) { if (log.isTraceEnabled()) { log.trace( - "Caught exception attempting to open: " + uri + ". Exception: " + e, - e); + "Caught exception attempting to open: " + uri + ". Exception: " + e, + e); } return null; } } - + /** * @return the current root context URL from which all absolute resource URIs * will be relative to. For example in a web application the root URL will @@ -435,7 +435,7 @@ public InputStream getResourceAsStream(String uri) { public URL getRootURL() { return rootURL; } - + /** * @return the scope of the given name, such as the 'parent' scope. * If Jelly is used in a Servlet situation then 'request', 'session' and 'application' are other names @@ -447,7 +447,7 @@ public JellyContext getScope(String name) { } return null; } - + /** * Gets a system property and handle security exceptions * @param name the name of the property to retrieve @@ -498,16 +498,16 @@ else if ( answer instanceof String ) { } else { log.error( - "The tag library object mapped to: " - + namespaceURI - + " is not a TagLibrary. Object = " - + object); + "The tag library object mapped to: " + + namespaceURI + + " is not a TagLibrary. Object = " + + object); } } catch (Exception e) { log.error( - "Could not instantiate instance of class: " + className + ". Reason: " + e, - e); + "Could not instantiate instance of class: " + className + ". Reason: " + e, + e); } } } @@ -638,12 +638,12 @@ public boolean isInherit() { } /** - * @return the suppressExpressionExceptions - * @deprecated after v1.1, exceptions will never be suppressed - */ - public boolean isSuppressExpressionExceptions() { - return suppressExpressionExceptions; - } + * @return the suppressExpressionExceptions + * @deprecated after v1.1, exceptions will never be suppressed + */ + public boolean isSuppressExpressionExceptions() { + return suppressExpressionExceptions; + } public boolean isTagLibraryRegistered(String namespaceURI) { boolean answer = taglibs.containsKey( namespaceURI ); @@ -686,8 +686,8 @@ public JellyContext newJellyContext(Map newVariables) { * This should be called before the parser is used. */ public void registerTagLibrary( - String namespaceURI, - String className) { + String namespaceURI, + String className) { if (log.isDebugEnabled()) { log.debug("Registering tag library to: " + namespaceURI + " taglib: " + className); @@ -742,8 +742,8 @@ public void removeVariable(String name, String scopeName) { */ public JellyContext runScript(File file, XMLOutput output) throws JellyException { try { - return runScript(file.toURL(), output, JellyContext.DEFAULT_EXPORT, - JellyContext.DEFAULT_INHERIT); + return runScript(file.toURI().toURL(), output, JellyContext.DEFAULT_EXPORT, + JellyContext.DEFAULT_INHERIT); } catch (MalformedURLException e) { throw new JellyException(e.toString()); } @@ -755,9 +755,9 @@ public JellyContext runScript(File file, XMLOutput output) throws JellyException * @return the new child context that was used to run the script */ public JellyContext runScript(File file, XMLOutput output, - boolean export, boolean inherit) throws JellyException { + boolean export, boolean inherit) throws JellyException { try { - return runScript(file.toURL(), output, export, inherit); + return runScript(file.toURI().toURL(), output, export, inherit); } catch (MalformedURLException e) { throw new JellyException(e.toString()); } @@ -770,7 +770,7 @@ public JellyContext runScript(File file, XMLOutput output, */ public JellyContext runScript(InputSource source, XMLOutput output) throws JellyException { return runScript(source, output, JellyContext.DEFAULT_EXPORT, - JellyContext.DEFAULT_INHERIT); + JellyContext.DEFAULT_INHERIT); } /** @@ -779,7 +779,7 @@ public JellyContext runScript(InputSource source, XMLOutput output) throws Jelly * @return the new child context that was used to run the script */ public JellyContext runScript(InputSource source, XMLOutput output, - boolean export, boolean inherit) throws JellyException { + boolean export, boolean inherit) throws JellyException { Script script = compileScript(source); URL newJellyContextURL = null; @@ -829,7 +829,7 @@ public JellyContext runScript(String uri, XMLOutput output) throws JellyExceptio throw new JellyException("Could not find Jelly script: " + url); } return runScript(url, output, JellyContext.DEFAULT_EXPORT, - JellyContext.DEFAULT_INHERIT); + JellyContext.DEFAULT_INHERIT); } /** @@ -839,7 +839,7 @@ public JellyContext runScript(String uri, XMLOutput output) throws JellyExceptio * @return the new child context that was used to run the script */ public JellyContext runScript(String uri, XMLOutput output, - boolean export, boolean inherit) throws JellyException { + boolean export, boolean inherit) throws JellyException { URL url = null; try { url = getResource(uri); @@ -861,7 +861,7 @@ public JellyContext runScript(String uri, XMLOutput output, */ public JellyContext runScript(URL url, XMLOutput output) throws JellyException { return runScript(url, output, JellyContext.DEFAULT_EXPORT, - JellyContext.DEFAULT_INHERIT); + JellyContext.DEFAULT_INHERIT); } /** @@ -870,7 +870,7 @@ public JellyContext runScript(URL url, XMLOutput output) throws JellyException { * @return the new child context that was used to run the script */ public JellyContext runScript(URL url, XMLOutput output, - boolean export, boolean inherit) throws JellyException { + boolean export, boolean inherit) throws JellyException { return runScript(new InputSource(url.toString()), output, export, inherit); } @@ -972,12 +972,12 @@ public void setRootURL(URL rootURL) { } /** - * @param suppressExpressionExceptions the suppressExpressionExceptions to set - * @deprecated after v1.1, exceptions will never be suppressed - */ - public void setSuppressExpressionExceptions(boolean suppressExpressionExceptions) { - this.suppressExpressionExceptions = suppressExpressionExceptions; - } + * @param suppressExpressionExceptions the suppressExpressionExceptions to set + * @deprecated after v1.1, exceptions will never be suppressed + */ + public void setSuppressExpressionExceptions(boolean suppressExpressionExceptions) { + this.suppressExpressionExceptions = suppressExpressionExceptions; + } /** * Determine whether to use the Context ClassLoader (the one found by @@ -1006,7 +1006,7 @@ public void setVariable(String name, Object value) { } } - /** + /** * Sets the value of the given variable name in the given variable scope * @param name is the name of the variable * @param scopeName is the optional scope name such as 'parent'. For servlet environments @@ -1020,7 +1020,7 @@ public void setVariable(String name, String scopeName, Object value) { } } - /** + /** * Sets the Map of variables to use */ public void setVariables(Map variables) { diff --git a/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java b/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java index 5bd938d33..43e9e9d6d 100644 --- a/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java +++ b/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java @@ -151,16 +151,10 @@ public Object evaluate(JellyContext context) { return value; } catch (Exception e) { - if (context.isSuppressExpressionExceptions()) { - log.warn("Caught exception evaluating: " + expression + ". Reason: " + e, e); - return null; - } else { - if (e instanceof RuntimeException) - throw (RuntimeException)e; - if (e instanceof IllegalStateException) - throw (IllegalStateException )e; - throw (IllegalStateException)new IllegalStateException (e.getMessage(), e); - } + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + throw new IllegalStateException (e.getMessage(), e); } } diff --git a/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java b/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java index 08d3093b9..685125979 100644 --- a/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java +++ b/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java @@ -33,7 +33,7 @@ import org.jaxen.dom4j.Dom4jXPath; /** An expression which returns an XPath object. - */ + */ public class XPathExpression extends ExpressionSupport implements VariableContext { /** The Log to which logging calls will be made. */ @@ -95,13 +95,8 @@ public Object evaluate(JellyContext context) { } catch (JaxenException e) { - if (context.isSuppressExpressionExceptions()) - log.error("Error constructing xpath", e); - else - throw (IllegalStateException)new IllegalStateException (e.getMessage(), e); + throw new IllegalStateException (e.getMessage(), e); } - - return null; } // Expression interface @@ -115,9 +110,9 @@ public String getExpressionText() { //------------------------------------------------------------------------- @Override public Object getVariableValue( - String namespaceURI, - String prefix, - String localName) { + String namespaceURI, + String prefix, + String localName) { Object value = context.getVariable(localName); diff --git a/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java b/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java index 643772c69..51c54af91 100644 --- a/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java +++ b/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java @@ -50,7 +50,7 @@ * // embedded.setScript(scriptAsInputStream) * * boolean bStatus=embedded.execute(); - * if (!bStatus) { // if error + * if (!bStatus) { // if error * String errorMsg=embedded.getErrorMsg(); * } * @@ -70,7 +70,7 @@ public class Embedded { private OutputStream outputStream; /** Output(default System.out) */ private XMLOutput output = - XMLOutput.createXMLOutput(new OutputStreamWriter(System.out)); + XMLOutput.createXMLOutput(new OutputStreamWriter(System.out)); /** Exception thrown during compilation of script*/ Exception scriptCompilationException; /** Boolean value indicating whether the script has been successfully compiled or NOT */ @@ -185,7 +185,7 @@ public void registerTagLibrary(String namespaceURI, TagLibrary taglib) { private URL resolveURL(String name) throws MalformedURLException { File file = new File(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } diff --git a/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java b/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java index 2688234ea..0a5f921ca 100644 --- a/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java +++ b/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java @@ -183,7 +183,7 @@ public XMLParser() { } /** - * Constructs s a new XMLParser, with the boolean + * Constructs s a new XMLParser, with the boolean * allowDtdToCallExternalEntities being passed in. If this is set to false, * the XMLParser will be created with: * XMLReader spf = XMLReaderFactory.createXMLReader(); @@ -198,7 +198,7 @@ public XMLParser(boolean allowDtdToCallExternalEntities) { } /** - * Constructs ts a new XMLParser, allowing a SAXParser to be passed in. This + * Constructs ts a new XMLParser, allowing a SAXParser to be passed in. This * allows XMLParser to be used in environments which are unfriendly to * JAXP1.1 (such as WebLogic 6.0). Thanks for the request to change go to * James House (james@interobjective.com). This may help in places where @@ -209,7 +209,7 @@ public XMLParser(SAXParser parser) { } /** - * Constructs cts a new XMLParser, allowing an XMLReader to be passed in. This + * Constructs cts a new XMLParser, allowing an XMLReader to be passed in. This * allows XMLParser to be used in environments which are unfriendly to * JAXP1.1 (such as WebLogic 6.0). Note that if you use this option you * have to configure namespace and validation support yourself, as these @@ -225,7 +225,7 @@ public XMLParser(XMLReader reader) { protected void addExpressionScript(ScriptBlock script, Expression expression) { if ( expression instanceof ConstantExpression ) { ConstantExpression constantExpression - = (ConstantExpression) expression; + = (ConstantExpression) expression; Object value = constantExpression.getValue(); if ( value != null ) { script.addScript(new TextScript( value.toString() )); @@ -237,7 +237,7 @@ protected void addExpressionScript(ScriptBlock script, Expression expression) { script.addScript(newBlock); CompositeExpression compositeExpression - = (CompositeExpression) expression; + = (CompositeExpression) expression; Iterator iter = compositeExpression.getExpressions().iterator(); while (iter.hasNext()) { addExpressionScript( newBlock, (Expression) iter.next() ); @@ -253,7 +253,7 @@ protected void addExpressionScript(ScriptBlock script, Expression expression) { * expressions into ExpressionScript objects. */ protected void addTextScript(String text) throws JellyException { - Expression expression = createExpression(tagScript, "", text); + Expression expression = createExpression(tagScript, "", text); addExpressionScript(script, expression); } @@ -268,7 +268,7 @@ protected void addTextScript(String text) throws JellyException { */ @Override public void characters(char buffer[], int start, int length) - throws SAXException { + throws SAXException { textBuffer.append(buffer, start, length); } @@ -321,9 +321,9 @@ protected void configureTagScript(TagScript aTagScript) { } protected Expression createConstantExpression( - String tagName, - String attributeName, - String attributeValue) { + String tagName, + String attributeName, + String attributeValue) { return new ConstantExpression(attributeValue); } @@ -336,11 +336,11 @@ protected Expression createConstantExpression( * @throws JellyException */ public Expression createExpression(TagScript script, String attributeName, String value) throws JellyException { - ExpressionFactory factory = getExpressionFactory(script); - TagLibrary tagLibrary = script.getTagLibrary(); - if (tagLibrary != null) - return tagLibrary.createExpression(factory, script, attributeName, value); - return CompositeExpression.parse(value, factory); + ExpressionFactory factory = getExpressionFactory(script); + TagLibrary tagLibrary = script.getTagLibrary(); + if (tagLibrary != null) + return tagLibrary.createExpression(factory, script, attributeName, value); + return CompositeExpression.parse(value, factory); } /** @@ -385,12 +385,12 @@ protected SAXException createSAXException(String message, Exception e) { } if (locator != null) { String error = - "Error at (" - + locator.getLineNumber() - + ", " - + locator.getColumnNumber() - + "): " - + message; + "Error at (" + + locator.getLineNumber() + + ", " + + locator.getColumnNumber() + + "): " + + message; if (e != null) { return new SAXParseException(error, locator, e); } @@ -411,20 +411,20 @@ protected SAXException createSAXException(String message, Exception e) { * Factory method to create a static Tag that represents some static content. */ protected TagScript createStaticTag( - final String namespaceURI, - final String localName, - final String qName, - Attributes list) - throws SAXException { + final String namespaceURI, + final String localName, + final String qName, + Attributes list) + throws SAXException { try { //StaticTag tag = new StaticTag( namespaceURI, localName, qName ); StaticTagScript script = new StaticTagScript( - new TagFactory() { - @Override - public Tag createTag(String name, Attributes attributes) { - return new StaticTag( namespaceURI, localName, qName ); + new TagFactory() { + @Override + public Tag createTag(String name, Attributes attributes) { + return new StaticTag( namespaceURI, localName, qName ); + } } - } ); configureTagScript(script); @@ -448,11 +448,11 @@ public Tag createTag(String name, Attributes attributes) { } catch (Exception e) { log.warn( - "Could not create static tag for URI: " - + namespaceURI - + " tag name: " - + localName, - e); + "Could not create static tag for URI: " + + namespaceURI + + " tag name: " + + localName, + e); throw createSAXException(e); } } @@ -462,10 +462,10 @@ public Tag createTag(String name, Attributes attributes) { * return null if this is not a custom Tag. */ protected TagScript createTag( - String namespaceURI, - String localName, - Attributes list) - throws SAXException { + String namespaceURI, + String localName, + Attributes list) + throws SAXException { try { // use the URI to load a taglib TagLibrary taglib = context.getTagLibrary(namespaceURI); @@ -507,12 +507,12 @@ protected TagScript createTag( // Fix for JELLY-184 where the xmlns attributes have a blank name and cause // an exception later on if (attributeName.length() == 0) - continue; + continue; String attributeValue = list.getValue(i); Expression expression = - createExpression(script, - attributeName, - attributeValue); + createExpression(script, + attributeName, + attributeValue); // Expression expression = // taglib.createExpression( // getExpressionFactory(), @@ -532,8 +532,8 @@ protected TagScript createTag( } catch (Exception e) { log.warn( - "Could not create taglib or URI: " + namespaceURI + " tag name: " + localName, - e); + "Could not create taglib or URI: " + namespaceURI + " tag name: " + localName, + e); throw createSAXException(e); } } @@ -562,7 +562,7 @@ public void endDocument() throws SAXException { */ @Override public void endElement(String namespaceURI, String localName, String qName) - throws SAXException { + throws SAXException { try { tagScript = (TagScript) tagScriptStack.remove(tagScriptStack.size() - 1); if (tagScript != null) { @@ -638,13 +638,13 @@ private void ensureConfigured() { @Override public void error(SAXParseException exception) throws SAXException { log.error( - "Parse Error at line " - + exception.getLineNumber() - + " column " - + exception.getColumnNumber() - + ": " - + exception.getMessage(), - exception); + "Parse Error at line " + + exception.getLineNumber() + + " column " + + exception.getColumnNumber() + + ": " + + exception.getMessage(), + exception); if (errorHandler != null) { errorHandler.error(exception); } else { @@ -662,13 +662,13 @@ public void error(SAXParseException exception) throws SAXException { @Override public void fatalError(SAXParseException exception) throws SAXException { log.error( - "Parse Fatal Error at line " - + exception.getLineNumber() - + " column " - + exception.getColumnNumber() - + ": " - + exception.getMessage(), - exception); + "Parse Fatal Error at line " + + exception.getLineNumber() + + " column " + + exception.getColumnNumber() + + ": " + + exception.getMessage(), + exception); if (errorHandler != null) { errorHandler.fatalError(exception); } else { @@ -739,27 +739,27 @@ public ErrorHandler getErrorHandler() { * @return the expression factory used to evaluate tag attributes */ public ExpressionFactory getExpressionFactory(TagScript tagScript) { - // Check the tag library - TagLibrary tagLibrary = null; - if (tagScript != null) - tagLibrary = tagScript.getTagLibrary(); - - // If the tagScript is a StaticTag, then go up the stack looking for a - // tagScript that belongs to a real TagLibrary - if (tagLibrary == null && tagScript instanceof StaticTagScript) - for (int i = tagScriptStack.size() - 1; i > -1; i--) { - TagScript script = (TagScript)tagScriptStack.get(i); - tagLibrary = script.getTagLibrary(); - if (tagLibrary != null) - break; - if (!(script instanceof StaticTagScript)) - break; - } - if (tagLibrary != null) { - ExpressionFactory factory = tagLibrary.getExpressionFactory(); - if (factory != null) - return factory; - } + // Check the tag library + TagLibrary tagLibrary = null; + if (tagScript != null) + tagLibrary = tagScript.getTagLibrary(); + + // If the tagScript is a StaticTag, then go up the stack looking for a + // tagScript that belongs to a real TagLibrary + if (tagLibrary == null && tagScript instanceof StaticTagScript) + for (int i = tagScriptStack.size() - 1; i > -1; i--) { + TagScript script = (TagScript)tagScriptStack.get(i); + tagLibrary = script.getTagLibrary(); + if (tagLibrary != null) + break; + if (!(script instanceof StaticTagScript)) + break; + } + if (tagLibrary != null) { + ExpressionFactory factory = tagLibrary.getExpressionFactory(); + if (factory != null) + return factory; + } if (expressionFactory == null) { expressionFactory = createExpressionFactory(); } @@ -775,7 +775,7 @@ protected synchronized Properties getJellyProperties() { InputStream in = null; URL url = - getClassLoader().getResource("org/apache/commons/jelly/jelly.properties"); + getClassLoader().getResource("org/apache/commons/jelly/jelly.properties"); if (url != null) { log.debug("Loading Jelly default tag libraries from: " + url); try { @@ -911,7 +911,7 @@ public synchronized XMLReader getXMLReader() throws SAXException { */ @Override public void ignorableWhitespace(char buffer[], int start, int len) - throws SAXException { + throws SAXException { // No processing required } @@ -946,7 +946,7 @@ public void notationDecl(String name, String publicId, String systemId) { * @throws SAXException if a parsing exception occurs */ public Script parse(File file) throws IOException, SAXException { - return parse(file.toURL()); + return parse(file.toURI().toURL()); } /** @@ -1051,7 +1051,7 @@ public Script parse(URL url) throws IOException, SAXException { */ @Override public void processingInstruction(String target, String data) - throws SAXException { + throws SAXException { // No processing is required } @@ -1193,11 +1193,11 @@ public void startDocument() throws SAXException { */ @Override public void startElement( - String namespaceURI, - String localName, - String qName, - Attributes list) - throws SAXException { + String namespaceURI, + String localName, + String qName, + Attributes list) + throws SAXException { try { // add check to ensure namespace URI is "" for no namespace @@ -1220,7 +1220,7 @@ public void startElement( } // sets the file name element names if (fileName != null) - tagScript.setFileName(fileName); + tagScript.setFileName(fileName); tagScript.setElementName(qName); tagScript.setLocalName(localName); @@ -1268,7 +1268,7 @@ public void startElement( */ @Override public void startPrefixMapping(String prefix, String namespaceURI) - throws SAXException { + throws SAXException { // Register this prefix mapping ArrayDeque stack = (ArrayDeque) namespaces.get(prefix); if (stack == null) { @@ -1293,10 +1293,10 @@ public void startPrefixMapping(String prefix, String namespaceURI) */ @Override public void unparsedEntityDecl( - String name, - String publicId, - String systemId, - String notation) { + String name, + String publicId, + String systemId, + String notation) { } /** * Forward notification of a parse warning to the application supplied @@ -1310,13 +1310,13 @@ public void unparsedEntityDecl( @Override public void warning(SAXParseException exception) throws SAXException { log.error( - "Parse Warning at line " - + exception.getLineNumber() - + " column " - + exception.getColumnNumber() - + ": " - + exception.getMessage(), - exception); + "Parse Warning at line " + + exception.getLineNumber() + + " column " + + exception.getColumnNumber() + + ": " + + exception.getMessage(), + exception); if (errorHandler != null) { errorHandler.warning(exception); } diff --git a/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java b/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java index 51b9c8794..f69f90528 100644 --- a/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java +++ b/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java @@ -25,11 +25,7 @@ import java.util.List; import java.util.Properties; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.Parser; +import org.apache.commons.cli.*; import org.apache.commons.jelly.Jelly; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyException; @@ -45,7 +41,7 @@ public class CommandLineParser { protected static CommandLineParser _instance = new CommandLineParser(); - + public static CommandLineParser getInstance() { return _instance; } @@ -67,11 +63,11 @@ public void invokeCommandLineJelly(String[] args) throws JellyException { } catch (ParseException e) { throw new JellyException(e); } - + // check for -h or -v if (cmdLine.hasOption("h")) { new HelpFormatter().printHelp("jelly [scriptFile] [-script scriptFile] [-o outputFile] [-Dsysprop=syspropval] [-awt]", - cmdLineOptions); + cmdLineOptions); System.exit(1); } if (cmdLine.hasOption("v")) { @@ -88,7 +84,7 @@ public void invokeCommandLineJelly(String[] args) throws JellyException { } else { scriptFile = args[0]; } - + // check the -awt option. boolean runInSwingThread = cmdLine.hasOption("awt") || cmdLine.hasOption("swing"); @@ -124,22 +120,22 @@ public void run() { } catch (Exception ex) { ex.printStackTrace(); } - } } ); } else { + } } ); } else { script.run(context, output); } // now lets wait for all threads to close Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - try { - output.close(); - } - catch (Exception e) { - // ignore errors - } - } - } + @Override + public void run() { + try { + output.close(); + } + catch (Exception e) { + // ignore errors + } + } + } ); } catch (Exception e) { @@ -201,7 +197,7 @@ public CommandLine parseCommandLineOptions(String[] args) throws ParseException filteredArgList.toArray(filterArgs); // parse the command line - Parser parser = new org.apache.commons.cli.GnuParser(); + DefaultParser parser = new DefaultParser(); return parser.parse(cmdLineOptions, filterArgs); } diff --git a/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java b/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java index b5995cc8b..21cd4018b 100644 --- a/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java +++ b/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java @@ -19,7 +19,6 @@ import java.util.Comparator; import java.util.List; -import org.apache.commons.jelly.util.NestedRuntimeException; import org.dom4j.Node; import org.jaxen.JaxenException; import org.jaxen.XPath; @@ -34,7 +33,7 @@ public class XPathComparator implements Comparator { /** * My own runtime exception in case something goes wrong with sort. */ - public static class XPathSortException extends NestedRuntimeException { + public static class XPathSortException extends RuntimeException { public XPathSortException(String message, Throwable cause) { super(message, cause); } diff --git a/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java b/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java index b82f93f25..c45908d5e 100644 --- a/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java +++ b/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java @@ -142,7 +142,7 @@ public void setXMLOutput(XMLOutput xmlOutput) { */ public URL getRootContext() throws MalformedURLException { if (rootContext == null) { - rootContext = new File(System.getProperty("user.dir")).toURL(); + rootContext = new File(System.getProperty("user.dir")).toURI().toURL(); } return rootContext; } @@ -206,7 +206,7 @@ protected Script compileScript() throws JellyException { protected URL resolveURL(String name) throws MalformedURLException { File file = getProject().resolveFile(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } diff --git a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java index 48b0aa5e3..6ba23da1d 100644 --- a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java +++ b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java @@ -22,10 +22,9 @@ import java.util.List; import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.methods.MultipartPostMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; /** * A Multipart MIME message post @@ -45,14 +44,14 @@ public class MultipartPostTag extends PostTag { /** The post method */ - private MultipartPostMethod _postMethod; + private MultipartRequestEntity _multipartRequestEntity; /** List of parts as name value pairs */ - private List _parts; + private List _parts; /** Creates a new instance of MppostTag */ public MultipartPostTag() { - _parts = new ArrayList(); + _parts = new ArrayList<>(); } /** @@ -65,7 +64,7 @@ public MultipartPostTag() { @Override protected HttpMethod getHttpMethod() throws MalformedURLException { if (_postMethod == null) { - _postMethod = new MultipartPostMethod(getResolvedUrl()); + _postMethod = new PostMethod(getResolvedUrl()); } return _postMethod; } @@ -88,8 +87,8 @@ public void addPart(Part part) { */ @Override protected void setParameters(HttpMethod method) { - for (int index = 0; index < _parts.size(); index++) { - ((MultipartPostMethod) method).addPart( (Part) _parts.get(index) ); - } + _multipartRequestEntity = new MultipartRequestEntity(_parts.toArray(new Part[0]), _postMethod.getParams()); + _postMethod.setRequestEntity(_multipartRequestEntity); } } + diff --git a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/PostTag.java b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/PostTag.java index cd2a35df7..69766dab5 100644 --- a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/PostTag.java +++ b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/PostTag.java @@ -28,7 +28,7 @@ public class PostTag extends HttpTagSupport { /** The post method */ - private PostMethod _postMethod; + protected PostMethod _postMethod; /** Creates a new instance of PostTag */ public PostTag() { @@ -60,7 +60,7 @@ protected void setParameters(HttpMethod method) { NameValuePair nvp = null; for (int index = 0; index < getParameters().size(); index++) { NameValuePair parameter = (NameValuePair) getParameters(). - get(index); + get(index); ((PostMethod) method).addParameter(parameter); } } diff --git a/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java b/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java index 4fb2f79a9..17a70eac9 100644 --- a/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java +++ b/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java @@ -119,7 +119,7 @@ public void run() { throw (RuntimeException) e; } else { - throw new NestedRuntimeException(e); + throw new RuntimeException(e); } } } diff --git a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java index 9ab52783e..833602c7d 100644 --- a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java +++ b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java @@ -48,7 +48,7 @@ import org.dom4j.io.XMLWriter; /** Tests the parser, the engine and the XML tags - */ + */ public class TestXMLTags extends TestCase { /** The Log to which logging calls will be made. */ @@ -105,7 +105,7 @@ private static String checkNamespaceFragment(String s, String pre, String post) * @param ns the namespaces to be matched in the fragment */ private static void findNamespaceFragment(String s, String pre, String post, - String... ns) { + String... ns) { Matcher matcher = matcherForNamespaceFragment(s, pre, post); assertTrue("Pattern '" + pre + REG_NS + post + "' does not match " + s, matcher.find()); @@ -149,9 +149,9 @@ public void testElementWithNameSpace() throws Exception { String text = evaluateScriptAsText(testBaseDir + "/elementWithNameSpace.jelly"); assertEquals("Should produce the correct output", ""+ - "", text); + "xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" "+ + "env:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"+ + "", text); } public void testElementWithNameSpaceError() throws Exception { @@ -170,8 +170,8 @@ public void testNamespaceReplace() throws Exception { String repeatingText = ""; assertEquals("Should produce the correct output", ""+ - repeatingText + repeatingText + - "", text); + repeatingText + repeatingText + + "", text); Map ctxVars = new HashMap(); ctxVars.put("ns", "http://java/ns"); @@ -231,9 +231,9 @@ public void testAttributeNameSpaceWithInnerElements() throws Exception { String text = evaluateScriptAsText(testBaseDir + "/attributeNameSpaceWithInnerElements.jelly"); assertEquals("Should produce the correct output", ""+ - ""+ - ""+ - "" + ""+ + ""+ + "" , text); } @@ -265,25 +265,25 @@ public void testTransformSAXOutput() throws Exception { public void testTransformSAXOutputNestedTransforms() throws Exception { String text = evaluateScriptAsText(testBaseDir + - "/transformExampleSAXOutputNestedTransforms.jelly"); + "/transformExampleSAXOutputNestedTransforms.jelly"); assertEquals("Should produce the correct output", "It works!", text); } public void testTransformSchematron() throws Exception { String text = evaluateScriptAsText(testBaseDir + - "/schematron/transformSchematronExample.jelly"); + "/schematron/transformSchematronExample.jelly"); assertEquals("Should produce the correct output", "Report count=1:assert count=2", text); } public void testTransformXmlVar() throws Exception { String text = evaluateScriptAsText(testBaseDir + - "/transformExampleXmlVar.jelly"); + "/transformExampleXmlVar.jelly"); assertEquals("Should produce the correct output", "It works!", text); } public void testDoctype() throws Exception { String text = evaluateScriptAsText(testBaseDir + - "/testDoctype.jelly"); + "/testDoctype.jelly"); assertEquals("Should produce the correct output", "\n", text); } @@ -342,7 +342,7 @@ protected String evaluateScriptAsText(String fileName, Map ctxVars) throws Excep // allow scripts to refer to any resource inside this project // using an absolute URI like /src/test/org/apache/foo.xml - context.setRootURL(new File(".").toURL()); + context.setRootURL(new File(".").toURI().toURL()); // capture the output StringWriter buffer = new StringWriter(); From 57331d9672f2b92f63d0b7c18eba41b75b3b6462 Mon Sep 17 00:00:00 2001 From: Pavan Kumar K Date: Fri, 13 Jun 2025 09:51:43 +0530 Subject: [PATCH 2/3] Fixed the deprecation warnings Deprecation warnings due to recent changes in the dependencies are fixed. Also the duplicate dependencies in core pom.xml are cleaned. --- core/pom.xml | 47 +------------------ .../java/org/apache/commons/jelly/Jelly.java | 4 +- .../apache/commons/jelly/JellyContext.java | 10 ++-- .../jelly/expression/jexl/JexlExpression.java | 16 ++----- .../expression/xpath/XPathExpression.java | 7 +-- .../apache/commons/jelly/impl/Embedded.java | 4 +- .../commons/jelly/parser/XMLParser.java | 7 ++- .../commons/jelly/util/CommandLineParser.java | 4 +- .../commons/jelly/xpath/XPathComparator.java | 3 +- .../apache/commons/jelly/task/JellyTask.java | 6 +-- .../jelly/tags/http/MultipartPostTag.java | 32 ++++++++----- .../commons/jelly/tags/threads/ThreadTag.java | 10 +--- .../commons/jelly/tags/xml/TestXMLTags.java | 6 +-- 13 files changed, 49 insertions(+), 107 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d50506f90..8cc1ed0e0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -16,7 +16,7 @@ limitations under the License. --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 commons-jelly @@ -52,46 +52,11 @@ - - javax.servlet - servlet-api - 2.5 - - - commons-cli - commons-cli - 1.9.0 - commons-lang commons-lang 2.0 - - commons-discovery - commons-discovery - 20030211.213356 - - - forehead - forehead - 1.0-beta-5 - - - javax.servlet - jstl - 1.0.6 - - - junit - junit - 3.8.1 - - - dom4j - dom4j - 1.6.1 - commons-beanutils commons-beanutils @@ -107,15 +72,5 @@ commons-jexl 1.1 - - jaxen - jaxen - 1.1.6 - - - xerces - xercesImpl - 2.12.2 - diff --git a/core/src/main/java/org/apache/commons/jelly/Jelly.java b/core/src/main/java/org/apache/commons/jelly/Jelly.java index 93ef73f17..a89ec3fb4 100644 --- a/core/src/main/java/org/apache/commons/jelly/Jelly.java +++ b/core/src/main/java/org/apache/commons/jelly/Jelly.java @@ -185,7 +185,7 @@ public JellyContext getJellyContext() throws MalformedURLException { */ public URL getRootContext() throws MalformedURLException { if (rootContext == null) { - rootContext = new File(System.getProperty("user.dir")).toURL(); + rootContext = new File(System.getProperty("user.dir")).toURI().toURL(); } return rootContext; } @@ -276,7 +276,7 @@ protected URL resolveURL(final String name) throws MalformedURLException { } final File file = new File(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } diff --git a/core/src/main/java/org/apache/commons/jelly/JellyContext.java b/core/src/main/java/org/apache/commons/jelly/JellyContext.java index c1e4b0ac0..f39ec9768 100644 --- a/core/src/main/java/org/apache/commons/jelly/JellyContext.java +++ b/core/src/main/java/org/apache/commons/jelly/JellyContext.java @@ -268,7 +268,7 @@ protected URL createRelativeURL(final URL rootURL, final String relativeURI) URL url = rootURL; if (url == null) { final File file = new File(System.getProperty("user.dir")); - url = file.toURL(); + url = file.toURI().toURL(); } final String urlText = url.toString() + relativeURI; if ( log.isDebugEnabled() ) { @@ -735,7 +735,7 @@ public void removeVariable(final String name, final String scopeName) { */ public JellyContext runScript(final File file, final XMLOutput output) throws JellyException { try { - return runScript(file.toURL(), output, JellyContext.DEFAULT_EXPORT, + return runScript(file.toURI().toURL(), output, JellyContext.DEFAULT_EXPORT, JellyContext.DEFAULT_INHERIT); } catch (final MalformedURLException e) { throw new JellyException(e.toString()); @@ -750,7 +750,7 @@ public JellyContext runScript(final File file, final XMLOutput output) throws Je public JellyContext runScript(final File file, final XMLOutput output, final boolean export, final boolean inherit) throws JellyException { try { - return runScript(file.toURL(), output, export, inherit); + return runScript(file.toURI().toURL(), output, export, inherit); } catch (final MalformedURLException e) { throw new JellyException(e.toString()); } @@ -1020,8 +1020,8 @@ public void setVariable(final String name, final String scopeName, final Object public void setVariables(final Map variables) { // I have seen this fail when the passed Map contains a key, value // pair where the value is null - for (final Iterator iter = variables.entrySet().iterator(); iter.hasNext();) { - final Map.Entry element = (Map.Entry) iter.next(); + for (Object o : variables.entrySet()) { + final Map.Entry element = (Map.Entry) o; if (element.getValue() != null) { this.variables.put(element.getKey(), element.getValue()); } diff --git a/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java b/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java index 13383deb7..7c9e06e4b 100644 --- a/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java +++ b/core/src/main/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java @@ -138,7 +138,7 @@ public JexlExpression(final Expression expression) { @Override public Object evaluate(final JellyContext context) { try { - final JexlContext jexlContext = new JellyJexlContext( context ); + final JexlContext jexlContext = new JellyJexlContext(context); if (log.isDebugEnabled()) { log.debug("Evaluating EL: " + expression.getExpression()); } @@ -149,19 +149,11 @@ public Object evaluate(final JellyContext context) { } return value; - } - catch (final Exception e) { - if (context.isSuppressExpressionExceptions()) { - log.warn("Caught exception evaluating: " + expression + ". Reason: " + e, e); - return null; - } + } catch (final Exception e) { if (e instanceof RuntimeException) { - throw (RuntimeException)e; - } - if (e instanceof IllegalStateException) { - throw (IllegalStateException )e; + throw (RuntimeException) e; } - throw (IllegalStateException)new IllegalStateException (e.getMessage(), e); + throw new IllegalStateException (e.getMessage(), e); } } diff --git a/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java b/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java index 0440a6113..8bba90978 100644 --- a/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java +++ b/core/src/main/java/org/apache/commons/jelly/expression/xpath/XPathExpression.java @@ -95,13 +95,8 @@ public Object evaluate(final JellyContext context) { } catch (final JaxenException e) { - if (!context.isSuppressExpressionExceptions()) { - throw (IllegalStateException)new IllegalStateException (e.getMessage(), e); - } - log.error("Error constructing xpath", e); + throw new IllegalStateException (e.getMessage(), e); } - - return null; } // Expression interface diff --git a/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java b/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java index 1e6d773b0..f69106bc4 100644 --- a/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java +++ b/core/src/main/java/org/apache/commons/jelly/impl/Embedded.java @@ -69,7 +69,7 @@ public class Embedded { private OutputStream outputStream; /** Output(default System.out) */ private XMLOutput output = - XMLOutput.createXMLOutput(new OutputStreamWriter(System.out)); + XMLOutput.createXMLOutput(new OutputStreamWriter(System.out)); /** Exception thrown during compilation of script*/ Exception scriptCompilationException; /** Boolean value indicating whether the script has been successfully compiled or NOT */ @@ -185,7 +185,7 @@ public void registerTagLibrary(final String namespaceURI, final TagLibrary tagli private URL resolveURL(final String name) throws MalformedURLException { final File file = new File(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } diff --git a/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java b/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java index 7fcd23101..65b92c227 100644 --- a/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java +++ b/core/src/main/java/org/apache/commons/jelly/parser/XMLParser.java @@ -236,9 +236,8 @@ protected void addExpressionScript(final ScriptBlock script, final Expression ex final CompositeExpression compositeExpression = (CompositeExpression) expression; - final Iterator iter = compositeExpression.getExpressions().iterator(); - while (iter.hasNext()) { - addExpressionScript( newBlock, (Expression) iter.next() ); + for (Object o : compositeExpression.getExpressions()) { + addExpressionScript(newBlock, (Expression) o); } } else { @@ -942,7 +941,7 @@ public void notationDecl(final String name, final String publicId, final String * @throws SAXException if a parsing exception occurs */ public Script parse(final File file) throws IOException, SAXException { - return parse(file.toURL()); + return parse(file.toURI().toURL()); } /** diff --git a/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java b/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java index a7b586f39..2b16cdc8c 100644 --- a/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java +++ b/core/src/main/java/org/apache/commons/jelly/util/CommandLineParser.java @@ -29,7 +29,7 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.Parser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.jelly.Jelly; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyException; @@ -199,7 +199,7 @@ public CommandLine parseCommandLineOptions(final String[] args) throws ParseExce filteredArgList.toArray(filterArgs); // parse the command line - final Parser parser = new org.apache.commons.cli.GnuParser(); + final DefaultParser parser = new DefaultParser(); return parser.parse(cmdLineOptions, filterArgs); } diff --git a/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java b/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java index 4759476df..b7eb96989 100644 --- a/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java +++ b/core/src/main/java/org/apache/commons/jelly/xpath/XPathComparator.java @@ -19,7 +19,6 @@ import java.util.Comparator; import java.util.List; -import org.apache.commons.jelly.util.NestedRuntimeException; import org.dom4j.Node; import org.jaxen.JaxenException; import org.jaxen.XPath; @@ -34,7 +33,7 @@ public class XPathComparator implements Comparator { /** * My own runtime exception in case something goes wrong with sort. */ - public static class XPathSortException extends NestedRuntimeException { + public static class XPathSortException extends RuntimeException { public XPathSortException(final String message, final Throwable cause) { super(message, cause); } diff --git a/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java b/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java index e0f961402..b72b8ac24 100644 --- a/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java +++ b/jelly-tags/ant/src/main/java/org/apache/commons/jelly/task/JellyTask.java @@ -134,7 +134,7 @@ public JellyContext getJellyContext() throws MalformedURLException { */ public URL getRootContext() throws MalformedURLException { if (rootContext == null) { - rootContext = new File(System.getProperty("user.dir")).toURL(); + rootContext = new File(System.getProperty("user.dir")).toURI().toURL(); } return rootContext; } @@ -156,7 +156,7 @@ public XMLOutput getXMLOutput() throws IOException { protected URL resolveURL(final String name) throws MalformedURLException { final File file = getProject().resolveFile(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } @@ -165,7 +165,7 @@ protected URL resolveURL(final String name) throws MalformedURLException { * Sets the script file to use */ public void setFile(final File file) throws MalformedURLException { - setUrl( file.toURL() ); + setUrl( file.toURI().toURL() ); } /** diff --git a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java index 81dfac5d5..e32458c66 100644 --- a/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java +++ b/jelly-tags/http/src/main/java/org/apache/commons/jelly/tags/http/MultipartPostTag.java @@ -22,7 +22,8 @@ import java.util.List; import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.MultipartPostMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; /** @@ -42,15 +43,12 @@ */ public class MultipartPostTag extends PostTag { - /** The post method */ - private MultipartPostMethod _postMethod; - /** List of parts as name value pairs */ - private final List _parts; + private final List _parts; /** Creates a new instance of MppostTag */ public MultipartPostTag() { - _parts = new ArrayList(); + _parts = new ArrayList<>(); } /** @@ -71,10 +69,7 @@ public void addPart(final Part part) { */ @Override protected HttpMethod getHttpMethod() throws MalformedURLException { - if (_postMethod == null) { - _postMethod = new MultipartPostMethod(getResolvedUrl()); - } - return _postMethod; + return super.getHttpMethod(); } /** @@ -86,8 +81,21 @@ protected HttpMethod getHttpMethod() throws MalformedURLException { */ @Override protected void setParameters(final HttpMethod method) { - for (final Object _part : _parts) { - ((MultipartPostMethod) method).addPart( (Part) _part ); + try { + ((PostMethod)getHttpMethod()).setRequestEntity(getMultipartRequestEntity(method)); + } catch (MalformedURLException e){ + throw new RuntimeException("Invalid url.", e); } } + + /** + * Gets the multipart request entity. + * + * @return the multipart request entity + */ + private MultipartRequestEntity getMultipartRequestEntity(final HttpMethod method) { + return new MultipartRequestEntity(_parts.toArray(new Part[0]), method.getParams()); + } + } + diff --git a/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java b/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java index 95bdeb93b..58c3287ec 100644 --- a/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java +++ b/jelly-tags/threads/src/main/java/org/apache/commons/jelly/tags/threads/ThreadTag.java @@ -24,7 +24,6 @@ import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; -import org.apache.commons.jelly.util.NestedRuntimeException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -106,16 +105,11 @@ public void doTag(final XMLOutput output) throws JellyTagException { log.error(e); // wrap the exception with a RuntimeException - throw new NestedRuntimeException(e); + throw new RuntimeException(e); } catch (final Exception e) { log.error(e); - - // wrap the exception with a RuntimeException - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new NestedRuntimeException(e); + throw new RuntimeException(e); } }); diff --git a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java index e404a2db0..051740f08 100644 --- a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java +++ b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java @@ -228,9 +228,9 @@ public void runUnitTest(final String name) throws Exception { final Document document = parseUnitTest(name); final List failures = document.selectNodes( "/*/fail" ); - for ( final Iterator iter = failures.iterator(); iter.hasNext(); ) { - final Node node = (Node) iter.next(); - fail( node.getStringValue() ); + for (Object failure : failures) { + final Node node = (Node) failure; + fail(node.getStringValue()); } } From b573d796fff6b5fc35d62e0cf0ae8680e374290a Mon Sep 17 00:00:00 2001 From: Pavan Kumar Date: Mon, 7 Jul 2025 12:15:24 +0530 Subject: [PATCH 3/3] Fixed few more deprecation warnings. --- .../java/org/apache/commons/jelly/avalon/JellyServiceImpl.java | 2 +- .../org/apache/commons/jelly/tags/betwixt/IntrospectorTag.java | 2 +- .../org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java | 2 +- .../java/org/apache/commons/jelly/demos/HomepageBuilder.java | 2 +- .../java/org/apache/commons/jelly/tags/xml/TransformTag.java | 2 +- .../java/org/apache/commons/jelly/tags/xml/TestXMLTags.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jelly-tags/avalon/src/main/java/org/apache/commons/jelly/avalon/JellyServiceImpl.java b/jelly-tags/avalon/src/main/java/org/apache/commons/jelly/avalon/JellyServiceImpl.java index 46d51dddd..a50b91b49 100644 --- a/jelly-tags/avalon/src/main/java/org/apache/commons/jelly/avalon/JellyServiceImpl.java +++ b/jelly-tags/avalon/src/main/java/org/apache/commons/jelly/avalon/JellyServiceImpl.java @@ -95,7 +95,7 @@ public void configure( final Configuration config ) throws ConfigurationExceptio URL url = null; final File file = new File( scriptName ); if ( file.exists() ) { - url = file.toURL(); + url = file.toURI().toURL(); } else { try { diff --git a/jelly-tags/betwixt/src/main/java/org/apache/commons/jelly/tags/betwixt/IntrospectorTag.java b/jelly-tags/betwixt/src/main/java/org/apache/commons/jelly/tags/betwixt/IntrospectorTag.java index fd8ef3e89..654762351 100644 --- a/jelly-tags/betwixt/src/main/java/org/apache/commons/jelly/tags/betwixt/IntrospectorTag.java +++ b/jelly-tags/betwixt/src/main/java/org/apache/commons/jelly/tags/betwixt/IntrospectorTag.java @@ -159,7 +159,7 @@ public XMLIntrospector getIntrospector() { * as aliases to the common name mapping strategies or specify a class name String. */ public void setAttributeNameMapper(final NameMapper nameMapper) { - getIntrospector().setAttributeNameMapper(nameMapper); + getIntrospector().getConfiguration().setAttributeNameMapper(nameMapper); } /** diff --git a/jelly-tags/jsl/src/main/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java b/jelly-tags/jsl/src/main/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java index 929bd7666..3b9684a47 100644 --- a/jelly-tags/jsl/src/main/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java +++ b/jelly-tags/jsl/src/main/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dom4j.rule.Stylesheet; -import org.jaxen.XPath; +import org.dom4j.XPath; /** * Implements the apply templates function in the stylesheet, similar to the XSLT equivalent. diff --git a/jelly-tags/swing/src/test/java/org/apache/commons/jelly/demos/HomepageBuilder.java b/jelly-tags/swing/src/test/java/org/apache/commons/jelly/demos/HomepageBuilder.java index 5592e17c2..68d65e23c 100644 --- a/jelly-tags/swing/src/test/java/org/apache/commons/jelly/demos/HomepageBuilder.java +++ b/jelly-tags/swing/src/test/java/org/apache/commons/jelly/demos/HomepageBuilder.java @@ -183,7 +183,7 @@ public void buildPage(final String template, final JellyContext ctx) { protected URL resolveURL(final String name) throws MalformedURLException { final File file = new File(name); if (file.exists()) { - return file.toURL(); + return file.toURI().toURL(); } return new URL(name); } diff --git a/jelly-tags/xml/src/main/java/org/apache/commons/jelly/tags/xml/TransformTag.java b/jelly-tags/xml/src/main/java/org/apache/commons/jelly/tags/xml/TransformTag.java index 990692d26..8c984f067 100644 --- a/jelly-tags/xml/src/main/java/org/apache/commons/jelly/tags/xml/TransformTag.java +++ b/jelly-tags/xml/src/main/java/org/apache/commons/jelly/tags/xml/TransformTag.java @@ -595,7 +595,7 @@ else if (sourceObj instanceof URL) { } else if (sourceObj instanceof File) { try { - final String uri = ((File) sourceObj).toURL().toString(); + final String uri = ((File) sourceObj).toURI().toURL().toString(); xmlInputSource = new InputSource(context.getResourceAsStream(uri)); } catch (final MalformedURLException e) { diff --git a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java index 98b5f74a5..a56e02937 100644 --- a/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java +++ b/jelly-tags/xml/src/test/java/org/apache/commons/jelly/tags/xml/TestXMLTags.java @@ -145,7 +145,7 @@ protected String evaluateScriptAsText(final String fileName, final Map ctxVars) // allow scripts to refer to any resource inside this project // using an absolute URI like /src/test/org/apache/foo.xml - context.setRootURL(new File(".").toURL()); + context.setRootURL(new File(".").toURI().toURL()); // capture the output final StringWriter buffer = new StringWriter();