Author: marijan
Date: Wed Jul  4 11:34:02 2012
New Revision: 1357228

URL: http://svn.apache.org/viewvc?rev=1357228&view=rev
Log:
RAVE-700 Provide basic PageDefinition filesystem storage using json or xml

- xml version, first cut

Added:
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
   (with props)
    
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/
    
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/FilePageConfigDaoTest.java
   (with props)
    rave/sandbox/content-services/rave-web-hmvc/src/test/resources/
    
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
   (with props)
    rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml   
(with props)

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.exceptions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version "$Id$"
+ */
+public class InvalidConfigurationException extends RuntimeException {
+
+    private static Logger log = 
LoggerFactory.getLogger(InvalidConfigurationException.class);
+
+    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-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/exceptions/InvalidConfigurationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.rave.portal.web.exceptions.InvalidConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+
+/**
+ * @version "$Id$"
+ */
+public class FilePageConfigDao implements PageConfigDao {
+
+    private static Logger log = 
LoggerFactory.getLogger(FilePageConfigDao.class);
+
+    public static final String FILE_PATH_PREFIX = "file:";
+    public static final String CLASSPATH_PREFIX = "classpath:";
+
+
+    @Override
+    public PageConfig loadConfig(String path) throws 
InvalidConfigurationException {
+
+        FileInputStream is = null;
+        try {
+            File file = getResourceFile(path);
+            if (file == null) {
+                throw new InvalidConfigurationException("Configuration file 
not found for path: " + path);
+            }
+            JAXBContext context = JAXBContext.newInstance(PageConfig.class);
+            Unmarshaller unmarshaller = context.createUnmarshaller();
+            is = new FileInputStream(file);
+            final PageConfig pageConfig = (PageConfig) 
unmarshaller.unmarshal(is);
+            if (pageConfig != null) {
+                pageConfig.initialize();
+            }
+
+            return pageConfig;
+        } catch (JAXBException e) {
+            throw new InvalidConfigurationException("Error parsing 
configuration file: " + path, e);
+        } catch (FileNotFoundException e) {
+            throw new InvalidConfigurationException("Configuration file not 
found for path: " + path, e);
+        } finally {
+            IOUtils.closeQuietly(is);
+        }
+
+
+    }
+
+
+    /**
+     * 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
+     */
+    private 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 = 
FilePageConfigDao.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);
+        }
+    }
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/FilePageConfigDao.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.rave.portal.web.model.PageDefinition;
+import org.apache.rave.portal.web.model.PageFragment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @version "$Id$"
+ */
+@XmlRootElement(name = "configuration")
+public class PageConfig {
+
+    private static final Logger log = 
LoggerFactory.getLogger(PageConfig.class);
+    private String name;
+
+    /**
+     * Flag which indicates if all components are parsed and initialized.
+     */
+    private boolean initialized;
+
+    private List<PageDefinitionConfig> definitions;
+
+    private List<PageFragmentConfig> pageFragments;
+
+    private Map<String, PageDefinition> pageDefinitionsMap;
+    private Map<String, PageFragment> fragmentDefinitionsMap;
+
+
+    /**
+     * Returns populated list of PageDefinition objects. Once populated, this 
list is cached.
+     *
+     * @return empty list if no PageDefinitions are defined, a populated list 
of PageDefinition objects otherwise.
+     */
+    @XmlTransient
+    public Collection<PageDefinition> getPageDefinitions() {
+        return getPageDefinitionsMap().values();
+    }
+
+    public final void initialize() {
+        if (!initialized) {
+            // initialize definitions first
+            initializeDefinitions();
+            initializeFragments();
+            initialized = true;
+        }
+    }
+
+
+    private void initializeDefinitions() {
+        if (initialized) {
+            return;
+        }
+        PageDefinition pageDefinition = null;
+        for (PageDefinitionConfig definition : definitions) {
+            // load references and parents:
+            final String definitionName = definition.getName();
+            if (StringUtils.isEmpty(definitionName)) {
+                log.warn("PageDefinition is invalid: it has no name, skipping: 
 {}", definition);
+                continue;
+            }
+            String path = definition.getPath();
+            if (path == null) {
+                path = definitionName;
+            }
+            pageDefinition = new PageDefinition(path, definitionName);
+            if (getPageDefinitionsMap().get(definitionName) != null) {
+                log.warn("Skipping PageDefinition for name: [{}] because it is 
" +
+                        "defined twice, only first one will be included. 
Please use unique PageDefinition name", pageDefinition);
+                continue;
+            }
+            getPageDefinitionsMap().put(definitionName, pageDefinition);
+
+        }
+        if (pageDefinition == null) {
+            return;
+        }
+        // process kids (page definition has no parent):
+        for (PageDefinitionConfig definition : definitions) {
+            final List<PageFragmentConfig> children = definition.getChildren();
+            for (PageFragmentConfig child : children) {
+                final String id = String.format("%s%s", definition.getPath(), 
child.getPath());
+                log.debug("Adding child fragment, id: [ {} ]", id);
+                final PageFragment fragment = new PageFragment(id, 
child.getName());
+                List<PageFragment> parentChildren = 
pageDefinition.getChildren();
+                parentChildren.add(fragment);
+            }
+        }
+    }
+
+
+    private void initializeFragments() {
+        if (initialized) {
+            return;
+        }
+        // initialize fragment kids first and merge parent components 
afterwards
+        for (PageFragmentConfig pageFragment : pageFragments) {
+            final String fragmentName = pageFragment.getName();
+            PageFragment fragment = new PageFragment(pageFragment.getPath(), 
fragmentName);
+            mergeFragmentChildren(fragment, pageFragment);
+
+
+            getFragmentDefinitionsMap().put(fragmentName, fragment);
+        }
+
+
+        // merge with parent child components
+        for (PageFragmentConfig pageFragment : pageFragments) {
+            final String parent = pageFragment.getParent();
+            if (StringUtils.isNotBlank(parent)) {
+                // lookup parent:
+                final PageDefinition pageDefinition = 
getPageDefinitionsMap().get(parent);
+                if (pageDefinition == null) {
+                    log.warn("Skipping populating of item: parent with name 
[{}]  could not be found for PageFragment with name  [{}].", parent, 
pageFragment.getName());
+                    continue;
+                }
+                final PageFragment fragment = 
getFragmentDefinitionsMap().get(pageFragment.getName());
+                fragment.setParent(pageDefinition);
+                fragment.setId(String.format("%s%s", pageDefinition.getPath(), 
fragment.getId()));
+                mergeFragment(fragment);
+            }
+        }
+
+    }
+
+    private void mergeFragmentChildren(PageFragment owner, PageFragmentConfig 
pageFragment) {
+        final List<PageFragmentConfig> fragmentChildren = 
pageFragment.getChildren();
+        if (fragmentChildren != null) {
+            final List<PageFragment> children = owner.getChildren();
+            for (PageFragmentConfig child : fragmentChildren) {
+                final PageFragment fragment = createFragment(child);
+                children.add(fragment);
+            }
+        }
+    }
+
+    private PageFragment createFragment(PageFragmentConfig pageFragment) {
+        final PageFragment fragment = new PageFragment(null, 
pageFragment.getName());
+        fragment.setSrc(pageFragment.getSrc());
+        fragment.setType(pageFragment.getType());
+        fragment.setController(pageFragment.getController());
+        return fragment;
+    }
+
+    public void mergeFragment(PageFragment fragment) {
+        final PageFragment parent = fragment.getParent();
+        if (parent != null) {
+            log.debug("@merging fragment:[ {} ] with parent:[ {} ]", 
fragment.getName(), parent.getName());
+            // merge first level and it's kids
+            final List<PageFragment> parentChildren = parent.getChildren();
+            final List<PageFragment> children = fragment.getChildren();
+            for (PageFragment parentChild : parentChildren) {
+                if (!contains(fragment, parentChild)) {
+                    log.info("Adding child fragment:[ {} ] from parent", 
parentChild.getName());
+                    children.add(parentChild);
+                } else {
+                    log.debug("Skipping parent:[ {} ] fragment because are 
overriding it.", parentChild.getName());
+                }
+            }
+
+        }
+    }
+
+    private boolean contains(PageFragment fragment, PageFragment parentChild) {
+        final List<PageFragment> children = fragment.getChildren();
+        for (PageFragment child : children) {
+            if (parentChild.getName().equals(child.getName())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @XmlTransient
+    public Map<String, PageFragment> getFragmentDefinitionsMap() {
+        if (fragmentDefinitionsMap == null) {
+            fragmentDefinitionsMap = new HashMap<String, PageFragment>();
+        }
+        return fragmentDefinitionsMap;
+    }
+
+
+    @XmlTransient
+    public Map<String, PageDefinition> getPageDefinitionsMap() {
+        if (pageDefinitionsMap == null) {
+            pageDefinitionsMap = new HashMap<String, PageDefinition>();
+        }
+        return pageDefinitionsMap;
+    }
+
+
+    @XmlTransient
+    public Collection<PageFragment> getFragmentDefinitions() {
+        return getFragmentDefinitionsMap().values();
+    }
+
+
+    @XmlElement(name = "page-definition", type = PageDefinitionConfig.class)
+    public List<PageDefinitionConfig> getDefinitions() {
+        return definitions;
+    }
+
+
+    public void setDefinitions(List<PageDefinitionConfig> definitions) {
+        this.definitions = definitions;
+    }
+
+    @XmlAttribute
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    @XmlElement(name = "page-fragment", type = PageFragmentConfig.class)
+    public List<PageFragmentConfig> getPageFragments() {
+        return pageFragments;
+    }
+
+    public void setPageFragments(List<PageFragmentConfig> pageFragments) {
+        this.pageFragments = pageFragments;
+    }
+
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("PageConfig");
+        sb.append("{name='").append(name).append('\'');
+        sb.append(", definitions=").append(definitions);
+        sb.append('}');
+        return sb.toString();
+    }
+
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfig.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.apache.rave.portal.web.exceptions.InvalidConfigurationException;
+
+/**
+ * Page definitions loader
+ *
+ * @version "$Id$"
+ */
+public interface PageConfigDao {
+
+
+    /**
+     * Load page definitions configuration file for given path
+     *
+     * @param path path to load configuration from
+     * @return populated configuration
+     * @throws InvalidConfigurationException exception is thrown when file is 
not found or invalid (e.g. when file could not be found)
+     */
+    PageConfig loadConfig(final String path) throws 
InvalidConfigurationException;
+
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageConfigDao.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version "$Id$"
+ */
+@XmlRootElement(name = "page-definition")
+public class PageDefinitionConfig extends PageFragmentConfig {
+
+    private static Logger log = 
LoggerFactory.getLogger(PageDefinitionConfig.class);
+
+
+    @Override
+    public String getParent() {
+        // page definition cannot have a parent
+        return null;
+    }
+
+    @Override
+    public void setParent(String parent) {
+        // we have no parent
+        //throw new InvalidConfigurationException("PageDefinition cannot have 
a parent");
+    }
+
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("PageDefinitionConfig {");
+        sb.append(super.toString());
+        sb.append("{parent=").append(getParent());
+        sb.append('}');
+        return sb.toString();
+    }
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageDefinitionConfig.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+import static org.apache.rave.portal.web.model.PageFragment.TYPE;
+
+/**
+ * @version "$Id$"
+ */
+@XmlRootElement(name = "page-fragment")
+public class PageFragmentConfig {
+
+    private static Logger log = 
LoggerFactory.getLogger(PageFragmentConfig.class);
+
+
+    private String parent;
+    private String reference;
+    private String name;
+    private String path;
+    private String displayName;
+    private String description;
+    private TYPE type = TYPE.TEMPLATE;
+    private String src;
+    private String controller;
+    private List<PageFragmentConfig> children;
+
+
+    @XmlAttribute
+    public String getReference() {
+        return reference;
+    }
+
+    public void setReference(String reference) {
+        this.reference = reference;
+    }
+
+    @XmlAttribute
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    @XmlAttribute
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public void setDisplayName(String displayName) {
+        this.displayName = displayName;
+    }
+
+    @XmlAttribute
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @XmlAttribute
+    public TYPE getType() {
+        return type;
+    }
+
+    public void setType(TYPE type) {
+        this.type = type;
+    }
+
+    @XmlAttribute
+    public String getSrc() {
+        return src;
+    }
+
+    public void setSrc(String src) {
+        this.src = src;
+    }
+
+    @XmlAttribute
+    public String getController() {
+        return controller;
+    }
+
+    public void setController(String controller) {
+        this.controller = controller;
+    }
+
+
+    @XmlElementRef(name = "page-fragment", type = PageFragmentConfig.class)
+    public List<PageFragmentConfig> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<PageFragmentConfig> children) {
+        this.children = children;
+    }
+
+    @XmlAttribute
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    @XmlAttribute
+    public String getParent() {
+        return parent;
+    }
+
+    public void setParent(String parentName) {
+        this.parent = parentName;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("PageFragmentConfig");
+        sb.append("{parent=").append(parent);
+        sb.append(", reference=").append(reference);
+        sb.append(", name='").append(name).append('\'');
+        sb.append(", path='").append(path).append('\'');
+        sb.append(", displayName='").append(displayName).append('\'');
+        sb.append(", description='").append(description).append('\'');
+        sb.append(", type=").append(type);
+        sb.append(", src='").append(src).append('\'');
+        sb.append(", controller='").append(controller).append('\'');
+        sb.append(", children=").append(children);
+        sb.append('}');
+        return sb.toString();
+    }
+}

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/main/java/org/apache/rave/portal/web/model/config/PageFragmentConfig.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/FilePageConfigDaoTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/FilePageConfigDaoTest.java?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/FilePageConfigDaoTest.java
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/java/org/apache/rave/portal/web/model/config/FilePageConfigDaoTest.java
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.model.config;
+
+import org.apache.rave.portal.web.exceptions.InvalidConfigurationException;
+import org.apache.rave.portal.web.model.PageDefinition;
+import org.apache.rave.portal.web.model.PageFragment;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import static junit.framework.Assert.*;
+
+/**
+ * @version "$Id$"
+ */
+public class FilePageConfigDaoTest {
+
+    private static Logger log = 
LoggerFactory.getLogger(FilePageConfigDaoTest.class);
+
+    @Test
+    public void testLoadConfig() throws Exception {
+        PageConfigDao dao = new FilePageConfigDao();
+        final PageConfig config = 
dao.loadConfig(FilePageConfigDao.CLASSPATH_PREFIX + 
"example_configuration.xml");
+        assertNotNull(config);
+        assertEquals("default", config.getName());
+        // expected only standard page
+        final List<PageDefinitionConfig> definitions = config.getDefinitions();
+        assertEquals(1, definitions.size());
+        final Collection<PageDefinition> pageDefinitions = 
config.getPageDefinitions();
+        assertEquals(1, pageDefinitions.size()); // make sure it is parsed 
properly
+        // expected 2 page fragments
+        final Collection<PageFragment> kids = config.getFragmentDefinitions();
+        assertEquals(2, kids.size());
+        //our fragments should have parent page:
+        final PageDefinitionConfig standardPage = definitions.get(0);
+        for (PageFragment kid : kids) {
+            final PageFragment parent = kid.getParent();
+            assertTrue("Expected valid parent, but found null", parent != 
null);
+            assertTrue(parent.getName().equals(standardPage.getName()));
+        }
+
+        final Map<String, PageFragment> fragmentDefinitionsMap = 
config.getFragmentDefinitionsMap();
+        final PageFragment adminFragment = 
fragmentDefinitionsMap.get("adminPage");
+        final List<PageFragment> adminKids = adminFragment.getChildren();
+        assertEquals(2, adminKids.size());
+        // admin should have header from page definition
+        PageDefinition standard = pageDefinitions.iterator().next();
+        final List<PageFragment> children = standard.getChildren();
+        PageFragment standardHeader = null;
+        for (PageFragment child : children) {
+            if (child.getName().equals("header")) {
+                standardHeader = child;
+                log.debug("found header");
+                break;
+
+            }
+        }
+        assertTrue(standardHeader != null);
+        assertTrue(adminKids.contains(standardHeader));
+        log.info("config {}", config);
+
+    }
+
+
+    @Test(expected = InvalidConfigurationException.class)
+    public void testLoadConfigFail() throws Exception {
+        PageConfigDao dao = new FilePageConfigDao();
+        // this should throw InvalidConfigurationException exception
+        final PageConfig pageConfig = 
dao.loadConfig(FilePageConfigDao.CLASSPATH_PREFIX + 
"NONE_EXISTING_example_configuration.xml");
+    }
+
+}

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

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

Added: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml?rev=1357228&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
 (added)
+++ 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
 Wed Jul  4 11:34:02 2012
@@ -0,0 +1,60 @@
+<?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.
+-->
+<configuration name="default">
+    <!--
+        STANDARD PAGE (HAS NO PARENT)
+    -->
+    <page-definition name="standard" description="Page that is being extended 
by other pages"
+                     displayname="Standard page"
+                     owner="testUser" src="standard.jsp" type="TEMPLATE" 
path="/standard">
+        <page-fragment name="header" path="/header">
+            <page-fragment name="headerController" 
class="com.test.HeaderController" src="header.jsp" type="COMPONENT"/>
+        </page-fragment>
+        <page-fragment name="footer" path="/footer">
+            <page-fragment name="nullController" 
class="com.test.ViewController" src="footer.jsp" type="COMPONENT"/>
+        </page-fragment>
+    </page-definition>
+
+
+    <!--
+        LOGIN PAGE (extends STANDARD page)
+    -->
+    <page-fragment name="loginPage" path="/login" description="Login screen" 
parent="standard">
+        <page-fragment name="header" path="/header">
+            <page-fragment name="headerController" 
class="com.test.LoginHeaderController" src="login.jsp"/>
+        </page-fragment>
+        <page-fragment name="body" path="/body">
+            <page-fragment name="headerController" 
class="com.test.LoginHeaderController" src="login.jsp"/>
+        </page-fragment>
+    </page-fragment>
+
+
+    <!--
+        ADMIN PAGE (extends STANDARD page)
+    -->
+    <page-fragment name="adminPage" path="/admin" description="User 
administration pages" src="admin.jsp"
+                   parent="standard">
+        <!-- @overrides footer-->
+        <page-fragment name="footer" path="/footer" src="myFooter.jsp">
+            <page-fragment name="footerController" 
class="com.test.FooterController"/>
+        </page-fragment>
+
+    </page-fragment>
+</configuration>

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/example_configuration.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml?rev=1357228&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml 
(added)
+++ rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml 
Wed Jul  4 11:34:02 2012
@@ -0,0 +1,59 @@
+<?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="%-5p - [%-80m] - at 
%c.%M(%F:%L)%n"/>
+        </layout>
+        <filter class="org.apache.log4j.varia.LevelRangeFilter">
+            <param name="levelMin" value="DEBUG"/>
+        </filter>
+    </appender>
+
+    <!-- 
====================================================================== -->
+    <!-- L O G G E R S                                                         
 -->
+    <!-- 
====================================================================== -->
+
+    <category name="org.apache.jackrabbit">
+        <level value="warn"/>
+    </category>
+
+    <category name="org.apache.rave.portal.web.hmvc">
+        <level value="debug"/>
+    </category>
+
+    <root>
+        <level value="debug"/>
+        <appender-ref ref="console"/>
+    </root>
+
+</log4j:configuration>
+

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
rave/sandbox/content-services/rave-web-hmvc/src/test/resources/log4j.xml
------------------------------------------------------------------------------
    svn:keywords = Id


Reply via email to