You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/08/05 13:49:10 UTC

svn commit: r230447 - in /lenya/trunk/src/java/org/apache/lenya/cms: jcr/ jcr/metadata/ jcr/usecases/ metadata/ metadata/dublincore/ publication/ workflow/

Author: andreas
Date: Fri Aug  5 04:48:56 2005
New Revision: 230447

URL: http://svn.apache.org/viewcvs?rev=230447&view=rev
Log:
JCR: store meta data as JCR properties. This required to change the return type of MetaDataManager methods to the MetaData interface.

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaJCRSourceFactory.java
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaDataManager.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaRepository.java
    lenya/trunk/src/java/org/apache/lenya/cms/jcr/usecases/Import.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaJCRSourceFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaJCRSourceFactory.java?rev=230447&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaJCRSourceFactory.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaJCRSourceFactory.java Fri Aug  5 04:48:56 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.cocoon.jcr.source.JCRSourceFactory;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+
+public class LenyaJCRSourceFactory extends JCRSourceFactory {
+
+    public Node createFileNode(Node folderNode, String name) throws RepositoryException {
+        Node node = super.createFileNode(folderNode, name);
+        String prefix = node.getSession().getNamespacePrefix(LenyaMetaData.NAMESPACE);
+        if (!prefix.equals("")) {
+            prefix = prefix + ":";
+        }
+        
+        node.addMixin(prefix + LenyaRepository.CONTENT_NODE);
+        return node;
+    }
+/*
+    public Node createContentNode(Node fileNode) throws RepositoryException {
+        Node node = super.createContentNode(fileNode);
+        
+        String prefix = node.getSession().getNamespacePrefix(LenyaMetaData.NAMESPACE);
+        if (!prefix.equals("")) {
+            prefix = prefix + ":";
+        }
+        
+        node.addMixin(prefix + LenyaRepository.CONTENT_NODE);
+        return node;
+    }
+*/
+}

Modified: lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaRepository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaRepository.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaRepository.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/jcr/LenyaRepository.java Fri Aug  5 04:48:56 2005
@@ -16,32 +16,72 @@
  */
 package org.apache.lenya.cms.jcr;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import javax.jcr.AccessDeniedException;
 import javax.jcr.LoginException;
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
 import org.apache.cocoon.jcr.JackrabbitRepository;
+import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.nodetype.PropDefImpl;
+import org.apache.jackrabbit.name.QName;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
 
 /**
  * Lenya-specific repository implementation.
  */
 public class LenyaRepository extends JackrabbitRepository {
-    
+
+    protected static final String CONTENT_NODE = "contentNode";
+
     protected static final String SESSION_ATTRIBUTE = javax.jcr.Session.class.getName();
-    
+
+    private Map namespaces = new HashMap();
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        super.configure(config);
+
+        Configuration[] namespaceConfigs = config.getChildren("namespace");
+        for (int i = 0; i < namespaceConfigs.length; i++) {
+            String prefix = namespaceConfigs[i].getAttribute("prefix");
+            String uri = namespaceConfigs[i].getAttribute("uri");
+            this.namespaces.put(prefix, uri);
+        }
+    }
+
     /**
      * @see javax.jcr.Repository#login()
      */
