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/09 23:48:03 UTC

svn commit: r376471 - in /lenya/trunk/src: java/org/apache/lenya/cms/migration/ modules/jcr/java/src/org/apache/lenya/cms/jcr/ modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/ modules/repository/java/test/org/apache/lenya/cms/jcr/ modules/reposit...

Author: andreas
Date: Thu Feb  9 14:48:00 2006
New Revision: 376471

URL: http://svn.apache.org/viewcvs?rev=376471&view=rev
Log:
Fixed some bugs in JCR-based repo implementation

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AssetProxy.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/PropertyPathElement.java
    lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java
    lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/mock/AssetTypeResolverImpl.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java?rev=376471&r1=376470&r2=376471&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java Thu Feb  9 14:48:00 2006
@@ -18,7 +18,10 @@
 
 import java.io.File;
 import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import javax.xml.transform.Result;
@@ -32,7 +35,6 @@
 import org.apache.lenya.cms.metadata.LenyaMetaData;
 import org.apache.lenya.cms.repo.Area;
 import org.apache.lenya.cms.repo.Asset;
-import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.AssetType;
 import org.apache.lenya.cms.repo.Publication;
 import org.apache.lenya.cms.repo.Repository;
@@ -40,6 +42,7 @@
 import org.apache.lenya.cms.repo.RepositoryManager;
 import org.apache.lenya.cms.repo.Session;
 import org.apache.lenya.cms.repo.SiteNode;
+import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.impl.AssetTypeImpl;
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
@@ -124,6 +127,8 @@
         try {
             this.repo = RepositoryManager.getRepository(getWebappDirectory(),
                     getRepositoryFactory());
+            repo.setAssetTypeResolver(new AssetTypeResolverImpl());
+
             this.session = this.repo.createSession();
 
             File publicationsDirectory = new File(webappDirectory, PUBLICATION_PREFIX);
@@ -224,7 +229,7 @@
             String resourceType = DocumentHelper.getSimpleElementText(resourceTypeElement);
             AssetType doctype;
 
-            AssetTypeResolverImpl resolver = new AssetTypeResolverImpl();
+            AssetTypeResolverImpl resolver = (AssetTypeResolverImpl) repo.getAssetTypeResolver();
             if (!resolver.canResolve(resourceType)) {
                 doctype = new AssetTypeImpl(resourceType, null, false);
                 resolver.register(doctype);
@@ -254,7 +259,7 @@
             }
 
             importDocuments(docDir, contentNode);
-            
+
             if (siteNode != null) {
                 importChildren(docDir, area, siteNode);
             }
@@ -282,6 +287,14 @@
         Translation document = contentNode.addTranslation(language, "Label", "application/xml");
 
         OutputStream out = document.getOutputStream();
+        FileInputStream in;
+        try {
+            in = new FileInputStream(file);
+        } catch (FileNotFoundException e) {
+            throw new RepositoryException(e);
+        }
+        copy(in, out);
+        /*
         try {
             Transformer transformer = TransformerFactory.newInstance().newTransformer();
             Source source = new StreamSource(file);
@@ -296,6 +309,33 @@
                 } catch (IOException e) {
                     throw new RepositoryException(e);
                 }
+            }
+        }
+        */
+    }
+
+    static void copy(InputStream fis, OutputStream fos) {
+        try {
+            byte buffer[] = new byte[0xffff];
+            int nbytes;
+
+            while ((nbytes = fis.read(buffer)) != -1)
+                fos.write(buffer, 0, nbytes);
+        } catch (IOException e) {
+            System.out.println(e);
+        } finally {
+            if (fis != null)
+                try {
+                    fis.close();
+                } catch (IOException e) {
+                    System.out.println(e);
+                }
+
+            try {
+                if (fos != null)
+                    fos.close();
+            } catch (IOException e) {
+                System.out.println(e);
             }
         }
     }

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AssetProxy.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AssetProxy.java?rev=376471&r1=376470&r2=376471&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AssetProxy.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AssetProxy.java Thu Feb  9 14:48:00 2006
@@ -18,10 +18,12 @@
 
 import org.apache.lenya.cms.jcr.mapping.AbstractNodeProxy;
 import org.apache.lenya.cms.jcr.mapping.NamePathElement;
+import org.apache.lenya.cms.jcr.mapping.NodeProxy;
 import org.apache.lenya.cms.jcr.mapping.Path;
 import org.apache.lenya.cms.jcr.mapping.PathElement;
 import org.apache.lenya.cms.jcr.metadata.MetaDataProxy;
 import org.apache.lenya.cms.repo.Asset;
+import org.apache.lenya.cms.repo.AssetTypeResolver;
 import org.apache.lenya.cms.repo.Content;
 import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.AssetType;
@@ -40,10 +42,13 @@
     protected static final String VISIBLE_IN_NAV_PROPERTY = "lenya:visibleInNav";
 
     public Translation[] getTranslations() throws RepositoryException {
-        ContentProxy contentProxy = (ContentProxy) getParentProxy();
-        Path path = contentProxy.getAbsolutePath()
-                .append(new NamePathElement(TranslationProxy.NODE_NAME));
-        return (Translation[]) getRepository().getProxies(path);
+        Path path = getAbsolutePath().append(new NamePathElement(TranslationProxy.NODE_NAME));
+        NodeProxy[] proxies = getRepository().getProxies(path);
+        Translation[] translations = new Translation[proxies.length];
+        for (int i = 0; i < proxies.length; i++) {
+            translations[i] = (Translation) proxies[i];
+        }
+        return translations;
     }
 
     public Translation addTranslation(String language, String label, String mimeType)
@@ -67,8 +72,7 @@
     }
 
     public void removeTranslation(Translation document) throws RepositoryException {
-        // TODO Auto-generated method stub
-
+        ((TranslationProxy) document).remove();
     }
 
     public Translation getTranslation(String language) throws RepositoryException {
@@ -78,7 +82,11 @@
 
     public AssetType getAssetType() throws RepositoryException {
         String name = getPropertyString(DOCUMENT_TYPE_PROPERTY);
-        return getRepository().getAssetTypeResolver().resolve(name);
+        AssetTypeResolver resolver = getRepository().getAssetTypeResolver();
+        if (resolver == null) {
+            throw new RepositoryException("The asset type resolver of the repository is not set.");
+        }
+        return resolver.resolve(name);
     }
 
     public String getAssetId() throws RepositoryException {

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/PropertyPathElement.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/PropertyPathElement.java?rev=376471&r1=376470&r2=376471&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/PropertyPathElement.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/mapping/PropertyPathElement.java Thu Feb  9 14:48:00 2006
@@ -74,14 +74,15 @@
                     if (node == null) {
                         node = aNode;
                     } else {
-                        throw new RepositoryException("More than 1 node [" + this + "] exists!");
+                        throw new RepositoryException("More than 1 node [" + parent.getPath()
+                                + this + "] exists!");
                     }
                 }
             }
             if (node == null) {
                 String workspace = parent.getSession().getWorkspace().getName();
-                throw new RepositoryException("Node [" + this + "] does not exist in area ["
-                        + workspace + "]!");
+                throw new RepositoryException("Node [" + parent.getPath() + this
+                        + "] does not exist in area [" + workspace + "]!");
             }
             return node;
         } catch (javax.jcr.RepositoryException e) {

Modified: lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java?rev=376471&r1=376470&r2=376471&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java (original)
+++ lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java Thu Feb  9 14:48:00 2006
@@ -170,6 +170,12 @@
 
     protected void doTestTranslation(Asset asset) throws Exception {
         Translation trans = asset.addTranslation(LANGUAGE_DE, "hello", "application/xml");
+        assertTrue(asset.getTranslations().length == 1);
+        
+        asset.removeTranslation(trans);
+        assertTrue(asset.getTranslations().length == 0);
+        
+        trans = asset.addTranslation(LANGUAGE_DE, "hello", "application/xml");
 
         String validXmlResource = "valid.xml";
         String invalidXmlResource = "invalid.xml";

Modified: lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/mock/AssetTypeResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/mock/AssetTypeResolverImpl.java?rev=376471&r1=376470&r2=376471&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/mock/AssetTypeResolverImpl.java (original)
+++ lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/jcr/mock/AssetTypeResolverImpl.java Thu Feb  9 14:48:00 2006
@@ -38,6 +38,9 @@
     }
     
     public AssetType resolve(String name) throws RepositoryException {
+        if (!types.containsKey(name)) {
+            throw new RepositoryException("The asset type [" + name + "] is not registered!");
+        }
         return (AssetType) types.get(name);
     }
 



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