cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/helpers SourceProperty.java
Date Sat, 27 Mar 2004 21:49:09 GMT
unico       2004/03/27 13:49:09

  Modified:    src/blocks/repository/java/org/apache/cocoon/components/source/impl
                        XPathSourceInspector.java
               src/blocks/repository/java/org/apache/cocoon/components/source/helpers
                        SourceProperty.java
  Log:
  formatting and cleanup
  
  Revision  Changes    Path
  1.8       +31 -37    cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/XPathSourceInspector.java
  
  Index: XPathSourceInspector.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/XPathSourceInspector.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathSourceInspector.java	5 Mar 2004 13:02:21 -0000	1.7
  +++ XPathSourceInspector.java	27 Mar 2004 21:49:09 -0000	1.8
  @@ -18,6 +18,7 @@
   import java.io.IOException;
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.ServiceException;
  @@ -39,13 +40,11 @@
   
   /**
    * This source inspector inspects XML files with a xpath expression.
  - *
  - * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
  - * @author <a href="mailto:unico@apache.org">Unico Hommes</a>
  + * 
    * @version CVS $Id$
    */
  -public class XPathSourceInspector extends AbstractLogEnabled implements 
  -    SourceInspector, Serviceable, Parameterizable, ThreadSafe {
  +public class XPathSourceInspector extends AbstractLogEnabled 
  +implements SourceInspector, Serviceable, Parameterizable, ThreadSafe {
   
       /**
        * The default namespace uri of the property exposed by this SourceInspector.
  @@ -63,45 +62,45 @@
        */
       public static final String DEFAULT_PROPERTY_NAME = "result";
       
  -    private static final SourceValidity VALIDITY = new NOPValidity();
  +    private String m_namespace;
  +    private String m_propertyname;
  +    private String m_extension;
  +    private String m_xpath;
       
  -    private String propertynamespace;
  -    private String propertyname;
  -    private String extension;
  -    private String xpath;
  -
       private ServiceManager manager = null;
  -
  +    
  +    public XPathSourceInspector() {
  +    }
  +    
       public void service(ServiceManager manager) {
           this.manager = manager;
       }
       
  -    public void parameterize(Parameters params)  {
  -        this.propertynamespace = params.getParameter("namespace", DEFAULT_PROPERTY_NS);
  -        this.propertyname = params.getParameter("name", DEFAULT_PROPERTY_NAME);
  -        this.extension = params.getParameter("extension", ".xml");
  -        this.xpath = params.getParameter("xpath", "/*");
  +    public void parameterize(Parameters params) throws ParameterException {
  +        this.m_namespace = params.getParameter("namespace", DEFAULT_PROPERTY_NS);
  +        this.m_propertyname = params.getParameter("name", DEFAULT_PROPERTY_NAME);
  +        this.m_extension = params.getParameter("extension", ".xml");
  +        this.m_xpath = params.getParameter("xpath", "/*");
       }
       
       public SourceProperty getSourceProperty(Source source, String namespace, String name)

  -        throws SourceException {
  +    throws SourceException {
   
  -        if ((namespace.equals(propertynamespace)) && (name.equals(propertyname))
&& 
  -            (source.getURI().endsWith(extension))) {
  +        if ((namespace.equals(m_namespace)) && 
  +                (name.equals(m_propertyname)) && 
  +                (source.getURI().endsWith(m_extension))) {
   
               DOMParser parser = null;
               Document doc = null;
               try { 
  -                parser = (DOMParser)manager.lookup(DOMParser.ROLE);
  -
  +                parser = (DOMParser) manager.lookup(DOMParser.ROLE);
                   doc = parser.parseDocument(new InputSource(source.getInputStream()));
               } catch (SAXException se) {
  -                this.getLogger().error(source.getURI()
  -                                        + " is not a valid XML file");
  +                this.getLogger().error(source.getURI() + " is not a valid XML file");
               } catch (IOException ioe) {
                   this.getLogger().error("Could not read file", ioe);
               } catch (ServiceException ce) {
  -                this.getLogger().error("Could not retrieve component", ce);
  +                this.getLogger().error("Missing service dependency: DOMParser", ce);
               } finally {
                   if (parser != null) {
                       this.manager.release(parser);
  @@ -109,16 +108,12 @@
               }
   
               if (doc != null) {
  -
                   XPathProcessor processor = null;
                   try {
                       processor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
  -
  -                    NodeList nodelist = processor.selectNodeList(doc.getDocumentElement(),
this.xpath);
  -
  -                    SourceProperty property = new SourceProperty(this.propertynamespace,
this.propertyname);
  +                    NodeList nodelist = processor.selectNodeList(doc.getDocumentElement(),
m_xpath);
  +                    SourceProperty property = new SourceProperty(m_namespace, m_propertyname);
                       property.setValue(nodelist);
  -
                       return property;
                   } catch (ServiceException se) {
                       this.getLogger().error("Could not retrieve component", se);
  @@ -129,26 +124,25 @@
                   }
               }
           } 
  -        return null;  
  +        return null;
       }
   
       public SourceProperty[] getSourceProperties(Source source) throws SourceException {
  -
  -        SourceProperty property = getSourceProperty(source, this.propertynamespace, this.propertyname);
  +        SourceProperty property = getSourceProperty(source, this.m_namespace, this.m_propertyname);
           if (property!=null)
               return new SourceProperty[]{property};
           return null;
       }
       
       public boolean handlesProperty(String namespace, String name) {
  -        return this.propertynamespace.equals(namespace) && this.propertyname.equals(name);
  +        return this.m_namespace.equals(namespace) && this.m_propertyname.equals(name);
       }
   
       /**
        * Returns NOPValidity
        */
       public SourceValidity getValidity(Source source) {
  -        return VALIDITY;
  +        return NOPValidity.SHARED_INSTANCE;
       }
       
   }
  
  
  
  1.3       +16 -52    cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/helpers/SourceProperty.java
  
  Index: SourceProperty.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/helpers/SourceProperty.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SourceProperty.java	5 Mar 2004 13:02:21 -0000	1.2
  +++ SourceProperty.java	27 Mar 2004 21:49:09 -0000	1.3
  @@ -35,16 +35,14 @@
    */
   public class SourceProperty implements XMLizable {
   
  +    private static final String URI = "http://www.w3.org/2000/xmlns/";
  +    private static final String NS_PREFIX = "property";
  +    private static final String D_PREFIX = NS_PREFIX+":";
  +    
       private String namespace;
       private String name;
       private Element value;
  -
  -    /**  */
  -    public static final String NS_PREFIX = "property";
  -    private static final String D_PREFIX = NS_PREFIX+":";
  -
  -    private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
  -
  +    
       /**
        * Creates a new property for a source
        *
  @@ -57,21 +55,15 @@
           this.name = name;
   
           try {
  -            // FIXME: There must be an easier way to create a DOM element
               DOMBuilder builder = new DOMBuilder();
  -
               builder.startDocument();
               builder.startPrefixMapping(NS_PREFIX, namespace);
               AttributesImpl attrs = new AttributesImpl();
  -
  -            attrs.addAttribute(XMLNS_NS, NS_PREFIX, "xmlns:"+NS_PREFIX,
  -                               "NMTOKEN", namespace);
  +            attrs.addAttribute(URI, NS_PREFIX, "xmlns:"+NS_PREFIX, "NMTOKEN", namespace);
               builder.startElement(namespace, name, D_PREFIX+name, attrs);
               builder.endElement(namespace, name, D_PREFIX+name);
               builder.endPrefixMapping(NS_PREFIX);
  -
               Document doc = builder.getDocument();
  -
               this.value = doc.getDocumentElement();
           } catch (SAXException se) {
               // do nothing
  @@ -146,28 +138,18 @@
        * @param value Value of the property
        */
       public void setValue(String value) {
  -        // this.value = value;
  -
           try {
               DOMBuilder builder = new DOMBuilder();
  -
               builder.startDocument();
               builder.startPrefixMapping(NS_PREFIX, namespace);
               AttributesImpl attrs = new AttributesImpl();
  -
  -            attrs.addAttribute(XMLNS_NS, NS_PREFIX, "xmlns:"+NS_PREFIX,
  -                               "NMTOKEN", namespace);
  -
  +            attrs.addAttribute(URI, NS_PREFIX, "xmlns:"+NS_PREFIX, "NMTOKEN", namespace);
               builder.startElement(namespace, name, D_PREFIX+name, attrs);
  -
               builder.characters(value.toCharArray(), 0, value.length());
  -
               builder.endElement(namespace, name, D_PREFIX+name);
               builder.endPrefixMapping(NS_PREFIX);
               builder.endDocument();
  -
               Document doc = builder.getDocument();
  -
               this.value = doc.getDocumentElement();
           } catch (SAXException se) {
               // do nothing
  @@ -180,15 +162,16 @@
        * @return Value of the property
        */
       public String getValueAsString() {
  -
           NodeList nodeslist = this.value.getChildNodes();
           StringBuffer buffer = new StringBuffer();
  -
  -        for (int i = 0; i<nodeslist.getLength(); i++)
  +        for (int i = 0; i<nodeslist.getLength(); i++) {
               if ((nodeslist.item(i).getNodeType()==Node.TEXT_NODE) ||
  -                (nodeslist.item(i).getNodeType()==Node.CDATA_SECTION_NODE)) {
  +                (nodeslist.item(i).getNodeType()==Node.CDATA_SECTION_NODE)) 
  +            {
  +                
                   buffer.append(nodeslist.item(i).getNodeValue());
               }
  +        }
   
           return buffer.toString();
       }
  @@ -196,38 +179,20 @@
       /**
        * Sets the value of the property
        *
  -     * @param value Value of the property
  -     */
  -    public void setValue(Element value) {
  -        if ((value.getLocalName().equals(name)) &&
  -            (value.getNamespaceURI().equals(namespace))) {
  -            this.value = value;
  -        }
  -    }
  -
  -    /**
  -     * Sets the value of the property
  -     *
  -     *
        * @param values
        */
       public void setValue(NodeList values) {
           try {
               DOMBuilder builder = new DOMBuilder();
  -
               builder.startDocument();
               builder.startElement(namespace, name, name, new AttributesImpl());
  -
               DOMStreamer stream = new DOMStreamer(builder);
  -
  -            for (int i = 0; i<values.getLength(); i++)
  +            for (int i = 0; i<values.getLength(); i++) {
                   stream.stream(values.item(i));
  -
  +            }
               builder.endElement(namespace, name, name);
               builder.endDocument();
  -
               Document doc = builder.getDocument();
  -
               this.value = doc.getDocumentElement();
           } catch (SAXException se) {
               // do nothing
  @@ -235,7 +200,7 @@
       }
   
       /**
  -     *
  +     * Get the property value as DOM Element.
        */
       public Element getValue() {
           return this.value;
  @@ -251,7 +216,6 @@
        */
       public void toSAX(ContentHandler handler) throws SAXException {
           DOMStreamer stream = new DOMStreamer(handler);
  -
           stream.stream(this.value);
       }
   }
  
  
  

Mime
View raw message