forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Williams <william...@gmail.com>
Subject Re: svn commit: r750422 - in /forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher: impl/helper/ transformation/
Date Thu, 05 Mar 2009 12:27:43 GMT
Hey Thorsten,
Not specific to this commit, but I happened to notice a lot of code like:

if (uri != null && !uri.equals("")) {

Since we're already using Commons Lang anyway, you might find it
easier to use StringUtils.isBlank(uri) in situations like this?

--tim



On Thu, Mar 5, 2009 at 6:20 AM,  <thorsten@apache.org> wrote:
> Author: thorsten
> Date: Thu Mar  5 11:20:29 2009
> New Revision: 750422
>
> URL: http://svn.apache.org/viewvc?rev=750422&view=rev
> Log:
> Fixing bug regarding comments that not have been passed to the output stage because the
StringXMLizable.toSAX does not invoke a lexicalHandler. Further removing all spaces and linebreaks
since the have caused problems in combination with <xsl:attribute> resulting in &#10;
in the output and extraspaces.
>
> Modified:
>    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/ContractHandler.java
>    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/EchoHandler.java
>    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
>
> Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/ContractHandler.java
> URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/ContractHandler.java?rev=750422&r1=750421&r2=750422&view=diff
> ==============================================================================
> --- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/ContractHandler.java
(original)
> +++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/ContractHandler.java
Thu Mar  5 11:20:29 2009
> @@ -67,7 +67,7 @@
>
>     if (recording) {
>       String prefix = extractPrefix(raw);
> -      emit(lineEnd + "<" + raw);
> +      emit( "<" + raw);
>       if (uri != null && !uri.equals("")) {
>         if (prefix != null) {
>           if (!map.containsKey(prefix)) {
>
> Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/EchoHandler.java
> URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/EchoHandler.java?rev=750422&r1=750421&r2=750422&view=diff
> ==============================================================================
> --- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/EchoHandler.java
(original)
> +++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/EchoHandler.java
Thu Mar  5 11:20:29 2009
> @@ -39,8 +39,6 @@
>
>   private byte[] bytes;
>
> -  protected String lineEnd;
> -
>   /**
>    * Establece la codificación que se empleará en el tratamiento de los datos.
>    * Si se pasa <code>null</code> o una cadena vacia emplea "UTF-8" por defecto.
> @@ -49,7 +47,6 @@
>    *          La codificación a emplear.
>    */
>   public EchoHandler(String encoding) {
> -    lineEnd = System.getProperty("line.separator");
>     if (null != encoding & !" ".equals(encoding)) {
>       this.encoding = encoding;
>     } else {
> @@ -64,7 +61,7 @@
>    */
>   public void startDocument() throws SAXException {
>     xmlBuffer = new StringBuffer();
> -    emit("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>" + lineEnd);
> +    emit("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>" );
>   }
>
>   /*
> @@ -178,7 +175,7 @@
>    */
>   public void endElement(String uri, String loc, String raw)
>       throws SAXException {
> -    emit("</" + raw + ">" + lineEnd);
> +    emit("</" + raw + ">" );
>   }
>
>   /*
> @@ -191,6 +188,7 @@
>    * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
>    */
>   public void characters(char ch[], int start, int length) throws SAXException {
> +    boolean ignorSpace = true;
>     for (int i = 0; i < length; i++) {
>       char c = ch[start + i];
>       if (c == '&') {
> @@ -199,8 +197,15 @@
>         emit("&lt;");
>       } else if (c == '>') {
>         emit("&gt;");
> -      } else {
> -        emit(c);
> +      } else if(c!='\n'){
> +        // this is a workaround to ignore whitespaces that are not needed.
> +        if(c==' ' && !ignorSpace){
> +          emit(c);
> +          ignorSpace=false;
> +        }else if (c!=' '){
> +          emit(c);
> +          ignorSpace=false;
> +        }
>       }
>     }
>   }
>
> Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
> URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=750422&r1=750421&r2=750422&view=diff
> ==============================================================================
> --- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
> +++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Thu Mar  5 11:20:29 2009
> @@ -21,6 +21,7 @@
>  import java.io.IOException;
>  import java.io.InputStream;
>  import java.io.Serializable;
> +import java.io.StringReader;
>  import java.util.HashMap;
>  import java.util.HashSet;
>  import java.util.Iterator;
> @@ -51,17 +52,13 @@
>  import org.apache.axiom.om.OMNode;
>  import org.apache.axiom.om.impl.builder.StAXOMBuilder;
>  import org.apache.cocoon.ProcessingException;
> -import org.apache.cocoon.ResourceNotFoundException;
>  import org.apache.cocoon.caching.CacheableProcessingComponent;
>  import org.apache.cocoon.environment.SourceResolver;
>  import org.apache.cocoon.transformation.AbstractSAXTransformer;
>  import org.apache.cocoon.util.TraxErrorHandler;
> -import org.apache.cocoon.xml.IncludeXMLConsumer;
>  import org.apache.cocoon.xml.RedundantNamespacesFilter;
> -import org.apache.cocoon.xml.StringXMLizable;
>  import org.apache.cocoon.xml.XMLUtils;
>  import org.apache.commons.io.output.ByteArrayOutputStream;
> -import org.apache.commons.logging.Log;
>  import org.apache.excalibur.source.Source;
>  import org.apache.excalibur.source.SourceException;
>  import org.apache.excalibur.source.SourceValidity;
> @@ -75,7 +72,6 @@
>  import org.apache.forrest.dispatcher.impl.CocoonResolver;
>  import org.apache.forrest.dispatcher.impl.helper.AXIOMXPathCreate;
>  import org.apache.forrest.dispatcher.impl.helper.Captions;
> -import org.apache.forrest.dispatcher.impl.helper.LoggingErrorListener;
>  import org.apache.forrest.dispatcher.impl.helper.StAX;
>  import org.apache.forrest.dispatcher.impl.helper.StreamHelper;
>  import org.apache.forrest.dispatcher.impl.helper.XMLProperties;
> @@ -245,8 +241,8 @@
>   private InputStream dataStream;
>
>   private String prefixString;
> -
> -  private HashMap storedPrefixMap;
> +
> +  private TransformerFactory tfactory = TransformerFactory.newInstance();
>
>   /*
>    * @see
> @@ -275,7 +271,13 @@
>     config.setShrink(shrink);
>     // request all factories to be created at this point since it is better to
>     // create them only once
> -    setNewTransformerFactory();
> +    try {
> +      setNewTransformerFactory();
> +    } catch (ProcessingException e) {
> +      throw new ConfigurationException(e.getLocalizedMessage(),e);
> +    } catch (TransformerFactoryConfigurationError e) {
> +      throw new ConfigurationException(e.getLocalizedMessage(),e);
> +    }
>   }
>
>   /**
> @@ -284,8 +286,10 @@
>    *
>    * @param config
>    *          the configuration to use.
> +   * @throws TransformerFactoryConfigurationError
> +   * @throws ProcessingException
>    */
> -  public void setConfig(WritableDispatcherBean config) {
> +  public void setConfig(WritableDispatcherBean config) throws ProcessingException, TransformerFactoryConfigurationError
{
>     this.config = config;
>     if (config.getTransFact() == null) {
>       setNewTransformerFactory();
> @@ -297,11 +301,10 @@
>    * Will prepare the factories that we need in further processing
>    *
>    * @throws TransformerFactoryConfigurationError
> +   * @throws ProcessingException
>    */
>   private void setNewTransformerFactory()
> -      throws TransformerFactoryConfigurationError {
> -    // Is this the best way to get an instance in cocoon?
> -    TransformerFactory tfactory = TransformerFactory.newInstance();
> +      throws TransformerFactoryConfigurationError, ProcessingException {
>     // set the uri resolver the same as this class
>     tfactory.setURIResolver(this);
>     // we want to set the error handler here to make sure it is intitialized
> @@ -312,6 +315,14 @@
>     this.factory = OMAbstractFactory.getOMFactory();
>     // get the contract factory
>     this.contractRep = new ContractFactory(config);
> +    try {
> +      parser = (SAXParser) manager.lookup(SAXParser.ROLE);
> +    } catch (ServiceException e) {
> +      String error = "dispatcherError:\n"
> +        + "SAXParser could not be setup! Abort";
> +      getLogger().error(error);
> +      throw new ProcessingException(error);
> +    }
>   }
>
>   /*
> @@ -328,7 +339,6 @@
>      */
>     // setup our super class
>     super.setup(resolver, objectModel, src, par);
> -    storedPrefixMap = new HashMap();
>
>     // get the id of this request
>     this.requestId = parameters
> @@ -480,11 +490,6 @@
>     }
>   }
>
> -  public void ignorableWhitespace(char c[], int start, int len)
> -  throws SAXException {
> - // do nothing here!
> -  }
> -
>
>   public void characters(char c[], int start, int len)
>   throws SAXException {
> @@ -498,7 +503,7 @@
>   }
>
>   public void startDocument() throws SAXException {
> - // Add the namespace filter to our own output.
> +    // Add the namespace filter to our own output.
>     RedundantNamespacesFilter nsPipe = new RedundantNamespacesFilter();
>     if (this.xmlConsumer != null) {
>         nsPipe.setConsumer(this.xmlConsumer);
> @@ -506,24 +511,28 @@
>         nsPipe.setContentHandler(this.contentHandler);
>     }
>     setConsumer(nsPipe);
> -    super.startDocument();
>   }
>
>   public void endDocument()
>   throws SAXException {
>     structurerProcessingEnd();
> -    super.endDocument();
>   }
>
>   /*
> -   * copy 'n paste
> +   * do nothing on the following methods, since we do not use them
>    */
> +  public void ignorableWhitespace(char c[], int start, int len)
> +  throws SAXException {
> +  }
>
>   public void startCDATA() throws SAXException {
>   }
>
>   public void endCDATA() throws SAXException {
>   }
> +
> +  public void comment(char[] ary, int start, int length) throws SAXException {
> +  }
>
>   /**
>    * Will execute the contract and process the result.
> @@ -665,8 +674,10 @@
>       }else{
>         root.serialize(out);
>       }
> -      StringXMLizable xml = new StringXMLizable(out.toString());
> -      xml.toSAX(new IncludeXMLConsumer(super.xmlConsumer));
> +
> +      InputSource is = new InputSource(new StringReader(out.toString()));
> +   // adding the result to the consumer
> +      parser.parse(is, super.xmlConsumer);
>     } catch (Exception e) {
>       throw new SAXException(e);
>     }
>
>
>

Mime
View raw message