update dev300-m58
[ooovba.git] / xmlsecurity / tools / uno / SAXEventCollector.java
blob77b9b43d461f889cc5d0bdeb4ed05108ba1532f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SAXEventCollector.java,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.xml.security.uno;
33 import javax.xml.parsers.DocumentBuilder;
34 import javax.xml.parsers.DocumentBuilderFactory;
35 import javax.xml.parsers.ParserConfigurationException;
37 import org.w3c.dom.Document;
38 import org.w3c.dom.Element;
39 import org.w3c.dom.Node;
40 import org.w3c.dom.Text;
41 import org.w3c.dom.ProcessingInstruction;
43 /* uno classes */
44 import com.sun.star.xml.sax.XDocumentHandler;
45 import com.sun.star.xml.sax.XAttributeList;
48 * this class is used to collect all received SAX events
49 * into a DOM document.
51 class SAXEventCollector implements XDocumentHandler
54 * the document which keeps received SAX events
56 private Document m_document;
59 * the current Element to which the next received
60 * SAX event will be added.
62 private Node m_currentElement;
65 * the TestTool which receives UI feedbacks
67 private TestTool m_testTool;
70 * whether displays information on console.
72 private boolean m_systemDisplay;
74 SAXEventCollector(TestTool testTool)
76 this(testTool, false);
79 SAXEventCollector(TestTool testTool, boolean sysDis)
81 m_systemDisplay = sysDis;
82 m_testTool = testTool;
84 DocumentBuilderFactory factory =
85 DocumentBuilderFactory.newInstance();
87 try
89 DocumentBuilder builder = factory.newDocumentBuilder();
90 m_document = builder.newDocument();
92 m_currentElement = m_document;
94 catch (ParserConfigurationException pce) {
95 pce.printStackTrace();
99 protected Document getDocument()
101 return m_document;
104 protected Node getCurrentElement()
106 return m_currentElement;
110 * XDocumentHandler
112 public void startDocument ()
116 public void endDocument()
120 public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs)
122 Element newElement = m_document.createElement(str);
124 if (xattribs !=null)
126 int length = xattribs.getLength();
127 for (short i=0; i<length; ++i)
129 newElement.setAttribute(
130 xattribs.getNameByIndex(i),
131 xattribs.getValueByIndex(i));
135 if (m_systemDisplay)
137 System.out.println("startElement:"+m_currentElement.toString());
140 m_currentElement.appendChild(newElement);
141 m_currentElement = newElement;
143 if (m_testTool != null)
145 m_testTool.updatesUIs();
149 public void endElement(String str)
151 if (m_systemDisplay)
153 System.out.println("endElement:"+str+" "+m_currentElement.toString());
156 m_currentElement = m_currentElement.getParentNode();
157 if (m_systemDisplay)
159 System.out.println("----> "+m_currentElement.toString());
162 if (m_testTool != null)
164 m_testTool.updatesUIs();
168 public void characters(String str)
170 Text newText = m_document.createTextNode(str);
171 m_currentElement.appendChild(newText);
172 if (m_testTool != null)
174 m_testTool.updatesUIs();
178 public void ignorableWhitespace(String str)
182 public void processingInstruction(String aTarget, String aData)
184 ProcessingInstruction newPI
185 = m_document.createProcessingInstruction(aTarget, aData);
186 m_currentElement.appendChild(newPI);
187 if (m_testTool != null)
189 m_testTool.updatesUIs();
193 public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator )
194 throws com.sun.star.xml.sax.SAXException