cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From step...@apache.org
Subject cvs commit: xml-cocoon2/src/blocks/chaperon/samples/stylesheets pattern2link.xsl
Date Wed, 05 Feb 2003 12:55:05 GMT
stephan     2003/02/05 04:55:05

  Modified:    src/blocks/chaperon/java/org/apache/cocoon/transformation
                        PatternTransformer.java
               src/blocks/chaperon/samples sitemap.xmap
               src/blocks/chaperon/samples/grammars link.xlex
               src/blocks/chaperon/samples/stylesheets pattern2link.xsl
  Log:
  Allow pattern groups for the PatternTransformer, with this feature you
  be able to write something like s/([a-z]+)@([a-z]+)/\1 at \2/g in
  a XML world.
  
  Revision  Changes    Path
  1.4       +33 -2     xml-cocoon2/src/blocks/chaperon/java/org/apache/cocoon/transformation/PatternTransformer.java
  
  Index: PatternTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/chaperon/java/org/apache/cocoon/transformation/PatternTransformer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PatternTransformer.java	4 Feb 2003 15:14:26 -0000	1.3
  +++ PatternTransformer.java	5 Feb 2003 12:55:05 -0000	1.4
  @@ -72,6 +72,8 @@
   import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
  @@ -109,7 +111,7 @@
    * @version CVS $Id$
    */
   public class PatternTransformer extends AbstractTransformer
  -  implements LogEnabled, Composable, Recyclable, Disposable,
  +  implements LogEnabled, Composable, Recyclable, Disposable, Parameterizable,
                CacheableProcessingComponent {
   
       /** Namespace for the SAX events. */
  @@ -125,6 +127,8 @@
       private LexicalAutomaton automaton = null;
       private PatternProcessor processor = new PatternProcessor();
   
  +    private boolean groups = false;
  +
       private StringBuffer buffer = new StringBuffer();
       private StringBuffer output = new StringBuffer();
   
  @@ -149,6 +153,18 @@
       }
   
       /**
  +     * Provide component with parameters.
  +     *
  +     * @param parameters the parameters
  +     * @throws ParameterException if parameters are invalid
  +     */
  +    public void parameterize(Parameters parameters)
  +      throws ParameterException {
  +
  +        groups = parameters.getParameterAsBoolean("groups", false);
  +    }
  +
  +    /**
        * Set the SourceResolver, objectModel Map, the source and sitemap
        * Parameters used to process the request.
        *
  @@ -400,6 +416,7 @@
           char[] text = buffer.toString().toCharArray();
   
           String lexemesymbol, lexemetext;
  +        String[] groups = null;
           int lexemeindex = 0;
           int position = 0;
   
  @@ -417,6 +434,11 @@
                        (processor.getGroup().length()>=lexemetext.length()))) {
                       lexemesymbol = automaton.getLexemeSymbol(lexemeindex);
                       lexemetext = processor.getGroup();
  +                    if (this.groups) {
  +                      groups = new String[processor.getGroupCount()];
  +                      for (int group=0; group<processor.getGroupCount(); group++)
  +                        groups[group] = processor.getGroup(group);
  +                    }
                   }
               }
   
  @@ -442,6 +464,15 @@
                       atts.addAttribute("", "text", "text", "CDATA",
                                         lexemetext);
                       contentHandler.startElement(NS, "lexeme", "lexeme", atts);
  +
  +                    if (this.groups) {
  +                      for (int group=0; group<groups.length; group++) {
  +                      contentHandler.startElement(NS, "group", "group", new AttributesImpl());
  +                      contentHandler.characters(groups[group].toCharArray(), 0, groups[group].length());
  +                      contentHandler.endElement(NS, "group", "group");
  +                      }
  +                    }
  +
                       contentHandler.endElement(NS, "lexeme", "lexeme");
                       contentHandler.endPrefixMapping("");
                   } else if (logger!=null) {
  
  
  
  1.6       +3 -1      xml-cocoon2/src/blocks/chaperon/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/chaperon/samples/sitemap.xmap,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sitemap.xmap	4 Feb 2003 20:58:31 -0000	1.5
  +++ sitemap.xmap	5 Feb 2003 12:55:05 -0000	1.6
  @@ -36,7 +36,9 @@
   
      <map:transformer name="pattern" 
                       src="org.apache.cocoon.transformation.PatternTransformer" 
  -                    logger="sitemap.transformer.pattern"/>
  +                    logger="sitemap.transformer.pattern">
  +    <parameter name="groups" value="true"/>
  +   </map:transformer>
      <map:transformer name="lexer" 
                       src="org.apache.cocoon.transformation.LexicalTransformer" 
                       logger="sitemap.transformer.lexer"/>
  
  
  
  1.2       +16 -12    xml-cocoon2/src/blocks/chaperon/samples/grammars/link.xlex
  
  Index: link.xlex
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/chaperon/samples/grammars/link.xlex,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- link.xlex	4 Feb 2003 13:26:34 -0000	1.1
  +++ link.xlex	5 Feb 2003 12:55:05 -0000	1.2
  @@ -56,19 +56,23 @@
    <lexeme symbol="email">
     <concat>
      <concat>
  -    <cclass maxOccurs="*">
  -     <cinterval min="A" max="Z"/>
  -     <cinterval min="a" max="z"/>
  -     <cinterval min="0" max="9"/>
  -     <cset content="._-:"/>
  -    </cclass>
  +    <group>
  +     <cclass maxOccurs="*">
  +      <cinterval min="A" max="Z"/>
  +      <cinterval min="a" max="z"/>
  +      <cinterval min="0" max="9"/>
  +      <cset content="._-:"/>
  +     </cclass>
  +    </group>
       <cstring content="@"/>
  -    <cclass maxOccurs="*">
  -     <cinterval min="A" max="Z"/>
  -     <cinterval min="a" max="z"/>
  -     <cinterval min="0" max="9"/>
  -     <cset content="._-:"/>
  -    </cclass>
  +    <group>
  +     <cclass maxOccurs="*">
  +      <cinterval min="A" max="Z"/>
  +      <cinterval min="a" max="z"/>
  +      <cinterval min="0" max="9"/>
  +      <cset content="._-:"/>
  +     </cclass>
  +    </group>
      </concat>
     </concat>
    </lexeme>
  
  
  
  1.2       +2 -1      xml-cocoon2/src/blocks/chaperon/samples/stylesheets/pattern2link.xsl
  
  Index: pattern2link.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/chaperon/samples/stylesheets/pattern2link.xsl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pattern2link.xsl	4 Feb 2003 13:26:34 -0000	1.1
  +++ pattern2link.xsl	5 Feb 2003 12:55:05 -0000	1.2
  @@ -12,7 +12,8 @@
   
    <xsl:template match="lex:lexeme[@symbol='email']">
     <a href="mailto:{@text}">
  -   <xsl:value-of select="@text"/>
  +   <xsl:value-of select="lex:group[2]"/> at
  +   <xsl:value-of select="lex:group[3]"/>
     </a>
    </xsl:template>
   
  
  
  

----------------------------------------------------------------------
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