cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From step...@apache.org
Subject cvs commit: xml-cocoon2/src/blocks/slide/samples sitemap.xmap
Date Wed, 05 Mar 2003 18:48:00 GMT
stephan     2003/03/05 10:48:00

  Modified:    src/blocks/slide/conf slide-repository.xconf
                        slide-repository.xroles
               src/blocks/slide/java/org/apache/cocoon/components/repository
                        Repository.java
               src/blocks/slide/java/org/apache/cocoon/components/repository/impl
                        SlidePrincipalProvider.java
               src/blocks/slide/java/org/apache/cocoon/components/source/impl
                        SlideSource.java SlideSourceFactory.java
               src/blocks/slide/samples sitemap.xmap
  Log:
  Add transaction support for setProperty, see Bug 17496.
  Add some fixes to use XML fragments in SourceProperties.
  And reverting the usage of the ComponentSelector, since the
  repository role depend heavy on Slide.
  
  Revision  Changes    Path
  1.2       +21 -28    xml-cocoon2/src/blocks/slide/conf/slide-repository.xconf
  
  Index: slide-repository.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/conf/slide-repository.xconf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- slide-repository.xconf	31 Jan 2003 18:08:42 -0000	1.1
  +++ slide-repository.xconf	5 Mar 2003 18:47:59 -0000	1.2
  @@ -1,33 +1,26 @@
   <?xml version="1.0"?>
  -<xconf xpath="/cocoon" unless="component[@role='org.apache.cocoon.components.repository.SourceRepositorySelector']">
  +<xconf xpath="/cocoon" unless="repository">
   
  - <!-- Source repositories:
  -   Each source repository handles serveral sources sorted in namspaces. Which
  -   can be access via the RepositorySourceFactory.
  -   -->
  - <component role="org.apache.cocoon.components.repository.SourceRepositorySelector"

  -            class="org.apache.cocoon.components.ExtendedComponentSelector"
  -            logger="core.repositories"
  -            default="slide">
  +  <!--+ 
  +      | Jakarta Slide repository
  +      |
  +      | The Slide repository handles serveral sources sorted in namspaces.
  +      +-->
  +  <repository logger="core.repositories.slide"
  +              file="context://samples/slide/slide.xconf"/>
   
  -  <!-- Default implementation via Jakarta Slide -->
  -  <component-instance class="org.apache.cocoon.components.repository.impl.SlideRepository"

  -                      name="slide"
  -                      logger="core.repositories.slide"
  -                      file="context://samples/slide/slide.xconf"/>
  - </component>
  +  <!--+
  +      | Principal providers:
  +      | The principal providers handles principals/users, should be used for 
  +      | user management.
  +      +-->
  +  <principal-provider role="org.apache.cocoon.components.repository.PrincipalProviderSelector"

  +                      class="org.apache.cocoon.components.ExtendedComponentSelector"
  +                      logger="core.repositories.principalprovider" default="slide">
   
  - <!-- Principal providers:
  -   The principal providers handles principals/users, they should use for user
  -   management,
  -   -->
  - <component role="org.apache.cocoon.components.repository.PrincipalProviderSelector"

  -            class="org.apache.cocoon.components.ExtendedComponentSelector"
  -            logger="core.repositories.principalprovider" default="slide">
  -
  -  <!-- Default implementation via Jakarta Slide -->
  -  <component-instance class="org.apache.cocoon.components.repository.impl.SlidePrincipalProvider"

  -                      name="slide" logger="core.repositories.principalprovider.slide"
  -                      repository="slide" namespace="myrepository"/>
  - </component>
  +    <!-- Default implementation via Jakarta Slide -->
  +    <component-instance class="org.apache.cocoon.components.repository.impl.SlidePrincipalProvider"

  +                        name="slide" logger="core.repositories.principalprovider.slide"
  +                        namespace="myrepository"/>
  +  </principal-provider>
   </xconf>
  
  
  
  1.2       +4 -6      xml-cocoon2/src/blocks/slide/conf/slide-repository.xroles
  
  Index: slide-repository.xroles
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/conf/slide-repository.xroles,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- slide-repository.xroles	31 Jan 2003 18:08:42 -0000	1.1
  +++ slide-repository.xroles	5 Mar 2003 18:47:59 -0000	1.2
  @@ -1,11 +1,9 @@
   <?xml version="1.0"?>
  -<xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.components.repository.RepositorySelector']">
  +<xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.components.repository.Repository']">
   
  -  <role name="org.apache.cocoon.components.repository.RepositorySelector"
  -        shorthand="repositories"
  -        default-class="org.apache.cocoon.components.ExtendedComponentSelector">
  -    <hint shorthand="slide" class="org.apache.cocoon.components.repository.impl.SlideRepository"/>
  
  -  </role>
  +  <role name="org.apache.cocoon.components.repository.Repository"
  +        shorthand="repository"
  +        default-class="org.apache.cocoon.components.repository.impl.SlideRepository"/>
   
     <role name="org.apache.cocoon.components.repository.PrincipalProviderSelector"
           shorthand="principal-provider"
  
  
  
  1.2       +2 -2      xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/repository/Repository.java
  
  Index: Repository.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/repository/Repository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Repository.java	31 Jan 2003 18:08:43 -0000	1.1
  +++ Repository.java	5 Mar 2003 18:47:59 -0000	1.2
  @@ -66,6 +66,6 @@
   public interface Repository extends Component {
   
       /** Role for the component */
  -    public final static String ROLE = "org.apache.cocoon.components.repository.SourceRepository";
  +    public final static String ROLE = "org.apache.cocoon.components.repository.Repository";
   }
   
  
  
  
  1.3       +4 -15     xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/repository/impl/SlidePrincipalProvider.java
  
  Index: SlidePrincipalProvider.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/repository/impl/SlidePrincipalProvider.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SlidePrincipalProvider.java	31 Jan 2003 22:49:32 -0000	1.2
  +++ SlidePrincipalProvider.java	5 Mar 2003 18:47:59 -0000	1.3
  @@ -130,7 +130,6 @@
       /** Slide token. */
       // private SlideToken slidetoken;
   
  -    private String repository = null;
       private String namespace = null;
   
       /**
  @@ -156,7 +155,6 @@
       public void configure(Configuration configuration)
         throws ConfigurationException {
   
  -        this.repository = configuration.getAttribute("repository", null);
           this.namespace = configuration.getAttribute("namespace", null);
       }
   
  @@ -169,14 +167,10 @@
        */
       public void initialize() throws Exception {
   
  -        ComponentSelector repositories = null;
           Repository repository = null;
   
           try {
  -            repositories = (ComponentSelector) this.manager.lookup(Repository.ROLE+
  -                "Selector");
  -
  -            repository = (Repository) repositories.select(this.repository);
  +            repository = (Repository) this.manager.lookup(Repository.ROLE);
   
               if ( !(repository instanceof SlideRepository)) {
                   getLogger().error("Can't get Slide repository");
  @@ -203,15 +197,10 @@
           } catch (ComponentException ce) {
               getLogger().error("Could not lookup for component.", ce);
           } finally {
  -            if ((repository!=null) && (repository instanceof Component)) {
  -                repositories.release((Component) repository);
  +            if (repository!=null) {
  +                this.manager.release(repository);
               }
               repository = null;
  -
  -            if (repositories!=null) {
  -                this.manager.release(repositories);
  -            }
  -            repositories = null;
           }
       }
   
  
  
  
  1.5       +91 -19    xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/source/impl/SlideSource.java
  
  Index: SlideSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/source/impl/SlideSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SlideSource.java	15 Feb 2003 22:56:25 -0000	1.4
  +++ SlideSource.java	5 Mar 2003 18:47:59 -0000	1.5
  @@ -55,11 +55,16 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  +import java.io.StringReader;
   import java.util.ArrayList;
   import java.util.Date;
   import java.util.Enumeration;
   import java.util.Vector;
   
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
  @@ -81,6 +86,7 @@
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceValidity;
   import org.apache.excalibur.source.impl.validity.TimeStampValidity;
  +import org.apache.excalibur.xml.dom.DOMParser;
   import org.apache.slide.authenticate.CredentialsToken;
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.NamespaceConfig;
  @@ -99,6 +105,9 @@
   import org.apache.slide.structure.Structure;
   import org.apache.slide.structure.SubjectNode;
   
  +import org.w3c.dom.Document;
  +import org.xml.sax.InputSource;
  +
   /**
    * A sources from jakarta slide repositories.
    *
  @@ -106,13 +115,16 @@
    * @version $Id$
    */
   public class SlideSource extends AbstractLogEnabled
  -  implements Contextualizable, Source, ModifiableSource,
  +  implements Contextualizable, Composable, Source, ModifiableSource,
                ModifiableTraversableSource, MoveableSource, RestrictableSource,
                LockableSource, InspectableSource, VersionableSource {
   
       /** Component context */
       private Context context;
   
  +    /** Component manager */
  +    private ComponentManager manager;
  +
       /** Namespace access token. */
       private NamespaceAccessToken nat;
   
  @@ -190,7 +202,7 @@
           this.config = this.nat.getNamespaceConfig();
           this.scheme = scheme;
           this.path = path;
  -        this.uri = scheme+"://"+path;
  +        this.uri = scheme+":/"+path;
   
           this.sourcerevision = sourcerevision;
           this.sourcerevisionbranch = sourcerevisionbranch;
  @@ -217,13 +229,13 @@
   
           } catch (RevisionDescriptorNotFoundException rdnfe) {
   
  -            //getLogger().warn("Could not retrieve revision descriptor", rdnfe);
  +            // getLogger().warn("Could not retrieve revision descriptor", rdnfe);
   
               this.revisionDescriptor = null;
               this.sourcerevision = null;
               this.sourcerevisionbranch = null;
           } catch (ObjectNotFoundException onfe) {
  -            //getLogger().debug("Source doesn't exist", onfe);
  +            // getLogger().debug("Source doesn't exist", onfe);
               // ignore
           } catch (SlideException se) {
               throw new SourceException("Access denied for source '"+this.uri+
  @@ -244,6 +256,18 @@
       }
   
       /**
  +     * Pass the ComponentManager to the composer. The Composable implementation
  +     * should use the specified ComponentManager to acquire the components it needs for
execution
  +     *
  +     * @param manager The ComponentManager which this Composable uses
  +     *
  +     * @throws ComponentException
  +     */
  +    public void compose(ComponentManager manager) throws ComponentException {
  +        this.manager = manager;
  +    }
  +
  +    /**
        * Return an <code>InputStream</code> object to read from the source.
        * This is the data at the point of invocation of this method,
        * so if this is Modifiable, you might get different content
  @@ -537,7 +561,7 @@
   
               } catch (Exception e) {
                   if (e instanceof IOException) {
  -                    throw (IOException)e;
  +                    throw (IOException) e;
                   }
                   throw new CascadingIOException("Could not create source", e);
               } finally {
  @@ -576,7 +600,7 @@
       /**
        * Move the current source to a specified destination.
        *
  -     * @param source     
  +     * @param source
        *
        * @throws SourceException If an exception occurs during
        *                         the move.
  @@ -599,7 +623,7 @@
       /**
        * Copy the current source to a specified destination.
        *
  -     * @param source     
  +     * @param source
        *
        * @throws SourceException If an exception occurs during
        *                         the copy.
  @@ -1574,6 +1598,7 @@
        */
       public void setSourceProperty(SourceProperty sourceproperty)
         throws SourceException {
  +        getLogger().debug("Set source property");
           try {
               revisionDescriptor.setProperty(sourceproperty.getName(),
                                              sourceproperty.getNamespace(),
  @@ -1582,10 +1607,17 @@
               // Last modification date
               revisionDescriptor.setLastModified(new Date());
   
  +            nat.begin();
               content.store(slideToken, this.config.getFilesPath()+this.path,
                             revisionDescriptor, null);
  -        } catch (SlideException se) {
  -            throw new SourceException("Could not set property", se);
  +            nat.commit();
  +        } catch (Exception se) {
  +            try {
  +                nat.rollback();
  +            } catch (Exception rbe) {
  +                getLogger().error("Rollback failed for setting a source property", rbe);
  +            }
  +            throw new SourceException("Could not set source property", se);
           }
       }
   
  @@ -1607,9 +1639,28 @@
               return null;
           }
   
  -        return new SourceProperty(namespace, name,
  -                                  revisionDescriptor.getProperty(name,
  -                                      namespace).getValue().toString());
  +        final String quote = "\"";
  +        NodeProperty np = revisionDescriptor.getProperty(name, namespace);
  +        String pre = "<"+name+" xmlns="+quote+namespace+quote+" >";
  +        String post = "</"+name+" >";
  +
  +        StringReader reader = new StringReader(pre+np.getValue().toString()+
  +                                               post);
  +        InputSource src = new InputSource(reader);
  +
  +        DOMParser parser = null;
  +        Document doc = null;
  +
  +        try {
  +            parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
  +            doc = parser.parseDocument(src);
  +        } catch (Exception e) {
  +            throw new SourceException("Could not parse property", e);
  +        } finally {
  +            this.manager.release((Component) parser);
  +        }
  +
  +        return new SourceProperty(doc.getDocumentElement());
       }
   
       /**
  @@ -1627,13 +1678,34 @@
   
           Vector sourceproperties = new Vector();
   
  -        NodeProperty property;
  +        DOMParser parser = null;
  +        String xml = "";
  +
  +        try {
  +            parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
  +            final String quote = "\"";
  +
  +            for (Enumeration e = revisionDescriptor.enumerateProperties();
  +                e.hasMoreElements(); ) {
  +                NodeProperty property = (NodeProperty) e.nextElement();
  +                String name = property.getName();
  +                String namespace = property.getNamespace();
  +                String pre = "<"+name+" xmlns="+quote+namespace+quote+" >";
  +                String post = "</"+name+" >";
  +
  +                xml = pre+property.getValue().toString()+post;
  +                StringReader reader = new StringReader(xml);
  +
  +                Document doc = parser.parseDocument(new InputSource(reader));
   
  -        for (Enumeration e = revisionDescriptor.enumerateProperties();
  -            e.hasMoreElements(); ) {
  -            property = (NodeProperty) e.nextElement();
  -            sourceproperties.addElement(new SourceProperty(property.getNamespace(),
  -                property.getName(), property.getValue().toString()));
  +                SourceProperty srcProperty = new SourceProperty(doc.getDocumentElement());
  +
  +                sourceproperties.addElement(srcProperty);
  +            }
  +        } catch (Exception e) {
  +            throw new SourceException("Could not parse property "+xml, e);
  +        } finally {
  +            this.manager.release((Component) parser);
           }
   
           SourceProperty[] sourcepropertiesArray = new SourceProperty[sourceproperties.size()];
  
  
  
  1.3       +5 -14     xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/source/impl/SlideSourceFactory.java
  
  Index: SlideSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/java/org/apache/cocoon/components/source/impl/SlideSourceFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SlideSourceFactory.java	31 Jan 2003 22:49:32 -0000	1.2
  +++ SlideSourceFactory.java	5 Mar 2003 18:47:59 -0000	1.3
  @@ -166,14 +166,9 @@
               path = "/";
           }
   
  -        ComponentSelector repositories = null;
           Repository repository = null;
  -
           try {
  -            repositories = (ComponentSelector) this.manager.lookup(Repository.ROLE+
  -                "Selector");
  -
  -            repository = (Repository) repositories.select(repositoryname);
  +            repository = (Repository) this.manager.lookup(Repository.ROLE);
   
               if ( !(repository instanceof SlideRepository)) {
                   getLogger().error("Can't get Slide repository");
  @@ -195,21 +190,17 @@
   
               source.enableLogging(getLogger());
               source.contextualize(this.context);
  +            source.compose(this.manager);
   
               return source;
   
           } catch (ComponentException ce) {
               getLogger().error("Could not lookup for component.", ce);
           } finally {
  -            if ((repository!=null) && (repository instanceof Component)) {
  -                repositories.release((Component) repository);
  +            if (repository!=null) {
  +                this.manager.release(repository);
               }
               repository = null;
  -
  -            if (repositories!=null) {
  -                this.manager.release(repositories);
  -            }
  -            repositories = null;
           }
   
           return null;
  
  
  
  1.6       +1 -1      xml-cocoon2/src/blocks/slide/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/slide/samples/sitemap.xmap,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sitemap.xmap	26 Feb 2003 15:28:32 -0000	1.5
  +++ sitemap.xmap	5 Mar 2003 18:48:00 -0000	1.6
  @@ -128,7 +128,7 @@
   
      <!-- =============  Source description ============= -->
      <map:match pattern="description/*/**">
  -    <map:generate type="sourcedescription" src="slide://{2}?cocoon-source-principal={1}">
  +    <map:generate type="sourcedescription" src="slide:/{2}?cocoon-source-principal={1}">
        <map:parameter name="repository" value="slide"/>
        <map:parameter name="namespace" value="myrepository"/>
        <map:parameter name="properties" value="true"/>
  
  
  

Mime
View raw message