001: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.layout.node;
007:
008: import org.jasig.portal.PortalException;
009: import org.w3c.dom.Document;
010: import org.w3c.dom.Element;
011:
012: /**
013: * A class describing a folder node fo the user layout structure.
014: *
015: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
016: * @version 1.0
017: */
018: public class UserLayoutFolderDescription extends
019: UserLayoutNodeDescription implements
020: IUserLayoutFolderDescription {
021: public static final int REGULAR_TYPE = 0;
022: public static final int HEADER_TYPE = 1;
023: public static final int FOOTER_TYPE = 2;
024:
025: public static final String[] folderTypeNames = { "regular",
026: "header", "footer" };
027:
028: protected int folderType = REGULAR_TYPE;
029:
030: /**
031: * Reconstruct folder information from an xml <code>Element</code>
032: *
033: * @param xmlNode a user layout channel <code>Element</code> value
034: * @exception PortalException if xml is malformed
035: */
036: public UserLayoutFolderDescription(Element xmlNode)
037: throws PortalException {
038: super (xmlNode);
039:
040: if (!xmlNode.getNodeName().equals("folder")) {
041: throw new PortalException(
042: "Given XML Element is not a folder!");
043: }
044:
045: // folder-specific attributes
046: String typeName = xmlNode.getAttribute("type");
047: // default to regular
048: int int_folderType = REGULAR_TYPE;
049: if (typeName != null) {
050: // search for a match
051: for (int i = 0; i < folderTypeNames.length; i++) {
052: if (typeName.equals(folderTypeNames[i])) {
053: int_folderType = i;
054: }
055: }
056: }
057: this .setFolderType(int_folderType);
058: }
059:
060: public UserLayoutFolderDescription() {
061: }
062:
063: public UserLayoutFolderDescription(IUserLayoutFolderDescription d) {
064: super (d);
065: setFolderType(d.getFolderType());
066: }
067:
068: /**
069: * Returns a type of the node, could be FOLDER or CHANNEL integer constant.
070: *
071: * @return a type
072: */
073: public int getType() {
074: return FOLDER;
075: }
076:
077: /**
078: * Returns folder type.
079: *
080: * @return an <code>int</code> value corresponding
081: * to one of the valid folder types.
082: */
083: public int getFolderType() {
084: return this .folderType;
085: }
086:
087: /**
088: * Assign a type to a folder.
089: *
090: * @param folderType an <code>int</code> value corresponding
091: * to one of the valid folder types.
092: */
093: public void setFolderType(int folderType) {
094: this .folderType = folderType;
095: }
096:
097: /**
098: * Creates a <code>org.w3c.dom.Element</code> representation of the current node.
099: *
100: * @param root a <code>Document</code> for which the <code>Element</code> should be created.
101: * @return a <code>Node</code> value
102: */
103: public Element getXML(Document root) {
104: Element node = root.createElement("folder");
105: this .addNodeAttributes(node);
106: return node;
107: }
108:
109: public void addNodeAttributes(Element node) {
110: super .addNodeAttributes(node);
111: node
112: .setAttribute("type", folderTypeNames[this
113: .getFolderType()]);
114: }
115: }
|