cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael French <mfre...@zycor.lgc.com>
Subject RE: New Tokenizer not working
Date Mon, 20 Mar 2000 19:43:08 GMT


> -----Original Message-----
> From: Robin Green [mailto:greenrd@HOTMAIL.COM]
> Sent: Monday, March 20, 2000 7:51 AM
> To: cocoon-dev@xml.apache.org
> Cc: moravek@pobox.sk
> Subject: New Tokenizer not working
> 
> The new class org.apache.cocoon.Tokenizer that was just 
> committed has a 
> behaviour which does not make sense when called by 
> org.apache.cocoon.Utils.getPIPseudoAttributes(Utils.java:169)

While we're on the subject of PIs, I had a problem with the 
pseudo attribute parser when the pseudo-values contain '='.
(e.g. href passing parameters to a dynamic stylesheet)
The existing code parses on '=', so I hacked it to parse on the '"'.
I also moved the common parsing code into a private utility function
called addPIPseudoAttributes. 

Mike


cocoon/Utils.java
------------------

Replace   getPIPseudoAttributes( Document, String )
with . . . 

    public static final Hashtable getPIPseudoAttributes(
        Document document, 
        String   name ) 
    {
        Hashtable   attributes = new Hashtable();
        Enumeration nodes      = getAllPIs(document, name).elements();
        
        while (nodes.hasMoreElements()) 
        {
            ProcessingInstruction pi = (ProcessingInstruction)
nodes.nextElement();
            addPIPseudoAttributes( pi, attributes );
        }   
        return attributes;
    }

Replace  getPIPseudoAttributes( ProcessingInstruction  )
with . . . 


    public static final Hashtable getPIPseudoAttributes(
        ProcessingInstruction pi ) 
    {
        Hashtable attributes = new Hashtable();
        addPIPseudoAttributes( pi, attributes );
        return attributes;
    }

Add

    /**
     * This method adds pseudo attributes from a pi to an existing attribute
list.
     * All attributes are all put in the same hashtable.
     * If there are collisions, the last attribute is inserted.
     * No validation is performed on the PI pseudo syntax.
     */

    private static final void addPIPseudoAttributes(
        ProcessingInstruction pi,
        Hashtable             attributes ) 
    {
        String data = pi.getData();

        StringTokenizer st = new StringTokenizer(data, '\"');
        try
        {
          while (st.hasMoreTokens()) {
              String key   = st.nextToken();     // attribute name and '='
              String token = st.nextToken();     // exact attribute value
              key = key.replace('=',' ').trim(); // remove whitespace and
'='
              attributes.put(key, token);    
          }
        }
        catch( NoSuchElementException nsee )
        {
          // ignore white-space at the end of pseudo-list
        }
    }

Mime
View raw message