-    public javax.jcr.Session login() throws LoginException, NoSuchWorkspaceException, RepositoryException {
-        
+    public javax.jcr.Session login() throws LoginException, NoSuchWorkspaceException,
+            RepositoryException {
+
         javax.jcr.Session jcrSession = null;
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
         Request request = ObjectModelHelper.getRequest(objectModel);
         Session session = request.getSession(false);
@@ -50,10 +90,81 @@
             if (jcrSession == null) {
                 jcrSession = super.login();
                 session.setAttribute(SESSION_ATTRIBUTE, jcrSession);
+
+                registerNamespaces(jcrSession);
+                try {
+                    registerNodeTypes(jcrSession);
+                } catch (InvalidNodeTypeDefException e) {
+                    throw new RepositoryException(e);
+                }
             }
         }
-        
+
         return jcrSession;
+    }
+
+    /**
+     * Registers the Lenya-specific namespaces at the JCR workspace.
+     * @param jcrSession The JCR session.
+     * @throws RepositoryException if an error occurs.
+     * @throws NamespaceException if an error occurs.
+     * @throws UnsupportedRepositoryOperationException if an error occurs.
+     * @throws AccessDeniedException if an error occurs.
+     */
+    protected void registerNamespaces(javax.jcr.Session jcrSession) throws RepositoryException,
+            NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException {
+        for (Iterator i = this.namespaces.keySet().iterator(); i.hasNext();) {
+            String prefix = (String) i.next();
+            String uri = (String) this.namespaces.get(prefix);
+            NamespaceRegistry registry = jcrSession.getWorkspace().getNamespaceRegistry();
+            if (!Arrays.asList(registry.getPrefixes()).contains(prefix)) {
+                registry.registerNamespace(prefix, uri);
+            }
+        }
+    }
+
+    protected void registerNodeTypes(javax.jcr.Session jcrSession) throws RepositoryException,
+            InvalidNodeTypeDefException {
+
+        NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) jcrSession.getWorkspace()
+                .getNodeTypeManager();
+        NodeTypeRegistry registry = nodeTypeManager.getNodeTypeRegistry();
+        if (!registry.isRegistered(new QName(LenyaMetaData.NAMESPACE, CONTENT_NODE))) {
+
+            List propDefs = new ArrayList();
+            Map key2namespace = new HashMap();
+
+            String[] lenyaKeys = LenyaMetaData.ELEMENTS;
+            for (int i = 0; i < lenyaKeys.length; i++) {
+                key2namespace.put(lenyaKeys[i], LenyaMetaData.NAMESPACE);
+            }
+
+            List dcKeyList = DublinCoreImpl.getAttributeNames();
+            String[] dcKeys = (String[]) dcKeyList.toArray(new String[dcKeyList.size()]);
+            for (int i = 0; i < dcKeys.length; i++) {
+                key2namespace.put(dcKeys[i], DublinCoreImpl.DC_NAMESPACE);
+            }
+
+            NodeTypeDef def = new NodeTypeDef();
+            def.setMixin(true);
+            def.setName(new QName(LenyaMetaData.NAMESPACE, CONTENT_NODE));
+
+            for (Iterator i = key2namespace.keySet().iterator(); i.hasNext();) {
+                String key = (String) i.next();
+                String namespace = (String) key2namespace.get(key);
+                PropDefImpl propDef = new PropDefImpl();
+                propDef.setDeclaringNodeType(def.getName());
+                propDef.setName(new QName(namespace, key));
+                propDef.setMandatory(false);
+                propDef.setRequiredType(PropertyType.STRING);
+                propDef.setMultiple(true);
+                propDefs.add(propDef);
+            }
+
+            def.setPropertyDefs((PropDef[]) propDefs.toArray(new PropDef[propDefs.size()]));
+
+            registry.registerNodeType(def);
+        }
     }
 
 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java?rev=230447&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java Fri Aug  5 04:48:56 2005
