KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > dataxslt > Block


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.dataxslt;
34
35 import java.util.Vector JavaDoc;
36 import org.w3c.dom.Element JavaDoc;
37 import org.w3c.dom.Node JavaDoc;
38 import org.w3c.dom.NodeList JavaDoc;
39
40 import dom.DOMSubDocument;
41
42 /**
43  * <p>Page Block</p>
44  * <p>This class represents a &lt;block&gt;&lt;/block&gt; section of a PageSet
45  * XML definition file. The XML file is first parsed into a DOMDocument and
46  * then DOMDocument nodes are wrapped with classes that add specific PageSet
47  * behavior.</p>
48  * @author Sergio Montoro Ten
49  * @version 1.1
50  */

51 public class Block extends DOMSubDocument {
52
53   private Node JavaDoc oBlockNode;
54   /**
55    * @param oRefNode DOMDocument Node holding &lt;block&gt; element.
56    */

57   public Block(Node JavaDoc oRefNode) {
58     super(oRefNode);
59
60     oBlockNode = oRefNode;
61   }
62
63   // ----------------------------------------------------------
64

65   public Node JavaDoc getNode() {
66     return oBlockNode;
67   }
68
69   // ----------------------------------------------------------
70

71   /**
72    * @return Block id attribute
73    */

74   public String JavaDoc id() {
75     Node JavaDoc oItem = oNode.getAttributes().getNamedItem("id");
76
77     if (null==oItem)
78       return null;
79     else
80       return oItem.getNodeValue();
81   } // id()
82

83   // ----------------------------------------------------------
84

85   public void id(String JavaDoc sNewId) {
86     Node JavaDoc oItem = oNode.getAttributes().getNamedItem("id");
87
88     oItem.setNodeValue(sNewId);
89   }
90
91   // ----------------------------------------------------------
92

93   /**
94    * @return metablock element value
95    */

96   public String JavaDoc metablock() {
97     return getElement("metablock");
98   } // metablock()
99

100   // ----------------------------------------------------------
101

102   /**
103    * @return tag element value
104    */

105   public String JavaDoc tag() {
106     return getElement("tag");
107   } // tag()
108

109   // ----------------------------------------------------------
110

111   /**
112    * @return zone element value
113    */

114   public String JavaDoc zone() {
115     return getElement("zone");
116   } // zone()
117

118   // ----------------------------------------------------------
119

120   /**
121    * @return Vector with Image objects for this Block.
122    */

123   public Vector JavaDoc images() {
124     Node JavaDoc oImagesNode = null;
125     NodeList JavaDoc oNodeList;
126     Vector JavaDoc oLinkVctr;
127
128     for (oImagesNode=oNode.getFirstChild(); oImagesNode!=null; oImagesNode=oImagesNode.getNextSibling())
129       if (Node.ELEMENT_NODE==oImagesNode.getNodeType())
130         if (oImagesNode.getNodeName().equals("images")) break;
131
132     oNodeList = ((Element JavaDoc) oImagesNode).getElementsByTagName("image");
133
134     oLinkVctr = new Vector JavaDoc(oNodeList.getLength());
135
136     for (int i=0; i<oNodeList.getLength(); i++)
137       oLinkVctr.add(new Image(oNodeList.item(i)));
138
139     return oLinkVctr;
140   } // images()
141

142   // ----------------------------------------------------------
143

144   /**
145    * @return Vector with Paragraph objects for this Block.
146    */

147   public Vector JavaDoc paragraphs() {
148     Node JavaDoc oParagraphsNode = null;
149     NodeList JavaDoc oNodeList;
150     Vector JavaDoc oLinkVctr;
151
152     for (oParagraphsNode=oNode.getFirstChild(); oParagraphsNode!=null; oParagraphsNode=oParagraphsNode.getNextSibling())
153       if (Node.ELEMENT_NODE==oParagraphsNode.getNodeType())
154         if (oParagraphsNode.getNodeName().equals("paragraphs")) break;
155
156     oNodeList = ((Element JavaDoc) oParagraphsNode).getElementsByTagName("paragraph");
157
158     oLinkVctr = new Vector JavaDoc(oNodeList.getLength());
159
160     for (int i=0; i<oNodeList.getLength(); i++)
161       oLinkVctr.add(new Paragraph(oNodeList.item(i)));
162
163     return oLinkVctr;
164   } // paragraphs()
165

166   // ----------------------------------------------------------
167
}
Popular Tags