You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/06/13 10:24:17 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication SiteTreeNodeImpl.java

egli        2003/06/13 01:24:17

  Modified:    src/java/org/apache/lenya/cms/publication
                        SiteTreeNodeImpl.java
  Log:
  Fixed a problem with a nullpointerexception in getLabel and
  fixed the indenting.
  
  Revision  Changes    Path
  1.7       +127 -120  cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java
  
  Index: SiteTreeNodeImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SiteTreeNodeImpl.java	30 May 2003 20:57:59 -0000	1.6
  +++ SiteTreeNodeImpl.java	13 Jun 2003 08:24:16 -0000	1.7
  @@ -54,124 +54,131 @@
   
   import org.apache.lenya.xml.DocumentHelper;
   
  -public class SiteTreeNodeImpl 
  -    implements SiteTreeNode {
  -    private static Category log = Category.getInstance(SiteTreeNodeImpl.class);
  -
  -    public static final String ID_ATTRIBUTE_NAME = "id";
  -    public static final String HREF_ATTRIBUTE_NAME = "href";
  -    public static final String SUFFIX_ATTRIBUTE_NAME = "suffix";
  -    public static final String LINK_ATTRIBUTE_NAME = "link";
  -    public static final String LANGUAGE_ATTRIBUTE_NAME = "xml:lang";
  -
  -    public static final String NODE_NAME = "node";
  -    public static final String LABEL_NAME = "label";
  -
  -    private Node node = null;
  -
  -    public SiteTreeNodeImpl(Node node) {
  - 	this.node = node;
  -    }
  -
  -    public String getParentId() {
  -	Node parent = node.getParentNode();
  -        if (parent == null) {
  -          return "/";
  -        }
  -        NamedNodeMap attributes = parent.getAttributes();
  -        if (attributes == null) {  
  -          return "/";
  -        }
  -        Node idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
  -        if (idAttribute == null) {
  -          return "/";
  -        }
  -        return idAttribute.getNodeValue();
  -    }
  -
  -    public String getAbsoluteParentId() {
  -	String absoluteId = "";
  -	Node parent = node.getParentNode();
  -	NamedNodeMap attributes = null;
  -	Node idAttribute = null;
  -	
  -	while (parent != null) {
  -	    attributes = parent.getAttributes();
  -	    if (attributes == null) {
  -		break;
  -	    }
  -	    idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
  -	    if (idAttribute == null) {
  -		break;
  -	    }
  -	    absoluteId = "/" + idAttribute.getNodeValue() + absoluteId;
  -	    parent = parent.getParentNode();
  -	}
  -	return absoluteId;
  -    }
  -
  -    public String getId() {
  -	return node.getAttributes().getNamedItem(ID_ATTRIBUTE_NAME).getNodeValue();
  -    }
  -
  -    public Label[] getLabels() {
  -	ArrayList labels = new ArrayList();
  -
  -	NodeList children = node.getChildNodes();
  -	for (int i = 0; i < children.getLength(); i++) {
  -	    NamedNodeMap attributes = children.item(i).getAttributes();
  -	    Node child = children.item(i);
  -	    if (child.getNodeType() == Node.ELEMENT_NODE &&
  -		child.getNodeName().equals(LABEL_NAME)) {
  -
  -		String labelName = DocumentHelper.getSimpleElementText((Element)child);
  -		String labelLanguage = null;
  -		Node languageAttribute = child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
  -		if (languageAttribute != null) {
  -		    labelLanguage = languageAttribute.getNodeValue();
  -		}
  -		labels.add(new Label(labelName, labelLanguage));
  -	    }
  -	}
  -	return (Label[])labels.toArray(new Label[labels.size()]);
  -    }
  -
  -    public Label getLabel(String xmlLanguage) {
  -	Label label = null;
  -	Label[] labels = getLabels();
  -	for (int i = 0; i < labels.length; i++) {
  -	    if (labels[i].getLanguage().equals(xmlLanguage)) {
  -		label = labels[i];
  -		break;
  -	    }
  -	}
  -	return label;
  -    }
  -
  -    public String getHref() {
  -	Node attribute = node.getAttributes().getNamedItem(HREF_ATTRIBUTE_NAME);
  -	if (attribute != null) {
  -	    return attribute.getNodeValue();
  -	} else {
  -	    return null;
  -	}
  -    }
  -
  -    public String getSuffix() {
  -	Node attribute = node.getAttributes().getNamedItem(SUFFIX_ATTRIBUTE_NAME);
  -	if (attribute != null) {
  -	    return attribute.getNodeValue();
  -	} else {
  -	    return null;
  -	}
  -    }
  -
  -    public boolean hasLink() {
  -	Node attribute = node.getAttributes().getNamedItem(LINK_ATTRIBUTE_NAME);
  -	if (attribute != null) {
  -	    return attribute.getNodeValue().equals("true");
  -	} else {
  -	    return false;
  +public class SiteTreeNodeImpl implements SiteTreeNode {
  +	private static Category log = Category.getInstance(SiteTreeNodeImpl.class);
  +
  +	public static final String ID_ATTRIBUTE_NAME = "id";
  +	public static final String HREF_ATTRIBUTE_NAME = "href";
  +	public static final String SUFFIX_ATTRIBUTE_NAME = "suffix";
  +	public static final String LINK_ATTRIBUTE_NAME = "link";
  +	public static final String LANGUAGE_ATTRIBUTE_NAME = "xml:lang";
  +
  +	public static final String NODE_NAME = "node";
  +	public static final String LABEL_NAME = "label";
  +
  +	private Node node = null;
  +
  +	public SiteTreeNodeImpl(Node node) {
  +		this.node = node;
  +	}
  +
  +	public String getParentId() {
  +		Node parent = node.getParentNode();
  +		if (parent == null) {
  +			return "/";
  +		}
  +		NamedNodeMap attributes = parent.getAttributes();
  +		if (attributes == null) {
  +			return "/";
  +		}
  +		Node idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
  +		if (idAttribute == null) {
  +			return "/";
  +		}
  +		return idAttribute.getNodeValue();
  +	}
  +
  +	public String getAbsoluteParentId() {
  +		String absoluteId = "";
  +		Node parent = node.getParentNode();
  +		NamedNodeMap attributes = null;
  +		Node idAttribute = null;
  +
  +		while (parent != null) {
  +			attributes = parent.getAttributes();
  +			if (attributes == null) {
  +				break;
  +			}
  +			idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
  +			if (idAttribute == null) {
  +				break;
  +			}
  +			absoluteId = "/" + idAttribute.getNodeValue() + absoluteId;
  +			parent = parent.getParentNode();
  +		}
  +		return absoluteId;
  +	}
  +
  +	public String getId() {
  +		return node
  +			.getAttributes()
  +			.getNamedItem(ID_ATTRIBUTE_NAME)
  +			.getNodeValue();
  +	}
  +
  +	public Label[] getLabels() {
  +		ArrayList labels = new ArrayList();
  +
  +		NodeList children = node.getChildNodes();
  +		for (int i = 0; i < children.getLength(); i++) {
  +			NamedNodeMap attributes = children.item(i).getAttributes();
  +			Node child = children.item(i);
  +			if (child.getNodeType() == Node.ELEMENT_NODE
  +				&& child.getNodeName().equals(LABEL_NAME)) {
  +
  +				String labelName =
  +					DocumentHelper.getSimpleElementText((Element) child);
  +				String labelLanguage = null;
  +				Node languageAttribute =
  +					child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
  +				if (languageAttribute != null) {
  +					labelLanguage = languageAttribute.getNodeValue();
  +				}
  +				labels.add(new Label(labelName, labelLanguage));
  +			}
  +		}
  +		return (Label[]) labels.toArray(new Label[labels.size()]);
  +	}
  +
  +	public Label getLabel(String xmlLanguage) {
  +		Label label = null;
  +		Label[] labels = getLabels();
  +		String language = null;
  +		for (int i = 0; i < labels.length; i++) {
  +			language = labels[i].getLanguage();
  +			if ((language != null) && (language.equals(xmlLanguage))) {
  +				label = labels[i];
  +				break;
  +			}
  +		}
  +		return label;
  +	}
  +
  +	public String getHref() {
  +		Node attribute = node.getAttributes().getNamedItem(HREF_ATTRIBUTE_NAME);
  +		if (attribute != null) {
  +			return attribute.getNodeValue();
  +		} else {
  +			return null;
  +		}
  +	}
  +
  +	public String getSuffix() {
  +		Node attribute =
  +			node.getAttributes().getNamedItem(SUFFIX_ATTRIBUTE_NAME);
  +		if (attribute != null) {
  +			return attribute.getNodeValue();
  +		} else {
  +			return null;
  +		}
  +	}
  +
  +	public boolean hasLink() {
  +		Node attribute = node.getAttributes().getNamedItem(LINK_ATTRIBUTE_NAME);
  +		if (attribute != null) {
  +			return attribute.getNodeValue().equals("true");
  +		} else {
  +			return false;
  +		}
   	}
  -    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org