java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.xml.AbstractXMLPipe
org.apache.cocoon.transformation.AbstractTransformer
org.apache.cocoon.transformation.AbstractSAXTransformer
org.apache.cocoon.transformation.SourceWritingTransformer
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, Transformer, XMLPipe, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer
This - transformer allows you to output to a ModifiableSource.sourcewriting - sitemap.transformer.write-source -
This transformer allows you to output to a ModifiableSource.
Definition:
<map:transformer name="tofile" src="org.apache.cocoon.transformation.SourceWritingTransformer"> <!-- 'xml' is the default Serializer (if your Source needs one, like for instance FileSource) --> <map:parameter name="serializer" value="xml"/> </map:transformer/>
Invocation:
<map:transform type="tofile"> <map:parameter name="serializer" value="xml"/> <!-- you can optionally override the serializer here --> </map:transform>
The Tags:
<source:write create="[true]|false"> - replaces the entire content of an existing asset, if @create is 'true' (default), a new asset will be created if one does not already exist. <source:source>The System ID of the asset to be written to</source:source> - eg: "docs/blah.xml" or "context://blah.xml" etc. <source:path>[Optional] XPath to specify how your content is wrapped</source:path> - eg: "doc" (your content is placed inside a <doc/> root tag). NOTE: if this value is omitted, your content MUST have only ONE top-level node. <source:fragment>The XML Fragment to be written</source:fragment> - eg: "<foo><bar id="dogcow"/></foo>" or "<foo/><bar><dogcow/><bar/>" etc. NOTE: the second example type, can only be used when the <source:path/> tag has been specified. <source:write> <source:insert create="[true]|false" overwrite="[true]|false"> - inserts content into an existing asset, if @create is 'true' (default), a new asset will be created if one does not already exist. If @overwrite is set to 'true' the data is only inserted if the node specified by the 'replacePath' does not exists. <source:source>The System ID of the asset to be written to</source:source> - eg: "docs/blah.xml" or "context://blah.xml" etc. <source:path>XPath specifying the node into which the content is inserted</source:path> - eg: "doc" (your content is appended as the last child of the <doc/> root tag), or "doc/section[3]". NOTE: this tag is required in <source:insert/> unlike <source:write/> where it is optional. <source:replace>[Optional] XPath (relative to <source:path/>) to the node that is replaced by your new content</source:replace> - eg: "foo/bar/dogcow/@status='cut'" (is equivalent to this in XSLT: select="foo[bar/dogcow/@status='cut']"). <source:reinsert>[Optional] The XPath (relative to <source:replace/>) to backup the overwritten node to</source:reinsert> - eg: "foo/versions" or "/doc/versions/foo". NOTE: If specified and a node is replaced, all children of this replaced node will be reinserted at the given path. <source:fragment>The XML Fragment to be written</source:fragment> - eg: "<foo><bar id="dogcow"/></foo>" or "<foo/><bar><dogcow/><bar/>" etc. <source:insert> <source:delete > - deletes an existing asset. <source:source>The System ID of the asset to be deleted</source:source> - eg: "docs/blah.xml" or "context://blah.xml" etc. <source:path>[Ignored] XPath to specify how your content is wrapped</source:path> <source:fragment>[Ignored]The XML Fragment to be written</source:fragment> <source:delete>
Input XML document example (write):
<page> ... <source:write xmlns:source="http://apache.org/cocoon/source/1.0"> <source:source>context://doc/editable/my.xml</source:source> <source:fragment><page> <title>Hello World</title> <content> <p>This is my first paragraph.</p> </content> </page></source:fragment> </source:write> ... </page>
Input XML document example (insert at end):
<page> ... <source:insert xmlns:source="http://apache.org/cocoon/source/1.0"> <source:source>context://doc/editable/my.xml</source:source> <source:path>page/content</source:path> <source:fragment> <p>This paragraph gets <emp>inserted</emp>.</p> <p>With this one, at the end of the content.</p> </source:fragment> </source:insert> ... </page>
Input XML document example (insert at beginning):
<page> ... <source:insert> <source:source>context://doc/editable/my.xml</source:source> <source:path>page</source:path> <source:replace>content</source:replace> <source:reinsert>content</source:reinsert> <source:fragment> <content> <p>This new paragraph gets inserted <emp>before</emp> the other ones.</p> </content> </source:fragment> <source:insert> ... </page>
Input XML document example (replace):
<page> ... <source:insert xmlns:source="http://apache.org/cocoon/source/1.0"> <source:source>context://doc/editable/my.xml"</source:source> <source:path>page/content</source:path> <source:replace>p[1]</source:replace> <source:fragment> <p>This paragraph <emp>replaces</emp> the first paragraph.</p> </source:fragment> </source:insert> ... </page>
Output XML document example:
<page> ... <sourceResult xmlns:source="http://apache.org/cocoon/source/1.0"> <action>new|overwritten|none</action> <behaviour>write|insert<behaviour> <execution>success|failure</execution> <serializer>xml</serializer> <source>file:/source/specific/path/to/context/doc/editable/my.xml</source> </sourceResult> ... </page>The XPath specification is very complicated. So here is an example for the sitemap:
<page xmlns:source="http://apache.org/cocoon/source/1.0"> ... <source:insert> <source:source>sitemap.xmap</source:source> <source:path>/*[namespace-uri()="http://apache.org/cocoon/sitemap/1.0" and local-name()="sitemap"]/*[namespace-uri()="http://apache.org/cocoon/sitemap/1.0" and local-name()="components"]/*[namespace-uri()="http://apache.org/cocoon/sitemap/1.0" and local-name()="generators"]</source:path> <source:fragment> <generator name="file" xmln="http://apache.org/cocoon/sitemap/1.0"> <test/> </generator> </source:fragment> <source:replace>*[namespace-uri()="http://apache.org/cocoon/sitemap/1.0" and local-name()="generator" and attribute::name="file"]</source:replace> </source:insert> ... </page>
This insert replaces (if it exists) the file generator definition with a new one. As the sitemap uses namespaces the XPath for the generator is rather complicated. Due to this it is necessary that the node specified by path exists if namespaces are used! Otherwise a node with the name * would be created...
The create attribute of insert. If this is set to true (default is true), the file is created if it does not exists. If it is set to false, it is not created, making insert a real insert. create is only usable for files!
In addition the overwrite attribute is used to check if replacing is allowed. If overwrite is true (the default) the node is replaced. If it is false the node is not inserted if the replace node is available.
[JQ] - the way I understand this, looking at the code:
if 'replace' is not specified, your 'fragment' is appended as a child of 'path'. if 'replace' is specified and it exists and 'overwrite' is true, your 'fragment' is inserted in 'path', before 'replace' and then 'replace' is deleted. if 'replace' is specified and it exists and 'overwrite' is false, no action occurs. if 'replace' is specified and it does not exist and 'overwrite' is true, your 'fragment' is appended as a child of 'path'. if 'replace' is specified and it does not exist and 'overwrite' is false, your 'fragment' is appended as a child of 'path'. if 'reinsert' is specified and it does not exist, no action occurs.The <source:reinsert> option can be used to reinsert a replaced node at a given path in the new fragment. TODO: Use the serializer instead of the XMLUtils for inserting of fragments
< - a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler< - a href="mailto:jeremy@apache.org">Jeremy Quinn< - a href="mailto:gianugo@apache.org">Gianugo Rabellino$ - Id: SourceWritingTransformer.java 433543 2006-08-22 06:22:54Z crossley $| Field Summary | ||
|---|---|---|
| public static final String | SWT_URI | |
| public static final String | DEFAULT_SERIALIZER | |
| public static final String | WRITE_ELEMENT | incoming elements |
| public static final String | INSERT_ELEMENT | |
| public static final String | PATH_ELEMENT | |
| public static final String | FRAGMENT_ELEMENT | |
| public static final String | REPLACE_ELEMENT | |
| public static final String | DELETE_ELEMENT | |
| public static final String | SOURCE_ELEMENT | |
| public static final String | REINSERT_ELEMENT | |
| public static final String | RESULT_ELEMENT | outgoing elements |
| public static final String | EXECUTION_ELEMENT | |
| public static final String | BEHAVIOUR_ELEMENT | |
| public static final String | ACTION_ELEMENT | |
| public static final String | MESSAGE_ELEMENT | |
| public static final String | SERIALIZER_ELEMENT | |
| public static final String | SERIALIZER_ATTRIBUTE | main (write or insert) tag attributes |
| public static final String | CREATE_ATTRIBUTE | |
| public static final String | OVERWRITE_ATTRIBUTE | |
| public static final String | RESULT_FAILED | results |
| public static final String | RESULT_SUCCESS | |
| public static final String | ACTION_NONE | |
| public static final String | ACTION_NEW | |
| public static final String | ACTION_OVER | |
| public static final String | ACTION_DELETE | |
| protected String | configuredSerializerName | The configured serializer name |
| protected XPathProcessor | xpathProcessor | The XPath processor |
| Fields inherited from org.apache.cocoon.xml.AbstractXMLProducer: |
|---|
| EMPTY_CONTENT_HANDLER, xmlConsumer, contentHandler, lexicalHandler |
| Constructor: |
|---|
|
| Method from org.apache.cocoon.transformation.SourceWritingTransformer Summary: |
|---|
| configure, dispose, endTransformingElement, insertFragment, service, setup, startTransformingElement |
| Methods from org.apache.cocoon.xml.AbstractXMLPipe: |
|---|
| characters, comment, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startPrefixMapping |
| Methods from org.apache.cocoon.xml.AbstractXMLProducer: |
|---|
| recycle, setConsumer, setContentHandler, setLexicalHandler |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.cocoon.transformation.SourceWritingTransformer Detail: |
|---|
Configuration instance used by this
Configurable. |
|
|
|
|
Parameter called "serializer" from the
Transformer invocation. |
|