You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2003/06/11 02:10:33 UTC
cvs commit: cocoon-2.0/src/java/org/apache/cocoon/serialization AbstractTextSerializer.java
joerg 2003/06/10 17:10:33
Modified: src/java/org/apache/cocoon/serialization
AbstractTextSerializer.java
Log:
not more than simple code formatting
Revision Changes Path
1.3 +70 -78 cocoon-2.0/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
Index: AbstractTextSerializer.java
===================================================================
RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractTextSerializer.java 19 Mar 2003 17:18:57 -0000 1.2
+++ AbstractTextSerializer.java 11 Jun 2003 00:10:33 -0000 1.3
@@ -62,6 +62,7 @@
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
@@ -90,9 +91,8 @@
* @author <a href="mailto:sylvain.wallez@anyware-tech.com">Sylvain Wallez</a>
* @version CVS $Id$
*/
-public abstract class AbstractTextSerializer
-extends AbstractSerializer
-implements Configurable, Cacheable {
+public abstract class AbstractTextSerializer extends AbstractSerializer
+ implements Configurable, Cacheable {
/**
* The trax <code>TransformerFactory</code> used by this serializer.
@@ -164,16 +164,14 @@
/**
* Helper for TransformerFactory.
*/
- protected SAXTransformerFactory getTransformerFactory()
- {
+ protected SAXTransformerFactory getTransformerFactory() {
return tfactory;
}
/**
* Helper for TransformerHandler.
*/
- protected TransformerHandler getTransformerHandler()
- throws javax.xml.transform.TransformerException {
+ protected TransformerHandler getTransformerHandler() throws TransformerException {
return this.getTransformerFactory().newTransformerHandler();
}
@@ -181,8 +179,7 @@
* Set the {@link OutputStream} where the requested resource should
* be serialized.
*/
- public void setOutputStream(OutputStream out)
- throws IOException {
+ public void setOutputStream(OutputStream out) throws IOException {
/*
* Add a level of buffering to the output stream. Xalan serializes
* every character individually. In conjunction with chunked
@@ -190,8 +187,7 @@
* increase of data on the wire.
*/
if (outputBufferSize > 0) {
- super.setOutputStream(
- new BufferedOutputStream(out, outputBufferSize));
+ super.setOutputStream(new BufferedOutputStream(out, outputBufferSize));
} else {
super.setOutputStream(out);
}
@@ -200,13 +196,13 @@
/**
* Set the configurations for this serializer.
*/
- public void configure(Configuration conf)
- throws ConfigurationException {
+ public void configure(Configuration conf) throws ConfigurationException {
// configure buffer size
Configuration bsc = conf.getChild("buffer-size", false);
- if(null != bsc)
- outputBufferSize = bsc.getValueAsInteger(DEFAULT_BUFFER_SIZE);
+ if (null != bsc) {
+ outputBufferSize = bsc.getValueAsInteger(DEFAULT_BUFFER_SIZE);
+ }
// configure xalan
Configuration cdataSectionElements = conf.getChild("cdata-section-elements");
@@ -220,53 +216,53 @@
Configuration standAlone = conf.getChild("standalone");
Configuration version = conf.getChild("version");
- if (! cdataSectionElements.getLocation().equals("-")) {
- format.put(OutputKeys.CDATA_SECTION_ELEMENTS,cdataSectionElements.getValue());
+ if (!cdataSectionElements.getLocation().equals("-")) {
+ format.put(OutputKeys.CDATA_SECTION_ELEMENTS, cdataSectionElements.getValue());
}
- if (! dtPublic.getLocation().equals("-")) {
- format.put(OutputKeys.DOCTYPE_PUBLIC,dtPublic.getValue());
+ if (!dtPublic.getLocation().equals("-")) {
+ format.put(OutputKeys.DOCTYPE_PUBLIC, dtPublic.getValue());
}
- if (! dtSystem.getLocation().equals("-")) {
- format.put(OutputKeys.DOCTYPE_SYSTEM,dtSystem.getValue());
+ if (!dtSystem.getLocation().equals("-")) {
+ format.put(OutputKeys.DOCTYPE_SYSTEM, dtSystem.getValue());
}
- if (! encoding.getLocation().equals("-")) {
- format.put(OutputKeys.ENCODING,encoding.getValue());
+ if (!encoding.getLocation().equals("-")) {
+ format.put(OutputKeys.ENCODING, encoding.getValue());
}
- if (! indent.getLocation().equals("-")) {
- format.put(OutputKeys.INDENT,indent.getValue());
+ if (!indent.getLocation().equals("-")) {
+ format.put(OutputKeys.INDENT, indent.getValue());
}
- if (! mediaType.getLocation().equals("-")) {
- format.put(OutputKeys.MEDIA_TYPE,mediaType.getValue());
+ if (!mediaType.getLocation().equals("-")) {
+ format.put(OutputKeys.MEDIA_TYPE, mediaType.getValue());
}
- if (! method.getLocation().equals("-")) {
- format.put(OutputKeys.METHOD,method.getValue());
+ if (!method.getLocation().equals("-")) {
+ format.put(OutputKeys.METHOD, method.getValue());
}
- if (! omitXMLDeclaration.getLocation().equals("-")) {
- format.put(OutputKeys.OMIT_XML_DECLARATION,omitXMLDeclaration.getValue());
+ if (!omitXMLDeclaration.getLocation().equals("-")) {
+ format.put(OutputKeys.OMIT_XML_DECLARATION, omitXMLDeclaration.getValue());
}
- if (! standAlone.getLocation().equals("-")) {
- format.put(OutputKeys.STANDALONE,standAlone.getValue());
+ if (!standAlone.getLocation().equals("-")) {
+ format.put(OutputKeys.STANDALONE, standAlone.getValue());
}
- if (! version.getLocation().equals("-")) {
- format.put(OutputKeys.VERSION,version.getValue());
+ if (!version.getLocation().equals("-")) {
+ format.put(OutputKeys.VERSION, version.getValue());
}
-
+
Configuration tFactoryConf = conf.getChild("transformer-factory", false);
if (tFactoryConf != null) {
String tFactoryClass = tFactoryConf.getValue();
try {
- this.tfactory = (SAXTransformerFactory)ClassUtils.newInstance(tFactoryClass);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Using transformer factory " + tFactoryClass);
- }
- } catch(Exception e) {
- throw new ConfigurationException("Cannot load transformer factory " + tFactoryClass, e);
+ this.tfactory = (SAXTransformerFactory) ClassUtils.newInstance(tFactoryClass);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Using transformer factory " + tFactoryClass);
+ }
+ } catch (Exception e) {
+ throw new ConfigurationException("Cannot load transformer factory " + tFactoryClass, e);
}
} else {
- // Standard TrAX behaviour
- this.tfactory = (SAXTransformerFactory)TransformerFactory.newInstance();
+ // Standard TrAX behaviour
+ this.tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
}
-
+
tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
// Check if we need namespace as attributes.
@@ -276,7 +272,7 @@
this.namespacePipe = new NamespaceAsAttributes();
this.namespacePipe.setLogger(getLogger());
}
- } catch(Exception e) {
+ } catch (Exception e) {
getLogger().warn("Cannot know if transformer needs namespaces attributes - assuming NO.", e);
}
}
@@ -289,7 +285,6 @@
}
}
-
/**
* Generate the unique key.
* This key must be unique inside the space of this component.
@@ -326,7 +321,7 @@
SAXTransformerFactory factory = getTransformerFactory();
- Boolean cacheValue = (Boolean)needsNamespaceCache.get(factory.getClass().getName());
+ Boolean cacheValue = (Boolean) needsNamespaceCache.get(factory.getClass().getName());
if (cacheValue != null) {
return cacheValue.booleanValue();
@@ -355,8 +350,7 @@
// Check if the namespace is there (replace " by ' to be sure of what we search in)
boolean needsIt = (text.replace('"', '\'').indexOf(check) == -1);
- String msg = needsIt ? " needs namespace attributes (will be slower)." :
- " handles correctly namespaces.";
+ String msg = needsIt ? " needs namespace attributes (will be slower)." : " handles correctly namespaces.";
getLogger().debug("Trax handler " + handler.getClass().getName() + msg);
@@ -409,8 +403,7 @@
* Track mappings to be able to add <code>xmlns:</code> attributes
* in <code>startElement()</code>.
*/
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
// Store the mappings to reconstitute xmlns:attributes
// except prefixes starting with "xml": these are reserved
// VG: (uri != null) fixes NPE in startElement
@@ -421,7 +414,7 @@
// append the prefix colon now, in order to save concatenations later, but
// only for non-empty prefixes.
- if(prefix.length() > 0) {
+ if (prefix.length() > 0) {
this.uriToPrefixMap.put(uri, prefix + ":");
} else {
this.uriToPrefixMap.put(uri, prefix);
@@ -439,11 +432,12 @@
* ignores <code>start/endPrefixMapping()</code>.
*/
public void startElement(String eltUri, String eltLocalName, String eltQName, Attributes attrs)
- throws SAXException {
+ throws SAXException {
// try to restore the qName. The map already contains the colon
- if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri))
- eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+ if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
+ eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+ }
if (this.hasMappings) {
// Add xmlns* attributes where needed
@@ -454,11 +448,11 @@
int mappingCount = this.prefixList.size();
int attrCount = attrs.getLength();
- for(int mapping = 0; mapping < mappingCount; mapping++) {
+ for (int mapping = 0; mapping < mappingCount; mapping++) {
// Build infos for this namespace
- String uri = (String)this.uriList.get(mapping);
- String prefix = (String)this.prefixList.get(mapping);
+ String uri = (String) this.uriList.get(mapping);
+ String prefix = (String) this.prefixList.get(mapping);
String qName = prefix.equals("") ? "xmlns" : ("xmlns:" + prefix);
// Search for the corresponding xmlns* attribute
@@ -466,8 +460,9 @@
for (int attr = 0; attr < attrCount; attr++) {
if (qName.equals(attrs.getQName(attr))) {
// Check if mapping and attribute URI match
- if (! uri.equals(attrs.getValue(attr))) {
- getLogger().error("URI in prefix mapping and attribute do not match : '" + uri + "' - '" + attrs.getURI(attr) + "'");
+ if (!uri.equals(attrs.getValue(attr))) {
+ getLogger().error("URI in prefix mapping and attribute do not match : '"
+ + uri + "' - '" + attrs.getURI(attr) + "'");
throw new SAXException("URI in prefix mapping and attribute do not match");
}
found = true;
@@ -480,10 +475,11 @@
if (newAttrs == null) {
// Need to test if attrs is empty or we go into an infinite loop...
// Well know SAX bug which I spent 3 hours to remind of :-(
- if (attrCount == 0)
+ if (attrCount == 0) {
newAttrs = new AttributesImpl();
- else
+ } else {
newAttrs = new AttributesImpl(attrs);
+ }
}
if (prefix.equals("")) {
@@ -499,8 +495,7 @@
// Start element with new attributes, if any
super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs);
- }
- else {
+ } else {
// Normal job
super.startElement(eltUri, eltLocalName, eltQName, attrs);
}
@@ -511,12 +506,11 @@
* Receive notification of the end of an element.
* Try to restore the element qName.
*/
- public void endElement(String eltUri, String eltLocalName, String eltQName)
- throws SAXException {
+ public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException {
// try to restore the qName. The map already contains the colon
- if(null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
- eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
-
+ if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
+ eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+ }
super.endElement(eltUri, eltLocalName, eltQName);
}
@@ -524,14 +518,13 @@
* End the scope of a prefix-URI mapping:
* remove entry from mapping tables.
*/
- public void endPrefixMapping(String prefix)
- throws SAXException {
+ public void endPrefixMapping(String prefix) throws SAXException {
// remove mappings for xalan-bug-workaround.
// Unfortunately, we're not passed the uri, but the prefix here,
// so we need to maintain maps in both directions.
- if(this.prefixToUriMap.containsKey(prefix)) {
- this.uriToPrefixMap.remove((String) this.prefixToUriMap.get(prefix));
- this.prefixToUriMap.remove(prefix);
+ if (this.prefixToUriMap.containsKey(prefix)) {
+ this.uriToPrefixMap.remove(this.prefixToUriMap.get(prefix));
+ this.prefixToUriMap.remove(prefix);
}
super.endPrefixMapping(prefix);
@@ -548,8 +541,7 @@
super.endDocument();
}
- private void clearMappings()
- {
+ private void clearMappings() {
this.hasMappings = false;
this.prefixList.clear();
this.uriList.clear();