You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2004/09/27 19:57:11 UTC
svn commit: rev 47320 - cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation
Author: pier
Date: Mon Sep 27 10:57:10 2004
New Revision: 47320
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java
Log:
More JavaDOCs, comments, re-indenting, and filtering out the "include" namespaces declarations
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation/IncludeTransformer.java Mon Sep 27 10:57:10 2004
@@ -1,146 +1,252 @@
-/*
- * Copyright 1999-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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cocoon.transformation;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Map;
-
-import org.apache.avalon.framework.parameters.Parameters;
-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.caching.CacheableProcessingComponent;
-import org.apache.cocoon.components.source.SourceUtil;
-import org.apache.cocoon.components.source.impl.MultiSourceValidity;
-import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.xml.IncludeXMLConsumer;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceValidity;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-/**
- * Simple Source include transformer.
- *
- * <p>
- * Triggers for the element <code>include</code> in the
- * namespace <code>http://apache.org/cocoon/include/1.0</code>.
- * Use <code><include src="scheme://path"/></code>
- * </p>
- *
- * @cocoon.sitemap.component.name include
- * @cocoon.sitemap.component.logger sitemap.transformer.include
- *
- * @cocoon.sitemap.component.pooling.min 2
- * @cocoon.sitemap.component.pooling.max 16
- * @cocoon.sitemap.component.pooling.grow 2
- */
-public class IncludeTransformer extends AbstractTransformer
- implements Serviceable, Transformer,
- CacheableProcessingComponent {
-
- private static final String NS_URI = "http://apache.org/cocoon/include/1.0";
- private static final String INCLUDE_ELEMENT = "include";
- private static final String SRC_ATTRIBUTE = "src";
-
- private ServiceManager m_manager;
- private SourceResolver m_resolver;
- private MultiSourceValidity m_validity;
-
- public IncludeTransformer() {
- }
-
- public void service(ServiceManager manager) throws ServiceException {
- m_manager = manager;
- }
-
- public void setup(SourceResolver resolver, Map om, String src, Parameters parameters)
- throws ProcessingException, SAXException, IOException {
- m_resolver = resolver;
- m_validity = null;
- }
-
- public void recycle() {
- super.recycle();
- m_resolver = null;
- m_validity = null;
- }
-
- public void startDocument()
- throws SAXException {
- // Make sure that we have a validity while processing
- this.getValidity();
- super.startDocument();
- }
-
- public void endDocument()
- throws SAXException {
- // Make sure that the validity is "closed" at the end
- this.m_validity.close();
- super.endDocument();
- }
-
- public void startElement(String uri, String localName, String qName, Attributes atts)
- throws SAXException {
- if (NS_URI.equals(uri)) {
- if (INCLUDE_ELEMENT.equals(localName)) {
- String src = atts.getValue(SRC_ATTRIBUTE);
- Source source = null;
- try {
- source = m_resolver.resolveURI(src);
- m_validity.addSource(source);
- SourceUtil.toSAX(m_manager,
- source,
- "text/xml",
- new IncludeXMLConsumer(super.contentHandler));
- } catch (IOException e) {
- throw new SAXException(e);
- } catch (ProcessingException e) {
- throw new SAXException(e);
- } finally {
- if (source != null) {
- m_resolver.release(source);
- }
- }
- } else {
- getLogger().warn("Unrecognized element <" + qName + ">");
- }
- } else {
- super.startElement(uri, localName, qName, atts);
- }
- }
-
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (!NS_URI.equals(uri)) {
- super.endElement(uri, localName, qName);
- }
- }
-
- public Serializable getKey() {
- // FIXME: In case of including "cocoon://" or other dynamic sources
- // key has to be dynamic.
- return "I";
- }
-
- public SourceValidity getValidity() {
- if (m_validity == null) {
- m_validity = new MultiSourceValidity(m_resolver, -1);
- }
- return m_validity;
- }
-}
+/*
+ * Copyright 1999-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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.transformation;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+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.caching.CacheableProcessingComponent;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.components.source.impl.MultiSourceValidity;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.cocoon.xml.NamespacesTable;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceValidity;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>A simple transformer including resolvable sources (accessed through Cocoon's
+ * {@link SourceResolver} from its input.</p>
+ *
+ * <p>Inclusion is triggered by the <code><include ... /></code> element
+ * defined in the <code>http://apache.org/cocoon/include/1.0</code> namespace.</p>
+ *
+ * <p>Example:</p>
+ *
+ * <p><code><incl:include xmlns="http://apache.org/cocoon/include/1.0"
+ * src="cocoon://path/to/include"/></code></p>
+ *
+ * <p>An interesting feature of this {@link Transformer} is that it implements the
+ * {@link CacheableProcessingComponent} interface and provides full support for
+ * caching. In other words, if the input given to this transformer has not changed,
+ * and all of the included sources are (cacheable) and still valid, this transformer
+ * will not force a pipeline re-generation like the {@link CIncludeTransformer}.</p>
+ *
+ * @cocoon.sitemap.component.name include
+ * @cocoon.sitemap.component.logger sitemap.transformer.include
+ *
+ * @cocoon.sitemap.component.pooling.min 2
+ * @cocoon.sitemap.component.pooling.max 16
+ * @cocoon.sitemap.component.pooling.grow 2
+ */
+public class IncludeTransformer extends AbstractTransformer
+implements Serviceable, Transformer, CacheableProcessingComponent {
+
+ private static final String NS_URI = "http://apache.org/cocoon/include/1.0";
+ private static final String INCLUDE_ELEMENT = "include";
+ private static final String SRC_ATTRIBUTE = "src";
+
+ private ServiceManager m_manager;
+ private SourceResolver m_resolver;
+ private MultiSourceValidity m_validity;
+ private NamespacesTable m_namespaces;
+
+ /**
+ * <p>Create a new {@link IncludeTransformer} instance.</p>
+ */
+ public IncludeTransformer() {
+ super();
+ }
+
+ /**
+ * <p>Setup the {@link ServiceManager} available for this instance.</p>
+ *
+ * @see Serviceable#service(ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.m_manager = manager;
+ }
+
+ /**
+ * <p>Setup this component instance in the context of its pipeline and
+ * current request.</p>
+ *
+ * @see Serviceable#service(ServiceManager)
+ */
+ public void setup(SourceResolver resolver, Map om, String src, Parameters parameters)
+ throws ProcessingException, SAXException, IOException {
+ this.m_resolver = resolver;
+ this.m_validity = null;
+ this.m_namespaces = new NamespacesTable();
+ }
+
+ /**
+ * <p>Recycle this component instance.</p>
+ *
+ * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+ */
+ public void recycle() {
+ super.recycle();
+ this.m_resolver = null;
+ this.m_validity = null;
+ this.m_namespaces = new NamespacesTable();
+ }
+
+ /**
+ * <p>Receive notification of the beginning of an XML document.</p>
+ *
+ * @see org.xml.sax.ContentHandler#startDocument()
+ */
+ public void startDocument()
+ throws SAXException {
+ /* Make sure that we have a validity while processing */
+ this.getValidity();
+ super.startDocument();
+ }
+
+ /**
+ * <p>Receive notification of the end of an XML document.</p>
+ *
+ * @see org.xml.sax.ContentHandler#startDocument()
+ */
+ public void endDocument()
+ throws SAXException {
+ /* Make sure that the validity is "closed" at the end */
+ this.m_validity.close();
+ super.endDocument();
+ }
+
+ /**
+ * <p>Receive notification of the start of a prefix mapping.</p>
+ *
+ * <p>This transformer will remove all prefix mapping declarations for those
+ * prefixes associated with the <code>http://apache.org/cocoon/include/1.0</code>
+ * namespace.</p>
+ *
+ * @see org.xml.sax.ContentHandler#startPrefixMapping(String)
+ */
+ public void startPrefixMapping(String prefix, String nsuri)
+ throws SAXException {
+ if (NS_URI.equals(nsuri)) {
+ /* Skipping mapping for the current prefix as it's ours */
+ this.m_namespaces.addDeclaration(prefix, nsuri);
+ } else {
+ /* Map the current prefix, as we don't know it */
+ super.startPrefixMapping(prefix, nsuri);
+ }
+ }
+
+ /**
+ * <p>Receive notification of the end of a prefix mapping.</p>
+ *
+ * <p>This transformer will remove all prefix mapping declarations for those
+ * prefixes associated with the <code>http://apache.org/cocoon/include/1.0</code>
+ * namespace.</p>
+ *
+ * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
+ */
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+ if (NS_URI.equals(this.m_namespaces.getUri(prefix))) {
+ /* Skipping unmapping for the current prefix as it's ours */
+ this.m_namespaces.removeDeclaration(prefix);
+ } else {
+ /* Unmap the current prefix, as we don't know it */
+ super.endPrefixMapping(prefix);
+ }
+ }
+
+ /**
+ * <p>Receive notification of the start of an element.</p>
+ *
+ * @see org.xml.sax.ContentHandler#startElement(String, String, String, org.xml.sax.Attributes)
+ */
+ public void startElement(String uri, String localName, String qName, Attributes atts)
+ throws SAXException {
+ if (NS_URI.equals(uri)) {
+ if (INCLUDE_ELEMENT.equals(localName)) {
+ String src = atts.getValue(SRC_ATTRIBUTE);
+ Source source = null;
+ try {
+ source = m_resolver.resolveURI(src);
+ if (m_validity != null) {
+ m_validity.addSource(source);
+ }
+ SourceUtil.toSAX(m_manager, source, "text/xml",
+ new IncludeXMLConsumer(super.contentHandler));
+ }
+ catch (IOException e) {
+ throw new SAXException(e);
+ }
+ catch (ProcessingException e) {
+ throw new SAXException(e);
+ }
+ finally {
+ if (source != null) {
+ m_resolver.release(source);
+ }
+ }
+ }
+ } else {
+ super.startElement(uri, localName, qName, atts);
+ }
+ }
+
+ /**
+ * <p>Receive notification of the end of an element.</p>
+ *
+ * @see org.xml.sax.ContentHandler#endElement(String, String, String)
+ */
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if (!NS_URI.equals(uri)) {
+ super.endElement(uri, localName, qName);
+ }
+ }
+
+ /**
+ * <p>Return the validity key associated with this transformation.</p>
+ *
+ * @see CacheableProcessingComponent#getKey()
+ */
+ public Serializable getKey() {
+ // FIXME: In case of including "cocoon://" or other dynamic sources
+ // key has to be dynamic.
+ return "I";
+ }
+
+ /**
+ * <p>Generate (or return) the {@link SourceValidity} instance used to
+ * possibly validate cached generations.</p>
+ *
+ * @return a <b>non null</b> {@link SourceValidity}.
+ * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
+ */
+ public SourceValidity getValidity() {
+ if (m_validity == null) {
+ m_validity = new MultiSourceValidity(m_resolver, -1);
+ }
+ return m_validity;
+ }
+}
Re: Adding Files to Subcersion, Re: svn commit: rev 47320
Posted by David Crossley <cr...@apache.org>.
Vadim Gritsenko wrote:
> Pier Fumagalli wrote:
> >
> > I think there's a line-ending problem with this file. My local diffs
> > were much smaller!
> >
> > Pier (scratching his head, and wondering)
>
> Don' wonder; properties were missing.
>
> Each time you add a text file into repository, these two properties have
> to be set:
>
> svn propset svn:keywords Id <path>
> svn propset svn:eol-style native <path>
>
> I guess there is some way to do this automatically - anybody knows how
> to set this up for Cocoon SVN repo?
http://issues.cocoondev.org/browse/FOR-124
--
David Crossley
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 28 Sep 2004, at 14:54, Pier Fumagalli wrote:
> + // TODO: remove this debugging code!
> + System.err.println("Including \"" + encodedSource
> + "\" from \""
> + + source.getURI() + "\" ("
> + + this.x_parameters.size() +
> ")");
> + Iterator iterator =
> this.x_parameters.keySet().iterator();
> + while (iterator.hasNext()) {
> + String name = (String) iterator.next();
> + System.err.println("Parameter \"" + name +
> "\"=\"" + this.x_parameters.get(name) + "\"");
> + }
> + // TODO: remove the above debugging code!
Sorry, left some debugging code in!
Pier
Eclipse, Re: FIXME in IncludeTransformer
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> FUDGE! :-) I blame that on Eclipse's auto-completion! ;-P
How do you fight with Eclipse and tab characters? I spent couple of hours in
eclipse and my source code now full of tabs... Had to reformat with IDEA.
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 28 Sep 2004, at 19:10, Vadim Gritsenko wrote:
> Ok, like Hashtable usage:
>
> + this.x_parameters = new Hashtable();
>
> Instead of HashMap (with default map size):
>
> + this.x_parameters = new HashMap(3);
FUDGE! :-) I blame that on Eclipse's auto-completion! ;-P
> Or, like doing:
>
> + this.x_source = atts.getValue(SRC_ATTRIBUTE);
> + if ((this.x_source == null) || (this.x_source.length() == 0)) {
> + throw new SAXException("Unspecified \"src\" attribute");
>
> When you just defined a constant ;-)
>
> + this.x_source = atts.getValue(SRC_ATTRIBUTE);
> + if ((this.x_source == null) || (this.x_source.length() == 0)) {
> + throw new SAXException("Unspecified \"" + SRC_ATTRIBUTE + "\"
> attribute");
>
> (Same with:
> + throw new SAXException("Unspecified \"name\" attribute");
> )
Yup... That's my mistake!
> I'd also go with null this.x_parameters by default, and creating
> HashMap when necessary, and this.x_parameters = null instead of
> .clear() - saves some cycles in most commonly used scenarios (no
> parameters).
Yep... Agreed!
Patched and committed.
Pier
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 28 Sep 2004, at 18:13, Vadim Gritsenko wrote:
>
>> Pier Fumagalli wrote:
>>
>>> On 28 Sep 2004, at 12:00, Vadim Gritsenko wrote:
>>>
>>>> Go ahead, add parameters.
>>
>> ...
>>
>>>> <i:parameter name="name">value</i:parameter>
>>>
>>> Done, I'm posting the patch here before applying just to triple-check
>>> I'm not f***ing up the whole thing. I mean, it works for me, but do
>>> a quick review.
>>
>>
>> Beside minor nitpicks, looks good :-)
>
>
> Like? :-P
Ok, like Hashtable usage:
+ this.x_parameters = new Hashtable();
Instead of HashMap (with default map size):
+ this.x_parameters = new HashMap(3);
Or, like doing:
+ this.x_source = atts.getValue(SRC_ATTRIBUTE);
+ if ((this.x_source == null) || (this.x_source.length() == 0)) {
+ throw new SAXException("Unspecified \"src\" attribute");
When you just defined a constant ;-)
+ this.x_source = atts.getValue(SRC_ATTRIBUTE);
+ if ((this.x_source == null) || (this.x_source.length() == 0)) {
+ throw new SAXException("Unspecified \"" + SRC_ATTRIBUTE + "\"
attribute");
(Same with:
+ throw new SAXException("Unspecified \"name\" attribute");
)
I'd also go with null this.x_parameters by default, and creating HashMap
when necessary, and this.x_parameters = null instead of .clear() -
saves some cycles in most commonly used scenarios (no parameters).
:-P
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 28 Sep 2004, at 18:13, Vadim Gritsenko wrote:
> Pier Fumagalli wrote:
>
>> On 28 Sep 2004, at 12:00, Vadim Gritsenko wrote:
>>> Go ahead, add parameters.
> ...
>>> <i:parameter name="name">value</i:parameter>
>> Done, I'm posting the patch here before applying just to triple-check
>> I'm not f***ing up the whole thing. I mean, it works for me, but do
>> a quick review.
>
> Beside minor nitpicks, looks good :-)
Like? :-P
Pier
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 28 Sep 2004, at 12:00, Vadim Gritsenko wrote:
>
>> Go ahead, add parameters.
...
>> <i:parameter name="name">value</i:parameter>
>
>
> Done, I'm posting the patch here before applying just to triple-check
> I'm not f***ing up the whole thing. I mean, it works for me, but do a
> quick review.
Beside minor nitpicks, looks good :-)
> Now, I moved all the inclusion in the EndElement method, and I'm
> matching parameters in the second format (the easy, non-verbose one).
> I'm making sure that ALL parameters are nicely URL-encoded, so that we
> don't have problems down the line, and (in my version), I updated the
> JavaDOCs quite a lot (including comments and re-indenting of the sources).
Cool
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 28 Sep 2004, at 12:00, Vadim Gritsenko wrote:
> Pier Fumagalli wrote:
>> On 27 Sep 2004, at 23:49, Vadim Gritsenko wrote:
>>> Pier Fumagalli wrote:
>>>
>>>> Then we could re-create the request by something like:
>>>> <incl:include src="proto://whatever">
>>>> <incl:param name="parameterName">value</incl:param>
>>>> </incl:include>
>>>
>>>
>>> Well, if the only thing which troubles you is request, then you can
>>> easily do this now with simple:
>>>
>>> <i:include src="cocoon://pipeline?param=value"/>
>>>
>>> And be done with it. You won't need any changes in
>>> IncludeTransformer at all.
>> The only problem with it is the encoding of the URL, which I shall do
>> in XSLT, somehow...
>> Parameters that might contain "weird" characters like "&" or "="
>> could be troublesome, while if explicitly included in elements, it
>> would make our life easier...
>
> Go ahead, add parameters. We still need to re-create CInclude
> functionality in order to deprecate it. But, it won't solve caching
> issue mentioned - I guess I'll tackle it later. JFYI, that's how it
> looks in CInclude:
>
> <!-- The following are optional parameters appended to the URI -->
> <cinclude:parameters>
> <cinclude:parameter>
> <cinclude:name>a name</cinclude:name>
> <cinclude:value>a value</cinclude:value>
> </cinclude:parameter>
> <!-- more can follow -->
> </cinclude:parameters>
>
> A bit too verbose... I'd go with your's:
>
> <i:parameter name="name">value</i:parameter>
Done, I'm posting the patch here before applying just to triple-check
I'm not f***ing up the whole thing. I mean, it works for me, but do a
quick review.
Now, I moved all the inclusion in the EndElement method, and I'm
matching parameters in the second format (the easy, non-verbose one).
I'm making sure that ALL parameters are nicely URL-encoded, so that we
don't have problems down the line, and (in my version), I updated the
JavaDOCs quite a lot (including comments and re-indenting of the
sources).
Pier
--
cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/transformation/
IncludeTransformer.java Mon Sep 27 18:56:13 2004
+++
core/sources/local/org/apache/cocoon/transformation/
IncludeTransformer.java Tue Sep 28 14:51:01 2004
@@ -17,6 +17,10 @@
import java.io.IOException;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.parameters.Parameters;
@@ -28,6 +32,7 @@
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.components.source.impl.MultiSourceValidity;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.util.NetUtils;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.cocoon.xml.NamespacesTable;
import org.apache.excalibur.source.Source;
@@ -44,8 +49,31 @@
*
* <p>Example:</p>
*
- * <p><code><incl:include
xmlns="http://apache.org/cocoon/include/1.0"
- * src="cocoon://path/to/include"/></code></p>
+ * <pre>
+ * <incl:include xmlns:incl="http://apache.org/cocoon/include/1.0"
+ * src="cocoon://path/to/include"/>
+ * </pre>
+ *
+ * <p>Parameters to be passed to the included sources can be specified
in two ways:
+ * the first one is to encode them onto the source itelf, for
example:</p>
+ *
+ * <pre>
+ * <incl:include xmlns:incl="http://apache.org/cocoon/include/1.0"
+ *
src="cocoon://path/to/include?paramA=valueA&paramB=valueB"/>
+ * </pre>
+ *
+ * <p>Another approach allows the encoding of parameters to be done
automatically by
+ * the transformer, so that one can easily pass parameter name or
values containing
+ * the <code>&</code> (amperstand) or <code>=</code> (equals)
character, which are
+ * reserved characters in URIs. An example:</p>
+ *
+ * <pre>
+ * <incl:include xmlns:incl="http://apache.org/cocoon/include/1.0"
+ * src="cocoon://path/to/include">
+ * <incl:parameter name="firstParameterName"
value="firstParameterValue"/>
+ * <incl:parameter name="other&Para=Name"
value="other=Para&Value"/>
+ * </incl:include>
+ * </pre>
*
* <p>An interesting feature of this {@link Transformer} is that it
implements the
* {@link CacheableProcessingComponent} interface and provides full
support for
@@ -63,15 +91,41 @@
public class IncludeTransformer extends AbstractTransformer
implements Serviceable, Transformer, CacheableProcessingComponent {
+ /** <p>The namespace URI of the elements recognized by this
transformer.</p> */
private static final String NS_URI =
"http://apache.org/cocoon/include/1.0";
+ /** <p>The name of the element triggering inclusion of
sources.</p> */
private static final String INCLUDE_ELEMENT = "include";
+ /** <p>The name of the element defining an included subrequest
parameter.</p> */
+ private static final String PARAMETER_ELEMENT = "parameter";
+ /** <p>The name of the attribute indicating the included source
URI.</p> */
private static final String SRC_ATTRIBUTE = "src";
+ /** <p>The name of the attribute indicating the parameter
name.</p> */
+ private static final String NAME_ATTRIBUTE = "name";
+ /** <p>The name of the attribute indicating the parameter
name.</p> */
+ private static final String VALUE_ATTRIBUTE = "value";
+ /** <p>The encoding to use for parameter names and values.</p> */
+ private static final String ENCODING = "US-ASCII";
+
+ /** <p>The {@link ServiceManager} instance associated with this
instance.</p> */
private ServiceManager m_manager;
+ /** <p>The {@link SourceResolver} used to resolve included
URIs.</p> */
private SourceResolver m_resolver;
+ /** <p>The {@link SourceValidity} instance associated with this
request.</p> */
private MultiSourceValidity m_validity;
+ /** <p>A {@link NamespacesTable} used to filter namespace
declarations.</p> */
private NamespacesTable m_namespaces;
+ /** <p>A {@link Map} of the parameters to supply to the included
source.</p> */
+ private Map x_parameters;
+ /** <p>The source to be included declared in an include
element.</p> */
+ private String x_source;
+ /** <p>The current parameter name captured.</p> */
+ private String x_parameter;
+ /** <p>The current parameter value (as a {@link
StringBuffer}).</p> */
+ private StringBuffer x_value;
+
+
/**
* <p>Create a new {@link IncludeTransformer} instance.</p>
*/
@@ -99,6 +153,8 @@
this.m_resolver = resolver;
this.m_validity = null;
this.m_namespaces = new NamespacesTable();
+ this.x_parameters = new Hashtable();
+ this.x_value = new StringBuffer();
}
/**
@@ -111,6 +167,8 @@
this.m_resolver = null;
this.m_validity = null;
this.m_namespaces = new NamespacesTable();
+ this.x_parameters = new Hashtable();
+ this.x_value = new StringBuffer();
}
/**
@@ -178,39 +236,90 @@
}
/**
+ * <p>Receive notification of characters.</p>
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ public void characters(char data[], int offset, int length)
+ throws SAXException {
+ /* If we have a parameter value to add to, let's add this
chunk */
+ if (this.x_parameter != null) {
+ this.x_value.append(data, offset, length);
+ /* Forward this only if we are not inside an include tag */
+ } else if (this.x_source != null) {
+ super.characters(data, offset, length);
+ }
+ }
+
+ /**
* <p>Receive notification of the start of an element.</p>
*
- * @see org.xml.sax.ContentHandler#startElement(String, String,
String, org.xml.sax.Attributes)
+ * @see org.xml.sax.ContentHandler#startElement(String, String,
String, Attributes)
*/
public void startElement(String uri, String localName, String
qName, Attributes atts)
throws SAXException {
+ /* Check the namespace declaration */
if (NS_URI.equals(uri)) {
+ /* Inclusion will not happen here but when we close this
tag */
if (INCLUDE_ELEMENT.equals(localName)) {
- String src = atts.getValue(SRC_ATTRIBUTE);
- Source source = null;
- try {
- source = m_resolver.resolveURI(src);
- if (m_validity != null) {
- m_validity.addSource(source);
+ /* Check before we include (we don't want nested
stuff) */
+ if (this.x_source != null) {
+ throw new SAXException("Invalid include nested in
another");
}
- SourceUtil.toSAX(m_manager, source, "text/xml",
- new
IncludeXMLConsumer(super.contentHandler));
+
+ /* Remember the source we are trying to include */
+ this.x_source = atts.getValue(SRC_ATTRIBUTE);
+ if ((this.x_source == null) || (this.x_source.length()
== 0)) {
+ throw new SAXException("Unspecified \"src\"
attribute");
}
- catch (IOException e) {
- throw new SAXException(e);
+
+ /* Whatever list of parameters we got before, we wipe
it! */
+ this.x_parameters.clear();
+ this.x_value.setLength(0);
+ this.x_parameter = null;
+
+ /* Done with this element */
+ return;
}
- catch (ProcessingException e) {
- throw new SAXException(e);
+
+ /* If this is a parameter, then make sure we prepare. */
+ if (PARAMETER_ELEMENT.equals(localName)) {
+ /* Check if we are in the right context */
+ if (this.x_source == null) {
+ throw new SAXException("Parameter specified
outside of include");
}
- finally {
- if (source != null) {
- m_resolver.release(source);
+ if (this.x_parameter != null) {
+ throw new SAXException("Invalid parameter nested
in another");
}
+
+ /* Get and process the parameter name */
+ this.x_parameter = atts.getValue(NAME_ATTRIBUTE);
+ if ((this.x_parameter == null) ||
(this.x_parameter.length() == 0)) {
+ throw new SAXException("Unspecified \"name\"
attribute");
}
+
+ /* Make some room for the parameter value */
+ this.x_value.setLength(0);
+ String value = atts.getValue(VALUE_ATTRIBUTE);
+ if (value != null) this.x_value.append(value);
+
+ /* Done with this element */
+ return;
}
- } else {
+
+ /* We don't have a clue of why we got here (wrong
element?) */
+ if (this.getLogger().isWarnEnabled()) {
+ this.getLogger().warn("Unknown element \"" + localName
+ "\"");
+ }
+ return;
+ }
+
+ /* Not our namespace, simply check and pass this element on! */
+ if (this.x_source == null) {
super.startElement(uri, localName, qName, atts);
+ return;
}
+ throw new SAXException("Element <" + qName + "/> invalid
inside include");
}
/**
@@ -220,7 +329,78 @@
*/
public void endElement(String uri, String localName, String qName)
throws SAXException {
- if (!NS_URI.equals(uri)) {
+ /* Check the namespace declaration */
+ if (NS_URI.equals(uri)) {
+
+ /* Inclusion will happen here, when we close the include
element */
+ if (INCLUDE_ELEMENT.equals(localName)) {
+
+ /* Get the source discovered opening the element and
include */
+ Source source = null;
+ try {
+ String encodedSource =
NetUtils.parameterize(this.x_source,
+
this.x_parameters);
+ source = m_resolver.resolveURI(encodedSource);
+ if (m_validity != null)
m_validity.addSource(source);
+
+ // TODO: remove this debugging code!
+ System.err.println("Including \"" + encodedSource
+ "\" from \""
+ + source.getURI() + "\" ("
+ + this.x_parameters.size() +
")");
+ Iterator iterator =
this.x_parameters.keySet().iterator();
+ while (iterator.hasNext()) {
+ String name = (String) iterator.next();
+ System.err.println("Parameter \"" + name +
"\"=\"" + this.x_parameters.get(name) + "\"");
+ }
+ // TODO: remove the above debugging code!
+
+ SourceUtil.toSAX(m_manager, source, "text/xml",
+ new
IncludeXMLConsumer(super.contentHandler));
+ } catch (IOException e) {
+ /* Something bad happenend processing a stream */
+ throw new SAXException(e);
+ } catch (ProcessingException e) {
+ /* Something bad happened processing a pipeline */
+ throw new SAXException(e);
+ } finally {
+ /* In any case, make sure we release the source */
+ if (source != null) m_resolver.release(source);
+ }
+
+ /* We are done with the include element */
+ this.x_parameters.clear();
+ this.x_value.setLength(0);
+ this.x_parameter = null;
+ this.x_source = null;
+ return;
+ }
+
+ /* Addition of parameters happens here (so that we can
capture chars) */
+ if (PARAMETER_ELEMENT.equals(localName)) {
+ String value = this.x_value.toString();
+
+ /* Store the parameter name and value */
+ try {
+ /*
+ * Note: the parameter name and value are URL
encoded, so that
+ * weird characters such as "&" or "=" (have
special meaning)
+ * are passed through flawlessly.
+ */
+
this.x_parameters.put(URLEncoder.encode(this.x_parameter, ENCODING),
+ URLEncoder.encode(value,
ENCODING));
+ } catch (UnsupportedEncodingException e) {
+ throw new SAXException("Your platform does not
support the "
+ + ENCODING + " encoding",
e);
+ }
+
+ /* We are done with this parameter element */
+ this.x_value.setLength(0);
+ this.x_parameter = null;
+ return;
+ }
+
+ } else {
+ /* This is not our namespace, pass the event on! */
super.endElement(uri, localName, qName);
}
}
@@ -231,8 +411,10 @@
* @see CacheableProcessingComponent#getKey()
*/
public Serializable getKey() {
- // FIXME: In case of including "cocoon://" or other dynamic
sources
- // key has to be dynamic.
+ /*
+ * FIXME: In case of including "cocoon://" or other dynamic
sources
+ * key has to be dynamic.
+ */
return "I";
}
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 27 Sep 2004, at 23:49, Vadim Gritsenko wrote:
>
>> Pier Fumagalli wrote:
>>
>>> Then we could re-create the request by something like:
>>> <incl:include src="proto://whatever">
>>> <incl:param name="parameterName">value</incl:param>
>>> </incl:include>
>>
>>
>> Well, if the only thing which troubles you is request, then you can
>> easily do this now with simple:
>>
>> <i:include src="cocoon://pipeline?param=value"/>
>>
>> And be done with it. You won't need any changes in IncludeTransformer
>> at all.
>
>
> The only problem with it is the encoding of the URL, which I shall do in
> XSLT, somehow...
>
> Parameters that might contain "weird" characters like "&" or "=" could
> be troublesome, while if explicitly included in elements, it would make
> our life easier...
Go ahead, add parameters. We still need to re-create CInclude
functionality in order to deprecate it. But, it won't solve caching
issue mentioned - I guess I'll tackle it later. JFYI, that's how it
looks in CInclude:
<!-- The following are optional parameters appended to the URI -->
<cinclude:parameters>
<cinclude:parameter>
<cinclude:name>a name</cinclude:name>
<cinclude:value>a value</cinclude:value>
</cinclude:parameter>
<!-- more can follow -->
</cinclude:parameters>
A bit too verbose... I'd go with your's:
<i:parameter name="name">value</i:parameter>
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 27 Sep 2004, at 23:49, Vadim Gritsenko wrote:
> Pier Fumagalli wrote:
>> On 27 Sep 2004, at 21:06, Vadim Gritsenko wrote:
>>>
>>>> What about using a similar approach to generate the cache? I'll try
>>>> to set up a test environment and to give it a shot if you have
>>>> nothing against it!
>>>
>>>
>>> Do you refer to the fact that it uses list of request parameters and
>>> its values as a cache key?
>>>
>>> Yes, I'm against it. Request parameter in previous email was simply
>>> an example - it could be anything from the environment at large (==
>>> JVM where application is running + OS + ...).
>> Yep... I see your point, you're 100% right...
>>> Proper solution will be composed key similar to the composed
>>> validity in IncludeTransformer. This also can be made configurable:
>>> in simplier cases, you won't need aggregated key and can use
>>> transformer as it is now.
>> I was thinking about one thing... The one thing that troubles us is
>> the "request". That introduce a degree of variability that (i don't
>> know to what degree), might be counter-productive to analyze and
>> cache...
>> What about if we were doing "subrequest"s, much like in Apache... I
>> mean, why making the "included" request inherit all the varible
>> stuff? Wouldn't it be simply easier to create a new request/response
>> and start from a clean status.
>> Then we could re-create the request by something like:
>> <incl:include src="proto://whatever">
>> <incl:param name="parameterName">value</incl:param>
>> </incl:include>
>
> Well, if the only thing which troubles you is request, then you can
> easily do this now with simple:
>
> <i:include src="cocoon://pipeline?param=value"/>
>
> And be done with it. You won't need any changes in IncludeTransformer
> at all.
The only problem with it is the encoding of the URL, which I shall do
in XSLT, somehow...
Parameters that might contain "weird" characters like "&" or "=" could
be troublesome, while if explicitly included in elements, it would make
our life easier...
Pier
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 27 Sep 2004, at 21:06, Vadim Gritsenko wrote:
>
>>
>>> What about using a similar approach to generate the cache? I'll try
>>> to set up a test environment and to give it a shot if you have
>>> nothing against it!
>>
>>
>> Do you refer to the fact that it uses list of request parameters and
>> its values as a cache key?
>>
>> Yes, I'm against it. Request parameter in previous email was simply an
>> example - it could be anything from the environment at large (== JVM
>> where application is running + OS + ...).
>
>
> Yep... I see your point, you're 100% right...
>
>> Proper solution will be composed key similar to the composed validity
>> in IncludeTransformer. This also can be made configurable: in simplier
>> cases, you won't need aggregated key and can use transformer as it is
>> now.
>
>
> I was thinking about one thing... The one thing that troubles us is the
> "request". That introduce a degree of variability that (i don't know to
> what degree), might be counter-productive to analyze and cache...
>
> What about if we were doing "subrequest"s, much like in Apache... I
> mean, why making the "included" request inherit all the varible stuff?
> Wouldn't it be simply easier to create a new request/response and start
> from a clean status.
>
> Then we could re-create the request by something like:
>
> <incl:include src="proto://whatever">
> <incl:param name="parameterName">value</incl:param>
> </incl:include>
Well, if the only thing which troubles you is request, then you can
easily do this now with simple:
<i:include src="cocoon://pipeline?param=value"/>
And be done with it. You won't need any changes in IncludeTransformer at
all.
Even better, I think you can implement a protocol which makes parameters
of original request unavailable.
Unfortunately, this does not help with issue I'm having. In my case
internal pipeline obtains everything it needs from environment on its
own - this allows to create static URLs (like cocoon://user/country)
which can be included into the CMSed content and these static URLs will
generate appropriate (customized / personalized) content depending on
current environment (session / cookies / virtual host / etc).
Same issue, IIUC, will also appear in block scenario, when interface to
the skin block is fixed as set of block:skin:// URIs, and skin
implementation can return personalized skin based on user preferences or
something.
So, how about doing it right the first time? ;-)
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 27 Sep 2004, at 21:06, Vadim Gritsenko wrote:
>
>> What about using a similar approach to generate the cache? I'll try
>> to set up a test environment and to give it a shot if you have
>> nothing against it!
>
> Do you refer to the fact that it uses list of request parameters and
> its values as a cache key?
>
> Yes, I'm against it. Request parameter in previous email was simply an
> example - it could be anything from the environment at large (== JVM
> where application is running + OS + ...).
Yep... I see your point, you're 100% right...
> Proper solution will be composed key similar to the composed validity
> in IncludeTransformer. This also can be made configurable: in simplier
> cases, you won't need aggregated key and can use transformer as it is
> now.
I was thinking about one thing... The one thing that troubles us is the
"request". That introduce a degree of variability that (i don't know to
what degree), might be counter-productive to analyze and cache...
What about if we were doing "subrequest"s, much like in Apache... I
mean, why making the "included" request inherit all the varible stuff?
Wouldn't it be simply easier to create a new request/response and start
from a clean status.
Then we could re-create the request by something like:
<incl:include src="proto://whatever">
<incl:param name="parameterName">value</incl:param>
</incl:include>
Pier
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 27 Sep 2004, at 20:17, Vadim Gritsenko wrote:
>
>> PK_G-file-doc.xml_T-I-cocoon://internal?pipelinehash=1234567890_S-xml
>
>
> Have you seen my earlier commit of the "ResourceParameterGenerator"
> today?
Yes, "RequestParameterGenerator".
> What about using a similar approach to generate the cache? I'll
> try to set up a test environment and to give it a shot if you have
> nothing against it!
Do you refer to the fact that it uses list of request parameters and its
values as a cache key?
Yes, I'm against it. Request parameter in previous email was simply an
example - it could be anything from the environment at large (== JVM
where application is running + OS + ...).
Proper solution will be composed key similar to the composed validity in
IncludeTransformer. This also can be made configurable: in simplier
cases, you won't need aggregated key and can use transformer as it is now.
Vadim
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 27 Sep 2004, at 20:17, Vadim Gritsenko wrote:
> Pier Fumagalli wrote:
>
> Sure. Problem is the following. Consider you have a pipeline
> 'internal' which generates different responses depending on the value
> of request parameter 'a':
>
> <map:match pattern="internal">
> <map:generate src="{request-param:a}.xml"/>
> <map:serialize type="xml"/>
> </map:match>
>
> Example request and responses:
>
> Requesting /internal?a=one gives:
> <one/>
>
> Requesting /internal?a=two gives:
> <two/>
>
>
> Now, let's aggregate this pipeline into another pipeline, 'external',
> using Include transformer and input document like this:
> <doc>
> <i:include src="cocoon://internal"/>
> </doc>
>
> Requesting 'external' pipeline *should* give following result:
>
> Requesting /external?a=one should give:
> <doc>
> <one/>
> </doc>
>
> Requesting /external?a=two should give:
> <doc>
> <two/>
> </doc>
>
>
> But, this does not happen. Response on the first request to the
> 'external' pipeline will get cached, and all following requests will
> get same cached response *regardless* of request parameter. This
> happens because pipeline keys for "/external?a=one" and
> "/external?a=two" do not differ, they are the same:
>
> PK_G-file-doc.xml_T-I_S-xml
>
> (that's how pipeline key would look like if 'external' consists of
> file generator / include transformer / xml serializer). This problem
> can be solved by adding keys of included sources to the pipeline key -
> same way as validity is assembled. In this example, key of the
> 'internal' SitemapSource will be added, which is composed out of
> source's system ID (cocoon://internal), and hash of the pipeline key
> (which is different for /internal?a=one and /internal?a=two because it
> contains name of the file to generate response from - one.xml or
> two.xml). Resulting key then will be something like:
>
> PK_G-file-doc.xml_T-I-cocoon://internal?pipelinehash=1234567890_S-xml
Have you seen my earlier commit of the "ResourceParameterGenerator"
today? What about using a similar approach to generate the cache? I'll
try to set up a test environment and to give it a shot if you have
nothing against it!
Pier
Re: FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 27 Sep 2004, at 19:15, Vadim Gritsenko wrote:
>
>> Don' wonder; properties were missing.
>
> Cheeridos!
:)
> Now, an annotated dump on the source tells me that you added the
> following FIXME comment:
>
> 36336 unico public Serializable getKey() {
> 47017 vgritsenko // FIXME: In case of including "cocoon://" or
> other dynamic sources
> 47017 vgritsenko // key has to be dynamic.
> 47017 vgritsenko return "I";
> 36336 unico }
>
> Care to explain the problem? I need to have this working (somehow) and
> have some time on my hands to spare and dedicate to the cause of
> caching! :-P
Sure. Problem is the following. Consider you have a pipeline 'internal'
which generates different responses depending on the value of request
parameter 'a':
<map:match pattern="internal">
<map:generate src="{request-param:a}.xml"/>
<map:serialize type="xml"/>
</map:match>
Example request and responses:
Requesting /internal?a=one gives:
<one/>
Requesting /internal?a=two gives:
<two/>
Now, let's aggregate this pipeline into another pipeline, 'external',
using Include transformer and input document like this:
<doc>
<i:include src="cocoon://internal"/>
</doc>
Requesting 'external' pipeline *should* give following result:
Requesting /external?a=one should give:
<doc>
<one/>
</doc>
Requesting /external?a=two should give:
<doc>
<two/>
</doc>
But, this does not happen. Response on the first request to the
'external' pipeline will get cached, and all following requests will get
same cached response *regardless* of request parameter. This happens
because pipeline keys for "/external?a=one" and "/external?a=two" do not
differ, they are the same:
PK_G-file-doc.xml_T-I_S-xml
(that's how pipeline key would look like if 'external' consists of file
generator / include transformer / xml serializer). This problem can be
solved by adding keys of included sources to the pipeline key - same way
as validity is assembled. In this example, key of the 'internal'
SitemapSource will be added, which is composed out of source's system ID
(cocoon://internal), and hash of the pipeline key (which is different
for /internal?a=one and /internal?a=two because it contains name of the
file to generate response from - one.xml or two.xml). Resulting key then
will be something like:
PK_G-file-doc.xml_T-I-cocoon://internal?pipelinehash=1234567890_S-xml
Vadim
FIXME in IncludeTransformer [Was: Re: Adding Files to Subversion]
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 27 Sep 2004, at 19:15, Vadim Gritsenko wrote:
> Pier Fumagalli wrote:On 27 Sep 2004, at 18:57, pier@apache.org wrote:
>>> Author: pier
>>> Date: Mon Sep 27 10:57:10 2004
>>> New Revision: 47320
>>>
>>> Modified:
>>>
>>> cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/
>>> cocoon/transformation/IncludeTransformer.java
>>> Log:
>>> More JavaDOCs, comments, re-indenting, and filtering out the
>>> "include" namespaces declarations
>> I think there's a line-ending problem with this file. My local diffs
>> were much smaller!
>> Pier (scratching his head, and wondering)
>
> Don' wonder; properties were missing.
Cheeridos!
Now, an annotated dump on the source tells me that you added the
following FIXME comment:
36336 unico public Serializable getKey() {
47017 vgritsenko // FIXME: In case of including "cocoon://" or
other dynamic sources
47017 vgritsenko // key has to be dynamic.
47017 vgritsenko return "I";
36336 unico }
Care to explain the problem? I need to have this working (somehow) and
have some time on my hands to spare and dedicate to the cause of
caching! :-P
Pier
Adding Files to Subcersion, Re: svn commit: rev 47320
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Pier Fumagalli wrote:
> On 27 Sep 2004, at 18:57, pier@apache.org wrote:
>
>> Author: pier
>> Date: Mon Sep 27 10:57:10 2004
>> New Revision: 47320
>>
>> Modified:
>>
>> cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/
>> cocoon/transformation/IncludeTransformer.java
>> Log:
>> More JavaDOCs, comments, re-indenting, and filtering out the
>> "include" namespaces declarations
>
>
> I think there's a line-ending problem with this file. My local diffs
> were much smaller!
>
> Pier (scratching his head, and wondering)
Don' wonder; properties were missing.
Each time you add a text file into repository, these two properties have
to be set:
svn propset svn:keywords Id <path>
svn propset svn:eol-style native <path>
I guess there is some way to do this automatically - anybody knows how
to set this up for Cocoon SVN repo?
Vadim
Re: svn commit: rev 47320 - cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/cocoon/transformation
Posted by Pier Fumagalli <pi...@betaversion.org>.
On 27 Sep 2004, at 18:57, pier@apache.org wrote:
> Author: pier
> Date: Mon Sep 27 10:57:10 2004
> New Revision: 47320
>
> Modified:
>
> cocoon/branches/BRANCH_2_1_X/src/blocks/scratchpad/java/org/apache/
> cocoon/transformation/IncludeTransformer.java
> Log:
> More JavaDOCs, comments, re-indenting, and filtering out the "include"
> namespaces declarations
I think there's a line-ending problem with this file. My local diffs
were much smaller!
Pier (scratching his head, and wondering)
BTW, my local diff was (from a console grab)
$ diff -w IncludeTransformer.java.old IncludeTransformer.java
31a32
> import org.apache.cocoon.xml.NamespacesTable;
38c39,40
< * Simple Source include transformer.
---
> * <p>A simple transformer including resolvable sources (accessed
through Cocoon's
> * {@link SourceResolver} from its input.</p>
40,44c42,54
< * <p>
< * Triggers for the element <code>include</code> in the
< * namespace <code>http://apache.org/cocoon/include/1.0</code>.
< * Use <code><include src="scheme://path"/></code>
< * </p>
---
> * <p>Inclusion is triggered by the <code><include ...
/></code> element
> * defined in the <code>http://apache.org/cocoon/include/1.0</code>
namespace.</p>
> *
> * <p>Example:</p>
> *
> * <p><code><incl:include
xmlns="http://apache.org/cocoon/include/1.0"
> * src="cocoon://path/to/include"/></code></p>
> *
> * <p>An interesting feature of this {@link Transformer} is that it
implements the
> * {@link CacheableProcessingComponent} interface and provides full
support for
> * caching. In other words, if the input given to this transformer
has not changed,
> * and all of the included sources are (cacheable) and still valid,
this transformer
> * will not force a pipeline re-generation like the {@link
CIncludeTransformer}.</p>
54,55c64
< implements Serviceable, Transformer,
<
CacheableProcessingComponent {
---
> implements Serviceable, Transformer, CacheableProcessingComponent {
63a73
> private NamespacesTable m_namespaces;
64a75,77
> /**
> * <p>Create a new {@link IncludeTransformer} instance.</p>
> */
65a79
> super();
67a82,86
> /**
> * <p>Setup the {@link ServiceManager} available for this
instance.</p>
> *
> * @see Serviceable#service(ServiceManager)
> */
69c88
< m_manager = manager;
---
> this.m_manager = manager;
71a91,96
> /**
> * <p>Setup this component instance in the context of its
pipeline and
> * current request.</p>
> *
> * @see Serviceable#service(ServiceManager)
> */
74,75c99,101
< m_resolver = resolver;
< m_validity = null;
---
> this.m_resolver = resolver;
> this.m_validity = null;
> this.m_namespaces = new NamespacesTable();
77a104,108
> /**
> * <p>Recycle this component instance.</p>
> *
> * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
> */
80,81c111,113
< m_resolver = null;
< m_validity = null;
---
> this.m_resolver = null;
> this.m_validity = null;
> this.m_namespaces = new NamespacesTable();
83a116,120
> /**
> * <p>Receive notification of the beginning of an XML
document.</p>
> *
> * @see org.xml.sax.ContentHandler#startDocument()
> */
86c123
< // Make sure that we have a validity while processing
---
> /* Make sure that we have a validity while processing */
90a128,132
> /**
> * <p>Receive notification of the end of an XML document.</p>
> *
> * @see org.xml.sax.ContentHandler#startDocument()
> */
93c135
< // Make sure that the validity is "closed" at the end
---
> /* Make sure that the validity is "closed" at the end */
97a140,184
> /**
> * <p>Receive notification of the start of a prefix mapping.</p>
> *
> * <p>This transformer will remove all prefix mapping
declarations for those
> * prefixes associated with the
<code>http://apache.org/cocoon/include/1.0</code>
> * namespace.</p>
> *
> * @see org.xml.sax.ContentHandler#startPrefixMapping(String)
> */
> public void startPrefixMapping(String prefix, String nsuri)
> throws SAXException {
> if (NS_URI.equals(nsuri)) {
> /* Skipping mapping for the current prefix as it's ours */
> this.m_namespaces.addDeclaration(prefix, nsuri);
> } else {
> /* Map the current prefix, as we don't know it */
> super.startPrefixMapping(prefix, nsuri);
> }
> }
>
> /**
> * <p>Receive notification of the end of a prefix mapping.</p>
> *
> * <p>This transformer will remove all prefix mapping
declarations for those
> * prefixes associated with the
<code>http://apache.org/cocoon/include/1.0</code>
> * namespace.</p>
> *
> * @see
org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
> */
> public void endPrefixMapping(String prefix)
> throws SAXException {
> if (NS_URI.equals(this.m_namespaces.getUri(prefix))) {
> /* Skipping unmapping for the current prefix as it's ours
*/
> this.m_namespaces.removeDeclaration(prefix);
> } else {
> /* Unmap the current prefix, as we don't know it */
> super.endPrefixMapping(prefix);
> }
> }
>
> /**
> * <p>Receive notification of the start of an element.</p>
> *
> * @see org.xml.sax.ContentHandler#startElement(String, String,
String, org.xml.sax.Attributes)
> */
105a193
> if (m_validity != null) {
107,109c195,196
< SourceUtil.toSAX(m_manager,
< source,
< "text/xml",
---
> }
> SourceUtil.toSAX(m_manager, source, "text/xml",
111c198,199
< } catch (IOException e) {
---
> }
> catch (IOException e) {
113c201,202
< } catch (ProcessingException e) {
---
> }
> catch (ProcessingException e) {
115c204,205
< } finally {
---
> }
> finally {
120,121d209
< } else {
< getLogger().warn("Unrecognized element <" + qName +
">");
128c216,222
< public void endElement(String uri, String localName, String
qName) throws SAXException {
---
> /**
> * <p>Receive notification of the end of an element.</p>
> *
> * @see org.xml.sax.ContentHandler#endElement(String, String,
String)
> */
> public void endElement(String uri, String localName, String qName)
> throws SAXException {
133a228,232
> /**
> * <p>Return the validity key associated with this
transformation.</p>
> *
> * @see CacheableProcessingComponent#getKey()
> */
139a239,245
> /**
> * <p>Generate (or return) the {@link SourceValidity} instance
used to
> * possibly validate cached generations.</p>
> *
> * @return a <b>non null</b> {@link SourceValidity}.
> * @see
org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
> */