JBoss PortletSwap SVN: r226 - src/server/trunk/server-webapp/src/test/resources.
by portletswap-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2008-01-28 08:27:30 -0500 (Mon, 28 Jan 2008)
New Revision: 226
Added:
src/server/trunk/server-webapp/src/test/resources/resultGetArtifacts.xml
Log:
Added: src/server/trunk/server-webapp/src/test/resources/resultGetArtifacts.xml
===================================================================
--- src/server/trunk/server-webapp/src/test/resources/resultGetArtifacts.xml (rev 0)
+++ src/server/trunk/server-webapp/src/test/resources/resultGetArtifacts.xml 2008-01-28 13:27:30 UTC (rev 226)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<result xmlns="http://www.portletswap.com/directory">
+ <artifacts>
+ <artifact id="id1">
+ <license id="LGPL">LGPL</license>
+ </artifact>
+ </artifacts>
+</result>
\ No newline at end of file
16 years, 2 months
JBoss PortletSwap SVN: r225 - src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter.
by portletswap-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2008-01-28 08:27:10 -0500 (Mon, 28 Jan 2008)
New Revision: 225
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
Log:
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java 2008-01-28 13:27:10 UTC (rev 225)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter;
+
+import org.jboss.portletswap.model.Category;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface CategoryFilter
+{
+
+ public boolean accept(Category category);
+}
+
16 years, 2 months
JBoss PortletSwap SVN: r224 - in src/server/trunk: server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl and 13 other directories.
by portletswap-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2008-01-28 08:26:48 -0500 (Mon, 28 Jan 2008)
New Revision: 224
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/AbstractDirectoryService.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/ModuleFilter.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/CategoryFilter.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/TypeFilter.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/CompatibilityLevel.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/DisplayNameModel.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModel.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelFactory.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelProvider.java
src/server/trunk/server-webapp/src/main/resources/result.xsd
src/server/trunk/server-webapp/src/test/resources/resultGetCategories.xml
Removed:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/Filter.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/TypeFilter.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/DisplayNameModel.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModel.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelFactory.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelProvider.java
src/server/trunk/server-webapp/src/main/resources/result.xsd
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/DirectoryService.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/License.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/MarshallerTestCase.java
src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/UnMarshallerTestCase.java
Log:
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/DirectoryService.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/DirectoryService.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/DirectoryService.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -24,10 +24,10 @@
import java.util.List;
-import org.jboss.portletswap.filter.Filter;
+import org.jboss.portletswap.filter.ModuleFilter;
+import org.jboss.portletswap.filter.CategoryFilter;
import org.jboss.portletswap.model.Category;
import org.jboss.portletswap.model.Module;
-import org.jboss.portletswap.model.Type;
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
@@ -48,23 +48,16 @@
*/
public List<Module> getModules(boolean published, Ordering ordering);
- public List<Module> getModules(boolean published, Type type);
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters);
- public List<Module> getModules(boolean published, Type type, Ordering ordering);
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters, Ordering ordering);
- public List<Module> getModules(boolean published, Category category);
+ public List<Category> getCategories(boolean published);
- public List<Module> getModules(boolean published, Category category, Ordering ordering);
+ public List<Category> getCategories(boolean published, Ordering ordering);
- public List<Module> getModules(boolean published, Filter filter);
+ public List<Category> getCategories(boolean published, List<CategoryFilter> filters);
- public List<Module> getModules(boolean published, Filter filter, Ordering ordering);
-
- public List<Module> getModules(boolean published, List<Filter> filters);
-
- public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering);
-
- public List<Category> getCategories(boolean published);
-
+ public List<Category> getCategories(boolean published, List<CategoryFilter> filters, Ordering ordering);
}
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/AbstractDirectoryService.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/AbstractDirectoryService.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/AbstractDirectoryService.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.directory.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.portletswap.DirectoryService;
+import org.jboss.portletswap.Ordering;
+import org.jboss.portletswap.filter.CategoryFilter;
+import org.jboss.portletswap.filter.ModuleFilter;
+import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.Module;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class AbstractDirectoryService implements DirectoryService
+{
+
+ public List<Category> getCategories(boolean published)
+ {
+ return getCategories(published, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public List<Category> getCategories(boolean published, Ordering ordering)
+ {
+ return getCategories(published, new ArrayList<CategoryFilter>(), ordering);
+ }
+
+ public List<Category> getCategories(boolean published, List<CategoryFilter> filters)
+ {
+ return getCategories(published, filters, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public abstract List<Category> getCategories(boolean published, List<CategoryFilter> filters, Ordering ordering);
+
+ public List<Module> getModules(boolean published)
+ {
+ return getModules(published, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public List<Module> getModules(boolean published, Ordering ordering)
+ {
+ return getModules(published, new ArrayList<ModuleFilter>(), ordering);
+ }
+
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters)
+ {
+ return getModules(published, filters, Ordering.NO_SPECIAL_ORDER);
+ }
+
+ public abstract List<Module> getModules(boolean published, List<ModuleFilter> filters, Ordering ordering);
+
+}
+
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceImpl.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.List;
-import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
@@ -35,10 +34,10 @@
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
-import org.jboss.portletswap.DirectoryService;
import org.jboss.portletswap.Ordering;
-import org.jboss.portletswap.model.Type;
-import org.jboss.portletswap.filter.Filter;
+import org.jboss.portletswap.directory.impl.AbstractDirectoryService;
+import org.jboss.portletswap.filter.CategoryFilter;
+import org.jboss.portletswap.filter.ModuleFilter;
import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.Category;
import org.jboss.portletswap.model.Module;
@@ -50,7 +49,7 @@
* @version $Revision$
*/
@SuppressWarnings("serial")
-public class DirectoryServiceImpl implements DirectoryService, Serializable
+public class DirectoryServiceImpl extends AbstractDirectoryService implements Serializable
{
@@ -66,12 +65,25 @@
this.jcrService = jcrService;
}
- public List<Module> getModules(boolean published)
+ private String orderby(Ordering ordering)
{
- return getModules(published, Ordering.NO_SPECIAL_ORDER);
+ if (Ordering.NAME_ASC.equals(ordering.name()))
+ {
+ return "ORDER BY ps:name";
+ }
+ else if (Ordering.NAME_DESC.equals(ordering.name()))
+ {
+ return " ORDER BY ps:name DESC";
+ }
+ else if (Ordering.NO_SPECIAL_ORDER.equals(ordering.name()))
+ {
+ return "";
+ }
+ return "";
}
- public List<Module> getModules(boolean published, Ordering ordering)
+ /*
+ public List<Module> getModules(boolean published, Category category)
{
String workspace = JCRService.MODULE_WORKSPACE_NAME;
if (published)
@@ -84,7 +96,7 @@
{
session = jcrService.openSession(workspace);
QueryManager queryManager = session.getWorkspace().getQueryManager();
- Query query = queryManager.createQuery("SELECT * from ps:module " + orderby(ordering), Query.SQL);
+ Query query = queryManager.createQuery("SELECT * from ps:module where ps:categories = '" + category.getId() + "'", Query.SQL);
QueryResult queryResult = query.execute();
NodeIterator it = queryResult.getNodes();
@@ -113,38 +125,11 @@
}
return null;
}
+ */
- private String orderby(Ordering ordering)
+ @Override
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters, Ordering ordering)
{
- if (Ordering.NAME_ASC.equals(ordering.name()))
- {
- return "ORDER BY ps:name";
- }
- else if (Ordering.NAME_DESC.equals(ordering.name()))
- {
- return " ORDER BY ps:name DESC";
- }
- else if (Ordering.NO_SPECIAL_ORDER.equals(ordering.name()))
- {
- return "";
- }
- return "";
- }
-
- public List<Module> getModules(boolean published, Type type)
- {
- // FIXME getModules
- return null;
- }
-
- public List<Module> getModules(boolean published, Type type, Ordering ordering)
- {
- // FIXME getModules
- return null;
- }
-
- public List<Module> getModules(boolean published, Category category)
- {
String workspace = JCRService.MODULE_WORKSPACE_NAME;
if (published)
{
@@ -156,7 +141,7 @@
{
session = jcrService.openSession(workspace);
QueryManager queryManager = session.getWorkspace().getQueryManager();
- Query query = queryManager.createQuery("SELECT * from ps:module where ps:categories = '" + category.getId() + "'", Query.SQL);
+ Query query = queryManager.createQuery("SELECT * from " + JCRModuleImpl.NODE_TYPE + " " + orderby(ordering), Query.SQL);
QueryResult queryResult = query.execute();
NodeIterator it = queryResult.getNodes();
@@ -164,17 +149,17 @@
while (it.hasNext())
{
Node node = it.nextNode();
- if (node.isNodeType("ps:module"))
+ if (node.isNodeType(JCRModuleImpl.NODE_TYPE))
{
- result.add(new JCRModuleImpl(jcrService, node));
+ Module module = new JCRModuleImpl(jcrService, node);
+ if (acceptModule(filters, module))
+ {
+ result.add(new JCRModuleImpl(jcrService, node));
+ }
}
}
return result;
}
- catch (ItemNotFoundException e)
- {
- return null;
- }
catch (RepositoryException e)
{
e.printStackTrace();
@@ -185,39 +170,34 @@
}
return null;
}
-
- public List<Module> getModules(boolean published, Category category, Ordering ordering)
+
+ public boolean acceptModule(List<ModuleFilter> filters, Module module)
{
- // FIXME getModules
- return null;
+ for (ModuleFilter filter: filters)
+ {
+ if (!filter.accept(module))
+ {
+ return false;
+ }
+ }
+ return true;
}
- public List<Module> getModules(boolean published, Filter filter)
+ public boolean acceptCategory(List<CategoryFilter> filters, Category category)
{
- // FIXME getModules
- return null;
+ for (CategoryFilter filter: filters)
+ {
+ if (!filter.accept(category))
+ {
+ return false;
+ }
+ }
+ return true;
}
- public List<Module> getModules(boolean published, Filter filter, Ordering ordering)
+ @Override
+ public List<Category> getCategories(boolean published, List<CategoryFilter> filters, Ordering ordering)
{
- // FIXME getModules
- return null;
- }
-
- public List<Module> getModules(boolean published, List<Filter> filters)
- {
- // FIXME getModules
- return null;
- }
-
- public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering)
- {
- // FIXME getModules
- return null;
- }
-
- public List<Category> getCategories(boolean published)
- {
String workspace = JCRService.MODULE_WORKSPACE_NAME;
if (published)
{
@@ -237,7 +217,11 @@
while (it.hasNext())
{
Node node = it.nextNode();
- result.add(new JCRCategoryImpl(jcrService, node));
+ Category category = new JCRCategoryImpl(jcrService, node);
+ if (acceptCategory(filters, category))
+ {
+ result.add(category);
+ }
}
return result;
}
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/directory/impl/memory/DirectoryServiceImpl.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -32,12 +32,11 @@
import java.util.TreeSet;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portletswap.DirectoryService;
import org.jboss.portletswap.Ordering;
import org.jboss.portletswap.model.Type;
-import org.jboss.portletswap.filter.CategoryFilter;
-import org.jboss.portletswap.filter.Filter;
-import org.jboss.portletswap.filter.TypeFilter;
+import org.jboss.portletswap.filter.ModuleFilter;
+import org.jboss.portletswap.filter.module.CategoryFilter;
+import org.jboss.portletswap.filter.module.TypeFilter;
import org.jboss.portletswap.model.Category;
import org.jboss.portletswap.model.Module;
@@ -45,7 +44,7 @@
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @version $Revision$
*/
-public class DirectoryServiceImpl implements DirectoryService
+public class DirectoryServiceImpl extends org.jboss.portletswap.directory.impl.AbstractDirectoryService
{
private Map<Object, Module> modules;
@@ -83,25 +82,25 @@
public List<Module> getModules(boolean published, Category category, Ordering ordering)
{
- List<Filter> filters = new ArrayList<Filter>();
+ List<ModuleFilter> filters = new ArrayList<ModuleFilter>();
filters.add(new CategoryFilter(category));
return getModules(published, filters);
}
- public List<Module> getModules(boolean published, Filter filter)
+ public List<Module> getModules(boolean published, ModuleFilter filter)
{
return getModules(published, filter, Ordering.NO_SPECIAL_ORDER);
}
- public List<Module> getModules(boolean published, Filter filter, Ordering ordering)
+ public List<Module> getModules(boolean published, ModuleFilter filter, Ordering ordering)
{
- List<Filter> list = new ArrayList<Filter>();
+ List<ModuleFilter> list = new ArrayList<ModuleFilter>();
list.add(filter);
return getModules(published, list, ordering);
}
- public List<Module> getModules(boolean published, List<Filter> filters, Ordering ordering)
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters, Ordering ordering)
{
Set<Module> result = null;
Comparator<Module> comparator = getComparator(ordering);
@@ -116,7 +115,7 @@
for(Module module: modules.values())
{
boolean accept = true;
- for (Filter filter:filters)
+ for (ModuleFilter filter:filters)
{
if (!filter.accept(module))
{
@@ -131,7 +130,7 @@
return Tools.toList(result.iterator());
}
- public List<Module> getModules(boolean published, List<Filter> filters)
+ public List<Module> getModules(boolean published, List<ModuleFilter> filters)
{
return getModules(published, filters, Ordering.NO_SPECIAL_ORDER);
}
@@ -162,7 +161,9 @@
return null;
}
- public List<Category> getCategories(boolean published)
+ @Override
+ public List<Category> getCategories(boolean published, List<org.jboss.portletswap.filter.CategoryFilter> filters,
+ Ordering ordering)
{
// FIXME getCategories
return null;
Deleted: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,56 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.filter;
-
-import org.jboss.portletswap.model.Category;
-import org.jboss.portletswap.model.Module;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class CategoryFilter implements Filter
-{
-
- private Category category;
-
- public CategoryFilter(Category category)
- {
- this.category = category;
- }
-
- public boolean accept(Module module)
- {
- /** TODO: do it recursively */
- if (module.getCategories().contains(category))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-}
-
Deleted: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/Filter.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/Filter.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/Filter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,36 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.filter;
-
-import org.jboss.portletswap.model.Module;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public interface Filter
-{
-
- public boolean accept(Module module);
-}
-
Copied: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/ModuleFilter.java (from rev 216, src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/Filter.java)
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/ModuleFilter.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/ModuleFilter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter;
+
+import org.jboss.portletswap.model.Module;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface ModuleFilter
+{
+
+ public boolean accept(Module module);
+}
+
Deleted: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/TypeFilter.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/TypeFilter.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/TypeFilter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,55 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.filter;
-
-import org.jboss.portletswap.model.Type;
-import org.jboss.portletswap.model.Module;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class TypeFilter implements Filter
-{
-
- private Type type;
-
- public TypeFilter(Type type)
- {
- this.type = type;
- }
-
- public boolean accept(Module module)
- {
- if (module.getType().equals(type))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-}
-
Copied: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/CategoryFilter.java (from rev 216, src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/CategoryFilter.java)
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/CategoryFilter.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/CategoryFilter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter.module;
+
+import java.util.List;
+
+import org.jboss.portletswap.filter.ModuleFilter;
+import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.Module;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CategoryFilter implements ModuleFilter
+{
+
+ private Category category;
+
+ public CategoryFilter(Category category)
+ {
+ this.category = category;
+ }
+
+ public boolean accept(Module module)
+ {
+ List<Category> categories = module.getCategories();
+
+ for (Category tmpCategory: categories)
+ {
+ if (category.getId().equals(tmpCategory.getId()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
+
Copied: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/TypeFilter.java (from rev 216, src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/TypeFilter.java)
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/TypeFilter.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/filter/module/TypeFilter.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.filter.module;
+
+import org.jboss.portletswap.filter.ModuleFilter;
+import org.jboss.portletswap.model.Type;
+import org.jboss.portletswap.model.Module;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class TypeFilter implements ModuleFilter
+{
+
+ private Type type;
+
+ public TypeFilter(Type type)
+ {
+ this.type = type;
+ }
+
+ public boolean accept(Module module)
+ {
+ if (module.getType().equals(type))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+}
+
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -55,6 +55,7 @@
public static final String ROOT_MODULE_NODENAME = "org.jboss.portletswap.root_module";
public static final String NODE_NAME = "ps:module";
+ public static final String NODE_TYPE = "ps:module";
public static final String DESCRIPTION_NODENAME = "ps:description";
public static final String ARTIFACTS_NODENAME = "ps:artifacts";
public static final String DESCRIPTION_LANG_ATTRIBUTENAME = "jcr:language";
Modified: src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/directory/impl/jcr/DirectoryServiceTestCase.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -25,6 +25,7 @@
import static org.jboss.unit.api.Assert.assertEquals;
import static org.jboss.unit.api.Assert.assertNull;
+import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
@@ -33,6 +34,8 @@
import javax.jcr.Session;
import org.jboss.portletswap.PortletswapException;
+import org.jboss.portletswap.filter.module.CategoryFilter;
+import org.jboss.portletswap.filter.ModuleFilter;
import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.jcr.JCRServiceImpl;
import org.jboss.portletswap.model.Category;
@@ -180,12 +183,17 @@
module2 = repositoryService.storeModule(module2);
List<Module> modules = directoryService.getModules(false);
assertEquals(2, modules.size());
- modules = directoryService.getModules(false, category);
+ List<ModuleFilter> filters = new ArrayList<ModuleFilter>();
+ filters.add(new CategoryFilter(category));
+ modules = directoryService.getModules(false, filters);
+ System.out.println("*************************************************");
+ System.out.println(module.getCategories().get(0));
+ System.out.println(category);
assertEquals(1, modules.size());
module2.addCategory(category);
- modules = directoryService.getModules(false, category);
+ modules = directoryService.getModules(false, filters);
assertEquals(2, modules.size());
- modules = directoryService.getModules(true, category);
+ modules = directoryService.getModules(true, filters);
assertEquals(0, modules.size());
}
}
Added: src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/CompatibilityLevel.java
===================================================================
--- src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/CompatibilityLevel.java (rev 0)
+++ src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/CompatibilityLevel.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.model;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public enum CompatibilityLevel {
+
+ COMPATIBLE, INCOMPATIBLE, UNKNOWN
+}
+
Modified: src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/License.java
===================================================================
--- src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/License.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/License.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -35,7 +35,7 @@
private String text;
- protected License()
+ public License()
{
}
Deleted: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/DisplayNameModel.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/DisplayNameModel.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/DisplayNameModel.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,37 +0,0 @@
-package org.jboss.portletswap.metadata;
-
-import java.util.Locale;
-
-public class DisplayNameModel {
-
- private Locale lang;
-
- private String text;
-
- public DisplayNameModel(Locale lang, String text)
- {
- this.lang = lang;
- this.text = text;
- }
-
- public DisplayNameModel(Locale lang)
- {
- this.lang = lang;
- }
-
- public Locale getLang() {
- return lang;
- }
-
- public void setLang(Locale lang) {
- this.lang = lang;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-}
Deleted: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModel.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModel.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModel.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,54 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.metadata;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.portletswap.model.Category;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class ResultModel
-{
- private List<Category> categories;
-
- public ResultModel()
- {
- categories = new ArrayList<Category>();
- }
-
- public List<Category> getCategories()
- {
- return categories;
- }
-
- public void addCategory(Category category)
- {
- categories.add(category);
- }
-
-}
-
Deleted: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelFactory.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelFactory.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelFactory.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,124 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.metadata;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portal.common.i18n.LocalizedString.Value;
-import org.jboss.portletswap.model.Category;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.UnmarshallingContext;
-import org.xml.sax.Attributes;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class ResultModelFactory implements ObjectModelFactory
-{
-
- public Object completeRoot(Object arg0, UnmarshallingContext arg1, String arg2, String arg3)
- {
- return arg0;
- }
-
- public ResultModel newRoot(Object arg0, UnmarshallingContext arg1, String arg2, String arg3, Attributes arg4)
- {
- return new ResultModel();
- }
-
- public Object newChild(ResultModel result,
- UnmarshallingContext context,
- String namespaceURI,
- String localName,
- Attributes attrs)
- {
- Object child = null;
- if("category".equals(localName))
- {
- child = new Category();
- }
- return child;
- }
-
- public Object newChild(Category result,
- UnmarshallingContext context,
- String namespaceURI,
- String localName,
- Attributes attrs)
- {
- Object child = null;
- if("displayName".equals(localName))
- {
- child = new DisplayNameModel(new Locale(attrs.getValue("lang")));
- }
- return child;
- }
-
- public void setValue(DisplayNameModel displayName, UnmarshallingContext navigator,
- String namespaceUri, String localName, String value)
- {
- displayName.setText(value);
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(ResultModel result, Category category, UnmarshallingContext arg1, String arg2, String arg3)
- {
- result.addCategory(category);
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(Category category, Category childCategory, UnmarshallingContext arg1, String arg2, String arg3)
- {
- category.addChild(childCategory);
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(Category category, DisplayNameModel displayName, UnmarshallingContext arg1, String arg2, String arg3)
- {
- LocalizedString lString = category.getDisplayName();
- @SuppressWarnings("unchecked")
- Map<Locale, Value> values = lString.getValues();
- Map<Locale, String> result = new HashMap<Locale, String>();
- Iterator<Value> it = values.values().iterator();
- while (it.hasNext())
- {
- Value value = it.next();
- result.put(value.getLocale(), value.getString());
- }
- result.put(displayName.getLang(), displayName.getText());
- category.setDisplayName(new LocalizedString(result, lString.getDefaultLocale()));
- }
-
-}
-
Deleted: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelProvider.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelProvider.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelProvider.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,117 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portletswap.metadata;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.jboss.portal.common.i18n.LocalizedString.Value;
-import org.jboss.portletswap.model.Category;
-import org.jboss.xb.binding.MarshallingContext;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class ResultModelProvider implements org.jboss.xb.binding.ObjectModelProvider
-{
-
- public ResultModel getRoot(Object object, MarshallingContext arg1, String namespaceURI, String localName)
- {
- return (ResultModel)object;
- }
-
- public List<Category> getChildren(ResultModel result, String namespaceUri, String localName)
- {
- if ("category".equals(localName))
- {
- return result.getCategories();
- }
- return null;
- }
-
- public Object getChildren(Category category, String namespaceUri, String localName)
- {
- if ("category".equals(localName))
- {
- List<Category> children = new ArrayList<Category>();
- children.addAll(category.getChildren());
- return children;
- }
- else if ("displayName".equals(localName))
- {
- List<DisplayNameModel> children = new ArrayList<DisplayNameModel>();
- if (category.getDisplayName() != null)
- {
- @SuppressWarnings("unchecked")
- Map<Locale, Value> map = category.getDisplayName().getValues();
- Iterator<Value> it = map.values().iterator();
- while (it.hasNext())
- {
- Value value = it.next();
- children.add(new DisplayNameModel(value.getLocale(), value.getString()));
- }
- }
- return children;
- }
- return null;
- }
-
-
- public String getAttributeValue(Category category, String namespaceUri, String localName)
- {
- String value = null;
- if("id".equals(localName))
- {
- value = category.getId().toString();
- }
- else
- {
- value = null;
- }
- return value;
- }
-
- public String getAttributeValue(DisplayNameModel displayName, String namespaceUri, String localName)
- {
- String value = null;
- if("lang".equals(localName))
- {
- value = displayName.getLang().toString();
- }
- else
- {
- value = null;
- }
- return value;
- }
-
- public Object getElementValue(DisplayNameModel displayName, String namespaceUri, String localName)
- {
- return displayName.getText();
- }
-}
-
Copied: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/DisplayNameModel.java (from rev 216, src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/DisplayNameModel.java)
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/DisplayNameModel.java (rev 0)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/DisplayNameModel.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,37 @@
+package org.jboss.portletswap.metadata.parsing;
+
+import java.util.Locale;
+
+public class DisplayNameModel {
+
+ private Locale lang;
+
+ private String text;
+
+ public DisplayNameModel(Locale lang, String text)
+ {
+ this.lang = lang;
+ this.text = text;
+ }
+
+ public DisplayNameModel(Locale lang)
+ {
+ this.lang = lang;
+ }
+
+ public Locale getLang() {
+ return lang;
+ }
+
+ public void setLang(Locale lang) {
+ this.lang = lang;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+}
Added: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModel.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModel.java (rev 0)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModel.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata.parsing;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Category;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ResultModel
+{
+ private List<Category> categories;
+
+ private List<Artifact> artifacts;
+
+ public ResultModel()
+ {
+ categories = new ArrayList<Category>();
+ artifacts = new ArrayList<Artifact>();
+ }
+
+ public List<Category> getCategories()
+ {
+ return categories;
+ }
+
+ public void addCategory(Category category)
+ {
+ categories.add(category);
+ }
+
+ public void addArtifact(Artifact artifact)
+ {
+ artifacts.add(artifact);
+ }
+
+ public List<Artifact> getArtifacts()
+ {
+ return artifacts;
+ }
+}
+
Added: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelFactory.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelFactory.java (rev 0)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelFactory.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata.parsing;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.i18n.LocalizedString.Value;
+import org.jboss.portletswap.model.Category;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ResultModelFactory implements ObjectModelFactory
+{
+
+ public Object completeRoot(Object arg0, UnmarshallingContext arg1, String arg2, String arg3)
+ {
+ return arg0;
+ }
+
+ public ResultModel newRoot(Object arg0, UnmarshallingContext arg1, String arg2, String arg3, Attributes arg4)
+ {
+ return new ResultModel();
+ }
+
+ public Object newChild(ResultModel result,
+ UnmarshallingContext context,
+ String namespaceURI,
+ String localName,
+ Attributes attrs)
+ {
+ Object child = null;
+ if("category".equals(localName))
+ {
+ child = new Category();
+ }
+ return child;
+ }
+
+ public Object newChild(Category result,
+ UnmarshallingContext context,
+ String namespaceURI,
+ String localName,
+ Attributes attrs)
+ {
+ Object child = null;
+ if("displayName".equals(localName))
+ {
+ child = new DisplayNameModel(new Locale(attrs.getValue("lang")));
+ }
+ return child;
+ }
+
+ public void setValue(DisplayNameModel displayName, UnmarshallingContext navigator,
+ String namespaceUri, String localName, String value)
+ {
+ displayName.setText(value);
+ }
+
+ /**
+ * Called when parsing character is complete.
+ */
+ public void addChild(ResultModel result, Category category, UnmarshallingContext arg1, String arg2, String arg3)
+ {
+ result.addCategory(category);
+ }
+
+ /**
+ * Called when parsing character is complete.
+ */
+ public void addChild(Category category, Category childCategory, UnmarshallingContext arg1, String arg2, String arg3)
+ {
+ category.addChild(childCategory);
+ }
+
+ /**
+ * Called when parsing character is complete.
+ */
+ public void addChild(Category category, DisplayNameModel displayName, UnmarshallingContext arg1, String arg2, String arg3)
+ {
+ LocalizedString lString = category.getDisplayName();
+ @SuppressWarnings("unchecked")
+ Map<Locale, Value> values = lString.getValues();
+ Map<Locale, String> result = new HashMap<Locale, String>();
+ Iterator<Value> it = values.values().iterator();
+ while (it.hasNext())
+ {
+ Value value = it.next();
+ result.put(value.getLocale(), value.getString());
+ }
+ result.put(displayName.getLang(), displayName.getText());
+ category.setDisplayName(new LocalizedString(result, lString.getDefaultLocale()));
+ }
+
+}
+
Copied: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelProvider.java (from rev 216, src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/ResultModelProvider.java)
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelProvider.java (rev 0)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/metadata/parsing/ResultModelProvider.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,175 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.metadata.parsing;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.jboss.portal.common.i18n.LocalizedString.Value;
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.FileArtifact;
+import org.jboss.portletswap.model.License;
+import org.jboss.xb.binding.MarshallingContext;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class ResultModelProvider implements org.jboss.xb.binding.ObjectModelProvider
+{
+
+ public ResultModel getRoot(Object object, MarshallingContext arg1, String namespaceURI, String localName)
+ {
+ return (ResultModel)object;
+ }
+
+ public Object getChildren(ResultModel result, String namespaceUri, String localName)
+ {
+ if (localName.equals("categories"))
+ {
+ List<Category> categories = result.getCategories();
+ if (categories.size() != 0)
+ {
+ return result.getCategories();
+ }
+ }
+ else if (localName.equals("artifacts"))
+ {
+ List<Artifact> artifacts = result.getArtifacts();
+ if (artifacts.size() != 0)
+ {
+ return result.getArtifacts();
+ }
+ }
+ return null;
+ }
+
+ public Object getChildren(Category category, String namespaceUri, String localName)
+ {
+ if ("category".equals(localName))
+ {
+ return category.getChildren();
+ }
+ else if ("displayName".equals(localName))
+ {
+ List<DisplayNameModel> children = new ArrayList<DisplayNameModel>();
+ if (category.getDisplayName() != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, Value> map = category.getDisplayName().getValues();
+ Iterator<Value> it = map.values().iterator();
+ while (it.hasNext())
+ {
+ Value value = it.next();
+ children.add(new DisplayNameModel(value.getLocale(), value.getString()));
+ }
+ }
+ return children;
+ }
+ return null;
+ }
+
+ public Object getChildren(FileArtifact artifact, String namespaceUri, String localName)
+ {
+ if ("displayName".equals(localName))
+ {
+ List<DisplayNameModel> children = new ArrayList<DisplayNameModel>();
+ if (artifact.getDisplayName() != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, Value> map = artifact.getDisplayName().getValues();
+ Iterator<Value> it = map.values().iterator();
+ while (it.hasNext())
+ {
+ Value value = it.next();
+ children.add(new DisplayNameModel(value.getLocale(), value.getString()));
+ }
+ }
+ return children;
+ }
+ else if ("license".equals(localName))
+ {
+ return artifact.getLicense();
+ }
+ return null;
+ }
+
+ public String getAttributeValue(FileArtifact artifact, String namespaceUri, String localName)
+ {
+ String value = null;
+ if("id".equals(localName))
+ {
+ value = artifact.getId().toString();
+ }
+ return value;
+ }
+
+ public String getAttributeValue(Category category, String namespaceUri, String localName)
+ {
+ String value = null;
+ if("id".equals(localName))
+ {
+ value = category.getId().toString();
+ }
+ return value;
+ }
+
+ public String getAttributeValue(DisplayNameModel displayName, String namespaceUri, String localName)
+ {
+ String value = null;
+ if("lang".equals(localName))
+ {
+ value = displayName.getLang().toString();
+ }
+ else
+ {
+ value = null;
+ }
+ return value;
+ }
+
+ public Object getElementValue(DisplayNameModel displayName, String namespaceUri, String localName)
+ {
+ return displayName.getText();
+ }
+
+ public String getAttributeValue(License license, String namespaceUri, String localName)
+ {
+ String value = null;
+ if("id".equals(localName))
+ {
+ value = license.getName().toString();
+ }
+ return value;
+ }
+
+ public Object getElementValue(License license, String namespaceUri, String localName)
+ {
+ return license.getName();
+ }
+}
+
Modified: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -18,8 +18,8 @@
import org.jboss.portal.common.i18n.LocalizedString;
//import org.jboss.portletswap.RepositoryService;
-import org.jboss.portletswap.metadata.ResultModel;
-import org.jboss.portletswap.metadata.ResultModelProvider;
+import org.jboss.portletswap.metadata.parsing.ResultModel;
+import org.jboss.portletswap.metadata.parsing.ResultModelProvider;
import org.jboss.portletswap.model.Artifact;
import org.jboss.portletswap.model.Category;
import org.jboss.portletswap.model.FileArtifact;
@@ -42,6 +42,8 @@
// private DirectoryService directoryService;
private Category rootCategory;
+
+ private Artifact artifact;
@Override
public void destroy()
@@ -82,7 +84,7 @@
category3.setDisplayName(new LocalizedString("foobar"));
Module module = new Module("Toto");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new File("/tmp"), new ByteArrayInputStream(new byte[0]));
+ artifact = new FileArtifact(Type.JSR168PORTLET, module, new File("/tmp"), new ByteArrayInputStream(new byte[0]));
module.addArtifact(artifact);
}
@@ -121,12 +123,24 @@
if ("categories".equals(command))
{
- printCategories(pw, getCategoriesResult());
+ returnCategories(pw, getCategoriesResult());
}
+ else if ("artifacts".equals(command))
+ {
+ returnCategories(pw, getArtifactsResult());
+ }
+
pw.flush();
pw.close();
}
+ private ResultModel getArtifactsResult()
+ {
+ ResultModel result = new ResultModel();
+ result.addArtifact(artifact);
+ return result;
+ }
+
private ResultModel getCategoriesResult()
{
ResultModel result = new ResultModel();
@@ -134,7 +148,7 @@
return result;
}
- private void printCategories(Writer writer, ResultModel result)
+ private void returnCategories(Writer writer, ResultModel result)
{
XercesXsMarshaller marshaller = new XercesXsMarshaller();
marshaller.addRootElement("http://www.portletswap.com/directory", "", "result");
Deleted: src/server/trunk/server-webapp/src/main/resources/result.xsd
===================================================================
--- src/server/trunk/server-webapp/src/main/resources/result.xsd 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/main/resources/result.xsd 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsd:schema
- targetNamespace="http://www.portletswap.com/directory"
- xmlns:ps="http://www.portletswap.com/directory"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified">
-
- <xsd:element name="result" type="ps:result"></xsd:element>
-
- <xsd:complexType name="result">
- <xsd:sequence>
- <xsd:element ref="ps:category" maxOccurs="unbounded" minOccurs="0">
- </xsd:element>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:element name="category" type="ps:category"></xsd:element>
-
- <xsd:complexType name="category">
- <xsd:sequence>
-
- <xsd:element name="displayName" type="ps:displayName"
- maxOccurs="unbounded" minOccurs="0">
-
- </xsd:element>
-
- <xsd:element name="category" type="ps:category"
- maxOccurs="unbounded" minOccurs="0">
- </xsd:element>
- </xsd:sequence>
-
- <xsd:attribute name="id" type="xsd:string"></xsd:attribute>
- </xsd:complexType>
-
- <xsd:complexType name="displayName">
- <xsd:simpleContent>
- <xsd:extension base="xsd:string">
- <xsd:attribute name="lang" type="xsd:string">
- </xsd:attribute>
- </xsd:extension>
- </xsd:simpleContent>
- </xsd:complexType>
-
-
-
- <xsd:simpleType name="test">
- <xsd:restriction base="xsd:string"></xsd:restriction>
- </xsd:simpleType>
-</xsd:schema>
\ No newline at end of file
Added: src/server/trunk/server-webapp/src/main/resources/result.xsd
===================================================================
--- src/server/trunk/server-webapp/src/main/resources/result.xsd (rev 0)
+++ src/server/trunk/server-webapp/src/main/resources/result.xsd 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema
+ targetNamespace="http://www.portletswap.com/directory"
+ xmlns:ps="http://www.portletswap.com/directory"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified">
+
+ <xsd:element name="result" type="ps:result"></xsd:element>
+
+ <xsd:complexType name="result">
+ <xsd:sequence>
+ <xsd:element name="categories" type="ps:categories" maxOccurs="1" minOccurs="0">
+ </xsd:element>
+ <xsd:element name="artifacts" type="ps:artifacts" maxOccurs="1" minOccurs="0">
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="categories">
+ <xsd:sequence>
+ <xsd:element name="category" type="ps:category"
+ maxOccurs="unbounded" minOccurs="1">
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="artifacts">
+ <xsd:sequence>
+ <xsd:element name="artifact" type="ps:artifact"
+ maxOccurs="unbounded" minOccurs="1">
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <xsd:complexType name="category">
+ <xsd:sequence>
+
+ <xsd:element name="displayName" type="ps:displayName"
+ maxOccurs="unbounded" minOccurs="0">
+
+ </xsd:element>
+
+ <xsd:element name="category" type="ps:category"
+ maxOccurs="unbounded" minOccurs="0">
+ </xsd:element>
+ </xsd:sequence>
+
+ <xsd:attribute name="id" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="displayName">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <!-- xsd:attribute name="lang" type="xsd:string">
+ </xsd:attribute-->
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="artifact">
+ <xsd:sequence>
+ <xsd:element name="displayName" type="ps:displayName"
+ maxOccurs="unbounded" minOccurs="0">
+ </xsd:element>
+ <xsd:element name="license" type="ps:license"
+ maxOccurs="1" minOccurs="1">
+ </xsd:element>
+ <xsd:element name="compatibilityLevel" type="xsd:string"
+ maxOccurs="1" minOccurs="1">
+ </xsd:element>
+ </xsd:sequence>
+ <xsd:attribute name="id" type="xsd:string"></xsd:attribute>
+ </xsd:complexType>
+
+ <xsd:complexType name="license">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="id" type="xsd:string">
+ </xsd:attribute>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file
Modified: src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/MarshallerTestCase.java
===================================================================
--- src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/MarshallerTestCase.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/MarshallerTestCase.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -1,7 +1,12 @@
package org.jboss.portletswap.metadata;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Locale;
@@ -10,7 +15,14 @@
import junit.framework.TestCase;
import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.metadata.parsing.ResultModel;
+import org.jboss.portletswap.metadata.parsing.ResultModelProvider;
+import org.jboss.portletswap.model.Artifact;
import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.FileArtifact;
+import org.jboss.portletswap.model.License;
+import org.jboss.portletswap.model.Module;
+import org.jboss.portletswap.model.Type;
import org.jboss.xb.binding.ObjectModelProvider;
import org.jboss.xb.binding.XercesXsMarshaller;
import org.xml.sax.SAXException;
@@ -28,11 +40,69 @@
marshaller.declareNamespace("", "http://www.portletswap.com/directory");
ObjectModelProvider provider = new ResultModelProvider();
+ Writer writer = new StringWriter();
+ try
+ {
+// Writer writer = new FileWriter("src/test/resources/resultGetCategories.xml");
+
+ marshaller.marshal("src/main/resources/result.xsd", provider, getCategoriesResult(), writer);
+ writer.flush();
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
+ catch (SAXException e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
- Writer writer = new PrintWriter(System.out);
try
{
- marshaller.marshal("src/main/resources/result.xsd", provider, getResult(), writer);
+ Reader file = new FileReader("src/test/resources/resultGetCategories.xml");
+ Reader reader = new StringReader(writer.toString());
+
+ char[] comparedBuffer = new char[1024];
+ char[] compareToBuffer = new char[1024];
+ while (file.read(comparedBuffer, 0, comparedBuffer.length) != -1)
+ {
+ int read = reader.read(compareToBuffer, 0, compareToBuffer.length);
+ if (read == -1)
+ {
+ fail();
+ }
+ else
+ {
+ assertEquals(new String(comparedBuffer), new String(compareToBuffer));
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void testMarshallArtifacts()
+ {
+
+ XercesXsMarshaller marshaller = new XercesXsMarshaller();
+ marshaller.addRootElement("http://www.portletswap.com/directory", "", "result");
+
+ // declare default namespace
+ marshaller.declareNamespace("", "http://www.portletswap.com/directory");
+
+ ObjectModelProvider provider = new ResultModelProvider();
+
+ Writer writer = new StringWriter();
+ try
+ {
+// writer = new FileWriter("src/test/resources/resultGetArtifacts.xml");
+ marshaller.marshal("src/main/resources/result.xsd", provider, getArtifactsResult(), writer);
writer.flush();
writer.close();
@@ -47,28 +117,73 @@
// FIXME
e.printStackTrace();
}
- }
-
- private ResultModel getResult()
+
+ try
+ {
+ Reader file = new FileReader("src/test/resources/resultGetArtifacts.xml");
+ Reader reader = new StringReader(writer.toString());
+
+ char[] comparedBuffer = new char[1024];
+ char[] compareToBuffer = new char[1024];
+ while (file.read(comparedBuffer, 0, comparedBuffer.length) != -1)
+ {
+ int read = reader.read(compareToBuffer, 0, compareToBuffer.length);
+ if (read == -1)
+ {
+ fail();
+ }
+ else
+ {
+ assertEquals(new String(comparedBuffer), new String(compareToBuffer));
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+}
+
+ private ResultModel getCategoriesResult()
{
ResultModel result = new ResultModel();
Category category1 = new Category(Category.ROOT_CATEGORY_NAME);
- ((Category)category1).setId("id");
-/*
- Category category2 = new CategoryImpl("2222-3333-4444");
- Category category3 = new CategoryImpl("3333-4444-5555");
-*/
+ ((Category)category1).setId("1");
+
+ Category category2 = new Category("2222-3333-4444");
+ category2.setId("2");
+ Category category3 = new Category("3333-4444-5555");
+ category3.setId("3");
+
result.addCategory(category1);
-/*
+
category2.addChild(category3);
-*/
+
Map<Locale, String> map = new HashMap<Locale, String>();
map.put(new Locale("fr"), "Mon display nom");
map.put(new Locale("en"), "My display name");
category1.setDisplayName(new LocalizedString(map, Locale.ENGLISH));
-/*
+
result.addCategory(category2);
-*/
+
return result;
}
+
+ private ResultModel getArtifactsResult()
+ {
+ ResultModel result = new ResultModel();
+
+ Module module = new Module();
+
+ Artifact artifact1 = null;
+ artifact1 = new FileArtifact(Type.JSR168PORTLET, module, new File("/tmp/toto"), new ByteArrayInputStream("foo".getBytes()));
+ artifact1.setName("foo");
+ artifact1.setId("id1");
+ artifact1.setLicense(new License("LGPL", "JGPL TEXT"));
+ result.addArtifact(artifact1);
+
+ return result;
+ }
+
+
}
Modified: src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/UnMarshallerTestCase.java
===================================================================
--- src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/UnMarshallerTestCase.java 2008-01-28 08:33:42 UTC (rev 223)
+++ src/server/trunk/server-webapp/src/test/java/org/jboss/portletswap/metadata/UnMarshallerTestCase.java 2008-01-28 13:26:48 UTC (rev 224)
@@ -27,6 +27,8 @@
import java.io.IOException;
import java.io.InputStream;
+import org.jboss.portletswap.metadata.parsing.ResultModel;
+import org.jboss.portletswap.metadata.parsing.ResultModelFactory;
import org.jboss.xb.binding.JBossXBException;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
Added: src/server/trunk/server-webapp/src/test/resources/resultGetCategories.xml
===================================================================
--- src/server/trunk/server-webapp/src/test/resources/resultGetCategories.xml (rev 0)
+++ src/server/trunk/server-webapp/src/test/resources/resultGetCategories.xml 2008-01-28 13:26:48 UTC (rev 224)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<result xmlns="http://www.portletswap.com/directory">
+ <categories>
+ <category id="1">
+ <displayName>My display name</displayName>
+ <displayName>Mon display nom</displayName>
+ </category>
+ <category id="2">
+ <category id="3"></category>
+ </category>
+ </categories>
+</result>
\ No newline at end of file
16 years, 2 months
JBoss PortletSwap SVN: r223 - in src: server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr and 9 other directories.
by portletswap-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2008-01-28 03:33:42 -0500 (Mon, 28 Jan 2008)
New Revision: 223
Added:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java
Modified:
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java
src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java
src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java
Log:
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/RepositoryService.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -70,7 +70,7 @@
public void deleteCategory(Category category) throws RepositoryException, NotFoundException;
- public Artifact storeArtifact(Module module, Artifact artifact) throws RepositoryException, NotFoundException;
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException, NotFoundException;
public Artifact getArtifact(Object id) throws RepositoryException, NotFoundException;
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/jcr/JCRServiceImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -45,6 +45,8 @@
import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
import org.apache.jackrabbit.value.DateValue;
import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
import org.jboss.portletswap.model.impl.jcr.JCRModuleImpl;
/**
@@ -203,12 +205,14 @@
{
try
{
- Node node = rootNode.addNode(Category.ROOT_CATEGORY_NAME, "ps:category");
+ Node node = rootNode.addNode(Category.ROOT_CATEGORY_NAME, JCRCategoryImpl.NODE_TYPE);
node.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
- node.addNode("ps:categories" , "ps:categories");
+ node.addNode(JCRCategoryImpl.CATEGORIES_NODE , JCRCategoryImpl.CATEGORIES_NODE);
node = rootNode.addNode(JCRModuleImpl.ROOT_MODULE_NODENAME);
- }
+
+ node = rootNode.addNode(JCRLicenseImpl.ROOT_LICENSE_NODENAME);
+}
catch (Exception e)
{
// FIXME
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRArtifactImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.model.impl.jcr;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.jcr.JCRService;
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Type;
+import org.jboss.portletswap.model.Version;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public abstract class JCRArtifactImpl extends Artifact
+{
+
+ public static final String NODE_NAME = "ps:artifact";
+ public static final String ARTIFACT_TYPE_ATTRIBUTENAME = "ps:type";
+ public static final String DESCRIPTION_NODENAME = "ps:description";
+ public static final String DESCRIPTION_LANG_ATTRIBUTENAME = "ps:language";
+ public static final String DESCRIPTION_VALUE_ATTRIBUTENAME = "ps:value";
+ public static final String DISPLAYNAME_NODENAME = "ps:displayName";
+ public static final String DISPLAYNAME_LANG_ATTRIBUTENAME = "ps:language";
+ public static final String DISPLAYNAME_VALUE_ATTRIBUTENAME = "ps:value";
+ public static final String MODULE_ATTRIBUTENAME = "ps:module";
+
+ public static void fillCommonArtifactData(JCRService jcrService, Node node, Artifact artifact) throws RepositoryException
+ {
+ artifact.setName(node.getName());
+ artifact.setId(node.getUUID());
+
+ Property typeProperty = node.getProperty(ARTIFACT_TYPE_ATTRIBUTENAME);
+ artifact.setType(Type.valueOf(typeProperty.getString()));
+
+ // Description
+ NodeIterator it = node.getNodes(DESCRIPTION_NODENAME);
+ Map<Locale, String> values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new Locale(tmpNode.getProperty(DESCRIPTION_LANG_ATTRIBUTENAME).getString());
+ String value = tmpNode.getProperty(DESCRIPTION_VALUE_ATTRIBUTENAME).getString();
+ values.put(locale, value);
+ }
+ artifact.setDescription(new LocalizedString(values, Locale.ENGLISH));
+
+ // DisplayName
+ it = node.getNodes(DISPLAYNAME_NODENAME);
+ values = new HashMap<Locale, String>();
+ while (it.hasNext())
+ {
+ Node tmpNode = it.nextNode();
+ Locale locale = new Locale(tmpNode.getProperty(DISPLAYNAME_LANG_ATTRIBUTENAME).getString());
+ String value = tmpNode.getProperty(DISPLAYNAME_VALUE_ATTRIBUTENAME).getString();
+ values.put(locale, value);
+ }
+ artifact.setDisplayName(new LocalizedString(values, Locale.ENGLISH));
+
+ // Compatibility List
+ // TODO
+
+ // License
+ try
+ {
+ Property property = node.getProperty(JCRLicenseImpl.NODE_TYPE);
+ Node licenseNode = node.getSession().getNodeByUUID(property.getString());
+ artifact.setLicense(new JCRLicenseImpl(licenseNode));
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore
+ }
+
+ // Module
+ try
+ {
+ Property property = node.getProperty(JCRModuleImpl.NODE_NAME);
+ Node moduleNode = node.getSession().getNodeByUUID(property.getString());
+ artifact.setModule(new JCRModuleImpl(jcrService, moduleNode));
+ }
+ catch (PathNotFoundException e)
+ {
+ throw new PathNotFoundException();
+ }
+
+ Node versionNode = node.getNode(JCRVersionImpl.NODE_NAME);
+ Version version = new JCRVersionImpl(versionNode);
+ artifact.setVersion(version);
+
+ }
+
+}
+
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRAuthorImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.model.impl.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portletswap.model.Author;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRAuthorImpl extends Author
+{
+ public static final String NODE_TYPE = "ps:author";
+ public static final String NODE_NAME = "ps:author";
+ public static final String USERNAME_ATTRIBUTE = "ps:username";
+ public static final String FIRSTNAME_ATTRIBUTE = "ps:firstname";
+ public static final String LASTNAME_ATTRIBUTE = "ps:lastname";
+
+ public JCRAuthorImpl(Node node) throws RepositoryException
+ {
+ super(node.getProperty(JCRAuthorImpl.USERNAME_ATTRIBUTE).getString(),
+ node.getProperty(JCRAuthorImpl.FIRSTNAME_ATTRIBUTE).getString(),
+ node.getProperty(JCRAuthorImpl.LASTNAME_ATTRIBUTE).getString());
+ }
+
+
+}
+
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRCategoryImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -41,7 +41,10 @@
*/
public class JCRCategoryImpl extends Category
{
+ public static final String NODE_TYPE = "ps:category";
+ public static final String CATEGORIES_NODE = "ps:categories";
+
private JCRService jcrService;
public JCRCategoryImpl(JCRService jcrService, Node node) throws RepositoryException
@@ -63,12 +66,6 @@
}
@Override
- public void addChild(Category category)
- {
-
- }
-
- @Override
public List<Category> getChildren()
{
Session session = null;
@@ -80,7 +77,7 @@
Node categoriesNode = null;
try
{
- categoriesNode = node.getNode("ps:categories");
+ categoriesNode = node.getNode(CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRFileArtifactImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -22,23 +22,14 @@
******************************************************************************/
package org.jboss.portletswap.model.impl.jcr;
-import java.io.File;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Property;
import javax.jcr.RepositoryException;
-import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.model.FileArtifact;
-import org.jboss.portletswap.model.Type;
-import org.jboss.portletswap.jcr.JCRService;
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
@@ -46,59 +37,16 @@
*/
public class JCRFileArtifactImpl extends FileArtifact
{
-
+ public static final String NODE_TYPE = "ps:fileArtifact";
+ public static final String INPUT_STREAM_PROPERTYNAME = "ps:inputStream";
+
private InputStream inputStream;
-
- private File file;
public JCRFileArtifactImpl(JCRService jcrService, Node node) throws RepositoryException
{
- setName(node.getName());
- setId(node.getUUID());
-
- Property typeProperty = node.getProperty("ps:type");
- setType(Type.valueOf(typeProperty.getString()));
-
- // Description
- NodeIterator it = node.getNodes("ps:description");
- Map<Locale, String> values = new HashMap<Locale, String>();
- while (it.hasNext())
- {
- Node tmpNode = it.nextNode();
- Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
- String value = tmpNode.getProperty("ps:value").getString();
- values.put(locale, value);
- }
- setDescription(new LocalizedString(values, Locale.ENGLISH));
-
- // DisplayName
- it = node.getNodes("ps:displayName");
- values = new HashMap<Locale, String>();
- while (it.hasNext())
- {
- Node tmpNode = it.nextNode();
- Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
- String value = tmpNode.getProperty("ps:value").getString();
- values.put(locale, value);
- }
- setDisplayName(new LocalizedString(values, Locale.ENGLISH));
-
- // Compatibility List
- // TODO
-
- // License
- try
- {
- Property property = node.getProperty("ps:license");
- Node licenseNode = node.getSession().getNodeByUUID(property.getString());
- setLicense(new JCRLicenseImpl(jcrService, licenseNode));
- }
- catch (PathNotFoundException e)
- {
- // ignore
- }
-
- this.inputStream = node.getProperty("ps:file").getStream();
+ super();
+ JCRArtifactImpl.fillCommonArtifactData(jcrService, node, this);
+ this.inputStream = node.getProperty(INPUT_STREAM_PROPERTYNAME).getStream();
}
public InputStream getInputStream()
@@ -106,11 +54,6 @@
return inputStream;
}
- public File getFile()
- {
- return file;
- }
-
public ArtifactType getArtifactType()
{
return ArtifactType.FILE_ARTIFACT_TYPE;
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRLicenseImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -25,7 +25,6 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
-import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.License;
/**
@@ -34,39 +33,15 @@
*/
public class JCRLicenseImpl extends License
{
- private String id;
-
- private String name;
-
- private String text;
+ public static final String ROOT_LICENSE_NODENAME = "org.jboss.portletswap.root_license";
+ public static final String NODE_TYPE = "ps:license";
+ public static final String NODE_NAME = "ps:license";
+ public static final String TEXT_PROPERTY = "ps:text";
- public JCRLicenseImpl(JCRService jcrService, Node licenseNode) throws RepositoryException
+ public JCRLicenseImpl(Node licenseNode) throws RepositoryException
{
- id = licenseNode.getUUID();
- name = licenseNode.getProperty("ps:name").getString();
- text = licenseNode.getProperty("ps:text").getString();
+ super(licenseNode.getName(), licenseNode.getProperty(TEXT_PROPERTY).getString());
+ setId(licenseNode.getUUID());
}
-
- public String getName()
- {
- return name;
- }
-
- public String getText()
- {
- return text;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setId(String id)
- {
- this.id = id;
-
- }
-
}
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRModuleImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -54,7 +54,12 @@
{
public static final String ROOT_MODULE_NODENAME = "org.jboss.portletswap.root_module";
-
+ public static final String NODE_NAME = "ps:module";
+ public static final String DESCRIPTION_NODENAME = "ps:description";
+ public static final String ARTIFACTS_NODENAME = "ps:artifacts";
+ public static final String DESCRIPTION_LANG_ATTRIBUTENAME = "jcr:language";
+ public static final String DESCRIPTION_VALUE_ATTRIBUTENAME = "ps:value";
+
private List<Artifact> artifacts = new ArrayList<Artifact>();
private JCRService jcrService;
@@ -65,37 +70,24 @@
setName(node.getName());
setId(node.getUUID());
-/*
- Node versionNode = node.getNode("ps:version");
- Version version = new Version(versionNode.getProperty("ps:name").getString(),
- (int)versionNode.getProperty("ps:major").getValue().getLong(),
- (int)versionNode.getProperty("ps:minor").getValue().getLong(),
- (int)versionNode.getProperty("ps:patch").getValue().getLong(),
- new Version.Qualifier(
- Version.Qualifier.Prefix.valueOf(versionNode.getProperty("ps:prefix").getValue().getString()),
- Version.Qualifier.Suffix.valueOf(versionNode.getProperty("ps:suffix").getValue().getString())),
- versionNode.getProperty("ps:codename").getValue().getString());
- setVersion(version);
-*/
- NodeIterator it = node.getNodes("ps:description");
+
+ NodeIterator it = node.getNodes(DESCRIPTION_NODENAME);
Map<Locale, String> values = new HashMap<Locale, String>();
while (it.hasNext())
{
Node tmpNode = it.nextNode();
- Locale locale = new Locale(tmpNode.getProperty("jcr:language").getString());
- String value = tmpNode.getProperty("ps:value").getString();
+ Locale locale = new Locale(tmpNode.getProperty(DESCRIPTION_LANG_ATTRIBUTENAME).getString());
+ String value = tmpNode.getProperty(DESCRIPTION_VALUE_ATTRIBUTENAME).getString();
values.put(locale, value);
}
setDescription(new LocalizedString(values, Locale.ENGLISH));
- it = node.getNodes("ps:author");
+ it = node.getNodes(JCRAuthorImpl.NODE_NAME);
List<Author> authors = new ArrayList<Author>();
while (it.hasNext())
{
Node tmpNode = it.nextNode();
- Author author = new Author(tmpNode.getProperty("ps:username").getString(),
- tmpNode.getProperty("ps:firstname").getString(),
- tmpNode.getProperty("ps:lastname").getString());
+ Author author = new JCRAuthorImpl(tmpNode);
authors.add(author);
}
setAuthors(authors);
@@ -142,7 +134,7 @@
Node artifactsNode = null;
try
{
- artifactsNode = node.getNode("ps:artifacts");
+ artifactsNode = node.getNode(ARTIFACTS_NODENAME);
}
catch (PathNotFoundException e)
{
@@ -181,7 +173,7 @@
List<Value> valuesList;
try
{
- Property property = node.getProperty("ps:categories");
+ Property property = node.getProperty(JCRCategoryImpl.CATEGORIES_NODE);
valuesList = new ArrayList<Value>(Arrays.asList(property.getValues()));
}
catch (PathNotFoundException e)
@@ -192,7 +184,7 @@
valuesList.add(new ReferenceValue(session.getNodeByUUID((String)category.getId())));
Value[] values = valuesList.toArray(new Value[valuesList.size()]);
- node.setProperty("ps:categories", values);
+ node.setProperty(JCRCategoryImpl.CATEGORIES_NODE, values);
session.save();
}
catch (RepositoryException e)
@@ -217,7 +209,7 @@
Property property;
try
{
- property = node.getProperty("ps:categories");
+ property = node.getProperty(JCRCategoryImpl.CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
@@ -243,9 +235,4 @@
session.logout();
}
}
-
- public void addArtifact(Artifact artifact)
- {
- // repositoryService.storeArtifact(this, artifact);
- }
}
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/model/impl/jcr/JCRVersionImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.model.impl.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.jboss.portletswap.model.Version;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRVersionImpl extends Version
+{
+
+ public static final String NODE_NAME = "ps:version";
+ public static final String NODE_TYPE = "ps:version";
+ public static final String MAJOR_PROPERTYNAME = "ps:major";
+ public static final String MINOR_PROPERTYNAME = "ps:minor";
+ public static final String PATCH_PROPERTYNAME = "ps:patch";
+ public static final String PREFIX_PROPERTYNAME = "ps:prefix";
+ public static final String SUFFIX_PROPERTYNAME = "ps:suffix";
+
+ public JCRVersionImpl(Node node) throws RepositoryException
+ {
+ super((int)node.getProperty(MAJOR_PROPERTYNAME).getLong(),
+ (int)node.getProperty(MINOR_PROPERTYNAME).getLong(),
+ (int)node.getProperty(PATCH_PROPERTYNAME).getLong(),
+ new Version.Qualifier(Version.Qualifier.Prefix.valueOf(node.getProperty(PREFIX_PROPERTYNAME).getString()),
+ Version.Qualifier.Suffix.valueOf(node.getProperty(SUFFIX_PROPERTYNAME).getString())));
+ }
+}
+
Added: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java (rev 0)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/NodeFactory.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portletswap.repository.impl.jcr;
+
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.value.DateValue;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portletswap.model.Artifact;
+import org.jboss.portletswap.model.Author;
+import org.jboss.portletswap.model.Category;
+import org.jboss.portletswap.model.FileArtifact;
+import org.jboss.portletswap.model.License;
+import org.jboss.portletswap.model.Module;
+import org.jboss.portletswap.model.Version;
+import org.jboss.portletswap.model.impl.jcr.JCRArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRAuthorImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRFileArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRVersionImpl;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class NodeFactory
+{
+
+ public static Node createFileArtifactNode(Node parent, Artifact artifact) throws RepositoryException
+ {
+ Node artifactNode = parent.addNode(JCRArtifactImpl.NODE_NAME, JCRFileArtifactImpl.NODE_TYPE);
+ artifactNode.setProperty(JCRFileArtifactImpl.INPUT_STREAM_PROPERTYNAME, ((FileArtifact)artifact).getInputStream());
+ artifactNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+ if (artifact.getLicense() != null)
+ {
+ artifactNode.setProperty(JCRLicenseImpl.NODE_NAME, ((License)artifact.getLicense()).getId());
+ }
+ artifactNode.setProperty(JCRArtifactImpl.ARTIFACT_TYPE_ATTRIBUTENAME, artifact.getType().name());
+ artifactNode.setProperty(JCRArtifactImpl.MODULE_ATTRIBUTENAME, (String)artifact.getModule().getId());
+
+ // Store the version
+ Version version = artifact.getVersion();
+ Node versionNode = artifactNode.addNode(JCRVersionImpl.NODE_NAME, JCRVersionImpl.NODE_TYPE);
+ {
+ versionNode.setProperty(JCRVersionImpl.MAJOR_PROPERTYNAME, version.getMajor());
+ versionNode.setProperty(JCRVersionImpl.MINOR_PROPERTYNAME, version.getMinor());
+ versionNode.setProperty(JCRVersionImpl.PATCH_PROPERTYNAME, version.getPatch());
+ versionNode.setProperty(JCRVersionImpl.PREFIX_PROPERTYNAME, version.getQualifier().getPrefix().getName());
+ versionNode.setProperty(JCRVersionImpl.SUFFIX_PROPERTYNAME, version.getQualifier().getSuffix().name());
+ }
+
+ // Store the description
+ LocalizedString description = artifact.getModule().getDescription();
+ if (description != null)
+ {
+ createLocalizedStringNode(artifactNode, "ps:description", description);
+ }
+
+ // Store the displayName
+ LocalizedString displayName = artifact.getDisplayName();
+ if (displayName != null)
+ {
+ createLocalizedStringNode(artifactNode, "ps:displayName", displayName);
+ }
+
+ return artifactNode;
+ }
+
+ private static Node createLocalizedStringNode(Node parent, String nodeType, LocalizedString lString) throws RepositoryException
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = lString.getValues();
+
+ Set<Locale> set = values.keySet();
+
+ Node descriptionNode = null;
+
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ descriptionNode = parent.addNode(nodeType, nodeType);
+ descriptionNode.setProperty("jcr:language", locale.toString());
+ descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
+ }
+ }
+ return descriptionNode;
+ }
+
+ public static Node createModuleNode(Node parent, Module module) throws RepositoryException
+ {
+ Node moduleNode = parent.addNode(module.getName(), "ps:module");
+
+ // Store the last modified date
+ moduleNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ // Store the description
+ LocalizedString description = module.getDescription();
+ if (description != null)
+ {
+ @SuppressWarnings("unchecked")
+ Map<Locale, LocalizedString.Value> values = description.getValues();
+
+ Set<Locale> set = values.keySet();
+ Iterator<Locale> it = set.iterator();
+ while (it.hasNext())
+ {
+ Locale locale = it.next();
+ {
+ Node descriptionNode = moduleNode.addNode("ps:description", "ps:description");
+ descriptionNode.setProperty("jcr:language", locale.toString());
+ descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
+ }
+ }
+ }
+
+ // Store the authors
+ List<Author> authors = module.getAuthors();
+ if (authors != null)
+ {
+ for (Author author: authors)
+ {
+ Node authorNode = moduleNode.addNode(JCRAuthorImpl.NODE_NAME, JCRAuthorImpl.NODE_TYPE);
+ authorNode.setProperty(JCRAuthorImpl.USERNAME_ATTRIBUTE, author.getUsername());
+ authorNode.setProperty(JCRAuthorImpl.FIRSTNAME_ATTRIBUTE, author.getFirstname());
+ authorNode.setProperty(JCRAuthorImpl.LASTNAME_ATTRIBUTE, author.getLastname());
+ }
+ }
+ return moduleNode;
+ }
+
+ public static Node createLicenseNode(Node parent, License license) throws RepositoryException
+ {
+ Node licenseNode = parent.addNode(license.getName(), JCRLicenseImpl.NODE_TYPE);
+ licenseNode.setProperty(JCRLicenseImpl.TEXT_PROPERTY, license.getText());
+ return licenseNode;
+ }
+
+ public static Node createCategoryNode(Node parent, Category category) throws RepositoryException
+ {
+ Node node = parent.addNode(category.getName(), JCRCategoryImpl.NODE_TYPE);
+ node.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+
+ // Store the displayName
+ LocalizedString displayName = category.getDisplayName();
+ if (displayName != null)
+ {
+ createLocalizedStringNode(node, "displayName", displayName);
+ }
+ return node;
+ }
+}
+
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -23,32 +23,24 @@
package org.jboss.portletswap.repository.impl.jcr;
import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Session;
-import org.apache.jackrabbit.value.DateValue;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.PortletswapException;
import org.jboss.portletswap.RepositoryService;
import org.jboss.portletswap.jcr.JCRService;
import org.jboss.portletswap.model.Artifact;
-import org.jboss.portletswap.model.Author;
+import org.jboss.portletswap.model.ArtifactType;
import org.jboss.portletswap.model.Category;
-import org.jboss.portletswap.model.FileArtifact;
import org.jboss.portletswap.model.License;
import org.jboss.portletswap.model.Module;
-import org.jboss.portletswap.model.Version;
import org.jboss.portletswap.model.impl.jcr.JCRCategoryImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRFileArtifactImpl;
+import org.jboss.portletswap.model.impl.jcr.JCRLicenseImpl;
import org.jboss.portletswap.model.impl.jcr.JCRModuleImpl;
import org.jboss.portletswap.repository.NotFoundException;
import org.jboss.portletswap.repository.RepositoryException;
@@ -203,37 +195,15 @@
Node categoriesNode = null;
try
{
- categoriesNode = parentNode.getNode("ps:categories");
+ categoriesNode = parentNode.getNode(JCRCategoryImpl.CATEGORIES_NODE);
}
catch (PathNotFoundException e)
{
- categoriesNode = parentNode.addNode("ps:categories", "ps:categories");
+ categoriesNode = parentNode.addNode(JCRCategoryImpl.CATEGORIES_NODE, JCRCategoryImpl.CATEGORIES_NODE);
}
- Node node = categoriesNode.addNode(category.getName(), "ps:category");
- node.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
+ Node node = NodeFactory.createCategoryNode(categoriesNode, category);
- // Store the displayName
- LocalizedString displayName = category.getDisplayName();
- if (displayName != null)
- {
- @SuppressWarnings("unchecked")
- Map<Locale, LocalizedString.Value> values = displayName.getValues();
-
- Set<Locale> set = values.keySet();
- Iterator<Locale> it = set.iterator();
- while (it.hasNext())
- {
- Locale locale = it.next();
- {
- Node displayNameNode = node.addNode("ps:displayName", "ps:displayName");
- displayNameNode.setProperty("jcr:language", locale.toString());
- displayNameNode.setProperty("ps:value", (values.get(locale)).getString());
- }
- }
- }
-
-
session.save();
return new JCRCategoryImpl(jcrService, node);
@@ -256,44 +226,9 @@
session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
// Store the module name
- Node moduleNode = session.getRootNode().getNode(JCRModuleImpl.ROOT_MODULE_NODENAME).addNode(module.getName(), "ps:module");
-
- // Store the last modified date
- moduleNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
-
- // Store the description
- LocalizedString description = module.getDescription();
- if (description != null)
- {
- @SuppressWarnings("unchecked")
- Map<Locale, LocalizedString.Value> values = description.getValues();
-
- Set<Locale> set = values.keySet();
- Iterator<Locale> it = set.iterator();
- while (it.hasNext())
- {
- Locale locale = it.next();
- {
- Node descriptionNode = moduleNode.addNode("ps:description", "ps:description");
- descriptionNode.setProperty("jcr:language", locale.toString());
- descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
- }
- }
- }
-
- // Store the authors
- List<Author> authors = module.getAuthors();
- if (authors != null)
- {
- for (Author author: authors)
- {
- Node authorNode = moduleNode.addNode("ps:author", "ps:author");
- authorNode.setProperty("ps:username", author.getUsername());
- authorNode.setProperty("ps:firstname", author.getFirstname());
- authorNode.setProperty("ps:lastname", author.getLastname());
- }
- }
-
+ Node parentNode = session.getRootNode().getNode(JCRModuleImpl.ROOT_MODULE_NODENAME);
+ Node moduleNode = NodeFactory.createModuleNode(parentNode, module);
+
session.save();
return new JCRModuleImpl(jcrService, moduleNode);
@@ -413,91 +348,29 @@
}
}
- public Artifact storeArtifact(Module module, Artifact artifact) throws RepositoryException, NotFoundException
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException, NotFoundException
{
Session session = null;
try
{
session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
- Node node = session.getNodeByUUID((String) module.getId());
+ Node node = session.getNodeByUUID((String) artifact.getModule().getId());
Node artifactsNode = null;
try
{
- artifactsNode = node.getNode("ps:artifacts");
+ artifactsNode = node.getNode(JCRModuleImpl.ARTIFACTS_NODENAME);
}
catch (PathNotFoundException e)
{
- artifactsNode = node.addNode("ps:artifacts", "ps:artifacts");
+ artifactsNode = node.addNode(JCRModuleImpl.ARTIFACTS_NODENAME, JCRModuleImpl.ARTIFACTS_NODENAME);
}
- Node artifactNode = null;
if (artifact.getArtifactType().equals(ArtifactType.FILE_ARTIFACT_TYPE))
{
- artifactNode = artifactsNode.addNode("ps:artifact", "ps:fileArtifact");
- artifactNode.setProperty("ps:file", ((FileArtifact)artifact).getInputStream());
- artifactNode.setProperty("jcr:lastModified", new DateValue(Calendar.getInstance()));
- if (artifact.getLicense() != null)
- {
- artifactNode.setProperty("ps:license", ((License)artifact.getLicense()).getId());
- }
- artifactNode.setProperty("ps:type", artifact.getType().name());
-
- // Store the version
- Version version = artifact.getVersion();
- Node versionNode = artifactNode.addNode("ps:version", "ps:version");
- {
- versionNode.setProperty("ps:major", version.getMajor());
- versionNode.setProperty("ps:minor", version.getMinor());
- versionNode.setProperty("ps:patch", version.getPatch());
- versionNode.setProperty("ps:prefix", version.getQualifier().getPrefix().getName());
- versionNode.setProperty("ps:suffix", version.getQualifier().getSuffix().name());
- }
-
- // Store the description
- LocalizedString description = module.getDescription();
- if (description != null)
- {
- @SuppressWarnings("unchecked")
- Map<Locale, LocalizedString.Value> values = description.getValues();
-
- Set<Locale> set = values.keySet();
- Iterator<Locale> it = set.iterator();
- while (it.hasNext())
- {
- Locale locale = it.next();
- {
- Node descriptionNode = artifactNode.addNode("ps:description", "ps:description");
- descriptionNode.setProperty("jcr:language", locale.toString());
- descriptionNode.setProperty("ps:value", (values.get(locale)).getString());
- }
- }
- }
-
- // Store the displayName
- LocalizedString displayName = artifact.getDisplayName();
- if (displayName != null)
- {
- @SuppressWarnings("unchecked")
- Map<Locale, LocalizedString.Value> values = displayName.getValues();
-
- Set<Locale> set = values.keySet();
- Iterator<Locale> it = set.iterator();
- while (it.hasNext())
- {
- Locale locale = it.next();
- {
- Node displayNameNode = artifactNode.addNode("ps:displayName", "ps:displayName");
- displayNameNode.setProperty("jcr:language", locale.toString());
- displayNameNode.setProperty("ps:value", (values.get(locale)).getString());
- }
- }
- }
-
-
+ Node artifactNode = NodeFactory.createFileArtifactNode(artifactsNode, (Artifact)artifact);
session.save();
- ((FileArtifact)artifact).setId(artifactNode.getUUID());
- return artifact;
+ return new JCRFileArtifactImpl(jcrService, artifactNode);
}
return null;
}
@@ -550,18 +423,10 @@
{
session = jcrService.openSession(JCRService.MODULE_WORKSPACE_NAME);
- // Store the license name
- Node licenseNode = session.getRootNode().addNode("ps:license", "ps:license");
-
- // Store the license text
- licenseNode.setProperty("ps:name", license.getName());
- licenseNode.setProperty("ps:text", license.getText());
-
+ Node rootLicenseNode = session.getRootNode().getNode(JCRLicenseImpl.ROOT_LICENSE_NODENAME);
+ Node licenseNode = NodeFactory.createLicenseNode(rootLicenseNode, license);
session.save();
-
- ((License)license).setId(licenseNode.getUUID());
-
- return license;
+ return new JCRLicenseImpl(licenseNode);
}
catch (javax.jcr.RepositoryException e)
{
Modified: src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceImpl.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -111,7 +111,7 @@
}
- public Artifact storeArtifact(Module module, Artifact artifact) throws RepositoryException, NotFoundException
+ public Artifact storeArtifact(Artifact artifact) throws RepositoryException, NotFoundException
{
return null;
}
Modified: src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd
===================================================================
--- src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/main/resources/customNodes.cnd 2008-01-28 08:33:42 UTC (rev 223)
@@ -34,13 +34,14 @@
+ ps:artifact multiple
[ps:artifact] > nt:base, mix:referenceable
+ - jcr:lastModified (date) mandatory ignore
+ - ps:module (reference) mandatory
+ - ps:license (reference)
+ - ps:type (string) mandatory
+ ps:version mandatory
[ps:fileArtifact] > ps:artifact
- - jcr:lastModified (date) mandatory ignore
- - ps:file (binary)
- - ps:type (string) mandatory
- - ps:license (reference)
+ - ps:inputStream (binary)
[ps:module] > nt:base, mix:referenceable
- jcr:lastModified (date) mandatory ignore
Modified: src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/jcr/RepositoryServiceTestCase.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -318,22 +318,22 @@
{
Module module = new Module("Test");
assertNull(module.getId());
- Module retModule = repositoryService.storeModule(module);
+ module = repositoryService.storeModule(module);
Version version = new Version(1, 0, 0, new Version.Qualifier(Version.Qualifier.Prefix.GA));
InputStream is = new FileInputStream("/tmp/test");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new File("/tmp/test"), is);
- ((FileArtifact)artifact).setName("Bozo");
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new File("/tmp/test"), is);
+ ((Artifact)artifact).setName("Bozo");
artifact.setVersion(version);
License license = new License("LGPL", "blah");
license = repositoryService.storeLicense(license);
artifact.setLicense(license);
- artifact = repositoryService.storeArtifact(retModule, artifact);
+ artifact = repositoryService.storeArtifact(artifact);
- List<Artifact> artifacts = retModule.getArtifacts();
+ List<Artifact> artifacts = module.getArtifacts();
assertEquals(1, artifacts.size());
FileArtifact getArtifact = (FileArtifact)artifacts.get(0);
Modified: src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java
===================================================================
--- src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-lib/src/test/java/org/jboss/portletswap/repository/impl/memory/RepositoryServiceTestCase.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -63,9 +63,9 @@
{
RepositoryService repositoryService = new RepositoryServiceImpl();
Module module = new Module("Foo");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, null, null);
module = repositoryService.storeModule(module);
- repositoryService.storeArtifact(module, artifact);
+ repositoryService.storeArtifact(artifact);
}
}
Modified: src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java
===================================================================
--- src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/Artifact.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -47,7 +47,27 @@
private CompatibilityList compatibilityList;
private License license;
+
+ private Module module;
+ protected Artifact()
+ {
+
+ }
+
+ protected Artifact(Module module)
+ {
+ this.module = module;
+ module.addArtifact(this);
+ }
+
+ public Artifact(Module module, Type type)
+ {
+ this.module = module;
+ module.addArtifact(this);
+ this.type = type;
+ }
+
public ArtifactType getArtifactType()
{
return artifactType;
@@ -138,6 +158,14 @@
this.version = version;
}
-
+ public Module getModule()
+ {
+ return module;
+ }
+
+ public void setModule(Module module)
+ {
+ this.module = module;
+ }
}
Modified: src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java
===================================================================
--- src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-service/server-model/src/main/java/org/jboss/portletswap/model/FileArtifact.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -32,19 +32,22 @@
*/
public class FileArtifact extends Artifact
{
-
private InputStream inputStream;
private File file;
-
+
protected FileArtifact()
{
-
}
- public FileArtifact(Type type, File file, InputStream inputStream)
+ protected FileArtifact(Module module)
{
- setType(type);
+ super(module);
+ }
+
+ public FileArtifact(Type type, Module module, File file, InputStream inputStream)
+ {
+ super(module, type);
this.inputStream = inputStream;
this.file = file;
}
Modified: src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java
===================================================================
--- src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/server/trunk/server-webapp/src/main/java/org/jboss/portletswap/servlet/DirectoryServlet.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -82,7 +82,7 @@
category3.setDisplayName(new LocalizedString("foobar"));
Module module = new Module("Toto");
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new File("/tmp"), new ByteArrayInputStream(new byte[0]));
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new File("/tmp"), new ByteArrayInputStream(new byte[0]));
module.addArtifact(artifact);
}
Modified: src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java
===================================================================
--- src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java 2008-01-25 14:07:01 UTC (rev 222)
+++ src/textClient/src/main/java/org/jboss/portletswap/textclient/TextClient.java 2008-01-28 08:33:42 UTC (rev 223)
@@ -206,8 +206,8 @@
try
{
Module module = repositoryService.getModule(moduleId);
- Artifact artifact = new FileArtifact(Type.JSR168PORTLET, new File(filename), new FileInputStream(filename));
- artifact = repositoryService.storeArtifact(module, artifact);
+ Artifact artifact = new FileArtifact(Type.JSR168PORTLET, module, new File(filename), new FileInputStream(filename));
+ artifact = repositoryService.storeArtifact(artifact);
System.out.println("Successfully inserted artifact: " + artifact.getId());
}
catch (PortletswapException e)
@@ -343,7 +343,7 @@
public void populate() throws RepositoryException
{
Module module1 = new Module("Module1");
- FileArtifact fileArtifact1_1 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact1_1 = new FileArtifact(Type.JSR168PORTLET, module1, null, null);
fileArtifact1_1.setDisplayName(new LocalizedString("Artifact 1:1", Locale.ENGLISH));
module1.addArtifact(fileArtifact1_1);
module1 = repositoryService.storeModule(module1);
@@ -355,10 +355,10 @@
module3 = repositoryService.storeModule(module3);
Module module4 = new Module("Module4");
- FileArtifact fileArtifact4_1 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact4_1 = new FileArtifact(Type.JSR168PORTLET, module4, null, null);
fileArtifact4_1.setDisplayName(new LocalizedString("Artifact 4:1", Locale.ENGLISH));
module4.addArtifact(fileArtifact4_1);
- FileArtifact fileArtifact4_2 = new FileArtifact(Type.JSR168PORTLET, null, null);
+ Artifact fileArtifact4_2 = new FileArtifact(Type.JSR168PORTLET, module4, null, null);
fileArtifact4_2.setDisplayName(new LocalizedString("Artifact 4:2", Locale.ENGLISH));
module4.addArtifact(fileArtifact4_2);
module4 = repositoryService.storeModule(module4);
16 years, 2 months