cziegeler 02/04/02 06:23:45
Modified: src/scratchpad/src/org/apache/cocoon/sunshine SunShine.java
src/scratchpad/src/org/apache/cocoon/sunshine/connector
ResourceConnectorImpl.java
src/scratchpad/src/org/apache/cocoon/sunshine/sunrise
SunRise.java
src/scratchpad/src/org/apache/cocoon/sunshine/sunspot
SunSpot.java
src/scratchpad/src/org/apache/cocoon/sunshine/transformation
AbstractSunShineTransformer.java
InsertTransformer.java SunShinePreTransformer.java
Removed: src/scratchpad/src/org/apache/cocoon/sunshine/helpers
NOPRecorder.java ParametersRecorder.java
TextRecorder.java
Log:
Removed obsolete code
Revision Changes Path
1.5 +6 -6
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/SunShine.java
Index: SunShine.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/SunShine.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SunShine.java 14 Mar 2002 07:09:50 -0000 1.4
+++ SunShine.java 2 Apr 2002 14:23:44 -0000 1.5
@@ -87,7 +87,7 @@
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
-
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.sunshine.connector.*;
import org.apache.cocoon.sunshine.context.SessionContext;
import org.apache.cocoon.sunshine.context.SessionContextProvider;
@@ -110,7 +110,7 @@
* allowed but if one thread wants to write, no other can read or write.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: SunShine.java,v 1.4 2002/03/14 07:09:50 cziegeler Exp $
+ * @version CVS $Id: SunShine.java,v 1.5 2002/04/02 14:23:44 cziegeler Exp $
*/
public final class SunShine
extends AbstractLoggable
@@ -526,7 +526,7 @@
frag = context.getXML(path);
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END getContextFragment documentFragment=" +
(frag == null ? "null" : XMLUtil.serializeNodeToXML(frag)));
+ this.getLogger().debug("END getContextFragment documentFragment=" +
(frag == null ? "null" : XMLUtils.serializeNodeToXML(frag)));
}
return frag;
}
@@ -591,7 +591,7 @@
if (this.getLogger().isDebugEnabled() == true) {
this.getLogger().debug("BEGIN setContextFragment name=" + contextName +
", path=" + path +
- ", fragment=" + (fragment == null ? "null" :
XMLUtil.serializeNodeToXML(fragment)));
+ ", fragment=" + (fragment == null ? "null" :
XMLUtils.serializeNodeToXML(fragment)));
}
// test arguments
if (contextName == null) {
@@ -637,7 +637,7 @@
if (this.getLogger().isDebugEnabled() == true) {
this.getLogger().debug("BEGIN appendContextFragment name=" +
contextName +
", path=" + path +
- ", fragment=" + (fragment == null ? "null" :
XMLUtil.serializeNodeToXML(fragment)));
+ ", fragment=" + (fragment == null ? "null" :
XMLUtils.serializeNodeToXML(fragment)));
}
// test arguments
if (contextName == null) {
@@ -682,7 +682,7 @@
// synchronized via context
if (this.getLogger().isDebugEnabled() == true) {
this.getLogger().debug("BEGIN mergeContextFragment name=" + contextName
+ ", path=" + path +
- ", fragment=" + (fragment == null ? "null" :
XMLUtil.serializeNodeToXML(fragment)));
+ ", fragment=" + (fragment == null ? "null" :
XMLUtils.serializeNodeToXML(fragment)));
}
// test arguments
1.4 +12 -11
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/connector/ResourceConnectorImpl.java
Index: ResourceConnectorImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/connector/ResourceConnectorImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceConnectorImpl.java 11 Mar 2002 11:15:25 -0000 1.3
+++ ResourceConnectorImpl.java 2 Apr 2002 14:23:44 -0000 1.4
@@ -85,6 +85,7 @@
import org.apache.cocoon.xml.dom.DOMBuilder;
import org.apache.cocoon.sunshine.helpers.URLRewriter;
import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.sunshine.xml.XMLUtil;
import org.w3c.dom.*;
@@ -97,7 +98,7 @@
* The Component for loading and saving xml to external resource connectors.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: ResourceConnectorImpl.java,v 1.3 2002/03/11 11:15:25 cziegeler
Exp $
+ * @version CVS $Id: ResourceConnectorImpl.java,v 1.4 2002/04/02 14:23:44 cziegeler
Exp $
*/
public final class ResourceConnectorImpl
extends AbstractLoggable
@@ -321,7 +322,7 @@
}
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END loadXMLFromURI fragment="+(recordedDocFrag
== null ? "null" : XMLUtil.serializeNodeToXML(recordedDocFrag)));
+ this.getLogger().debug("END loadXMLFromURI fragment="+(recordedDocFrag
== null ? "null" : XMLUtils.serializeNodeToXML(recordedDocFrag)));
}
return recordedDocFrag;
}
@@ -336,7 +337,7 @@
DocumentFragment fragment)
throws IOException, SAXException, ProcessingException {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN saveXMLToURI fragment="+(fragment == null
? "null" : XMLUtil.serializeNodeToXML(fragment))+
+ this.getLogger().debug("BEGIN saveXMLToURI fragment="+(fragment == null
? "null" : XMLUtils.serializeNodeToXML(fragment))+
", typeParams="+typeParameters+
", uri=" + uri +
", parameters="+resourceParameters);
@@ -345,9 +346,9 @@
throw new IllegalArgumentException("saveXMLToURI: URI is required");
}
- Properties format = XMLUtil.defaultSerializeToXMLFormat(true);
+ Properties format = XMLUtils.defaultSerializeToXMLFormat(true);
this.setOutputKeys(format, typeParameters);
- String content = XMLUtil.serializeNode(fragment, format);
+ String content = XMLUtils.serializeNode(fragment, format);
if (resourceParameters == null) {
resourceParameters = new SourceParameters();
} else {
@@ -425,7 +426,7 @@
}
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END loadXMLFromClass fragment="+(frag == null ?
"null" : XMLUtil.serializeNodeToXML(frag)));
+ this.getLogger().debug("END loadXMLFromClass fragment="+(frag == null ?
"null" : XMLUtils.serializeNodeToXML(frag)));
}
return frag;
}
@@ -439,7 +440,7 @@
DocumentFragment fragment)
throws ProcessingException {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN saveXMLToClass fragment="+(fragment ==
null ? "null" : XMLUtil.serializeNodeToXML(fragment))+
+ this.getLogger().debug("BEGIN saveXMLToClass fragment="+(fragment ==
null ? "null" : XMLUtils.serializeNodeToXML(fragment))+
", typeParams="+typeParameters+
", class=" + className+
", params="+resourceParameters);
@@ -510,7 +511,7 @@
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END loadXMLFromFile fragment="+(frag == null ?
"null" : XMLUtil.serializeNodeToXML(frag)));
+ this.getLogger().debug("END loadXMLFromFile fragment="+(frag == null ?
"null" : XMLUtils.serializeNodeToXML(frag)));
}
return frag;
}
@@ -524,7 +525,7 @@
DocumentFragment fragment)
throws SAXException, IOException, ProcessingException {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN saveXMLToFile fragment="+(fragment ==
null ? "null" : XMLUtil.serializeNodeToXML(fragment))+
+ this.getLogger().debug("BEGIN saveXMLToFile fragment="+(fragment ==
null ? "null" : XMLUtils.serializeNodeToXML(fragment))+
", typeParams="+typeParameters+
", file=" + fileName +
", params="+resourceParameters);
@@ -552,7 +553,7 @@
Source input = null;
try {
- Properties format = XMLUtil.defaultSerializeToXMLFormat(false);
+ Properties format = XMLUtils.defaultSerializeToXMLFormat(false);
this.setOutputKeys(format, typeParameters);
input = this.resolver.resolve(fileName);
String absolutePath = input.getSystemId();
@@ -567,7 +568,7 @@
}
file.createNewFile();
}
- String xml = XMLUtil.serializeNode(fragment, format);
+ String xml = XMLUtils.serializeNode(fragment, format);
Writer writer = new BufferedWriter(new FileWriter(file));;
writer.write(xml);
writer.flush();
1.5 +3 -2
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunrise/SunRise.java
Index: SunRise.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunrise/SunRise.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SunRise.java 13 Mar 2002 15:45:30 -0000 1.4
+++ SunRise.java 2 Apr 2002 14:23:44 -0000 1.5
@@ -68,6 +68,7 @@
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.cocoon.xml.XMLUtils;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@@ -96,7 +97,7 @@
* This is the basis sunShine component.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: SunRise.java,v 1.4 2002/03/13 15:45:30 cziegeler Exp $
+ * @version CVS $Id: SunRise.java,v 1.5 2002/04/02 14:23:44 cziegeler Exp $
*/
public final class SunRise
extends AbstractSunShineComponent
@@ -1213,7 +1214,7 @@
}
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END getUsers fragment="+(frag == null ? "null"
: XMLUtil.serializeNodeToXML(frag)));
+ this.getLogger().debug("END getUsers fragment="+(frag == null ? "null"
: XMLUtils.serializeNodeToXML(frag)));
}
return frag;
}
1.5 +3 -2
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunspot/SunSpot.java
Index: SunSpot.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/sunspot/SunSpot.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SunSpot.java 13 Mar 2002 15:45:30 -0000 1.4
+++ SunSpot.java 2 Apr 2002 14:23:45 -0000 1.5
@@ -80,6 +80,7 @@
import org.apache.cocoon.sunshine.context.SessionContext;
import org.apache.cocoon.sunshine.context.SessionContextProvider;
import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.sunshine.xml.XMLUtil;
import org.apache.cocoon.sunshine.sunrise.SunRise;
import org.apache.cocoon.sunshine.sunspot.context.SessionContextProviderImpl;
@@ -104,7 +105,7 @@
* This is the basis sunSpot component
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: SunSpot.java,v 1.4 2002/03/13 15:45:30 cziegeler Exp $
+ * @version CVS $Id: SunSpot.java,v 1.5 2002/04/02 14:23:45 cziegeler Exp $
*/
public final class SunSpot
extends AbstractSunShineComponent {
@@ -714,7 +715,7 @@
}
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END getStatusProfile
statusProfile="+(statusProfile == null ? "null" :
XMLUtil.serializeNodeToXML(statusProfile)));
+ this.getLogger().debug("END getStatusProfile
statusProfile="+(statusProfile == null ? "null" :
XMLUtils.serializeNodeToXML(statusProfile)));
}
return statusProfile;
}
1.5 +4 -841
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/AbstractSunShineTransformer.java
Index: AbstractSunShineTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/AbstractSunShineTransformer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractSunShineTransformer.java 11 Mar 2002 11:15:26 -0000 1.4
+++ AbstractSunShineTransformer.java 2 Apr 2002 14:23:45 -0000 1.5
@@ -70,15 +70,12 @@
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.transformation.AbstractTransformer;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.cocoon.xml.XMLConsumer;
-import org.apache.cocoon.xml.dom.DOMBuilder;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.sunshine.SunShine;
import org.apache.cocoon.sunshine.connector.*;
-import org.apache.cocoon.sunshine.helpers.*;
-import org.apache.cocoon.sunshine.xml.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
@@ -93,128 +90,18 @@
import org.xml.sax.helpers.AttributesImpl;
/**
- * This class is the basis for all transformers. It provides various useful
- * methods and hooks for implementing own custom transformers.<p>
- * <p>
- * The basic behaviour of each transformer consists of the following four parts:
- * <ul>
- * <li>Listen for specific events with a given namespace</li>
- * <li>Collect information via these events</li>
- * <li>Process the information</li>
- * <li>Create new events from the processed information</li>
- * </ul><p>
- * For all these four purposes the AbstractSunshineTransformer offers some
- * powerful methods and hooks:
- * <p>
- * Namespace handling<p>
- * By setting the instance variable namespaceURI to the namespace the
- * events are filtered and only events with this namespace are send to
- * the two hooks startTransformingElement() and endTransformingElement().<p>
- * Starting with version 1.2.1 it is possible to override the default
- * namespace for the transformer by specifying the parameter "namespaceURI"
- * in the pipeline. This avoids possible namespace collisions.<p>
- *
- * Recording of information<p>
- * There are several methods for recording information, e.g. startRecording(),
- * startTextRecording() etc. These methods collect information from the xml
- * stream for further processing.<p>
- *
- * Creating new events<p>
- * New events can be easily created with the <code>sendEvents()</code>
- * method, the <code>sendStartElementEvent()</code> methods, the
<code>sendEndElementEvent()</code>
- * method or the <code>sendTextEvent()</code> method.<p>
- *
- * Initialization<p>
- * Before the document is processed the setupTransforming() hook is invoked.
- *
+ * This class is the basis for all sunShine transformers.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: AbstractSunShineTransformer.java,v 1.4 2002/03/11 11:15:26
cziegeler Exp $
+ * @version CVS $Id: AbstractSunShineTransformer.java,v 1.5 2002/04/02 14:23:45
cziegeler Exp $
*/
public abstract class AbstractSunShineTransformer
-extends AbstractTransformer
-implements Composable, Configurable, Recyclable {
-
- /** Controlls SAX event handling.
- * If set to true all whitespace events are ignored.
- */
- protected boolean ignoreWhitespaces;
- /** Controlls SAX event handling
- * If set to true all characters events containing only whitespaces
- * are ignored.
- */
- protected boolean ignoreEmptyCharacters;
-
- /** Controlls SAX event handling
- * If this is incremented all events are not forwarded to the next
- * pipeline component, but the hooks are still called.
- */
- protected int ignoreEventsCount;
-
- /** Controlls SAX event handling
- * If this is greater than zero, the hooks are not called. Attention,
- * make sure, that you decrement this counter properly as your hooks are
- * not called anymore!
- */
- protected int ignoreHooksCount;
-
- /**
- * The used namespace for the SAX filtering.
- * This is either the defaultNamespaceURI or the value
- * set by the "namespaceURI" parameter for the pipeline.
- */
- protected String namespaceURI;
-
- /**
- * This is the default namespace used by the transformer.
- * It should be set by in the constructor.
- */
- protected String defaultNamespaceURI;
+extends AbstractSAXTransformer {
- /** A stack for collecting information.
- * The stack is important for collection information especially when
- * the tags can be nested.
- */
- protected Stack stack = new Stack();
- /** The stack of current used recorders */
- protected Stack recorderStack = new Stack();
-
- /** The current Request object */
- protected Request request;
- /** The current Response object */
- protected Response response;
- /** The current Context object */
- protected Context context;
- /** The current objectModel of the environment */
- protected Map objectModel;
- /** The parameters specified in the sitemap */
- protected Parameters parameters;
- /** The source attribute specified in the sitemap */
- protected String source;
- /** The Avalon ComponentManager for getting Components */
- protected ComponentManager manager;
- /** The sunShine component for this request */
private SunShine sunShine;
/** The Resource Connector */
private ResourceConnector resourceConnector;
/** The SourceResolver for this request */
- protected SourceResolver resolver;
-
- /** Empty attributes (for performance). This can be used
- * do create own attributes, but make sure to clean them
- * afterwords.
- */
- protected AttributesImpl emptyAttributes = new AttributesImpl();
-
- /** The namespaces */
- private List namespaces = new ArrayList(5);
-
- /**
- * Avalon Configurable Interface
- */
- public void configure(Configuration configuration)
- throws ConfigurationException {
- }
/**
* Get the sunShine component
@@ -247,79 +134,14 @@
}
/**
- * Setup the next round.
- * The instance variables are initialised.
- * @param resolver The current SourceResolver
- * @param objectModel The objectModel of the environment.
- * @param src The value of the src attribute in the sitemap.
- * @param par The parameters from the sitemap.
- */
- public void setup(SourceResolver resolver,
- Map objectModel,
- String src,
- Parameters par)
- throws ProcessingException,
- SAXException,
- IOException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN setup resolver="+resolver+
- ", objectModel="+objectModel+
- ", src="+src+
- ", parameters="+par);
- }
-
- if (this.defaultNamespaceURI == null) {
- this.defaultNamespaceURI = this.namespaceURI;
- }
- this.objectModel = objectModel;
-
- this.request = ObjectModelHelper.getRequest(objectModel);
- this.response = ObjectModelHelper.getResponse(objectModel);
- this.context = ObjectModelHelper.getContext(objectModel);
- this.resolver = resolver;
- this.parameters = par;
- this.source = src;
-
- // get the current namespace
- this.namespaceURI = this.parameters.getParameter("namespaceURI",
this.defaultNamespaceURI);
-
- this.ignoreHooksCount = 0;
- this.ignoreEventsCount = 0;
- this.ignoreWhitespaces = true;
- this.ignoreEmptyCharacters = false;
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END setup");
- }
- }
-
- /**
* Recycle this component.
*/
public void recycle() {
super.recycle();
- this.objectModel = null;
- this.request = null;
- this.response = null;
- this.context = null;
- this.resolver = null;
this.manager.release(this.resourceConnector);
this.manager.release(this.sunShine);
this.resourceConnector = null;
this.sunShine = null;
- this.stack.clear();
- this.recorderStack.clear();
- this.parameters = null;
- this.source = null;
- this.namespaces.clear();
- }
-
- /**
- * Avalon Composable Interface
- * @param manager The Avalon Component Manager
- */
- public void compose(ComponentManager manager) {
- this.manager = manager;
}
/**
@@ -329,665 +151,6 @@
public Session getSession()
throws ProcessingException {
return this.getSunShineComponent().getSession(false);
- }
-
- /**
- * Process the SAX event. A new document is processed. The hook (method)
- * <code>setupTransforming()</code> is invoked.
- * @see org.xml.sax.ContentHandler#startDocument
- */
- public void startDocument()
- throws SAXException {
- try {
- this.setupTransforming();
- } catch (ProcessingException local) {
- throw new SAXException("ProcessingException: " + local, local);
- } catch (IOException ioe) {
- throw new SAXException("IOException: " + ioe, ioe);
- }
- if (this.ignoreEventsCount == 0) super.startDocument();
- }
-
- /**
- * Process the SAX event. The processing of the document is finished.
- * @see org.xml.sax.ContentHandler#endDocument
- */
- public void endDocument()
- throws SAXException {
- if (this.ignoreEventsCount == 0) super.endDocument();
- }
-
-
- /**
- * 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.
- */
- public void startElement(String uri,
- String name,
- String raw,
- Attributes attr)
- throws SAXException {
- if (uri != null
- && namespaceURI != null
- && uri.equals(namespaceURI) == true
- && this.ignoreHooksCount == 0) {
-
- // this is our namespace:
- try {
- this.startTransformingElement(uri, name, raw, attr);
- } catch (ProcessingException sunShineException) {
- throw new SAXException("ProcessingException: " + sunShineException,
sunShineException);
- } catch (IOException ioe) {
- throw new SAXException("Exception occured during processing: " +
ioe, ioe);
- }
- } else {
- if (ignoreEventsCount == 0) super.startElement(uri, name, raw, attr);
- }
- }
-
-
- /**
- * 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.
- */
- public void endElement(String uri, String name, String raw) throws SAXException
{
- if (uri != null
- && namespaceURI != null
- && uri.equals(namespaceURI) == true
- && this.ignoreHooksCount == 0) {
-
- // this is our namespace:
- try {
- this.endTransformingElement(uri, name, raw);
- } catch (ProcessingException sunShineException) {
- throw new SAXException("ProcessingException: " + sunShineException,
- sunShineException);
- } catch (IOException ioe) {
- throw new SAXException("Exception occured during processing: " +
ioe, ioe);
- }
- } else {
- if (ignoreEventsCount == 0) super.endElement(uri, name, raw);
- }
- }
-
- /**
- * Process the SAX event.
- */
- public void characters(char[] p0, int p1, int p2)
- throws SAXException {
- if (this.ignoreEventsCount == 0) {
- if (this.ignoreEmptyCharacters == true) {
- String value = new String(p0, p1, p2);
- if (value.trim().length() > 0) {
- super.characters(p0, p1, p2);
- }
- } else {
- super.characters(p0, p1, p2);
- }
- }
- }
-
- /**
- * Process the SAX event.
- */
- public void ignorableWhitespace(char[] p0, int p1, int p2)
- throws SAXException {
- if (ignoreWhitespaces == false && ignoreEventsCount == 0)
super.ignorableWhitespace(p0, p1, p2);
- }
-
- /*
- * Recording of events.
- * With this method all events are not forwarded to the next component in the
pipeline.
- * They are recorded to create a document fragment.
- */
- private LexicalHandler originalLexicalHandler;
- private ContentHandler originalContentHandler;
-
- /**
- * Add a new recorder to the recording chain.
- * Do not invoke this method directly.
- */
- protected void addRecorder(XMLConsumer recorder) {
- if (this.recorderStack.empty() == true) {
- // redirect if first (top) recorder
- this.originalLexicalHandler = this.lexicalHandler;
- this.originalContentHandler = this.contentHandler;
- }
- this.setContentHandler(recorder);
- this.setLexicalHandler(recorder);
- this.recorderStack.push(recorder);
- }
-
- /**
- * Remove a recorder from the recording chain.
- * Do not invoke this method directly.
- */
- protected Object removeRecorder() {
- Object recorder = this.recorderStack.pop();
- if (this.recorderStack.empty() == true) {
- // undo redirect if no recorder any more
- this.setContentHandler(originalContentHandler);
- this.setLexicalHandler(originalLexicalHandler);
- this.originalLexicalHandler = null;
- this.originalContentHandler = null;
- } else {
- XMLConsumer next = (XMLConsumer)recorderStack.peek();
- this.setContentHandler(next);
- this.setLexicalHandler(next);
- }
- return recorder;
- }
-
- /**
- * Start DocumentFragment recording.
- * All invoming events are recorded and not forwarded. The resulting
- * DocumentFragment can be obtained by the matching endRecording() call.
- */
- public void startRecording()
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startRecording");
- }
- DOMBuilder builder = new DOMBuilder();
- this.addRecorder(builder);
- builder.startDocument();
- builder.startElement("", "sunShine", "sunShine", new AttributesImpl());
-
- this.sendStartPrefixMapping();
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startRecording");
- }
- }
-
- /**
- * Stop DocumentFragment recording.
- * All invoming events are recorded and not forwarded. This method returns
- * the resulting DocumentFragment.
- */
- public DocumentFragment endRecording()
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endRecording");
- }
-
- this.sendEndPrefixMapping();
-
- DOMBuilder builder = (DOMBuilder)this.removeRecorder();
- builder.endElement("", "sunShine", "sunShine");
- builder.endDocument();
-
- // Create Document Fragment
- final Document doc = builder.getDocument();
- final DocumentFragment recordedDocFrag = doc.createDocumentFragment();
- final Node root = doc.getDocumentElement();
- root.normalize();
- Node child;
- boolean appendedNode = false;
- while (root.hasChildNodes() == true) {
- child = root.getFirstChild();
- root.removeChild(child);
- // Leave out empty text nodes before any other node
- if (appendedNode == true
- || child.getNodeType() != Node.TEXT_NODE
- || child.getNodeValue().trim().length() > 0) {
- recordedDocFrag.appendChild(child);
- appendedNode = true;
- }
- }
-
- if (this.getLogger().isDebugEnabled() == true) {
- Object serializedXML = null;
- try {
- serializedXML = (recordedDocFrag == null ? "null" :
XMLUtil.serializeNodeToXML(recordedDocFrag));
- } catch (ProcessingException ignore) {
- serializedXML = recordedDocFrag;
- }
- this.getLogger().debug("END endRecording fragment=" + serializedXML);
- }
- return recordedDocFrag;
- }
-
- /**
- * Start recording of text.
- * All events are not forwarded and the characters events
- * are merged to a string
- */
- public void startTextRecording()
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startTextRecording");
- }
- XMLConsumer recorder = new TextRecorder();
- this.addRecorder(recorder);
-
- this.sendStartPrefixMapping();
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startTextRecording");
- }
- }
-
- /**
- * Stop recording of text and return the recorded information.
- * @return The String.
- */
- public String endTextRecording()
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endTextRecording");
- }
-
- this.sendEndPrefixMapping();
-
- TextRecorder recorder = (TextRecorder)this.removeRecorder();
- String text = recorder.getText();
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endTextRecording text="+text);
- }
- return text;
- }
-
- /**
- * Start recording of serialized xml
- * All events are converted to an xml string which can be retrieved by
- * endSerializedXMLRecording.
- * @param format The format for the serialized output. If <CODE>null</CODE>
- * is specified, the default format is used.
- */
- public void startSerializedXMLRecording(Properties format)
- throws SAXException, IOException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startSerializedXMLRecording
format="+format);
- }
- this.stack.push((format == null ? XMLUtil.defaultSerializeToXMLFormat() :
format));
- this.startRecording();
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startSerializedXMLRecording");
- }
- }
-
- /**
- * Return the serialized xml string.
- * @return A string containing the recorded xml information, formatted by
- * the properties passed to the corresponding startSerializedXMLRecording().
- */
- public String endSerializedXMLRecording()
- throws SAXException, ProcessingException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endSerializedXMLRecording");
- }
- DocumentFragment fragment = this.endRecording();
- String text = XMLUtil.serializeNode(fragment, (Properties)this.stack.pop());
-/* this.sendEndPrefixMapping();
- SerializedXMLRecorder recorder =
(SerializedXMLRecorder)this.removeRecorder();
- String text = recorder.getSerializedXML();
-*/
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endSerializedXMLRecording xml="+text);
- }
- return text;
- }
-
- /**
- * Start recording of parameters.
- * All events are not forwarded and the incoming xml is converted to
- * parameters. Each toplevel node is a parameter and its text subnodes
- * form the value.
- * The Parameters can eiter be retrieved by endParametersRecording().
- */
- public void startParametersRecording()
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startParametersRecording");
- }
- XMLConsumer recorder = new ParametersRecorder();
- this.addRecorder(recorder);
-
- this.sendStartPrefixMapping();
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startParametersRecording");
- }
- }
-
- /**
- * End recording of parameters
- * If source is null a new parameters object is created, otherwise
- * the parameters are added to this object.
- * @param source An optional parameters object.
- * @return The object containing all parameters.
- */
- public SourceParameters endParametersRecording(Parameters source)
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endParametersRecording source="+source);
- }
- this.sendEndPrefixMapping();
- ParametersRecorder recorder = (ParametersRecorder)this.removeRecorder();
- SourceParameters pars = recorder.getParameters(source);
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endParametersRecording parameters="+pars);
- }
- return pars;
- }
-
- /**
- * End recording of parameters
- * If source is null a new parameters object is created, otherwise
- * the parameters are added to this object.
- * @param source An optional parameters object.
- * @return The object containing all parameters.
- */
- public SourceParameters endParametersRecording(SourceParameters source)
- throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endParametersRecording source="+source);
- }
- this.sendEndPrefixMapping();
- ParametersRecorder recorder = (ParametersRecorder)this.removeRecorder();
- SourceParameters pars = recorder.getParameters(source);
-
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endParametersRecording parameters="+pars);
- }
- return pars;
- }
-
- // ************
- // Hooks
- // ************
-
- /**
- * Setup the transformation of an xml document.
- * This method is called just before the transformation (sending of sax events)
- * starts. It should be used to initialize setup parameter depending on the
- * object modell.
- */
- public void setupTransforming()
- throws IOException, ProcessingException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN setupTransforming");
- }
- this.stack.clear();
- this.recorderStack.clear();
- this.ignoreWhitespaces = true;
- this.ignoreEmptyCharacters = false;
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END setupTransforming");
- }
- }
-
- /**
- * Start processing elements of our namespace.
- * This hook is invoked for each sax event with our namespace.
- * @param uri The namespace of the element.
- * @param name The local name of the element.
- * @param raw The qualified name of the element.
- * @param attr The attributes of the element.
- */
- public void startTransformingElement(String uri,
- String name,
- String raw,
- Attributes attr)
- throws ProcessingException, IOException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startTransformingElement uri=" + uri + ",
name=" + name + ", raw=" + raw + ", attr=" + attr + ")");
- }
- if (this.ignoreEventsCount == 0) super.startElement(uri, name, raw, attr);
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startTransformingElement");
- }
- }
-
- /**
- * Start processing elements of our namespace.
- * This hook is invoked for each sax event with our namespace.
- * @param uri The namespace of the element.
- * @param name The local name of the element.
- * @param raw The qualified name of the element.
- */
- public void endTransformingElement(String uri,
- String name,
- String raw)
- throws ProcessingException, IOException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endTransformingElement uri=" + uri + ",
name=" + name + ", raw=" + raw + ")");
- }
- if (this.ignoreEventsCount == 0) super.endElement(uri, name, raw);
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endTransformingElement");
- }
- }
-
- /**
- * Send SAX events to the next pipeline component.
- * The characters event for the given text is send to the next
- * component in the current pipeline.
- * @param text The string containing the information.
- */
- public void sendTextEvent(String text)
- throws SAXException {
- this.characters(text.toCharArray(), 0, text.length());
- }
-
- /**
- * Send SAX events to the next pipeline component.
- * The startElement event for the given element is send
- * to the next component in the current pipeline.
- * The element has no namespace and no attributes
- * @param localname The name of the event.
- */
- public void sendStartElementEvent(String localname)
- throws SAXException {
- this.startElement("", localname, localname, emptyAttributes);
- }
-
- /**
- * Send SAX events to the next pipeline component.
- * The startElement event for the given element is send
- * to the next component in the current pipeline.
- * The element has no namespace.
- * @param localname The name of the event.
- * @param attr The Attributes of the element
- */
- public void sendStartElementEvent(String localname, Attributes attr)
- throws SAXException {
- this.startElement("", localname, localname, attr);
- }
-
- /**
- * Send SAX events to the next pipeline component.
- * The endElement event for the given element is send
- * to the next component in the current pipeline.
- * The element has no namespace.
- * @param localname The name of the event.
- */
- public void sendEndElementEvent(String localname)
- throws SAXException {
- this.endElement("", localname, localname);
- }
-
- /**
- * Send SAX events to the next pipeline component.
- * The node is parsed and the events are send to
- * the next component in the pipeline.
- * @param node The tree to be included.
- */
- public void sendEvents(Node node)
- throws SAXException {
- IncludeXMLConsumer.includeNode(node, this, this);
- }
-
- /**
- * Send SAX events for the <code>SourceParameters</code>.
- * For each parametername/value pair an element is
- * created with the name of the parameter and the content
- * of this element is the value.
- */
- public void sendParametersEvents(SourceParameters pars)
- throws SAXException {
- if (pars != null) {
- Iterator names = pars.getParameterNames();
- String currentName;
- String currentValue;
- Iterator values;
- while (names.hasNext() == true) {
- currentName = (String)names.next();
- values = pars.getParameterValues(currentName);
- while (values.hasNext() == true) {
- currentValue = (String)values.next();
- this.sendStartElementEvent(currentName);
- this.sendTextEvent(currentValue);
- this.sendEndElementEvent(currentName);
- }
- }
- }
- }
-
- /**
- * 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()
- throws SAXException {
- int i,l;
- l = this.namespaces.size();
- String[] prefixAndUri;
- for(i=0; i<l; i++) {
- prefixAndUri = (String[])this.namespaces.get(i);
- super.contentHandler.startPrefixMapping(prefixAndUri[0],
prefixAndUri[1]);
- }
- }
-
- /**
- * Send all end prefix mapping events to the current content handler
- */
- protected void sendEndPrefixMapping()
- throws SAXException {
- int i,l;
- l = this.namespaces.size();
- String[] prefixAndUri;
- for(i=0; i<l; i++) {
- prefixAndUri = (String[])this.namespaces.get(i);
- super.contentHandler.endPrefixMapping(prefixAndUri[0]);
- }
- }
-
- /**
- * 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 (this.ignoreEventsCount == 0) super.startPrefixMapping(prefix, uri);
- }
-
- /**
- * SAX Event handling
- */
- public void endPrefixMapping(String prefix)
- throws SAXException {
- if (prefix != null) {
- // search the namespace prefix
- boolean found = false;
- int l = this.namespaces.size();
- int i = l-1;
- String currentPrefix;
- while (found == false && i >= 0) {
- currentPrefix = ((String[])this.namespaces.get(i))[0];
- if (currentPrefix.equals(prefix) == true) {
- found = true;
- } else {
- i--;
- }
- }
- if (found == false) {
- throw new SAXException("Namespace for prefix '"+ prefix + "' not
found.");
- }
- this.namespaces.remove(i);
- }
- if (this.ignoreEventsCount == 0) super.endPrefixMapping(prefix);
- }
-
- /**
- * SAX Event handling
- */
- public void processingInstruction(String target, String data)
- throws SAXException {
- if (this.ignoreEventsCount == 0) super.processingInstruction(target, data);
- }
-
- /**
- * SAX Event handling
- */
- public void skippedEntity(String name)
- throws SAXException {
- if (this.ignoreEventsCount == 0) super.skippedEntity(name);
- }
-
- /**
- * SAX Event handling
- */
- public void startDTD(String name, String public_id, String system_id)
- throws SAXException {
- if (this.ignoreEventsCount == 0) super.startDTD(name, public_id, system_id);
- }
-
- /**
- * SAX Event handling
- */
- public void endDTD() throws SAXException {
- if (this.ignoreEventsCount == 0) super.endDTD();
- }
-
- /**
- * SAX Event handling
- */
- public void startCDATA() throws SAXException {
- if (this.ignoreEventsCount == 0) super.startCDATA();
- }
-
- /**
- * SAX Event handling
- */
- public void endCDATA() throws SAXException {
- if (this.ignoreEventsCount == 0) super.endCDATA();
- }
-
-
- /**
- * SAX Event handling
- */
- public void comment(char ary[], int start, int length)
- throws SAXException {
- if (this.ignoreEventsCount == 0) super.comment(ary, start, length);
}
}
1.4 +3 -2
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/InsertTransformer.java
Index: InsertTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/InsertTransformer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InsertTransformer.java 22 Feb 2002 06:57:19 -0000 1.3
+++ InsertTransformer.java 2 Apr 2002 14:23:45 -0000 1.4
@@ -56,6 +56,7 @@
import org.xml.sax.*;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.sunshine.SunShineConstants;
import org.apache.cocoon.sunshine.connector.ResourceConnector;
import org.apache.cocoon.sunshine.xml.XMLUtil;
@@ -111,7 +112,7 @@
* reinsert a replaced node at a given path in the new fragment.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: InsertTransformer.java,v 1.3 2002/02/22 06:57:19 cziegeler Exp
$
+ * @version CVS $Id: InsertTransformer.java,v 1.4 2002/04/02 14:23:45 cziegeler Exp
$
*/
public class InsertTransformer
extends AbstractSunShineTransformer {
@@ -346,7 +347,7 @@
", create="+create+
", overwrite="+overwrite+
", resinsert="+reinsertPath+
- ", fragment="+(fragment == null ? "null" :
XMLUtil.serializeNodeToXML(fragment)));
+ ", fragment="+(fragment == null ? "null" :
XMLUtils.serializeNodeToXML(fragment)));
}
// test parameter
if (fileName == null) {
1.4 +3 -3
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/SunShinePreTransformer.java
Index: SunShinePreTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/transformation/SunShinePreTransformer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SunShinePreTransformer.java 13 Mar 2002 15:45:30 -0000 1.3
+++ SunShinePreTransformer.java 2 Apr 2002 14:23:45 -0000 1.4
@@ -60,7 +60,7 @@
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.sunshine.SunShineConstants;
import org.apache.cocoon.sunshine.connector.*;
-import org.apache.cocoon.sunshine.xml.XMLUtil;
+import org.apache.cocoon.xml.XMLUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -73,7 +73,7 @@
* pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: SunShinePreTransformer.java,v 1.3 2002/03/13 15:45:30
cziegeler Exp $
+ * @version CVS $Id: SunShinePreTransformer.java,v 1.4 2002/04/02 14:23:45
cziegeler Exp $
*/
public class SunShinePreTransformer
extends SunShineConnectTransformer {
@@ -263,7 +263,7 @@
this.stack.push(medium);
this.stack.push("MEDIUM");
}
-
this.startSerializedXMLRecording(XMLUtil.defaultSerializeToXMLFormat(true));
+
this.startSerializedXMLRecording(XMLUtils.defaultSerializeToXMLFormat(true));
// DEFAULT
} else {
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]