[jboss-svn-commits] JBL Code SVN: r5119 - labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 16 20:15:17 EDT 2006
Author: unibrew
Date: 2006-07-16 20:15:16 -0400 (Sun, 16 Jul 2006)
New Revision: 5119
Modified:
labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java
Log:
[JBLAB-681] Implementing parsing counters together with downloads.
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-16 20:25:04 UTC (rev 5118)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java 2006-07-17 00:15:16 UTC (rev 5119)
@@ -31,6 +31,7 @@
import java.util.Set;
import org.jboss.forge.common.ForgeHelper;
+import org.jboss.forge.common.XmlTools;
import org.jboss.forge.common.projects.XmlInputFactory.XmlNotFoundException;
import org.jboss.forge.common.projects.elements.BindingsHandlerIterSingleKey;
import org.jboss.forge.common.projects.elements.ElementDescriptor;
@@ -70,24 +71,32 @@
private String categoryContext;
private DelegateContext context;
+
+
+ // Counters Settings
+ private Sorting sortOrder=Sorting.RANDOM;
+
+ private Boolean visible = Boolean.TRUE;
/**
- * Creates a new component descriptor that hold information about one
+ * Creates a new component descriptor that hold information about root
* category.
*
+ * @param isf
+ * A factory of XML files.
* @param xht
* A XML -> HTML transformer.
- * @param isf
- * A factory of XML files.
- * @param portalName
- * Name of the portal to which this downloads belong to.
- * @param projectId
- * Id of the project to which this downloads belong to.
+ * @param node
+ * XML DOM node
* @param componentDir
* Name of the directory storing the files used (descriptors,
* content, etc)
* @param componentDesc
* Name of the descriptor file of the component
+ * @param portalName
+ * Name of the portal to which this downloads belong to.
+ * @param projectId
+ * Id of the project to which this downloads belong to.
* @throws SAXException
* @throws IOException
* @throws XmlNotFoundException
@@ -97,13 +106,44 @@
String projectId) throws SAXException, IOException,
XmlNotFoundException {
this(isf, xht,node, "", "", componentDir, componentDesc, portalName,
- projectId,null);
+ projectId,null,null,null);
}
+ /**
+ * Creates a new component descriptor that hold information about one
+ * category.
+ *
+ * @param isf
+ * A factory of XML files.
+ * @param xht
+ * A XML -> HTML transformer.
+ * @param node
+ * XML DOM node
+ * @param categoryContext
+ * Context of the category.
+ * @param categoryNameContext
+ * Context name category.
+ * @param componentDir
+ * Name of the directory storing the files used (descriptors,
+ * content, etc)
+ * @param componentDesc
+ * Name of the descriptor file of the component
+ * @param portalName
+ * Name of the portal to which this downloads belong to.
+ * @param projectId
+ * Id of the project to which this downloads belong to.
+ * @param thisCategory
+ * Parent category's ElementDescriptor
+ * @param parentDesc
+ * Parent DownloadsDescriptor
+ * @throws SAXException
+ * @throws IOException
+ * @throws XmlNotFoundException
+ */
private DownloadsDescriptor(XmlInputFactory isf, DomToXmlTransformer xht,Node node,
- String categoryContext, String categoryNameContext,
- String componentDir, String componentDesc, String portalName,
- String projectId,ElementDescriptor thisCategory)
+ String categoryContext, String categoryNameContext,String componentDir,
+ String componentDesc, String portalName,String projectId,
+ ElementDescriptor thisCategory, DownloadsDescriptor parentDesc,Map<String,Counter> counters)
throws SAXException, IOException, XmlNotFoundException {
this.categoryContext = categoryContext;
@@ -130,15 +170,50 @@
NodeList nodes = node.getChildNodes();
// Parsing the descriptor
- // If there's no parent category info, we look for a "root-category"
- // tag.
- if (thisCategory == null) {
+ // If there's no parent category info
+ if (thisCategory == null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
thisCategory = new ElementDescriptor(node, xht, new PropertiesHandlerDefault());
categoryNameContext = thisCategory.getProperty("name");
}
- }
+ }
+
+ // If this is root DownloadsDescriptor then counters should be null
+ // so we initialize it.
+ if (counters==null) {
+ counters = new HashMap<String,Counter>();
+ }
+
+ //System.out.println("-----------------------");
+ //System.out.println("JESTEM PRZED IF");
+ if (parentDesc!=null){
+ this.sortOrder = parentDesc.getSortOrder();
+ this.visible = parentDesc.getVisible();
+ //System.out.println("USTAWIŁEM SORT: "+sortOrder.name()+" VISIBLE: "+visible);
+ }
+ // Iterating to find counters' settings which must be parsed first because
+ // they are inherited by all underlaying nodes.
+ for (int i = 0; i < nodes.getLength(); i++) {
+ n = nodes.item(i);
+
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ if (n.getNodeName().equals("counters")) {
+ ElementDescriptor countSettings = new ElementDescriptor(n, xht,
+ new PropertiesHandlerDefault());
+ String visible = countSettings.getProperty("visible");
+ String sort = countSettings.getProperty("sorting");
+ if (visible!=null && visible.trim().length()>0) {
+ this.visible= Boolean.valueOf(visible.trim());
+ }
+ if (sort!=null && sort.trim().length()>0) {
+ this.sortOrder = Sorting.valueOf(sort.trim().toUpperCase());
+ }
+ }
+ }
+ }
+
+
// Parsing child categories and files descriptors.
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
@@ -149,17 +224,28 @@
getCategoriesPropertiesHandler(isf,xht,n,
categoryContext,categoryNameContext,
componentDir, componentDesc,
- portalName, projectId ));
+ portalName, projectId,this,counters ));
} else if (n.getNodeName().equals("files")) {
- filesDesc = new ElementsDescriptor(n, xht, "file",
+ String visible = XmlTools.getAttributeValue(n,"visible");
+ String sort = XmlTools.getAttributeValue(n,"sorting");
+ //System.out.println("FILES NODE VISIBLE: "+visible+ " SORT: "+sort);
+ if (visible!=null && visible.trim().length()>0) {
+ this.visible= Boolean.valueOf(visible.trim());
+ //System.out.println("FILES : W IFIE VISIBLE");
+ }
+ if (sort!=null && sort.trim().length()>0) {
+ this.sortOrder = Sorting.valueOf(sort.trim().toUpperCase());
+ //System.out.println("FILES : W IFIE SORTING");
+ }
+ filesDesc = new ElementsDescriptor(n, xht, "file",
getFilesPropertiesHandler(isf, projectId,
downloadPrefix, pathCategoryContext,
- File.separator,componentDir),
+ File.separator,componentDir,counters),
getFilesExtendedPropertiesMap(downloadPrefix,
pathCategoryContext, File.separator, portalName,
projectId),
- new OutsidePropertiesMap());
- }
+ new OutsidePropertiesMap());
+ }
}
}
@@ -182,8 +268,8 @@
DelegateContext rootTraceContext = context.next("trace");
rootTraceContext.put("id", "");
- rootTraceContext.put("name", nameTokens[0]);
-
+ rootTraceContext.put("name", nameTokens[0]);
+
for (int i = 1; i < idTokens.length; i++) {
DelegateContext traceContext = context.next("trace");
@@ -192,7 +278,18 @@
traceContext.put("id", idPath);
traceContext.put("name", nameTokens[i]);
}
-
+
+ if (parentDesc==null) {
+ //System.out.println("++++++++++++");
+ //System.out.println("ITERACJA DOWNLOADCOUNTERÓW");
+ for (String path : counters.keySet()) {
+ //System.out.println("COUNTER: "+path);
+ }
+ //System.out.println("++++++++++++");
+ }
+
+ //System.out.println("KONIEC SORT: "+sortOrder.name()+" VISIBLE: "+visible);
+ //System.out.println("++++++++++++++++++++");
}
@@ -228,7 +325,8 @@
final XmlInputFactory isf, final DomToXmlTransformer xht, final Node node,
final String categoryContext, final String categoryNameContext,
final String componentDir, final String componentDesc,
- final String portalName, final String projectId) {
+ final String portalName, final String projectId,
+ final DownloadsDescriptor parentDD, final Map<String,Counter>counters) {
PropertiesHandlerStack stack = new PropertiesHandlerStack();
stack.addHandler(new PropertiesHandlerDefault());
stack.addHandler(new PropertiesHandler() {
@@ -246,8 +344,8 @@
+ categoryId, categoryNameContext
+ CAT_ID_SEPARATOR
+ thisElement.getProperty("name"),
- componentDir, componentDesc,
- portalName, projectId,thisElement));
+ componentDir, componentDesc, portalName, projectId,
+ thisElement,parentDD,counters));
} catch (Exception e) {
// In case of an exception, we just don't add a child
// category.
@@ -346,10 +444,11 @@
private PropertiesHandler getFilesPropertiesHandler(
final XmlInputFactory isf, final String projectId,
final String downloadPrefix, final String pathCategoryContext,
- final String separator, final String componentDir) {
+ final String separator, final String componentDir, final Map<String,Counter>counters) {
PropertiesHandlerStack stack = new PropertiesHandlerStack();
stack.addHandler(new PropertiesHandlerDefault());
stack.addHandler(new PropertiesHandler() {
+
public void fillContext(PropertiesMap properties,
DelegateContext context, PermissionsChecker pc) {
String id = properties.get("id").getFirstValue();
@@ -397,13 +496,40 @@
}
public void processNode(ElementDescriptor thisElement, Node node) {
-
+
+ if (node.getNodeName().compareToIgnoreCase("id")==0) {
+
+ String id = XmlTools.unmarshallText(node);
+
+ if (id==null) return;
+
+ String pathToFile = separator + projectId
+ + separator + componentDir + separator
+ + pathCategoryContext + separator + id.trim();
+ //System.out.println("PATHTOFILE: "+pathToFile);
+
+ String visible = XmlTools.getAttributeValue(node.getParentNode(),"visible");
+
+ //System.out.println("----------------------");
+ //System.out.println("PROCNODE: "+ node.getNodeName());
+ //System.out.println("FILENODE VIS: "+visible);
+
+
+ Boolean counterVis = getVisible();
+ Sorting counterSort = getSortOrder();
+ if (visible!=null && visible.trim().length()>0) {
+ counterVis= Boolean.valueOf(visible);
+ }
+ //System.out.println("KONINODE VIS: "+counterVis+ " SORT: "+ counterSort.name());
+ counters.put(pathToFile,new Counter(0L,projectId,counterVis,counterSort));
+
+ }
}
- public void collect(PropertiesMap properties, Object data,
+ public void collect(PropertiesMap properties, Object data,
PermissionsChecker pc) {
- }
+ }
});
return stack;
@@ -483,6 +609,10 @@
return dd.getDownloadsDesciptor(tokens[1]);
}
+
+ public DownloadsDescriptor getThisDownloadsDescriptor() {
+ return this;
+ }
/**
* Gets a context for JSP pages that holds information about this category.
@@ -492,6 +622,21 @@
public DelegateContext getContext() {
return context;
}
+
+ /**
+ * Gets a sortOrder enum value.
+ */
+ public Sorting getSortOrder() {
+ return sortOrder;
+ }
+
+ /**
+ * Gets counters visibility state.
+ */
+ public Boolean getVisible() {
+ return visible;
+ }
+
/**
* To the given set, adds all descriptors for this category and child
More information about the jboss-svn-commits
mailing list