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 2006/02/10 00:14:44 UTC

svn commit: r376480 - in /lenya/trunk/src: java/org/apache/lenya/ modules/repository/java/src/org/apache/lenya/cms/repo/adapter/

Author: andreas
Date: Thu Feb  9 15:14:42 2006
New Revision: 376480

URL: http://svn.apache.org/viewcvs?rev=376480&view=rev
Log:
Added adapter classes from the existing repo implementation to the new repo draft API

Added:
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/DublinCoreElements.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/LenyaElements.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoLenyaMetaData.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaData.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaDataManager.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapper.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapperResolver.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/lenya.roles

Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?rev=376480&r1=376479&r2=376480&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Thu Feb  9 15:14:42 2006
@@ -178,6 +178,7 @@
         shorthand="node-factory"
         default-class="org.apache.lenya.cms.repository.SourceNodeFactory"/>
         <!--
+        default-class="org.apache.lenya.cms.repo.adapter.RepoNodeFactory"/>
         default-class="org.apache.lenya.cms.jcr.JCRNodeFactory"/>
         -->
 

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/DublinCoreElements.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/DublinCoreElements.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/DublinCoreElements.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/DublinCoreElements.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,73 @@
+/*
+ * 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.repo.adapter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.repo.metadata.Element;
+import org.apache.lenya.cms.repo.metadata.impl.ElementImpl;
+
+public class DublinCoreElements {
+
+    public static String ELEMENT_SET = DublinCoreElements.class.getName();
+
+    /**
+     * The dublin core elements.
+     */
+    private static String[] ELEMENTS = { DublinCore.ELEMENT_TITLE, DublinCore.ELEMENT_CREATOR,
+            DublinCore.ELEMENT_SUBJECT, DublinCore.ELEMENT_DESCRIPTION,
+            DublinCore.ELEMENT_PUBLISHER, DublinCore.ELEMENT_CONTRIBUTOR, DublinCore.ELEMENT_DATE,
+            DublinCore.ELEMENT_TYPE, DublinCore.ELEMENT_FORMAT, DublinCore.ELEMENT_IDENTIFIER,
+            DublinCore.ELEMENT_SOURCE, DublinCore.ELEMENT_LANGUAGE, DublinCore.ELEMENT_RELATION,
+            DublinCore.ELEMENT_COVERAGE, DublinCore.ELEMENT_RIGHTS };
+
+    /**
+     * The dublin core terms.
+     */
+    private static String[] TERMS = { DublinCore.TERM_AUDIENCE, DublinCore.TERM_ALTERNATIVE,
+            DublinCore.TERM_TABLEOFCONTENTS, DublinCore.TERM_ABSTRACT, DublinCore.TERM_CREATED,
+            DublinCore.TERM_VALID, DublinCore.TERM_EXTENT, DublinCore.TERM_AVAILABLE,
+            DublinCore.TERM_ISSUED, DublinCore.TERM_MODIFIED, DublinCore.TERM_LICENSE,
+            DublinCore.TERM_MEDIUM, DublinCore.TERM_ISVERSIONOF, DublinCore.TERM_HASVERSION,
+            DublinCore.TERM_ISREPLACEDBY, DublinCore.TERM_REPLACES, DublinCore.TERM_ISREQUIREDBY,
+            DublinCore.TERM_REQUIRES, DublinCore.TERM_ISPARTOF, DublinCore.TERM_HASPART,
+            DublinCore.TERM_ISREFERENCEDBY, DublinCore.TERM_REFERENCES,
+            DublinCore.TERM_RIGHTSHOLDER, DublinCore.TERM_ISFORMATOF, DublinCore.TERM_HASFORMAT,
+            DublinCore.TERM_CONFORMSTO, DublinCore.TERM_SPATIAL, DublinCore.TERM_TEMPORAL,
+            DublinCore.TERM_MEDIATOR, DublinCore.TERM_DATEACCEPTED,
+            DublinCore.TERM_DATECOPYRIGHTED, DublinCore.TERM_DATESUBMITTED,
+            DublinCore.TERM_EDUCATIONLEVEL, DublinCore.TERM_ACCESSRIGHTS,
+            DublinCore.TERM_BIBLIOGRAPHICCITATION };
+
+    /**
+     * Returns a list of all allowed attribute names in this metadata.
+     * @return the list of attribute names
+     */
+    public static Element[] getElements() {
+        List names = new ArrayList();
+        names.addAll(Arrays.asList(ELEMENTS));
+        names.addAll(Arrays.asList(TERMS));
+        Element[] elements = new Element[names.size()];
+        for (int i = 0; i < elements.length; i++) {
+            elements[i] = new ElementImpl((String) names.get(i), true);
+        }
+        return elements;
+    }
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/LenyaElements.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/LenyaElements.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/LenyaElements.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/LenyaElements.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.repo.adapter;
+
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.repo.metadata.Element;
+import org.apache.lenya.cms.repo.metadata.impl.ElementImpl;
+
+public interface LenyaElements {
+
+    String ELEMENT_SET = LenyaElements.class.getName();
+
+    Element[] ELEMENTS = { new ElementImpl(LenyaMetaData.ELEMENT_RESOURCE_TYPE, false),
+            new ElementImpl(LenyaMetaData.ELEMENT_CONTENT_TYPE, false),
+            new ElementImpl(LenyaMetaData.ELEMENT_WORKFLOW_VERSION, true),
+            new ElementImpl(LenyaMetaData.ELEMENT_PLACEHOLDER, false),
+            new ElementImpl(LenyaMetaData.ELEMENTE_HEIGHT, false),
+            new ElementImpl(LenyaMetaData.ELEMENT_WIDTH, false) };
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoLenyaMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoLenyaMetaData.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoLenyaMetaData.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoLenyaMetaData.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.repo.adapter;
+
+import org.apache.lenya.cms.metadata.LenyaMetaData;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.Translation;
+import org.apache.lenya.cms.repo.metadata.MetaData;
+
+public class RepoLenyaMetaData extends RepoMetaData {
+
+    private Translation translation;
+
+    public RepoLenyaMetaData(MetaData metaData, Translation translation) {
+        super(metaData);
+        this.translation = translation;
+    }
+
+    public String getFirstValue(String key) throws DocumentException {
+        if (key.equals(LenyaMetaData.ELEMENT_RESOURCE_TYPE)) {
+            try {
+                return translation.getAsset().getAssetType().getName();
+            } catch (RepositoryException e) {
+                throw new DocumentException(e);
+            }
+        }
+        return super.getFirstValue(key);
+    }
+
+    public String[] getValues(String key) throws DocumentException {
+        if (key.equals(LenyaMetaData.ELEMENT_RESOURCE_TYPE)) {
+            try {
+                return new String[] { translation.getAsset().getAssetType().getName() };
+            } catch (RepositoryException e) {
+                throw new DocumentException(e);
+            }
+        }
+        return super.getValues(key);
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaData.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaData.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaData.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaData.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,118 @@
+/*
+ * 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.repo.adapter;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.metadata.Element;
+
+public class RepoMetaData implements MetaData {
+
+    private org.apache.lenya.cms.repo.metadata.MetaData delegate;
+
+    public RepoMetaData(org.apache.lenya.cms.repo.metadata.MetaData metaData) {
+        this.delegate = metaData;
+    }
+    
+    protected org.apache.lenya.cms.repo.metadata.MetaData getDelegate() {
+        return this.delegate;
+    }
+
+    public void save() throws DocumentException {
+    }
+
+    public String[] getValues(String key) throws DocumentException {
+        try {
+            return delegate.getValues(key);
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public String getFirstValue(String key) throws DocumentException {
+        try {
+            if (delegate.getElementSet().getElement(key).isMultiple()) {
+                String[] values = delegate.getValues(key);
+                return values.length == 0 ? null : values[0];
+            } else {
+                return delegate.getValue(key);
+            }
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public String[] getAvailableKeys() {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void setValue(String key, String value) throws DocumentException {
+        try {
+            if (delegate.getElementSet().getElement(key).isMultiple()) {
+                delegate.clear(key);
+                delegate.addValue(key, value);
+            } else {
+                delegate.setValue(key, value);
+            }
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public void addValue(String key, String value) throws DocumentException {
+        try {
+            delegate.addValue(key, value);
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public void replaceBy(MetaData other) throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public String[] getPossibleKeys() {
+        Element[] elements;
+        try {
+            elements = delegate.getElementSet().getElements();
+        } catch (RepositoryException e) {
+            throw new RuntimeException(e);
+        }
+        String[] names = new String[elements.length];
+        for (int i = 0; i < names.length; i++) {
+            names[i] = elements[i].getName();
+        }
+        return names;
+    }
+
+    public HashMap getAvailableKey2Value() {
+        throw new RuntimeException("not implemented");
+    }
+
+    public boolean isValidAttribute(String key) {
+        return Arrays.asList(getPossibleKeys()).contains(key);
+    }
+
+    public long getLastModified() throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaDataManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaDataManager.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaDataManager.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoMetaDataManager.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,112 @@
+/*
+ * 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.repo.adapter;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.Session;
+import org.apache.lenya.cms.repo.Translation;
+import org.apache.lenya.cms.repo.metadata.Element;
+import org.apache.lenya.cms.repo.metadata.MetaDataOwner;
+import org.apache.lenya.cms.repo.metadata.MetaDataRegistry;
+
+public class RepoMetaDataManager extends MetaDataManager {
+
+    private Session session;
+    private MetaDataOwner owner;
+
+    public RepoMetaDataManager(Session session, MetaDataOwner owner, Logger _logger) {
+        super(null, null, _logger);
+        this.session = session;
+        this.owner = owner;
+    }
+
+    protected void register(String name, Element[] elements) throws DocumentException {
+        try {
+            MetaDataRegistry registry = this.session.getRepository().getMetaDataRegistry();
+            if (!registry.isRegistered(name)) {
+                registry.register(name, elements);
+            }
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public MetaData getCustomMetaData() throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    private RepoMetaData dublinCore = null;
+
+    public MetaData getDublinCoreMetaData() throws DocumentException {
+        try {
+            register(DublinCoreElements.ELEMENT_SET, DublinCoreElements.getElements());
+            if (this.dublinCore == null) {
+                this.dublinCore = new RepoMetaData(this.owner.getMetaData(DublinCoreElements.ELEMENT_SET));
+            }
+            return this.dublinCore;
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    private RepoMetaData lenyaMetaData = null;
+
+    public MetaData getLenyaMetaData() throws DocumentException {
+        register(LenyaElements.ELEMENT_SET, LenyaElements.ELEMENTS);
+        try {
+            if (this.lenyaMetaData == null) {
+                this.lenyaMetaData = new RepoLenyaMetaData(this.owner.getMetaData(LenyaElements.ELEMENT_SET),
+                        (Translation) this.owner);
+            }
+            return this.lenyaMetaData;
+        } catch (RepositoryException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    protected String getSourceURI() {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void replaceMetaData(MetaDataManager sourceManager) throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void setCustomMetaData(Map customMetaDataValues) throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void setDublinCoreMetaData(Map dcMetaDataValues) throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void setLenyaMetaData(Map lenyaMetaDataValues) throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void setMetaData(Map dcMetaData, Map lenyaMetaData, Map customMetaData)
+            throws DocumentException {
+        throw new RuntimeException("not implemented");
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNode.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,169 @@
+/*
+ * 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.repo.adapter;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.lenya.cms.metadata.MetaDataManager;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.repo.Translation;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.transaction.Identifiable;
+
+public class RepoNode extends AbstractLogEnabled implements Node, Identifiable {
+
+    private Translation translation;
+
+    /**
+     * @param url
+     */
+    public RepoNode(Translation trans, Logger logger) {
+        this.translation = trans;
+        ContainerUtil.enableLogging(this, logger);
+    }
+
+    public Translation getTranslation() {
+        return this.translation;
+    }
+
+    public Session getSession() {
+        throw new RuntimeException("not implemented");
+    }
+
+    public boolean exists() throws RepositoryException {
+        return this.translation != null;
+    }
+
+    public boolean isCollection() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public Collection getChildren() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public InputStream getInputStream() throws RepositoryException {
+        try {
+            return getTranslation().getInputStream();
+        } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public OutputStream getOutputStream() throws RepositoryException {
+        try {
+            return getTranslation().getOutputStream();
+        } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public long getLastModified() throws RepositoryException {
+        try {
+            return getTranslation().getLastModified();
+        } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public long getContentLength() throws RepositoryException {
+        try {
+            return getTranslation().getContentLength();
+        } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public String getMimeType() throws RepositoryException {
+        try {
+            return getTranslation().getMimeType();
+        } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public String getSourceURI() {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void lock() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void unlock() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void checkout() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void checkin() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void registerDirty() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public boolean isCheckedOut() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public boolean isCheckedOutByUser() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public boolean isLocked() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    public void registerRemoved() throws RepositoryException {
+        throw new RuntimeException("not implemented");
+    }
+
+    private MetaDataManager metaDataManager;
+
+    public MetaDataManager getMetaDataManager() throws DocumentException {
+        if (this.metaDataManager == null) {
+            org.apache.lenya.cms.repo.Session session;
+            try {
+                session = getTranslation().getAsset()
+                        .getContent()
+                        .getArea()
+                        .getPublication()
+                        .getSession();
+            } catch (org.apache.lenya.cms.repo.RepositoryException e) {
+                throw new DocumentException(e);
+            }
+            this.metaDataManager = new RepoMetaDataManager(session, getTranslation(), getLogger());
+        }
+        return this.metaDataManager;
+    }
+
+    public String getIdentifiableType() {
+        return Node.IDENTIFIABLE_TYPE;
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,123 @@
+/*
+ * 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.repo.adapter;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.lenya.cms.repo.Area;
+import org.apache.lenya.cms.repo.Asset;
+import org.apache.lenya.cms.repo.AssetTypeResolver;
+import org.apache.lenya.cms.repo.Publication;
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.SiteNode;
+import org.apache.lenya.cms.repo.Translation;
+import org.apache.lenya.cms.repo.avalon.RepositoryFactory;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.NodeFactory;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.repository.SourceNode;
+import org.apache.lenya.transaction.Identifiable;
+import org.apache.lenya.transaction.IdentityMap;
+
+/**
+ * Repository node factory.
+ */
+public class RepoNodeFactory extends AbstractLogEnabled implements NodeFactory, Serviceable,
+        Initializable {
+
+    private Session oldSession;
+
+    public void setSession(Session session) {
+        this.oldSession = session;
+    }
+
+    public Identifiable build(IdentityMap map, String key) throws Exception {
+
+        String url = key;
+        String path = url.substring("lenya://lenya/pubs/".length());
+        String pubId = path.split("/")[0];
+
+        path = path.substring((pubId + "/content/").length());
+        String areaId = path.split("/")[0];
+
+        String docPath = path.substring(areaId.length());
+
+        int lastSlashIndex = docPath.lastIndexOf("/");
+        int underscoreIndex = docPath.lastIndexOf("_");
+
+        if (underscoreIndex == -1 || lastSlashIndex > underscoreIndex) {
+            return new SourceNode(this.oldSession, key, this.manager, getLogger());
+        } else {
+
+            try {
+                String language = docPath.substring(underscoreIndex + 1, underscoreIndex + 3);
+
+                docPath = docPath.substring(0, docPath.length() - "/index_de.xml".length());
+
+                Publication pub = this.session.getPublication(pubId);
+                Area area = pub.getArea(areaId);
+
+                Translation trans = null;
+
+                SiteNode siteNode = area.getSite().getNode(docPath);
+                if (siteNode != null) {
+                    Asset asset = siteNode.getAsset();
+                    if (asset != null) {
+                        trans = asset.getTranslation(language);
+                    }
+                }
+                return new RepoNode(trans, getLogger());
+            } catch (RepositoryException e) {
+                throw new RepositoryException("Error resolving translation for URL [" + key + "]: "
+                        + e.getMessage(), e);
+            }
+        }
+    }
+
+    public String getType() {
+        return Node.IDENTIFIABLE_TYPE;
+    }
+
+    private ServiceManager manager;
+    private org.apache.lenya.cms.repo.Session session;
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+    public void initialize() throws Exception {
+        RepositoryFactory factory = null;
+        try {
+            factory = (RepositoryFactory) manager.lookup(RepositoryFactory.ROLE);
+            Repository repository = factory.getRepository();
+            AssetTypeResolver resolver = new ResourceTypeWrapperResolver(this.manager);
+            repository.setAssetTypeResolver(resolver);
+            this.session = repository.createSession();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (factory != null) {
+                manager.release(factory);
+            }
+        }
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapper.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapper.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapper.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,43 @@
+/*
+ * 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.repo.adapter;
+
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.repo.AssetType;
+import org.apache.lenya.xml.Schema;
+
+public class ResourceTypeWrapper implements AssetType {
+
+    private ResourceType delegate;
+    
+    public ResourceTypeWrapper(ResourceType type) {
+        this.delegate = type;
+    }
+    
+    public String getName() {
+        return delegate.getName();
+    }
+
+    public Schema getSchema() {
+        return delegate.getSchema();
+    }
+
+    public boolean isValidating() {
+        return delegate.getSchema() != null;
+    }
+
+}

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapperResolver.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapperResolver.java?rev=376480&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapperResolver.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/ResourceTypeWrapperResolver.java Thu Feb  9 15:14:42 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.repo.adapter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.repo.AssetType;
+import org.apache.lenya.cms.repo.AssetTypeResolver;
+import org.apache.lenya.cms.repo.RepositoryException;
+
+public class ResourceTypeWrapperResolver implements AssetTypeResolver {
+
+    private ServiceManager manager;
+
+    public ResourceTypeWrapperResolver(ServiceManager manager) {
+        this.manager = manager;
+    }
+
+    private Map types = new HashMap();
+
+    public AssetType resolve(String name) throws RepositoryException {
+        if (!types.containsKey(name)) {
+            ServiceSelector selector = null;
+            try {
+                selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
+                ResourceType type = (ResourceType) selector.select(name);
+                AssetType assetType = new ResourceTypeWrapper(type);
+                this.types.put(name, assetType);
+            } catch (Exception e) {
+                throw new RepositoryException(e);
+            }
+        }
+        return (AssetType) types.get(name);
+    }
+
+    public boolean canResolve(String name) throws RepositoryException {
+        if (types.containsKey(name)) {
+            return true;
+        } else {
+            ServiceSelector selector = null;
+            try {
+                selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
+                return selector.isSelectable(name);
+            } catch (Exception e) {
+                throw new RepositoryException(e);
+            }
+        }
+    }
+
+}



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