cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject cvs commit: xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation SourceWritingTransformer.java
Date Thu, 14 Mar 2002 22:12:00 GMT
jeremy      02/03/14 14:12:00

  Modified:    src/scratchpad/src/org/apache/cocoon/transformation
                        SourceWritingTransformer.java
  Log:
  fixed bug where no message would appear if .tmp blocking file existed. Still a problem with
blocking files being left behind when StreamGenerator barfs on non well-formed XML.
  
  Revision  Changes    Path
  1.2       +44 -36    xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/SourceWritingTransformer.java
  
  Index: SourceWritingTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/SourceWritingTransformer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SourceWritingTransformer.java	13 Mar 2002 19:03:51 -0000	1.1
  +++ SourceWritingTransformer.java	14 Mar 2002 22:12:00 -0000	1.2
  @@ -125,12 +125,17 @@
   public class SourceWritingTransformer extends AbstractTransformer
       implements Disposable, Configurable, Composable {
   
  -    private static String WST_URI = "http://apache.org/cocoon/source/1.0";
  -    private static String WST_ELEMENT = "write";
  -    private static String WST_RESULT_ATTRIBUTE= "result";
  -    private static String WST_SRC_ATTRIBUTE = "src";
  -    private static String WST_ACTION_ATTRIBUTE = "action";
  -    private static String WST_SERIALIZER_ATTRIBUTE = "serializer";
  +    private static String SWT_URI = "http://apache.org/cocoon/source/1.0";
  +    private static String SWT_ELEMENT = "write";
  +    private static String SWT_RESULT_ATTRIBUTE= "result";
  +    private static String SWT_SRC_ATTRIBUTE = "src";
  +    private static String SWT_ACTION_ATTRIBUTE = "action";
  +    private static String SWT_SERIALIZER_ATTRIBUTE = "serializer";
  +    private static String SWT_RESULT_FAILED = "failed";
  +    private static String SWT_RESULT_SUCCESS = "success";
  +    private static String SWT_ACTION_NONE = "none";
  +    private static String SWT_ACTION_NEW = "new";
  +    private static String SWT_ACTION_OVER = "overwritten";
   
   
       /** The <code>SourceResolver</code> */
  @@ -192,9 +197,9 @@
        */
       public void configure(Configuration configuration) throws ConfigurationException {
   			try {
  -				this.serializer_name = configuration.getChild(WST_SERIALIZER_ATTRIBUTE).getValue();
  +				this.serializer_name = configuration.getChild(SWT_SERIALIZER_ATTRIBUTE).getValue();
   			} catch (Exception e) {
  -				getLogger().debug("SourceWritingTransformer: Configuration - no serializer yet");
  +				getLogger().debug("Configuration - no serializer yet");
   			}
       }
   
  @@ -205,9 +210,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(WST_SERIALIZER_ATTRIBUTE, this.serializer_name);
  +			this.serializer_name = par.getParameter(SWT_SERIALIZER_ATTRIBUTE, this.serializer_name);
   			if (this.serializer_name != null)
  -				getLogger().debug("SourceWritingTransformer: Setup, using serializer: " + this.serializer_name);
  +				getLogger().debug("Setup, using serializer: " + this.serializer_name);
       }
   
       /**
  @@ -253,14 +258,14 @@
       public void startElement(String uri, String loc, String raw, Attributes a)
       throws SAXException {
   			if (!this.processing) {
  -				if (WST_URI.equals(uri) && WST_ELEMENT.equals(loc)) {
  -					getLogger().debug("SourceWritingTransformer: start processing xmlns:source");
  +				if (SWT_URI.equals(uri) && SWT_ELEMENT.equals(loc)) {
  +					getLogger().debug("start processing xmlns:source");
   					this.failed = false;
   					this.message = null;
   					this.target = "";
   
   					// look for the Source
  -					String src = a.getValue("",WST_SRC_ATTRIBUTE);
  +					String src = a.getValue("",SWT_SRC_ATTRIBUTE);
   					try {
   						this.message = "The src attribute could not be resolved";
   						this.source = this.sourceResolver.resolve(src);
  @@ -274,7 +279,7 @@
   						this.os = this.wsource.getOutputStream();
   						
   						// has a Serializer been specified?
  -						String local_serializer = a.getValue("",WST_SERIALIZER_ATTRIBUTE);
  +						String local_serializer = a.getValue("",SWT_SERIALIZER_ATTRIBUTE);
   						if (local_serializer != null) this.serializer_name = local_serializer;
   						if (this.serializer_name != null) {
   							// Lookup the Serializer
  @@ -286,23 +291,24 @@
   							this.isSerializer = true;
   						} else {
   							this.message = "could not get a ContentHandler";
  -							this.ch = (XMLConsumer)wsource.getContentHandler();            	// Is there a way
to avoid this casting?
  +							this.ch = (XMLConsumer)wsource.getContentHandler();
   						}
  -						// start the document
  -						if (!this.failed) {
  -							this.ch.startDocument();
  -						}						
   					} catch (Exception e) {
  -						getLogger().warn("SourceWritingTransformer failed, " + this.message, e);
  +						getLogger().warn("failed, " + this.message, e);
   						this.failed = true;
   						try {
   							this.wsource.cancel(this.ch);
   						} catch (Exception e2) {
  -							throw new SAXException("SourceWritingTransformer: " + this.message, e2);
  +							getLogger().warn("failed to cancel: " + this.target, e2);
  +							this.message += " and failed to cancel";
   						}
   					}
  +					// start the document
  +					if (!this.failed) {
  +						this.ch.startDocument();
  +					}						
   					this.processing = true;
  -					getLogger().debug("SourceWritingTransformer: Processing Started");
  +					getLogger().debug("Processing Started");
   				} else {
   					super.startElement(uri,loc,raw,a);
   				}
  @@ -328,28 +334,28 @@
   			if (!this.processing) {
   				super.endElement(uri,loc,raw);
   			} else {
  -				if (WST_URI.equals(uri) && WST_ELEMENT.equals(loc)){
  +				if (SWT_URI.equals(uri) && SWT_ELEMENT.equals(loc)){
   					if (!this.failed) {
   						this.ch.endDocument();
   					}
   					this.processing = false;
  -					getLogger().debug("SourceWritingTransformer: Processing Ended");
  -					if (isSerializer) this.manager.release((Component)this.ch);            	// Is there
a way to avoid this casting?
  +					getLogger().debug("Processing Ended");
   					// close the OutputStream
   					try {
   						if (this.os != null) {
   							this.os.close();
   							this.os = null;
   						}
  +						
   					} catch(Exception e) {
  -						getLogger().warn("SourceWritingTransformer: Failed to close source", e);
  +						getLogger().warn("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("SourceWritingTransformer: " + this.message, e2);
  +							getLogger().warn("failed to cancel: " + this.target, e2);
   						}
   					} finally {
   						if (this.source != null) {
  @@ -357,20 +363,20 @@
   						}
   					}
   					// Report result
  -					String result = (this.failed) ? "failed" : "success";
  -					String action = "none";
  +					String result = (this.failed) ? SWT_RESULT_FAILED : SWT_RESULT_SUCCESS;
  +					String action = SWT_ACTION_NONE;
   					if (!this.failed){
   						if (this.exists) {
  -							action = "overwritten";
  +							action = SWT_ACTION_OVER;
   						} else {
  -							action = "new";
  +							action = SWT_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_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);
  +					attrs.addAttribute(null, SWT_SRC_ATTRIBUTE, SWT_SRC_ATTRIBUTE, "CDATA", this.target);
  +					attrs.addAttribute(null, SWT_ACTION_ATTRIBUTE, SWT_ACTION_ATTRIBUTE, "CDATA", action);
  +					attrs.addAttribute(null, SWT_RESULT_ATTRIBUTE, SWT_RESULT_ATTRIBUTE, "CDATA", result);
  +					if (this.serializer_name != null) attrs.addAttribute(null, SWT_SERIALIZER_ATTRIBUTE,
SWT_SERIALIZER_ATTRIBUTE, "CDATA", this.serializer_name);
   					super.startElement(uri, loc, raw, attrs);
   					if (this.message != null && this.failed == true) super.characters(this.message.toCharArray(),
0, this.message.length());
   					super.endElement(uri, loc, raw);
  @@ -528,12 +534,14 @@
   
       public void recycle() {
       	if (this.wsource != null) {
  +				getLogger().error("cancelled by recycle() method");
       		try {
       			this.wsource.cancel(this.ch);
       		} catch (Exception e) {
  -					getLogger().error("SourceWritingTransformer: cancelled");
  +					getLogger().error("failed to cancel in recycle() method");
       		}    	
       	}
  +			if (isSerializer) this.manager.release((Component)this.ch);
         this.sourceResolver = null;
       }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message