init
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Abstract base class for <code>ObjectCreationFactory</code>
|
||||
* implementations.</p>
|
||||
*/
|
||||
public abstract class AbstractObjectCreationFactory
|
||||
implements ObjectCreationFactory {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The associated <code>Digester</code> instance that was set up by
|
||||
* {@link FactoryCreateRule} upon initialization.
|
||||
*/
|
||||
private Digester digester = null;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* <p>Factory method called by {@link FactoryCreateRule} to supply an
|
||||
* object based on the element's attributes.
|
||||
*
|
||||
* @param attributes the element's attributes
|
||||
*
|
||||
* @throws Exception any exception thrown will be propagated upwards
|
||||
*/
|
||||
@Override
|
||||
public abstract Object createObject(Attributes attributes) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns the {@link Digester} that was set by the
|
||||
* {@link FactoryCreateRule} upon initialization.
|
||||
*/
|
||||
@Override
|
||||
public Digester getDigester() {
|
||||
return this.digester;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Set the {@link Digester} to allow the implementation to do logging,
|
||||
* classloading based on the digester's classloader, etc.
|
||||
*
|
||||
* @param digester parent Digester object
|
||||
*/
|
||||
@Override
|
||||
public void setDigester(Digester digester) {
|
||||
this.digester = digester;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
141
java/org/apache/tomcat/util/digester/ArrayStack.java
Normal file
141
java/org/apache/tomcat/util/digester/ArrayStack.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
/**
|
||||
* <p>Imported copy of the <code>ArrayStack</code> class from
|
||||
* Commons Collections, which was the only direct dependency from Digester.</p>
|
||||
*
|
||||
* <p><strong>WARNNG</strong> - This class is public solely to allow it to be
|
||||
* used from subpackages of <code>org.apache.commons.digester</code>.
|
||||
* It should not be considered part of the public API of Commons Digester.
|
||||
* If you want to use such a class yourself, you should use the one from
|
||||
* Commons Collections directly.</p>
|
||||
*
|
||||
* <p>An implementation of the {@link java.util.Stack} API that is based on an
|
||||
* <code>ArrayList</code> instead of a <code>Vector</code>, so it is not
|
||||
* synchronized to protect against multi-threaded access. The implementation
|
||||
* is therefore operates faster in environments where you do not need to
|
||||
* worry about multiple thread contention.</p>
|
||||
*
|
||||
* <p>Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null entries.
|
||||
* </p>
|
||||
*
|
||||
* @param <E> Type of object in this stack
|
||||
*
|
||||
* @see java.util.Stack
|
||||
* @since Digester 1.6 (from Commons Collections 1.0)
|
||||
*/
|
||||
public class ArrayStack<E> extends ArrayList<E> {
|
||||
|
||||
/** Ensure serialization compatibility */
|
||||
private static final long serialVersionUID = 2130079159931574599L;
|
||||
|
||||
/**
|
||||
* Constructs a new empty <code>ArrayStack</code>. The initial size
|
||||
* is controlled by <code>ArrayList</code> and is currently 10.
|
||||
*/
|
||||
public ArrayStack() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new empty <code>ArrayStack</code> with an initial size.
|
||||
*
|
||||
* @param initialSize the initial size to use
|
||||
* @throws IllegalArgumentException if the specified initial size
|
||||
* is negative
|
||||
*/
|
||||
public ArrayStack(int initialSize) {
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if this stack is currently empty.
|
||||
* <p>
|
||||
* This method exists for compatibility with <code>java.util.Stack</code>.
|
||||
* New users of this class should use <code>isEmpty</code> instead.
|
||||
*
|
||||
* @return true if the stack is currently empty
|
||||
*/
|
||||
public boolean empty() {
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the top item off of this stack without removing it.
|
||||
*
|
||||
* @return the top item on the stack
|
||||
* @throws EmptyStackException if the stack is empty
|
||||
*/
|
||||
public E peek() throws EmptyStackException {
|
||||
int n = size();
|
||||
if (n <= 0) {
|
||||
throw new EmptyStackException();
|
||||
} else {
|
||||
return get(n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the n'th item down (zero-relative) from the top of this
|
||||
* stack without removing it.
|
||||
*
|
||||
* @param n the number of items down to go
|
||||
* @return the n'th item on the stack, zero relative
|
||||
* @throws EmptyStackException if there are not enough items on the
|
||||
* stack to satisfy this request
|
||||
*/
|
||||
public E peek(int n) throws EmptyStackException {
|
||||
int m = (size() - n) - 1;
|
||||
if (m < 0) {
|
||||
throw new EmptyStackException();
|
||||
} else {
|
||||
return get(m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the top item off of this stack and return it.
|
||||
*
|
||||
* @return the top item on the stack
|
||||
* @throws EmptyStackException if the stack is empty
|
||||
*/
|
||||
public E pop() throws EmptyStackException {
|
||||
int n = size();
|
||||
if (n <= 0) {
|
||||
throw new EmptyStackException();
|
||||
} else {
|
||||
return remove(n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a new item onto the top of this stack. The pushed item is also
|
||||
* returned. This is equivalent to calling <code>add</code>.
|
||||
*
|
||||
* @param item the item to be added
|
||||
* @return the item just pushed
|
||||
*/
|
||||
public E push(E item) {
|
||||
add(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
478
java/org/apache/tomcat/util/digester/CallMethodRule.java
Normal file
478
java/org/apache/tomcat/util/digester/CallMethodRule.java
Normal file
@@ -0,0 +1,478 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import org.apache.tomcat.util.IntrospectionUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Rule implementation that calls a method on an object on the stack
|
||||
* (normally the top/parent object), passing arguments collected from
|
||||
* subsequent <code>CallParamRule</code> rules or from the body of this
|
||||
* element. </p>
|
||||
*
|
||||
* <p>By using {@link #CallMethodRule(String methodName)}
|
||||
* a method call can be made to a method which accepts no
|
||||
* arguments.</p>
|
||||
*
|
||||
* <p>Incompatible method parameter types are converted
|
||||
* using <code>org.apache.commons.beanutils.ConvertUtils</code>.
|
||||
* </p>
|
||||
*
|
||||
* <p>This rule now uses
|
||||
* <a href="https://commons.apache.org/beanutils/apidocs/org/apache/commons/beanutils/MethodUtils.html">
|
||||
* org.apache.commons.beanutils.MethodUtils#invokeMethod
|
||||
* </a> by default.
|
||||
* This increases the kinds of methods successfully and allows primitives
|
||||
* to be matched by passing in wrapper classes.
|
||||
* There are rare cases when org.apache.commons.beanutils.MethodUtils#invokeExactMethod
|
||||
* (the old default) is required.
|
||||
* This method is much stricter in its reflection.
|
||||
* Setting the <code>UseExactMatch</code> to true reverts to the use of this
|
||||
* method.</p>
|
||||
*
|
||||
* <p>Note that the target method is invoked when the <i>end</i> of
|
||||
* the tag the CallMethodRule fired on is encountered, <i>not</i> when the
|
||||
* last parameter becomes available. This implies that rules which fire on
|
||||
* tags nested within the one associated with the CallMethodRule will
|
||||
* fire before the CallMethodRule invokes the target method. This behaviour is
|
||||
* not configurable. </p>
|
||||
*
|
||||
* <p>Note also that if a CallMethodRule is expecting exactly one parameter
|
||||
* and that parameter is not available (eg CallParamRule is used with an
|
||||
* attribute name but the attribute does not exist) then the method will
|
||||
* not be invoked. If a CallMethodRule is expecting more than one parameter,
|
||||
* then it is always invoked, regardless of whether the parameters were
|
||||
* available or not (missing parameters are passed as null values).</p>
|
||||
*/
|
||||
|
||||
public class CallMethodRule extends Rule {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* Construct a "call method" rule with the specified method name. The
|
||||
* parameter types (if any) default to java.lang.String.
|
||||
*
|
||||
* @param methodName Method name of the parent method to call
|
||||
* @param paramCount The number of parameters to collect, or
|
||||
* zero for a single argument from the body of this element.
|
||||
*/
|
||||
public CallMethodRule(String methodName,
|
||||
int paramCount) {
|
||||
this(0, methodName, paramCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a "call method" rule with the specified method name. The
|
||||
* parameter types (if any) default to java.lang.String.
|
||||
*
|
||||
* @param targetOffset location of the target object. Positive numbers are
|
||||
* relative to the top of the digester object stack. Negative numbers
|
||||
* are relative to the bottom of the stack. Zero implies the top
|
||||
* object on the stack.
|
||||
* @param methodName Method name of the parent method to call
|
||||
* @param paramCount The number of parameters to collect, or
|
||||
* zero for a single argument from the body of this element.
|
||||
*/
|
||||
public CallMethodRule(int targetOffset,
|
||||
String methodName,
|
||||
int paramCount) {
|
||||
|
||||
this.targetOffset = targetOffset;
|
||||
this.methodName = methodName;
|
||||
this.paramCount = paramCount;
|
||||
if (paramCount == 0) {
|
||||
this.paramTypes = new Class[] { String.class };
|
||||
} else {
|
||||
this.paramTypes = new Class[paramCount];
|
||||
for (int i = 0; i < this.paramTypes.length; i++) {
|
||||
this.paramTypes[i] = String.class;
|
||||
}
|
||||
}
|
||||
this.paramClassNames = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a "call method" rule with the specified method name.
|
||||
* The method should accept no parameters.
|
||||
*
|
||||
* @param methodName Method name of the parent method to call
|
||||
*/
|
||||
public CallMethodRule(String methodName) {
|
||||
|
||||
this(0, methodName, 0, (Class[]) null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a "call method" rule with the specified method name and
|
||||
* parameter types. If <code>paramCount</code> is set to zero the rule
|
||||
* will use the body of this element as the single argument of the
|
||||
* method, unless <code>paramTypes</code> is null or empty, in this
|
||||
* case the rule will call the specified method with no arguments.
|
||||
*
|
||||
* @param targetOffset location of the target object. Positive numbers are
|
||||
* relative to the top of the digester object stack. Negative numbers
|
||||
* are relative to the bottom of the stack. Zero implies the top
|
||||
* object on the stack.
|
||||
* @param methodName Method name of the parent method to call
|
||||
* @param paramCount The number of parameters to collect, or
|
||||
* zero for a single argument from the body of this element
|
||||
* @param paramTypes The Java classes that represent the
|
||||
* parameter types of the method arguments
|
||||
* (if you wish to use a primitive type, specify the corresponding
|
||||
* Java wrapper class instead, such as <code>java.lang.Boolean.TYPE</code>
|
||||
* for a <code>boolean</code> parameter)
|
||||
*/
|
||||
public CallMethodRule( int targetOffset,
|
||||
String methodName,
|
||||
int paramCount,
|
||||
Class<?> paramTypes[]) {
|
||||
|
||||
this.targetOffset = targetOffset;
|
||||
this.methodName = methodName;
|
||||
this.paramCount = paramCount;
|
||||
if (paramTypes == null) {
|
||||
this.paramTypes = new Class[paramCount];
|
||||
for (int i = 0; i < this.paramTypes.length; i++) {
|
||||
this.paramTypes[i] = String.class;
|
||||
}
|
||||
} else {
|
||||
this.paramTypes = new Class[paramTypes.length];
|
||||
for (int i = 0; i < this.paramTypes.length; i++) {
|
||||
this.paramTypes[i] = paramTypes[i];
|
||||
}
|
||||
}
|
||||
this.paramClassNames = null;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The body text collected from this element.
|
||||
*/
|
||||
protected String bodyText = null;
|
||||
|
||||
|
||||
/**
|
||||
* location of the target object for the call, relative to the
|
||||
* top of the digester object stack. The default value of zero
|
||||
* means the target object is the one on top of the stack.
|
||||
*/
|
||||
protected final int targetOffset;
|
||||
|
||||
/**
|
||||
* The method name to call on the parent object.
|
||||
*/
|
||||
protected final String methodName;
|
||||
|
||||
|
||||
/**
|
||||
* The number of parameters to collect from <code>MethodParam</code> rules.
|
||||
* If this value is zero, a single parameter will be collected from the
|
||||
* body of this element.
|
||||
*/
|
||||
protected final int paramCount;
|
||||
|
||||
|
||||
/**
|
||||
* The parameter types of the parameters to be collected.
|
||||
*/
|
||||
protected Class<?> paramTypes[] = null;
|
||||
|
||||
/**
|
||||
* The names of the classes of the parameters to be collected.
|
||||
* This attribute allows creation of the classes to be postponed until the digester is set.
|
||||
*
|
||||
* @deprecated Unused. This will be removed in Tomcat 9.
|
||||
*/
|
||||
@Deprecated
|
||||
protected final String paramClassNames[];
|
||||
|
||||
/**
|
||||
* Should <code>MethodUtils.invokeExactMethod</code> be used for reflection.
|
||||
*/
|
||||
protected boolean useExactMatch = false;
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Should <code>MethodUtils.invokeExactMethod</code>
|
||||
* be used for the reflection.
|
||||
* @return <code>true</code> if invokeExactMethod is used
|
||||
*/
|
||||
public boolean getUseExactMatch() {
|
||||
return useExactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether <code>MethodUtils.invokeExactMethod</code>
|
||||
* should be used for the reflection.
|
||||
* @param useExactMatch The flag value
|
||||
*/
|
||||
public void setUseExactMatch(boolean useExactMatch)
|
||||
{
|
||||
this.useExactMatch = useExactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the associated digester.
|
||||
* If needed, this class loads the parameter classes from their names.
|
||||
*/
|
||||
@Override
|
||||
public void setDigester(Digester digester)
|
||||
{
|
||||
// call superclass
|
||||
super.setDigester(digester);
|
||||
// if necessary, load parameter classes
|
||||
if (this.paramClassNames != null) {
|
||||
this.paramTypes = new Class[paramClassNames.length];
|
||||
for (int i = 0; i < this.paramClassNames.length; i++) {
|
||||
try {
|
||||
this.paramTypes[i] =
|
||||
digester.getClassLoader().loadClass(this.paramClassNames[i]);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// use the digester log
|
||||
digester.getLogger().error("(CallMethodRule) Cannot load class " + this.paramClassNames[i], e);
|
||||
this.paramTypes[i] = null; // Will cause NPE later
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the start of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param attributes The attribute list for this element
|
||||
*/
|
||||
@Override
|
||||
public void begin(String namespace, String name, Attributes attributes)
|
||||
throws Exception {
|
||||
|
||||
// Push an array to capture the parameter values if necessary
|
||||
if (paramCount > 0) {
|
||||
Object parameters[] = new Object[paramCount];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
parameters[i] = null;
|
||||
}
|
||||
digester.pushParams(parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the body text of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param bodyText The body text of this element
|
||||
*/
|
||||
@Override
|
||||
public void body(String namespace, String name, String bodyText)
|
||||
throws Exception {
|
||||
|
||||
if (paramCount == 0) {
|
||||
this.bodyText = bodyText.trim().intern();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the end of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
*/
|
||||
@SuppressWarnings("null") // parameters can't trigger NPE
|
||||
@Override
|
||||
public void end(String namespace, String name) throws Exception {
|
||||
|
||||
// Retrieve or construct the parameter values array
|
||||
Object parameters[] = null;
|
||||
if (paramCount > 0) {
|
||||
|
||||
parameters = (Object[]) digester.popParams();
|
||||
|
||||
if (digester.log.isTraceEnabled()) {
|
||||
for (int i=0,size=parameters.length;i<size;i++) {
|
||||
digester.log.trace("[CallMethodRule](" + i + ")" + parameters[i]) ;
|
||||
}
|
||||
}
|
||||
|
||||
// In the case where the parameter for the method
|
||||
// is taken from an attribute, and that attribute
|
||||
// isn't actually defined in the source XML file,
|
||||
// skip the method call
|
||||
if (paramCount == 1 && parameters[0] == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (paramTypes != null && paramTypes.length != 0) {
|
||||
|
||||
// In the case where the parameter for the method
|
||||
// is taken from the body text, but there is no
|
||||
// body text included in the source XML file,
|
||||
// skip the method call
|
||||
if (bodyText == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
parameters = new Object[1];
|
||||
parameters[0] = bodyText;
|
||||
}
|
||||
|
||||
// Construct the parameter values array we will need
|
||||
// We only do the conversion if the param value is a String and
|
||||
// the specified paramType is not String.
|
||||
Object paramValues[] = new Object[paramTypes.length];
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
// convert nulls and convert stringy parameters
|
||||
// for non-stringy param types
|
||||
if(
|
||||
parameters[i] == null ||
|
||||
(parameters[i] instanceof String &&
|
||||
!String.class.isAssignableFrom(paramTypes[i]))) {
|
||||
|
||||
paramValues[i] =
|
||||
IntrospectionUtils.convert((String) parameters[i], paramTypes[i]);
|
||||
} else {
|
||||
paramValues[i] = parameters[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the target object for the method call
|
||||
Object target;
|
||||
if (targetOffset >= 0) {
|
||||
target = digester.peek(targetOffset);
|
||||
} else {
|
||||
target = digester.peek( digester.getCount() + targetOffset );
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[CallMethodRule]{");
|
||||
sb.append(digester.match);
|
||||
sb.append("} Call target is null (");
|
||||
sb.append("targetOffset=");
|
||||
sb.append(targetOffset);
|
||||
sb.append(",stackdepth=");
|
||||
sb.append(digester.getCount());
|
||||
sb.append(")");
|
||||
throw new org.xml.sax.SAXException(sb.toString());
|
||||
}
|
||||
|
||||
// Invoke the required method on the top object
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
StringBuilder sb = new StringBuilder("[CallMethodRule]{");
|
||||
sb.append(digester.match);
|
||||
sb.append("} Call ");
|
||||
sb.append(target.getClass().getName());
|
||||
sb.append(".");
|
||||
sb.append(methodName);
|
||||
sb.append("(");
|
||||
for (int i = 0; i < paramValues.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (paramValues[i] == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(paramValues[i].toString());
|
||||
}
|
||||
sb.append("/");
|
||||
if (paramTypes[i] == null) {
|
||||
sb.append("null");
|
||||
} else {
|
||||
sb.append(paramTypes[i].getName());
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
digester.log.debug(sb.toString());
|
||||
}
|
||||
Object result = IntrospectionUtils.callMethodN(target, methodName,
|
||||
paramValues, paramTypes);
|
||||
processMethodCallResult(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean up after parsing is complete.
|
||||
*/
|
||||
@Override
|
||||
public void finish() throws Exception {
|
||||
|
||||
bodyText = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override this method to perform additional processing of the
|
||||
* invoked method's result.
|
||||
*
|
||||
* @param result the Object returned by the method invoked, possibly null
|
||||
*/
|
||||
protected void processMethodCallResult(Object result) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("CallMethodRule[");
|
||||
sb.append("methodName=");
|
||||
sb.append(methodName);
|
||||
sb.append(", paramCount=");
|
||||
sb.append(paramCount);
|
||||
sb.append(", paramTypes={");
|
||||
if (paramTypes != null) {
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(paramTypes[i].getName());
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
206
java/org/apache/tomcat/util/digester/CallParamRule.java
Normal file
206
java/org/apache/tomcat/util/digester/CallParamRule.java
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* <p>Rule implementation that saves a parameter for use by a surrounding
|
||||
* <code>CallMethodRule</code>.</p>
|
||||
*
|
||||
* <p>This parameter may be:</p>
|
||||
* <ul>
|
||||
* <li>from an attribute of the current element
|
||||
* See {@link #CallParamRule(int paramIndex, String attributeName)}
|
||||
* <li>from current the element body
|
||||
* See {@link #CallParamRule(int paramIndex)}
|
||||
* </ul>
|
||||
*/
|
||||
public class CallParamRule extends Rule {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* Construct a "call parameter" rule that will save the body text of this
|
||||
* element as the parameter value.
|
||||
*
|
||||
* @param paramIndex The zero-relative parameter number
|
||||
*/
|
||||
public CallParamRule(int paramIndex) {
|
||||
this(paramIndex, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a "call parameter" rule that will save the value of the
|
||||
* specified attribute as the parameter value.
|
||||
*
|
||||
* @param paramIndex The zero-relative parameter number
|
||||
* @param attributeName The name of the attribute to save
|
||||
*/
|
||||
public CallParamRule(int paramIndex,
|
||||
String attributeName) {
|
||||
this(attributeName, paramIndex, 0, false);
|
||||
}
|
||||
|
||||
|
||||
private CallParamRule(String attributeName, int paramIndex, int stackIndex,
|
||||
boolean fromStack) {
|
||||
this.attributeName = attributeName;
|
||||
this.paramIndex = paramIndex;
|
||||
this.stackIndex = stackIndex;
|
||||
this.fromStack = fromStack;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The attribute from which to save the parameter value
|
||||
*/
|
||||
protected final String attributeName;
|
||||
|
||||
|
||||
/**
|
||||
* The zero-relative index of the parameter we are saving.
|
||||
*/
|
||||
protected final int paramIndex;
|
||||
|
||||
|
||||
/**
|
||||
* Is the parameter to be set from the stack?
|
||||
*/
|
||||
protected final boolean fromStack;
|
||||
|
||||
/**
|
||||
* The position of the object from the top of the stack
|
||||
*/
|
||||
protected final int stackIndex;
|
||||
|
||||
/**
|
||||
* Stack is used to allow nested body text to be processed.
|
||||
* Lazy creation.
|
||||
*/
|
||||
protected ArrayStack<String> bodyTextStack;
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Process the start of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param attributes The attribute list for this element
|
||||
*/
|
||||
@Override
|
||||
public void begin(String namespace, String name, Attributes attributes)
|
||||
throws Exception {
|
||||
|
||||
Object param = null;
|
||||
|
||||
if (attributeName != null) {
|
||||
|
||||
param = attributes.getValue(attributeName);
|
||||
|
||||
} else if(fromStack) {
|
||||
|
||||
param = digester.peek(stackIndex);
|
||||
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
|
||||
StringBuilder sb = new StringBuilder("[CallParamRule]{");
|
||||
sb.append(digester.match);
|
||||
sb.append("} Save from stack; from stack?").append(fromStack);
|
||||
sb.append("; object=").append(param);
|
||||
digester.log.debug(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Have to save the param object to the param stack frame here.
|
||||
// Can't wait until end(). Otherwise, the object will be lost.
|
||||
// We can't save the object as instance variables, as
|
||||
// the instance variables will be overwritten
|
||||
// if this CallParamRule is reused in subsequent nesting.
|
||||
|
||||
if(param != null) {
|
||||
Object parameters[] = (Object[]) digester.peekParams();
|
||||
parameters[paramIndex] = param;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the body text of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param bodyText The body text of this element
|
||||
*/
|
||||
@Override
|
||||
public void body(String namespace, String name, String bodyText)
|
||||
throws Exception {
|
||||
|
||||
if (attributeName == null && !fromStack) {
|
||||
// We must wait to set the parameter until end
|
||||
// so that we can make sure that the right set of parameters
|
||||
// is at the top of the stack
|
||||
if (bodyTextStack == null) {
|
||||
bodyTextStack = new ArrayStack<>();
|
||||
}
|
||||
bodyTextStack.push(bodyText.trim());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Process any body texts now.
|
||||
*/
|
||||
@Override
|
||||
public void end(String namespace, String name) {
|
||||
if (bodyTextStack != null && !bodyTextStack.empty()) {
|
||||
// what we do now is push one parameter onto the top set of parameters
|
||||
Object parameters[] = (Object[]) digester.peekParams();
|
||||
parameters[paramIndex] = bodyTextStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("CallParamRule[");
|
||||
sb.append("paramIndex=");
|
||||
sb.append(paramIndex);
|
||||
sb.append(", attributeName=");
|
||||
sb.append(attributeName);
|
||||
sb.append(", from stack=");
|
||||
sb.append(fromStack);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
2096
java/org/apache/tomcat/util/digester/Digester.java
Normal file
2096
java/org/apache/tomcat/util/digester/Digester.java
Normal file
File diff suppressed because it is too large
Load Diff
44
java/org/apache/tomcat/util/digester/DocumentProperties.java
Normal file
44
java/org/apache/tomcat/util/digester/DocumentProperties.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
/**
|
||||
*
|
||||
* A collection of interfaces, one per property, that enables the object being
|
||||
* populated by the digester to signal to the digester that it supports the
|
||||
* given property and that the digester should populate that property if
|
||||
* available.
|
||||
*/
|
||||
public interface DocumentProperties {
|
||||
|
||||
/**
|
||||
* The encoding used by the source XML document.
|
||||
*
|
||||
* @deprecated This method will be removed in Tomcat 9
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Encoding {
|
||||
public void setEncoding(String encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* The character encoding used by the source XML document.
|
||||
*/
|
||||
public interface Charset {
|
||||
public void setCharset(java.nio.charset.Charset charset);
|
||||
}
|
||||
}
|
||||
179
java/org/apache/tomcat/util/digester/FactoryCreateRule.java
Normal file
179
java/org/apache/tomcat/util/digester/FactoryCreateRule.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Rule implementation that uses an {@link ObjectCreationFactory} to create
|
||||
* a new object which it pushes onto the object stack. When the element is
|
||||
* complete, the object will be popped.</p>
|
||||
*
|
||||
* <p>This rule is intended in situations where the element's attributes are
|
||||
* needed before the object can be created. A common scenario is for the
|
||||
* ObjectCreationFactory implementation to use the attributes as parameters
|
||||
* in a call to either a factory method or to a non-empty constructor.
|
||||
*/
|
||||
|
||||
public class FactoryCreateRule extends Rule {
|
||||
|
||||
// ----------------------------------------------------------- Fields
|
||||
|
||||
/** Should exceptions thrown by the factory be ignored? */
|
||||
private boolean ignoreCreateExceptions;
|
||||
/** Stock to manage */
|
||||
private ArrayStack<Boolean> exceptionIgnoredStack;
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* Construct a factory create rule using the given, already instantiated,
|
||||
* {@link ObjectCreationFactory}.
|
||||
*
|
||||
* @param creationFactory called on to create the object.
|
||||
* @param ignoreCreateExceptions if true, exceptions thrown by the object
|
||||
* creation factory will be ignored.
|
||||
*/
|
||||
public FactoryCreateRule(
|
||||
ObjectCreationFactory creationFactory,
|
||||
boolean ignoreCreateExceptions) {
|
||||
|
||||
this.creationFactory = creationFactory;
|
||||
this.ignoreCreateExceptions = ignoreCreateExceptions;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The object creation factory we will use to instantiate objects
|
||||
* as required based on the attributes specified in the matched XML
|
||||
* element.
|
||||
*/
|
||||
protected ObjectCreationFactory creationFactory = null;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Process the beginning of this element.
|
||||
*
|
||||
* @param attributes The attribute list of this element
|
||||
*/
|
||||
@Override
|
||||
public void begin(String namespace, String name, Attributes attributes) throws Exception {
|
||||
|
||||
if (ignoreCreateExceptions) {
|
||||
|
||||
if (exceptionIgnoredStack == null) {
|
||||
exceptionIgnoredStack = new ArrayStack<>();
|
||||
}
|
||||
|
||||
try {
|
||||
Object instance = creationFactory.createObject(attributes);
|
||||
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[FactoryCreateRule]{" + digester.match +
|
||||
"} New " + instance.getClass().getName());
|
||||
}
|
||||
digester.push(instance);
|
||||
exceptionIgnoredStack.push(Boolean.FALSE);
|
||||
|
||||
} catch (Exception e) {
|
||||
// log message and error
|
||||
if (digester.log.isInfoEnabled()) {
|
||||
digester.log.info("[FactoryCreateRule] Create exception ignored: " +
|
||||
((e.getMessage() == null) ? e.getClass().getName() : e.getMessage()));
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[FactoryCreateRule] Ignored exception:", e);
|
||||
}
|
||||
}
|
||||
exceptionIgnoredStack.push(Boolean.TRUE);
|
||||
}
|
||||
|
||||
} else {
|
||||
Object instance = creationFactory.createObject(attributes);
|
||||
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[FactoryCreateRule]{" + digester.match +
|
||||
"} New " + instance.getClass().getName());
|
||||
}
|
||||
digester.push(instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the end of this element.
|
||||
*/
|
||||
@Override
|
||||
public void end(String namespace, String name) throws Exception {
|
||||
|
||||
// check if object was created
|
||||
// this only happens if an exception was thrown and we're ignoring them
|
||||
if (
|
||||
ignoreCreateExceptions &&
|
||||
exceptionIgnoredStack != null &&
|
||||
!(exceptionIgnoredStack.empty())) {
|
||||
|
||||
if ((exceptionIgnoredStack.pop()).booleanValue()) {
|
||||
// creation exception was ignored
|
||||
// nothing was put onto the stack
|
||||
if (digester.log.isTraceEnabled()) {
|
||||
digester.log.trace("[FactoryCreateRule] No creation so no push so no pop");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Object top = digester.pop();
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[FactoryCreateRule]{" + digester.match +
|
||||
"} Pop " + top.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean up after parsing is complete.
|
||||
*/
|
||||
@Override
|
||||
public void finish() throws Exception {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("FactoryCreateRule[");
|
||||
if (creationFactory != null) {
|
||||
sb.append("creationFactory=");
|
||||
sb.append(creationFactory);
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
19
java/org/apache/tomcat/util/digester/LocalStrings.properties
Normal file
19
java/org/apache/tomcat/util/digester/LocalStrings.properties
Normal file
@@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=Attribute [{0}] failed to update and remains [{1}]
|
||||
digester.failedToUpdateSystemProperty=System property [{0}] failed to update and remains [{1}]
|
||||
|
||||
disgester.encodingInvalid=The encoding [{0}] is not recognised by the JRE and will be ignored
|
||||
@@ -0,0 +1,16 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=Attribut [{0}} konnte nicht angepasst werden und bleibt auf dem Wert [{1}]
|
||||
@@ -0,0 +1,16 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=El tribunto [{0}] falló la actualización y permanece [{1}]\n
|
||||
@@ -0,0 +1,17 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=L''attribut [{0}] n''a pu être mis à jour et garde la valeur [{1}]
|
||||
digester.failedToUpdateSystemProperty=La propriété système [{0}] n''a pu être mise à jour et reste [{1}]
|
||||
@@ -0,0 +1,17 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=属性[{0}]が更新に失敗し、[{1}]に残りました。
|
||||
digester.failedToUpdateSystemProperty=システムプロパティ [{0}] を更新できません。元の値 [{1}] はそのままです。
|
||||
@@ -0,0 +1,17 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=속성 [{0}]을(를) 변경하지 못하여, [{1}](으)로 유지합니다.
|
||||
digester.failedToUpdateSystemProperty=시스템 프로퍼티 [{0}]을(를) 변경하지 못했으며, 해당 프로퍼티는 [{1}] 값으로 남습니다.
|
||||
@@ -0,0 +1,16 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
digester.failedToUpdateAttributes=属性[{0}]更新失败,旧数据为[{1}]
|
||||
158
java/org/apache/tomcat/util/digester/ObjectCreateRule.java
Normal file
158
java/org/apache/tomcat/util/digester/ObjectCreateRule.java
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* Rule implementation that creates a new object and pushes it
|
||||
* onto the object stack. When the element is complete, the
|
||||
* object will be popped
|
||||
*/
|
||||
|
||||
public class ObjectCreateRule extends Rule {
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* Construct an object create rule with the specified class name.
|
||||
*
|
||||
* @param className Java class name of the object to be created
|
||||
*/
|
||||
public ObjectCreateRule(String className) {
|
||||
|
||||
this(className, (String) null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an object create rule with the specified class name and an
|
||||
* optional attribute name containing an override.
|
||||
*
|
||||
* @param className Java class name of the object to be created
|
||||
* @param attributeName Attribute name which, if present, contains an
|
||||
* override of the class name to create
|
||||
*/
|
||||
public ObjectCreateRule(String className,
|
||||
String attributeName) {
|
||||
|
||||
this.className = className;
|
||||
this.attributeName = attributeName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The attribute containing an override class name if it is present.
|
||||
*/
|
||||
protected String attributeName = null;
|
||||
|
||||
|
||||
/**
|
||||
* The Java class name of the object to be created.
|
||||
*/
|
||||
protected String className = null;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Process the beginning of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param attributes The attribute list for this element
|
||||
*/
|
||||
@Override
|
||||
public void begin(String namespace, String name, Attributes attributes)
|
||||
throws Exception {
|
||||
|
||||
// Identify the name of the class to instantiate
|
||||
String realClassName = className;
|
||||
if (attributeName != null) {
|
||||
String value = attributes.getValue(attributeName);
|
||||
if (value != null) {
|
||||
realClassName = value;
|
||||
}
|
||||
}
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[ObjectCreateRule]{" + digester.match +
|
||||
"}New " + realClassName);
|
||||
}
|
||||
|
||||
if (realClassName == null) {
|
||||
throw new NullPointerException("No class name specified for " +
|
||||
namespace + " " + name);
|
||||
}
|
||||
|
||||
// Instantiate the new object and push it on the context stack
|
||||
Class<?> clazz = digester.getClassLoader().loadClass(realClassName);
|
||||
Object instance = clazz.getConstructor().newInstance();
|
||||
digester.push(instance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the end of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
*/
|
||||
@Override
|
||||
public void end(String namespace, String name) throws Exception {
|
||||
|
||||
Object top = digester.pop();
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[ObjectCreateRule]{" + digester.match +
|
||||
"} Pop " + top.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("ObjectCreateRule[");
|
||||
sb.append("className=");
|
||||
sb.append(className);
|
||||
sb.append(", attributeName=");
|
||||
sb.append(attributeName);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* <p> Interface for use with {@link FactoryCreateRule}.
|
||||
* The rule calls {@link #createObject} to create an object
|
||||
* to be pushed onto the <code>Digester</code> stack
|
||||
* whenever it is matched.</p>
|
||||
*
|
||||
* <p> {@link AbstractObjectCreationFactory} is an abstract
|
||||
* implementation suitable for creating anonymous
|
||||
* <code>ObjectCreationFactory</code> implementations.
|
||||
*/
|
||||
public interface ObjectCreationFactory {
|
||||
|
||||
/**
|
||||
* Factory method called by {@link FactoryCreateRule} to supply an
|
||||
* object based on the element's attributes.
|
||||
*
|
||||
* @param attributes the element's attributes
|
||||
* @return the creted object
|
||||
* @throws Exception any exception thrown will be propagated upwards
|
||||
*/
|
||||
public Object createObject(Attributes attributes) throws Exception;
|
||||
|
||||
/**
|
||||
* @return the {@link Digester} that was set by the
|
||||
* {@link FactoryCreateRule} upon initialization.
|
||||
*/
|
||||
public Digester getDigester();
|
||||
|
||||
/**
|
||||
* Set the {@link Digester} to allow the implementation to do logging,
|
||||
* classloading based on the digester's classloader, etc.
|
||||
*
|
||||
* @param digester parent Digester object
|
||||
*/
|
||||
public void setDigester(Digester digester);
|
||||
|
||||
}
|
||||
161
java/org/apache/tomcat/util/digester/Rule.java
Normal file
161
java/org/apache/tomcat/util/digester/Rule.java
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* Concrete implementations of this class implement actions to be taken when
|
||||
* a corresponding nested pattern of XML elements has been matched.
|
||||
*/
|
||||
public abstract class Rule {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* <p>Base constructor.
|
||||
* Now the digester will be set when the rule is added.</p>
|
||||
*/
|
||||
public Rule() {}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The Digester with which this Rule is associated.
|
||||
*/
|
||||
protected Digester digester = null;
|
||||
|
||||
|
||||
/**
|
||||
* The namespace URI for which this Rule is relevant, if any.
|
||||
*/
|
||||
protected String namespaceURI = null;
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* Identify the Digester with which this Rule is associated.
|
||||
*
|
||||
* @return the Digester with which this Rule is associated.
|
||||
*/
|
||||
public Digester getDigester() {
|
||||
return digester;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the <code>Digester</code> with which this <code>Rule</code> is
|
||||
* associated.
|
||||
*
|
||||
* @param digester The digester with which to associate this rule
|
||||
*/
|
||||
public void setDigester(Digester digester) {
|
||||
this.digester = digester;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the namespace URI for which this Rule is relevant, if any.
|
||||
*
|
||||
* @return The namespace URI for which this rule is relevant or
|
||||
* <code>null</code> if none.
|
||||
*/
|
||||
public String getNamespaceURI() {
|
||||
return namespaceURI;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the namespace URI for which this Rule is relevant, if any.
|
||||
*
|
||||
* @param namespaceURI Namespace URI for which this Rule is relevant,
|
||||
* or <code>null</code> to match independent of namespace.
|
||||
*/
|
||||
public void setNamespaceURI(String namespaceURI) {
|
||||
this.namespaceURI = namespaceURI;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* This method is called when the beginning of a matching XML element
|
||||
* is encountered. The default implementation is a NO-OP.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the
|
||||
* element has no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param attributes The attribute list of this element
|
||||
*
|
||||
* @throws Exception if an error occurs while processing the event
|
||||
*/
|
||||
public void begin(String namespace, String name, Attributes attributes) throws Exception {
|
||||
// NO-OP by default.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the body of a matching XML element is
|
||||
* encountered. If the element has no body, this method is not called at
|
||||
* all. The default implementation is a NO-OP.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an empty
|
||||
* string if the parser is not namespace aware or the
|
||||
* element has no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just the
|
||||
* element name otherwise
|
||||
* @param text The text of the body of this element
|
||||
*
|
||||
* @throws Exception if an error occurs while processing the event
|
||||
*/
|
||||
public void body(String namespace, String name, String text) throws Exception {
|
||||
// NO-OP by default.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the end of a matching XML element
|
||||
* is encountered. The default implementation is a NO-OP.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an empty
|
||||
* string if the parser is not namespace aware or the
|
||||
* element has no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just the
|
||||
* element name otherwise
|
||||
*
|
||||
* @throws Exception if an error occurs while processing the event
|
||||
*/
|
||||
public void end(String namespace, String name) throws Exception {
|
||||
// NO-OP by default.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called after all parsing methods have been
|
||||
* called, to allow Rules to remove temporary data.
|
||||
*
|
||||
* @throws Exception if an error occurs while processing the event
|
||||
*/
|
||||
public void finish() throws Exception {
|
||||
// NO-OP by default.
|
||||
}
|
||||
}
|
||||
69
java/org/apache/tomcat/util/digester/RuleSet.java
Normal file
69
java/org/apache/tomcat/util/digester/RuleSet.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Public interface defining a shorthand means of configuring a complete
|
||||
* set of related <code>Rule</code> definitions, possibly associated with
|
||||
* a particular namespace URI, in one operation. To use an instance of a
|
||||
* class that implements this interface:</p>
|
||||
* <ul>
|
||||
* <li>Create a concrete implementation of this interface.</li>
|
||||
* <li>Optionally, you can configure a <code>RuleSet</code> to be relevant
|
||||
* only for a particular namespace URI by configuring the value to be
|
||||
* returned by <code>getNamespaceURI()</code>.</li>
|
||||
* <li>As you are configuring your Digester instance, call
|
||||
* <code>digester.addRuleSet()</code> and pass the RuleSet instance.</li>
|
||||
* <li>Digester will call the <code>addRuleInstances()</code> method of
|
||||
* your RuleSet to configure the necessary rules.</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
public interface RuleSet {
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
/**
|
||||
* @return the namespace URI that will be applied to all Rule instances
|
||||
* created from this RuleSet.
|
||||
*
|
||||
* @deprecated Unused. Will be removed in Tomcat 9
|
||||
*/
|
||||
@Deprecated
|
||||
public String getNamespaceURI();
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Add the set of Rule instances defined in this RuleSet to the
|
||||
* specified <code>Digester</code> instance, associating them with
|
||||
* our namespace URI (if any). This method should only be called
|
||||
* by a Digester instance.
|
||||
*
|
||||
* @param digester Digester instance to which the new Rule instances
|
||||
* should be added.
|
||||
*/
|
||||
public void addRuleInstances(Digester digester);
|
||||
|
||||
|
||||
}
|
||||
70
java/org/apache/tomcat/util/digester/RuleSetBase.java
Normal file
70
java/org/apache/tomcat/util/digester/RuleSetBase.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
/**
|
||||
* <p>Convenience base class that implements the {@link RuleSet} interface.
|
||||
* Concrete implementations should list all of their actual rule creation
|
||||
* logic in the <code>addRuleSet()</code> implementation.</p>
|
||||
*
|
||||
* @deprecated Unnecessary once deprecated methods are removed. Will be removed
|
||||
* in Tomcat 9.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class RuleSetBase implements RuleSet {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The namespace URI that all Rule instances created by this RuleSet
|
||||
* will be associated with.
|
||||
*
|
||||
* @deprecated Unused. This will be removed in Tomcat 9.
|
||||
*/
|
||||
@Deprecated
|
||||
protected String namespaceURI = null;
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
/**
|
||||
* Return the namespace URI that will be applied to all Rule instances
|
||||
* created from this RuleSet.
|
||||
*
|
||||
* @deprecated Unused. This will be removed in Tomcat 9.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getNamespaceURI() {
|
||||
return this.namespaceURI;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Add the set of Rule instances defined in this RuleSet to the
|
||||
* specified <code>Digester</code> instance, associating them with
|
||||
* our namespace URI (if any). This method should only be called
|
||||
* by a Digester instance.
|
||||
*
|
||||
* @param digester Digester instance to which the new Rule instances
|
||||
* should be added.
|
||||
*/
|
||||
@Override
|
||||
public abstract void addRuleInstances(Digester digester);
|
||||
}
|
||||
121
java/org/apache/tomcat/util/digester/Rules.java
Normal file
121
java/org/apache/tomcat/util/digester/Rules.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Public interface defining a collection of Rule instances (and corresponding
|
||||
* matching patterns) plus an implementation of a matching policy that selects
|
||||
* the rules that match a particular pattern of nested elements discovered
|
||||
* during parsing.
|
||||
*/
|
||||
|
||||
public interface Rules {
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
/**
|
||||
* @return the Digester instance with which this Rules instance is
|
||||
* associated.
|
||||
*/
|
||||
public Digester getDigester();
|
||||
|
||||
|
||||
/**
|
||||
* Set the Digester instance with which this Rules instance is associated.
|
||||
*
|
||||
* @param digester The newly associated Digester instance
|
||||
*/
|
||||
public void setDigester(Digester digester);
|
||||
|
||||
|
||||
/**
|
||||
* @return the namespace URI that will be applied to all subsequently
|
||||
* added <code>Rule</code> objects.
|
||||
*
|
||||
* @deprecated Unused. Will be removed in Tomcat 9
|
||||
*/
|
||||
@Deprecated
|
||||
public String getNamespaceURI();
|
||||
|
||||
|
||||
/**
|
||||
* Set the namespace URI that will be applied to all subsequently
|
||||
* added <code>Rule</code> objects.
|
||||
*
|
||||
* @param namespaceURI Namespace URI that must match on all
|
||||
* subsequently added rules, or <code>null</code> for matching
|
||||
* regardless of the current namespace URI
|
||||
*
|
||||
* @deprecated Unused. Will be removed in Tomcat 9
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNamespaceURI(String namespaceURI);
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Register a new Rule instance matching the specified pattern.
|
||||
*
|
||||
* @param pattern Nesting pattern to be matched for this Rule
|
||||
* @param rule Rule instance to be registered
|
||||
*/
|
||||
public void add(String pattern, Rule rule);
|
||||
|
||||
|
||||
/**
|
||||
* Clear all existing Rule instance registrations.
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
|
||||
/**
|
||||
* Return a List of all registered Rule instances that match the specified
|
||||
* nesting pattern, or a zero-length List if there are no matches. If more
|
||||
* than one Rule instance matches, they <strong>must</strong> be returned
|
||||
* in the order originally registered through the <code>add()</code>
|
||||
* method.
|
||||
*
|
||||
* @param namespaceURI Namespace URI for which to select matching rules,
|
||||
* or <code>null</code> to match regardless of namespace URI
|
||||
* @param pattern Nesting pattern to be matched
|
||||
* @return a rules list
|
||||
*/
|
||||
public List<Rule> match(String namespaceURI, String pattern);
|
||||
|
||||
|
||||
/**
|
||||
* Return a List of all registered Rule instances, or a zero-length List
|
||||
* if there are no registered Rule instances. If more than one Rule
|
||||
* instance has been registered, they <strong>must</strong> be returned
|
||||
* in the order originally registered through the <code>add()</code>
|
||||
* method.
|
||||
* @return a rules list
|
||||
*/
|
||||
public List<Rule> rules();
|
||||
|
||||
|
||||
}
|
||||
271
java/org/apache/tomcat/util/digester/RulesBase.java
Normal file
271
java/org/apache/tomcat/util/digester/RulesBase.java
Normal file
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Default implementation of the <code>Rules</code> interface that supports
|
||||
* the standard rule matching behavior. This class can also be used as a
|
||||
* base class for specialized <code>Rules</code> implementations.</p>
|
||||
*
|
||||
* <p>The matching policies implemented by this class support two different
|
||||
* types of pattern matching rules:</p>
|
||||
* <ul>
|
||||
* <li><em>Exact Match</em> - A pattern "a/b/c" exactly matches a
|
||||
* <code><c></code> element, nested inside a <code><b></code>
|
||||
* element, which is nested inside an <code><a></code> element.</li>
|
||||
* <li><em>Tail Match</em> - A pattern "*/a/b" matches a
|
||||
* <code><b></code> element, nested inside an <code><a></code>
|
||||
* element, no matter how deeply the pair is nested.</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
public class RulesBase implements Rules {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The set of registered Rule instances, keyed by the matching pattern.
|
||||
* Each value is a List containing the Rules for that pattern, in the
|
||||
* order that they were originally registered.
|
||||
*/
|
||||
protected HashMap<String,List<Rule>> cache = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* The Digester instance with which this Rules instance is associated.
|
||||
*/
|
||||
protected Digester digester = null;
|
||||
|
||||
|
||||
/**
|
||||
* The namespace URI for which subsequently added <code>Rule</code>
|
||||
* objects are relevant, or <code>null</code> for matching independent
|
||||
* of namespaces.
|
||||
*
|
||||
* @deprecated Unused. Will be removed in Tomcat 9.0.x
|
||||
*/
|
||||
@Deprecated
|
||||
protected String namespaceURI = null;
|
||||
|
||||
|
||||
/**
|
||||
* The set of registered Rule instances, in the order that they were
|
||||
* originally registered.
|
||||
*/
|
||||
protected ArrayList<Rule> rules = new ArrayList<>();
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Properties
|
||||
|
||||
|
||||
/**
|
||||
* Return the Digester instance with which this Rules instance is
|
||||
* associated.
|
||||
*/
|
||||
@Override
|
||||
public Digester getDigester() {
|
||||
return this.digester;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Digester instance with which this Rules instance is associated.
|
||||
*
|
||||
* @param digester The newly associated Digester instance
|
||||
*/
|
||||
@Override
|
||||
public void setDigester(Digester digester) {
|
||||
|
||||
this.digester = digester;
|
||||
for (Rule item : rules) {
|
||||
item.setDigester(digester);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the namespace URI that will be applied to all subsequently
|
||||
* added <code>Rule</code> objects.
|
||||
*/
|
||||
@Override
|
||||
public String getNamespaceURI() {
|
||||
return this.namespaceURI;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the namespace URI that will be applied to all subsequently
|
||||
* added <code>Rule</code> objects.
|
||||
*
|
||||
* @param namespaceURI Namespace URI that must match on all
|
||||
* subsequently added rules, or <code>null</code> for matching
|
||||
* regardless of the current namespace URI
|
||||
*/
|
||||
@Override
|
||||
public void setNamespaceURI(String namespaceURI) {
|
||||
|
||||
this.namespaceURI = namespaceURI;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Register a new Rule instance matching the specified pattern.
|
||||
*
|
||||
* @param pattern Nesting pattern to be matched for this Rule
|
||||
* @param rule Rule instance to be registered
|
||||
*/
|
||||
@Override
|
||||
public void add(String pattern, Rule rule) {
|
||||
// to help users who accidentally add '/' to the end of their patterns
|
||||
int patternLength = pattern.length();
|
||||
if (patternLength>1 && pattern.endsWith("/")) {
|
||||
pattern = pattern.substring(0, patternLength-1);
|
||||
}
|
||||
|
||||
|
||||
List<Rule> list = cache.get(pattern);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
cache.put(pattern, list);
|
||||
}
|
||||
list.add(rule);
|
||||
rules.add(rule);
|
||||
if (this.digester != null) {
|
||||
rule.setDigester(this.digester);
|
||||
}
|
||||
if (this.namespaceURI != null) {
|
||||
rule.setNamespaceURI(this.namespaceURI);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all existing Rule instance registrations.
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
cache.clear();
|
||||
rules.clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a List of all registered Rule instances that match the specified
|
||||
* nesting pattern, or a zero-length List if there are no matches. If more
|
||||
* than one Rule instance matches, they <strong>must</strong> be returned
|
||||
* in the order originally registered through the <code>add()</code>
|
||||
* method.
|
||||
*
|
||||
* @param namespaceURI Namespace URI for which to select matching rules,
|
||||
* or <code>null</code> to match regardless of namespace URI
|
||||
* @param pattern Nesting pattern to be matched
|
||||
*/
|
||||
@Override
|
||||
public List<Rule> match(String namespaceURI, String pattern) {
|
||||
|
||||
// List rulesList = (List) this.cache.get(pattern);
|
||||
List<Rule> rulesList = lookup(namespaceURI, pattern);
|
||||
if ((rulesList == null) || (rulesList.size() < 1)) {
|
||||
// Find the longest key, ie more discriminant
|
||||
String longKey = "";
|
||||
for (String key : this.cache.keySet()) {
|
||||
if (key.startsWith("*/")) {
|
||||
if (pattern.equals(key.substring(2)) ||
|
||||
pattern.endsWith(key.substring(1))) {
|
||||
if (key.length() > longKey.length()) {
|
||||
// rulesList = (List) this.cache.get(key);
|
||||
rulesList = lookup(namespaceURI, key);
|
||||
longKey = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rulesList == null) {
|
||||
rulesList = new ArrayList<>();
|
||||
}
|
||||
return rulesList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a List of all registered Rule instances, or a zero-length List
|
||||
* if there are no registered Rule instances. If more than one Rule
|
||||
* instance has been registered, they <strong>must</strong> be returned
|
||||
* in the order originally registered through the <code>add()</code>
|
||||
* method.
|
||||
*/
|
||||
@Override
|
||||
public List<Rule> rules() {
|
||||
return this.rules;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------ Protected Methods
|
||||
|
||||
|
||||
/**
|
||||
* Return a List of Rule instances for the specified pattern that also
|
||||
* match the specified namespace URI (if any). If there are no such
|
||||
* rules, return <code>null</code>.
|
||||
*
|
||||
* @param namespaceURI Namespace URI to match, or <code>null</code> to
|
||||
* select matching rules regardless of namespace URI
|
||||
* @param pattern Pattern to be matched
|
||||
* @return a rules list
|
||||
*/
|
||||
protected List<Rule> lookup(String namespaceURI, String pattern) {
|
||||
// Optimize when no namespace URI is specified
|
||||
List<Rule> list = this.cache.get(pattern);
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
if ((namespaceURI == null) || (namespaceURI.length() == 0)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
// Select only Rules that match on the specified namespace URI
|
||||
ArrayList<Rule> results = new ArrayList<>();
|
||||
for (Rule item : list) {
|
||||
if ((namespaceURI.equals(item.getNamespaceURI())) ||
|
||||
(item.getNamespaceURI() == null)) {
|
||||
results.add(item);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
166
java/org/apache/tomcat/util/digester/SetNextRule.java
Normal file
166
java/org/apache/tomcat/util/digester/SetNextRule.java
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
import org.apache.tomcat.util.IntrospectionUtils;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Rule implementation that calls a method on the (top-1) (parent)
|
||||
* object, passing the top object (child) as an argument. It is
|
||||
* commonly used to establish parent-child relationships.</p>
|
||||
*
|
||||
* <p>This rule now supports more flexible method matching by default.
|
||||
* It is possible that this may break (some) code
|
||||
* written against release 1.1.1 or earlier.
|
||||
* See {@link #isExactMatch()} for more details.</p>
|
||||
*/
|
||||
|
||||
public class SetNextRule extends Rule {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* Construct a "set next" rule with the specified method name.
|
||||
*
|
||||
* @param methodName Method name of the parent method to call
|
||||
* @param paramType Java class of the parent method's argument
|
||||
* (if you wish to use a primitive type, specify the corresponding
|
||||
* Java wrapper class instead, such as <code>java.lang.Boolean</code>
|
||||
* for a <code>boolean</code> parameter)
|
||||
*/
|
||||
public SetNextRule(String methodName,
|
||||
String paramType) {
|
||||
|
||||
this.methodName = methodName;
|
||||
this.paramType = paramType;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* The method name to call on the parent object.
|
||||
*/
|
||||
protected String methodName = null;
|
||||
|
||||
|
||||
/**
|
||||
* The Java class name of the parameter type expected by the method.
|
||||
*/
|
||||
protected String paramType = null;
|
||||
|
||||
/**
|
||||
* Should we use exact matching. Default is no.
|
||||
*/
|
||||
protected boolean useExactMatch = false;
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* <p>Is exact matching being used.</p>
|
||||
*
|
||||
* <p>This rule uses <code>org.apache.commons.beanutils.MethodUtils</code>
|
||||
* to introspect the relevant objects so that the right method can be called.
|
||||
* Originally, <code>MethodUtils.invokeExactMethod</code> was used.
|
||||
* This matches methods very strictly
|
||||
* and so may not find a matching method when one exists.
|
||||
* This is still the behaviour when exact matching is enabled.</p>
|
||||
*
|
||||
* <p>When exact matching is disabled, <code>MethodUtils.invokeMethod</code> is used.
|
||||
* This method finds more methods but is less precise when there are several methods
|
||||
* with correct signatures.
|
||||
* So, if you want to choose an exact signature you might need to enable this property.</p>
|
||||
*
|
||||
* <p>The default setting is to disable exact matches.</p>
|
||||
*
|
||||
* @return true iff exact matching is enabled
|
||||
* @since Digester Release 1.1.1
|
||||
*/
|
||||
public boolean isExactMatch() {
|
||||
|
||||
return useExactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set whether exact matching is enabled.</p>
|
||||
*
|
||||
* <p>See {@link #isExactMatch()}.</p>
|
||||
*
|
||||
* @param useExactMatch should this rule use exact method matching
|
||||
* @since Digester Release 1.1.1
|
||||
*/
|
||||
public void setExactMatch(boolean useExactMatch) {
|
||||
|
||||
this.useExactMatch = useExactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the end of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param name the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
*/
|
||||
@Override
|
||||
public void end(String namespace, String name) throws Exception {
|
||||
|
||||
// Identify the objects to be used
|
||||
Object child = digester.peek(0);
|
||||
Object parent = digester.peek(1);
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
if (parent == null) {
|
||||
digester.log.debug("[SetNextRule]{" + digester.match +
|
||||
"} Call [NULL PARENT]." +
|
||||
methodName + "(" + child + ")");
|
||||
} else {
|
||||
digester.log.debug("[SetNextRule]{" + digester.match +
|
||||
"} Call " + parent.getClass().getName() + "." +
|
||||
methodName + "(" + child + ")");
|
||||
}
|
||||
}
|
||||
|
||||
// Call the specified method
|
||||
IntrospectionUtils.callMethod1(parent, methodName,
|
||||
child, paramType, digester.getClassLoader());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("SetNextRule[");
|
||||
sb.append("methodName=");
|
||||
sb.append(methodName);
|
||||
sb.append(", paramType=");
|
||||
sb.append(paramType);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
93
java/org/apache/tomcat/util/digester/SetPropertiesRule.java
Normal file
93
java/org/apache/tomcat/util/digester/SetPropertiesRule.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.tomcat.util.digester;
|
||||
|
||||
|
||||
import org.apache.tomcat.util.IntrospectionUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Rule implementation that sets properties on the object at the top of the
|
||||
* stack, based on attributes with corresponding names.</p>
|
||||
*/
|
||||
|
||||
public class SetPropertiesRule extends Rule {
|
||||
|
||||
/**
|
||||
* Process the beginning of this element.
|
||||
*
|
||||
* @param namespace the namespace URI of the matching element, or an
|
||||
* empty string if the parser is not namespace aware or the element has
|
||||
* no namespace
|
||||
* @param theName the local name if the parser is namespace aware, or just
|
||||
* the element name otherwise
|
||||
* @param attributes The attribute list for this element
|
||||
*/
|
||||
@Override
|
||||
public void begin(String namespace, String theName, Attributes attributes)
|
||||
throws Exception {
|
||||
|
||||
// Populate the corresponding properties of the top object
|
||||
Object top = digester.peek();
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
if (top != null) {
|
||||
digester.log.debug("[SetPropertiesRule]{" + digester.match +
|
||||
"} Set " + top.getClass().getName() +
|
||||
" properties");
|
||||
} else {
|
||||
digester.log.debug("[SetPropertiesRule]{" + digester.match +
|
||||
"} Set NULL properties");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
String name = attributes.getLocalName(i);
|
||||
if ("".equals(name)) {
|
||||
name = attributes.getQName(i);
|
||||
}
|
||||
String value = attributes.getValue(i);
|
||||
|
||||
if (digester.log.isDebugEnabled()) {
|
||||
digester.log.debug("[SetPropertiesRule]{" + digester.match +
|
||||
"} Setting property '" + name + "' to '" +
|
||||
value + "'");
|
||||
}
|
||||
if (!digester.isFakeAttribute(top, name)
|
||||
&& !IntrospectionUtils.setProperty(top, name, value)
|
||||
&& digester.getRulesValidation()) {
|
||||
digester.log.warn("[SetPropertiesRule]{" + digester.match +
|
||||
"} Setting property '" + name + "' to '" +
|
||||
value + "' did not find a matching property.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a printable version of this Rule.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("SetPropertiesRule[");
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
1188
java/org/apache/tomcat/util/digester/package.html
Normal file
1188
java/org/apache/tomcat/util/digester/package.html
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user