commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [digester] Rule for processing instruction?
Date Thu, 25 Sep 2003 20:36:41 GMT
robert burrell donkin wrote:

> hi janek
>
> i don't see any reason why we shouldn't put something to allow access 
> to processing instructions into digester. this probably means storing 
> the indexed processing instruction (just as your example code does). 
> probably worth giving a getting for the keys as well as a 
> per-instruction getter. rules would be able to access these properties 
> during their execution by calling the properties on digester.
>
> 1. can anyone see any issues with this approach?
> 2. can anyone think of anything i've forgotten? 

Wouldn't some use cases for processing instructions want to depend on 
the context in which they occurred?  If so, it might be nice to invent a 
syntax where you could match on them in rules, just like we match on 
element names.

>
>
> - robert

Craig

>
> On Thursday, September 25, 2003, at 12:10 PM, Janek Bogucki wrote:
>
>> On Wed, 2003-09-24 at 15:25, Norbert Pabiś wrote:
>>
>>> Udało Ci się znaleźć regułe na processing instruction?
>>>
>>>
>>> -- 
>>> Norbert Pabiś
>>>
>>>
>>
>> AFAIK there is no rule set for using PIs when building the data. If you
>> are happy to obtain the PIs after the parse you could adapt this class
>> which collects PIs into a Map. Create an instance of this class and use
>> it as a normal Digester:
>>
>>    Digester d = new PIDigester () ;
>>
>>    // set-up
>>
>>    d.parse () ;
>>
>>    String myPIvalue = (PIDigester)d.getProcessingIntruction ( target ) ;
>>
>> -Janek
>>
>> /*
>>  * PIDigester.java
>>  *
>>  * Created on 18 March 2003, 14:34
>>  */
>>
>> package com.studylink.data.load;
>>
>> import java.util.HashMap ;
>> import java.util.Map ;
>>
>> import org.xml.sax.SAXException ;
>>
>> import org.apache.commons.digester.Digester ;
>>
>> import com.studylink.utility.StringUtilities ;
>>
>> /**
>>  * A subclass of org.apache.commons.digester.Digester to collect
>> processing
>>  * instructions and provide access to these instructions after the
>> parse.
>>  *
>>  * @author  Janek Bogucki
>>  * @version $Id: PIDigester.java,v 1.1 2003/03/18 15:41:00 jdb Exp $
>>  */
>> public class PIDigester extends Digester {
>>
>>     /**
>>      * Creates new PIDigester
>>      */
>>     public PIDigester () {
>>         super () ;
>>     }
>>
>>
>>     private Map processingInstructions = new HashMap () ;
>>
>>     public String getProcessingIntruction ( String piTarget ) {
>>
>>         StringUtilities.validateNonZeroLength ( piTarget ) ;
>>
>>         return ( String ) processingInstructions.get ( piTarget ) ;
>>     }
>>
>>     /**
>>      * @throws SAXException if the target has already been encountered
>>      */
>>     public void processingInstruction ( String target, String data)
>> throws SAXException {
>>
>>         /* logging */
>>         super.processingInstruction ( target, data ) ;
>>
>>         if ( getProcessingIntruction ( target ) != null )
>>             throw new SAXException ( "target already encountered: " +
>> target ) ;
>>
>>         processingInstructions.put ( target, data ) ;
>>     }
>>
>>
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message