@@ -0,0 +1,192 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr.metadata;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Value;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.jcr.source.JCRNodeSource;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * JCR based meta data.
+ */
+public class JCRMetaData extends AbstractLogEnabled implements MetaData {
+
+    private String namespace;
+    private String sourceUri;
+    protected ServiceManager manager;
+
+    private Map key2values = null;
+
+    public JCRMetaData(String namespace, String sourceUri, ServiceManager manager, Logger logger) {
+        this.namespace = namespace;
+        this.sourceUri = sourceUri;
+        this.manager = manager;
+        ContainerUtil.enableLogging(this, logger);
+    }
+
+    protected Map getKey2Values() {
+        if (this.key2values == null) {
+            load();
+        }
+        return this.key2values;
+    }
+
+    protected void load() {
+
+        this.key2values = new HashMap();
+        SourceResolver resolver = null;
+        JCRNodeSource source = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            source = (JCRNodeSource) resolver.resolveURI(this.sourceUri);
+
+            Node node = source.getNode();
+            String prefix = node.getSession()
+                    .getWorkspace()
+                    .getNamespaceRegistry()
+                    .getPrefix(this.namespace);
+            if (!prefix.equals("")) {
+                prefix = prefix + ":";
+            }
+
+            String possibleKeys[] = getPossibleKeys();
+            for (int i = 0; i < possibleKeys.length; i++) {
+                String key = prefix + possibleKeys[i];
+                if (node.hasProperty(key)) {
+                    Property property = node.getProperty(key);
+                    Value[] values = property.getValues();
+                    String[] stringValues = new String[values.length];
+                    for (int v = 0; v < values.length; v++) {
+                        stringValues[v] = values[v].getString();
+                    }
+                    this.key2values.put(possibleKeys[i], stringValues);
+                }
+            }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (resolver != null) {
+                if (source != null) {
+                    resolver.release(source);
+                }
+                this.manager.release(resolver);
+            }
+        }
+    }
+
+    public void save() throws DocumentException {
+        SourceResolver resolver = null;
+        JCRNodeSource source = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            source = (JCRNodeSource) resolver.resolveURI(this.sourceUri);
+
+            Node node = source.getNode();
+            String prefix = node.getSession()
+                    .getWorkspace()
+                    .getNamespaceRegistry()
+                    .getPrefix(this.namespace);
+            if (!prefix.equals("")) {
+                prefix = prefix + ":";
+            }
+
+            String possibleKeys[] = getPossibleKeys();
+            for (int i = 0; i < possibleKeys.length; i++) {
+                String[] stringValues = (String[]) getKey2Values().get(possibleKeys[i]);
+                String key = prefix + possibleKeys[i];
+                node.setProperty(key, stringValues);
+            }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (resolver != null) {
+                if (source != null) {
+                    resolver.release(source);
+                }
+                this.manager.release(resolver);
+            }
+        }
+    }
+
+    public String[] getValues(String key) throws DocumentException {
+        return (String[]) getKey2Values().get(key);
+    }
+
+    public String getFirstValue(String key) throws DocumentException {
+        String value = null;
+        String[] values = (String[]) getKey2Values().get(key);
+        if (values.length > 0) {
+            value = values[0];
+        }
+        return value;
+    }
+
+    public void setValue(String key, String value) throws DocumentException {
+        String[] values = { value };
+        getKey2Values().put(key, values);
+    }
+
+    public void addValue(String key, String value) throws DocumentException {
+        String[] values = (String[]) getKey2Values().get(key);
+        List valueList = Arrays.asList(values);
+        valueList.add(value);
+        values = (String[]) valueList.toArray(new String[valueList.size()]);
+        getKey2Values().put(key, values);
+    }
+
+    public void replaceBy(MetaData other) throws DocumentException {
+        this.key2values = new HashMap();
+        String[] keys = getPossibleKeys();
+        for (int i = 0; i < keys.length; i++) {
+            String[] values = other.getValues(keys[i]);
+            this.key2values.put(keys[i], values);
+        }
+        save();
+    }
+
+    private String[] possibleKeys = new String[0];
+
+    public void setPossibleKeys(String[] keys) {
+        this.possibleKeys = keys;
+    }
+
+    public String[] getPossibleKeys() {
+        return this.possibleKeys;
+    }
+
+    public boolean isValidAttribute(String key) {
+        String[] keys = getPossibleKeys();
+        return Arrays.asList(keys).contains(key);
+    }
+
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaDataManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaDataManager.java?rev=230447&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaDataManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/jcr/metadata/JCRMetaDataManager.java Fri Aug  5 04:48:56 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr.metadata;
+
+import java.util.List;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.metadata.CustomMetaData;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
+import org.apache.lenya.cms.publication.DocumentException;
+
+/**
+ * JCR based meta data manager.
+ */
+public class JCRMetaDataManager extends MetaDataManager {
+
+    private JCRMetaData customMetaData, lenyaMetaData, dublinCore;
+
+    /**
+     * @param _sourceUri The source URI.
+     * @param _serviceManager The service manager.
+     * @param _logger The logger.
+     */
+    public JCRMetaDataManager(String _sourceUri, ServiceManager _serviceManager, Logger _logger) {
+        super(_sourceUri, _serviceManager, _logger);
+    }
+
+    public MetaData getCustomMetaData() throws DocumentException {
+        if (this.customMetaData == null) {
+            this.customMetaData = new JCRMetaData(CustomMetaData.NAMESPACE,
+                    getSourceURI(),
+                    this.serviceManager,
+                    getLogger());
+        }
+        return this.customMetaData;
+    }
+
+    public MetaData getDublinCoreMetaData() throws DocumentException {
+        if (this.dublinCore == null) {
+            this.dublinCore = new JCRMetaData(DublinCoreImpl.DC_NAMESPACE,
+                    getSourceURI(),
+                    this.serviceManager,
+                    getLogger());
+            List names  = DublinCoreImpl.getAttributeNames();
+            String[] array = (String[]) names.toArray(new String[names.size()]);
+            this.dublinCore.setPossibleKeys(array);
+        }
+        return this.dublinCore;
+    }
+
+    public MetaData getLenyaMetaData() throws DocumentException {
+        if (this.lenyaMetaData == null) {
+            this.lenyaMetaData = new JCRMetaData(LenyaMetaData.NAMESPACE,
+                    getSourceURI(),
+                    this.serviceManager,
+                    getLogger());
+            this.lenyaMetaData.setPossibleKeys(LenyaMetaData.ELEMENTS);
+        }
+        return this.lenyaMetaData;
+    }
+
+}

