You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2004/04/03 02:46:33 UTC

cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generation TextGenerator.java

antonio     2004/04/02 16:46:33

  Modified:    src/java/org/apache/cocoon/components/pipeline/impl
                        AbstractCachingProcessingPipeline.java
               src/blocks/qdox/java/org/apache/cocoon/components/source/impl
                        QDoxSourceFactory.java QDoxSource.java
               src/blocks/chaperon/java/org/apache/cocoon/generation
                        TextGenerator.java
  Log:
  using o.a.commons.lang
  
  Revision  Changes    Path
  1.18      +4 -10     cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
  
  Index: AbstractCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractCachingProcessingPipeline.java	5 Mar 2004 13:02:50 -0000	1.17
  +++ AbstractCachingProcessingPipeline.java	3 Apr 2004 00:46:33 -0000	1.18
  @@ -383,8 +383,7 @@
       /**
        * Generate validity objects for the new response
        */
  -    protected void setupValidities()
  -    throws ProcessingException {
  +    protected void setupValidities() throws ProcessingException {
   
           if (this.toCacheKey != null) {
               // only update validity objects if we cannot use
  @@ -502,17 +501,12 @@
                           // it means that the sitemap was modified, and the old expires value is not valid
                           // anymore.
                           if (expires != 0) {
  -                     
                               if (this.getLogger().isDebugEnabled())
                                   this.getLogger().debug("Refreshing expires informations");
  -                     
                               response.setExpires(new Long(expires + System.currentTimeMillis()));    
  -                     
                           } else {
  -                     
                               if (this.getLogger().isDebugEnabled())
                                   this.getLogger().debug("No expires defined anymore for this object, setting it to no expires");
  -                     
                               response.setExpires(null);
                           }                                   
                       }
  @@ -549,7 +543,7 @@
                       } else {
                           isValid = (valid == 1);
                       }
  -                    if ( !isValid ) {
  +                    if (!isValid) {
                           responseIsValid = false;
                           // update validity
                           if (validity == null) {
  @@ -566,7 +560,7 @@
                           i++;
                       }
                   }
  -                if ( responseIsValid ) {
  +                if (responseIsValid) {
                       if (this.getLogger().isDebugEnabled()) {
                           this.getLogger().debug("validatePipeline: using valid cached content for '" + environment.getURI() + "'.");
                       }
  
  
  
  1.5       +4 -6      cocoon-2.1/src/blocks/qdox/java/org/apache/cocoon/components/source/impl/QDoxSourceFactory.java
  
  Index: QDoxSourceFactory.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/qdox/java/org/apache/cocoon/components/source/impl/QDoxSourceFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- QDoxSourceFactory.java	5 Mar 2004 13:02:21 -0000	1.4
  +++ QDoxSourceFactory.java	3 Apr 2004 00:46:33 -0000	1.5
  @@ -32,6 +32,7 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.commons.lang.StringUtils;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceFactory;
  @@ -137,7 +138,7 @@
        * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
        */
       public Source getSource(String location, Map parameters) throws MalformedURLException, IOException, SourceException {
  -        String className = location.substring(location.indexOf(':') + 1);
  +        String className = StringUtils.substringAfter(location, ":");
           Source javaSource = null;
           if (className.length() > 0) {
               try {
  @@ -272,7 +273,6 @@
                   return source;
               }
           }
  -        
           return null;
       }
       
  @@ -287,7 +287,6 @@
           if (getLogger().isDebugEnabled()) {
               getLogger().debug("Testing uri <" + uri + ">...");
           }
  -            
           try {
               Source source = resolver.resolveURI(uri);
                   
  @@ -303,7 +302,6 @@
                   getLogger().debug("uri <" + uri + "> is invalid: " + e.getClass().getName() + " says " + e.getMessage());
               }
           }
  -        
           return null;
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.8       +10 -18    cocoon-2.1/src/blocks/qdox/java/org/apache/cocoon/components/source/impl/QDoxSource.java
  
  Index: QDoxSource.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/qdox/java/org/apache/cocoon/components/source/impl/QDoxSource.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- QDoxSource.java	5 Mar 2004 13:02:21 -0000	1.7
  +++ QDoxSource.java	3 Apr 2004 00:46:33 -0000	1.8
  @@ -42,6 +42,7 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.serialization.XMLSerializer;
  +import org.apache.commons.lang.StringUtils;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceResolver;
  @@ -232,13 +233,13 @@
           String[] imports = parent.getImports();
   
           saxStartElement(handler, IMPORTS_ELEMENT);
  -        for (int i=0; i<imports.length; i++) {
  +        for (int i = 0; i < imports.length; i++) {
               if (imports[i].endsWith("*")) {
                   // package import:
                   saxStartElement(handler, IMPORT_ELEMENT, new String[][] {{IMPORT_ATTRIBUTE, "package"}});
                   String imp = imports[i];
                   while (imp.endsWith("*") || imp.endsWith(".")) {
  -                    imp = imp.substring(0, imp.length() - 1);
  +                    imp = StringUtils.chop(imp);
                   }
                   saxCharacters(handler, imp);
               } else {
  @@ -410,12 +411,7 @@
        * @return String
        */
       private String resolveMemberNameFromLink(String ref) {
  -        int hashIndex = ref.indexOf('#');
  -        if (hashIndex < 0) {
  -            return "";
  -        } else {
  -            return ref.substring(hashIndex + 1);
  -        }
  +        return StringUtils.substringAfter(ref, "#");
       }
   
       /**
  @@ -460,7 +456,7 @@
               }
   
               boolean found = false;
  -            for (int i=0; !found && i<classImports.size(); i++) {
  +            for (int i = 0; !found && i < classImports.size(); i++) {
                   String name = (String) classImports.get(i);
                   if (name.endsWith(classPart)) {
                       classPart = name;
  @@ -504,7 +500,6 @@
                   }
               }
           }
  -
           return classPart;
       }
   
  @@ -559,7 +554,7 @@
                       outputSuperClassInheritance(handler, jClass, mode);
                   }
                   JavaMethod[] methods = jClass.getMethods();
  -                for (int i=0; i<methods.length; i++) {
  +                for (int i = 0; i < methods.length; i++) {
                       if ((mode == METHOD_INHERITANCE && methods[i].getReturns() != null) ||
                           (mode == CONSTRUCTOR_INHERITANCE && methods[i].getReturns() == null)) {
                           outputMethodStartElement(handler, methods[i]);
  @@ -567,11 +562,9 @@
                       }
                   }
                   break;
  -
               default :
                   break;
           }
  -
           saxEndElement(handler, INHERIT_ELEMENT);
       }
   
  @@ -695,7 +688,6 @@
                   }
               }
           }
  -
           return null;
       }
   
  @@ -855,15 +847,15 @@
   
           List attrs = new ArrayList();
   
  -        if (classPart != null && classPart.length() > 0) {
  +        if (StringUtils.isNotEmpty(classPart)) {
               attrs.add(new String[] {LINK_CLASS_ATTRIBUTE, classPart});
           }
   
  -        if (memberPart != null && memberPart.length() > 0) {
  +        if (StringUtils.isNotEmpty(memberPart)) {
               attrs.add(new String[] {LINK_MEMBER_ATTRIBUTE, memberPart});
           }
   
  -        if (display == null || display.length() == 0 && !ref.equals(classPart + "#" + memberPart)) {
  +        if (StringUtils.isEmpty(display) && !ref.equals(classPart + "#" + memberPart)) {
               displayPart = ref.replace('#', '.');
           }
   
  
  
  
  1.8       +43 -57    cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generation/TextGenerator.java
  
  Index: TextGenerator.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generation/TextGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TextGenerator.java	5 Mar 2004 13:01:47 -0000	1.7
  +++ TextGenerator.java	3 Apr 2004 00:46:33 -0000	1.8
  @@ -23,6 +23,7 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
   import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.commons.lang.SystemUtils;
   
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
  @@ -57,7 +58,6 @@
   {
     /** The URI of the text element */
     public static final String URI = "http://chaperon.sourceforge.net/schema/text/1.0";
  -  private static final String NL = System.getProperty("line.separator");
     private static final char[] initNonXmlChars =
     {
       ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
  @@ -112,25 +112,21 @@
      * @throws SAXException
      */
     public void setup(SourceResolver resolver, Map objectmodel, String src, Parameters parameters)
  -    throws ProcessingException, SAXException, IOException
  -  {
  +    throws ProcessingException, SAXException, IOException {
       super.setup(resolver, objectmodel, src, parameters);
  -    try
  -    {
  +    try {
         this.encoding = parameters.getParameter("encoding", null);
         this.inputSource = resolver.resolveURI(src);
   
         String nXmlCh = parameters.getParameter("nonXmlChars", String.valueOf(initNonXmlChars));
  -      if (nXmlCh.length()!=initNonXmlChars.length)
  +      if (nXmlCh.length() != initNonXmlChars.length)
           throw new ProcessingException("Error during resolving of '"+src+"'.",
                                         new SourceException("length of attribute string 'nonXmlChars' is "+
                                                             nXmlCh.length()+" where it should be "+
                                                             initNonXmlChars.length+"!"));
   
         this.nonXmlChars = nXmlCh.toCharArray();
  -    }
  -    catch (SourceException se)
  -    {
  +    } catch (SourceException se) {
         throw new ProcessingException("Error during resolving of '"+src+"'.", se);
       }
     }
  @@ -163,23 +159,21 @@
      * @throws ProcessingException
      * @throws SAXException
      */
  -  public void generate() throws IOException, SAXException, ProcessingException
  -  {
  +  public void generate() throws IOException, SAXException, ProcessingException {
       InputStreamReader in = null;
   
  -    try
  -    {
  +    try {
         final InputStream sis = this.inputSource.getInputStream();
  -      if (sis==null)
  +      if (sis == null) {
           throw new ProcessingException("Source '"+this.inputSource.getURI()+"' not found");
  +      }
   
  -      if (encoding!=null)
  +      if (encoding != null) {
           in = new InputStreamReader(sis, encoding);
  -      else
  +      } else {
           in = new InputStreamReader(sis);
  -    }
  -    catch (SourceException se)
  -    {
  +      }
  +    } catch (SourceException se) {
         throw new ProcessingException("Error during resolving of '"+this.source+"'.", se);
       }
   
  @@ -194,9 +188,7 @@
       contentHandler.startPrefixMapping("", URI);
   
       AttributesImpl atts = new AttributesImpl();
  -
  -    if (localizable)
  -    {
  +    if (localizable) {
         atts.addAttribute("", "source", "source", "CDATA", locator.getSystemId());
         atts.addAttribute("", "line", "line", "CDATA", String.valueOf(locator.getLineNumber()));
         atts.addAttribute("", "column", "column", "CDATA", String.valueOf(locator.getColumnNumber()));
  @@ -208,54 +200,48 @@
       String line;
       String newline = null;
   
  -    while (true)
  -    {
  -      if (newline==null)
  +    while (true) {
  +      if (newline==null) {
           line = convertNonXmlChars(reader.readLine());
  -      else
  +      } else {
           line = newline;
  -
  -      if (line==null)
  +      }
  +      if (line==null) {
           break;
  -
  +      }
         newline = convertNonXmlChars(reader.readLine());
  -
  -      line = (newline!=null) ? (line+NL) : line;
  -
  +      if (newline != null) {
  +          line += SystemUtils.LINE_SEPARATOR;
  +      }
         locator.setLineNumber(reader.getLineNumber());
         locator.setColumnNumber(1);
         contentHandler.characters(line.toCharArray(), 0, line.length());
  -
  -      if (newline==null)
  +      if (newline==null) {
           break;
  +      }
       }
  -
       contentHandler.endElement(URI, "text", "text");
  -
       contentHandler.endPrefixMapping("");
       contentHandler.endDocument();
     }
   
  -  private String convertNonXmlChars(String s)
  -  {
  -    if (s==null)
  -      return null;
  -
  -    int nv;
  -    char[] sc = s.toCharArray();
  -
  -    for (int i = 0; i<sc.length; i++)
  -    {
  -      nv = sc[i];
  -
  -      if ((nv>=0) && (nv<nonXmlChars.length))
  -      {
  -        //do not convert white space characters
  -        if ((nv!=9) && (nv!=10) && (nv!=13))
  -          sc[i] = nonXmlChars[nv];
  -      }
  +  private String convertNonXmlChars(String s) {
  +    if (s != null) {
  +        int nv;
  +        char[] sc = s.toCharArray();
  +    
  +        for (int i = 0; i<sc.length; i++) {
  +          nv = sc[i];
  +    
  +          if ((nv>=0) && (nv<nonXmlChars.length)) {
  +            //do not convert white space characters
  +            if ((nv!=9) && (nv!=10) && (nv!=13))
  +              sc[i] = nonXmlChars[nv];
  +          }
  +        }
  +        return String.valueOf(sc);
  +    } else {
  +        return null;
       }
  -
  -    return String.valueOf(sc);
     }
   }
  
  
  

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generationTextGe nerator.java

Posted by Antonio Gallardo <ag...@agssa.net>.
Tim Larson dijo:
> On Fri, Apr 02, 2004 at 07:28:24PM -0600, Antonio Gallardo wrote:
>> I want to see Groovy running inside Cocoon. This is why I am working on
>> the BSF block :-D
>
> Hey thanks Antonio.  Let us know when you get Groovy working :)

Of course!

Best Regards,

Antonio Gallardo

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generationTextGe nerator.java

Posted by Tim Larson <ti...@keow.org>.
On Fri, Apr 02, 2004 at 07:28:24PM -0600, Antonio Gallardo wrote:
> I want to see Groovy running inside Cocoon. This is why I am working on
> the BSF block :-D

Hey thanks Antonio.  Let us know when you get Groovy working :)

--Tim Larson

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generationTextGe nerator.java

Posted by Antonio Gallardo <ag...@agssa.net>.
Joerg Heinicke dijo:
> 19:17 is not a time to go to bed under normal circumstances - but after
> a night without sleep ;-)

Still no, because there are very interesting stuff that don't allow me sleep:

I want to see Groovy running inside Cocoon. This is why I am working on
the BSF block :-D

Best Regards,

Antonio Gallardo.

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generationTextGe nerator.java

Posted by Joerg Heinicke <jo...@gmx.de>.
On 03.04.2004 03:17, Antonio Gallardo wrote:

> Hi Joerg:
> 
> Thanks for posting it, I already reverted the change. Yes, I still does
> not sleep, here is now 19:17.
> 
> Sorry for the inconvenience.

No inconvenience as I do not use it. Just looked over the changes, 
StringUtils is really an interesting class.

19:17 is not a time to go to bed under normal circumstances - but after 
a night without sleep ;-)

Joerg

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generationTextGe nerator.java

Posted by Antonio Gallardo <ag...@agssa.net>.
Joerg Heinicke dijo:
>>   Index: QDoxSourceFactory.java
>>   ===================================================================
>>   -        String className = location.substring(location.indexOf(':') +
>> 1);
>>   +        String className = StringUtils.substringAfter(location, ":");

Hi Joerg:

Thanks for posting it, I already reverted the change. Yes, I still does
not sleep, here is now 19:17.

Sorry for the inconvenience.

Best Regards,

Antonio Gallardo

Re: cvs commit: cocoon-2.1/src/blocks/chaperon/java/org/apache/cocoon/generation TextGenerator.java

Posted by Joerg Heinicke <jo...@gmx.de>.
On 03.04.2004 02:46, antonio@apache.org wrote:

> antonio     2004/04/02 16:46:33
> 
>   Modified:    src/java/org/apache/cocoon/components/pipeline/impl
>                         AbstractCachingProcessingPipeline.java
>                src/blocks/qdox/java/org/apache/cocoon/components/source/impl
>                         QDoxSourceFactory.java QDoxSource.java
>                src/blocks/chaperon/java/org/apache/cocoon/generation
>                         TextGenerator.java
>   Log:
>   using o.a.commons.lang

>   Index: QDoxSourceFactory.java
>   ===================================================================
>   -        String className = location.substring(location.indexOf(':') + 1);
>   +        String className = StringUtils.substringAfter(location, ":");

>   Index: QDoxSource.java
>   ===================================================================
>        private String resolveMemberNameFromLink(String ref) {
>   -        int hashIndex = ref.indexOf('#');
>   -        if (hashIndex < 0) {
>   -            return "";
>   -        } else {
>   -            return ref.substring(hashIndex + 1);
>   -        }
>   +        return StringUtils.substringAfter(ref, "#");

Still no sleep, Antonio?

One of the above must obviously be wrong IMO as it changes the behaviour 
in comparison to the original code. From commons lang JavaDoc I guess 
it's the QDoxSourceFactory change:
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringUtils.html#substringAfter(java.lang.String,%20java.lang.String)

If the second argument of substringAfter() is not found in the first 
argument, the function returns an empty string. This is why you can 
replace 6 lines in QDoxSource with one line.
But for the original code of QDoxSourceFactory this did not happen. If 
there is no ':' in location, className would be location 
(location.indexOf(':') = -1), now it is empty string. And there it also 
makes not much sense to introduce dependency on another library as it 
saves only 3 chars.

Joerg