You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/01/22 01:02:34 UTC
cvs commit: cocoon-2.1/src/blocks/batik/java/org/apache/cocoon/generation FragmentExtractorGenerator.java
vgritsenko 2004/01/21 16:02:34
Modified: src/blocks/batik/java/org/apache/cocoon/transformation
FragmentExtractorTransformer.java
src/blocks/batik/java/org/apache/cocoon/generation
FragmentExtractorGenerator.java
Log:
Call recucle() in dispose().
Throw RNFE instead of SAXException if fragment is not found.
Braces/spaces.
Revision Changes Path
1.9 +52 -60 cocoon-2.1/src/blocks/batik/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java
Index: FragmentExtractorTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/batik/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FragmentExtractorTransformer.java 24 Nov 2003 19:31:55 -0000 1.8
+++ FragmentExtractorTransformer.java 22 Jan 2004 00:02:34 -0000 1.9
@@ -81,12 +81,12 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-
/**
* The transformation half of the FragmentExtractor.
- * This transformer sieves an incoming stream of xml
- * and replaces fragments with an xlink locator pointing to the fragments.
- * <p>
+ *
+ * This transformer recieves an incoming stream of xml and replaces
+ * fragments with an fragment extractor locator pointing to the fragments.
+ *
* The extracted fragments are identified by their element name and namespace URI.
* The default is to extract SVG images ("svg" elements in namespace
* "http://www.w3.org/2000/svg"), but this can be overriden in the configuration:
@@ -94,7 +94,11 @@
* <extract-uri>http://my/namespace/uri</extract-uri>
* <extract-element>my-element</extract-element>
* </pre>
- * <p>
+ *
+ * Fragment extractor locator format is following:
+ * <pre>
+ * <fe:fragment xmlns:fe="http://apache.org/cocoon/fragmentextractor/2.0" fragment-id="..."/>
+ * </pre>
*
* @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
* @version CVS $Id$
@@ -102,19 +106,19 @@
public class FragmentExtractorTransformer extends AbstractTransformer
implements CacheableProcessingComponent, Configurable, Serviceable, Disposable, Recyclable {
+ public static final String FE_URI = "http://apache.org/cocoon/fragmentextractor/2.0";
+
private static final String EXTRACT_URI_NAME = "extract-uri";
private static final String EXTRACT_ELEMENT_NAME = "extract-element";
private static final String EXTRACT_URI = "http://www.w3.org/2000/svg";
private static final String EXTRACT_ELEMENT = "svg";
- private static final String FE_URI = "http://apache.org/cocoon/fragmentextractor/2.0";
-
private String extractURI;
private String extractElement;
/** The ServiceManager instance */
- protected ServiceManager manager = null;
+ protected ServiceManager manager;
private XMLSerializer serializer;
@@ -138,16 +142,6 @@
}
}
- /** Setup the transformer. */
- public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
- throws ProcessingException, SAXException, IOException {
- extractLevel = 0;
- fragmentID = 0;
- prefixMap = new HashMap();
-
- this.requestURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
- }
-
/**
* Set the current <code>ServiceManager</code> instance used by this
* <code>Serviceable</code>.
@@ -157,21 +151,34 @@
}
/**
+ * Recycle this component
+ */
+ public void recycle() {
+ if (this.manager != null) {
+ this.manager.release(serializer);
+ this.serializer = null;
+ }
+ super.recycle();
+ }
+
+ /**
* Release all resources.
*/
public void dispose() {
+ recycle();
this.manager = null;
}
/**
- * Recycle this component
+ * Setup the transformer.
*/
- public void recycle() {
- if ( this.manager != null ) {
- this.manager.release(serializer);
- this.serializer = null;
- }
- super.recycle();
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
+ throws ProcessingException, SAXException, IOException {
+ extractLevel = 0;
+ fragmentID = 0;
+ prefixMap = new HashMap();
+
+ this.requestURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
}
/**
@@ -195,20 +202,6 @@
}
/**
- * Receive notification of the beginning of a document.
- */
- public void startDocument() throws SAXException {
- super.startDocument();
- }
-
- /**
- * Receive notification of the end of a document.
- */
- public void endDocument() throws SAXException {
- super.endDocument();
- }
-
- /**
* Begin the scope of a prefix-URI Namespace mapping.
*
* @param prefix The Namespace prefix being declared.
@@ -217,10 +210,10 @@
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
if (extractLevel == 0) {
- super.startPrefixMapping(prefix,uri);
- prefixMap.put(prefix,uri);
+ super.startPrefixMapping(prefix, uri);
+ prefixMap.put(prefix, uri);
} else {
- this.serializer.startPrefixMapping(prefix,uri);
+ this.serializer.startPrefixMapping(prefix, uri);
}
}
@@ -257,7 +250,7 @@
if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) {
extractLevel++;
fragmentID++;
- if (this.getLogger().isDebugEnabled()) {
+ if (getLogger().isDebugEnabled()) {
getLogger().debug("extractLevel now " + extractLevel + ".");
}
@@ -281,9 +274,9 @@
}
if (extractLevel == 0) {
- super.startElement(uri,loc,raw,a);
+ super.startElement(uri, loc, raw, a);
} else {
- this.serializer.startElement(uri,loc,raw,a);
+ this.serializer.startElement(uri, loc, raw, a);
}
}
@@ -302,12 +295,12 @@
public void endElement(String uri, String loc, String raw)
throws SAXException {
if (extractLevel == 0) {
- super.endElement(uri,loc,raw);
+ super.endElement(uri, loc, raw);
} else {
- this.serializer.endElement(uri,loc,raw);
+ this.serializer.endElement(uri, loc, raw);
if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) {
extractLevel--;
- if (this.getLogger().isDebugEnabled()) {
+ if (getLogger().isDebugEnabled()) {
getLogger().debug("extractLevel now " + extractLevel + ".");
}
@@ -337,7 +330,7 @@
this.serializer = null;
}
- if (this.getLogger().isDebugEnabled()) {
+ if (getLogger().isDebugEnabled()) {
getLogger().debug("Stored document " + id + ".");
}
@@ -363,9 +356,9 @@
public void characters(char c[], int start, int len)
throws SAXException {
if (extractLevel == 0) {
- super.characters(c,start,len);
+ super.characters(c, start, len);
} else {
- this.serializer.characters(c,start,len);
+ this.serializer.characters(c, start, len);
}
}
@@ -379,9 +372,9 @@
public void ignorableWhitespace(char c[], int start, int len)
throws SAXException {
if (extractLevel == 0) {
- super.ignorableWhitespace(c,start,len);
+ super.ignorableWhitespace(c, start, len);
} else {
- this.serializer.ignorableWhitespace(c,start,len);
+ this.serializer.ignorableWhitespace(c, start, len);
}
}
@@ -395,9 +388,9 @@
public void processingInstruction(String target, String data)
throws SAXException {
if (extractLevel == 0) {
- super.processingInstruction(target,data);
+ super.processingInstruction(target, data);
} else {
- this.serializer.processingInstruction(target,data);
+ this.serializer.processingInstruction(target, data);
}
}
@@ -428,7 +421,7 @@
public void startDTD(String name, String publicId, String systemId)
throws SAXException {
if (extractLevel == 0) {
- super.startDTD(name,publicId,systemId);
+ super.startDTD(name, publicId, systemId);
} else {
throw new SAXException(
"Recieved startDTD after beginning fragment extraction process."
@@ -513,10 +506,9 @@
public void comment(char ch[], int start, int len)
throws SAXException {
if (extractLevel == 0) {
- super.comment(ch,start,len);
+ super.comment(ch, start, len);
} else {
- this.serializer.comment(ch,start,len);
+ this.serializer.comment(ch, start, len);
}
}
-
}
1.4 +15 -12 cocoon-2.1/src/blocks/batik/java/org/apache/cocoon/generation/FragmentExtractorGenerator.java
Index: FragmentExtractorGenerator.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/batik/java/org/apache/cocoon/generation/FragmentExtractorGenerator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FragmentExtractorGenerator.java 4 Sep 2003 09:38:35 -0000 1.3
+++ FragmentExtractorGenerator.java 22 Jan 2004 00:02:34 -0000 1.4
@@ -51,6 +51,8 @@
package org.apache.cocoon.generation;
import org.apache.avalon.framework.service.ServiceException;
+import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.components.sax.XMLDeserializer;
@@ -60,7 +62,9 @@
import org.xml.sax.SAXException;
-/** The generation half of FragmentExtractor.
+/**
+ * The generation half of FragmentExtractor.
+ *
* FragmentExtractor is a transformer-generator pair which is designed to allow
* sitemap managers to extract certain nodes from a SAX stream and move them
* into a separate pipeline. The main use for this is to extract inline SVG
@@ -69,13 +73,12 @@
*
* This is by no means complete yet, but it should prove useful, particularly
* for offline generation.
- * <p>
*
* @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
* @version CVS $Id$
*/
public class FragmentExtractorGenerator extends ServiceableGenerator
- implements CacheableProcessingComponent {
+ implements CacheableProcessingComponent {
/**
* Generate the unique key.
@@ -97,9 +100,11 @@
return NOPValidity.SHARED_INSTANCE;
}
- public void generate() throws SAXException {
+ public void generate() throws SAXException, ProcessingException {
// Obtain the fragmentID (which is simply the filename portion of the source)
- getLogger().debug("FragmentExtractorGenerator retrieving document " + source + ".");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Retrieving fragment " + source + ".");
+ }
Store store = null;
XMLDeserializer deserializer = null;
@@ -107,9 +112,9 @@
try {
store = (Store) this.manager.lookup(Store.TRANSIENT_STORE);
fragment = store.get(source);
-
- if (fragment==null)
- throw new SAXException("Could not find frament with id " + source + " in store");
+ if (fragment == null) {
+ throw new ResourceNotFoundException("Could not find fragment " + source + " in store");
+ }
deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE);
deserializer.setConsumer(this.xmlConsumer);
@@ -118,11 +123,9 @@
} catch (ServiceException ce) {
getLogger().error("Could not lookup for component.", ce);
throw new SAXException("Could not lookup for component.", ce);
- } finally
- {
+ } finally {
this.manager.release(store);
this.manager.release(deserializer);
}
}
}
-