KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > util > DOMBuilder


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.util;
24
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * Define a SAX ContentHandler or/and LexicalHandler writing a DOM-tree inside a given document.
30  * Such writing doesn't erase previous content but append to it.
31  * So, if the document is not empty, this handler will try to add nodes anyway, and
32  * probably cause a hierarchy error due to try to add root node or doc type in addition
33  * of a previous one... <BR>
34  * <BR>
35  * WARNING: if this class is used for two differents types of handler to build a DOMTree from
36  * the same parsing, the parser must reference the SAME DOMBuilder object for the two types of
37  * handlers unless the DOM-Tree will not correspond to the waited DOM-Tree.
38  *
39  * WARNING: This class is designed to be used with a SAX2 XMLReader set with the default
40  * features (namespaces = true, prefixes = false).
41  *
42  * @see org.xml.sax.ContentHandler, org.xml.sax.LexicalHandler, org.w3c.dom.Document
43  */

44 public class DOMBuilder extends NSPrefixDecorator
45 {
46     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
47     private static final String JavaDoc RCSName = "$Name: $";
48
49     private BasicDOMBuilder builder;
50     
51     public DOMBuilder(Document JavaDoc doc)
52     {
53         builder = new BasicDOMBuilder(doc);
54         plugBuilder();
55     }
56     
57     public DOMBuilder(Element JavaDoc node)
58     {
59         builder = new BasicDOMBuilder(node);
60         plugBuilder();
61     }
62     
63     private void plugBuilder()
64     {
65         setContentHandler(builder);
66         setLexicalHandler(builder);
67         setEnabled(true);
68     }
69     
70     public void setDocument(Document JavaDoc doc)
71     {
72         builder.setDocument(doc);
73     }
74     
75     public void setElement(Element JavaDoc root)
76     {
77         builder.setElement(root);
78     }
79 }
80
Popular Tags