Modified: lenya/trunk/src/java/org/apache/lenya/cms/jcr/usecases/Import.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/jcr/usecases/Import.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/jcr/usecases/Import.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/jcr/usecases/Import.java Fri Aug  5 04:48:56 2005
@@ -18,13 +18,17 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.jcr.metadata.JCRMetaDataManager;
+import org.apache.lenya.cms.metadata.MetaDataManager;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.cms.publication.Publication;
@@ -65,12 +69,14 @@
         try {
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
             Source context = resolver.resolveURI("context://");
-            String contextPath = org.apache.excalibur.source.SourceUtil.getFile(context).getAbsolutePath();
+            String contextPath = org.apache.excalibur.source.SourceUtil.getFile(context)
+                    .getAbsolutePath();
             Publication pub = factory.getPublication(pubId, contextPath);
             selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
             siteManager = (SiteManager) selector.select(pub.getSiteManagerHint());
 
             List nodes = new ArrayList();
+            Map uri2meta = new HashMap();
 
             String[] areas = { Publication.AUTHORING_AREA, Publication.LIVE_AREA,
                     Publication.TRASH_AREA, Publication.ARCHIVE_AREA };
@@ -78,16 +84,25 @@
                 Document[] docs = siteManager.getDocuments(map, pub, areas[i]);
                 for (int j = 0; j < docs.length; j++) {
                     nodes.addAll(Arrays.asList(docs[j].getRepositoryNodes()));
+                    uri2meta.put(docs[j].getSourceURI(), docs[j].getMetaDataManager());
                 }
                 nodes.add(siteManager.getSiteStructure(map, pub, areas[i]).getRepositoryNode());
             }
