From: <jbo...@li...> - 2005-12-25 00:35:13
|
Author: unibrew Date: 2005-12-24 19:35:09 -0500 (Sat, 24 Dec 2005) New Revision: 1931 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCounterDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java Log: [JBLAB-581] DownloadCounters have now possibility to hide them. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java 2005-12-25 00:33:18 UTC (rev 1930) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Counter.java 2005-12-25 00:35:09 UTC (rev 1931) @@ -44,6 +44,11 @@ private String projectId; /** + * The information whether counter should be visible on portlet or not. + */ + private Boolean visible; + + /** * Main constructor simply initiates values. * * @param value @@ -51,9 +56,10 @@ * @param projectId * Name of project for this counter. */ - Counter (long value,String projectId) { + Counter (long value,String projectId,Boolean visible) { this.value=value; this.projectId=projectId; + this.visible = visible; } /** @@ -81,6 +87,23 @@ } /** + * Method returns information if counter is visible. + * @return + * Visibility status of the counter. + */ + public Boolean getVisible() { + return visible; + } + + /** + * Method sets visibility of the counter. + * @param visible + */ + public void setVisible(Boolean visible) { + this.visible = visible; + } + + /** * Overrided method returns String containing value of the counter. */ public String toString () { Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCounterDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCounterDescriptor.java 2005-12-25 00:33:18 UTC (rev 1930) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCounterDescriptor.java 2005-12-25 00:35:09 UTC (rev 1931) @@ -25,8 +25,10 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Hashtable; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.apache.xerces.parsers.DOMParser; import org.jboss.forge.common.XmlTools; @@ -49,7 +51,7 @@ /** * This variable contains all links, which need to be tracked, collected from xml descriptor. */ - private List<String> links; + private Map<String,Boolean> links; /** * Name of tag in counter.xml containing counter link. @@ -62,6 +64,21 @@ public static final String COUNTER = "counter"; /** + * This variable contains name of the visibility attribute. + */ + public static final String VISIBILITY = "visible"; + + /** + * This variable contains value for attributes which means TRUE. + */ + public static final String TRUE = "true"; + + /** + * This variable contains value for attributes which means FALSE. + */ + public static final String FALSE = "false"; + + /** * Main DownloadCounterDescriptor constructor which parses the xml descriptor for a project * and collects data from it. * @@ -86,7 +103,7 @@ NodeList nodes = doc.getDocumentElement().getChildNodes(); // Parsing and gettting download links which are requested to be tracked by download counter. - links = new LinkedList<String>(); + links = new Hashtable<String,Boolean>(); for (int i = 0; i < nodes.getLength(); i++) { n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { @@ -95,10 +112,16 @@ for (int j=0;j< counterProps.getLength() ; j++) { property = counterProps.item(j); if (property.getNodeType()== Node.ELEMENT_NODE){ + String visibilityAtt = XmlTools.getAttributeValue(property,VISIBILITY); + boolean visibility = true; + if (visibilityAtt!=null && visibilityAtt.equals(FALSE)) { + visibility = false; + } if (property.getNodeName().equals(LINK) && XmlTools.unmarshallText(property) != null && !XmlTools.unmarshallText(property).trim().equals("")) { - links.add(XmlTools.unmarshallText(property).trim()); + links.put(XmlTools.unmarshallText(property).trim(),visibility); } + } } } @@ -112,7 +135,7 @@ * @return * List<String> of download links. */ - public List<String> getLinks () { + public Map<String,Boolean> getLinks () { return links; } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2005-12-25 00:33:18 UTC (rev 1930) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2005-12-25 00:35:09 UTC (rev 1931) @@ -71,8 +71,23 @@ * Name of tag in counters.xml containing project id. */ public static final String ID = "id"; + + /** + * This variable contains name of the visibility attribute. + */ + public static final String VISIBILITY = "visible"; /** + * This variable contains value for attributes which means TRUE. + */ + public static final String TRUE = "true"; + + /** + * This variable contains value for attributes which means FALSE. + */ + public static final String FALSE = "false"; + + /** * This Map contains all counters for the portal. */ private Map<String,Counter> downloadCounters; @@ -212,19 +227,20 @@ new DownloadCounterDescriptor(counters.get(projectId)); // Getting list of links which are now tracked by downloadCounters. - List<String> xmlProjectLinks = getProjectLinks(projectId); + Map<String,Boolean> xmlProjectLinks = getProjectLinks(projectId); // Getting the list of links from download counter descriptor. - List<String> links = counterDesc.getLinks(); + Map<String,Boolean> links = counterDesc.getLinks(); // This list will be used for collecting links which must be // removed from downloadCounters. List<String> linksToDelete = new LinkedList<String>(); // Searching for links to remove and links which are already tracked. - for (String link:xmlProjectLinks) { - if (links.contains(link)) { - links.remove(link); + for (String link:xmlProjectLinks.keySet()) { + if (links.keySet().contains(link)) { + setCounterVisibility (link,links.get(link)); + links.keySet().remove(link); } else { linksToDelete.add(link); } @@ -262,6 +278,18 @@ } /** + * Method sets visibility for counter in downloadCounters Map as requested + * in <code>visibility</code> parameter. + * @param link + * The link to the counter. + * @param visibility + * Visibility which counter should have. + */ + private synchronized void setCounterVisibility (String link, Boolean visibility) { + downloadCounters.get(link).setVisible(visibility); + } + + /** * Method adds links which are wished to be tracked. * * @param links @@ -269,10 +297,10 @@ * @param projectId * Project id name for which the links are added. */ - private synchronized void addLinksForCounting (List<String> links,String projectId) { + private synchronized void addLinksForCounting (Map<String,Boolean> links,String projectId) { // Adding new download links for tracking. - for (String link:links) { - downloadCounters.put(link,new Counter(0,projectId)); + for (String link:links.keySet()) { + downloadCounters.put(link,new Counter(0,projectId,links.get(link))); } } @@ -305,11 +333,11 @@ * Id of a project for which the links will be searched. * @return List<String> Containing tracked links. */ - private synchronized List<String> getProjectLinks (String projectId) { - List<String> links = new LinkedList<String>(); + private synchronized Map<String,Boolean> getProjectLinks (String projectId) { + Map<String,Boolean> links = new Hashtable<String,Boolean>(); for (String link:downloadCounters.keySet()) { if (downloadCounters.get(link).getProjectId().equals(projectId)) { - links.add(new String(link)); + links.put(new String(link),downloadCounters.get(link).getVisible()); } } return links; @@ -324,10 +352,12 @@ * Map<String,Long> containing link:value pairs. */ public synchronized Map<String,Long> getValuesForPortlet (String projectId) { - List<String> links = getProjectLinks(projectId); + Map<String,Boolean> links = getProjectLinks(projectId); Map<String,Long> values = new Hashtable<String,Long>(links.size()); - for (String link : links) { - values.put(link,downloadCounters.get(link).getValue()); + for (String link : links.keySet()) { + if (links.get(link)) { + values.put(link,downloadCounters.get(link).getValue()); + } } return values; } @@ -384,6 +414,9 @@ for (String link:keys) { temporary = downloadCounters.get(link); Node newCounter = doc.createElement(COUNTER); + Node counterVisibility = doc.createAttribute(VISIBILITY); + counterVisibility.appendChild(doc.createTextNode(temporary.getVisible().toString())); + newCounter.getAttributes().setNamedItem(counterVisibility); Node newLink = doc.createElement(LINK); Node newLinkText = doc.createTextNode(link); @@ -472,11 +505,16 @@ String tempLink = null; String tempValue = null; String tempId = null; + boolean visibility = true; for (int j=0;j< counterProps.getLength() ; j++) { property = counterProps.item(j); if (property.getNodeType()== Node.ELEMENT_NODE){ String nodeTextCnt = XmlTools.unmarshallText(property); if (property.getNodeName().equals(LINK) && nodeTextCnt != null && !nodeTextCnt.trim().equals("")) { + String visibilityAtt = XmlTools.getAttributeValue(property,VISIBILITY); + if (visibilityAtt!=null && visibilityAtt.equals(FALSE)) { + visibility = false; + } tempLink = nodeTextCnt.trim(); } else if (property.getNodeName().equals(VALUE) && nodeTextCnt !=null && !nodeTextCnt.trim().equals("")) { tempValue = nodeTextCnt.trim(); @@ -486,7 +524,7 @@ } } if (tempLink!=null && tempValue!=null && tempId!=null) { - values.put(tempLink,new Counter(Long.valueOf(tempValue),tempId)); + values.put(tempLink,new Counter(Long.valueOf(tempValue),tempId,visibility)); } } } |