cziegeler 02/02/20 02:39:25 Modified: src/scratchpad/src/org/apache/cocoon/sunshine/transformation InsertTransformer.java src/scratchpad/src/org/apache/cocoon/transformation FileWritingTransformer.java Log: Making subclassing possible Revision Changes Path 1.2 +2 -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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InsertTransformer.java 18 Feb 2002 09:10:10 -0000 1.1 +++ InsertTransformer.java 20 Feb 2002 10:39:24 -0000 1.2 @@ -115,9 +115,9 @@ * 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.1 2002/02/18 09:10:10 cziegeler Exp $ + * @version CVS $Id: InsertTransformer.java,v 1.2 2002/02/20 10:39:24 cziegeler Exp $ */ -public final class InsertTransformer +public class InsertTransformer extends AbstractSunShineTransformer { /** 1.3 +146 -180 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/FileWritingTransformer.java Index: FileWritingTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/FileWritingTransformer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- FileWritingTransformer.java 16 Feb 2002 20:24:24 -0000 1.2 +++ FileWritingTransformer.java 20 Feb 2002 10:39:24 -0000 1.3 @@ -127,10 +127,10 @@ * </ul> * * @author <a href="mailto:[EMAIL PROTECTED]">Jeremy Quinn</a> - * + * */ public class FileWritingTransformer extends AbstractTransformer - implements Disposable, Cacheable, Configurable, Composable { + implements Disposable, Configurable, Composable { private static String FRT_URI = "http://apache.org/cocoon/xfwt/1.0"; private static String FRT_ELEMENT = "write"; @@ -187,7 +187,7 @@ * <code>Composable</code>. */ public void compose(ComponentManager manager) throws ComponentException { - this.manager=manager; // We need this later to get the Serializer + this.manager=manager; // We need this later to get the Serializer } /** @@ -195,12 +195,12 @@ * <code>Configurable</code>. */ public void configure(Configuration configuration) throws ConfigurationException { - try { - this.default_serializer_name = configuration.getChild(FRT_SERIALIZER_ATTRIBUTE).getValue(); - } catch (Exception e) { - this.default_serializer_name = FRT_DEFAULT_SERIALIZER; - getLogger().debug("FileWritingTransformer: Configuration - no serializer yet, using default: " + this.default_serializer_name); - } + try { + this.default_serializer_name = configuration.getChild(FRT_SERIALIZER_ATTRIBUTE).getValue(); + } catch (Exception e) { + this.default_serializer_name = FRT_DEFAULT_SERIALIZER; + getLogger().debug("FileWritingTransformer: Configuration - no serializer yet, using default: " + this.default_serializer_name); + } } /** @@ -209,43 +209,9 @@ */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { - this.sourceResolver = resolver; // save it for later, when we know the filepath to save to - this.serializer_name = par.getParameter(FRT_SERIALIZER_ATTRIBUTE, this.default_serializer_name); - getLogger().debug("FileWritingTransformer: Setup, using serializer: " + this.serializer_name); - } - - /** - * Generate the unique key. - * This key must be unique inside the space of this component. - * - * @return The generated key hashes the src - */ - public long generateKey() { - return 1; - } - - /** - * Generate the validity object. - * - * @return The generated validity object or <code>null</code> if the - * component is currently not cacheable. - */ - public CacheValidity generateValidity() { - return null; - } - - /** - * 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(); + this.sourceResolver = resolver; // save it for later, when we know the filepath to save to + this.serializer_name = par.getParameter(FRT_SERIALIZER_ATTRIBUTE, this.default_serializer_name); + getLogger().debug("FileWritingTransformer: Setup, using serializer: " + this.serializer_name); } /** @@ -290,98 +256,98 @@ */ public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { - if (!this.processing) { - if (FRT_URI.equals(uri) && FRT_ELEMENT.equals(loc)) { - getLogger().debug("FileWritingTransformer: start processing xmlns:xfwt"); - this.failed = false; - this.message = null; - this.target = ""; - this.action = FRT_ACTION_OVERWRITE; - - // look for the Source - String src = a.getValue("",FRT_SRC_ATTRIBUTE); - Source source = null; - try { - source = this.sourceResolver.resolve(src); - this.target = source.getSystemId(); - } catch (Exception e) { // Sorry about this, but resolve throws 3 different Exceptions .... - getLogger().error("FileWritingTransformer failed, could not resolve the source: ", e); - this.failed = true; - this.message = "could not resolve the source: " + src; - } finally { - source.recycle(); - } - - // open the file - if (!this.failed) { - if (!this.target.startsWith(FRT_PROTOCOL)) { - getLogger().error("FileWritingTransformer failed, the src parameter did not resolve to a file:"); - this.failed = true; - this.message = "the src parameter did not resolve to a file:"; - } - File file = new File (this.target.substring(5)); - try { - if (!file.exists()) { - File dir = new File (this.target.substring(5, this.target.lastIndexOf(File.separatorChar))); - if (!dir.exists() && dir.mkdirs() == true) { - getLogger().warn("FileWritingTransformer: made new directories: " + dir.toString()); - } - this.action = FRT_ACTION_NEW; - } else if (file.isDirectory()) { - getLogger().error("FileWritingTransformer failed, the src parameter cannot point to a directory"); - this.failed = true; - this.message = "the src parameter pointed to a directory"; - } - } catch (SecurityException se) { - getLogger().error("FileWritingTransformer failed, did not have the required file permissions for writing", se); - this.failed = true; - this.message = "could not open the file for writing"; - } - try { - this.fos = new java.io.FileOutputStream(file); - } catch (IOException ioe) { - getLogger().error("FileWritingTransformer failed, could not open the file for writing", ioe); - this.failed = true; - this.message = "could not open the file for writing"; - } - } - - // which Serializer? - String local_serializer = a.getValue("",FRT_SERIALIZER_ATTRIBUTE); - if (local_serializer != null) this.serializer_name = local_serializer; - getLogger().debug("FileWritingTransformer: StartElement, using serializer: " + this.serializer_name); - - // Lookup the Serializer - try { - ComponentSelector selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector"); - this.serializer = (Serializer)selector.select(this.serializer_name); - } catch (ComponentException e) { - throw new SAXException("FileWritingTransformer: that Serializer does not exist. Please provide the name of a Serializer defined in the SiteMap", e); - } - - // set up the Serializer - if (!this.failed) { - try { - this.serializer.setOutputStream(this.fos); - } catch (IOException ioe2) { - getLogger().error("FileWritingTransformer failed, could not Serialize to the file", ioe2); - this.failed = true; - this.message = "could not write the file"; - } - } - - // start the document - if (!this.failed) { - this.serializer.startDocument(); - } - this.processing = true; - getLogger().debug("FileWritingTransformer: Processing Started"); - } else { - super.startElement(uri,loc,raw,a); - } - } else if (this.serializer != null){ - this.serializer.startElement(uri,loc,raw,a); - } + if (!this.processing) { + if (FRT_URI.equals(uri) && FRT_ELEMENT.equals(loc)) { + getLogger().debug("FileWritingTransformer: start processing xmlns:xfwt"); + this.failed = false; + this.message = null; + this.target = ""; + this.action = FRT_ACTION_OVERWRITE; + + // look for the Source + String src = a.getValue("",FRT_SRC_ATTRIBUTE); + Source source = null; + try { + source = this.sourceResolver.resolve(src); + this.target = source.getSystemId(); + } catch (Exception e) { // Sorry about this, but resolve throws 3 different Exceptions .... + getLogger().error("FileWritingTransformer failed, could not resolve the source: ", e); + this.failed = true; + this.message = "could not resolve the source: " + src; + } finally { + source.recycle(); + } + + // open the file + if (!this.failed) { + if (!this.target.startsWith(FRT_PROTOCOL)) { + getLogger().error("FileWritingTransformer failed, the src parameter did not resolve to a file:"); + this.failed = true; + this.message = "the src parameter did not resolve to a file:"; + } + File file = new File (this.target.substring(5)); + try { + if (!file.exists()) { + File dir = new File (this.target.substring(5, this.target.lastIndexOf(File.separatorChar))); + if (!dir.exists() && dir.mkdirs() == true) { + getLogger().warn("FileWritingTransformer: made new directories: " + dir.toString()); + } + this.action = FRT_ACTION_NEW; + } else if (file.isDirectory()) { + getLogger().error("FileWritingTransformer failed, the src parameter cannot point to a directory"); + this.failed = true; + this.message = "the src parameter pointed to a directory"; + } + } catch (SecurityException se) { + getLogger().error("FileWritingTransformer failed, did not have the required file permissions for writing", se); + this.failed = true; + this.message = "could not open the file for writing"; + } + try { + this.fos = new java.io.FileOutputStream(file); + } catch (IOException ioe) { + getLogger().error("FileWritingTransformer failed, could not open the file for writing", ioe); + this.failed = true; + this.message = "could not open the file for writing"; + } + } + + // which Serializer? + String local_serializer = a.getValue("",FRT_SERIALIZER_ATTRIBUTE); + if (local_serializer != null) this.serializer_name = local_serializer; + getLogger().debug("FileWritingTransformer: StartElement, using serializer: " + this.serializer_name); + + // Lookup the Serializer + try { + ComponentSelector selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector"); + this.serializer = (Serializer)selector.select(this.serializer_name); + } catch (ComponentException e) { + throw new SAXException("FileWritingTransformer: that Serializer does not exist. Please provide the name of a Serializer defined in the SiteMap", e); + } + + // set up the Serializer + if (!this.failed) { + try { + this.serializer.setOutputStream(this.fos); + } catch (IOException ioe2) { + getLogger().error("FileWritingTransformer failed, could not Serialize to the file", ioe2); + this.failed = true; + this.message = "could not write the file"; + } + } + + // start the document + if (!this.failed) { + this.serializer.startDocument(); + } + this.processing = true; + getLogger().debug("FileWritingTransformer: Processing Started"); + } else { + super.startElement(uri,loc,raw,a); + } + } else if (this.serializer != null){ + this.serializer.startElement(uri,loc,raw,a); + } } @@ -398,38 +364,38 @@ */ public void endElement(String uri, String loc, String raw) throws SAXException { - if (!this.processing) { - super.endElement(uri,loc,raw); - } else { - if (FRT_URI.equals(uri) && FRT_ELEMENT.equals(loc)){ - if (!this.failed) { - this.serializer.endDocument(); - } - this.processing = false; - getLogger().debug("FileWritingTransformer: Processing Ended"); - this.manager.release(this.serializer); - try { - this.fos.close(); - this.fos = null; - } catch (IOException e) { - getLogger().error("FileWritingTransformer failed, could not close the file", e); - this.failed = true; - } - // Report result - String result = (this.failed) ? "failed" : "success"; - AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute(null, FRT_SRC_ATTRIBUTE, FRT_SRC_ATTRIBUTE, "CDATA", this.target); - attrs.addAttribute(null, FRT_ACTION_ATTRIBUTE, FRT_ACTION_ATTRIBUTE, "CDATA", this.action); - attrs.addAttribute(null, FRT_RESULT_ATTRIBUTE, FRT_RESULT_ATTRIBUTE, "CDATA", result); - attrs.addAttribute(null, FRT_SERIALIZER_ATTRIBUTE, FRT_SERIALIZER_ATTRIBUTE, "CDATA", this.serializer_name); - super.startElement(uri, loc, raw, attrs); - if (this.message != null) super.characters(this.message.toCharArray(), 0, this.message.length()); - super.endElement(uri, loc, raw); - getLogger().debug("FileWritingTransformer: File Written"); - } else if (this.serializer != null){ - this.serializer.endElement(uri, loc, raw); - } - } + if (!this.processing) { + super.endElement(uri,loc,raw); + } else { + if (FRT_URI.equals(uri) && FRT_ELEMENT.equals(loc)){ + if (!this.failed) { + this.serializer.endDocument(); + } + this.processing = false; + getLogger().debug("FileWritingTransformer: Processing Ended"); + this.manager.release(this.serializer); + try { + this.fos.close(); + this.fos = null; + } catch (IOException e) { + getLogger().error("FileWritingTransformer failed, could not close the file", e); + this.failed = true; + } + // Report result + String result = (this.failed) ? "failed" : "success"; + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute(null, FRT_SRC_ATTRIBUTE, FRT_SRC_ATTRIBUTE, "CDATA", this.target); + attrs.addAttribute(null, FRT_ACTION_ATTRIBUTE, FRT_ACTION_ATTRIBUTE, "CDATA", this.action); + attrs.addAttribute(null, FRT_RESULT_ATTRIBUTE, FRT_RESULT_ATTRIBUTE, "CDATA", result); + attrs.addAttribute(null, FRT_SERIALIZER_ATTRIBUTE, FRT_SERIALIZER_ATTRIBUTE, "CDATA", this.serializer_name); + super.startElement(uri, loc, raw, attrs); + if (this.message != null) super.characters(this.message.toCharArray(), 0, this.message.length()); + super.endElement(uri, loc, raw); + getLogger().debug("FileWritingTransformer: File Written"); + } else if (this.serializer != null){ + this.serializer.endElement(uri, loc, raw); + } + } } /** @@ -484,11 +450,11 @@ * entity, the name will begin with '%'. */ public void skippedEntity(String name) throws SAXException { - if (!this.processing) { - super.skippedEntity(name); - } else if (this.serializer != null){ - this.serializer.skippedEntity(name); - } + if (!this.processing) { + super.skippedEntity(name); + } else if (this.serializer != null){ + this.serializer.skippedEntity(name); + } } /** @@ -500,17 +466,17 @@ * @param systemId The declared system identifier for the external DTD * subset, or null if none was declared. */ - public void startDTD(String name, String publicId, String systemId) throws SAXException { - if (!this.processing) - super.startDTD(name,publicId,systemId); + public void startDTD(String name, String publicId, String systemId) throws SAXException { + if (!this.processing) + super.startDTD(name,publicId,systemId); } /** * Report the end of DTD declarations. */ public void endDTD() throws SAXException { - if (!this.processing) - super.endDTD(); + if (!this.processing) + super.endDTD(); } /**
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]