You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/08 06:52:22 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml CopyTag.java SetTag.java ElementTag.java
dion 2004/09/07 21:52:22
Modified: jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml
CopyTag.java SetTag.java ElementTag.java
Log:
detab
Revision Changes Path
1.6 +17 -17 jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyTag.java
Index: CopyTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CopyTag.java 27 Aug 2004 04:37:45 -0000 1.5
+++ CopyTag.java 8 Sep 2004 04:52:22 -0000 1.6
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed 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.
@@ -24,8 +24,8 @@
import org.jaxen.XPath;
import org.xml.sax.SAXException;
-/**
- * A tag which performs a copy operation like the XSLT tag,
+/**
+ * A tag which performs a copy operation like the XSLT tag,
* performing a shallow copy of the element and its attributes but no content.
*
* @author James Strachan
@@ -34,7 +34,7 @@
/** The XPath expression to evaluate. */
private XPath select;
-
+
/** Should we output lexical XML data like entity names?
*/
private boolean lexical;
@@ -43,28 +43,28 @@
}
// Tag interface
- //-------------------------------------------------------------------------
- public void doTag(XMLOutput output) throws JellyTagException {
- Object xpathContext = getXPathContext();
+ //-------------------------------------------------------------------------
+ public void doTag(XMLOutput output) throws JellyTagException {
+ Object xpathContext = getXPathContext();
Object node = xpathContext;
-
+
try {
- if (select != null) {
+ if (select != null) {
node = select.selectSingleNode(xpathContext);
- }
+ }
if ( node instanceof Element ) {
Element element = (Element) node;
-
+
SAXWriter saxWriter;
-
+
if (lexical) {
saxWriter = new SAXWriter(output, output);
} else {
saxWriter = new SAXWriter(output);
}
-
+
saxWriter.writeOpen(element);
invokeBody(output);
saxWriter.writeClose(element);
@@ -72,7 +72,7 @@
else {
invokeBody(output);
}
- }
+ }
catch (SAXException e) {
throw new JellyTagException(e);
}
@@ -82,7 +82,7 @@
}
// Properties
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
/** Sets the XPath expression to evaluate. */
public void setSelect(XPath select) {
this.select = select;
1.7 +42 -42 jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
Index: SetTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SetTag.java 21 Jun 2004 11:20:11 -0000 1.6
+++ SetTag.java 8 Sep 2004 04:52:22 -0000 1.7
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed 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.
@@ -35,7 +35,7 @@
* (for example {@link org.dom4j.Element} or {@link org.dom4j.Attribute}).
* Thus, the variable created from xml:set can be
* used from the other xml library functions.
- *
+ *
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
@@ -43,24 +43,24 @@
/** The Log to which logging calls will be made. */
private Log log = LogFactory.getLog(SetTag.class);
-
+
/** The variable name to export. */
private String var;
-
- /** The XPath expression to evaluate. */
+
+ /** The XPath expression to evaluate. */
private XPath select;
-
+
/** Xpath comparator for sorting */
private XPathComparator xpCmp = null;
-
- private boolean single=false;
+
+ private boolean single=false;
public SetTag() {
}
-
+
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
if (var == null) {
throw new MissingAttributeException( "var" );
@@ -68,12 +68,12 @@
if (select == null) {
throw new MissingAttributeException( "select" );
}
-
- Object xpathContext = getXPathContext();
+
+ Object xpathContext = getXPathContext();
Object value = null;
- try {
+ try {
value = select.evaluate(xpathContext);
- }
+ }
catch (JaxenException e) {
throw new JellyTagException(e);
}
@@ -84,45 +84,45 @@
Collections.sort((List)value, xpCmp);
}
}
- if (single==true) {
- if(value instanceof List) {
- List l = (List) value;
- if (l.size()==0)
- value=null;
- else
- value=l.get(0);
- }
- }
-
+ if (single==true) {
+ if(value instanceof List) {
+ List l = (List) value;
+ if (l.size()==0)
+ value=null;
+ else
+ value=l.get(0);
+ }
+ }
+
//log.info( "Evaluated xpath: " + select + " as: " + value + " of type: " + value.getClass().getName() );
-
+
context.setVariable(var, value);
}
-
+
// Properties
- //-------------------------------------------------------------------------
-
+ //-------------------------------------------------------------------------
+
/** Sets the variable name to define for this expression
*/
public void setVar(String var) {
this.var = var;
}
-
+
/** Sets the XPath expression to evaluate. */
public void setSelect(XPath select) {
this.select = select;
}
-
- /** If set to true will only take the first element matching.
- It then guarantees that the result is of type
- {@link org.dom4j.Node} thereby making sure that, for example,
- when an element is selected, one can directly call such methods
- as setAttribute.
- */
- public void setSingle(boolean single) {
- this.single = single;
- }
+
+ /** If set to true will only take the first element matching.
+ It then guarantees that the result is of type
+ {@link org.dom4j.Node} thereby making sure that, for example,
+ when an element is selected, one can directly call such methods
+ as setAttribute.
+ */
+ public void setSingle(boolean single) {
+ this.single = single;
+ }
/** Sets the xpath expression to use to sort selected nodes.
1.5 +90 -90 jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ElementTag.java
Index: ElementTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ElementTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ElementTag.java 25 Feb 2004 01:31:50 -0000 1.4
+++ ElementTag.java 8 Sep 2004 04:52:22 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed 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.
@@ -22,46 +22,46 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-/** A tag to produce an XML element which can contain other attributes
+/** A tag to produce an XML element which can contain other attributes
* or elements like the <code><xsl:element></code> tag.
*
* @author James Strachan
* @version $Revision$
*/
public class ElementTag extends TagSupport {
-
+
/** The namespace URI */
private String namespace;
-
+
/** The qualified name */
private String name;
-
+
/** The XML Attributes */
private AttributesImpl attributes = new AttributesImpl();
- /** flag set if attributes are output */
- private boolean outputAttributes;
-
+ /** flag set if attributes are output */
+ private boolean outputAttributes;
+
public ElementTag() {
}
- /**
- * Sets the attribute of the given name to the specified value.
- *
- * @param name of the attribute
- * @param value of the attribute
- * @throws JellyException if the start element has already been output.
- * Attributes must be set on the outer element before any content
- * (child elements or text) is output
- */
+ /**
+ * Sets the attribute of the given name to the specified value.
+ *
+ * @param name of the attribute
+ * @param value of the attribute
+ * @throws JellyException if the start element has already been output.
+ * Attributes must be set on the outer element before any content
+ * (child elements or text) is output
+ */
public void setAttributeValue( String name, String value ) throws JellyTagException {
- if (outputAttributes) {
- throw new JellyTagException(
- "Cannot set the value of attribute: "
- + name + " as we have already output the startElement() SAX event"
- );
- }
-
+ if (outputAttributes) {
+ throw new JellyTagException(
+ "Cannot set the value of attribute: "
+ + name + " as we have already output the startElement() SAX event"
+ );
+ }
+
// ### we'll assume that all attributes are in no namespace!
// ### this is severely limiting!
// ### we should be namespace aware
@@ -69,109 +69,109 @@
if (index >= 0) {
attributes.removeAttribute(index);
}
- // treat null values as no attribute
+ // treat null values as no attribute
if (value != null) {
attributes.addAttribute("", name, name, "CDATA", value);
}
}
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws JellyTagException {
int idx = name.indexOf(':');
- final String localName = (idx >= 0)
- ? name.substring(idx + 1)
- : name;
-
+ final String localName = (idx >= 0)
+ ? name.substring(idx + 1)
+ : name;
+
outputAttributes = false;
-
+
XMLOutput newOutput = new XMLOutput(output) {
- // add an initialize hook to the core content-generating methods
-
- public void startElement(
- String uri,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
- initialize();
- super.startElement(uri, localName, qName, atts);
- }
-
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- initialize();
- super.endElement(uri, localName, qName);
- }
-
- public void characters(char ch[], int start, int length) throws SAXException {
- initialize();
- super.characters(ch, start, length);
- }
-
- public void ignorableWhitespace(char ch[], int start, int length)
- throws SAXException {
- initialize();
- super.ignorableWhitespace(ch, start, length);
- }
- public void processingInstruction(String target, String data)
- throws SAXException {
- initialize();
- super.processingInstruction(target, data);
- }
-
- /**
- * Ensure that the outer start element is generated
- * before any content is output
- */
- protected void initialize() throws SAXException {
- if (!outputAttributes) {
- super.startElement(namespace, localName, name, attributes);
- outputAttributes = true;
- }
- }
+ // add an initialize hook to the core content-generating methods
+
+ public void startElement(
+ String uri,
+ String localName,
+ String qName,
+ Attributes atts)
+ throws SAXException {
+ initialize();
+ super.startElement(uri, localName, qName, atts);
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ initialize();
+ super.endElement(uri, localName, qName);
+ }
+
+ public void characters(char ch[], int start, int length) throws SAXException {
+ initialize();
+ super.characters(ch, start, length);
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException {
+ initialize();
+ super.ignorableWhitespace(ch, start, length);
+ }
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ initialize();
+ super.processingInstruction(target, data);
+ }
+
+ /**
+ * Ensure that the outer start element is generated
+ * before any content is output
+ */
+ protected void initialize() throws SAXException {
+ if (!outputAttributes) {
+ super.startElement(namespace, localName, name, attributes);
+ outputAttributes = true;
+ }
+ }
};
-
+
invokeBody(newOutput);
-
+
try {
if (!outputAttributes) {
- output.startElement(namespace, localName, name, attributes);
- outputAttributes = true;
+ output.startElement(namespace, localName, name, attributes);
+ outputAttributes = true;
}
-
+
output.endElement(namespace, localName, name);
attributes.clear();
} catch (SAXException e) {
throw new JellyTagException(e);
}
}
-
+
// Properties
//-------------------------------------------------------------------------
-
- /**
+
+ /**
* @return the qualified name of the element
*/
public String getName() {
return name;
}
-
- /**
+
+ /**
* Sets the qualified name of the element
*/
public void setName(String name) {
this.name = name;
}
-
+
/**
* @return the namespace URI of the element
*/
public String getURI() {
return namespace;
}
-
+
/**
* Sets the namespace URI of the element
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org