You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by un...@apache.org on 2004/07/14 18:44:35 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/extractor SimpleXmlExtractor.java PropertyExtractorTrigger.java

unico       2004/07/14 09:44:35

  Modified:    src/share/org/apache/slide/extractor SimpleXmlExtractor.java
                        PropertyExtractorTrigger.java
  Log:
  add support for extracting and setting properties in other namespaces than DAV:
  add an optional 'namespace' attribute on an <instruction> declaration in SimpleXmlExtractor
  
  Revision  Changes    Path
  1.6       +17 -12    jakarta-slide/src/share/org/apache/slide/extractor/SimpleXmlExtractor.java
  
  Index: SimpleXmlExtractor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/extractor/SimpleXmlExtractor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleXmlExtractor.java	9 Jul 2004 15:38:10 -0000	1.5
  +++ SimpleXmlExtractor.java	14 Jul 2004 16:44:35 -0000	1.6
  @@ -23,6 +23,7 @@
   
   package org.apache.slide.extractor;
   
  +import org.apache.slide.common.PropertyName;
   import org.apache.slide.util.conf.Configurable;
   import org.apache.slide.util.conf.Configuration;
   import org.apache.slide.util.conf.ConfigurationException;
  @@ -86,10 +87,12 @@
        * @return  the property value to be set, <code>null</codee> if to be ignored.
        */
       protected Object filter(List nodeList, Instruction instruction) throws ExtractorException {
  -        if (nodeList.get(0) instanceof Text) {
  -            return ((Text) nodeList.get(0)).getText();
  -        } else if (nodeList.get(0) instanceof String) {
  -            return nodeList.get(0);
  +        if (nodeList.size() > 0) {
  +            if (nodeList.get(0) instanceof Text) {
  +                return ((Text) nodeList.get(0)).getText();
  +            } else if (nodeList.get(0) instanceof String) {
  +                return nodeList.get(0);
  +            }
           }
           return null;
       }
  @@ -101,27 +104,29 @@
       protected Instruction createInstruction(Configuration instruction) throws ConfigurationException {
           try {
               String property = instruction.getAttribute("property");
  +            String namespace = instruction.getAttribute("namespace", "DAV:");
               XPath xPath = XPath.newInstance(instruction.getAttribute("xpath"));
  -            return new Instruction(xPath, property);
  +            return new Instruction(xPath, new PropertyName(property, namespace));
           } catch (JDOMException e) {
               throw new ConfigurationException("Could not create xPath from given attribute", instruction);
           }
       }
       
       protected static class Instruction {
  +
           private XPath xPath;
  -        private String propertyName;
  +        private PropertyName propertyName;
   
  -        public Instruction(XPath xPath, String propertyName) {
  +        public Instruction(XPath xPath, PropertyName property) {
               this.xPath = xPath;
  -            this.propertyName = propertyName;
  +            this.propertyName = property;
           }
   
           public XPath getxPath() {
               return xPath;
           }
   
  -        public String getPropertyName() {
  +        public PropertyName getPropertyName() {
               return propertyName;
           }
       }
  
  
  
  1.4       +15 -7     jakarta-slide/src/share/org/apache/slide/extractor/PropertyExtractorTrigger.java
  
  Index: PropertyExtractorTrigger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/extractor/PropertyExtractorTrigger.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertyExtractorTrigger.java	5 Jun 2004 12:20:19 -0000	1.3
  +++ PropertyExtractorTrigger.java	14 Jul 2004 16:44:35 -0000	1.4
  @@ -27,6 +27,7 @@
   import java.util.Iterator;
   import java.util.Map;
   
  +import org.apache.slide.common.PropertyName;
   import org.apache.slide.content.NodeRevisionContent;
   import org.apache.slide.content.NodeRevisionDescriptor;
   import org.apache.slide.content.NodeRevisionDescriptors;
  @@ -38,7 +39,6 @@
    * @author <a href="mailto:dflorey@c1-fse.de">Daniel Florey</a>
    * @version $Revision$
    */
  -
   public class PropertyExtractorTrigger extends ContentAdapter {
       public void create(ContentEvent event) throws VetoException {
           store(event);
  @@ -54,8 +54,16 @@
                   for ( int i = 0; i < extractor.length; i++ ) {
                       Map extractedProperties = extractor[i].extract(new ByteArrayInputStream(content.getContentBytes()));
                       for ( Iterator j = extractedProperties.entrySet().iterator(); j.hasNext(); ) {
  -                        Map.Entry entry = (Map.Entry)j.next();
  -                        descriptor.setProperty((String)entry.getKey(), entry.getValue());
  +                        Map.Entry entry = (Map.Entry) j.next();
  +                        final Object key = entry.getKey();
  +                        if (key instanceof PropertyName) {
  +                            final String name = ((PropertyName) key).getName();
  +                            final String namespace = ((PropertyName) key).getNamespace();
  +                            descriptor.setProperty(name, namespace, entry.getValue());
  +                        }
  +                        else {
  +                            descriptor.setProperty((String) entry.getKey(), entry.getValue());
  +                        }
                       }
                   }
               }
  
  
  

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