Author: marijan
Date: Thu Aug 30 20:34:58 2012
New Revision: 1379125

URL: http://svn.apache.org/viewvc?rev=1379125&view=rev
Log:
RAVE-695 Create new rave-jcr-ocm module providing JCR based Object Content 
Mapping (OCM) support

- remove util class
- add binary wiring

Added:
    rave/sandbox/content-services/rave-jcr-utils/src/test/
    rave/sandbox/content-services/rave-jcr-utils/src/test/java/
    rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/
    rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/
    rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/
    
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/
    
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/
    
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java
   (contents, props changed)
      - copied, changed from r1379124, 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/util/DataUtilsTest.java
    
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
   (with props)
Removed:
    
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/util/DataUtilsTest.java
Modified:
    
rave/sandbox/content-services/rave-jcr-integration/data-model/src/main/java/org/apache/rave/jcr/data/util/DataUtils.java
    
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/mapping/DefaultDocumentManagerTest.java
    rave/sandbox/content-services/rave-jcr-utils/pom.xml
    
rave/sandbox/content-services/rave-jcr-utils/src/main/java/org/apache/rave/jcr/utils/JcrUtils.java
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/resource/BinaryResourceView.java
    
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BinaryRepositoryControllerTest.java
    
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/JcrRepositoryResourceLoaderTest.java

Modified: 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/main/java/org/apache/rave/jcr/data/util/DataUtils.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/data-model/src/main/java/org/apache/rave/jcr/data/util/DataUtils.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/main/java/org/apache/rave/jcr/data/util/DataUtils.java
 (original)
+++ 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/main/java/org/apache/rave/jcr/data/util/DataUtils.java
 Thu Aug 30 20:34:58 2012
@@ -19,11 +19,6 @@
 
 package org.apache.rave.jcr.data.util;
 
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.tika.Tika;
-import org.apache.tika.config.TikaConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,21 +32,5 @@ public final class DataUtils {
     private DataUtils() {
     }
 
-    /**
-     * Parses metadata of give input stream
-     *
-     * @param inputStream input stream to check
-     * @return plain/text by default
-     */
-    public static String parseMimeType(final InputStream inputStream) {
-        final Tika tika = new Tika(TikaConfig.getDefaultConfig());
-        try {
-            return tika.detect(inputStream);
-        } catch (IOException e) {
-            log.error("Error defining mime type", e);
-        }
-        return "text/plain";
-    }
-
 
 }

Modified: 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/mapping/DefaultDocumentManagerTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/mapping/DefaultDocumentManagerTest.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/mapping/DefaultDocumentManagerTest.java
 (original)
+++ 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/mapping/DefaultDocumentManagerTest.java
 Thu Aug 30 20:34:58 2012
@@ -38,10 +38,10 @@ import org.apache.rave.jcr.data.document
 import org.apache.rave.jcr.data.document.impl.BinaryContent;
 import org.apache.rave.jcr.data.document.impl.BinaryResource;
 import org.apache.rave.jcr.data.document.impl.ContentFolder;
-import org.apache.rave.jcr.data.util.DataUtils;
 import org.apache.rave.jcr.exporting.ContentExporter;
 import org.apache.rave.jcr.importing.ContentImporter;
 import org.apache.rave.jcr.importing.ImportBehavior;
+import org.apache.rave.jcr.utils.JcrUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -132,7 +132,7 @@ public class DefaultDocumentManagerTest 
             BinaryResource resource = new BinaryResource();
             resource.setData(image);
             document.setResource(resource);
-            resource.setMimeType(DataUtils.parseMimeType(image));
+            resource.setMimeType(JcrUtils.parseMimeType(image));
             // tika
             resource.setEncoding("test");
             final Calendar lastModified = Calendar.getInstance();

Modified: rave/sandbox/content-services/rave-jcr-utils/pom.xml
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-utils/pom.xml?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-utils/pom.xml (original)
+++ rave/sandbox/content-services/rave-jcr-utils/pom.xml Thu Aug 30 20:34:58 
2012
@@ -69,6 +69,15 @@
       <version>${apache.jackrabbit.version}</version>
       <scope>provided</scope>
     </dependency>
