Nicht sichtbare Kategorien (Category#setVisible(false)) werden jetzt nur noch angezeigt, wenn sie explizit aufgerufen werden.
git-svn-id: https://svn.libreccm.org/ccm/trunk@2173 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
4edddb7faa
commit
d29291bd87
|
|
@ -15,10 +15,8 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.arsdigita.navigation.ui.category;
|
package com.arsdigita.navigation.ui.category;
|
||||||
|
|
||||||
|
|
||||||
import com.arsdigita.navigation.ui.CategoryComponent;
|
import com.arsdigita.navigation.ui.CategoryComponent;
|
||||||
import com.arsdigita.navigation.Navigation;
|
import com.arsdigita.navigation.Navigation;
|
||||||
|
|
||||||
|
|
@ -51,27 +49,27 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
public abstract class AbstractTree extends CategoryComponent {
|
public abstract class AbstractTree extends CategoryComponent {
|
||||||
|
|
||||||
private static Logger s_log = Logger.getLogger(AbstractTree.class);
|
private static Logger s_log = Logger.getLogger(AbstractTree.class);
|
||||||
|
|
||||||
protected Element generateTreeXML(HttpServletRequest request,
|
protected Element generateTreeXML(HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
Category cat,
|
Category cat,
|
||||||
CategoryCollection cats,
|
CategoryCollection cats,
|
||||||
BigDecimal[] selected) {
|
BigDecimal[] selected) {
|
||||||
Map children = new HashMap();
|
Map children = new HashMap();
|
||||||
Category currentCat = new Category(selected[selected.length - 1]);
|
Category currentCat = new Category(selected[selected.length - 1]);
|
||||||
while (cats.next()) {
|
while (cats.next()) {
|
||||||
Category category = cats.getCategory();
|
Category category = cats.getCategory();
|
||||||
|
|
||||||
// enable implementations to fettle with the path without breaking the
|
// enable implementations to fettle with the path without breaking the
|
||||||
// tree that is created, by setting the parent to ensure it is in the
|
// tree that is created, by setting the parent to ensure it is in the
|
||||||
// tree (this can be used eg to skip categories in some circumstances
|
// tree (this can be used eg to skip categories in some circumstances
|
||||||
// without breaking the chain from root to the selected category
|
// without breaking the chain from root to the selected category
|
||||||
BigDecimal parentID = getParentID(cats, currentCat, category, selected);
|
BigDecimal parentID = getParentID(cats, currentCat, category, selected);
|
||||||
|
|
||||||
Boolean isDefault = (Boolean) cats.get("parents@link.isDefault");
|
Boolean isDefault = (Boolean) cats.get("parents@link.isDefault");
|
||||||
|
|
||||||
if (isDefault == null) {
|
if (isDefault == null) {
|
||||||
isDefault = new Boolean(false);
|
isDefault = new Boolean(false);
|
||||||
}
|
}
|
||||||
|
|
@ -79,61 +77,63 @@ public abstract class AbstractTree extends CategoryComponent {
|
||||||
Category parent = new Category(parentID);
|
Category parent = new Category(parentID);
|
||||||
s_log.debug("Parent is " + parent.getName());
|
s_log.debug("Parent is " + parent.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Set childList = (Set)children.get(parentID);
|
Set childList = (Set) children.get(parentID);
|
||||||
if (childList == null) {
|
if (childList == null) {
|
||||||
childList = new TreeSet();
|
childList = new TreeSet();
|
||||||
s_log.debug("Adding new list for this parent");
|
s_log.debug("Adding new list for this parent");
|
||||||
children.put(parentID, childList);
|
children.put(parentID, childList);
|
||||||
}
|
}
|
||||||
|
|
||||||
childList.add(new CategorySortKeyPair
|
childList.add(new CategorySortKeyPair(category,
|
||||||
(category,
|
(BigDecimal) cats.get("parents.link.sortKey"),
|
||||||
(BigDecimal)cats.get("parents.link.sortKey"),
|
isDefault.booleanValue()));
|
||||||
isDefault.booleanValue()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = URLService.locate(cat.getOID());
|
String path = URLService.locate(cat.getOID());
|
||||||
|
|
||||||
return generateNodeXML(request,
|
return generateNodeXML(request,
|
||||||
response,
|
response,
|
||||||
cat,
|
cat,
|
||||||
null,
|
null,
|
||||||
selected,
|
selected,
|
||||||
children,
|
children,
|
||||||
path,
|
path,
|
||||||
Collections.EMPTY_LIST);
|
Collections.EMPTY_LIST);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* implementations may override this method to change the parent associated with the current category
|
* implementations may override this method to change the parent associated with the current category
|
||||||
* enabling categories to be skipped without breaking the tree
|
* enabling categories to be skipped without breaking the tree
|
||||||
*/
|
*/
|
||||||
protected BigDecimal getParentID(CategoryCollection cats,
|
protected BigDecimal getParentID(CategoryCollection cats,
|
||||||
Category currentCat,
|
Category currentCat,
|
||||||
Category currentChild,
|
Category currentChild,
|
||||||
BigDecimal[] selected) {
|
BigDecimal[] selected) {
|
||||||
return (BigDecimal)cats.get("parents.id");
|
return (BigDecimal) cats.get("parents.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Element generateNodeXML(HttpServletRequest request,
|
protected Element generateNodeXML(HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
Category cat,
|
Category cat,
|
||||||
BigDecimal sortKey,
|
BigDecimal sortKey,
|
||||||
BigDecimal[] selected,
|
BigDecimal[] selected,
|
||||||
Map children,
|
Map children,
|
||||||
String path,
|
String path,
|
||||||
List idPath) {
|
List idPath) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!cat.isEnabled()) {
|
if (!cat.isEnabled()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
s_log.debug("generating node XML for category " + cat.getName() );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
s_log.debug("generating node XML for category " + cat.getName());
|
||||||
|
|
||||||
// replace idPath list with one containing cat.id appended
|
// replace idPath list with one containing cat.id appended
|
||||||
idPath = new ArrayList(idPath);
|
idPath = new ArrayList(idPath);
|
||||||
idPath.add(cat.getID());
|
idPath.add(cat.getID());
|
||||||
|
|
@ -141,121 +141,143 @@ public abstract class AbstractTree extends CategoryComponent {
|
||||||
StringBuffer buff = new StringBuffer("ID Path is ");
|
StringBuffer buff = new StringBuffer("ID Path is ");
|
||||||
Iterator it = idPath.iterator();
|
Iterator it = idPath.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
BigDecimal id = (BigDecimal)it.next();
|
BigDecimal id = (BigDecimal) it.next();
|
||||||
Category thisCat = new Category(id);
|
Category thisCat = new Category(id);
|
||||||
buff.append(thisCat.getName() + " - ");
|
buff.append(thisCat.getName() + " - ");
|
||||||
}
|
}
|
||||||
s_log.debug(buff.toString());
|
s_log.debug(buff.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isSelected = false;
|
||||||
|
if (selected.length >= idPath.size()) {
|
||||||
|
isSelected = true;
|
||||||
|
for (int x = 0; x < idPath.size(); x++) {
|
||||||
|
if (!idPath.get(x).equals(selected[x])) {
|
||||||
|
isSelected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
isSelected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSelected && !cat.isVisible()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// We will concatenate category URLs only if all ancestors have
|
// We will concatenate category URLs only if all ancestors have
|
||||||
// their URLs set correctly. We recognize that is the case if
|
// their URLs set correctly. We recognize that is the case if
|
||||||
// path ends with slash. Otherwise resort to generic (ie. redirect)
|
// path ends with slash. Otherwise resort to generic (ie. redirect)
|
||||||
// URLs.
|
// URLs.
|
||||||
boolean concatURLs = (path != null && path.endsWith("/"));
|
boolean concatURLs = (path != null && path.endsWith("/"));
|
||||||
|
|
||||||
Element el = generateCategoryXML(request,
|
Element el = generateCategoryXML(request,
|
||||||
response,
|
response,
|
||||||
cat.getID(),
|
cat.getID(),
|
||||||
cat.getName(),
|
cat.getName(),
|
||||||
cat.getDescription(),
|
cat.getDescription(),
|
||||||
concatURLs ? path : Navigation.redirectURL(cat.getOID()));
|
concatURLs ? path : Navigation.redirectURL(cat.getOID()));
|
||||||
|
|
||||||
el.addAttribute("AbstractTree", "AbstractTree");
|
el.addAttribute("AbstractTree", "AbstractTree");
|
||||||
|
|
||||||
el.addAttribute("sortKey", XML.format(sortKey));
|
el.addAttribute("sortKey", XML.format(sortKey));
|
||||||
|
|
||||||
// compare idPath with the start of selected
|
if (isSelected) {
|
||||||
if (selected.length >= idPath.size()) {
|
el.addAttribute("isSelected", "true");
|
||||||
boolean isSelected = true;
|
|
||||||
for (int x=0; x<idPath.size(); x++) {
|
|
||||||
if (!idPath.get(x).equals(selected[x])) {
|
|
||||||
isSelected = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isSelected) {
|
|
||||||
el.addAttribute("isSelected", "true" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compare idPath with the start of selected
|
||||||
|
// if (selected.length >= idPath.size()) {
|
||||||
|
// boolean isSelected = true;
|
||||||
|
// for (int x = 0; x < idPath.size(); x++) {
|
||||||
|
// if (!idPath.get(x).equals(selected[x])) {
|
||||||
|
// isSelected = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (isSelected) {
|
||||||
|
// el.addAttribute("isSelected", "true");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Quasimodo: Begin
|
// Quasimodo: Begin
|
||||||
Set c = (Set)children.get(cat.getID());
|
Set c = (Set) children.get(cat.getID());
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
Iterator i = c.iterator();
|
Iterator i = c.iterator();
|
||||||
|
|
||||||
// Lokale Hilfsvariablen
|
// Lokale Hilfsvariablen
|
||||||
long childCounter = 0;
|
long childCounter = 0;
|
||||||
long maxChildCounter = calcMaxChildCounter(cat, selected);
|
long maxChildCounter = calcMaxChildCounter(cat, selected);
|
||||||
|
|
||||||
while (i.hasNext() && maxChildCounter > 0) {
|
while (i.hasNext() && maxChildCounter > 0) {
|
||||||
|
|
||||||
CategorySortKeyPair pair = (CategorySortKeyPair) i.next();
|
CategorySortKeyPair pair = (CategorySortKeyPair) i.next();
|
||||||
Category child = pair.getCategory();
|
Category child = pair.getCategory();
|
||||||
BigDecimal childSortKey = pair.getSortKey();
|
BigDecimal childSortKey = pair.getSortKey();
|
||||||
|
|
||||||
Element childEl = generateNodeXML(request,
|
Element childEl = generateNodeXML(request,
|
||||||
response,
|
response,
|
||||||
child,
|
child,
|
||||||
childSortKey,
|
childSortKey,
|
||||||
selected,
|
selected,
|
||||||
children,
|
children,
|
||||||
concatURLs && child.getURL() != null
|
concatURLs && child.getURL() != null
|
||||||
? path + child.getURL() + "/"
|
? path + child.getURL() + "/"
|
||||||
: null,
|
: null,
|
||||||
idPath
|
idPath);
|
||||||
);
|
|
||||||
|
|
||||||
if (childEl != null) {
|
if (childEl != null) {
|
||||||
|
|
||||||
// Respect the calculated maxChildCounter
|
// Respect the calculated maxChildCounter
|
||||||
if(childCounter < maxChildCounter) {
|
if (childCounter < maxChildCounter) {
|
||||||
|
|
||||||
boolean isDefault = pair.isDefault();
|
boolean isDefault = pair.isDefault();
|
||||||
childEl.addAttribute("isDefault", String.valueOf(isDefault));
|
childEl.addAttribute("isDefault", String.valueOf(isDefault));
|
||||||
|
|
||||||
el.addContent(childEl);
|
el.addContent(childEl);
|
||||||
childCounter++;
|
childCounter++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// add showMore attribute
|
// add showMore attribute
|
||||||
el.addAttribute(Menu.MORE_ATTRIB, "true");
|
el.addAttribute(Menu.MORE_ATTRIB, "true");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Quasimodo: End
|
// Quasimodo: End
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quasimodo: Begin
|
// Quasimodo: Begin
|
||||||
// Java ist mal wieder zu blöd richtig zu vergleichen. Es gibt wieder keine Methode, die den Inhalt
|
// Java ist mal wieder zu blöd richtig zu vergleichen. Es gibt wieder keine Methode, die den Inhalt
|
||||||
// der Collections vergleicht - equals vergleicht nur auf Objectbasis, also ob es sich um das selbe
|
// der Collections vergleicht - equals vergleicht nur auf Objectbasis, also ob es sich um das selbe
|
||||||
// Object handelt. Was für eine sinnlose Implementierung.
|
// Object handelt. Was für eine sinnlose Implementierung.
|
||||||
// Compare the CONTENTS of CategoryCollections
|
// Compare the CONTENTS of CategoryCollections
|
||||||
protected boolean compareCategoryCollection(CategoryCollection a, CategoryCollection b) {
|
protected boolean compareCategoryCollection(CategoryCollection a, CategoryCollection b) {
|
||||||
|
|
||||||
// Not equal, if sizes don't match
|
// Not equal, if sizes don't match
|
||||||
if(a.size() != b.size()) return false;
|
if (a.size() != b.size()) {
|
||||||
|
return false;
|
||||||
// Access every Object in the Collections
|
|
||||||
while(a.next() && b.next()) {
|
|
||||||
|
|
||||||
// If they don't match, they ain't equal
|
|
||||||
if(!a.getCategory().equals(b.getCategory())) return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Access every Object in the Collections
|
||||||
|
while (a.next() && b.next()) {
|
||||||
|
|
||||||
|
// If they don't match, they ain't equal
|
||||||
|
if (!a.getCategory().equals(b.getCategory())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hurray, they are equal
|
// Hurray, they are equal
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Quasimodo: End
|
// Quasimodo: End
|
||||||
|
|
||||||
// Quasimodo: Begin
|
// Quasimodo: Begin
|
||||||
// Calculating the maxChildCounter for generateNodeXML
|
// Calculating the maxChildCounter for generateNodeXML
|
||||||
// This is needed for the adaptive mode of the Menu class. Calculating the maximum shown children per menu.
|
// This is needed for the adaptive mode of the Menu class. Calculating the maximum shown children per menu.
|
||||||
|
|
@ -266,29 +288,34 @@ public abstract class AbstractTree extends CategoryComponent {
|
||||||
return new Long(Long.MAX_VALUE).longValue();
|
return new Long(Long.MAX_VALUE).longValue();
|
||||||
}
|
}
|
||||||
// Quasimodo: End
|
// Quasimodo: End
|
||||||
|
|
||||||
private class CategorySortKeyPair implements Comparable {
|
private class CategorySortKeyPair implements Comparable {
|
||||||
|
|
||||||
private Category m_category;
|
private Category m_category;
|
||||||
private BigDecimal m_sortKey;
|
private BigDecimal m_sortKey;
|
||||||
private boolean m_isDefault;
|
private boolean m_isDefault;
|
||||||
|
|
||||||
public CategorySortKeyPair(Category category, BigDecimal sortKey, boolean isDefault) {
|
public CategorySortKeyPair(Category category, BigDecimal sortKey, boolean isDefault) {
|
||||||
m_category = category;
|
m_category = category;
|
||||||
m_sortKey = sortKey;
|
m_sortKey = sortKey;
|
||||||
m_isDefault = isDefault;
|
m_isDefault = isDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Category getCategory() {
|
public Category getCategory() {
|
||||||
return m_category;
|
return m_category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getSortKey() {
|
public BigDecimal getSortKey() {
|
||||||
return m_sortKey;
|
return m_sortKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDefault() {
|
public boolean isDefault() {
|
||||||
return m_isDefault;
|
return m_isDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
return m_sortKey.compareTo(((CategorySortKeyPair)o).m_sortKey);
|
return m_sortKey.compareTo(((CategorySortKeyPair) o).m_sortKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue