1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package com
.sun
.star
.xml
.security
.uno
;
30 import javax
.xml
.parsers
.DocumentBuilder
;
31 import javax
.xml
.parsers
.DocumentBuilderFactory
;
32 import javax
.xml
.parsers
.ParserConfigurationException
;
34 import org
.w3c
.dom
.Document
;
35 import org
.w3c
.dom
.Element
;
36 import org
.w3c
.dom
.Node
;
37 import org
.w3c
.dom
.Text
;
38 import org
.w3c
.dom
.ProcessingInstruction
;
41 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
42 import com
.sun
.star
.xml
.sax
.XAttributeList
;
45 * this class is used to collect all received SAX events
46 * into a DOM document.
48 class SAXEventCollector
implements XDocumentHandler
51 * the document which keeps received SAX events
53 private Document m_document
;
56 * the current Element to which the next received
57 * SAX event will be added.
59 private Node m_currentElement
;
62 * the TestTool which receives UI feedbacks
64 private TestTool m_testTool
;
67 * whether displays information on console.
69 private boolean m_systemDisplay
;
71 SAXEventCollector(TestTool testTool
)
73 this(testTool
, false);
76 SAXEventCollector(TestTool testTool
, boolean sysDis
)
78 m_systemDisplay
= sysDis
;
79 m_testTool
= testTool
;
81 DocumentBuilderFactory factory
=
82 DocumentBuilderFactory
.newInstance();
86 DocumentBuilder builder
= factory
.newDocumentBuilder();
87 m_document
= builder
.newDocument();
89 m_currentElement
= m_document
;
91 catch (ParserConfigurationException pce
) {
92 pce
.printStackTrace();
96 protected Document
getDocument()
101 protected Node
getCurrentElement()
103 return m_currentElement
;
109 public void startDocument ()
113 public void endDocument()
117 public void startElement (String str
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
)
119 Element newElement
= m_document
.createElement(str
);
123 int length
= xattribs
.getLength();
124 for (short i
=0; i
<length
; ++i
)
126 newElement
.setAttribute(
127 xattribs
.getNameByIndex(i
),
128 xattribs
.getValueByIndex(i
));
134 System
.out
.println("startElement:"+m_currentElement
.toString());
137 m_currentElement
.appendChild(newElement
);
138 m_currentElement
= newElement
;
140 if (m_testTool
!= null)
142 m_testTool
.updatesUIs();
146 public void endElement(String str
)
150 System
.out
.println("endElement:"+str
+" "+m_currentElement
.toString());
153 m_currentElement
= m_currentElement
.getParentNode();
156 System
.out
.println("----> "+m_currentElement
.toString());
159 if (m_testTool
!= null)
161 m_testTool
.updatesUIs();
165 public void characters(String str
)
167 Text newText
= m_document
.createTextNode(str
);
168 m_currentElement
.appendChild(newText
);
169 if (m_testTool
!= null)
171 m_testTool
.updatesUIs();
175 public void ignorableWhitespace(String str
)
179 public void processingInstruction(String aTarget
, String aData
)
181 ProcessingInstruction newPI
182 = m_document
.createProcessingInstruction(aTarget
, aData
);
183 m_currentElement
.appendChild(newPI
);
184 if (m_testTool
!= null)
186 m_testTool
.updatesUIs();
190 public void setDocumentLocator (com
.sun
.star
.xml
.sax
.XLocator xLocator
)
191 throws com
.sun
.star
.xml
.sax
.SAXException