+    <!-- TEST -->
+
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-jcr-tests</artifactId>
+      <version>${apache.jackrabbit.version}</version>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
 </project>

Modified: 
rave/sandbox/content-services/rave-jcr-utils/src/main/java/org/apache/rave/jcr/utils/JcrUtils.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-utils/src/main/java/org/apache/rave/jcr/utils/JcrUtils.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-utils/src/main/java/org/apache/rave/jcr/utils/JcrUtils.java
 (original)
+++ 
rave/sandbox/content-services/rave-jcr-utils/src/main/java/org/apache/rave/jcr/utils/JcrUtils.java
 Thu Aug 30 20:34:58 2012
@@ -18,15 +18,42 @@
  */
 package org.apache.rave.jcr.utils;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 
+import org.apache.tika.Tika;
+import org.apache.tika.config.TikaConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public final class JcrUtils {
 
+    private static final Logger log = LoggerFactory.getLogger(JcrUtils.class);
+
     private JcrUtils() {
     }
 
+    /**
+     * Parses metadata of give input stream
+     *
+     * @param inputStream input stream to check
+     * @return plain/text by default
+     */
+    public static String parseMimeType(final InputStream inputStream) {
+
+        final Tika tika = new Tika(TikaConfig.getDefaultConfig());
+        try {
+            return tika.detect(inputStream);
+        } catch (IOException e) {
+            log.error("Error defining mime type", e);
+        }
+        return "text/plain";
+    }
+
     public static String getStringProperty(Node node, String propertyName, 
String defaultValue) throws RepositoryException {
         try {
             return node.getProperty(propertyName).getString();

Copied: 
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java
 (from r1379124, 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/util/DataUtilsTest.java)
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java?p2=rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java&p1=rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/util/DataUtilsTest.java&r1=1379124&r2=1379125&rev=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-integration/data-model/src/test/java/org/apache/rave/jcr/data/util/DataUtilsTest.java
 (original)
+++ 
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java
 Thu Aug 30 20:34:58 2012
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.rave.jcr.data.util;
+package org.apache.rave.jcr.utils;
 
 import java.io.InputStream;
 
@@ -30,15 +30,16 @@ import static org.junit.Assert.assertEqu
 /**
  * @version "$Id$"
  */
-public class DataUtilsTest {
+public class JcrUtilsTest {
+
+    private static Logger log = LoggerFactory.getLogger(JcrUtilsTest.class);
 
-    private static Logger log = LoggerFactory.getLogger(DataUtilsTest.class);
 
     @Test
     public void testParseMimeType() throws Exception {
         final InputStream resourceAsStream = 
getClass().getResourceAsStream("/one-pixel-image.png");
         try {
-            final String mimeType = DataUtils.parseMimeType(resourceAsStream);
+            final String mimeType = JcrUtils.parseMimeType(resourceAsStream);
             assertEquals("image/png", mimeType);
         } finally {
             resourceAsStream.close();

Propchange: 
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-jcr-utils/src/test/java/org/apache/rave/jcr/utils/JcrUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/resource/BinaryResourceView.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/resource/BinaryResourceView.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/resource/BinaryResourceView.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/hmvc/resource/BinaryResourceView.java
 Thu Aug 30 20:34:58 2012
@@ -20,13 +20,20 @@
 package org.apache.rave.portal.web.hmvc.resource;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.rave.jcr.data.document.BinaryDocument;
+import org.apache.rave.jcr.data.document.impl.BinaryContent;
+import org.apache.rave.jcr.data.mapping.DocumentManager;
+import org.apache.rave.jcr.utils.JcrUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.servlet.view.AbstractView;
 
 /**
@@ -37,14 +44,25 @@ public class BinaryResourceView extends 
     private static Logger log = 
LoggerFactory.getLogger(BinaryResourceView.class);
     private static final int DEFAULT_SIZE = 1024 << 10;
 
+    private final String binaryPath;
+
+    @Autowired
+    private DocumentManager documentManager;
+
+    public BinaryResourceView(String binaryPath) {
+        this.binaryPath = binaryPath;
+    }
+
+
     @Override
     protected void renderMergedOutputModel(Map<String, Object> model, 
HttpServletRequest request, HttpServletResponse response) throws Exception {
 
-        final ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream(DEFAULT_SIZE);
-        setContentType(extractContentType(request));
 
-        try {
+        final BinaryContent binaryContent = 
documentManager.fetchDocument(binaryPath, BinaryContent.class);
+        final ByteArrayOutputStream byteArrayOutputStream = 
fillOutputStream(binaryContent);
+        setContentType(extractContentType(binaryContent));
 
+        try {
             writeToResponse(response, byteArrayOutputStream);
         } finally {
             byteArrayOutputStream.close();
@@ -52,8 +70,27 @@ public class BinaryResourceView extends 
 
     }
 
-    private String extractContentType(HttpServletRequest request) {
-        return "html/text";
+    private ByteArrayOutputStream fillOutputStream(BinaryDocument content) 
throws IOException {
+        final ByteArrayOutputStream outputStream = new 
ByteArrayOutputStream(DEFAULT_SIZE);
+        if (content == null || content.getResource() == null) {
+            log.warn("Content was null: {}", binaryPath);
+            return outputStream;
+        }
+        final InputStream stream = content.getResource().getData();
+        final byte[] data = new byte[DEFAULT_SIZE];
+        int read;
+        while ((read = stream.read(data, 0, data.length)) != -1) {
+            outputStream.write(data, 0, read);
+        }
+        return outputStream;
+
+    }
+
+    private String extractContentType(BinaryDocument content) {
+        if (content == null || content.getResource() == null) {
+            return "plain/text";
+        }
+        return JcrUtils.parseMimeType(content.getResource().getData());
     }
 
 

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java?rev=1379125&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
 Thu Aug 30 20:34:58 2012
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.rave.portal.web.hmvc.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.rave.jcr.data.mapping.DocumentManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public abstract class BaseTest {
+
+    private static Logger log = LoggerFactory.getLogger(BaseTest.class);
+
+    protected void registerDataCnd(DocumentManager manager) {
+        final String cndFile = "/rave-data-model.cnd";
+        final InputStream cnd = getClass().getResourceAsStream(cndFile);
+        registerCnd(manager.getSession(), cnd);
+    }
+
+    protected void registerCnd(final Session session, final InputStream 
stream) {
+
+        try {
+            NodeType[] nodeTypes = CndImporter.registerNodeTypes(new 
InputStreamReader(stream), session);
+            for (NodeType nt : nodeTypes) {
+                log.info("@registered nodetype: {}", nt.getName());
+            }
+
+        } catch (org.apache.jackrabbit.commons.cnd.ParseException e) {
+            log.error("Error parsing CND: ", e);
+        } catch (RepositoryException e) {
+            log.error("Error registering CND: ", e);
+        } catch (IOException e) {
+            log.error("Error loading CND file: ", e);
+        }
+
+    }
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BaseTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BinaryRepositoryControllerTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BinaryRepositoryControllerTest.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BinaryRepositoryControllerTest.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/BinaryRepositoryControllerTest.java
 Thu Aug 30 20:34:58 2012
@@ -19,10 +19,15 @@
 
 package org.apache.rave.portal.web.hmvc.resource;
 
+import java.util.Calendar;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.rave.jcr.data.document.BinaryDocument;
+import org.apache.rave.jcr.data.document.impl.BinaryContent;
+import org.apache.rave.jcr.data.document.impl.BinaryResource;
+import org.apache.rave.jcr.data.mapping.DocumentManager;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -49,12 +54,16 @@ import static junit.framework.Assert.ass
  */
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration({"classpath:test-config.xml"})
-public class BinaryRepositoryControllerTest {
+public class BinaryRepositoryControllerTest extends BaseTest {
 
     private static Logger log = 
LoggerFactory.getLogger(BinaryRepositoryControllerTest.class);
 
     @Autowired
     private ApplicationContext applicationContext;
+
+    @Autowired
+    private DocumentManager documentManager;
+
     private MockHttpServletRequest request;
     private MockHttpServletResponse response;
 
@@ -71,6 +80,18 @@ public class BinaryRepositoryControllerT
         response = new MockHttpServletResponse();
         handlerMapping = (SimpleUrlHandlerMapping) 
applicationContext.getBean("org.springframework.web.servlet.config.viewControllerHandlerMapping");
 
+
+        // register CND:
+        registerDataCnd(documentManager);
+        final BinaryDocument document = new BinaryContent();
+        document.setPath("/binaries/freemarker");
+        final BinaryResource resource = new BinaryResource();
+        resource.setLastModified(Calendar.getInstance());
+        resource.setData(getClass().getResourceAsStream("/test-template.ftl"));
+        resource.setMimeType("plain/text");
+        document.setResource(resource);
+        documentManager.saveDocument(document);
+
     }
 
     @Test
@@ -92,6 +113,7 @@ public class BinaryRepositoryControllerT
         request.setMethod("GET");
         modelAndView = controller.handleRequest(request, response);
         assertTrue("expected model and view", modelAndView != null);
+        log.info("modelAndView {}", modelAndView);
         // mismatch
         requestUri = "/no-binaries/somepath/test/foo.jpeg";
         request.setRequestURI(requestUri);

Modified: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/JcrRepositoryResourceLoaderTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/JcrRepositoryResourceLoaderTest.java?rev=1379125&r1=1379124&r2=1379125&view=diff
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/JcrRepositoryResourceLoaderTest.java
 (original)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/hmvc/resource/JcrRepositoryResourceLoaderTest.java
 Thu Aug 30 20:34:58 2012
@@ -19,22 +19,14 @@
 
 package org.apache.rave.portal.web.hmvc.resource;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.StringWriter;
 import java.util.Calendar;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.rave.jcr.data.document.BinaryDocument;
 import org.apache.rave.jcr.data.document.impl.BinaryContent;
 import org.apache.rave.jcr.data.document.impl.BinaryResource;
-import org.apache.rave.jcr.data.document.impl.ContentFolder;
 import org.apache.rave.jcr.data.mapping.DocumentManager;
 import org.junit.Before;
 import org.junit.Test;
@@ -57,25 +49,21 @@ import static org.junit.Assert.assertTru
  */
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration({"classpath:test-config.xml"})
-public class JcrRepositoryResourceLoaderTest {
+public class JcrRepositoryResourceLoaderTest extends BaseTest {
 
     private static Logger log = 
LoggerFactory.getLogger(JcrRepositoryResourceLoaderTest.class);
 
     @Autowired
     private ApplicationContext applicationContext;
 
+    @Autowired
+    private DocumentManager documentManager;
+
     @Before
     public void setUp() throws Exception {
 
-
-        // load samples into repository:
-        DocumentManager manager = (DocumentManager) 
applicationContext.getBean("documentManager");
         // register CND:
-        final String cndFile = "/rave-data-model.cnd";
-        final InputStream cnd = getClass().getResourceAsStream(cndFile);
-        registerCnd(manager.getSession(), cnd);
-        // create binaries folder:
-        manager.saveDocument(new ContentFolder("/binaries"));
+        registerDataCnd(documentManager);
 
         final BinaryDocument document = new BinaryContent();
         document.setPath("/binaries/freemarker");
@@ -84,7 +72,7 @@ public class JcrRepositoryResourceLoader
         resource.setData(getClass().getResourceAsStream("/test-template.ftl"));
         resource.setMimeType("plain/text");
         document.setResource(resource);
-        manager.saveDocument(document);
+        documentManager.saveDocument(document);
 
     }
 
@@ -118,22 +106,4 @@ public class JcrRepositoryResourceLoader
     }
 
 
-    protected void registerCnd(final Session session, final InputStream 
stream) {
-
-        try {
-            NodeType[] nodeTypes = CndImporter.registerNodeTypes(new 
InputStreamReader(stream), session);
-            for (NodeType nt : nodeTypes) {
-                log.info("@registered nodetype: {}", nt.getName());
-            }
-
-        } catch (org.apache.jackrabbit.commons.cnd.ParseException e) {
-            log.error("Error parsing CND: ", e);
-        } catch (RepositoryException e) {
-            log.error("Error registering CND: ", e);
-        } catch (IOException e) {
-            log.error("Error loading CND file: ", e);
-        }
-
-    }
-
 }


Reply via email to