xref: /AOO41X/main/xmlsecurity/tools/uno/TestTool.java (revision db8598795e2025b89968fa208f4cf0f9125a6f19)
1*db859879SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*db859879SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*db859879SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*db859879SAndrew Rist  * distributed with this work for additional information
6*db859879SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*db859879SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*db859879SAndrew Rist  * "License"); you may not use this file except in compliance
9*db859879SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*db859879SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*db859879SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*db859879SAndrew Rist  * software distributed under the License is distributed on an
15*db859879SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*db859879SAndrew Rist  * KIND, either express or implied.  See the License for the
17*db859879SAndrew Rist  * specific language governing permissions and limitations
18*db859879SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*db859879SAndrew Rist  *************************************************************/
21*db859879SAndrew Rist 
22*db859879SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.xml.security.uno;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import javax.xml.parsers.DocumentBuilder;
27cdf0e10cSrcweir import javax.xml.parsers.DocumentBuilderFactory;
28cdf0e10cSrcweir import javax.xml.parsers.ParserConfigurationException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import java.io.File;
31cdf0e10cSrcweir import java.io.IOException;
32cdf0e10cSrcweir import java.io.FileOutputStream;
33cdf0e10cSrcweir import java.io.FileInputStream;
34cdf0e10cSrcweir import java.io.InputStream;
35cdf0e10cSrcweir import java.io.ByteArrayInputStream;
36cdf0e10cSrcweir import java.io.UnsupportedEncodingException;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir import org.w3c.dom.Document;
39cdf0e10cSrcweir import org.w3c.dom.Node;
40cdf0e10cSrcweir import org.w3c.dom.NodeList;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir /* Basic GUI components */
43cdf0e10cSrcweir import javax.swing.JFrame;
44cdf0e10cSrcweir import javax.swing.JPanel;
45cdf0e10cSrcweir import javax.swing.JScrollPane;
46cdf0e10cSrcweir import javax.swing.JTree;
47cdf0e10cSrcweir import javax.swing.JButton;
48cdf0e10cSrcweir import javax.swing.JCheckBox;
49cdf0e10cSrcweir import javax.swing.JTextArea;
50cdf0e10cSrcweir import javax.swing.JTextField;
51cdf0e10cSrcweir import javax.swing.JFileChooser;
52cdf0e10cSrcweir import javax.swing.ToolTipManager;
53cdf0e10cSrcweir import javax.swing.JTable;
54cdf0e10cSrcweir import javax.swing.JLabel;
55cdf0e10cSrcweir import javax.swing.BorderFactory;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /* GUI components for right-hand side */
58cdf0e10cSrcweir import javax.swing.JSplitPane;
59cdf0e10cSrcweir import javax.swing.JOptionPane;
60cdf0e10cSrcweir import javax.swing.JTabbedPane;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /* GUI support classes */
64cdf0e10cSrcweir import java.awt.BorderLayout;
65cdf0e10cSrcweir import java.awt.Dimension;
66cdf0e10cSrcweir import java.awt.Container;
67cdf0e10cSrcweir import java.awt.Toolkit;
68cdf0e10cSrcweir import java.awt.event.WindowEvent;
69cdf0e10cSrcweir import java.awt.event.WindowAdapter;
70cdf0e10cSrcweir import java.awt.event.ActionEvent;
71cdf0e10cSrcweir import java.awt.event.ActionListener;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir /* For creating borders */
74cdf0e10cSrcweir import javax.swing.border.EmptyBorder;
75cdf0e10cSrcweir import javax.swing.border.BevelBorder;
76cdf0e10cSrcweir import javax.swing.border.CompoundBorder;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /* For creating a TreeModel */
79cdf0e10cSrcweir import javax.swing.tree.TreePath;
80cdf0e10cSrcweir import java.util.Vector;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir /* UNO classes */
83cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
84cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
85cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
86cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
87cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
88cdf0e10cSrcweir import com.sun.star.xml.sax.XDocumentHandler;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir import com.sun.star.xml.crypto.*;
91cdf0e10cSrcweir import com.sun.star.xml.crypto.sax.*;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir public class TestTool extends JFrame implements ActionListener
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	/*
96cdf0e10cSrcweir 	 * xml security framewrok component names
97cdf0e10cSrcweir 	 */
98cdf0e10cSrcweir 	public static String SIGNATURECREATOR_COMPONENT = "com.sun.star.xml.crypto.sax.SignatureCreator";
99cdf0e10cSrcweir 	public static String SIGNATUREVERIFIER_COMPONENT = "com.sun.star.xml.crypto.sax.SignatureVerifier";
100cdf0e10cSrcweir 	public static String ENCRYPTOR_COMPONENT = "com.sun.star.xml.crypto.sax.Encryptor";
101cdf0e10cSrcweir 	public static String DECRYPTOR_COMPONENT = "com.sun.star.xml.crypto.sax.Decryptor";
102cdf0e10cSrcweir 	public static String SAXEVENTKEEPER_COMPONENT = "com.sun.star.xml.crypto.sax.SAXEventKeeper";
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	/*
105cdf0e10cSrcweir 	 * Java-based component names
106cdf0e10cSrcweir 	 */
107cdf0e10cSrcweir 	public static String SEINITIALIZER_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.SEInitializer_JxsecImpl";
108cdf0e10cSrcweir 	public static String XMLSIGNATURE_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLSignature_JxsecImpl";
109cdf0e10cSrcweir 	public static String XMLENCRYPTION_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLEncryption_JxsecImpl";
110cdf0e10cSrcweir 	public static String XMLDOCUMENTWRAPPER_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLDocumentWrapper_JxsecImpl";
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	/*
113cdf0e10cSrcweir 	 * C-based component names
114cdf0e10cSrcweir 	 */
115cdf0e10cSrcweir 	public static String SEINITIALIZER_COMPONENT_C = "com.sun.star.xml.crypto.SEInitializer";
116cdf0e10cSrcweir 	public static String XMLSIGNATURE_COMPONENT_C = "com.sun.star.xml.crypto.XMLSignature";
117cdf0e10cSrcweir 	public static String XMLENCRYPTION_COMPONENT_C = "com.sun.star.xml.crypto.XMLEncryption";
118cdf0e10cSrcweir 	public static String XMLDOCUMENTWRAPPER_COMPONENT_C = "com.sun.star.xml.wrapper.XMLDocumentWrapper";
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	/* url resolver name */
121cdf0e10cSrcweir 	public static String UNOURLRESOLVER = "com.sun.star.bridge.UnoUrlResolver";
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	/*
124cdf0e10cSrcweir 	 * connection URL
125cdf0e10cSrcweir 	 */
126cdf0e10cSrcweir 	private String m_unoURL = "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager";
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	/* key file */
129cdf0e10cSrcweir 	private String m_javaTokenFile = null;
130cdf0e10cSrcweir 	private String m_nssTokenPath = null;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	/* User Interfaces */
133cdf0e10cSrcweir 	private JButton m_goButton;
134cdf0e10cSrcweir 	private JButton m_stepButton;
135cdf0e10cSrcweir 	private JButton m_startButton;
136cdf0e10cSrcweir 	private JButton m_openButton;
137cdf0e10cSrcweir 	private JCheckBox m_isExportingButton;
138cdf0e10cSrcweir 	private JCheckBox m_isJavaComponentButton;
139cdf0e10cSrcweir 	private JButton m_saveButton;
140cdf0e10cSrcweir 	private JButton m_batchButton;
141cdf0e10cSrcweir 	private JTree m_leftTree;
142cdf0e10cSrcweir 	private JTextArea m_leftTextArea;
143cdf0e10cSrcweir 	private JTree m_middleTree;
144cdf0e10cSrcweir 	private JTree m_rightTree;
145cdf0e10cSrcweir 	private JTabbedPane m_leftTabPane;
146cdf0e10cSrcweir 	private JTextArea m_bufferNodeTextArea;
147cdf0e10cSrcweir 	private JLabel m_saxChainLabel;
148cdf0e10cSrcweir 	private JTextField m_saxEventText;
149cdf0e10cSrcweir 	private JTable m_unsolvedReferenceTable;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	/*
152cdf0e10cSrcweir 	 * whether a batch file is running,
153cdf0e10cSrcweir 	 * if so, no message box is popped up
154cdf0e10cSrcweir 	 */
155cdf0e10cSrcweir 	private boolean m_bIsBatchRunning = false;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	/*
158cdf0e10cSrcweir 	 * whether the UI needs to be updated.
159cdf0e10cSrcweir 	 * when user click the "go" button, the UI needs
160cdf0e10cSrcweir 	 * not to be updated step by step for performance
161cdf0e10cSrcweir 	 * reason
162cdf0e10cSrcweir 	 */
163cdf0e10cSrcweir 	private boolean m_bIsUIUpdateSuppressed = false;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	/*
166cdf0e10cSrcweir 	 * three DOM tree adapter
167cdf0e10cSrcweir 	 */
168cdf0e10cSrcweir 	private DomToTreeModelAdapter m_leftTreeModelAdapter;
169cdf0e10cSrcweir 	private DomToTreeModelAdapter m_middleTreeModelAdapter;
170cdf0e10cSrcweir 	private DomToTreeModelAdapter m_rightTreeModelAdapter;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	/*
173cdf0e10cSrcweir 	 * the current directory, which reserves the default
174cdf0e10cSrcweir 	 * location when user open/save a file.
175cdf0e10cSrcweir 	 */
176cdf0e10cSrcweir 	private File m_currentDirectory = null;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	/*
179cdf0e10cSrcweir 	 * the log file
180cdf0e10cSrcweir 	 */
181cdf0e10cSrcweir 	private FileOutputStream m_logFileOutputStream = null;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	/*
184cdf0e10cSrcweir 	 * the thread which is parsing the current XML
185cdf0e10cSrcweir 	 * file
186cdf0e10cSrcweir 	 */
187cdf0e10cSrcweir 	private ParsingThread m_parsingThread;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	/*
190cdf0e10cSrcweir 	 * whether is exporting or importing
191cdf0e10cSrcweir 	 */
192cdf0e10cSrcweir 	private boolean m_bIsExporting;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	/*
195cdf0e10cSrcweir 	 * whether java based component or c based component
196cdf0e10cSrcweir 	 * is used now
197cdf0e10cSrcweir 	 */
198cdf0e10cSrcweir 	private boolean m_bIsJavaBased;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	/*
201cdf0e10cSrcweir 	 * XML security component interface
202cdf0e10cSrcweir 	 */
203cdf0e10cSrcweir 	private XComponentContext m_xRemoteContext = null;
204cdf0e10cSrcweir 	private XMultiComponentFactory m_xRemoteServiceManager = null;
205cdf0e10cSrcweir 	private XXMLSecurityContext m_xXMLSecurityContext = null;
206cdf0e10cSrcweir 	private XXMLSignature m_xXMLSignature = null;
207cdf0e10cSrcweir 	private XXMLEncryption m_xXMLEncryption = null;
208cdf0e10cSrcweir 	private XSEInitializer m_xSEInitializer = null;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	/*
211cdf0e10cSrcweir 	 * SAX event collector for the middle tree and the right tree
212cdf0e10cSrcweir 	 */
213cdf0e10cSrcweir 	private SAXEventCollector m_rightTreeEventCollector = null;
214cdf0e10cSrcweir 	private SAXEventCollector m_middleTreeEventCollector = null;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	/*
217cdf0e10cSrcweir 	 * security framework controller
218cdf0e10cSrcweir 	 */
219cdf0e10cSrcweir 	private XMLSecurityFrameworkController m_xmlSecurityFrameworkController = null;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	/* org.w3c.dom.Document */
222cdf0e10cSrcweir 	private Document m_document;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	/* represents whether "Go" or "Step" */
225cdf0e10cSrcweir 	private boolean stepMode = true;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir /**************************************************************************************
228cdf0e10cSrcweir  * private methods
229cdf0e10cSrcweir  **************************************************************************************/
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	/******************************************************************************
233cdf0e10cSrcweir 	 * UI related methods
234cdf0e10cSrcweir 	 ******************************************************************************/
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	/*
237cdf0e10cSrcweir 	 * initalizes the UI.
238cdf0e10cSrcweir 	 */
initUI()239cdf0e10cSrcweir 	private void initUI()
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		m_leftTreeModelAdapter = new DomToTreeModelAdapter(m_document);
242cdf0e10cSrcweir 		m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_document);
243cdf0e10cSrcweir 		m_rightTreeModelAdapter = new DomToTreeModelAdapter(m_document);
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 		m_parsingThread = null;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		m_leftTree.setModel(m_leftTreeModelAdapter);
248cdf0e10cSrcweir 		m_middleTree.setModel(m_middleTreeModelAdapter);
249cdf0e10cSrcweir 		m_rightTree.setModel(m_rightTreeModelAdapter);
250cdf0e10cSrcweir 	}
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	/*
253cdf0e10cSrcweir 	 * constructs the user interface.
254cdf0e10cSrcweir 	 */
buildUI(int width, int height)255cdf0e10cSrcweir 	private Container buildUI(int width, int height)
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		JPanel mainPanel = new JPanel();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 		int frameHeight = height-40;
260cdf0e10cSrcweir 		int leftWindowWidth = (width-40)/3;
261cdf0e10cSrcweir 		int middleWindowWidth = leftWindowWidth;
262cdf0e10cSrcweir 		int rightWindowWidth = leftWindowWidth;
263cdf0e10cSrcweir 		int leftPaneWidth = leftWindowWidth+middleWindowWidth;
264cdf0e10cSrcweir 		int frameWidth = leftPaneWidth + rightWindowWidth;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 		/* Make a nice border */
267cdf0e10cSrcweir 		EmptyBorder emptyBorder = new EmptyBorder(5,5,5,5);
268cdf0e10cSrcweir 		BevelBorder bevelBorder = new BevelBorder(BevelBorder.LOWERED);
269cdf0e10cSrcweir 		CompoundBorder compoundBorder = new CompoundBorder(emptyBorder,bevelBorder);
270cdf0e10cSrcweir 		mainPanel.setBorder(new CompoundBorder(compoundBorder,emptyBorder));
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 		/* Set up the tree */
273cdf0e10cSrcweir 		m_leftTreeModelAdapter = new DomToTreeModelAdapter(m_document);
274cdf0e10cSrcweir 		m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_document);
275cdf0e10cSrcweir 		m_rightTreeModelAdapter = new DomToTreeModelAdapter(m_document);
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 		m_leftTree = new JTree(m_leftTreeModelAdapter);
278cdf0e10cSrcweir 		m_leftTextArea = new JTextArea();
279cdf0e10cSrcweir 		m_middleTree = new JTree(m_middleTreeModelAdapter);
280cdf0e10cSrcweir 		m_rightTree = new JTree(m_rightTreeModelAdapter);
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 		ToolTipManager.sharedInstance().registerComponent(m_leftTree);
283cdf0e10cSrcweir 		ToolTipManager.sharedInstance().registerComponent(m_middleTree);
284cdf0e10cSrcweir 		ToolTipManager.sharedInstance().registerComponent(m_rightTree);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 		/* Builds left tab pane */
287cdf0e10cSrcweir 		JScrollPane leftTreePane = new JScrollPane(m_leftTree);
288cdf0e10cSrcweir 		JScrollPane leftTextPane = new JScrollPane(m_leftTextArea);
289cdf0e10cSrcweir 		m_leftTabPane= new JTabbedPane();
290cdf0e10cSrcweir 		m_leftTabPane.add("Tree View",leftTreePane);
291cdf0e10cSrcweir 		m_leftTabPane.add("Text View",leftTextPane);
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 		/* Builds middle tree pane */
294cdf0e10cSrcweir 		JScrollPane middleTreePane = new JScrollPane(m_middleTree);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 		/* Builds right tree pane */
297cdf0e10cSrcweir 		JScrollPane rightTreePane = new JScrollPane(m_rightTree);
298cdf0e10cSrcweir 		rightTreePane.setBorder(BorderFactory.createCompoundBorder(
299cdf0e10cSrcweir                         BorderFactory.createTitledBorder("Result"),
300cdf0e10cSrcweir                         BorderFactory.createEmptyBorder(8,8,8,8)));
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 		m_leftTabPane.setPreferredSize(
303cdf0e10cSrcweir 			new Dimension( leftWindowWidth, frameHeight ));
304cdf0e10cSrcweir 		middleTreePane.setPreferredSize(
305cdf0e10cSrcweir 			new Dimension( middleWindowWidth, frameHeight ));
306cdf0e10cSrcweir 		rightTreePane.setPreferredSize(
307cdf0e10cSrcweir 			new Dimension( rightWindowWidth, frameHeight ));
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		/* Builds the SAX event text box */
310cdf0e10cSrcweir 		m_saxEventText = new JTextField();
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 		/* Builds the unsolved reference table */
313cdf0e10cSrcweir 		m_unsolvedReferenceTable = new JTable(
314cdf0e10cSrcweir 				new UnsolvedReferenceTableModel(this));
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 		/* Builds the BufferNode information text area */
317cdf0e10cSrcweir 		m_bufferNodeTextArea = new JTextArea();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 		/* Builds the SAX chain information label */
320cdf0e10cSrcweir 		m_saxChainLabel = new JLabel();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 		/* Builds the left pane */
323cdf0e10cSrcweir 		JPanel tabPaneWithSaxEventPane = new JPanel();
324cdf0e10cSrcweir 		tabPaneWithSaxEventPane.setLayout(new BorderLayout());
325cdf0e10cSrcweir 		tabPaneWithSaxEventPane.add("Center",m_leftTabPane);
326cdf0e10cSrcweir 		tabPaneWithSaxEventPane.add("South",new JScrollPane(m_saxEventText));
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 		JSplitPane leftPane =
329cdf0e10cSrcweir 			new JSplitPane( JSplitPane.VERTICAL_SPLIT,
330cdf0e10cSrcweir 				tabPaneWithSaxEventPane,
331cdf0e10cSrcweir 				new JScrollPane(m_unsolvedReferenceTable));
332cdf0e10cSrcweir 		leftPane.setBorder(BorderFactory.createCompoundBorder(
333cdf0e10cSrcweir                         BorderFactory.createTitledBorder("Original"),
334cdf0e10cSrcweir                         BorderFactory.createEmptyBorder(8,8,8,8)));
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		leftPane.setContinuousLayout( true );
337cdf0e10cSrcweir 		leftPane.setDividerLocation( frameHeight*2/3 );
338cdf0e10cSrcweir 		leftPane.setPreferredSize(
339cdf0e10cSrcweir 			new Dimension( leftWindowWidth, frameHeight ));
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 		/* Builds the middle pane */
342cdf0e10cSrcweir 		JPanel bufferNodeWithSaxChainPane = new JPanel();
343cdf0e10cSrcweir 		bufferNodeWithSaxChainPane.setLayout(new BorderLayout());
344cdf0e10cSrcweir 		bufferNodeWithSaxChainPane.add("Center",m_bufferNodeTextArea);
345cdf0e10cSrcweir 		bufferNodeWithSaxChainPane.add("South",new JScrollPane(m_saxChainLabel));
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 		JSplitPane middlePane =
348cdf0e10cSrcweir 			new JSplitPane( JSplitPane.VERTICAL_SPLIT,
349cdf0e10cSrcweir 				middleTreePane,
350cdf0e10cSrcweir 				new JScrollPane(bufferNodeWithSaxChainPane));
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 		middlePane.setBorder(BorderFactory.createCompoundBorder(
353cdf0e10cSrcweir                         BorderFactory.createTitledBorder("Insight SAXEventKeeper"),
354cdf0e10cSrcweir                         BorderFactory.createEmptyBorder(8,8,8,8)));
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		middlePane.setContinuousLayout( true );
357cdf0e10cSrcweir 		middlePane.setDividerLocation( frameHeight/2+5 );
358cdf0e10cSrcweir 		middlePane.setPreferredSize(
359cdf0e10cSrcweir 			new Dimension( middleWindowWidth, frameHeight ));
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 		/* Builds the whole frame pane */
362cdf0e10cSrcweir 		JSplitPane leftWithMiddlePane =
363cdf0e10cSrcweir 			new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
364cdf0e10cSrcweir 				leftPane,
365cdf0e10cSrcweir 				middlePane );
366cdf0e10cSrcweir 		leftWithMiddlePane.setContinuousLayout( true );
367cdf0e10cSrcweir 		leftWithMiddlePane.setDividerLocation( leftWindowWidth );
368cdf0e10cSrcweir 		leftWithMiddlePane.setPreferredSize(
369cdf0e10cSrcweir 			new Dimension( leftPaneWidth + 10, frameHeight+10 ));
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 		JSplitPane framePane =
372cdf0e10cSrcweir 			new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
373cdf0e10cSrcweir 				leftWithMiddlePane,
374cdf0e10cSrcweir 				rightTreePane );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 		framePane.setContinuousLayout( true );
378cdf0e10cSrcweir 		framePane.setDividerLocation(leftPaneWidth+10 );
379cdf0e10cSrcweir 		framePane.setPreferredSize(
380cdf0e10cSrcweir 			new Dimension( frameWidth + 20, frameHeight+10 ));
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		/* Adds all GUI components to the main panel */
383cdf0e10cSrcweir 		mainPanel.setLayout(new BorderLayout());
384cdf0e10cSrcweir 		mainPanel.add("Center", framePane );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		m_openButton = new JButton("Open...");
387cdf0e10cSrcweir 		m_openButton.addActionListener(this);
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		m_goButton = new JButton("Go!");
390cdf0e10cSrcweir 		m_goButton.addActionListener(this);
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 		m_stepButton = new JButton("Step");
393cdf0e10cSrcweir 		m_stepButton.addActionListener(this);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 		m_startButton = new JButton("Start");
396cdf0e10cSrcweir 		m_startButton.addActionListener(this);
397cdf0e10cSrcweir 		m_startButton.setEnabled(false);
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		m_isExportingButton = new JCheckBox("export, not import", true);
400cdf0e10cSrcweir 		m_isJavaComponentButton = new JCheckBox("use java component", false);
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 		m_saveButton = new JButton("Save...");
403cdf0e10cSrcweir 		m_saveButton.addActionListener(this);
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 		m_batchButton = new JButton("Batch...");
406cdf0e10cSrcweir 		m_batchButton.addActionListener(this);
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 		JPanel buttonPanel = new JPanel();
409cdf0e10cSrcweir 		buttonPanel.add(m_batchButton);
410cdf0e10cSrcweir 		buttonPanel.add(m_openButton);
411cdf0e10cSrcweir 		buttonPanel.add(m_startButton);
412cdf0e10cSrcweir 		buttonPanel.add(m_goButton);
413cdf0e10cSrcweir 		buttonPanel.add(m_stepButton);
414cdf0e10cSrcweir 		buttonPanel.add(m_isExportingButton);
415cdf0e10cSrcweir 		buttonPanel.add(m_isJavaComponentButton);
416cdf0e10cSrcweir 		buttonPanel.add(m_saveButton);
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 		mainPanel.add("South", buttonPanel);
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		enableGoButton(false);
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 		return mainPanel;
423cdf0e10cSrcweir 	}
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	/*
426cdf0e10cSrcweir 	 * enables/disables the Go(and Step) button.
427cdf0e10cSrcweir 	 */
enableGoButton(boolean enabled)428cdf0e10cSrcweir 	private void enableGoButton(boolean enabled)
429cdf0e10cSrcweir 	{
430cdf0e10cSrcweir 		m_goButton.setEnabled(enabled);
431cdf0e10cSrcweir 		m_stepButton.setEnabled(enabled);
432cdf0e10cSrcweir 	}
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	/*
435cdf0e10cSrcweir 	 * updates the unsolved reference information.
436cdf0e10cSrcweir 	 */
updatesUnsolvedReferencesInformation()437cdf0e10cSrcweir 	private void updatesUnsolvedReferencesInformation()
438cdf0e10cSrcweir 	{
439cdf0e10cSrcweir 		m_unsolvedReferenceTable.setModel(new UnsolvedReferenceTableModel(this));
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	/*
443cdf0e10cSrcweir 	 * adjusts the view of the tree in order to make the
444cdf0e10cSrcweir 	 * particular Node into the focus tree leaf.
445cdf0e10cSrcweir 	 */
updatesTree(Node node, JTree tree)446cdf0e10cSrcweir 	private void updatesTree(Node node, JTree tree)
447cdf0e10cSrcweir 	{
448cdf0e10cSrcweir 		int i=0;
449cdf0e10cSrcweir 		int currentLine = 0;
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 		while (i<tree.getRowCount())
452cdf0e10cSrcweir 		{
453cdf0e10cSrcweir 			TreePath treePath = tree.getPathForRow(i);
454cdf0e10cSrcweir 			tree.expandPath(treePath);
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 			AdapterNode adapterNode = (AdapterNode)treePath.getLastPathComponent();
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 			if (node == adapterNode.getNode())
459cdf0e10cSrcweir 			{
460cdf0e10cSrcweir 				tree.addSelectionPath(treePath);
461cdf0e10cSrcweir 				currentLine = i;
462cdf0e10cSrcweir 			}
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 			++i;
465cdf0e10cSrcweir 		}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 		tree.setCellRenderer(new XMLTreeCellRanderer(node));
468cdf0e10cSrcweir 		tree.scrollRowToVisible(currentLine);
469cdf0e10cSrcweir 	}
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	/******************************************************************************
472cdf0e10cSrcweir 	 * action listener related methods.
473cdf0e10cSrcweir 	 ******************************************************************************/
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	/*
476cdf0e10cSrcweir 	 * reads in a document, either the document is a file or
477cdf0e10cSrcweir 	 * is a text paragraph.
478cdf0e10cSrcweir 	 */
openDocument()479cdf0e10cSrcweir 	private void openDocument()
480cdf0e10cSrcweir 	{
481cdf0e10cSrcweir 		if (m_leftTabPane.getSelectedIndex() == 0)
482cdf0e10cSrcweir 		{
483cdf0e10cSrcweir 			File f = openFile();
484cdf0e10cSrcweir 			if (f != null)
485cdf0e10cSrcweir 			{
486cdf0e10cSrcweir 				parseFile(f);
487cdf0e10cSrcweir 			}
488cdf0e10cSrcweir 		}
489cdf0e10cSrcweir 		else
490cdf0e10cSrcweir 		{
491cdf0e10cSrcweir 			String text = m_leftTextArea.getText();
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 			try
494cdf0e10cSrcweir 			{
495cdf0e10cSrcweir 				parseStream(new ByteArrayInputStream(text.getBytes("UTF-8")));
496cdf0e10cSrcweir 			}
497cdf0e10cSrcweir 			catch(UnsupportedEncodingException e)
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				e.printStackTrace();
500cdf0e10cSrcweir 			}
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			m_leftTabPane.setSelectedIndex(0);
503cdf0e10cSrcweir 		}
504cdf0e10cSrcweir 	}
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 	/*
507cdf0e10cSrcweir 	 * save the result tree to a file.
508cdf0e10cSrcweir 	 */
saveResult()509cdf0e10cSrcweir 	private void saveResult()
510cdf0e10cSrcweir 	{
511cdf0e10cSrcweir 		saveFile();
512cdf0e10cSrcweir 	}
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 	/*
515cdf0e10cSrcweir 	 * selects a batch file to excute.
516cdf0e10cSrcweir 	 */
openBatch()517cdf0e10cSrcweir 	private void openBatch()
518cdf0e10cSrcweir 	{
519cdf0e10cSrcweir 		File f = openFile();
520cdf0e10cSrcweir 		if (f != null)
521cdf0e10cSrcweir 		{
522cdf0e10cSrcweir 			runBatch(f);
523cdf0e10cSrcweir 		}
524cdf0e10cSrcweir 	}
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	/*
527cdf0e10cSrcweir 	 * makes the current operation to an end.
528cdf0e10cSrcweir 	 */
endMission()529cdf0e10cSrcweir 	private void endMission()
530cdf0e10cSrcweir 	{
531cdf0e10cSrcweir 		enableGoButton(false);
532cdf0e10cSrcweir 		m_parsingThread = null;
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 		if (m_xmlSecurityFrameworkController != null)
535cdf0e10cSrcweir 		{
536cdf0e10cSrcweir 			m_xmlSecurityFrameworkController.endMission();
537cdf0e10cSrcweir 		}
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 		updatesUIs();
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 		m_xmlSecurityFrameworkController = null;
542cdf0e10cSrcweir 		freeComponents();
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 		System.gc();
545cdf0e10cSrcweir 	}
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 	/******************************************************************************
549cdf0e10cSrcweir 	 * UNO component related methods
550cdf0e10cSrcweir 	 ******************************************************************************/
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 	/*
553cdf0e10cSrcweir 	 * connects the SO server.
554cdf0e10cSrcweir 	 */
connectSO(String unoUrlString)555cdf0e10cSrcweir 	private void connectSO(String unoUrlString)
556cdf0e10cSrcweir 	{
557cdf0e10cSrcweir 		if (unoUrlString != null)
558cdf0e10cSrcweir 		{
559cdf0e10cSrcweir 			m_unoURL = new String(unoUrlString);
560cdf0e10cSrcweir 		}
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 		try
563cdf0e10cSrcweir 		{
564cdf0e10cSrcweir 			m_xRemoteServiceManager = getRemoteServiceManager(m_unoURL);
565cdf0e10cSrcweir 		}
566cdf0e10cSrcweir 		catch(Exception e)
567cdf0e10cSrcweir 		{
568cdf0e10cSrcweir 			e.printStackTrace();
569cdf0e10cSrcweir 		}
570cdf0e10cSrcweir 	}
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 	/*
573cdf0e10cSrcweir 	 * creates UNO components.
574cdf0e10cSrcweir 	 */
createComponents()575cdf0e10cSrcweir 	private boolean createComponents()
576cdf0e10cSrcweir 	{
577cdf0e10cSrcweir 		try
578cdf0e10cSrcweir 		{
579cdf0e10cSrcweir 			String SEInitializer_comp;
580cdf0e10cSrcweir 			String XMLSignature_comp;
581cdf0e10cSrcweir 			String XMLEncryption_comp;
582cdf0e10cSrcweir 			String tokenPath;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 			if (m_bIsJavaBased)
585cdf0e10cSrcweir 			{
586cdf0e10cSrcweir 				SEInitializer_comp = SEINITIALIZER_COMPONENT_JAVA;
587cdf0e10cSrcweir 				XMLSignature_comp = XMLSIGNATURE_COMPONENT_JAVA;
588cdf0e10cSrcweir 				XMLEncryption_comp = XMLENCRYPTION_COMPONENT_JAVA;
589cdf0e10cSrcweir 				tokenPath = m_javaTokenFile;
590cdf0e10cSrcweir 			}
591cdf0e10cSrcweir 			else
592cdf0e10cSrcweir 			{
593cdf0e10cSrcweir 				SEInitializer_comp = SEINITIALIZER_COMPONENT_C;
594cdf0e10cSrcweir 				XMLSignature_comp = XMLSIGNATURE_COMPONENT_C;
595cdf0e10cSrcweir 				XMLEncryption_comp = XMLENCRYPTION_COMPONENT_C;
596cdf0e10cSrcweir 				tokenPath = m_nssTokenPath;
597cdf0e10cSrcweir 			}
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 			Object seInitializerObj = m_xRemoteServiceManager.createInstanceWithContext(
600cdf0e10cSrcweir 				SEInitializer_comp, m_xRemoteContext);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 			if (seInitializerObj == null)
603cdf0e10cSrcweir 			{
604cdf0e10cSrcweir 				freeComponents();
605cdf0e10cSrcweir 				return false;
606cdf0e10cSrcweir 			}
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 			m_xSEInitializer = (XSEInitializer)UnoRuntime.queryInterface(
609cdf0e10cSrcweir 						XSEInitializer.class, seInitializerObj);
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 			m_xXMLSecurityContext = m_xSEInitializer.createSecurityContext(tokenPath);
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 			Object xmlSignatureObj = m_xRemoteServiceManager.createInstanceWithContext(
614cdf0e10cSrcweir 				XMLSignature_comp, m_xRemoteContext);
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 			if (xmlSignatureObj == null)
617cdf0e10cSrcweir 			{
618cdf0e10cSrcweir 				freeComponents();
619cdf0e10cSrcweir 				return false;
620cdf0e10cSrcweir 			}
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 			m_xXMLSignature = (XXMLSignature)UnoRuntime.queryInterface(
623cdf0e10cSrcweir 						XXMLSignature.class, xmlSignatureObj);
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 			Object xmlEncryptionObj = m_xRemoteServiceManager.createInstanceWithContext(
626cdf0e10cSrcweir 				XMLEncryption_comp, m_xRemoteContext);
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 			if (xmlEncryptionObj == null)
629cdf0e10cSrcweir 			{
630cdf0e10cSrcweir 				freeComponents();
631cdf0e10cSrcweir 				return false;
632cdf0e10cSrcweir 			}
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 			m_xXMLEncryption = (XXMLEncryption)UnoRuntime.queryInterface(
635cdf0e10cSrcweir 						XXMLEncryption.class, xmlEncryptionObj);
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 			return true;
638cdf0e10cSrcweir 		}
639cdf0e10cSrcweir 		catch(Exception e)
640cdf0e10cSrcweir 		{
641cdf0e10cSrcweir 			freeComponents();
642cdf0e10cSrcweir 			e.printStackTrace();
643cdf0e10cSrcweir 			return false;
644cdf0e10cSrcweir 		}
645cdf0e10cSrcweir 	}
646cdf0e10cSrcweir 
647cdf0e10cSrcweir         /*
648cdf0e10cSrcweir          * frees UNO components.
649cdf0e10cSrcweir          */
freeComponents()650cdf0e10cSrcweir 	private void freeComponents()
651cdf0e10cSrcweir 	{
652cdf0e10cSrcweir 		try
653cdf0e10cSrcweir 		{
654cdf0e10cSrcweir 			if (m_xXMLSecurityContext != null)
655cdf0e10cSrcweir 			{
656cdf0e10cSrcweir 				m_xSEInitializer.freeSecurityContext(m_xXMLSecurityContext);
657cdf0e10cSrcweir 				m_xXMLSecurityContext = null;
658cdf0e10cSrcweir 			}
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 			m_xXMLSignature = null;
661cdf0e10cSrcweir 			m_xXMLEncryption = null;
662cdf0e10cSrcweir 			m_xSEInitializer = null;
663cdf0e10cSrcweir 		}
664cdf0e10cSrcweir 		catch(Exception e)
665cdf0e10cSrcweir 		{
666cdf0e10cSrcweir 			e.printStackTrace();
667cdf0e10cSrcweir 		}
668cdf0e10cSrcweir 	}
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 	/*
671cdf0e10cSrcweir 	 * getRemoteServiceManager
672cdf0e10cSrcweir 	 */
getRemoteServiceManager(String unoUrl)673cdf0e10cSrcweir 	private XMultiComponentFactory getRemoteServiceManager(String unoUrl) throws java.lang.Exception
674cdf0e10cSrcweir 	{
675cdf0e10cSrcweir 		if (m_xRemoteContext == null)
676cdf0e10cSrcweir 		{
677cdf0e10cSrcweir 			/*
678cdf0e10cSrcweir 			 * First step: create local component context, get local servicemanager and
679cdf0e10cSrcweir 			 * ask it to create a UnoUrlResolver object with an XUnoUrlResolver interface
680cdf0e10cSrcweir 			 */
681cdf0e10cSrcweir 			XComponentContext xLocalContext =
682cdf0e10cSrcweir 				com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
683cdf0e10cSrcweir 			XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
684cdf0e10cSrcweir 			Object urlResolver = xLocalServiceManager.createInstanceWithContext(
685cdf0e10cSrcweir 				UNOURLRESOLVER, xLocalContext );
686cdf0e10cSrcweir 			/*
687cdf0e10cSrcweir 			 * query XUnoUrlResolver interface from urlResolver object
688cdf0e10cSrcweir 			 */
689cdf0e10cSrcweir 			XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
690cdf0e10cSrcweir 				XUnoUrlResolver.class, urlResolver );
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 			/*
693cdf0e10cSrcweir 			 * Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
694cdf0e10cSrcweir 			 * retrieve its property DefaultContext and get the remote servicemanager
695cdf0e10cSrcweir 			 */
696cdf0e10cSrcweir 			Object initialObject = xUnoUrlResolver.resolve( unoUrl );
697cdf0e10cSrcweir 			XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
698cdf0e10cSrcweir 			XPropertySet.class, initialObject);
699cdf0e10cSrcweir 			Object context = xPropertySet.getPropertyValue("DefaultContext");
700cdf0e10cSrcweir 			m_xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(
701cdf0e10cSrcweir 				XComponentContext.class, context);
702cdf0e10cSrcweir 		}
703cdf0e10cSrcweir 		return m_xRemoteContext.getServiceManager();
704cdf0e10cSrcweir 	}
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 
707cdf0e10cSrcweir 	/******************************************************************************
708cdf0e10cSrcweir 	 * XML related methods
709cdf0e10cSrcweir 	 ******************************************************************************/
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 	/*
712cdf0e10cSrcweir 	 * removes all empty text node inside the particular element
713cdf0e10cSrcweir 	 */
removeEmptyText(Node node)714cdf0e10cSrcweir 	private void removeEmptyText(Node node)
715cdf0e10cSrcweir 	{
716cdf0e10cSrcweir 		int type = node.getNodeType();
717cdf0e10cSrcweir 		NodeList children;
718cdf0e10cSrcweir 		int i;
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 		switch (type)
721cdf0e10cSrcweir 		{
722cdf0e10cSrcweir 		case Node.DOCUMENT_NODE:
723cdf0e10cSrcweir 		case Node.ELEMENT_NODE:
724cdf0e10cSrcweir 			Node child = node.getFirstChild();
725cdf0e10cSrcweir 			while (child!= null)
726cdf0e10cSrcweir 			{
727cdf0e10cSrcweir 				Node nextSibling = child.getNextSibling();
728cdf0e10cSrcweir 				int childType = child.getNodeType();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 				if (childType==Node.TEXT_NODE)
731cdf0e10cSrcweir 				{
732cdf0e10cSrcweir 					String message = child.getNodeValue().trim();
733cdf0e10cSrcweir 					if (message == null || message.length()<=0)
734cdf0e10cSrcweir 					{
735cdf0e10cSrcweir 						node.removeChild(child);
736cdf0e10cSrcweir 					}
737cdf0e10cSrcweir 				}
738cdf0e10cSrcweir 				else if (childType == Node.ELEMENT_NODE)
739cdf0e10cSrcweir 				{
740cdf0e10cSrcweir 					removeEmptyText(child);
741cdf0e10cSrcweir 				}
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 				child = nextSibling;
744cdf0e10cSrcweir 			}
745cdf0e10cSrcweir 			break;
746cdf0e10cSrcweir 		}
747cdf0e10cSrcweir 	}
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 	/*
750cdf0e10cSrcweir 	 * reads a stream, and parses it into the original tree.
751cdf0e10cSrcweir 	 */
parseStream(InputStream is)752cdf0e10cSrcweir 	private void parseStream(InputStream is)
753cdf0e10cSrcweir 	{
754cdf0e10cSrcweir 		try
755cdf0e10cSrcweir 		{
756cdf0e10cSrcweir 			DocumentBuilderFactory factory =
757cdf0e10cSrcweir 				DocumentBuilderFactory.newInstance();
758cdf0e10cSrcweir 			m_document = null;
759cdf0e10cSrcweir 			m_startButton.setEnabled(false);
760cdf0e10cSrcweir 			initUI();
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 			/* factory.setValidating(true); */
763cdf0e10cSrcweir 			/* factory.setNamespaceAware(true); */
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 			try
766cdf0e10cSrcweir 			{
767cdf0e10cSrcweir 				DocumentBuilder builder = factory.newDocumentBuilder();
768cdf0e10cSrcweir 				m_document = builder.parse(is);
769cdf0e10cSrcweir 				m_startButton.setEnabled(true);
770cdf0e10cSrcweir 				initUI();
771cdf0e10cSrcweir 			}
772cdf0e10cSrcweir 			catch (ParserConfigurationException pce)
773cdf0e10cSrcweir 			{
774cdf0e10cSrcweir 				pce.printStackTrace();
775cdf0e10cSrcweir 			}
776cdf0e10cSrcweir 			catch (IOException ioe)
777cdf0e10cSrcweir 			{
778cdf0e10cSrcweir 				ioe.printStackTrace();
779cdf0e10cSrcweir 			}
780cdf0e10cSrcweir 		}
781cdf0e10cSrcweir 		catch(Exception exce)
782cdf0e10cSrcweir 		{
783cdf0e10cSrcweir 			System.out.println("input stream Exception");
784cdf0e10cSrcweir 		}
785cdf0e10cSrcweir 	}
786cdf0e10cSrcweir 
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 	/******************************************************************************
789cdf0e10cSrcweir 	 * file operation related methods
790cdf0e10cSrcweir 	 ******************************************************************************/
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 	/*
793cdf0e10cSrcweir 	 * opens a file, and parses it into the original tree.
794cdf0e10cSrcweir 	 */
parseFile(File name)795cdf0e10cSrcweir 	private void parseFile(File name)
796cdf0e10cSrcweir 	{
797cdf0e10cSrcweir 		try
798cdf0e10cSrcweir 		{
799cdf0e10cSrcweir 			FileInputStream fis = new FileInputStream(name);
800cdf0e10cSrcweir 			parseStream(fis);
801cdf0e10cSrcweir 			fis.close();
802cdf0e10cSrcweir 		}
803cdf0e10cSrcweir 		catch(Exception exce)
804cdf0e10cSrcweir 		{
805cdf0e10cSrcweir 			System.out.println("open file Exception");
806cdf0e10cSrcweir 		}
807cdf0e10cSrcweir 	}
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 	/*
811cdf0e10cSrcweir 	 * selects a file to open
812cdf0e10cSrcweir 	 */
openFile()813cdf0e10cSrcweir 	private File openFile()
814cdf0e10cSrcweir 	{
815cdf0e10cSrcweir 		File rc = null;
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 		JFileChooser fileChooser= new JFileChooser();
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		fileChooser.setDialogTitle("Select File To Open");
820cdf0e10cSrcweir 		fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
821cdf0e10cSrcweir 
822cdf0e10cSrcweir 		fileChooser.setApproveButtonText("Ok");
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 		if (m_currentDirectory == null)
825cdf0e10cSrcweir 		{
826cdf0e10cSrcweir 			fileChooser.rescanCurrentDirectory();
827cdf0e10cSrcweir 		}
828cdf0e10cSrcweir 		else
829cdf0e10cSrcweir 		{
830cdf0e10cSrcweir 			fileChooser.setCurrentDirectory(m_currentDirectory);
831cdf0e10cSrcweir 		}
832cdf0e10cSrcweir 
833cdf0e10cSrcweir 		fileChooser.setFileFilter(new XMLFileFilter());
834cdf0e10cSrcweir 
835cdf0e10cSrcweir 		int result = fileChooser.showDialog(this,null);
836cdf0e10cSrcweir 		if (result==fileChooser.APPROVE_OPTION)
837cdf0e10cSrcweir 		{
838cdf0e10cSrcweir 			m_currentDirectory = fileChooser.getCurrentDirectory();
839cdf0e10cSrcweir 			rc = fileChooser.getSelectedFile();
840cdf0e10cSrcweir 		}
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 		return rc;
843cdf0e10cSrcweir 	}
844cdf0e10cSrcweir 
saveFile()845cdf0e10cSrcweir 	private void saveFile()
846cdf0e10cSrcweir 	{
847cdf0e10cSrcweir 		JFileChooser fileChooser= new JFileChooser();
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 		fileChooser.setDialogTitle("Select File To Save");
850cdf0e10cSrcweir 		fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 		fileChooser.setApproveButtonText("Ok");
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 		if (m_currentDirectory == null)
855cdf0e10cSrcweir 		{
856cdf0e10cSrcweir 			fileChooser.rescanCurrentDirectory();
857cdf0e10cSrcweir 		}
858cdf0e10cSrcweir 		else
859cdf0e10cSrcweir 		{
860cdf0e10cSrcweir 			fileChooser.setCurrentDirectory(m_currentDirectory);
861cdf0e10cSrcweir 		}
862cdf0e10cSrcweir 
863cdf0e10cSrcweir 		fileChooser.setFileFilter(new XMLFileFilter());
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 		int result = fileChooser.showDialog(this,null);
866cdf0e10cSrcweir 		if (result==fileChooser.APPROVE_OPTION)
867cdf0e10cSrcweir 		{
868cdf0e10cSrcweir 			try
869cdf0e10cSrcweir 			{
870cdf0e10cSrcweir 				m_currentDirectory = fileChooser.getCurrentDirectory();
871cdf0e10cSrcweir 				saveFile(fileChooser.getSelectedFile());
872cdf0e10cSrcweir 			}
873cdf0e10cSrcweir 			catch(Exception exce)
874cdf0e10cSrcweir 			{
875cdf0e10cSrcweir 				System.out.println("save file Exception");
876cdf0e10cSrcweir 				exce.printStackTrace();
877cdf0e10cSrcweir 			}
878cdf0e10cSrcweir 		}
879cdf0e10cSrcweir 	}
880cdf0e10cSrcweir 
881cdf0e10cSrcweir 	/*
882cdf0e10cSrcweir 	 * excutes a batch file.
883cdf0e10cSrcweir 	 */
runBatch(File f)884cdf0e10cSrcweir 	private void runBatch(File f)
885cdf0e10cSrcweir 	{
886cdf0e10cSrcweir 		FileInputStream fis = null;
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 		try
889cdf0e10cSrcweir 		{
890cdf0e10cSrcweir 			fis = new FileInputStream(f);
891cdf0e10cSrcweir 			StringBuffer commandBuffer = new StringBuffer();
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 			m_logFileOutputStream = new FileOutputStream("TestTool-log.txt");
894cdf0e10cSrcweir 			m_bIsBatchRunning = true;
895cdf0e10cSrcweir 			int ch = 0;
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 			while (ch != -1)
898cdf0e10cSrcweir 			{
899cdf0e10cSrcweir 				ch = fis.read();
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 				if (ch != 0x0a && ch != -1)
902cdf0e10cSrcweir 				{
903cdf0e10cSrcweir 					if (ch != 0x0d)
904cdf0e10cSrcweir 					{
905cdf0e10cSrcweir 						commandBuffer.append((char)ch);
906cdf0e10cSrcweir 					}
907cdf0e10cSrcweir 				}
908cdf0e10cSrcweir 				else
909cdf0e10cSrcweir 				{
910cdf0e10cSrcweir 					String command = new String(commandBuffer);
911cdf0e10cSrcweir 					if (command.startsWith("Open "))
912cdf0e10cSrcweir 					{
913cdf0e10cSrcweir 						m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
914cdf0e10cSrcweir 						String fileName = command.substring(5);
915cdf0e10cSrcweir 						parseFile(new File(fileName));
916cdf0e10cSrcweir 						m_logFileOutputStream.write("command end \n\n".getBytes());
917cdf0e10cSrcweir 					}
918cdf0e10cSrcweir 					else if (command.startsWith("Use Java Component"))
919cdf0e10cSrcweir 					{
920cdf0e10cSrcweir 						m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
921cdf0e10cSrcweir 						m_isJavaComponentButton.setSelected(true);
922cdf0e10cSrcweir 						m_logFileOutputStream.write("command end \n\n".getBytes());
923cdf0e10cSrcweir 					}
924cdf0e10cSrcweir 					else if (command.startsWith("Use C++ Component"))
925cdf0e10cSrcweir 					{
926cdf0e10cSrcweir 						m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
927cdf0e10cSrcweir 						m_isJavaComponentButton.setSelected(false);
928cdf0e10cSrcweir 						m_logFileOutputStream.write("command end \n\n".getBytes());
929cdf0e10cSrcweir 					}
930cdf0e10cSrcweir 					else if (command.startsWith("Go "))
931cdf0e10cSrcweir 					{
932cdf0e10cSrcweir 						m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
933cdf0e10cSrcweir 						String opera = command.substring(3);
934cdf0e10cSrcweir 						if (opera.equals("Sign") || opera.equals("Encrypt"))
935cdf0e10cSrcweir 						{
936cdf0e10cSrcweir 							m_isExportingButton.setSelected(true);
937cdf0e10cSrcweir 						}
938cdf0e10cSrcweir 						else
939cdf0e10cSrcweir 						{
940cdf0e10cSrcweir 							m_isExportingButton.setSelected(false);
941cdf0e10cSrcweir 						}
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 						startsUp();
944cdf0e10cSrcweir 						if (m_parsingThread != null)
945cdf0e10cSrcweir 						{
946cdf0e10cSrcweir 							m_bIsUIUpdateSuppressed = true;
947cdf0e10cSrcweir 							try{
948cdf0e10cSrcweir 								while (m_parsingThread.nextStep());
949cdf0e10cSrcweir 								endMission();
950cdf0e10cSrcweir 							}
951cdf0e10cSrcweir 							catch(Exception e)
952cdf0e10cSrcweir 							{
953cdf0e10cSrcweir 								System.out.println("exception happen during batch:"+e);
954cdf0e10cSrcweir 								e.printStackTrace();
955cdf0e10cSrcweir 							}
956cdf0e10cSrcweir 
957cdf0e10cSrcweir 							m_bIsUIUpdateSuppressed = false;
958cdf0e10cSrcweir 							updatesUIs();
959cdf0e10cSrcweir 						}
960cdf0e10cSrcweir 						m_logFileOutputStream.write("command end \n\n".getBytes());
961cdf0e10cSrcweir 					}
962cdf0e10cSrcweir 					else if (command.startsWith("Save "))
963cdf0e10cSrcweir 					{
964cdf0e10cSrcweir 						m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
965cdf0e10cSrcweir 						String fileName = command.substring(5);
966cdf0e10cSrcweir 						saveFile(new File(fileName));
967cdf0e10cSrcweir 						m_logFileOutputStream.write("command end \n\n".getBytes());
968cdf0e10cSrcweir 					}
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 					commandBuffer = new StringBuffer();
971cdf0e10cSrcweir 				}
972cdf0e10cSrcweir 			}
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 			m_bIsBatchRunning = false;
975cdf0e10cSrcweir 			m_logFileOutputStream.close();
976cdf0e10cSrcweir 			m_logFileOutputStream = null;
977cdf0e10cSrcweir 
978cdf0e10cSrcweir 			fis.close();
979cdf0e10cSrcweir 			fis = null;
980cdf0e10cSrcweir 		}
981cdf0e10cSrcweir 		catch(java.io.IOException e)
982cdf0e10cSrcweir 		{
983cdf0e10cSrcweir 			e.printStackTrace();
984cdf0e10cSrcweir 		}
985cdf0e10cSrcweir 	}
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 	/*
988cdf0e10cSrcweir 	 * save the current result tree to a particular file.
989cdf0e10cSrcweir 	 */
saveFile(File f)990cdf0e10cSrcweir 	private void saveFile(File f)
991cdf0e10cSrcweir 	{
992cdf0e10cSrcweir 		try{
993cdf0e10cSrcweir 			FileOutputStream fos = new FileOutputStream(f);
994cdf0e10cSrcweir 			SAXEventPrinter.display((Document)m_rightTreeEventCollector.getDocument(),
995cdf0e10cSrcweir 				0,fos,false);
996cdf0e10cSrcweir 			fos.close();
997cdf0e10cSrcweir 		}catch(Exception e)
998cdf0e10cSrcweir 		{
999cdf0e10cSrcweir 			e.printStackTrace();
1000cdf0e10cSrcweir 		}
1001cdf0e10cSrcweir 	}
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 	/******************************************************************************
1004cdf0e10cSrcweir 	 * others
1005cdf0e10cSrcweir 	 ******************************************************************************/
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	/*
1008cdf0e10cSrcweir 	 * starts up the operation.
1009cdf0e10cSrcweir 	 */
startsUp()1010cdf0e10cSrcweir 	private void startsUp()
1011cdf0e10cSrcweir 	{
1012cdf0e10cSrcweir 		if (m_parsingThread != null)
1013cdf0e10cSrcweir 		{
1014cdf0e10cSrcweir 			m_parsingThread = null;
1015cdf0e10cSrcweir 		}
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 		m_bIsExporting = m_isExportingButton.isSelected();
1018cdf0e10cSrcweir 		m_bIsJavaBased = m_isJavaComponentButton.isSelected();
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 		if (createComponents())
1021cdf0e10cSrcweir 		{
1022cdf0e10cSrcweir 			m_rightTreeEventCollector = new SAXEventCollector(this);
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 			m_parsingThread = new ParsingThread(
1025cdf0e10cSrcweir 				m_document,
1026cdf0e10cSrcweir 				null,
1027cdf0e10cSrcweir 				this);
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 			m_xmlSecurityFrameworkController =
1030cdf0e10cSrcweir 				new XMLSecurityFrameworkController(
1031cdf0e10cSrcweir 					this,
1032cdf0e10cSrcweir 					m_bIsExporting,
1033cdf0e10cSrcweir 					m_bIsJavaBased,
1034cdf0e10cSrcweir 					m_rightTreeEventCollector,
1035cdf0e10cSrcweir 					m_parsingThread,
1036cdf0e10cSrcweir 					m_xXMLSecurityContext,
1037cdf0e10cSrcweir 					m_xXMLSignature,
1038cdf0e10cSrcweir 					m_xXMLEncryption,
1039cdf0e10cSrcweir 					m_xRemoteServiceManager,
1040cdf0e10cSrcweir 					m_xRemoteContext);
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 			enableGoButton(true);
1043cdf0e10cSrcweir 		}
1044cdf0e10cSrcweir 		else
1045cdf0e10cSrcweir 		{
1046cdf0e10cSrcweir 			showMessage("Error in creating XML Security Components!");
1047cdf0e10cSrcweir 		}
1048cdf0e10cSrcweir 	}
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir /**************************************************************************************
1051cdf0e10cSrcweir  * protected methods
1052cdf0e10cSrcweir  **************************************************************************************/
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 	/******************************************************************************
1055cdf0e10cSrcweir 	 * UI related methods
1056cdf0e10cSrcweir 	 ******************************************************************************/
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir 	/*
1059cdf0e10cSrcweir 	 * updates the sax chain information.
1060cdf0e10cSrcweir 	 */
updatesSAXChainInformation(String chainStr)1061cdf0e10cSrcweir 	protected void updatesSAXChainInformation(String chainStr)
1062cdf0e10cSrcweir 	{
1063cdf0e10cSrcweir 		m_saxChainLabel.setText(chainStr);
1064cdf0e10cSrcweir 	}
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 	/*
1067cdf0e10cSrcweir 	 * update the current SAX event information.
1068cdf0e10cSrcweir 	 */
updatesCurrentSAXEventInformation(String event)1069cdf0e10cSrcweir 	protected void updatesCurrentSAXEventInformation(String event)
1070cdf0e10cSrcweir 	{
1071cdf0e10cSrcweir 		m_saxEventText.setText(event);
1072cdf0e10cSrcweir 	}
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 	/*
1075cdf0e10cSrcweir 	 * updates all information in the UI.
1076cdf0e10cSrcweir 	 */
updatesUIs()1077cdf0e10cSrcweir 	protected void updatesUIs()
1078cdf0e10cSrcweir 	{
1079cdf0e10cSrcweir 		if (!m_bIsUIUpdateSuppressed)
1080cdf0e10cSrcweir 		{
1081cdf0e10cSrcweir 			m_leftTree.clearSelection();
1082cdf0e10cSrcweir 			updatesTree(null, m_leftTree);
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir 			if (m_xmlSecurityFrameworkController != null)
1085cdf0e10cSrcweir 			{
1086cdf0e10cSrcweir 				String bufferNodeTreeText = m_xmlSecurityFrameworkController.getBufferNodeTreeInformation();
1087cdf0e10cSrcweir 				if (bufferNodeTreeText == null)
1088cdf0e10cSrcweir 				{
1089cdf0e10cSrcweir 					m_middleTree.setVisible(false);
1090cdf0e10cSrcweir 					m_bufferNodeTextArea.setText("No XML Security Related");
1091cdf0e10cSrcweir 				}
1092cdf0e10cSrcweir 				else
1093cdf0e10cSrcweir 				{
1094cdf0e10cSrcweir 					m_middleTreeEventCollector = new SAXEventCollector(null);
1095cdf0e10cSrcweir 					m_xmlSecurityFrameworkController.getDocument(m_middleTreeEventCollector);
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 					m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_middleTreeEventCollector.getDocument());
1098cdf0e10cSrcweir 					m_middleTree.setModel(m_middleTreeModelAdapter);
1099cdf0e10cSrcweir 					updatesTree(null, m_middleTree);
1100cdf0e10cSrcweir 					m_middleTree.setVisible(true);
1101cdf0e10cSrcweir 					m_bufferNodeTextArea.setText(bufferNodeTreeText);
1102cdf0e10cSrcweir 				}
1103cdf0e10cSrcweir 			}
1104cdf0e10cSrcweir 			else
1105cdf0e10cSrcweir 			{
1106cdf0e10cSrcweir 				m_middleTree.setVisible(false);
1107cdf0e10cSrcweir 				m_bufferNodeTextArea.setText("No XMLImporter/XMLExporter");
1108cdf0e10cSrcweir 			}
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir 			if (m_rightTreeEventCollector != null)
1111cdf0e10cSrcweir 			{
1112cdf0e10cSrcweir 				m_rightTreeModelAdapter = new DomToTreeModelAdapter((Document)m_rightTreeEventCollector.getDocument());
1113cdf0e10cSrcweir 				m_rightTree.setModel(m_rightTreeModelAdapter);
1114cdf0e10cSrcweir 				updatesTree((Node)m_rightTreeEventCollector.getCurrentElement(), m_rightTree);
1115cdf0e10cSrcweir 			}
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 			updatesUnsolvedReferencesInformation();
1118cdf0e10cSrcweir 		}
1119cdf0e10cSrcweir 	}
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 	/*
1122cdf0e10cSrcweir 	 * shows a message.
1123cdf0e10cSrcweir 	 */
showMessage(String msg)1124cdf0e10cSrcweir 	protected void showMessage(String msg)
1125cdf0e10cSrcweir 	{
1126cdf0e10cSrcweir 		if (m_bIsBatchRunning)
1127cdf0e10cSrcweir 		{
1128cdf0e10cSrcweir 			try
1129cdf0e10cSrcweir 			{
1130cdf0e10cSrcweir 				if (!msg.startsWith("Message from : SAXEventKeeper"))
1131cdf0e10cSrcweir 				{
1132cdf0e10cSrcweir 					byte [] b = msg.getBytes();
1133cdf0e10cSrcweir 					m_logFileOutputStream.write("        ".getBytes());
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 					for (int i=0; i<b.length; ++i)
1136cdf0e10cSrcweir 					{
1137cdf0e10cSrcweir 						m_logFileOutputStream.write(b[i]);
1138cdf0e10cSrcweir 						if (b[i] == '\n')
1139cdf0e10cSrcweir 						{
1140cdf0e10cSrcweir 							m_logFileOutputStream.write("        ".getBytes());
1141cdf0e10cSrcweir 						}
1142cdf0e10cSrcweir 					}
1143cdf0e10cSrcweir 					m_logFileOutputStream.write("\n        ==============================\n".getBytes());
1144cdf0e10cSrcweir 				}
1145cdf0e10cSrcweir 			}
1146cdf0e10cSrcweir 			catch(IOException e)
1147cdf0e10cSrcweir 			{
1148cdf0e10cSrcweir 				e.printStackTrace();
1149cdf0e10cSrcweir 			}
1150cdf0e10cSrcweir 		}
1151cdf0e10cSrcweir 		else
1152cdf0e10cSrcweir 		{
1153cdf0e10cSrcweir 			if (stepMode)
1154cdf0e10cSrcweir 			{
1155cdf0e10cSrcweir 				JOptionPane optionPane = new JOptionPane();
1156cdf0e10cSrcweir 				optionPane.showMessageDialog(this, msg, "TestTool Notification", JOptionPane.INFORMATION_MESSAGE);
1157cdf0e10cSrcweir 			}
1158cdf0e10cSrcweir 			else
1159cdf0e10cSrcweir 			{
1160cdf0e10cSrcweir 				Object[] options = { "OK", "Go back to step mode" };
1161cdf0e10cSrcweir 				if (1 == JOptionPane.showOptionDialog(this, msg, "TestTool Notification",
1162cdf0e10cSrcweir 					JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
1163cdf0e10cSrcweir 					null, options, options[0]))
1164cdf0e10cSrcweir 				{
1165cdf0e10cSrcweir 					stepMode = true;
1166cdf0e10cSrcweir 				}
1167cdf0e10cSrcweir 			}
1168cdf0e10cSrcweir 		}
1169cdf0e10cSrcweir 	}
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 	/******************************************************************************
1173cdf0e10cSrcweir 	 * information retrieving
1174cdf0e10cSrcweir 	 ******************************************************************************/
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir 	/*
1177cdf0e10cSrcweir 	 * gets all unsolved reference ids.
1178cdf0e10cSrcweir 	 * a reference id is the value of the id attribute of an
1179cdf0e10cSrcweir 	 * referenced element.
1180cdf0e10cSrcweir 	 */
getUnsolvedReferenceIds()1181cdf0e10cSrcweir 	protected Vector getUnsolvedReferenceIds()
1182cdf0e10cSrcweir 	{
1183cdf0e10cSrcweir 		Vector rc;
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 		if (m_xmlSecurityFrameworkController == null)
1186cdf0e10cSrcweir 		{
1187cdf0e10cSrcweir 			rc = new Vector();
1188cdf0e10cSrcweir 		}
1189cdf0e10cSrcweir 		else
1190cdf0e10cSrcweir 		{
1191cdf0e10cSrcweir 			rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
1192cdf0e10cSrcweir 				getUnsolvedReferenceIds();
1193cdf0e10cSrcweir 		}
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 		return rc;
1196cdf0e10cSrcweir 	}
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir 	/*
1199cdf0e10cSrcweir 	 * gets all unsolved reference keeper ids.
1200cdf0e10cSrcweir 	 * a reference keeper id is the id which the SAXEventKeeper uses
1201cdf0e10cSrcweir 	 * to identify the corresponding BufferNode.
1202cdf0e10cSrcweir 	 */
getUnsolvedReferenceKeeperIds()1203cdf0e10cSrcweir 	protected Vector getUnsolvedReferenceKeeperIds()
1204cdf0e10cSrcweir 	{
1205cdf0e10cSrcweir 		Vector rc;
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 		if (m_xmlSecurityFrameworkController == null)
1208cdf0e10cSrcweir 		{
1209cdf0e10cSrcweir 			rc = new Vector();
1210cdf0e10cSrcweir 		}
1211cdf0e10cSrcweir 		else
1212cdf0e10cSrcweir 		{
1213cdf0e10cSrcweir 			rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
1214cdf0e10cSrcweir 				getUnsolvedReferenceKeeperIds();
1215cdf0e10cSrcweir 		}
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir 		return rc;
1218cdf0e10cSrcweir 	}
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir 	/*
1221cdf0e10cSrcweir 	 * gets all unsolved references' remaining numbers.
1222cdf0e10cSrcweir 	 * a remaining number is that how many claims have not been found for
1223cdf0e10cSrcweir 	 * a unsolved reference.
1224cdf0e10cSrcweir 	 */
getUnsolvedReferenceRefNum()1225cdf0e10cSrcweir 	protected Vector getUnsolvedReferenceRefNum()
1226cdf0e10cSrcweir 	{
1227cdf0e10cSrcweir 		Vector rc;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 		if (m_xmlSecurityFrameworkController == null)
1230cdf0e10cSrcweir 		{
1231cdf0e10cSrcweir 			rc = new Vector();
1232cdf0e10cSrcweir 		}
1233cdf0e10cSrcweir 		else
1234cdf0e10cSrcweir 		{
1235cdf0e10cSrcweir 			rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
1236cdf0e10cSrcweir 				getUnsolvedReferenceRefNum();
1237cdf0e10cSrcweir 		}
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir 		return rc;
1240cdf0e10cSrcweir 	}
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir /**************************************************************************************
1244cdf0e10cSrcweir  * public methods
1245cdf0e10cSrcweir  **************************************************************************************/
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir 	/******************************************************************************
1248cdf0e10cSrcweir 	 * action listener related methods.
1249cdf0e10cSrcweir 	 ******************************************************************************/
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 	/*
1252cdf0e10cSrcweir 	 * action listening method.
1253cdf0e10cSrcweir 	 */
actionPerformed(ActionEvent e)1254cdf0e10cSrcweir 	public void actionPerformed(ActionEvent e)
1255cdf0e10cSrcweir 	{
1256cdf0e10cSrcweir 		if (e.getSource().equals(m_startButton))
1257cdf0e10cSrcweir 		{
1258cdf0e10cSrcweir 			endMission();
1259cdf0e10cSrcweir 			startsUp();
1260cdf0e10cSrcweir 		}
1261cdf0e10cSrcweir 		if (e.getSource().equals(m_goButton))
1262cdf0e10cSrcweir 		{
1263cdf0e10cSrcweir 			if (m_parsingThread != null)
1264cdf0e10cSrcweir 			{
1265cdf0e10cSrcweir 				stepMode = false;
1266cdf0e10cSrcweir 				boolean notOver;
1267cdf0e10cSrcweir 				while ( notOver = m_parsingThread.nextStep())
1268cdf0e10cSrcweir 				{
1269cdf0e10cSrcweir 					if (stepMode) break;
1270cdf0e10cSrcweir 				}
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 				if (!notOver) endMission();
1273cdf0e10cSrcweir 			}
1274cdf0e10cSrcweir 		}
1275cdf0e10cSrcweir 		if (e.getSource().equals(m_stepButton))
1276cdf0e10cSrcweir 		{
1277cdf0e10cSrcweir 			if (m_parsingThread != null)
1278cdf0e10cSrcweir 			{
1279cdf0e10cSrcweir 				if (!m_parsingThread.nextStep())
1280cdf0e10cSrcweir 				{
1281cdf0e10cSrcweir 					endMission();
1282cdf0e10cSrcweir 				}
1283cdf0e10cSrcweir 			}
1284cdf0e10cSrcweir 		}
1285cdf0e10cSrcweir 		if (e.getSource().equals(m_openButton))
1286cdf0e10cSrcweir 		{
1287cdf0e10cSrcweir 			openDocument();
1288cdf0e10cSrcweir 		}
1289cdf0e10cSrcweir 		if (e.getSource().equals(m_saveButton))
1290cdf0e10cSrcweir 		{
1291cdf0e10cSrcweir 			saveResult();
1292cdf0e10cSrcweir 		}
1293cdf0e10cSrcweir 		if (e.getSource().equals(m_batchButton))
1294cdf0e10cSrcweir 		{
1295cdf0e10cSrcweir 			openBatch();
1296cdf0e10cSrcweir 		}
1297cdf0e10cSrcweir 	}
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir 	/*
1300cdf0e10cSrcweir 	 * void-consturctor method
1301cdf0e10cSrcweir 	 */
TestTool()1302cdf0e10cSrcweir 	public TestTool()
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 	        getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir         	try
1307cdf0e10cSrcweir         	{
1308cdf0e10cSrcweir         		m_currentDirectory = new File(System.getProperty("user.dir"));
1309cdf0e10cSrcweir 		}
1310cdf0e10cSrcweir 		catch(Exception e)
1311cdf0e10cSrcweir 		{
1312cdf0e10cSrcweir 			System.out.println("getProperty error :"+e);
1313cdf0e10cSrcweir 		}
1314cdf0e10cSrcweir 	}
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 	/*
1317cdf0e10cSrcweir 	 * consturctor method with a specific connection URL
1318cdf0e10cSrcweir 	 */
TestTool(String connecturl)1319cdf0e10cSrcweir 	public TestTool(String connecturl)
1320cdf0e10cSrcweir 	{
1321cdf0e10cSrcweir 		this();
1322cdf0e10cSrcweir 		m_unoURL = new String(connecturl);
1323cdf0e10cSrcweir 	}
1324cdf0e10cSrcweir 
main(String argv[])1325cdf0e10cSrcweir 	public static void main(String argv[])
1326cdf0e10cSrcweir 	{
1327cdf0e10cSrcweir 		Dimension screenSize =
1328cdf0e10cSrcweir 			Toolkit.getDefaultToolkit().getScreenSize();
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 		TestTool tt;
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir 		if (argv.length < 1)
1333cdf0e10cSrcweir 		{
1334cdf0e10cSrcweir 			System.out.println("Usage: java TestTool [javaTokenFile] [nssTokenPath] [xml file]?");
1335cdf0e10cSrcweir 			return;
1336cdf0e10cSrcweir 		}
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 		boolean hasFile = false;
1339cdf0e10cSrcweir 		boolean hasBatch = false;
1340cdf0e10cSrcweir 		String fileName = null;
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 		if (argv.length >= 3)
1343cdf0e10cSrcweir 		{
1344cdf0e10cSrcweir 			if (argv[2].startsWith("-b"))
1345cdf0e10cSrcweir 			{
1346cdf0e10cSrcweir 				fileName = argv[2].substring(2);
1347cdf0e10cSrcweir 				hasBatch = true;
1348cdf0e10cSrcweir 			}
1349cdf0e10cSrcweir 			else
1350cdf0e10cSrcweir 			{
1351cdf0e10cSrcweir 				fileName = argv[2];
1352cdf0e10cSrcweir 				hasFile = true;
1353cdf0e10cSrcweir 			}
1354cdf0e10cSrcweir 		}
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 		tt = new TestTool();
1357cdf0e10cSrcweir 		tt.m_javaTokenFile = new String(argv[0]);
1358cdf0e10cSrcweir 		tt.m_nssTokenPath = new String(argv[1]);
1359cdf0e10cSrcweir 		tt.connectSO(null);
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 		/* Set up a GUI framework */
1362cdf0e10cSrcweir 		JFrame myFrame = new JFrame("XML Security Components Tester");
1363cdf0e10cSrcweir 		myFrame.addWindowListener(
1364cdf0e10cSrcweir 			new WindowAdapter() {
1365cdf0e10cSrcweir 				public void windowClosing(WindowEvent e) {System.exit(0);}
1366cdf0e10cSrcweir 			}
1367cdf0e10cSrcweir 			);
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 		myFrame.setContentPane(tt.buildUI(screenSize.width, screenSize.height));
1370cdf0e10cSrcweir 		myFrame.pack();
1371cdf0e10cSrcweir 		int w = screenSize.width-30;
1372cdf0e10cSrcweir 		int h = screenSize.height-30;
1373cdf0e10cSrcweir 		myFrame.setLocation(screenSize.width/2 - w/2,
1374cdf0e10cSrcweir 		screenSize.height/2 - h/2);
1375cdf0e10cSrcweir 		myFrame.setSize(w, h);
1376cdf0e10cSrcweir 		myFrame.setVisible(true);
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir 		if (hasFile)
1379cdf0e10cSrcweir 		{
1380cdf0e10cSrcweir 			tt.parseFile(new File(fileName));
1381cdf0e10cSrcweir 		}
1382cdf0e10cSrcweir 		else if (hasBatch)
1383cdf0e10cSrcweir 		{
1384cdf0e10cSrcweir 			tt.runBatch(new File(fileName));
1385cdf0e10cSrcweir 		}
1386cdf0e10cSrcweir 	}
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir 
1389