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