|
From: <jbo...@li...> - 2006-07-06 01:26:35
|
Author: unibrew
Date: 2006-07-05 21:26:30 -0400 (Wed, 05 Jul 2006)
New Revision: 4925
Modified:
labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java
labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectDescriptor.java
Log:
[JBLAB-682] Flattening downloads.xml structure to project.xml.
Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java 2006-07-05 22:44:42 UTC (rev 4924)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java 2006-07-06 01:26:30 UTC (rev 4925)
@@ -21,6 +21,7 @@
*/
package org.jboss.forge.common.projects;
+import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
@@ -88,14 +89,125 @@
* @throws IOException
* @throws XmlNotFoundException
*/
- public DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,
+ /*public DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,
String componentDir, String componentDesc, String portalName,
String projectId) throws SAXException, IOException,
XmlNotFoundException {
this(isf, xht, "", "", componentDir, componentDesc, portalName,
- projectId, null);
+ projectId, null);
+ }*/
+ public DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,
+ Node node, String componentDir, String componentDesc, String portalName,
+ String projectId) throws SAXException, IOException,
+ XmlNotFoundException {
+ this(isf, xht,node, "", "", componentDir, componentDesc, portalName,
+ projectId,null);
}
+
+ private DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,Node node,
+ String categoryContext, String categoryNameContext,
+ String componentDir, String componentDesc, String portalName,
+ String projectId,ElementDescriptor thisCategory)
+ throws SAXException, IOException, XmlNotFoundException {
+
+ this.categoryContext = categoryContext;
+ categories = new HashMap<String, DownloadsDescriptor>();
+ context = new DelegateContext();
+ // Prefix to prepend to each file path to make a component link
+ String downloadPrefix = File.separator + ForgeHelper.FILE_ACCESS_DIR
+ + File.separator + portalName + File.separator
+ + ProjectsHelper.MEMBERS_DIR + File.separator + projectId
+ + File.separator + componentDir;
+
+ // Getting the category which has a path-like structure, not the
+ // web-address-like structure
+ String pathCategoryContext = categoryContext.replaceAll("["
+ + CAT_ID_SEPARATOR + "]", File.separator);
+
+ // Descriptors of categories and files that are contained in this
+ // category.
+ ElementsDescriptor categoriesDesc = null;
+ ElementsDescriptor filesDesc = null;
+
+ Node n;
+ NodeList nodes = node.getChildNodes();
+
+ // Parsing the descriptor
+ // If there's no parent category info, we look for a "root-category"
+ // tag.
+ System.out.println("BEFORE NODENAME: "+node.getNodeName());
+ if (thisCategory == null) {
+ System.out.println("IN IF");
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ System.out.println("IN ELEMENT");
+ thisCategory = new ElementDescriptor(node, xht, new PropertiesHandlerDefault());
+ categoryNameContext = thisCategory.getProperty("name");
+ System.out.println("CATEGORY NAME: "+categoryNameContext);
+ // categoryDescription = thisCategory.getProperty("description");
+ }
+ }
+
+ // Parsing child categories and files descriptors.
+ for (int i = 0; i < nodes.getLength(); i++) {
+ n = nodes.item(i);
+
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ System.out.println("PARSING ZA NODETYPE: "+n.getNodeName());
+ if (n.getNodeName().equals("categories")) {
+ System.out.println("W KATEGORIACH");
+ categoriesDesc = new ElementsDescriptor(n, xht, "category",
+ getCategoriesPropertiesHandler(isf,xht,n,
+ categoryContext,categoryNameContext,
+ componentDir, componentDesc,
+ portalName, projectId ));
+ } else if (n.getNodeName().equals("files")) {
+ System.out.println("W PLIKACH");
+ filesDesc = new ElementsDescriptor(n, xht, "file",
+ getFilesPropertiesHandler(isf, projectId,
+ downloadPrefix, pathCategoryContext,
+ File.separator,componentDir),
+ getFilesExtendedPropertiesMap(downloadPrefix,
+ pathCategoryContext, File.separator, portalName,
+ projectId),
+ new OutsidePropertiesMap());
+ }
+ }
+ }
+
+ if (categoriesDesc != null)
+ categoriesDesc.fillContext(context.next("hasCategories"), "categories",
+ new NullPermissionsChecker());
+ if (filesDesc != null)
+ filesDesc.fillContext(context.next("hasFiles"), "files",
+ new NullPermissionsChecker());
+
+ if (thisCategory != null)
+ thisCategory.fillContext(context, new NullPermissionsChecker());
+
+ // Creating the trace (for each category, a path from from the root to
+ // that category).
+ String[] idTokens = categoryContext.split("[" + CAT_ID_SEPARATOR + "]");
+ String[] nameTokens = categoryNameContext.split("[" + CAT_ID_SEPARATOR
+ + "]");
+ String idPath = "";
+
+ DelegateContext rootTraceContext = context.next("trace");
+ rootTraceContext.put("id", "");
+ rootTraceContext.put("name", nameTokens[0]);
+
+ for (int i = 1; i < idTokens.length; i++) {
+ DelegateContext traceContext = context.next("trace");
+
+ idPath += CAT_ID_SEPARATOR + idTokens[i];
+
+ traceContext.put("id", idPath);
+ traceContext.put("name", nameTokens[i]);
+ }
+
+ }
+
+
/**
* Creates a new component descriptor that hold information about one
* category.
@@ -124,7 +236,7 @@
* @throws IOException
* @throws XmlNotFoundException
*/
- private DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,
+ /* private DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,
String categoryContext, String categoryNameContext,
String componentDir, String componentDesc, String portalName,
String projectId, ElementDescriptor thisCategory)
@@ -167,6 +279,11 @@
Node n;
NodeList nodes = doc.getDocumentElement().getChildNodes();
+
+
+ //TODO: BECOMES OUTDATED
+
+
// Parsing the descriptor
// If there's no parent category info, we look for a "root-category"
// tag.
@@ -181,11 +298,15 @@
categoryNameContext = thisCategory.getProperty("name");
}
}
- }
-
+ }
+
// If there's still no root category info, we throw an exception.
if (thisCategory == null)
throw new SAXException();
+
+ //TODO: BECOMES OUTDATED
+
+
// Parsing child categories and files descriptors.
for (int i = 0; i < nodes.getLength(); i++) {
@@ -210,8 +331,14 @@
}
}
+
+ //TODO: BECOMES OUTDATED
if (thisCategory != null)
thisCategory.fillContext(context, new NullPermissionsChecker());
+ //TODO: BECOMES OUTDATED
+
+
+
if (categoriesDesc != null)
categoriesDesc.fillContext(context.next("hasCategories"), "categories",
new NullPermissionsChecker());
@@ -238,13 +365,13 @@
traceContext.put("id", idPath);
traceContext.put("name", nameTokens[i]);
}
- }
+ }*/
private PropertiesHandler getCategoriesPropertiesHandler(
- final XmlInputFactory isf, final DomToXmlTransformer xht,
- final String portalName, final String projectId,
+ final XmlInputFactory isf, final DomToXmlTransformer xht, final Node node,
final String categoryContext, final String categoryNameContext,
- final String componentDir, final String componentDesc) {
+ final String componentDir, final String componentDesc,
+ final String portalName, final String projectId) {
PropertiesHandlerStack stack = new PropertiesHandlerStack();
stack.addHandler(new PropertiesHandlerDefault());
stack.addHandler(new PropertiesHandler() {
@@ -258,12 +385,12 @@
String categoryId = thisElement.getId();
try {
categories.put(categoryId, new DownloadsDescriptor(isf,
- xht, categoryContext + CAT_ID_SEPARATOR
+ xht,node, categoryContext + CAT_ID_SEPARATOR
+ categoryId, categoryNameContext
+ CAT_ID_SEPARATOR
+ thisElement.getProperty("name"),
componentDir, componentDesc,
- portalName, projectId, thisElement));
+ portalName, projectId,thisElement));
} catch (Exception e) {
// In case of an exception, we just don't add a child
// category.
Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectDescriptor.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectDescriptor.java 2006-07-05 22:44:42 UTC (rev 4924)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/ProjectDescriptor.java 2006-07-06 01:26:30 UTC (rev 4925)
@@ -67,6 +67,9 @@
private Node issueTrackerNode;
private IssueTracker issueTracker;
+ // TODO: HACK
+ private Node downloadsNode;
+
/**
* Reads information about a project from an xml file.
*
@@ -117,7 +120,7 @@
// Trying to create a downloads descriptor.
try {
- downloads = new DownloadsDescriptor(isf, xht,
+ downloads = new DownloadsDescriptor(isf, xht,downloadsNode,
ProjectsHelper.DOWNLOADS_DIR,
ProjectsHelper.DOWNLOADS_DESC,
portalName, getId());
@@ -210,6 +213,9 @@
if (IssueTracker.ISSUE_TRACKER_ELEMENT.equals(node.getNodeName())) {
setIssueTrackerNode(node);
}
+ if ("downloads".equals(node.getNodeName())) {
+ downloadsNode=node;
+ }
}
public void collect(PropertiesMap properties, Object data,
|