commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janek Bogucki <...@studylink.com>
Subject Re: [digester] Rule for processing instruction?
Date Thu, 25 Sep 2003 11:10:53 GMT
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


Mime
View raw message