Author: vgritsenko
Date: Thu May 5 11:28:46 2005
New Revision: 168368
URL: http://svn.apache.org/viewcvs?rev=168368&view=rev
Log:
AbstractSAXTransformer:
- implement Disposable
- group methods by interface
- add method findPrefixMapping
Call super.recycle last.
Call super.dispose.
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
cocoon/trunk/src/java/org/apache/cocoon/transformation/JPathTransformer.java
cocoon/trunk/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java
cocoon/trunk/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java?rev=168368&r1=168367&r2=168368&view=diff
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
Thu May 5 11:28:46 2005
@@ -15,15 +15,8 @@
*/
package org.apache.cocoon.transformation;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Stack;
-
import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -31,9 +24,8 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
+
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.TraxErrorHandler;
import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
@@ -41,11 +33,14 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.helpers.ParametersRecorder;
import org.apache.cocoon.transformation.helpers.TextRecorder;
+import org.apache.cocoon.util.ClassUtils;
+import org.apache.cocoon.util.TraxErrorHandler;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.cocoon.xml.SaxBuffer;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.xml.dom.DOMBuilder;
+
import org.apache.excalibur.source.SourceParameters;
import org.apache.excalibur.xml.sax.XMLizable;
import org.w3c.dom.Document;
@@ -57,8 +52,15 @@
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
-import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Stack;
/**
* This class is the basis for all transformers. It provides various useful
@@ -102,9 +104,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version $Id$
*/
-public abstract class AbstractSAXTransformer
- extends AbstractTransformer
- implements Serviceable, Configurable, Recyclable {
+public abstract class AbstractSAXTransformer extends AbstractTransformer
+ implements Serviceable,
Configurable, Recyclable, Disposable {
/**
* Empty immutable attributes (for performance). Use them
@@ -227,6 +228,16 @@
*/
private String ourPrefix;
+ //
+ // Lifecycle
+ //
+
+ /* (non-Javadoc)
+ * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
/* (non-Javadoc)
* @see Configurable#configure(Configuration)
@@ -293,8 +304,6 @@
* @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
*/
public void recycle() {
- super.recycle();
-
this.namespaceURI = null;
this.objectModel = null;
this.request = null;
@@ -307,20 +316,32 @@
this.source = null;
this.namespaces.clear();
this.ourPrefix = null;
+
+ super.recycle();
}
- /* (non-Javadoc)
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ public void dispose() {
+ this.manager = null;
+ }
+
+ //
+ // SAX ContentHandler methods
+ //
+
+ /**
+ * Process the SAX event.
+ * @see ContentHandler#setDocumentLocator
*/
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
+ public void setDocumentLocator(Locator locator) {
+ if (this.ignoreEventsCount == 0) {
+ super.setDocumentLocator(locator);
+ }
}
/**
- * Process the SAX event. A new document is processed. The hook (method)
- * <code>setupTransforming()</code> is invoked.
- *
- * @see org.xml.sax.ContentHandler#startDocument()
+ * Process the SAX event. A new document is processed. The hook method
+ * [EMAIL PROTECTED] #setupTransforming} is invoked.
+ * @see ContentHandler#startDocument
*/
public void startDocument()
throws SAXException {
@@ -341,8 +362,8 @@
}
/**
- * Process the SAX event. The processing of the document is finished.
- * @see org.xml.sax.ContentHandler#endDocument()
+ * Process the SAX event. The processing of the document is finished.
+ * @see org.xml.sax.ContentHandler#endDocument
*/
public void endDocument()
throws SAXException {
@@ -353,8 +374,68 @@
/**
* Process the SAX event.
- * The namespace of the event is checked. If it is the defined namespace
- * for this transformer the startTransformingElement() hook is called.
+ * @see org.xml.sax.ContentHandler#startPrefixMapping
+ */
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ if (prefix != null) {
+ this.namespaces.add(new String[] {prefix, uri});
+ }
+ if (namespaceURI.equals(uri)) {
+ this.ourPrefix = prefix;
+ }
+ if (this.ignoreEventsCount == 0) {
+ super.startPrefixMapping(prefix, uri);
+ }
+ }
+
+ /**
+ * Process the SAX event.
+ * @see org.xml.sax.ContentHandler#endPrefixMapping
+ */
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+
+ if (prefix != null) {
+ // Find and remove the namespace prefix
+ boolean found = false;
+ for (int i = this.namespaces.size() - 1; i >= 0; i--) {
+ final String[] prefixAndUri = (String[])
this.namespaces.get(i);
+ if (prefixAndUri[0].equals(prefix)) {
+ this.namespaces.remove(i);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new SAXException("Namespace for prefix '" + prefix + "'
not found.");
+ }
+
+ if (prefix.equals(this.ourPrefix)) {
+ // Reset our current prefix
+ this.ourPrefix = null;
+
+ // Now search if we have a different prefix for our namespace
+ for (int i = this.namespaces.size() - 1; i >= 0; i--) {
+ final String[] prefixAndUri = (String[])
this.namespaces.get(i);
+ if (namespaceURI.equals(prefixAndUri[1])) {
+ this.ourPrefix = prefixAndUri[0];
+ break;
+ }
+ }
+ }
+ }
+
+ if (this.ignoreEventsCount == 0) {
+ super.endPrefixMapping(prefix);
+ }
+ }
+
+ /**
+ * Process the SAX event. The namespace of the event is checked.
+ * If it is the defined namespace for this transformer,
+ * the [EMAIL PROTECTED] #startTransformingElement} hook is called.
+ * @see org.xml.sax.ContentHandler#startElement
*/
public void startElement(String uri,
String name,
@@ -378,9 +459,10 @@
}
/**
- * Process the SAX event.
- * The namespace of the event is checked. If it is the defined namespace
- * for this transformer the endTransformingElement() hook is called.
+ * Process the SAX event. The namespace of the event is checked.
+ * If it is the defined namespace for this transformer,
+ * the [EMAIL PROTECTED] #endTransformingElement} hook is called.
+ * @see org.xml.sax.ContentHandler#endElement
*/
public void endElement(String uri, String name, String raw)
throws SAXException {
@@ -402,6 +484,7 @@
/**
* Process the SAX event.
+ * @see org.xml.sax.ContentHandler#characters
*/
public void characters(char[] p0, int p1, int p2)
throws SAXException {
@@ -419,6 +502,7 @@
/**
* Process the SAX event.
+ * @see org.xml.sax.ContentHandler#ignorableWhitespace
*/
public void ignorableWhitespace(char[] p0, int p1, int p2)
throws SAXException {
@@ -427,6 +511,99 @@
}
}
+ /**
+ * Process the SAX event.
+ * @see ContentHandler#processingInstruction
+ */
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.processingInstruction(target, data);
+ }
+ }
+
+ /**
+ * Process the SAX event.
+ * @see ContentHandler#skippedEntity
+ */
+ public void skippedEntity(String name)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.skippedEntity(name);
+ }
+ }
+
+ //
+ // SAX LexicalHandler methods
+ //
+
+ /**
+ * @see LexicalHandler#startDTD
+ */
+ public void startDTD(String name, String public_id, String system_id)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.startDTD(name, public_id, system_id);
+ }
+ }
+
+ /**
+ * @see LexicalHandler#endDTD
+ */
+ public void endDTD() throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.endDTD();
+ }
+ }
+
+ /**
+ * @see LexicalHandler#startEntity
+ */
+ public void startEntity (String name)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.startEntity(name);
+ }
+ }
+
+ /**
+ * @see LexicalHandler#endEntity
+ */
+ public void endEntity (String name)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.endEntity(name);
+ }
+ }
+
+ /**
+ * @see LexicalHandler#startCDATA
+ */
+ public void startCDATA() throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.startCDATA();
+ }
+ }
+
+ /**
+ * @see LexicalHandler#endCDATA
+ */
+ public void endCDATA() throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.endCDATA();
+ }
+ }
+
+ /**
+ * @see LexicalHandler#comment
+ */
+ public void comment(char ary[], int start, int length)
+ throws SAXException {
+ if (this.ignoreEventsCount == 0) {
+ super.comment(ary, start, length);
+ }
+ }
+
/*
* Recording of events.
@@ -678,9 +855,9 @@
return fragment;
}
- // ************
+ //
// Hooks
- // ************
+ //
/**
* Setup the transformation of an xml document.
@@ -858,26 +1035,6 @@
}
/**
- * SAX Event handling
- */
- public void startEntity (String name)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.startEntity(name);
- }
- }
-
- /**
- * SAX Event handling
- */
- public void endEntity (String name)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.endEntity(name);
- }
- }
-
- /**
* Send all start prefix mapping events to the current content handler
*/
protected void sendStartPrefixMapping()
@@ -902,135 +1059,18 @@
}
/**
- * SAX Event handling
- */
- public void setDocumentLocator(Locator locator) {
- if (this.ignoreEventsCount == 0) {
- super.setDocumentLocator(locator);
- }
- }
-
- /**
- * SAX Event handling
- */
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- if (prefix != null) {
- this.namespaces.add(new String[] {prefix, uri});
- }
- if (namespaceURI.equals(uri)) {
- this.ourPrefix = prefix;
- }
- if (this.ignoreEventsCount == 0) {
- super.startPrefixMapping(prefix, uri);
- }
- }
-
- /**
- * SAX Event handling
+ * Find prefix mapping for the given namespace URI.
+ * @return Prefix mapping or null if no prefix defined
*/
- public void endPrefixMapping(String prefix)
- throws SAXException {
-
- if (prefix != null) {
- // Find and remove the namespace prefix
- boolean found = false;
- for (int i = this.namespaces.size() - 1; i >= 0; i--) {
- final String[] prefixAndUri = (String[])
this.namespaces.get(i);
- if (prefixAndUri[0].equals(prefix)) {
- this.namespaces.remove(i);
- found = true;
- break;
- }
- }
- if (!found) {
- throw new SAXException("Namespace for prefix '" + prefix + "'
not found.");
- }
-
- if (prefix.equals(this.ourPrefix)) {
- // Reset our current prefix
- this.ourPrefix = null;
-
- // Now search if we have a different prefix for our namespace
- for (int i = this.namespaces.size() - 1; i >= 0; i--) {
- final String[] prefixAndUri = (String[])
this.namespaces.get(i);
- if (namespaceURI.equals(prefixAndUri[1])) {
- this.ourPrefix = prefixAndUri[0];
- break;
- }
- }
+ protected String findPrefixMapping(String uri) {
+ final int l = this.namespaces.size();
+ for (int i = 0; i < l; i++) {
+ String[] prefixAndUri = (String[]) this.namespaces.get(i);
+ if (prefixAndUri[1].equals(uri)) {
+ return prefixAndUri[0];
}
}
- if (this.ignoreEventsCount == 0) {
- super.endPrefixMapping(prefix);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String,
java.lang.String)
- */
- public void processingInstruction(String target, String data)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.processingInstruction(target, data);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
- */
- public void skippedEntity(String name)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.skippedEntity(name);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String,
java.lang.String, java.lang.String)
- */
- public void startDTD(String name, String public_id, String system_id)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.startDTD(name, public_id, system_id);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ext.LexicalHandler#endDTD()
- */
- public void endDTD() throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.endDTD();
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ext.LexicalHandler#startCDATA()
- */
- public void startCDATA() throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.startCDATA();
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ext.LexicalHandler#endCDATA()
- */
- public void endCDATA() throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.endCDATA();
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
- */
- public void comment(char ary[], int start, int length)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- super.comment(ary, start, length);
- }
+ return null;
}
}
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java?rev=168368&r1=168367&r2=168368&view=diff
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
Thu May 5 11:28:46 2005
@@ -221,10 +221,11 @@
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
- if ( null != this.manager ) {
- this.manager.release( this.cacheManager );
+ if (null != this.manager) {
+ this.manager.release(this.cacheManager);
this.manager = null;
}
+ super.dispose();
}
/**
@@ -239,7 +240,7 @@
this.manager.release( this.recorder );
this.recorder = null;
}
- super.recycle();
+
this.configurationParameters = null;
this.resourceParameters = null;
if (getLogger().isDebugEnabled()) {
@@ -248,6 +249,8 @@
this.startTime = 0;
}
this.filter = null;
+
+ super.recycle();
}
public void startTransformingElement(String uri, String name, String raw,
Attributes attr)
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/JPathTransformer.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/JPathTransformer.java?rev=168368&r1=168367&r2=168368&view=diff
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/transformation/JPathTransformer.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/transformation/JPathTransformer.java
Thu May 5 11:28:46 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -54,10 +54,10 @@
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
- * @version CVS $Id$
+ * @version $Id$
*/
-public class JPathTransformer
-extends AbstractSAXTransformer implements Initializable {
+public class JPathTransformer extends AbstractSAXTransformer
+ implements Initializable {
/** namespace constant */
public static final String JPATH_NAMESPACE_URI =
"http://apache.org/xsp/jpath/1.0";
@@ -366,10 +366,10 @@
* Release all held resources.
*/
public void recycle() {
- super.recycle();
-
m_cache.clear();
m_kont = null;
m_jxpathContext = null;
+
+ super.recycle();
}
}
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java?rev=168368&r1=168367&r2=168368&view=diff
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java
Thu May 5 11:28:46 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -145,7 +145,7 @@
* </pre></p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
- * @version CVS $Id$
+ * @version $Id$
*/
public class SimpleFormTransformer extends AbstractSAXTransformer implements
Recyclable {
@@ -235,46 +235,46 @@
}
/** current element's request parameter values */
- protected Object[] values = null;
+ protected Object[] values;
/** current request's validation results (all validated elements) */
- protected Map validationResults = null;
+ protected Map validationResults;
/** Should we skip inserting values? */
- private boolean fixed = false;
+ private boolean fixed;
/** Is the complete document protected? */
- private boolean documentFixed = false;
+ private boolean documentFixed;
private String fixedName = "fixed";
- private String prefix = null;
- private String suffix = null;
- private String defaultPrefix = null;
- private String defaultSuffix = null;
- private String separator = null;
- private String formName = null;
- private boolean useFormName = false;
- private boolean useFormNameTwice = false;
- private boolean ignoreValidation = false;
+ private String prefix;
+ private String suffix;
+ private String defaultPrefix;
+ private String defaultSuffix;
+ private String separator;
+ private String formName;
+ private boolean useFormName;
+ private boolean useFormNameTwice;
+ private boolean ignoreValidation;
private int decorationSize = 1;
private String defaultInput = "request-param";
- private Configuration defaultInputConf = null;
- private Configuration inputConf = null;
- private InputModule input = null;
- private ServiceSelector inputSelector = null;
- private String inputName = null;
+ private Configuration defaultInputConf;
+ private Configuration inputConf;
+ private InputModule input;
+ private ServiceSelector inputSelector;
+ private String inputName;
/** Skip element's content only. Otherwise skip also surrounding element.
*/
- protected boolean skipChildrenOnly = false;
+ protected boolean skipChildrenOnly;
/** Count nested repeat elements. */
- protected int recordingCount = 0;
+ protected int recordingCount;
/** List of [EMAIL PROTECTED] RepeaterStatus} elements keeping track of
nested repeat blocks. */
- protected List repeater = null;
+ protected List repeater;
/** Map of [EMAIL PROTECTED] ValueList} to track multiple parameters. */
- protected Map formValues = null;
+ protected Map formValues;
/**
@@ -466,8 +466,8 @@
* Recycle this component.
*/
public void recycle() {
+ reset();
super.recycle();
- this.reset();
}
/**
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java?rev=168368&r1=168367&r2=168368&view=diff
==============================================================================
---
cocoon/trunk/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
(original)
+++
cocoon/trunk/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
Thu May 5 11:28:46 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -229,11 +229,10 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jeremy Quinn</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a>
- * @version CVS $Id$
+ * @version $Id$
*/
-public class SourceWritingTransformer
- extends AbstractSAXTransformer
- implements Disposable {
+public class SourceWritingTransformer extends AbstractSAXTransformer
+ implements Disposable {
public static final String SWT_URI = "http://apache.org/cocoon/source/1.0";
public static final String DEFAULT_SERIALIZER = "xml";
@@ -816,5 +815,6 @@
this.manager.release(this.xpathProcessor);
this.xpathProcessor = null;
}
+ super.dispose();
}
}