jeremy 02/03/02 05:43:55 Modified: src/scratchpad/src/org/apache/cocoon/transformation WriteableSourceTransformer.java Log: Added calls to WriteableSource.exists() and WriteableSource.cancel() Revision Changes Path 1.2 +148 -28 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/WriteableSourceTransformer.java Index: WriteableSourceTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/WriteableSourceTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WriteableSourceTransformer.java 28 Feb 2002 19:03:05 -0000 1.1 +++ WriteableSourceTransformer.java 2 Mar 2002 13:43:55 -0000 1.2 @@ -167,6 +167,13 @@ /** True when inside <write> element. */ private boolean processing; + /** the Source. */ + private Source source = null; + + /** the WritableSource. */ + private WriteableSource wsource = null; + + public void WriteableSourceTransformer() { } @@ -210,11 +217,19 @@ * @param uri The Namespace URI the prefix is mapped to. */ public void startPrefixMapping(String prefix, String uri) throws SAXException { - if (!this.processing) { - super.startPrefixMapping(prefix,uri); - } else if (this.ch != null){ - this.ch.startPrefixMapping(prefix, uri); - } + try { + if (!this.processing) { + super.startPrefixMapping(prefix,uri); + } else if (this.ch != null){ + this.ch.startPrefixMapping(prefix, uri); + } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -223,11 +238,19 @@ * @param prefix The prefix that was being mapping. */ public void endPrefixMapping(String prefix) throws SAXException { + try { if (!this.processing) { super.endPrefixMapping(prefix); } else if (this.ch != null){ this.ch.endPrefixMapping(prefix); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -254,18 +277,17 @@ // look for the Source String src = a.getValue("",WST_SRC_ATTRIBUTE); - Source source = null; try { this.message = "The src attribute could not be resolved"; - source = this.sourceResolver.resolve(src); - this.target = source.getSystemId(); + this.source = this.sourceResolver.resolve(src); + this.target = this.source.getSystemId(); this.message = "The src attribute doesn't resolve to a writeable source"; - WriteableSource wsource = (WriteableSource)source; - //this.exists = wsource.exists(); + this.wsource = (WriteableSource)this.source; + this.exists = this.wsource.exists(); this.message = "Could not open the source for writing"; - this.os = wsource.getOutputStream(); + this.os = this.wsource.getOutputStream(); // has a Serializer been specified? String local_serializer = a.getValue("",WST_SERIALIZER_ATTRIBUTE); @@ -289,10 +311,10 @@ } catch (Exception e) { getLogger().warn("WritableSourceTransformer failed, " + this.message, e); this.failed = true; - //throw new SAXException("FileWritingTransformer: " + this.message, e); - } finally { - if (source != null) { - source.recycle(); + try { + this.wsource.cancel(this.ch); + } catch (Exception e2) { + throw new SAXException("WritableSourceTransformer: " + this.message, e2); } } this.processing = true; @@ -339,20 +361,30 @@ getLogger().warn("WritableSourceTransformer: Failed to close source", e); this.message = "Failed to close source"; this.failed = true; + try { + this.message = "Failed to cancel source"; + this.wsource.cancel(this.ch); + } catch (Exception e2) { + throw new SAXException("WritableSourceTransformer: " + this.message, e2); + } + } finally { + if (this.source != null) { + this.source.recycle(); + } } // Report result String result = (this.failed) ? "failed" : "success"; String action = "none"; - /*if (!this.failed){ + if (!this.failed){ if (this.exists) { action = "overwritten"; } else { action = "new"; } - } */ + } AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(null, WST_SRC_ATTRIBUTE, WST_SRC_ATTRIBUTE, "CDATA", this.target); - //attrs.addAttribute(null, WST_ACTION_ATTRIBUTE, WST_ACTION_ATTRIBUTE, "CDATA", action); + attrs.addAttribute(null, WST_ACTION_ATTRIBUTE, WST_ACTION_ATTRIBUTE, "CDATA", action); attrs.addAttribute(null, WST_RESULT_ATTRIBUTE, WST_RESULT_ATTRIBUTE, "CDATA", result); if (this.serializer_name != null) attrs.addAttribute(null, WST_SERIALIZER_ATTRIBUTE, WST_SERIALIZER_ATTRIBUTE, "CDATA", this.serializer_name); super.startElement(uri, loc, raw, attrs); @@ -373,11 +405,19 @@ * @param len The number of characters to read from the array. */ public void characters(char c[], int start, int len) throws SAXException { + try { if (!this.processing) { super.characters(c,start,len); } else if (this.ch != null){ this.ch.characters(c,start,len); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -388,11 +428,19 @@ * @param len The number of characters to read from the array. */ public void ignorableWhitespace(char c[], int start, int len) throws SAXException { + try { if (!this.processing) { super.ignorableWhitespace(c,start,len); } else if (this.ch != null){ this.ch.ignorableWhitespace(c,start,len); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -403,11 +451,19 @@ * supplied. */ public void processingInstruction(String target, String data) throws SAXException { + try { if (!this.processing) { super.processingInstruction(target,data); } else if (this.ch != null){ this.ch.processingInstruction(target,data); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -417,11 +473,19 @@ * entity, the name will begin with '%'. */ public void skippedEntity(String name) throws SAXException { - if (!this.processing) { - super.skippedEntity(name); - } else if (this.ch != null){ - this.ch.skippedEntity(name); - } + try { + if (!this.processing) { + super.skippedEntity(name); + } else if (this.ch != null){ + this.ch.skippedEntity(name); + } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -433,17 +497,33 @@ * @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 { + try { + if (!this.processing) + super.startDTD(name,publicId,systemId); + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** * Report the end of DTD declarations. */ public void endDTD() throws SAXException { - if (!this.processing) - super.endDTD(); + try { + if (!this.processing) + super.endDTD(); + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -453,11 +533,19 @@ * name will begin with '%'. */ public void startEntity(String name) throws SAXException { + try { if (!this.processing) { super.startEntity(name); } else if (this.ch != null){ this.ch.startEntity(name); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -466,33 +554,57 @@ * @param name The name of the entity that is ending. */ public void endEntity(String name) throws SAXException { + try { if (!this.processing) { super.endEntity(name); } else if (this.ch != null){ this.ch.endEntity(name); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** * Report the start of a CDATA section. */ public void startCDATA() throws SAXException { + try { if (!this.processing) { super.startCDATA(); } else if (this.ch != null){ this.ch.startCDATA(); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** * Report the end of a CDATA section. */ public void endCDATA() throws SAXException { + try { if (!this.processing) { super.endCDATA(); } else if (this.ch != null){ this.ch.endCDATA(); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } /** @@ -503,11 +615,19 @@ * @param len The number of characters to use from the array. */ public void comment(char ch[], int start, int len) throws SAXException { + try { if (!this.processing) { super.comment(ch,start,len); } else if (this.ch != null){ this.ch.comment(ch,start,len); } + } catch (SAXException se) { + try { + this.wsource.cancel(this.ch); + } finally { + throw new SAXException("WritableSourceTransformer: cancelled", se); + } + } } public void recycle() {
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]