You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ma...@apache.org on 2012/08/23 16:10:25 UTC
svn commit: r1376497 - in /rave/sandbox/content-services: ./
rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/
rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/
rave-jcr-integration/...
Author: marijan
Date: Thu Aug 23 14:10:23 2012
New Revision: 1376497
URL: http://svn.apache.org/viewvc?rev=1376497&view=rev
Log:
RAVE-695 Create new rave-jcr-ocm module providing JCR based Object Content Mapping (OCM) support
- fix config module
- add tool import skeleton
- add url mapping skeleton
Added:
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java (contents, props changed)
- copied, changed from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/UrlConfig.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlConfiguration.java
- copied, changed from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java (with props)
rave/sandbox/content-services/rave-jcr-tools/
rave/sandbox/content-services/rave-jcr-tools/src/
rave/sandbox/content-services/rave-jcr-tools/src/main/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java (with props)
rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java (with props)
rave/sandbox/content-services/rave-jcr-tools/src/main/resources/
rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml (with props)
rave/sandbox/content-services/rave-jcr-tools/src/test/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/
rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/ImportExportToolTest.java
- copied, changed from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java
rave/sandbox/content-services/rave-jcr-tools/src/test/repository/
rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml (with props)
rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/
rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/
rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml (with props)
rave/sandbox/content-services/rave-jcr-tools/src/test/resources/
rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/
rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/
rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/module.json
rave/sandbox/content-services/rave-jcr-tools/src/test/resources/testData.json
Removed:
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/UrlConfig.java
Modified:
rave/sandbox/content-services/pom.xml
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/FileConfigManager.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlMapping.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/page-config.json
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/rave-page-config.cnd
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/FileConfigManagerTest.java
rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
Modified: rave/sandbox/content-services/pom.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/pom.xml?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/pom.xml (original)
+++ rave/sandbox/content-services/pom.xml Thu Aug 23 14:10:23 2012
@@ -188,6 +188,7 @@
<module>rave-jcr-integration</module>
<module>rave-jcr-utils</module>
<module>rave-web-hmvc</module>
+ <module>rave-jcr-tools</module>
<!-- disable incomple simple-app module
<module>simple-app</module>
-->
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/ConfigManager.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/ConfigManager.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/ConfigManager.java Thu Aug 23 14:10:23 2012
@@ -21,7 +21,7 @@ package org.apache.rave.jcr.config;
import org.apache.rave.jcr.config.exc.InvalidConfigurationException;
import org.apache.rave.jcr.config.model.api.PageConfiguration;
-import org.apache.rave.jcr.config.url.UrlConfig;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
/**
* @version "$Id$"
@@ -37,7 +37,7 @@ public interface ConfigManager {
* @throws org.apache.rave.jcr.config.exc.InvalidConfigurationException
* thrown when config cannot be loaded or parsed or configuration parameter was null
*/
- UrlConfig loadUrlConfig(String path, PageConfiguration configuration) throws InvalidConfigurationException;
+ UrlConfiguration loadUrlConfig(String path, PageConfiguration configuration) throws InvalidConfigurationException;
/**
* Loads configuration for given name
@@ -56,4 +56,5 @@ public interface ConfigManager {
void saveConfiguration(PageConfiguration configuration);
+ void saveUrlConfiguration(UrlConfiguration configuration);
}
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/FileConfigManager.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/FileConfigManager.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/FileConfigManager.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/FileConfigManager.java Thu Aug 23 14:10:23 2012
@@ -20,11 +20,9 @@
package org.apache.rave.jcr.config;
import java.io.InputStream;
-import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.io.IOUtils;
@@ -32,7 +30,8 @@ import org.apache.commons.lang.StringUti
import org.apache.rave.jcr.config.exc.InvalidConfigurationException;
import org.apache.rave.jcr.config.model.FilePageConfiguration;
import org.apache.rave.jcr.config.model.api.PageConfiguration;
-import org.apache.rave.jcr.config.url.UrlConfig;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
+import org.apache.rave.jcr.config.url.FileUrlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,7 +44,7 @@ public class FileConfigManager implement
@Override
- public UrlConfig loadUrlConfig(String path, PageConfiguration configuration) throws InvalidConfigurationException {
+ public UrlConfiguration loadUrlConfig(String path, PageConfiguration configuration) throws InvalidConfigurationException {
if (configuration == null || StringUtils.isEmpty(path)) {
throw new InvalidConfigurationException("Provided PageConfiguration was null or configuration path was null or empty: " + path);
}
@@ -56,9 +55,9 @@ public class FileConfigManager implement
if (is == null) {
throw new InvalidConfigurationException("Configuration file not found for path: " + path);
}
- JAXBContext context = JAXBContext.newInstance(UrlConfig.class);
+ JAXBContext context = JAXBContext.newInstance(FileUrlConfiguration.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
- final UrlConfig config = (UrlConfig) unmarshaller.unmarshal(is);
+ final FileUrlConfiguration config = (FileUrlConfiguration) unmarshaller.unmarshal(is);
if (config != null) {
config.initialize(configuration);
}
@@ -97,21 +96,15 @@ public class FileConfigManager implement
}
+
@Override
public void saveConfiguration(PageConfiguration configuration) {
- try {
- JAXBContext context = JAXBContext.newInstance(FilePageConfiguration.class);
-
- Marshaller marshaller = context.createMarshaller();
- final StringWriter writer = new StringWriter();
- marshaller.marshal(configuration, writer);
- // TODO write XML to file system
- log.info("{}", writer);
- } catch (JAXBException e) {
- log.error("Error writing configuration", e);
- }
-
+ throw new IllegalStateException("Not supported");
+ }
+ @Override
+ public void saveUrlConfiguration(UrlConfiguration configuration) {
+ throw new IllegalStateException("Not supported");
}
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java Thu Aug 23 14:10:23 2012
@@ -19,22 +19,13 @@
package org.apache.rave.jcr.config;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-import org.apache.jackrabbit.commons.cnd.CndImporter;
-import org.apache.jackrabbit.commons.cnd.ParseException;
import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
import org.apache.jackrabbit.ocm.mapper.Mapper;
@@ -46,7 +37,10 @@ import org.apache.rave.jcr.config.model.
import org.apache.rave.jcr.config.model.api.PageConfiguration;
import org.apache.rave.jcr.config.model.api.PageDefinition;
import org.apache.rave.jcr.config.model.api.PageFragment;
-import org.apache.rave.jcr.config.url.UrlConfig;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
+import org.apache.rave.jcr.config.model.api.UrlMapping;
+import org.apache.rave.jcr.config.url.JcrUrlConfiguration;
+import org.apache.rave.jcr.config.url.JcrUrlMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,7 +50,7 @@ import org.slf4j.LoggerFactory;
public class JcrConfigManager implements ConfigManager {
private static Logger log = LoggerFactory.getLogger(JcrConfigManager.class);
- public static final String RAVE_CND = "rave-page-config.cnd";
+
private Session session;
private String configPath;
@@ -67,25 +61,46 @@ public class JcrConfigManager implements
this.session = session;
this.configPath = configPath;
this.manager = createManager();
- // TODO move to bootstrapping
- registerCnd(session, RAVE_CND);
-
}
@Override
- public UrlConfig loadUrlConfig(String path, PageConfiguration configuration) throws InvalidConfigurationException {
- throw new InvalidConfigurationException("not implemented yet");
+ public UrlConfiguration loadUrlConfig(String name, PageConfiguration configuration) throws InvalidConfigurationException {
+ final UrlConfiguration urlConfiguration = (UrlConfiguration) manager.getObject(JcrUrlConfiguration.class, configPath + '/' + name);
+ log.info("Loaded URL configuration {}", configuration);
+ urlConfiguration.initialize(configuration);
+ return urlConfiguration;
+
+
}
@Override
public PageConfiguration loadConfiguration(String name) {
final PageConfiguration configuration = (PageConfiguration) manager.getObject(JcrPageConfiguration.class, configPath + '/' + name);
- log.info("Loaded configuration {}", configuration);
+ log.info("Loaded PAGE configuration {}", configuration);
return configuration;
}
@Override
+ public void saveUrlConfiguration(UrlConfiguration configuration) {
+ if (configuration == null) {
+ throw new IllegalArgumentException("UrlConfiguration must not be null");
+ }
+ final String configurationName = configuration.getName();
+ final String path = configPath + '/' + configurationName;
+ final Object existing = manager.getObject(path);
+ if (existing != null) {
+ log.info("@DELETING: UrlConfiguration with name: {}, path: {} already exist, will be deleted", configurationName, path);
+ manager.remove(path);
+ }
+ // initialize root path:
+ initConfigRoot();
+ ((JcrUrlConfiguration) configuration).setPath(path);
+ manager.insert(configuration);
+ manager.save();
+ }
+
+ @Override
public void saveConfiguration(PageConfiguration configuration) {
if (configuration == null) {
throw new IllegalArgumentException("PageConfiguration must not be null");
@@ -123,40 +138,22 @@ public class JcrConfigManager implements
private ObjectContentManager createManager() {
@SuppressWarnings("rawtypes")
List<Class> classes = new ArrayList<Class>();
+ //
+ classes.add(UrlConfiguration.class);
+ classes.add(UrlMapping.class);
classes.add(PageFragment.class);
classes.add(PageDefinition.class);
classes.add(PageConfiguration.class);
// implementations:
- classes.add(JcrPageFragment.class);
+ classes.add(JcrUrlMapping.class);
+ classes.add(JcrUrlConfiguration.class);
classes.add(JcrPageDefinition.class);
+ classes.add(JcrPageFragment.class);
classes.add(JcrPageConfiguration.class);
+
Mapper mapper = new AnnotationMapperImpl(classes);
return new ObjectContentManagerImpl(session, mapper);
}
- private void registerCnd(final Session session, final String fileName) {
- try {
- NodeType[] nodeTypes = CndImporter.registerNodeTypes(new FileReader(getFile(fileName)), session);
- for (NodeType nt : nodeTypes) {
- log.info("@registered nodetype: {}", nt.getName());
- }
- } catch (ParseException e) {
- log.error("Error parsing CND: " + fileName, e);
- } catch (RepositoryException e) {
- log.error("Error registering CND: " + fileName, e);
- } catch (IOException e) {
- log.error("Error loading CND file: " + fileName, e);
- }
-
- }
-
- private File getFile(final String path) throws UnsupportedEncodingException {
- URL url = JcrConfigManager.class.getClassLoader().getResource(path);
- if (url == null) {
- return null;
- }
- String fileName = URLDecoder.decode(url.toString(), "UTF-8").substring("file:".length());
- return new File(fileName);
- }
}
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java Thu Aug 23 14:10:23 2012
@@ -39,10 +39,10 @@ public class JcrPageConfiguration implem
@Field(path = true, id = true)
private String path;
- @Collection(elementClassName = JcrPageDefinition.class, jcrName = "raveconfig:definitioncollection", jcrType = "raveconfig:definitioncollection", jcrElementName = "raveconfig:definitioncollection")
+ @Collection(elementClassName = JcrPageDefinition.class, jcrType = "raveconfig:pagedefinition")
private List<PageDefinition> pageDefinitions;
- @Collection(elementClassName = JcrPageFragment.class, jcrName = "raveconfig:fragmentcollection", jcrType = "raveconfig:fragmentcollection", jcrElementName = "raveconfig:fragmentcollection")
+ @Collection(elementClassName = JcrPageFragment.class, jcrType = "raveconfig:pagefragment")
private List<PageFragment> pageFragments;
@Field(jcrName = "raveconfig:name", jcrType = "String")
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java Thu Aug 23 14:10:23 2012
@@ -60,13 +60,13 @@ public class JcrPageFragment implements
private String viewName;
- @Field(jcrName = "raveconfig:name", jcrType = "String")
+ @Field(jcrType = "String")
private String name;
@Bean(jcrType = "raveconfig:pagefragment", jcrName = "raveconfig:parentfragment")
- private JcrPageFragment parent;
+ private PageFragment parent;
- @Collection(elementClassName = JcrPageFragment.class, jcrName = "raveconfig:fragmentchildren", jcrType = "raveconfig:pagefragment", jcrElementName = "raveconfig:fragmentchildren")
+ @Collection(elementClassName = JcrPageFragment.class, jcrType = "raveconfig:pagefragment", jcrName = "pageFragments")
private List<PageFragment> children;
public String getPath() {
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java Thu Aug 23 14:10:23 2012
@@ -21,9 +21,12 @@ package org.apache.rave.jcr.config.model
import java.util.List;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
/**
* @version "$Id$"
*/
+@Node(isInterface = true, jcrType = "mix:referenceable", discriminator = false)
public interface UrlConfiguration {
void initialize(PageConfiguration configuration);
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlMapping.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlMapping.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlMapping.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlMapping.java Thu Aug 23 14:10:23 2012
@@ -21,9 +21,12 @@ package org.apache.rave.jcr.config.model
import java.util.List;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
/**
* @version "$Id$"
*/
+@Node(isInterface = true, jcrType = "mix:referenceable", discriminator = false)
public interface UrlMapping {
void setParent(UrlMapping parent);
Copied: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java (from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/UrlConfig.java)
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java?p2=rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java&p1=rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/UrlConfig.java&r1=1375555&r2=1376497&rev=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/UrlConfig.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java Thu Aug 23 14:10:23 2012
@@ -38,9 +38,9 @@ import org.slf4j.LoggerFactory;
* @version "$Id$"
*/
@XmlRootElement(name = "url-configuration")
-public class UrlConfig implements UrlConfiguration {
+public class FileUrlConfiguration implements UrlConfiguration {
- private static Logger log = LoggerFactory.getLogger(UrlConfig.class);
+ private static Logger log = LoggerFactory.getLogger(FileUrlConfiguration.class);
private boolean initialized;
@@ -100,8 +100,6 @@ public class UrlConfig implements UrlCon
final List<PageDefinition> pageDefinitions = configuration.getPageDefinitions();
for (PageDefinition pageDefinition : pageDefinitions) {
if (pageDefinition.getName().equals(page)) {
- log.info("###page {}", page);
- log.info("page {}", pageDefinition.getName());
mapping.setPageDefinition(pageDefinition);
return true;
}
@@ -151,7 +149,7 @@ public class UrlConfig implements UrlCon
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
- sb.append("UrlConfig");
+ sb.append("FileUrlConfiguration");
sb.append("{initialized=").append(initialized);
sb.append(", name='").append(name).append('\'');
sb.append(", mappings=").append(mappings);
Propchange: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/FileUrlConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Id
Copied: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlConfiguration.java (from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java)
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlConfiguration.java?p2=rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlConfiguration.java&p1=rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java&r1=1375555&r2=1376497&rev=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlConfiguration.java Thu Aug 23 14:10:23 2012
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.rave.jcr.config.model;
+package org.apache.rave.jcr.config.url;
import java.util.ArrayList;
import java.util.List;
@@ -26,81 +26,64 @@ import org.apache.jackrabbit.ocm.mapper.
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
import org.apache.rave.jcr.config.model.api.PageConfiguration;
-import org.apache.rave.jcr.config.model.api.PageDefinition;
-import org.apache.rave.jcr.config.model.api.PageFragment;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
+import org.apache.rave.jcr.config.model.api.UrlMapping;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version "$Id$"
*/
-@Node(discriminator = false, jcrType = "raveconfig:pageconfiguration")
-public class JcrPageConfiguration implements PageConfiguration {
+@Node(discriminator = false, jcrType = "raveconfig:urlconfiguration", jcrMixinTypes = "mix:referenceable")
+public class JcrUrlConfiguration implements UrlConfiguration {
+ private static Logger log = LoggerFactory.getLogger(JcrUrlConfiguration.class);
@Field(path = true, id = true)
private String path;
- @Collection(elementClassName = JcrPageDefinition.class, jcrName = "raveconfig:definitioncollection", jcrType = "raveconfig:definitioncollection", jcrElementName = "raveconfig:definitioncollection")
- private List<PageDefinition> pageDefinitions;
-
- @Collection(elementClassName = JcrPageFragment.class, jcrName = "raveconfig:fragmentcollection", jcrType = "raveconfig:fragmentcollection", jcrElementName = "raveconfig:fragmentcollection")
- private List<PageFragment> pageFragments;
-
@Field(jcrName = "raveconfig:name", jcrType = "String")
private String name;
+ @Collection(elementClassName = JcrUrlMapping.class, jcrType = "raveconfig:urlmapping")
+ private List<UrlMapping> mappings;
@Override
- public void initialize() {
- // TODO implement
+ public void initialize(PageConfiguration configuration) {
+ log.info("Initializing URL config");
}
- @Override
- public String getName() {
- return name;
+ public JcrUrlConfiguration() {
}
- @Override
- public void setName(String name) {
+ public JcrUrlConfiguration(String name) {
this.name = name;
-
}
@Override
- public List<PageDefinition> getPageDefinitions() {
- if (pageDefinitions == null) {
- pageDefinitions = new ArrayList<PageDefinition>();
- }
- return pageDefinitions;
+ public String getName() {
+ return name;
}
@Override
- public void setPageDefinitions(List<PageDefinition> definitions) {
- pageDefinitions = definitions;
+ public void setName(String name) {
+ this.name = name;
}
@Override
- public List<PageFragment> getPageFragments() {
- if (pageFragments == null) {
- pageFragments = new ArrayList<PageFragment>();
+ public List<UrlMapping> getMappings() {
+ if (mappings == null) {
+ return new ArrayList<UrlMapping>();
}
- return pageFragments;
+ return mappings;
}
@Override
- public void setPageFragments(List<PageFragment> fragments) {
- pageFragments = fragments;
+ public void setMappings(List<UrlMapping> mappings) {
+ this.mappings = mappings;
}
- @Override
- public void addPageFragment(PageFragment fragment) {
- getPageFragments().add(fragment);
- }
-
- @Override
- public void addPageDefinition(PageDefinition definition) {
- getPageDefinitions().add(definition);
- }
public String getPath() {
return path;
@@ -113,9 +96,9 @@ public class JcrPageConfiguration implem
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
- sb.append("JcrPageConfiguration");
+ sb.append("JcrUrlConfiguration");
sb.append("{name='").append(name).append('\'');
- sb.append(", path='").append(path).append('\'');
+ sb.append(",nr of mappings=").append(getMappings().size());
sb.append('}');
return sb.toString();
}
Added: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java (added)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java Thu Aug 23 14:10:23 2012
@@ -0,0 +1,119 @@
+/*
+ * 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.jcr.config.url;
+
+import java.util.List;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+import org.apache.rave.jcr.config.model.api.PageDefinition;
+import org.apache.rave.jcr.config.model.api.UrlMapping;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+@Node(discriminator = false, jcrType = "raveconfig:urlmapping", jcrMixinTypes = "mix:referenceable")
+public class JcrUrlMapping implements UrlMapping {
+
+ private static Logger log = LoggerFactory.getLogger(JcrUrlMapping.class);
+
+ @Field(jcrType = "String")
+ private String url;
+
+ @Field(jcrType = "String")
+ private String page;
+
+
+ // set by code
+ private UrlMapping parent;
+
+ // set by code
+ //@Bean(jcrType = "raveconfig:urlmapping", jcrName = "raveconfig:urlmapping")
+ private PageDefinition pageDefinition;
+
+ @Collection(jcrType = "raveconfig:urlmapping", jcrName = "raveconfig:urlmapping")
+ private List<UrlMapping> children;
+
+ @Override
+ public String getUrl() {
+ return url;
+ }
+
+ @Override
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Override
+ public String getPage() {
+ return page;
+ }
+
+ @Override
+ public void setPage(String page) {
+ this.page = page;
+ }
+
+ @Override
+ public UrlMapping getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(UrlMapping parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public PageDefinition getPageDefinition() {
+ return pageDefinition;
+ }
+
+ @Override
+ public void setPageDefinition(PageDefinition pageDefinition) {
+ this.pageDefinition = pageDefinition;
+ }
+
+ @Override
+ public List<UrlMapping> getChildren() {
+ return children;
+ }
+
+ @Override
+ public void setChildren(List<UrlMapping> children) {
+ this.children = children;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("JcrUrlMapping");
+ sb.append("{url='").append(url).append('\'');
+ sb.append(", page='").append(page).append('\'');
+ sb.append(", parent=").append(parent);
+ sb.append(", pageDefinition=").append(pageDefinition);
+ sb.append(", children=").append(children);
+ sb.append('}');
+ return sb.toString();
+ }
+}
Propchange: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/url/JcrUrlMapping.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/page-config.json
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/page-config.json?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/page-config.json (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/page-config.json Thu Aug 23 14:10:23 2012
@@ -1,29 +1,33 @@
{
"myConfiguration":{
"jcr:primaryType":"raveconfig:pageconfiguration",
- "myPage":{
+ "name":"myConfiguration",
+ "pageDefinitions":{
"jcr:primaryType":"raveconfig:pagedefinition",
- "name":"myPage",
- "path":"/mypage2",
- "description":"Simple page",
- "controller":"org.apache.rave.portal.web.hmvc.example.MyPageController",
- "head":{
- "jcr:primaryType":"raveconfig:pagefragment",
- "name":"head",
- "path":"myHeader",
- "controller":"org.apache.rave.portal.web.hmvc.example.MyHeaderController"
- },
- "body":{
- "jcr:primaryType":"raveconfig:pagefragment",
- "name":"body",
- "path":"myBody",
- "controller":"org.apache.rave.portal.web.hmvc.example.MyContentController"
- },
- "footer":{
- "jcr:primaryType":"raveconfig:pagefragment",
- "name":"footer",
- "path":"myFooter",
- "controller":"org.apache.rave.portal.web.hmvc.example.MyFooterController"
+ "myPage":{
+ "jcr:primaryType":"raveconfig:pagedefinition",
+ "name":"myPage",
+ "path":"/mypage2",
+ "description":"Simple page",
+ "controller":"org.apache.rave.portal.web.hmvc.example.MyPageController",
+ "head":{
+ "jcr:primaryType":"raveconfig:pagefragment",
+ "name":"head",
+ "path":"myHeader",
+ "controller":"org.apache.rave.portal.web.hmvc.example.MyHeaderController"
+ },
+ "body":{
+ "jcr:primaryType":"raveconfig:pagefragment",
+ "name":"body",
+ "path":"myBody",
+ "controller":"org.apache.rave.portal.web.hmvc.example.MyContentController"
+ },
+ "footer":{
+ "jcr:primaryType":"raveconfig:pagefragment",
+ "name":"footer",
+ "path":"myFooter",
+ "controller":"org.apache.rave.portal.web.hmvc.example.MyFooterController"
+ }
}
}
}
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/rave-page-config.cnd
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/rave-page-config.cnd?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/rave-page-config.cnd (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/resources/rave-page-config.cnd Thu Aug 23 14:10:23 2012
@@ -1,6 +1,10 @@
<nt='http://www.jcp.org/jcr/nt/1.0'>
<'raveconfig'='http://www.apache.org/rave/config/1.0'>
+//############################################
+// RELAX TYPES
+//############################################
+
[raveconfig:relaxed] mixin
- * (boolean)
- * (boolean) multiple
@@ -18,6 +22,10 @@
- * (uri) multiple
+//############################################
+// PAGE CONFIGURATION
+//############################################
+
[raveconfig:pagefragment] > raveconfig:relaxed
+ raveconfig:parentfragment (raveconfig:pagefragment)
+ * (raveconfig:pagefragment) multiple
@@ -34,9 +42,18 @@
[raveconfig:pageconfiguration] > raveconfig:relaxed
-+ raveconfig:fragmentcollection (raveconfig:fragmentcollection)
-+ raveconfig:definitioncollection (raveconfig:definitioncollection)
+ * (raveconfig:pagefragment) multiple
+ * (raveconfig:pagedefinition) multiple
+//############################################
+// URL CONFIGURATION
+//############################################
+
+
+[raveconfig:urlmapping] > raveconfig:relaxed
+ + raveconfig:urlmapping (raveconfig:urlmapping)
+ + * (raveconfig:urlmapping) multiple
+
+[raveconfig:urlconfiguration] > raveconfig:relaxed
++ * (raveconfig:urlmapping) multiple
\ No newline at end of file
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/FileConfigManagerTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/FileConfigManagerTest.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/FileConfigManagerTest.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/FileConfigManagerTest.java Thu Aug 23 14:10:23 2012
@@ -27,8 +27,8 @@ import org.apache.rave.jcr.config.model.
import org.apache.rave.jcr.config.model.api.PageConfiguration;
import org.apache.rave.jcr.config.model.api.PageDefinition;
import org.apache.rave.jcr.config.model.api.PageFragment;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
import org.apache.rave.jcr.config.model.api.UrlMapping;
-import org.apache.rave.jcr.config.url.UrlConfig;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -134,7 +134,7 @@ public class FileConfigManagerTest {
@Test
public void testLoadUrlConfig() throws Exception {
FileConfigManager dao = new FileConfigManager();
- final UrlConfig config = dao.loadUrlConfig(URL_CONFIG_PATH, dao.loadConfiguration(PAGE_CONFIG_PATH));
+ final UrlConfiguration config = dao.loadUrlConfig(URL_CONFIG_PATH, dao.loadConfiguration(PAGE_CONFIG_PATH));
log.info("config {}", config);
assertTrue(config != null);
assertEquals("default", config.getName());
Modified: rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java?rev=1376497&r1=1376496&r2=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java (original)
+++ rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java Thu Aug 23 14:10:23 2012
@@ -19,14 +19,24 @@
package org.apache.rave.jcr.config;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
+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.config.model.JcrPageConfiguration;
import org.apache.rave.jcr.config.model.JcrPageDefinition;
import org.apache.rave.jcr.config.model.JcrPageFragment;
import org.apache.rave.jcr.config.model.api.PageConfiguration;
import org.apache.rave.jcr.config.model.api.PageDefinition;
import org.apache.rave.jcr.config.model.api.PageFragment;
+import org.apache.rave.jcr.config.model.api.UrlConfiguration;
+import org.apache.rave.jcr.config.url.JcrUrlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,11 +47,36 @@ public class JcrConfigManagerTest extend
private static Logger log = LoggerFactory.getLogger(JcrConfigManagerTest.class);
public static final String CONFIG_ROOT = "/raveconfig";
-
+ public static final String RAVE_CND = "rave-page-config.cnd";
@Override
public void setUp() throws Exception {
super.setUp();
+ // register namespace:
+ registerCnd(superuser, RAVE_CND);
+ }
+
+
+ public void testSaveUrlConfiguration() throws Exception {
+ ConfigManager manager = new JcrConfigManager(superuser, CONFIG_ROOT);
+ // create page config:
+ final PageConfiguration configuration = new JcrPageConfiguration();
+ final String configName = "myPageConfigName";
+ configuration.setName(configName);
+ final PageDefinition definition = new JcrPageDefinition();
+ definition.setPath("def1");
+ definition.setName("def1");
+ definition.setController("def1");
+ final ArrayList<PageDefinition> definitions = new ArrayList<PageDefinition>();
+ definition.addChild(definition);
+ configuration.setPageDefinitions(definitions);
+ manager.saveConfiguration(configuration);
+ //
+ final String urlConfigName = "urlConfig";
+ UrlConfiguration urlConfiguration = new JcrUrlConfiguration(urlConfigName);
+ manager.saveUrlConfiguration(urlConfiguration);
+ urlConfiguration = manager.loadUrlConfig(urlConfigName, configuration);
+ assertTrue(urlConfiguration != null);
}
@@ -100,4 +135,25 @@ public class JcrConfigManagerTest extend
}
+ //*************************************************************************************
+ // NOTE: loading CND is only for testing purposes
+ //*************************************************************************************
+
+ private void registerCnd(final Session session, final String fileName) {
+ try {
+ NodeType[] nodeTypes = CndImporter.registerNodeTypes(new FileReader(getFile(fileName)), session);
+ for (NodeType nt : nodeTypes) {
+ log.info("@registered nodetype: {}", nt.getName());
+ }
+ } catch (org.apache.jackrabbit.commons.cnd.ParseException e) {
+ log.error("Error parsing CND: " + fileName, e);
+ } catch (RepositoryException e) {
+ log.error("Error registering CND: " + fileName, e);
+ } catch (IOException e) {
+ log.error("Error loading CND file: " + fileName, e);
+ }
+
+ }
+
+
}
Added: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java Thu Aug 23 14:10:23 2012
@@ -0,0 +1,158 @@
+/*
+ * 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.tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.rave.jcr.importing.ContentImporter;
+import org.apache.rave.jcr.importing.ImportBehavior;
+import org.apache.rave.jcr.importing.ImportException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Command line tool used to import and export JSON based JCR content
+ *
+ * @version "$Id$"
+ */
+public class ImportExportTool {
+
+ private static Logger log = LoggerFactory.getLogger(ImportExportTool.class);
+
+ /**
+ * The repository.xml configuration file.
+ */
+ private final String repoConfig;
+
+ /**
+ * The home directory of the repository.
+ */
+ private final String repoHome;
+ /**
+ * Name of the file to import
+ */
+ private final String fileName;
+ private String username;
+ private String password;
+
+
+ /**
+ * Import/Export tool constructor
+ *
+ * @param repoConfig path to repository.xml file
+ * @param repoHome home directory of the repository.
+ * @param fileName name of the file to import (JSON format)
+ */
+ public ImportExportTool(String repoConfig, String repoHome, String fileName) {
+ this.repoConfig = repoConfig;
+ this.repoHome = repoHome;
+ this.fileName = fileName;
+ }
+
+
+ private Session createConnection(final String user, final String password) throws RepositoryException {
+ Repository repository = new TransientRepository(repoConfig, repoHome);
+ if (username == null || password == null) {
+ return repository.login();
+ }
+ return repository.login(new SimpleCredentials(user, password.toCharArray()));
+
+ }
+
+
+ /**
+ * Import given filename into repository.
+ *
+ * @param parentPath repository parentPath to import file to
+ * @param nodeName name of the node
+ */
+ public void importData(String parentPath, String nodeName) {
+
+ Session session = null;
+
+ try {
+ session = createConnection(username, password);
+ ContentImporter contentImporter = new ContentImporter(session);
+ File file;
+ if (fileName.startsWith(ToolUtils.CLASSPATH_PREFIX)) {
+ file = ToolUtils.getResourceFile(fileName);
+ } else {
+ file = new File(fileName);
+ }
+ final FileInputStream content = new FileInputStream(file);
+ contentImporter.importContent(parentPath, nodeName, content, ImportBehavior.MERGE);
+
+ } catch (RepositoryException e) {
+ log.error("Error importing file: " + fileName, e);
+ revertTransaction(session);
+ } catch (FileNotFoundException e) {
+ log.error("Data file not found", e);
+ } catch (ImportException e) {
+ log.error("Error importing file", e);
+ } catch (IOException e) {
+ log.error("Error reading file", e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
+ private void revertTransaction(Session session) {
+ if (session != null) {
+ // revert transaction
+ try {
+ session.refresh(false);
+ } catch (RepositoryException e) {
+ log.error("Error refreshing session", e);
+ }
+ }
+ }
+
+ //*************************************************************************************
+ // GETTERS /SETTERS
+ //*************************************************************************************
+
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ImportExportTool.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java Thu Aug 23 14:10:23 2012
@@ -0,0 +1,117 @@
+/*
+ * 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.tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO: this is a copy from org.apache.rave.jcr.config.ConfigUtils, refactor
+ *
+ * @version "$Id$"
+ */
+public final class ToolUtils {
+
+ private static Logger log = LoggerFactory.getLogger(ToolUtils.class);
+
+
+ public static final String FILE_PATH_PREFIX = "file:";
+ public static final String CLASSPATH_PREFIX = "classpath:";
+
+
+ private ToolUtils() {
+ }
+
+
+ /**
+ * Returns the physical resource file object. <p> <ul> <li>When the resourcePath starts with 'file:', it is assumed
+ * as a file path on the file system.</li> <li>When the resourcePath starts with 'classpath:', it is assumed as a
+ * classpath resource path.</li> <li>When the resourcePath does not starts with 'file:' nor with 'classpath:', it is
+ * assumed as a file path on the file system.</li> </ul> </p>
+ *
+ * @param resourcePath the path of the resource.
+ * @return File or null if nothing is found or encoding exception is thrown
+ */
+ public static File getResourceFile(String resourcePath) {
+ if (resourcePath == null) {
+ throw new IllegalArgumentException("resourcePath parameter cannot be <null>");
+ }
+ if (resourcePath.startsWith(FILE_PATH_PREFIX)) {
+ String fileName = resourcePath.substring(FILE_PATH_PREFIX.length());
+ return new File(fileName);
+ } else if (resourcePath.startsWith(CLASSPATH_PREFIX)) {
+ String classPath = resourcePath.substring(CLASSPATH_PREFIX.length());
+ URL url = ToolUtils.class.getClassLoader().getResource(classPath);
+ try {
+ if (url == null) {
+ return null;
+ }
+ String fileName = URLDecoder.decode(url.toString(), "UTF-8").substring("file:".length());
+ return new File(fileName);
+ } catch (UnsupportedEncodingException e) {
+ // The system should always have UTF-8
+ return null;
+ }
+ } else {
+ // fallback
+ log.info("Neither file or classpath prefix used, trying to get resource directly from '{}'", resourcePath);
+ return new File(resourcePath);
+ }
+ }
+
+ public static InputStream getResourceInputStream(String resourcePath) {
+ if (resourcePath == null) {
+ throw new IllegalArgumentException("resourcePath parameter cannot be <null>");
+ }
+ if (resourcePath.startsWith(FILE_PATH_PREFIX)) {
+ String fileName = resourcePath.substring(FILE_PATH_PREFIX.length());
+ try {
+ return new FileInputStream(new File(fileName));
+ } catch (FileNotFoundException e) {
+ log.error("Cannot load resource file from '{}'", resourcePath, e);
+ return null;
+ }
+ } else if (resourcePath.startsWith(CLASSPATH_PREFIX)) {
+ String classPath = resourcePath.substring(CLASSPATH_PREFIX.length());
+ URL url = ToolUtils.class.getClassLoader().getResource(classPath);
+ if (url == null) {
+ return null;
+ }
+ return ToolUtils.class.getClassLoader().getResourceAsStream(classPath);
+ } else {
+ // fallback
+ log.info("Neither file or classpath prefix used, trying to get resource directly from '{}'", resourcePath);
+ try {
+ return new FileInputStream(new File(resourcePath));
+ } catch (FileNotFoundException e) {
+ log.error("Cannot load resource file from '{}'", resourcePath, e);
+ return null;
+ }
+ }
+ }
+}
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/java/org/apache/rave/tools/ToolUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml Thu Aug 23 14:10:23 2012
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ 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.
+ -->
+
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <!-- ====================================================================== -->
+ <!-- A P P E N D E R S -->
+ <!-- ====================================================================== -->
+
+
+ <!-- console -->
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} %-5p [%C.%M():%L] %m%n"/>
+ </layout>
+ <filter class="org.apache.log4j.varia.LevelRangeFilter">
+ <param name="levelMin" value="ERROR"/>
+ </filter>
+ </appender>
+
+ <!-- ====================================================================== -->
+ <!-- L O G G E R S -->
+ <!-- ====================================================================== -->
+
+ <!-- CMS logging -->
+ <category name="org.apache.jackrabbit.core">
+ <level value="warn"/>
+ </category>
+ <category name="org.apache.jackrabbit.extractor">
+ <level value="warn"/>
+ </category>
+ <category name="org.apache.jackrabbit">
+ <level value="warn"/>
+ </category>
+ <category name="org.hippoecm.repository">
+ <level value="warn"/>
+ </category>
+ <category name="org.hippoecm.frontend">
+ <level value="warn"/>
+ </category>
+ <category name="org.apache.wicket">
+ <level value="warn"/>
+ </category>
+
+ <!-- too many caching warnings -->
+ <category name="org.apache.jackrabbit.core.state">
+ <level value="error"/>
+ </category>
+ <category name="org.apache.jackrabbit.core.ItemManager">
+ <level value="error"/>
+ </category>
+ <category name="org.apache.jackrabbit.core.persistence.bundle.util.LRUNodeIdCache">
+ <level value="error"/>
+ </category>
+
+
+ <category name="org.apache.rave">
+ <level value="debug"/>
+ </category>
+
+ <root>
+ <level value="debug"/>
+ <appender-ref ref="console"/>
+ </root>
+
+</log4j:configuration>
+
+
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/main/resources/log4j.xml
------------------------------------------------------------------------------
svn:keywords = Id
Copied: rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/ImportExportToolTest.java (from r1375555, rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java)
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/ImportExportToolTest.java?p2=rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/ImportExportToolTest.java&p1=rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java&r1=1375555&r2=1376497&rev=1376497&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/page-configuration/src/main/java/org/apache/rave/jcr/config/model/api/UrlConfiguration.java (original)
+++ rave/sandbox/content-services/rave-jcr-tools/src/test/java/org/apache/rave/tools/ImportExportToolTest.java Thu Aug 23 14:10:23 2012
@@ -17,22 +17,26 @@
* under the License.
*/
-package org.apache.rave.jcr.config.model.api;
+package org.apache.rave.tools;
-import java.util.List;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version "$Id$"
*/
-public interface UrlConfiguration {
+public class ImportExportToolTest {
- void initialize(PageConfiguration configuration);
+ private static Logger log = LoggerFactory.getLogger(ImportExportToolTest.class);
+ public static final String FILE_NAME = ToolUtils.CLASSPATH_PREFIX + "testData.json";
- String getName();
+ @Test
+ public void testImport() throws Exception {
- void setName(String name);
-
- List<UrlMapping> getMappings();
-
- void setMappings(List<UrlMapping> mappings);
+ ImportExportTool tool = new ImportExportTool("repository/repository.xml", "repository", FILE_NAME);
+ tool.setPassword("admin");
+ tool.setUsername("admin");
+ tool.importData("/", "testnode");
+ }
}
Added: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml Thu Aug 23 14:10:23 2012
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+ -->
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN" "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
+<Repository>
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+
+ <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+
+ <Security appName="Jackrabbit">
+ <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security"/>
+ <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"/>
+ <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule"/>
+ </Security>
+
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" maxIdleTime="2"/>
+
+ <Workspace name="${wsp.name}">
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemBundlePersistenceManager"/>
+ </Workspace>
+
+ <Versioning rootPath="${rep.home}/version">
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemBundlePersistenceManager"/>
+ </Versioning>
+
+</Repository>
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/repository.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml Thu Aug 23 14:10:23 2012
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+ -->
+<Workspace name="default">
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem"/>
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemBundlePersistenceManager"/>
+</Workspace>
\ No newline at end of file
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: rave/sandbox/content-services/rave-jcr-tools/src/test/repository/workspaces/default/workspace.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/module.json
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/module.json?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/module.json (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/test/resources/META-INF/rave/module.json Thu Aug 23 14:10:23 2012
@@ -0,0 +1,36 @@
+{
+ "name":"foo",
+ "version":"v1",
+ "workspace":"moduleWs",
+ "dependencies":[ "bar", "quz" ],
+ "namespaces":{
+ "foo":"http://foo.com/1.0"
+ },
+ "cnds":{
+ "foo":{
+ "file":"foo.cnd",
+ "reload":false
+ }
+ },
+ "contents":{
+ "foo":{
+ "file":"foo.json",
+ "parent":"/testroot",
+ "importBehavior":"merge"
+ },
+ "bar":{
+ "file":"bar.json",
+ "parent":"/testroot",
+ "reload":true,
+ "version":"v2",
+ "workspace":"myws"
+ }
+ },
+ "resources":{
+ "quux":{
+ "path":"quux",
+ "parent":"/testroot",
+ "importBehavior":"skip"
+ }
+ }
+}
Added: rave/sandbox/content-services/rave-jcr-tools/src/test/resources/testData.json
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-tools/src/test/resources/testData.json?rev=1376497&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-tools/src/test/resources/testData.json (added)
+++ rave/sandbox/content-services/rave-jcr-tools/src/test/resources/testData.json Thu Aug 23 14:10:23 2012
@@ -0,0 +1,6 @@
+{
+ "myConfiguration":{
+ "jcr:primaryType":"nt:unstructured",
+ "name":"test"
+ }
+}