-            
-            for (Iterator i = nodes.iterator(); i.hasNext(); ) {
+
+            for (Iterator i = nodes.iterator(); i.hasNext();) {
                 Node node = (Node) i.next();
                 final String lenyaUri = node.getSourceURI();
                 final String sourcePath = lenyaUri.substring("lenya://".length());
                 final String jcrUri = "jcr://" + sourcePath;
                 SourceUtil.copy(resolver, lenyaUri, jcrUri);
+
+                MetaDataManager sourceMgr = (MetaDataManager) uri2meta.get(lenyaUri);
+                if (sourceMgr != null) {
+                    MetaDataManager jcrMgr = new JCRMetaDataManager(jcrUri,
+                            this.manager,
+                            getLogger());
+                    jcrMgr.replaceMetaData(sourceMgr);
+                }
             }
 
         } finally {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/CustomMetaData.java Fri Aug  5 04:48:56 2005
@@ -40,7 +40,7 @@
 
     private static final String LOCAL_META = "custom";
 
-    private static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
+    public static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
     private static final String PREFIX = "lenya";
 
     /**

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java Fri Aug  5 04:48:56 2005
@@ -31,7 +31,7 @@
 
     private static final String LOCAL_META = "internal";
 
-    private static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
+    public static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
     private static final String PREFIX = "lenya";
 
     /**
@@ -60,7 +60,7 @@
      */
     public static final String ELEMENT_PLACEHOLDER = "placeholder";
 
-    static final String[] ELEMENTS = {
+    public static final String[] ELEMENTS = {
        ELEMENT_RESOURCE_TYPE,
        ELEMENT_CONTENT_TYPE,
        ELEMENT_WORKFLOW_VERSION,

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/MetaDataManager.java Fri Aug  5 04:48:56 2005
@@ -33,7 +33,7 @@
 public class MetaDataManager extends AbstractLogEnabled {
     
     private String sourceUri;
-    private ServiceManager serviceManager;
+    protected ServiceManager serviceManager;
 
     private DublinCoreImpl dublinCoreMetaData;
     private LenyaMetaData lenyaMetaData;
@@ -53,7 +53,7 @@
      * @return the dublin core meta-data
      * @throws DocumentException if the meta-data could not be retrieved
      */
-    public DublinCoreImpl getDublinCoreMetaData() throws DocumentException {
+    public MetaData getDublinCoreMetaData() throws DocumentException {
         if (dublinCoreMetaData == null) {
             dublinCoreMetaData = new DublinCoreImpl(this.sourceUri, this.serviceManager, getLogger());
         }
@@ -75,7 +75,7 @@
      * @return the Lenya meta-data
      * @throws DocumentException if the meta-data could not be retrieved
      */
-    public LenyaMetaData getLenyaMetaData() throws DocumentException {
+    public MetaData getLenyaMetaData() throws DocumentException {
         if (lenyaMetaData == null) {
             lenyaMetaData = new LenyaMetaData(this.sourceUri, this.serviceManager, getLogger());
         }
@@ -97,7 +97,7 @@
      * @return the custom meta-data
      * @throws DocumentException if the meta-data could not be retrieved
      */
-    public CustomMetaData getCustomMetaData() throws DocumentException {
+    public MetaData getCustomMetaData() throws DocumentException {
         if (customMetaData == null) {
             customMetaData = new CustomMetaData(this.sourceUri, this.serviceManager, getLogger());
         }
@@ -153,5 +153,9 @@
         source = sourceManager.getCustomMetaData();
         dest = this.getCustomMetaData();
         dest.replaceBy(source);
+    }
+    
+    protected String getSourceURI() {
+        return this.sourceUri;
     }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java Fri Aug  5 04:48:56 2005
@@ -35,8 +35,8 @@
 
     private static final String LOCAL_META = "dc";
 
-    private static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
-    private static final String DC_PREFIX = "dc";
+    public static final String DC_NAMESPACE = "http://purl.org/dc/elements/1.1/";
+    public static final String DC_PREFIX = "dc";
 
     /**
      * The dublin core elements.
@@ -58,8 +58,8 @@
             DublinCore.ELEMENT_COVERAGE, 
             DublinCore.ELEMENT_RIGHTS };
 
-    private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
-    private static final String DCTERMS_PREFIX = "dcterms";
+    public static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
+    public static final String DCTERMS_PREFIX = "dcterms";
 
     /**
      * The dublin core terms.

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Fri Aug  5 04:48:56 2005
@@ -30,10 +30,13 @@
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.cocoon.source.RepositorySource;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.jcr.JCRSourceNode;
+import org.apache.lenya.cms.jcr.metadata.JCRMetaDataManager;
 import org.apache.lenya.cms.metadata.LenyaMetaData;
 import org.apache.lenya.cms.metadata.MetaDataManager;
 import org.apache.lenya.cms.publication.util.DocumentVisitor;
 import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.SourceNode;
 import org.apache.lenya.cms.site.SiteManager;
 
 /**
@@ -378,7 +381,31 @@
      */
     public MetaDataManager getMetaDataManager() {
         if (this.metaDataManager == null) {
-            metaDataManager = new MetaDataManager(getMetaSourceURI(), this.manager, getLogger());
+            SourceResolver resolver = null;
+            RepositorySource source = null;
+            try {
+                resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+                source = (RepositorySource) resolver.resolveURI(getSourceURI());
+                Node node = source.getNode();
+                if (node instanceof JCRSourceNode) {
+                    String path = getSourceURI().substring(SourceNode.LENYA_PROTOCOL.length());
+                    String jcrUri = "jcr://" + path;
+                    this.metaDataManager = new JCRMetaDataManager(jcrUri, this.manager, getLogger());
+                }
+                else {
+                    this.metaDataManager = new MetaDataManager(getMetaSourceURI(), this.manager, getLogger());
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            finally {
+                if (resolver != null) {
+                    if (source != null) {
+                        resolver.release(source);
+                    }
+                    this.manager.release(resolver);
+                }
+            }
         }
         return metaDataManager;
     }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java?rev=230447&r1=230446&r2=230447&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java Fri Aug  5 04:48:56 2005
@@ -26,6 +26,7 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.metadata.MetaData;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.ResourceType;
@@ -77,7 +78,7 @@
     public Version[] getVersions() {
         if (this.versions == null) {
             try {
-                LenyaMetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
+                MetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
 
                 String[] versionStrings = meta.getValues(LenyaMetaData.ELEMENT_WORKFLOW_VERSION);
                 this.versions = new Version[versionStrings.length];
@@ -125,7 +126,7 @@
 
         String string = number + " " + encodeVersion(workflow, version, (LenyaSituation) situation);
         try {
-            LenyaMetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
+            MetaData meta = this.document.getMetaDataManager().getLenyaMetaData();
             meta.addValue(LenyaMetaData.ELEMENT_WORKFLOW_VERSION, string);
             meta.save();
         } catch (DocumentException e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org