Author: marijan
Date: Mon Jul 16 08:37:21 2012
New Revision: 1361935
URL: http://svn.apache.org/viewvc?rev=1361935&view=rev
Log:
RAVE-695 Create new rave-jcr-ocm module providing JCR based Object Content
Mapping (OCM) support
- skeleton
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/main/resources/
rave/sandbox/content-services/rave-jcr-config/src/main/resources/rave-config.cnd
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
(with props)
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
(with props)
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import org.apache.rave.jcr.config.model.api.PageConfiguration;
+
+/**
+ * @version "$Id$"
+ */
+public interface ConfigManager {
+
+
+ /**
+ * Loads configuration for given name
+ *
+ * @param name configuration name
+ * @return configuration or null if none found
+ */
+ PageConfiguration loadConfiguration(String name);
+
+ /**
+ * TODO: introduce update config method ??
+ * Saves configuration. An existing configuration will be overwritten
+ *
+ * @param configuration instance of PageConfiguration
+ */
+ void saveConfiguration(PageConfiguration configuration);
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/ConfigManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,156 @@
+/*
+ * 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;
+
+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;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl;
+import org.apache.rave.jcr.config.exc.InvalidConfigurationException;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class JcrConfigManager implements ConfigManager {
+
+ private static Logger log =
LoggerFactory.getLogger(JcrConfigManager.class);
+ public static final String RAVE_CND = "rave-config.cnd";
+
+ private Session session;
+ private String configPath;
+ private ObjectContentManager manager;
+
+
+ public JcrConfigManager(Session session, String configPath) {
+ this.session = session;
+ this.configPath = configPath;
+ this.manager = createManager();
+ // TODO move to bootstrapping
+ registerCnd(session, RAVE_CND);
+
+ }
+
+
+ @Override
+ public PageConfiguration loadConfiguration(String name) {
+ final PageConfiguration configuration = (PageConfiguration)
manager.getObject(JcrPageConfiguration.class, configPath + '/' + name);
+ log.info("Loaded configuration {}", configuration);
+ return configuration;
+ }
+
+ @Override
+ public void saveConfiguration(PageConfiguration configuration) {
+ if (configuration == null) {
+ throw new IllegalArgumentException("PageConfiguration 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: Configuration with name: {}, path: {} already
exist, will be deleted", configurationName, path);
+ manager.remove(path);
+ }
+ // initialize root path:
+ initConfigRoot();
+ // set path:
+ ((JcrPageConfiguration) configuration).setPath(path);
+ manager.insert(configuration);
+ manager.save();
+ }
+
+ private void initConfigRoot() {
+ try {
+ if (!session.nodeExists(configPath)) {
+
+ final Node root = session.getNode("/");
+
+ root.addNode(configPath.substring(1, configPath.length()),
"nt:unstructured");
+ session.save();
+ }
+ } catch (RepositoryException e) {
+
+ throw new InvalidConfigurationException("Couldn't initialize
configuration root path: " + configPath, e);
+ }
+ }
+
+ private ObjectContentManager createManager() {
+ @SuppressWarnings("rawtypes")
+ List<Class> classes = new ArrayList<Class>();
+ classes.add(PageFragment.class);
+ classes.add(PageDefinition.class);
+ classes.add(PageConfiguration.class);
+ // implementations:
+ classes.add(JcrPageFragment.class);
+ classes.add(JcrPageDefinition.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);
+ }
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/JcrConfigManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.exc;
+
+/**
+ * @version "$Id$"
+ */
+public class InvalidConfigurationException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidConfigurationException() {
+ }
+
+ public InvalidConfigurationException(String message) {
+ super(message);
+ }
+
+ public InvalidConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidConfigurationException(Throwable cause) {
+ super(cause);
+ }
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/exc/InvalidConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
Mon Jul 16 08:37:21 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.jcr.config.model;
+
+import java.util.ArrayList;
+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.PageConfiguration;
+import org.apache.rave.jcr.config.model.api.PageDefinition;
+import org.apache.rave.jcr.config.model.api.PageFragment;
+
+/**
+ * @version "$Id$"
+ */
+@Node(discriminator = false, jcrType = "raveconfig:pageconfiguration")
+public class JcrPageConfiguration implements PageConfiguration {
+
+
+ @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;
+
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+
+ }
+
+ @Override
+ public List<PageDefinition> getPageDefinitions() {
+ if (pageDefinitions == null) {
+ pageDefinitions = new ArrayList<PageDefinition>();
+ }
+ return pageDefinitions;
+ }
+
+ @Override
+ public void setPageDefinitions(List<PageDefinition> definitions) {
+ pageDefinitions = definitions;
+
+ }
+
+ @Override
+ public List<PageFragment> getPageFragments() {
+ if (pageFragments == null) {
+ pageFragments = new ArrayList<PageFragment>();
+ }
+ return pageFragments;
+ }
+
+ @Override
+ public void setPageFragments(List<PageFragment> fragments) {
+ pageFragments = fragments;
+ }
+
+ @Override
+ public void addPageFragment(PageFragment fragment) {
+ getPageFragments().add(fragment);
+ }
+
+ @Override
+ public void addPageDefinition(PageDefinition definition) {
+ getPageDefinitions().add(definition);
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("JcrPageConfiguration");
+ sb.append("{name='").append(name).append('\'');
+ sb.append(", path='").append(path).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,51 @@
+/*
+ * 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.model;
+
+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.PageFragment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+@Node(jcrType = "raveconfig:pagedefinition", extend = JcrPageFragment.class,
discriminator = false)
+public class JcrPageDefinition extends JcrPageFragment implements
PageDefinition {
+
+ private static Logger log =
LoggerFactory.getLogger(JcrPageDefinition.class);
+
+ @Override
+ public PageFragment getParent() {
+ // no parent allowed
+ return null;
+ }
+
+ @Override
+ public void setParent(PageFragment parent) {
+ // no parent allowed, just warn:
+ if (parent == null) {
+ return;
+ }
+ log.warn("### NOT ALLOWED ### Trying to set PageDefinition({}) parent:
{}", this.getName(), parent.getName());
+ }
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageDefinition.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,167 @@
+/*
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Bean;
+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.PageFragment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+@Node(discriminator = false, jcrType = "raveconfig:pagefragment",
jcrMixinTypes = "mix:referenceable")
+public class JcrPageFragment implements PageFragment {
+
+ private static Logger log = LoggerFactory.getLogger(JcrPageFragment.class);
+
+
+ @Field(path = true, id = true)
+ private String path;
+
+ @Field(jcrType = "String")
+ private String reference;
+ @Field(jcrType = "String")
+ private String displayName;
+ @Field(jcrType = "String")
+ private String description;
+ @Field(jcrType = "String")
+ private String controller;
+
+
+ @Field(jcrName = "raveconfig:name", jcrType = "String")
+ private String name;
+
+ @Bean(jcrType = "raveconfig:pagefragment", jcrName =
"raveconfig:parentfragment")
+ private JcrPageFragment parent;
+
+ @Collection(elementClassName = JcrPageFragment.class, jcrName =
"raveconfig:fragmentchildren", jcrType = "raveconfig:pagefragment",
jcrElementName = "raveconfig:fragmentchildren")
+ private List<PageFragment> children;
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public PageFragment getParent() {
+ return parent;
+
+ }
+
+ @Override
+ public void setParent(PageFragment parent) {
+ this.parent = (JcrPageFragment) parent;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+
+ @Override
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ @Override
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public String getController() {
+ return controller;
+ }
+
+ @Override
+ public void setController(String controller) {
+ this.controller = controller;
+ }
+
+ @Override
+ public List<PageFragment> getChildren() {
+ if (children == null) {
+ children = new ArrayList<PageFragment>();
+ }
+ return children;
+ }
+
+ @Override
+ public void setChildren(List<PageFragment> children) {
+ this.children = children;
+ }
+
+ @Override
+ public void addChild(PageFragment child) {
+ getChildren().add(child);
+
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("JcrPageFragment");
+ sb.append("{path='").append(path).append('\'');
+ sb.append(", reference='").append(reference).append('\'');
+ sb.append(", displayName='").append(displayName).append('\'');
+ sb.append(", description='").append(description).append('\'');
+ sb.append(", controller='").append(controller).append('\'');
+ sb.append(", name='").append(name).append('\'');
+ sb.append(", parent=").append(parent);
+ sb.append('}');
+ return sb.toString();
+ }
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/JcrPageFragment.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,72 @@
+/*
+ * 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.model.api;
+
+import java.util.List;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+/**
+ * Page configuration contains PageDefinition and PageFragment
+ *
+ * @version "$Id$"
+ * @see PageDefinition
+ * @see PageFragment
+ */
+@Node(isInterface = true, jcrType = "mix:referenceable", discriminator = false)
+public interface PageConfiguration {
+
+ /**
+ * Configuration name
+ *
+ * @return config name,
+ */
+ String getName();
+
+ /**
+ * Sets configuration name
+ *
+ * @param name configuration name, cannot be null
+ */
+ void setName(String name);
+
+ /**
+ * Returns all page definitions
+ *
+ * @return a list of PageDefinition elements or empty list
+ */
+ List<PageDefinition> getPageDefinitions();
+
+ void setPageDefinitions(List<PageDefinition> definitions);
+
+ /**
+ * Returns all page fragments
+ *
+ * @return a list of PageFragment elements or empty list
+ */
+ List<PageFragment> getPageFragments();
+
+ void setPageFragments(List<PageFragment> fragments);
+
+
+ void addPageFragment(PageFragment fragment);
+
+ void addPageDefinition(PageDefinition definition);
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,30 @@
+/*
+ * 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.model.api;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+/**
+ * @version "$Id$"
+ */
+@Node(isInterface = true, jcrType = "mix:referenceable", discriminator = false)
+public interface PageDefinition extends PageFragment {
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageDefinition.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,98 @@
+/*
+ * 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.model.api;
+
+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 PageFragment {
+
+
+ /**
+ * Sets Node path
+ *
+ * @param path path node is saved to
+ */
+ void setPath(String path);
+
+ /**
+ * Returns node path
+ *
+ * @return node path, should not be null
+ */
+ String getPath();
+
+ /**
+ * Sets name of the fragment
+ *
+ * @param name name of the fragment
+ */
+ void setName(String name);
+
+ /**
+ * Returnd name of the fragment
+ *
+ * @return name of the fragment. Should not be null
+ */
+ String getName();
+
+ /**
+ * Returns PageFragment parent (if any)
+ *
+ * @return null if no parent
+ */
+ PageFragment getParent();
+
+
+ /**
+ * Sets PageFragment parent
+ *
+ * @param parent instance of PageFragment
+ */
+ void setParent(PageFragment parent);
+
+ void setController(String controller);
+
+ String getController();
+
+ void setDescription(String description);
+
+ String getDescription();
+
+ void setDisplayName(String displayName);
+
+ String getDisplayName();
+
+ void setReference(String reference);
+
+ String getReference();
+
+ List<PageFragment> getChildren();
+
+ void setChildren(List<PageFragment> children);
+
+ void addChild(PageFragment child);
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/config/model/api/PageFragment.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/resources/rave-config.cnd
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/resources/rave-config.cnd?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/main/resources/rave-config.cnd
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/main/resources/rave-config.cnd
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,42 @@
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<'raveconfig'='http://www.apache.org/rave/config/1.0'>
+
+[raveconfig:relaxed] mixin
+- * (boolean)
+- * (boolean) multiple
+- * (date)
+- * (date) multiple
+- * (decimal)
+- * (decimal) multiple
+- * (double)
+- * (double) multiple
+- * (long)
+- * (long) multiple
+- * (string)
+- * (string) multiple
+- * (uri)
+- * (uri) multiple
+
+
+[raveconfig:pagefragment] > raveconfig:relaxed
+ + raveconfig:parentfragment (raveconfig:pagefragment)
+ + * (raveconfig:pagefragment) multiple
+
+[raveconfig:pagedefinition] > raveconfig:pagefragment
+
+// collections
+[raveconfig:fragmentcollection]
++ * (raveconfig:pagefragment) multiple
+
+[raveconfig:definitioncollection]
++ * (raveconfig:pagedefinition) multiple
+
+
+
+[raveconfig:pageconfiguration] > raveconfig:relaxed
++ raveconfig:fragmentcollection (raveconfig:fragmentcollection)
++ raveconfig:definitioncollection (raveconfig:definitioncollection)
++ * (raveconfig:pagefragment) multiple
++ * (raveconfig:pagedefinition) multiple
+
+
Added:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public abstract class BaseConfigTest extends AbstractJCRTest {
+
+ private static Logger log = LoggerFactory.getLogger(BaseConfigTest.class);
+ public static final String RAVE_NODE_TYPES_XML = "rave-node-types.xml";
+
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ //registerNamespace(superuser);
+ // registerNamespace(superuser);
+ //registerNodeTypes(superuser);
+
+
+ }
+
+
+ protected void registerNodeTypes(Session session) throws
InvalidNodeTypeDefException, RepositoryException, IOException {
+ InputStream xml = new FileInputStream(getFile(RAVE_NODE_TYPES_XML));
+ QNodeTypeDefinition[] types = NodeTypeReader.read(xml);
+ Workspace workspace = session.getWorkspace();
+ NodeTypeManager ntMgr = workspace.getNodeTypeManager();
+ NodeTypeRegistry ntReg = ((NodeTypeManagerImpl)
ntMgr).getNodeTypeRegistry();
+ for (QNodeTypeDefinition def : types) {
+ try {
+ final Name name = def.getName();
+ log.info("Registering {}", name);
+ ntReg.getNodeTypeDef(name);
+ } catch (NoSuchNodeTypeException nsne) {
+ ntReg.registerNodeType(def);
+ }
+
+ }
+ }
+
+ protected File getFile(final String path) throws
UnsupportedEncodingException {
+ URL url = BaseConfigTest.class.getClassLoader().getResource(path);
+ if (url == null) {
+ return null;
+ }
+ String fileName = URLDecoder.decode(url.toString(),
"UTF-8").substring("file:".length());
+ return new File(fileName);
+ }
+
+ private void registerNamespace(final Session session) throws
RepositoryException {
+ final NamespaceRegistry namespaceRegistry =
superuser.getWorkspace().getNamespaceRegistry();
+ String[] prefixes = namespaceRegistry.getPrefixes();
+ boolean register = true;
+ for (String ns : prefixes) {
+ if (ns.equals("ocm")) {
+ register = false;
+ log.debug("Ocm namespace already registered");
+ }
+ }
+ if (register) {
+ namespaceRegistry.registerNamespace("ocm",
"http://jackrabbit.apache.org/ocm");
+ }
+ }
+
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/BaseConfigTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
URL:
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java?rev=1361935&view=auto
==============================================================================
---
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
(added)
+++
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
Mon Jul 16 08:37:21 2012
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import java.util.List;
+
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class JcrConfigManagerTest extends BaseConfigTest {
+
+ private static Logger log =
LoggerFactory.getLogger(JcrConfigManagerTest.class);
+ public static final String CONFIG_ROOT = "/raveconfig";
+
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+
+ public void testSaveConfiguration() throws Exception {
+ ConfigManager manager = new JcrConfigManager(superuser, CONFIG_ROOT);
+ final PageConfiguration configuration = new JcrPageConfiguration();
+ final String configName = "myName";
+ configuration.setName(configName);
+ manager.saveConfiguration(configuration);
+ PageConfiguration retrievedConfiguration =
manager.loadConfiguration(configName);
+ assertTrue(retrievedConfiguration != null);
+ // add some fragments:
+
+ final PageFragment fragment = new JcrPageFragment();
+ fragment.setPath("fragment1");
+ fragment.setName("fragment1");
+ fragment.setController("controller");
+ fragment.setDescription("description");
+ fragment.setDisplayName("displayName");
+ configuration.addPageFragment(fragment);
+ final PageFragment fragment2 = new JcrPageFragment();
+ fragment2.setPath("fragment2");
+ fragment2.setName("fragment2");
+ configuration.addPageFragment(fragment2);
+ // add kid fragment
+ final PageFragment kid = new JcrPageFragment();
+ kid.setName("kid");
+ kid.setPath("kid");
+ fragment.addChild(kid);
+
+ // add page definitions
+ final PageDefinition definition = new JcrPageDefinition();
+ definition.setPath("def1");
+ definition.setName("def1");
+ configuration.addPageDefinition(definition);
+ final PageDefinition definition2 = new JcrPageDefinition();
+ definition2.setPath("def2");
+ definition2.setName("def2");
+ configuration.addPageDefinition(definition2);
+
+
+ manager.saveConfiguration(configuration);
+ retrievedConfiguration = manager.loadConfiguration(configName);
+ assertTrue(retrievedConfiguration != null);
+ final List<PageFragment> pageFragments =
retrievedConfiguration.getPageFragments();
+ assertEquals(pageFragments.size(), 2);
+ assertEquals(retrievedConfiguration.getPageDefinitions().size(), 2);
+ for (PageFragment pageFragment : pageFragments) {
+ if (pageFragment.getName().equals("fragment1")) {
+ assertEquals("displayName", pageFragment.getDisplayName());
+ assertEquals("description", pageFragment.getDescription());
+ assertEquals("kid",
pageFragment.getChildren().get(0).getName());
+ }
+ }
+ }
+
+
+}
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/config/JcrConfigManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Id