001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.dataxslt;
034:
035: import java.util.Vector;
036: import org.w3c.dom.Element;
037: import org.w3c.dom.Node;
038: import org.w3c.dom.NodeList;
039:
040: import dom.DOMSubDocument;
041:
042: /**
043: * <p>Page Block</p>
044: * <p>This class represents a <block></block> section of a PageSet
045: * XML definition file. The XML file is first parsed into a DOMDocument and
046: * then DOMDocument nodes are wrapped with classes that add specific PageSet
047: * behavior.</p>
048: * @author Sergio Montoro Ten
049: * @version 1.1
050: */
051: public class Block extends DOMSubDocument {
052:
053: private Node oBlockNode;
054:
055: /**
056: * @param oRefNode DOMDocument Node holding <block> element.
057: */
058: public Block(Node oRefNode) {
059: super (oRefNode);
060:
061: oBlockNode = oRefNode;
062: }
063:
064: // ----------------------------------------------------------
065:
066: public Node getNode() {
067: return oBlockNode;
068: }
069:
070: // ----------------------------------------------------------
071:
072: /**
073: * @return Block id attribute
074: */
075: public String id() {
076: Node oItem = oNode.getAttributes().getNamedItem("id");
077:
078: if (null == oItem)
079: return null;
080: else
081: return oItem.getNodeValue();
082: } // id()
083:
084: // ----------------------------------------------------------
085:
086: public void id(String sNewId) {
087: Node oItem = oNode.getAttributes().getNamedItem("id");
088:
089: oItem.setNodeValue(sNewId);
090: }
091:
092: // ----------------------------------------------------------
093:
094: /**
095: * @return metablock element value
096: */
097: public String metablock() {
098: return getElement("metablock");
099: } // metablock()
100:
101: // ----------------------------------------------------------
102:
103: /**
104: * @return tag element value
105: */
106: public String tag() {
107: return getElement("tag");
108: } // tag()
109:
110: // ----------------------------------------------------------
111:
112: /**
113: * @return zone element value
114: */
115: public String zone() {
116: return getElement("zone");
117: } // zone()
118:
119: // ----------------------------------------------------------
120:
121: /**
122: * @return Vector with Image objects for this Block.
123: */
124: public Vector images() {
125: Node oImagesNode = null;
126: NodeList oNodeList;
127: Vector oLinkVctr;
128:
129: for (oImagesNode = oNode.getFirstChild(); oImagesNode != null; oImagesNode = oImagesNode
130: .getNextSibling())
131: if (Node.ELEMENT_NODE == oImagesNode.getNodeType())
132: if (oImagesNode.getNodeName().equals("images"))
133: break;
134:
135: oNodeList = ((Element) oImagesNode)
136: .getElementsByTagName("image");
137:
138: oLinkVctr = new Vector(oNodeList.getLength());
139:
140: for (int i = 0; i < oNodeList.getLength(); i++)
141: oLinkVctr.add(new Image(oNodeList.item(i)));
142:
143: return oLinkVctr;
144: } // images()
145:
146: // ----------------------------------------------------------
147:
148: /**
149: * @return Vector with Paragraph objects for this Block.
150: */
151: public Vector paragraphs() {
152: Node oParagraphsNode = null;
153: NodeList oNodeList;
154: Vector oLinkVctr;
155:
156: for (oParagraphsNode = oNode.getFirstChild(); oParagraphsNode != null; oParagraphsNode = oParagraphsNode
157: .getNextSibling())
158: if (Node.ELEMENT_NODE == oParagraphsNode.getNodeType())
159: if (oParagraphsNode.getNodeName().equals("paragraphs"))
160: break;
161:
162: oNodeList = ((Element) oParagraphsNode)
163: .getElementsByTagName("paragraph");
164:
165: oLinkVctr = new Vector(oNodeList.getLength());
166:
167: for (int i = 0; i < oNodeList.getLength(); i++)
168: oLinkVctr.add(new Paragraph(oNodeList.item(i)));
169:
170: return oLinkVctr;
171: } // paragraphs()
172:
173: // ----------------------------------------------------------
174: }
|