sboag 00/11/15 08:18:47
Modified: java/src/org/apache/xalan/templates StylesheetRoot.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/utils DefaultErrorHandler.java
QName.java
java/src/org/apache/xpath VariableStack.java
Log:
Bug fixes for SPRs that have to do with output properties and param setting.
Revision Changes Path
1.22 +24 -41
xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
Index: StylesheetRoot.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- StylesheetRoot.java 2000/11/14 18:35:06 1.21
+++ StylesheetRoot.java 2000/11/15 16:18:45 1.22
@@ -137,6 +137,28 @@
return new TransformerImpl(this);
}
+
+ public Properties getDefaultOutputProps()
+ {
+ OutputFormat outputProps = m_outputFormatComposed;
+ Properties defaultProps = new Properties();
+ defaultProps.put(OutputKeys.METHOD, outputProps.getMethod());
+ defaultProps.put(OutputKeys.INDENT, outputProps.getIndent() ? "yes" :
"no");
+ if(null != outputProps.getDoctypePublicId())
+ defaultProps.put(OutputKeys.DOCTYPE_PUBLIC,
outputProps.getDoctypePublicId());
+ if(null != outputProps.getDoctypeSystemId())
+ defaultProps.put(OutputKeys.DOCTYPE_SYSTEM,
outputProps.getDoctypeSystemId());
+ if(null != outputProps.getMediaType())
+ defaultProps.put(OutputKeys.MEDIA_TYPE, outputProps.getMediaType());
+ defaultProps.put(OutputKeys.OMIT_XML_DECLARATION,
outputProps.getOmitXMLDeclaration() ? "yes" : "no");
+ defaultProps.put(OutputKeys.STANDALONE, outputProps.getStandalone() ?
"yes" : "no");
+ if(null != outputProps.getEncoding())
+ defaultProps.put(OutputKeys.ENCODING, outputProps.getEncoding());
+ if(null != outputProps.getVersion())
+ defaultProps.put(OutputKeys.VERSION, outputProps.getVersion());
+ return defaultProps;
+ }
+
/**
* Get the static properties for xsl:output. The object returned will
* be a clone of the internal values, and thus it can be mutated
@@ -149,47 +171,8 @@
* @return A Properties object, not null.
*/
public Properties getOutputProperties()
- {
- Properties oprops = new Properties();
-
- if (m_outputFormatComposed instanceof OutputFormatExtended)
- {
- OutputFormatExtended ofe = (OutputFormatExtended)
m_outputFormatComposed;
- if(ofe.methodHasBeenSet())
- oprops.put(OutputKeys.METHOD, ofe.getMethod());
- if(ofe.indentHasBeenSet())
- oprops.put(OutputKeys.INDENT, ofe.getIndent() ? "yes" : "no");
- if(ofe.doctypePublicHasBeenSet())
- oprops.put(OutputKeys.DOCTYPE_PUBLIC, ofe.getDoctypePublicId());
- if(ofe.doctypeSystemHasBeenSet())
- oprops.put(OutputKeys.DOCTYPE_SYSTEM, ofe.getDoctypeSystemId());
- if(ofe.mediaTypeHasBeenSet())
- oprops.put(OutputKeys.MEDIA_TYPE, ofe.getMediaType());
- if(ofe.omitXmlDeclarationHasBeenSet())
- oprops.put(OutputKeys.OMIT_XML_DECLARATION,
ofe.getOmitXMLDeclaration() ? "yes" : "no");
- if(ofe.standaloneHasBeenSet())
- oprops.put(OutputKeys.STANDALONE, ofe.getStandalone() ? "yes" :
"no");
- if(ofe.encodingHasBeenSet())
- oprops.put(OutputKeys.ENCODING, ofe.getEncoding());
- if(ofe.versionHasBeenSet())
- oprops.put(OutputKeys.VERSION, ofe.getVersion());
- }
- else
- {
- OutputFormat ofe = m_outputFormatComposed;
- // Just set them all for now.
- oprops.put(OutputKeys.METHOD, ofe.getMethod());
- oprops.put(OutputKeys.INDENT, ofe.getIndent() ? "yes" : "no");
- oprops.put(OutputKeys.DOCTYPE_PUBLIC, ofe.getDoctypePublicId());
- oprops.put(OutputKeys.DOCTYPE_SYSTEM, ofe.getDoctypeSystemId());
- oprops.put(OutputKeys.MEDIA_TYPE, ofe.getMediaType());
- oprops.put(OutputKeys.OMIT_XML_DECLARATION,
ofe.getOmitXMLDeclaration() ? "yes" : "no");
- oprops.put(OutputKeys.STANDALONE, ofe.getStandalone() ? "yes" : "no");
- oprops.put(OutputKeys.ENCODING, ofe.getEncoding());
- oprops.put(OutputKeys.VERSION, ofe.getVersion());
- }
-
- return oprops;
+ {
+ return getDefaultOutputProps();
}
/**
1.50 +55 -44
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- TransformerImpl.java 2000/11/14 18:56:26 1.49
+++ TransformerImpl.java 2000/11/15 16:18:46 1.50
@@ -328,7 +328,7 @@
/**
* The SAX error handler, where errors and warnings are sent.
*/
- private ErrorListener m_errorHandler = null;
+ private ErrorListener m_errorHandler = new
org.apache.xalan.utils.DefaultErrorHandler();
/**
* The trace manager.
@@ -633,13 +633,20 @@
* XMLReader recognizes the property name but
* cannot set the requested value.
*
- * @throws TransformerException
+ * @throws IllegalArgumentException If the property is not supported,
+ * and is not namespaced.
*/
- public String getOutputProperty(String name)
+ public String getOutputProperty(String qnameString)
+ throws IllegalArgumentException
{
- if (m_outputFormat instanceof OutputFormatExtended)
+ OutputFormat of = getOutputFormat();
+ QName qname = QName.getQNameFromString(qnameString);
+ if(qname.getNamespace() != null)
+ return null; // fix
+ String name = qname.getLocalName();
+ if (of instanceof OutputFormatExtended)
{
- OutputFormatExtended ofe = (OutputFormatExtended) m_outputFormat;
+ OutputFormatExtended ofe = (OutputFormatExtended) of;
if(name.equals(OutputKeys.METHOD))
return ofe.methodHasBeenSet() ? ofe.getMethod() : null;
else if(name.equals(OutputKeys.INDENT))
@@ -658,34 +665,37 @@
return ofe.encodingHasBeenSet() ? ofe.getEncoding() : null;
else if(name.equals(OutputKeys.VERSION))
return ofe.versionHasBeenSet() ? ofe.getVersion() : null;
+ else
+ throw new IllegalArgumentException("output property not recognized:
"+qnameString);
+
}
else
{
- OutputFormat ofe = m_outputFormat;
// Just set them all for now.
if(name.equals(OutputKeys.METHOD))
- return ofe.getMethod();
+ return of.getMethod();
else if(name.equals(OutputKeys.INDENT))
- return ofe.getIndent() ? "yes" : "no";
+ return of.getIndent() ? "yes" : "no";
else if(name.equals(OutputKeys.DOCTYPE_PUBLIC))
- return ofe.getDoctypePublicId();
+ return of.getDoctypePublicId();
else if(name.equals(OutputKeys.DOCTYPE_SYSTEM))
- return ofe.getDoctypeSystemId();
+ return of.getDoctypeSystemId();
else if(name.equals(OutputKeys.MEDIA_TYPE))
- return ofe.getMediaType();
+ return of.getMediaType();
else if(name.equals(OutputKeys.OMIT_XML_DECLARATION))
- return ofe.getOmitXMLDeclaration() ? "yes" : "no";
+ return of.getOmitXMLDeclaration() ? "yes" : "no";
else if(name.equals(OutputKeys.STANDALONE))
- return ofe.getStandalone() ? "yes" : "no";
+ return of.getStandalone() ? "yes" : "no";
else if(name.equals(OutputKeys.ENCODING))
- return ofe.getEncoding();
+ return of.getEncoding();
else if(name.equals(OutputKeys.VERSION))
- return ofe.getVersion();
+ return of.getVersion();
+ else
+ throw new IllegalArgumentException("output property not recognized:
"+qnameString);
}
- return null;
}
-
+
/**
* Set the value of a property. Recognized properties are:
*
@@ -706,9 +716,7 @@
public void setOutputProperty(String name, String value)
throws IllegalArgumentException
{
- OutputFormat ofe = m_outputFormat;
- if(null == ofe)
- ofe = m_stylesheetRoot.getOutputComposed();
+ OutputFormat ofe = getOutputFormat();
if(name == OutputKeys.METHOD)
ofe.setMethod(value);
@@ -763,9 +771,7 @@
public void setOutputProperties(Properties oformat)
{
Enumeration names = oformat.propertyNames();
- OutputFormat ofe = m_outputFormat;
- if(null == ofe)
- ofe = m_stylesheetRoot.getOutputComposed();
+ OutputFormat ofe = getOutputFormat();
while(names.hasMoreElements())
{
String name = (String)names.nextElement();
@@ -803,12 +809,11 @@
*/
public Properties getOutputProperties()
{
- Properties oprops = new Properties();
-
- OutputFormat outputProps = m_outputFormat;
- if(null == outputProps)
- outputProps = m_stylesheetRoot.getOutputComposed();
-
+ OutputFormat outputProps = getOutputFormat();
+ Properties defaultProps = m_stylesheetRoot.getDefaultOutputProps();
+
+ Properties oprops = new Properties(defaultProps);
+
if (outputProps instanceof OutputFormatExtended)
{
OutputFormatExtended ofe = (OutputFormatExtended) outputProps;
@@ -1301,7 +1306,7 @@
QName qname = new QName(namespace, name);
XObject xobject = XObject.create(value);
- varstack.pushVariable(qname, xobject);
+ varstack.pushOrReplaceVariable(qname, xobject);
}
Vector m_userParams;
@@ -1329,14 +1334,12 @@
m_userParams = new Vector();
if(null == s2)
{
- m_userParams.addElement(new Arg(new QName(s1),
- new XObject(value)));
+ replaceOrPushUserParam(new QName(s1), new XObject(value));
setParameter(s1, null, value);
}
else
{
- m_userParams.addElement(new Arg(new QName(s1, s2),
- new XObject(value)));
+ replaceOrPushUserParam(new QName(s1, s2), new XObject(value));
setParameter(s2, s1, value);
}
@@ -1347,6 +1350,21 @@
}
}
+ private void replaceOrPushUserParam(QName qname, XObject xval)
+ {
+ int n = m_userParams.size();
+ for(int i = n-1; i >= 0; i--)
+ {
+ Arg arg = (Arg)m_userParams.elementAt(i);
+ if(arg.getQName().equals(qname))
+ {
+ m_userParams.setElementAt(new Arg(qname, xval), i);
+ return;
+ }
+ }
+ m_userParams.addElement(new Arg(qname, xval));
+ }
+
/**
* Get a parameter that was explicitly set with setParameter
* or setParameters.
@@ -1358,24 +1376,17 @@
*/
public Object getParameter(String name)
{
- StringTokenizer tokenizer = new StringTokenizer(name, "{}", false);
try
{
- VariableStack varstack = getXPathContext().getVarStack();
+ // VariableStack varstack = getXPathContext().getVarStack();
// The first string might be the namespace, or it might be
// the local name, if the namespace is null.
- QName qname;
- String s1 = tokenizer.nextToken();
- String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
- if(null == s2)
- qname = new QName(null, s1);
- else
- qname = new QName(s1, s2);
+ QName qname = QName.getQNameFromString(name);
if(null == m_userParams)
return null;
int n = m_userParams.size();
- for(int i = 0; i < n; i++)
+ for(int i = n-1; i >= 0; i--)
{
Arg arg = (Arg)m_userParams.elementAt(i);
if(arg.getQName().equals(qname))
1.4 +0 -3
xml-xalan/java/src/org/apache/xalan/utils/DefaultErrorHandler.java
Index: DefaultErrorHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/utils/DefaultErrorHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultErrorHandler.java 2000/11/13 16:27:24 1.3
+++ DefaultErrorHandler.java 2000/11/15 16:18:46 1.4
@@ -70,9 +70,6 @@
/**
* Constructor DefaultErrorHandler
- *
- *
- * NEEDSDOC @param identifier
*/
public DefaultErrorHandler()
{
1.9 +14 -0 xml-xalan/java/src/org/apache/xalan/utils/QName.java
Index: QName.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/utils/QName.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- QName.java 2000/11/13 16:27:24 1.8
+++ QName.java 2000/11/15 16:18:46 1.9
@@ -57,6 +57,7 @@
package org.apache.xalan.utils;
import java.util.Stack;
+import java.util.StringTokenizer;
import org.w3c.dom.Element;
@@ -161,6 +162,19 @@
&& (((null != thisnamespace) && (null != thatnamespace))
? thisnamespace.equals(thatnamespace)
: ((null == thisnamespace) && (null == thatnamespace)));
+ }
+
+ public static QName getQNameFromString(String name)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(name, "{}", false);
+ QName qname;
+ String s1 = tokenizer.nextToken();
+ String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
+ if(null == s2)
+ qname = new QName(null, s1);
+ else
+ qname = new QName(s1, s2);
+ return qname;
}
/**
1.11 +25 -0 xml-xalan/java/src/org/apache/xpath/VariableStack.java
Index: VariableStack.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/VariableStack.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- VariableStack.java 2000/11/13 16:27:26 1.10
+++ VariableStack.java 2000/11/15 16:18:46 1.11
@@ -214,6 +214,31 @@
setSize(newSize);
}
+
+ /**
+ * Push an argument onto the stack, or replace it
+ * if it already exists. Don't forget
+ * to call startContext before pushing a series of
+ * arguments for a given macro call.
+ *
+ * @param qname The qualified name of the variable.
+ * @param val The wrapped value of the variable.
+ */
+ public void pushOrReplaceVariable(QName qname, XObject xval)
+ {
+ int n = this.size();
+ for(int i = n-1; i >= 0; i--)
+ {
+ Arg arg = (Arg)this.elementAt(i);
+ if(arg.getQName().equals(qname))
+ {
+ this.setElementAt(new Arg(qname, xval), i);
+ return;
+ }
+ }
+ push(new Arg(qname, xval, false));
+ }
+
/**
* Push an argument onto the stack. Don't forget