001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.util;
011:
012: import org.mmbase.util.logging.*;
013: import org.w3c.dom.*;
014:
015: /**
016: * Reads a contextdepth type of application export configuration file.
017: * Such a file conatins paramters for the ContextDepth appliaction export.
018: * Parameters exits of a start node, and a maximum depth to which to collect nodes for export.
019: * The start node is identified either an alias or a combination of buildername and where clause.
020: * This class can be used to easily retrive these parameters.
021: *
022: * @application Applications
023: * @move org.mmbase.util.xml
024: * @rename ContextDepthReader
025: * @duplicate extend from org.mmbase.util.xml.DocumentReader
026: * @author Daniel Ockeloen
027: * @version $Id: XMLContextDepthReader.java,v 1.12 2008/02/03 17:33:57 nklasens Exp $
028: */
029: public class XMLContextDepthReader {
030:
031: private static final Logger log = Logging
032: .getLoggerInstance(XMLContextDepthReader.class);
033:
034: final Document document;
035:
036: /**
037: * Creates the Context Depth Reader
038: */
039: public XMLContextDepthReader(Document doc) {
040: document = doc;
041: }
042:
043: /**
044: * Retrieves the depth to which to serach.
045: */
046: public int getDepth() {
047: Node n1 = document.getFirstChild();
048: if (n1 != null) {
049: Node n2 = n1.getFirstChild();
050: while (n2 != null) {
051: if (n2.getNodeName().equals("depth")) {
052: Node n3 = n2.getFirstChild();
053: String tmp = n3.getNodeValue();
054: try {
055: return Integer.parseInt(tmp);
056: } catch (Exception e) {
057: return -1;
058: }
059:
060: }
061: n2 = n2.getNextSibling();
062: }
063: }
064: return -1;
065: }
066:
067: /**
068: * Retrieves the content of the buidler attribute of the startnode.
069: */
070: public String getStartBuilder() {
071: Node n1 = document.getFirstChild();
072: if (n1 != null) {
073: Node n2 = n1.getFirstChild();
074: while (n2 != null) {
075: if (n2.getNodeName().equals("startnode")) {
076: Node n3 = n2.getFirstChild();
077: while (n3 != null) {
078: if (n3.getNodeName().equals("builder")) {
079: Node n4 = n3.getFirstChild();
080: return n4.getNodeValue();
081: }
082: n3 = n3.getNextSibling();
083: }
084: }
085: n2 = n2.getNextSibling();
086: }
087: }
088: return null;
089: }
090:
091: /**
092: * Retrieves the content of the alias attribute of the startnode.
093: */
094: public String getStartAlias() {
095: Node n1 = document.getFirstChild();
096: if (n1 != null) {
097: Node n2 = n1.getFirstChild();
098: while (n2 != null) {
099: if (n2.getNodeName().equals("startnode")) {
100: NamedNodeMap nm = n2.getAttributes();
101: if (nm != null) {
102: Node n4 = nm.getNamedItem("alias");
103: if (n4 != null)
104: return n4.getNodeValue();
105: }
106:
107: }
108: n2 = n2.getNextSibling();
109: }
110: }
111: return null;
112: }
113:
114: /**
115: * Retrieves the content of the where attribute of the startnode.
116: */
117: public String getStartWhere() {
118: Node n1 = document.getFirstChild();
119: if (n1 != null) {
120: Node n2 = n1.getFirstChild();
121: while (n2 != null) {
122: if (n2.getNodeName().equals("startnode")) {
123: Node n3 = n2.getFirstChild();
124: while (n3 != null) {
125: if (n3.getNodeName().equals("where")) {
126: Node n4 = n3.getFirstChild();
127: return n4.getNodeValue();
128: }
129: n3 = n3.getNextSibling();
130: }
131: }
132: n2 = n2.getNextSibling();
133: }
134: }
135: return null;
136: }
137: }
|