summaryrefslogtreecommitdiff
path: root/xmlsecurity/tools/uno
diff options
context:
space:
mode:
Diffstat (limited to 'xmlsecurity/tools/uno')
-rw-r--r--xmlsecurity/tools/uno/AdapterNode.java165
-rw-r--r--xmlsecurity/tools/uno/AttributeListHelper.java148
-rw-r--r--xmlsecurity/tools/uno/DomToTreeModelAdapter.java166
-rw-r--r--xmlsecurity/tools/uno/EncryptionEntity.java218
-rw-r--r--xmlsecurity/tools/uno/ParsingThread.java248
-rw-r--r--xmlsecurity/tools/uno/SAXEventCollector.java195
-rw-r--r--xmlsecurity/tools/uno/SAXEventPrinter.java320
-rw-r--r--xmlsecurity/tools/uno/SecurityEntity.java202
-rw-r--r--xmlsecurity/tools/uno/SignatureEntity.java288
-rw-r--r--xmlsecurity/tools/uno/TestTool.java1392
-rw-r--r--xmlsecurity/tools/uno/UnsolvedReferenceTableModel.java89
-rw-r--r--xmlsecurity/tools/uno/XMLFileFilter.java79
-rw-r--r--xmlsecurity/tools/uno/XMLSecurityFrameworkController.java1085
-rw-r--r--xmlsecurity/tools/uno/XMLTreeCellRanderer.java85
-rw-r--r--xmlsecurity/tools/uno/current.gifbin0 -> 94 bytes
-rw-r--r--xmlsecurity/tools/uno/makefile.mk48
16 files changed, 4728 insertions, 0 deletions
diff --git a/xmlsecurity/tools/uno/AdapterNode.java b/xmlsecurity/tools/uno/AdapterNode.java
new file mode 100644
index 000000000000..bed8e2a3631c
--- /dev/null
+++ b/xmlsecurity/tools/uno/AdapterNode.java
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+
+
+/*
+ * This class wraps a DOM node and returns the text we want to
+ * display in the tree. It also returns children, index values,
+ * and child counts.
+ */
+class AdapterNode
+{
+ private Node m_domNode;
+ static final int ELEMENT_TYPE = Node.ELEMENT_NODE;
+
+ /*
+ * An array of names for DOM node-types
+ */
+ static final String[] typeName = {
+ "none",
+ "Element",
+ "Attr",
+ "Text",
+ "CDATA",
+ "EntityRef",
+ "Entity",
+ "ProcInstr",
+ "Comment",
+ "Document",
+ "DocType",
+ "DocFragment",
+ "Notation",
+ };
+
+ protected Node getNode()
+ {
+ return m_domNode;
+ }
+
+ /*
+ * Construct an Adapter node from a DOM node
+ */
+ protected AdapterNode(org.w3c.dom.Node node)
+ {
+ m_domNode = node;
+ }
+
+ /*
+ * Return children, index, and count values
+ */
+ protected int index(AdapterNode child)
+ {
+ int count = childCount();
+ for (int i=0; i<count; ++i)
+ {
+ AdapterNode n = this.child(i);
+ if (child.m_domNode == n.m_domNode) return i;
+ }
+ return -1;
+ }
+
+ protected AdapterNode child(int searchIndex)
+ {
+ if (m_domNode == null) return null;
+
+ /*
+ * Note: JTree index is zero-based.
+ */
+ org.w3c.dom.Node node =
+ m_domNode.getChildNodes().item(searchIndex);
+
+ return new AdapterNode(node);
+ }
+
+ protected int childCount()
+ {
+ int rc = 0;
+
+ if (m_domNode != null)
+ {
+ rc = m_domNode.getChildNodes().getLength();
+ }
+
+ return rc;
+ }
+
+ /*
+ * Return a string that identifies this node in the tree
+ */
+ public String toString()
+ {
+ String rc = null;
+
+ if (m_domNode != null)
+ {
+ String s = typeName[m_domNode.getNodeType()];
+ String nodeName = m_domNode.getNodeName();
+
+ if (! nodeName.startsWith("#"))
+ {
+ s += ": " + nodeName;
+ }
+
+ if (m_domNode.getNodeValue() != null)
+ {
+ if (s.startsWith("ProcInstr"))
+ {
+ s += ", ";
+ }
+ else
+ {
+ s += ": ";
+ }
+
+ String t = m_domNode.getNodeValue();
+ s += t;
+ }
+
+ if (m_domNode.getNodeType() == ELEMENT_TYPE)
+ {
+ NamedNodeMap attrs = m_domNode.getAttributes();
+
+ int length = attrs.getLength();
+ for (int i=0; i<length; ++i)
+ {
+ Attr attr = (Attr)(attrs.item(i));
+ s += " "+ attr.getName()+"='"+attr.getValue() + "'";
+ }
+ }
+ rc = s;
+ }
+
+ return rc;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/AttributeListHelper.java b/xmlsecurity/tools/uno/AttributeListHelper.java
new file mode 100644
index 000000000000..c95067bcecb6
--- /dev/null
+++ b/xmlsecurity/tools/uno/AttributeListHelper.java
@@ -0,0 +1,148 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import java.util.Vector;
+import com.sun.star.xml.sax.XAttributeList;
+
+/**
+ * Class to construct an attribute list, and provide a XAttributeList
+ * interface.
+ *
+ * @author Michael Mi
+ * @version %I%, %G%
+ */
+public class AttributeListHelper implements com.sun.star.xml.sax.XAttributeList
+{
+ private Vector m_AttributeList;
+
+ public AttributeListHelper()
+ {
+ m_AttributeList = new Vector();
+ }
+
+ public void clear()
+ {
+ m_AttributeList.removeAllElements();
+ }
+
+ public void setAttribute(String name, String type, String value)
+ {
+ int nLength = m_AttributeList.size();
+ boolean bFound = false;
+
+ for (int i=0; i<nLength; ++i)
+ {
+ if (getNameByIndex((short)i).equals(name))
+ {
+ Vector attribute = (Vector)m_AttributeList.get(i);
+ attribute.setElementAt(type,1);
+ attribute.setElementAt(value,2);
+ bFound = true;
+ break;
+ }
+ }
+
+ if (!bFound)
+ {
+ Vector attribute = new Vector();
+ attribute.addElement(name);
+ attribute.addElement(type);
+ attribute.addElement(value);
+ m_AttributeList.addElement(attribute);
+ }
+ }
+
+ public String getAttributeItem(short index, int itemIndex)
+ {
+ String item = null;
+
+ if (index>=0 && index<getLength())
+ {
+ Vector attribute = (Vector)m_AttributeList.get(index);
+ item = (String)(attribute.get(itemIndex));
+ }
+
+ return item;
+ }
+
+ /* XAttributeList */
+ public short getLength()
+ {
+ return (short)m_AttributeList.size();
+ }
+
+ public String getNameByIndex(short i)
+ {
+ return getAttributeItem(i, 0);
+ }
+
+ public String getTypeByIndex(short i)
+ {
+ return getAttributeItem(i, 1);
+ }
+
+ public String getValueByIndex(short i)
+ {
+ return getAttributeItem(i, 2);
+ }
+
+ public String getTypeByName(String aName)
+ {
+ int nLength = m_AttributeList.size();
+ String type = null;
+
+ for (int i=0; i<nLength; ++i)
+ {
+ if (getNameByIndex((short)i).equals(aName))
+ {
+ type = getTypeByIndex((short)i);
+ break;
+ }
+ }
+
+ return type;
+ }
+
+ public String getValueByName(String aName)
+ {
+ int nLength = m_AttributeList.size();
+ String value = null;
+
+ for (int i=0; i<nLength; ++i)
+ {
+ if (getNameByIndex((short)i).equals(aName))
+ {
+ value = getValueByIndex((short)i);
+ break;
+ }
+ }
+ return value;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/DomToTreeModelAdapter.java b/xmlsecurity/tools/uno/DomToTreeModelAdapter.java
new file mode 100644
index 000000000000..709d0efa9515
--- /dev/null
+++ b/xmlsecurity/tools/uno/DomToTreeModelAdapter.java
@@ -0,0 +1,166 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import org.w3c.dom.Document;
+import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.tree.TreePath;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/*
+ * This adapter converts the current Document (a DOM) into
+ * a JTree model.
+ */
+class DomToTreeModelAdapter
+ implements javax.swing.tree.TreeModel
+{
+ private Document m_document;
+ private Vector m_listenerList = new Vector();
+
+ public DomToTreeModelAdapter(Document document)
+ {
+ m_document = document;
+ }
+
+ /*
+ * Basic TreeModel operations
+ */
+ public Object getRoot()
+ {
+ return new AdapterNode(m_document);
+ }
+
+ public boolean isLeaf(Object aNode)
+ {
+ boolean rc = true;
+
+ /*
+ * Determines whether the icon shows up to the left.
+ * Return true for any node with no children.
+ */
+ AdapterNode node = (AdapterNode) aNode;
+
+ if (node.childCount() > 0)
+ {
+ rc = false;
+ }
+
+ return rc;
+ }
+
+ public int getChildCount(Object parent)
+ {
+ AdapterNode node = (AdapterNode) parent;
+ return node.childCount();
+ }
+
+ public Object getChild(Object parent, int index)
+ {
+ AdapterNode node = (AdapterNode) parent;
+ return node.child(index);
+ }
+
+ public int getIndexOfChild(Object parent, Object child)
+ {
+ AdapterNode node = (AdapterNode) parent;
+ return node.index((AdapterNode) child);
+ }
+
+ public void valueForPathChanged(TreePath path, Object newValue)
+ {
+ /*
+ * Null. We won't be making changes in the GUI
+ * If we did, we would ensure the new value was really new,
+ * adjust the model, and then fire a TreeNodesChanged event.
+ */
+ }
+
+ public void addTreeModelListener(TreeModelListener listener)
+ {
+ if ( listener != null
+ && ! m_listenerList.contains( listener ) )
+ {
+ m_listenerList.addElement( listener );
+ }
+ }
+
+ public void removeTreeModelListener(TreeModelListener listener)
+ {
+ if ( listener != null )
+ {
+ m_listenerList.removeElement( listener );
+ }
+ }
+
+ public void fireTreeNodesChanged( TreeModelEvent e )
+ {
+ Enumeration listeners = m_listenerList.elements();
+ while ( listeners.hasMoreElements() )
+ {
+ TreeModelListener listener =
+ (TreeModelListener) listeners.nextElement();
+ listener.treeNodesChanged( e );
+ }
+ }
+
+ public void fireTreeNodesInserted( TreeModelEvent e )
+ {
+ Enumeration listeners = m_listenerList.elements();
+ while ( listeners.hasMoreElements() )
+ {
+ TreeModelListener listener =
+ (TreeModelListener) listeners.nextElement();
+ listener.treeNodesInserted( e );
+ }
+ }
+
+ public void fireTreeNodesRemoved( TreeModelEvent e )
+ {
+ Enumeration listeners = m_listenerList.elements();
+ while ( listeners.hasMoreElements() )
+ {
+ TreeModelListener listener =
+ (TreeModelListener) listeners.nextElement();
+ listener.treeNodesRemoved( e );
+ }
+ }
+
+ public void fireTreeStructureChanged( TreeModelEvent e )
+ {
+ Enumeration listeners = m_listenerList.elements();
+ while ( listeners.hasMoreElements() )
+ {
+ TreeModelListener listener =
+ (TreeModelListener) listeners.nextElement();
+ listener.treeStructureChanged( e );
+ }
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/EncryptionEntity.java b/xmlsecurity/tools/uno/EncryptionEntity.java
new file mode 100644
index 000000000000..51f14b2bbf6b
--- /dev/null
+++ b/xmlsecurity/tools/uno/EncryptionEntity.java
@@ -0,0 +1,218 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+/* uno classes */
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.xml.crypto.*;
+import com.sun.star.xml.crypto.sax.*;
+
+/*
+ * this class maintains the data for an encryption operation.
+ */
+class EncryptionEntity extends SecurityEntity
+{
+ private int m_nEncryptionElementCollectorId;
+
+ EncryptionEntity(
+ XSecuritySAXEventKeeper xSAXEventKeeper,
+ boolean isExporting,
+ Object resultListener,
+ XXMLSecurityContext xXMLSecurityContext,
+ XXMLSignature xXMLSignature,
+ XXMLEncryption xXMLEncryption,
+ XMultiComponentFactory xRemoteServiceManager,
+ XComponentContext xRemoteContext)
+ {
+ super(xSAXEventKeeper, xXMLSecurityContext, xXMLSignature,
+ xXMLEncryption, xRemoteServiceManager, xRemoteContext);
+
+ m_nEncryptionElementCollectorId = m_xSAXEventKeeper.addSecurityElementCollector(
+ ElementMarkPriority.AFTERMODIFY,
+ true);
+
+ m_xSAXEventKeeper.setSecurityId(m_nEncryptionElementCollectorId, m_nSecurityId);
+
+ if (isExporting)
+ {
+ try
+ {
+ /*
+ * creates a Encryptor.
+ */
+ Object encryptor = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.ENCRYPTOR_COMPONENT, m_xRemoteContext);
+
+ m_xReferenceResolvedListener =
+ (XReferenceResolvedListener)UnoRuntime.queryInterface(
+ XReferenceResolvedListener.class, encryptor);
+
+ /*
+ * initializes the Encryptor.
+ */
+ XInitialization xInitialization =
+ (XInitialization)UnoRuntime.queryInterface(
+ XInitialization.class, m_xReferenceResolvedListener);
+ Object args[]=new Object[5];
+ args[0] = new Integer(m_nSecurityId).toString();
+ args[1] = m_xSAXEventKeeper;
+ args[2] = new Integer(m_nEncryptionElementCollectorId).toString();
+ args[3] = m_xXMLSecurityContext.getSecurityEnvironment();
+ args[4] = m_xXMLEncryption;
+ xInitialization.initialize(args);
+
+ /*
+ * sets encryption result listener.
+ */
+ XEncryptionResultBroadcaster m_xEncryptionResultBroadcaster =
+ (XEncryptionResultBroadcaster)UnoRuntime.queryInterface(
+ XEncryptionResultBroadcaster.class, m_xReferenceResolvedListener);
+ m_xEncryptionResultBroadcaster.addEncryptionResultListener(
+ (XEncryptionResultListener)UnoRuntime.queryInterface(
+ XEncryptionResultListener.class, resultListener));
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ try{
+ /*
+ * creates a Decryptor.
+ */
+ Object decryptor = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.DECRYPTOR_COMPONENT, m_xRemoteContext);
+
+ m_xReferenceResolvedListener =
+ (XReferenceResolvedListener)UnoRuntime.queryInterface(
+ XReferenceResolvedListener.class, decryptor);
+
+ /*
+ * initializes the Decryptor.
+ */
+ XInitialization xInitialization = (XInitialization)UnoRuntime.queryInterface(XInitialization.class, m_xReferenceResolvedListener);
+ Object args[]=new Object[5];
+ args[0] = new Integer(m_nSecurityId).toString();
+ args[1] = m_xSAXEventKeeper;
+ args[2] = new Integer(m_nEncryptionElementCollectorId).toString();
+ args[3] = m_xXMLSecurityContext;
+ args[4] = m_xXMLEncryption;
+ xInitialization.initialize(args);
+
+ /*
+ * sets decryption result listener.
+ */
+ XDecryptionResultBroadcaster m_xDecryptionResultBroadcaster =
+ (XDecryptionResultBroadcaster)UnoRuntime.queryInterface(
+ XDecryptionResultBroadcaster.class, m_xReferenceResolvedListener);
+ m_xDecryptionResultBroadcaster.addDecryptionResultListener(
+ (XDecryptionResultListener)UnoRuntime.queryInterface(
+ XDecryptionResultListener.class, resultListener));
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * creates a Blocker.
+ */
+ int blockerId = m_xSAXEventKeeper.addBlocker();
+ m_xSAXEventKeeper.setSecurityId(blockerId, m_nSecurityId);
+
+ try
+ {
+ XBlockerMonitor xBlockerMonitor = (XBlockerMonitor)UnoRuntime.queryInterface(
+ XBlockerMonitor.class, m_xReferenceResolvedListener);
+ xBlockerMonitor.setBlockerId(blockerId);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ /*
+ * configures the resolve listener for the encryption template.
+ */
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(m_nEncryptionElementCollectorId, m_xReferenceResolvedListener);
+ }
+
+ /*
+ * add the reference to this encryption.
+ *
+ * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
+ * referenced element;
+ * 2. configures this ElementCollector's security id;
+ * 3. tells the SAXEventKeeper which listener will receive the reference
+ * resolved notification.
+ * 4. notifies the SignatureCollector about the reference id.
+ */
+ protected boolean setReference(boolean isExporting)
+ {
+ boolean rc = false;
+
+ int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
+ isExporting?
+ (ElementMarkPriority.AFTERMODIFY):(ElementMarkPriority.BEFOREMODIFY),
+ true);
+
+ m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
+
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(
+ referenceId, m_xReferenceResolvedListener);
+
+ try
+ {
+ XReferenceCollector xReferenceCollector =
+ (XReferenceCollector)UnoRuntime.queryInterface(
+ XReferenceCollector.class, m_xReferenceResolvedListener);
+ xReferenceCollector.setReferenceId(referenceId);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ rc = false;
+ }
+
+ return rc;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/ParsingThread.java b/xmlsecurity/tools/uno/ParsingThread.java
new file mode 100644
index 000000000000..f4bfea4a442e
--- /dev/null
+++ b/xmlsecurity/tools/uno/ParsingThread.java
@@ -0,0 +1,248 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import org.w3c.dom.Node;
+import com.sun.star.xml.sax.XDocumentHandler;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+
+/*
+ * this class is used to parse a document into SAX events
+ */
+class ParsingThread
+{
+ /*
+ * the Node which will be handled with in the next step
+ */
+ private Node m_node;
+
+ /*
+ * the event to be handled in the next step.
+ * true means endElement event, false otherwise.
+ */
+ private boolean m_bIsEndEvent;
+
+ /*
+ * the document handler which receives generated SAX events
+ */
+ private XDocumentHandler m_xDocumentHandler;
+
+ /*
+ * the TestTool which receives UI feedbacks
+ */
+ private TestTool m_testTool;
+
+
+ ParsingThread(Node node, XDocumentHandler xDocumentHandler, TestTool testTool)
+ {
+ m_node = node;
+ m_xDocumentHandler = xDocumentHandler;
+ m_testTool = testTool;
+
+ m_bIsEndEvent = false;
+ }
+
+ /*
+ * changes the document handler.
+ */
+ protected void setHandler(XDocumentHandler xDocumentHandler)
+ {
+ this.m_xDocumentHandler = xDocumentHandler;
+ }
+
+ /*
+ * sends the next SAX event.
+ * when there is no further step, then false is returned,
+ * otherwise, true returned.
+ */
+ protected boolean nextStep()
+ {
+ boolean rc = true;
+
+ try
+ {
+ String message;
+ int type = m_node.getNodeType();
+ if (!m_bIsEndEvent)
+ /*
+ * the next event is not a endElement event.
+ */
+ {
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE: /* startDocument */
+ m_testTool.updatesCurrentSAXEventInformation("startDocument");
+ m_xDocumentHandler.startDocument();
+ m_testTool.updatesUIs();
+ break;
+ case Node.ELEMENT_NODE: /* startElement */
+ String nodeName = m_node.getNodeName();
+ message = "startElement:"+nodeName;
+ NamedNodeMap attrs = m_node.getAttributes();
+
+ AttributeListHelper attributeListHelper = new AttributeListHelper();
+
+ int length = attrs.getLength();
+ for (int i=0; i<length; ++i)
+ {
+ Attr attr = (Attr)attrs.item(i);
+ attributeListHelper.setAttribute(attr.getName(), "CDATA", attr.getValue());
+ message += " "+attr.getName()+"='"+attr.getValue()+"'";
+ }
+
+ m_testTool.updatesCurrentSAXEventInformation(message);
+ m_xDocumentHandler.startElement(m_node.getNodeName(), attributeListHelper);
+
+ m_testTool.updatesUIs();
+ break;
+ case Node.TEXT_NODE: /* characters */
+ message = m_node.getNodeValue();
+ if (message != null)
+ {
+ m_testTool.updatesCurrentSAXEventInformation("characters:"+message);
+ m_xDocumentHandler.characters(message);
+ m_testTool.updatesUIs();
+ }
+ break;
+ case Node.COMMENT_NODE: /* comment */
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE: /* PI */
+ m_testTool.updatesCurrentSAXEventInformation("processingInstruction:"+m_node.getNodeName()+" "+m_node.getNodeValue());
+ m_xDocumentHandler.processingInstruction(m_node.getNodeName(), m_node.getNodeValue());
+ m_testTool.updatesUIs();
+ break;
+ }
+
+ /*
+ * figures out the event for the next step.
+ */
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE:
+ case Node.ELEMENT_NODE:
+ if (m_node.hasChildNodes())
+ /*
+ * for a Document node or an Element node,
+ * if the node has children, then the next event will be for its
+ * first child node.
+ */
+ {
+ m_node = m_node.getFirstChild();
+ }
+ else
+ /*
+ * otherwise, the next event will be endElement.
+ */
+ {
+ m_bIsEndEvent = true;
+ }
+ break;
+ case Node.TEXT_NODE:
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ case Node.COMMENT_NODE:
+ Node nextNode = m_node.getNextSibling();
+ if (nextNode != null)
+ /*
+ * for other kinds of node,
+ * if it has a next sibling, then the next event will be for that
+ * sibling.
+ */
+ {
+ m_node = nextNode;
+ }
+ else
+ /*
+ * otherwise, the next event will be the endElement for the node's
+ * parent node.
+ */
+ {
+ m_node = m_node.getParentNode();
+ m_bIsEndEvent = true;
+ }
+ break;
+ }
+ }
+ else
+ /*
+ * the next event is an endElement event.
+ */
+ {
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE: /* endDocument */
+ m_testTool.updatesCurrentSAXEventInformation("endDocument");
+ m_xDocumentHandler.endDocument();
+ m_testTool.updatesUIs();
+
+ /*
+ * no further steps.
+ */
+ rc = false;
+ break;
+ case Node.ELEMENT_NODE: /* endElement */
+ m_testTool.updatesCurrentSAXEventInformation("endElement:"+m_node.getNodeName());
+ m_xDocumentHandler.endElement(m_node.getNodeName());
+ m_testTool.updatesUIs();
+
+ Node nextNode = m_node.getNextSibling();
+ if (nextNode != null)
+ /*
+ * if the node has a next sibling, then the next event will be the
+ * start event for that sibling node.
+ */
+ {
+ m_node = nextNode;
+ m_bIsEndEvent = false;
+ }
+ else
+ /*
+ * otherwise, the next event will be the endElement for the node's
+ * parent node.
+ */
+ {
+ m_node = m_node.getParentNode();
+ }
+ break;
+ }
+ }
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+
+ /*
+ * forces to end.
+ */
+ rc = false;
+ }
+
+ return rc;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/SAXEventCollector.java b/xmlsecurity/tools/uno/SAXEventCollector.java
new file mode 100644
index 000000000000..e94c55252083
--- /dev/null
+++ b/xmlsecurity/tools/uno/SAXEventCollector.java
@@ -0,0 +1,195 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+import org.w3c.dom.ProcessingInstruction;
+
+/* uno classes */
+import com.sun.star.xml.sax.XDocumentHandler;
+import com.sun.star.xml.sax.XAttributeList;
+
+/*
+ * this class is used to collect all received SAX events
+ * into a DOM document.
+ */
+class SAXEventCollector implements XDocumentHandler
+{
+ /*
+ * the document which keeps received SAX events
+ */
+ private Document m_document;
+
+ /*
+ * the current Element to which the next received
+ * SAX event will be added.
+ */
+ private Node m_currentElement;
+
+ /*
+ * the TestTool which receives UI feedbacks
+ */
+ private TestTool m_testTool;
+
+ /*
+ * whether displays information on console.
+ */
+ private boolean m_systemDisplay;
+
+ SAXEventCollector(TestTool testTool)
+ {
+ this(testTool, false);
+ }
+
+ SAXEventCollector(TestTool testTool, boolean sysDis)
+ {
+ m_systemDisplay = sysDis;
+ m_testTool = testTool;
+
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+
+ try
+ {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ m_document = builder.newDocument();
+
+ m_currentElement = m_document;
+ }
+ catch (ParserConfigurationException pce) {
+ pce.printStackTrace();
+ }
+ }
+
+ protected Document getDocument()
+ {
+ return m_document;
+ }
+
+ protected Node getCurrentElement()
+ {
+ return m_currentElement;
+ }
+
+ /*
+ * XDocumentHandler
+ */
+ public void startDocument ()
+ {
+ }
+
+ public void endDocument()
+ {
+ }
+
+ public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs)
+ {
+ Element newElement = m_document.createElement(str);
+
+ if (xattribs !=null)
+ {
+ int length = xattribs.getLength();
+ for (short i=0; i<length; ++i)
+ {
+ newElement.setAttribute(
+ xattribs.getNameByIndex(i),
+ xattribs.getValueByIndex(i));
+ }
+ }
+
+ if (m_systemDisplay)
+ {
+ System.out.println("startElement:"+m_currentElement.toString());
+ }
+
+ m_currentElement.appendChild(newElement);
+ m_currentElement = newElement;
+
+ if (m_testTool != null)
+ {
+ m_testTool.updatesUIs();
+ }
+ }
+
+ public void endElement(String str)
+ {
+ if (m_systemDisplay)
+ {
+ System.out.println("endElement:"+str+" "+m_currentElement.toString());
+ }
+
+ m_currentElement = m_currentElement.getParentNode();
+ if (m_systemDisplay)
+ {
+ System.out.println("----> "+m_currentElement.toString());
+ }
+
+ if (m_testTool != null)
+ {
+ m_testTool.updatesUIs();
+ }
+ }
+
+ public void characters(String str)
+ {
+ Text newText = m_document.createTextNode(str);
+ m_currentElement.appendChild(newText);
+ if (m_testTool != null)
+ {
+ m_testTool.updatesUIs();
+ }
+ }
+
+ public void ignorableWhitespace(String str)
+ {
+ }
+
+ public void processingInstruction(String aTarget, String aData)
+ {
+ ProcessingInstruction newPI
+ = m_document.createProcessingInstruction(aTarget, aData);
+ m_currentElement.appendChild(newPI);
+ if (m_testTool != null)
+ {
+ m_testTool.updatesUIs();
+ }
+ }
+
+ public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator )
+ throws com.sun.star.xml.sax.SAXException
+ {
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/SAXEventPrinter.java b/xmlsecurity/tools/uno/SAXEventPrinter.java
new file mode 100644
index 000000000000..d841926bdd13
--- /dev/null
+++ b/xmlsecurity/tools/uno/SAXEventPrinter.java
@@ -0,0 +1,320 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NodeList;
+import java.io.IOException;
+import java.io.FileOutputStream;
+
+/* uno classes */
+import com.sun.star.xml.sax.XDocumentHandler;
+import com.sun.star.xml.sax.XAttributeList;
+
+/*
+ * The SAXEventPrinter class is used to print out received
+ * SAX event stream.
+ */
+class SAXEventPrinter implements XDocumentHandler
+{
+ /*
+ * how many spaces as the indent of line
+ */
+ private int m_nIndent;
+
+ /*
+ * whether a NEW LINE character need to be appended to
+ * each line
+ */
+ private boolean m_bIsFormatted;
+
+ /*
+ * the output stream to write
+ */
+ private FileOutputStream m_fileOutputStream;
+
+ SAXEventPrinter(FileOutputStream fileOutputStream, boolean isFormatted)
+ {
+ m_nIndent = 0;
+ m_fileOutputStream = fileOutputStream;
+ m_bIsFormatted = isFormatted;
+ }
+
+ protected static void outputIndent(int m_nIndent, FileOutputStream fileOutputStream)
+ throws IOException
+ {
+ for (int i=0; i<m_nIndent; ++i)
+ {
+ fileOutputStream.write(" ".getBytes());
+ }
+ }
+
+ /*
+ * displays the tree of a Node.
+ */
+ protected static void display(Node node, int indent, FileOutputStream fileOutputStream, boolean isFormatted)
+ throws IOException
+ {
+ if (node != null)
+ {
+ int type = node.getNodeType();
+ String message;
+ NodeList children;
+ int i, length;
+
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE:
+ children = node.getChildNodes();
+ length = children.getLength();
+ for (i=0; i<length; ++i)
+ {
+ display(children.item(i), indent+2, fileOutputStream, isFormatted);
+ }
+
+ break;
+
+ case Node.ELEMENT_NODE:
+ message = new String("<"+node.getNodeName());
+ NamedNodeMap attrs = node.getAttributes();
+
+ length = attrs.getLength();
+ for (i=0; i<length; ++i)
+ {
+ Attr attr = (Attr)attrs.item(i);
+ message += " "+attr.getNodeName()+"=\""+attr.getNodeValue()+"\"";
+ }
+
+ message += ">";
+
+ if (isFormatted)
+ {
+ outputIndent(indent, fileOutputStream);
+ }
+
+ fileOutputStream.write(message.getBytes("UTF-8"));
+
+ if (isFormatted)
+ {
+ fileOutputStream.write("\n".getBytes());
+ }
+
+ children = node.getChildNodes();
+ length = children.getLength();
+ for (i=0; i<length; ++i)
+ {
+ display(children.item(i), indent+2, fileOutputStream, isFormatted);
+ }
+
+ if (isFormatted)
+ {
+ outputIndent(indent, fileOutputStream);
+ }
+
+ fileOutputStream.write("</".getBytes());
+ fileOutputStream.write(node.getNodeName().getBytes("UTF-8"));
+ fileOutputStream.write(">".getBytes());
+
+ if (isFormatted)
+ {
+ fileOutputStream.write("\n".getBytes());
+ }
+
+ break;
+
+ case Node.TEXT_NODE:
+ message = node.getNodeValue();
+ if (message != null )
+ {
+ if (isFormatted)
+ {
+ outputIndent(indent, fileOutputStream);
+ }
+
+ fileOutputStream.write(node.getNodeValue().getBytes("UTF-8"));
+
+ if (isFormatted)
+ {
+ fileOutputStream.write("\n".getBytes());
+ }
+ }
+ break;
+
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ if (isFormatted)
+ {
+ outputIndent(indent, fileOutputStream);
+ }
+
+ fileOutputStream.write("<?".getBytes());
+ fileOutputStream.write(node.getNodeName().getBytes("UTF-8"));
+ fileOutputStream.write(node.getNodeValue().getBytes("UTF-8"));
+ fileOutputStream.write("?>".getBytes());
+
+ if (isFormatted)
+ {
+ fileOutputStream.write("\n".getBytes());
+ }
+
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /*
+ * XDocumentHandler
+ */
+ public void startDocument ()
+ {
+ }
+
+ public void endDocument()
+ {
+ }
+
+ public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs)
+ {
+ try
+ {
+ String message;
+
+ message = new String("<"+str);
+ if (xattribs !=null)
+ {
+ int length = xattribs.getLength();
+ for (short i=0; i<length; ++i)
+ {
+ message += " "+xattribs.getNameByIndex(i)+"=\""+xattribs.getValueByIndex(i)+"\"";
+ }
+ }
+ message += ">";
+
+ if (m_bIsFormatted)
+ {
+ outputIndent(m_nIndent, m_fileOutputStream);
+ }
+
+ m_fileOutputStream.write(message.getBytes("UTF-8"));
+
+ if (m_bIsFormatted)
+ {
+ m_fileOutputStream.write("\n".getBytes());
+ }
+
+ m_nIndent += 2;
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void endElement(String str)
+ {
+ try
+ {
+ m_nIndent -= 2;
+ if (m_bIsFormatted)
+ {
+ outputIndent(m_nIndent, m_fileOutputStream);
+ }
+
+ m_fileOutputStream.write("</".getBytes());
+ m_fileOutputStream.write(str.getBytes("UTF-8"));
+ m_fileOutputStream.write(">".getBytes());
+
+ if (m_bIsFormatted)
+ {
+ m_fileOutputStream.write("\n".getBytes());
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void characters(String str)
+ {
+ try
+ {
+ if (m_bIsFormatted)
+ {
+ outputIndent(m_nIndent, m_fileOutputStream);
+ }
+
+ m_fileOutputStream.write(str.getBytes("UTF-8"));
+
+ if (m_bIsFormatted)
+ {
+ m_fileOutputStream.write("\n".getBytes());
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void ignorableWhitespace(String str)
+ {
+ }
+
+ public void processingInstruction(String aTarget, String aData)
+ {
+ try
+ {
+ if (m_bIsFormatted)
+ {
+ outputIndent(m_nIndent, m_fileOutputStream);
+ }
+
+ m_fileOutputStream.write("<?".getBytes());
+ m_fileOutputStream.write(aTarget.getBytes("UTF-8"));
+ m_fileOutputStream.write("?>".getBytes());
+
+ if (m_bIsFormatted)
+ {
+ m_fileOutputStream.write("\n".getBytes());
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator )
+ throws com.sun.star.xml.sax.SAXException
+ {
+ }
+}
diff --git a/xmlsecurity/tools/uno/SecurityEntity.java b/xmlsecurity/tools/uno/SecurityEntity.java
new file mode 100644
index 000000000000..85ef5ed49891
--- /dev/null
+++ b/xmlsecurity/tools/uno/SecurityEntity.java
@@ -0,0 +1,202 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+/* uno classes */
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.xml.crypto.*;
+import com.sun.star.xml.crypto.sax.*;
+
+/*
+ * this class maintains the data for a security operation.
+ */
+class SecurityEntity
+{
+ /*
+ * the security id, which identifies this security entity
+ * uniquely.
+ */
+ private static int m_nNextSecurityId = 1;
+ protected int m_nSecurityId;
+
+ /*
+ * xml security related components
+ */
+ protected XXMLSecurityContext m_xXMLSecurityContext;
+ protected XXMLSignature m_xXMLSignature;
+ protected XXMLEncryption m_xXMLEncryption;
+ protected XMultiComponentFactory m_xRemoteServiceManager;
+ protected XComponentContext m_xRemoteContext;
+ protected XReferenceResolvedListener m_xReferenceResolvedListener;
+ protected XSecuritySAXEventKeeper m_xSAXEventKeeper;
+
+ /*
+ * the uri of the key material of this security entity
+ */
+ private String m_keyURI;
+
+ SecurityEntity(
+ XSecuritySAXEventKeeper xSAXEventKeeper,
+ XXMLSecurityContext xXMLSecurityContext,
+ XXMLSignature xXMLSignature,
+ XXMLEncryption xXMLEncryption,
+ XMultiComponentFactory xRemoteServiceManager,
+ XComponentContext xRemoteContext)
+ {
+ m_xSAXEventKeeper = xSAXEventKeeper;
+ m_xXMLSecurityContext = xXMLSecurityContext;
+ m_xXMLSignature = xXMLSignature;
+ m_xXMLEncryption = xXMLEncryption;
+ m_xRemoteServiceManager = xRemoteServiceManager;
+ m_xRemoteContext = xRemoteContext;
+
+ m_nSecurityId = getNextSecurityId();
+ m_keyURI = null;
+ }
+
+/**************************************************************************************
+ * private methods
+ **************************************************************************************/
+
+ /*
+ * generates a new security id.
+ */
+ private static int getNextSecurityId()
+ {
+ int id = m_nNextSecurityId++;
+ return id;
+ }
+
+/**************************************************************************************
+ * protected methods
+ **************************************************************************************/
+
+ /*
+ * notifies the key collector about the key id, this key id
+ * is used to ask the SAXEventKeeper to release the bufferred
+ * key element.
+ * when the id is 0, that means there is no independant key
+ * element needed.
+ */
+ protected void setKeyId(int id)
+ {
+ try
+ {
+ XKeyCollector xKeyCollector =
+ (XKeyCollector)UnoRuntime.queryInterface(
+ XKeyCollector.class, m_xReferenceResolvedListener);
+ xKeyCollector.setKeyId(id);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * set the key uri, which will be the value of the id attribute
+ * of the key element
+ */
+ protected void setKeyURI(String uri)
+ {
+ m_keyURI = new String(uri);
+ }
+
+ protected XReferenceResolvedListener getReferenceListener()
+ {
+ return m_xReferenceResolvedListener;
+ }
+
+ protected int getSecurityId()
+ {
+ return m_nSecurityId;
+ }
+
+ /*
+ * configures the key material to the security entity.
+ *
+ * if the uri is the key, then:
+ * 1. askes the SAXEventKeeper to add a ElementCollector to the key
+ * element;
+ * 2. notifies the key collector;
+ * 3. configures this ElementCollector's security id;
+ * 4. tells the SAXEventKeeper which listener will receive the reference
+ * resolved notification.
+ */
+ protected boolean setKey(String uri, boolean isExporting)
+ {
+ boolean rc = false;
+
+ if (m_keyURI != null &&
+ m_keyURI.equals(uri))
+ {
+ int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
+ isExporting?
+ (ElementMarkPriority.BEFOREMODIFY):(ElementMarkPriority.AFTERMODIFY),
+ false );
+
+ setKeyId(referenceId);
+ m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
+
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(referenceId, m_xReferenceResolvedListener);
+
+ rc = true;
+ }
+
+ return rc;
+ }
+
+ /*
+ * ends this misstion, asks the security engine to clear up all
+ * resources.
+ */
+ protected boolean endMission()
+ {
+ XMissionTaker xMissionTaker =
+ (XMissionTaker)UnoRuntime.queryInterface(
+ XMissionTaker.class, m_xReferenceResolvedListener);
+
+ boolean rc = xMissionTaker.endMission();
+
+ m_xXMLSecurityContext = null;
+ m_xXMLSignature = null;
+ m_xXMLEncryption = null;
+ m_xReferenceResolvedListener = null;
+ m_xSAXEventKeeper = null;
+
+ return rc;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/SignatureEntity.java b/xmlsecurity/tools/uno/SignatureEntity.java
new file mode 100644
index 000000000000..d02ad3ee74d7
--- /dev/null
+++ b/xmlsecurity/tools/uno/SignatureEntity.java
@@ -0,0 +1,288 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import java.util.Vector;
+
+/* uno classes */
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.xml.crypto.*;
+import com.sun.star.xml.crypto.sax.*;
+
+/*
+ * this class maintains the data for a signature operation.
+ */
+class SignatureEntity extends SecurityEntity
+{
+ private Vector m_vReferenceIds;
+ private int m_nSignatureElementCollectorId;
+
+ SignatureEntity(
+ XSecuritySAXEventKeeper xSAXEventKeeper,
+ boolean isExporting,
+ Object resultListener,
+ XXMLSecurityContext xXMLSecurityContext,
+ XXMLSignature xXMLSignature,
+ XXMLEncryption xXMLEncryption,
+ XMultiComponentFactory xRemoteServiceManager,
+ XComponentContext xRemoteContext)
+ {
+ super(xSAXEventKeeper, xXMLSecurityContext, xXMLSignature,
+ xXMLEncryption, xRemoteServiceManager, xRemoteContext);
+
+ m_vReferenceIds = new Vector();
+
+ if (isExporting)
+ {
+ m_nSignatureElementCollectorId = m_xSAXEventKeeper.addSecurityElementCollector(
+ ElementMarkPriority.AFTERMODIFY,
+ true);
+
+ m_xSAXEventKeeper.setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId);
+
+ try
+ {
+ /*
+ * creates a SignatureCreator.
+ */
+ Object signatureCreator = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.SIGNATURECREATOR_COMPONENT, m_xRemoteContext);
+
+ m_xReferenceResolvedListener =
+ (XReferenceResolvedListener)UnoRuntime.queryInterface(
+ XReferenceResolvedListener.class, signatureCreator);
+
+ /*
+ * initializes the SignatureCreator.
+ */
+ XInitialization xInitialization =
+ (XInitialization)UnoRuntime.queryInterface(
+ XInitialization.class, m_xReferenceResolvedListener);
+
+ Object args[]=new Object[5];
+ args[0] = new Integer(m_nSecurityId).toString();
+ args[1] = m_xSAXEventKeeper;
+ args[2] = new Integer(m_nSignatureElementCollectorId).toString();
+ args[3] = m_xXMLSecurityContext.getSecurityEnvironment();
+ args[4] = m_xXMLSignature;
+ xInitialization.initialize(args);
+
+ /*
+ * creates a Blocker.
+ */
+ int blockerId = m_xSAXEventKeeper.addBlocker();
+ m_xSAXEventKeeper.setSecurityId(blockerId, m_nSecurityId);
+
+ XBlockerMonitor xBlockerMonitor = (XBlockerMonitor)UnoRuntime.queryInterface(
+ XBlockerMonitor.class, m_xReferenceResolvedListener);
+ xBlockerMonitor.setBlockerId(blockerId);
+
+ /*
+ * sets signature creation result listener.
+ */
+ XSignatureCreationResultBroadcaster xSignatureCreationResultBroadcaster =
+ (XSignatureCreationResultBroadcaster)UnoRuntime.queryInterface(
+ XSignatureCreationResultBroadcaster.class, m_xReferenceResolvedListener);
+ xSignatureCreationResultBroadcaster.addSignatureCreationResultListener(
+ (XSignatureCreationResultListener)UnoRuntime.queryInterface(
+ XSignatureCreationResultListener.class, resultListener));
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+ else
+ {
+ m_nSignatureElementCollectorId = m_xSAXEventKeeper.addSecurityElementCollector(
+ ElementMarkPriority.BEFOREMODIFY, false);
+
+ m_xSAXEventKeeper.setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId);
+
+ try
+ {
+ /*
+ * creates a SignatureVerifier.
+ */
+ Object signatureVerifier = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.SIGNATUREVERIFIER_COMPONENT, m_xRemoteContext);
+
+ m_xReferenceResolvedListener =
+ (XReferenceResolvedListener)UnoRuntime.queryInterface(
+ XReferenceResolvedListener.class, signatureVerifier);
+
+ /*
+ * initializes the SignatureVerifier.
+ */
+ XInitialization xInitialization =
+ (XInitialization)UnoRuntime.queryInterface(
+ XInitialization.class, m_xReferenceResolvedListener);
+ Object args[]=new Object[5];
+ args[0] = new Integer(m_nSecurityId).toString();
+ args[1] = m_xSAXEventKeeper;
+ args[2] = new Integer(m_nSignatureElementCollectorId).toString();
+ args[3] = m_xXMLSecurityContext;
+ args[4] = m_xXMLSignature;
+ xInitialization.initialize(args);
+
+ /*
+ * sets signature verify result listener.
+ */
+ XSignatureVerifyResultBroadcaster xSignatureVerifyResultBroadcaster =
+ (XSignatureVerifyResultBroadcaster)UnoRuntime.queryInterface(
+ XSignatureVerifyResultBroadcaster.class, m_xReferenceResolvedListener);
+ xSignatureVerifyResultBroadcaster.addSignatureVerifyResultListener(
+ (XSignatureVerifyResultListener)UnoRuntime.queryInterface(
+ XSignatureVerifyResultListener.class, resultListener));
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * configures the resolve listener for the signature template.
+ */
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(
+ m_nSignatureElementCollectorId, m_xReferenceResolvedListener);
+ }
+
+/**************************************************************************************
+ * private methods
+ **************************************************************************************/
+
+ /*
+ * checks whether this signature has a reference with
+ * the particular id.
+ */
+ private boolean hasReference(String id)
+ {
+ boolean rc = false;
+
+ int length = m_vReferenceIds.size();
+ for (int i=0; i<length; ++i)
+ {
+ if (id.equals((String)m_vReferenceIds.elementAt(i)))
+ {
+ rc = true;
+ break;
+ }
+ }
+
+ return rc;
+ }
+
+
+/**************************************************************************************
+ * protected methods
+ **************************************************************************************/
+
+ /*
+ * adds a new reference id.
+ */
+ protected void addReferenceId(String referenceId)
+ {
+ m_vReferenceIds.add(referenceId);
+ }
+
+ /*
+ * notifies how many reference in this signature.
+ */
+ protected void setReferenceNumber()
+ {
+ try
+ {
+ XReferenceCollector xReferenceCollector =
+ (XReferenceCollector)UnoRuntime.queryInterface(
+ XReferenceCollector.class, m_xReferenceResolvedListener);
+ xReferenceCollector.setReferenceCount(m_vReferenceIds.size());
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * tries to add a reference to this signature.
+ *
+ * If the specific id belongs to this signature's references, then:
+ * 1. askes the SAXEventKeeper to add a ElementCollector to for the new
+ * referenced element;
+ * 2. configures this ElementCollector's security id;
+ * 3. tells the SAXEventKeeper which listener will receive the reference
+ * resolved notification.
+ * 4. notifies the SignatureCollector about the reference id.
+ */
+ protected boolean setReference(String id, boolean isExporting)
+ {
+ boolean rc = false;
+
+ if (hasReference(id))
+ {
+ int referenceId = m_xSAXEventKeeper.addSecurityElementCollector(
+ isExporting?
+ (ElementMarkPriority.AFTERMODIFY):(ElementMarkPriority.BEFOREMODIFY),
+ false );
+
+ m_xSAXEventKeeper.setSecurityId(referenceId, m_nSecurityId);
+
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(
+ referenceId, m_xReferenceResolvedListener);
+
+ try
+ {
+ XReferenceCollector xReferenceCollector =
+ (XReferenceCollector)UnoRuntime.queryInterface(
+ XReferenceCollector.class, m_xReferenceResolvedListener);
+ xReferenceCollector.setReferenceId(referenceId);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ rc = true;
+ }
+
+ return rc;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/TestTool.java b/xmlsecurity/tools/uno/TestTool.java
new file mode 100644
index 000000000000..6c87b34bbb43
--- /dev/null
+++ b/xmlsecurity/tools/uno/TestTool.java
@@ -0,0 +1,1392 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/* Basic GUI components */
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JFileChooser;
+import javax.swing.ToolTipManager;
+import javax.swing.JTable;
+import javax.swing.JLabel;
+import javax.swing.BorderFactory;
+
+/* GUI components for right-hand side */
+import javax.swing.JSplitPane;
+import javax.swing.JOptionPane;
+import javax.swing.JTabbedPane;
+
+
+/* GUI support classes */
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Container;
+import java.awt.Toolkit;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/* For creating borders */
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.CompoundBorder;
+
+/* For creating a TreeModel */
+import javax.swing.tree.TreePath;
+import java.util.Vector;
+
+/* UNO classes */
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.xml.sax.XDocumentHandler;
+
+import com.sun.star.xml.crypto.*;
+import com.sun.star.xml.crypto.sax.*;
+
+public class TestTool extends JFrame implements ActionListener
+{
+ /*
+ * xml security framewrok component names
+ */
+ public static String SIGNATURECREATOR_COMPONENT = "com.sun.star.xml.crypto.sax.SignatureCreator";
+ public static String SIGNATUREVERIFIER_COMPONENT = "com.sun.star.xml.crypto.sax.SignatureVerifier";
+ public static String ENCRYPTOR_COMPONENT = "com.sun.star.xml.crypto.sax.Encryptor";
+ public static String DECRYPTOR_COMPONENT = "com.sun.star.xml.crypto.sax.Decryptor";
+ public static String SAXEVENTKEEPER_COMPONENT = "com.sun.star.xml.crypto.sax.SAXEventKeeper";
+
+ /*
+ * Java-based component names
+ */
+ public static String SEINITIALIZER_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.SEInitializer_JxsecImpl";
+ public static String XMLSIGNATURE_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLSignature_JxsecImpl";
+ public static String XMLENCRYPTION_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLEncryption_JxsecImpl";
+ public static String XMLDOCUMENTWRAPPER_COMPONENT_JAVA = "com.sun.star.xml.security.bridge.jxsec.XMLDocumentWrapper_JxsecImpl";
+
+ /*
+ * C-based component names
+ */
+ public static String SEINITIALIZER_COMPONENT_C = "com.sun.star.xml.crypto.SEInitializer";
+ public static String XMLSIGNATURE_COMPONENT_C = "com.sun.star.xml.crypto.XMLSignature";
+ public static String XMLENCRYPTION_COMPONENT_C = "com.sun.star.xml.crypto.XMLEncryption";
+ public static String XMLDOCUMENTWRAPPER_COMPONENT_C = "com.sun.star.xml.wrapper.XMLDocumentWrapper";
+
+ /* url resolver name */
+ public static String UNOURLRESOLVER = "com.sun.star.bridge.UnoUrlResolver";
+
+ /*
+ * connection URL
+ */
+ private String m_unoURL = "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager";
+
+ /* key file */
+ private String m_javaTokenFile = null;
+ private String m_nssTokenPath = null;
+
+ /* User Interfaces */
+ private JButton m_goButton;
+ private JButton m_stepButton;
+ private JButton m_startButton;
+ private JButton m_openButton;
+ private JCheckBox m_isExportingButton;
+ private JCheckBox m_isJavaComponentButton;
+ private JButton m_saveButton;
+ private JButton m_batchButton;
+ private JTree m_leftTree;
+ private JTextArea m_leftTextArea;
+ private JTree m_middleTree;
+ private JTree m_rightTree;
+ private JTabbedPane m_leftTabPane;
+ private JTextArea m_bufferNodeTextArea;
+ private JLabel m_saxChainLabel;
+ private JTextField m_saxEventText;
+ private JTable m_unsolvedReferenceTable;
+
+ /*
+ * whether a batch file is running,
+ * if so, no message box is popped up
+ */
+ private boolean m_bIsBatchRunning = false;
+
+ /*
+ * whether the UI needs to be updated.
+ * when user click the "go" button, the UI needs
+ * not to be updated step by step for performance
+ * reason
+ */
+ private boolean m_bIsUIUpdateSuppressed = false;
+
+ /*
+ * three DOM tree adapter
+ */
+ private DomToTreeModelAdapter m_leftTreeModelAdapter;
+ private DomToTreeModelAdapter m_middleTreeModelAdapter;
+ private DomToTreeModelAdapter m_rightTreeModelAdapter;
+
+ /*
+ * the current directory, which reserves the default
+ * location when user open/save a file.
+ */
+ private File m_currentDirectory = null;
+
+ /*
+ * the log file
+ */
+ private FileOutputStream m_logFileOutputStream = null;
+
+ /*
+ * the thread which is parsing the current XML
+ * file
+ */
+ private ParsingThread m_parsingThread;
+
+ /*
+ * whether is exporting or importing
+ */
+ private boolean m_bIsExporting;
+
+ /*
+ * whether java based component or c based component
+ * is used now
+ */
+ private boolean m_bIsJavaBased;
+
+ /*
+ * XML security component interface
+ */
+ private XComponentContext m_xRemoteContext = null;
+ private XMultiComponentFactory m_xRemoteServiceManager = null;
+ private XXMLSecurityContext m_xXMLSecurityContext = null;
+ private XXMLSignature m_xXMLSignature = null;
+ private XXMLEncryption m_xXMLEncryption = null;
+ private XSEInitializer m_xSEInitializer = null;
+
+ /*
+ * SAX event collector for the middle tree and the right tree
+ */
+ private SAXEventCollector m_rightTreeEventCollector = null;
+ private SAXEventCollector m_middleTreeEventCollector = null;
+
+ /*
+ * security framework controller
+ */
+ private XMLSecurityFrameworkController m_xmlSecurityFrameworkController = null;
+
+ /* org.w3c.dom.Document */
+ private Document m_document;
+
+ /* represents whether "Go" or "Step" */
+ private boolean stepMode = true;
+
+/**************************************************************************************
+ * private methods
+ **************************************************************************************/
+
+
+ /******************************************************************************
+ * UI related methods
+ ******************************************************************************/
+
+ /*
+ * initalizes the UI.
+ */
+ private void initUI()
+ {
+ m_leftTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+ m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+ m_rightTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+
+ m_parsingThread = null;
+
+ m_leftTree.setModel(m_leftTreeModelAdapter);
+ m_middleTree.setModel(m_middleTreeModelAdapter);
+ m_rightTree.setModel(m_rightTreeModelAdapter);
+ }
+
+ /*
+ * constructs the user interface.
+ */
+ private Container buildUI(int width, int height)
+ {
+ JPanel mainPanel = new JPanel();
+
+ int frameHeight = height-40;
+ int leftWindowWidth = (width-40)/3;
+ int middleWindowWidth = leftWindowWidth;
+ int rightWindowWidth = leftWindowWidth;
+ int leftPaneWidth = leftWindowWidth+middleWindowWidth;
+ int frameWidth = leftPaneWidth + rightWindowWidth;
+
+ /* Make a nice border */
+ EmptyBorder emptyBorder = new EmptyBorder(5,5,5,5);
+ BevelBorder bevelBorder = new BevelBorder(BevelBorder.LOWERED);
+ CompoundBorder compoundBorder = new CompoundBorder(emptyBorder,bevelBorder);
+ mainPanel.setBorder(new CompoundBorder(compoundBorder,emptyBorder));
+
+ /* Set up the tree */
+ m_leftTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+ m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+ m_rightTreeModelAdapter = new DomToTreeModelAdapter(m_document);
+
+ m_leftTree = new JTree(m_leftTreeModelAdapter);
+ m_leftTextArea = new JTextArea();
+ m_middleTree = new JTree(m_middleTreeModelAdapter);
+ m_rightTree = new JTree(m_rightTreeModelAdapter);
+
+ ToolTipManager.sharedInstance().registerComponent(m_leftTree);
+ ToolTipManager.sharedInstance().registerComponent(m_middleTree);
+ ToolTipManager.sharedInstance().registerComponent(m_rightTree);
+
+ /* Builds left tab pane */
+ JScrollPane leftTreePane = new JScrollPane(m_leftTree);
+ JScrollPane leftTextPane = new JScrollPane(m_leftTextArea);
+ m_leftTabPane= new JTabbedPane();
+ m_leftTabPane.add("Tree View",leftTreePane);
+ m_leftTabPane.add("Text View",leftTextPane);
+
+ /* Builds middle tree pane */
+ JScrollPane middleTreePane = new JScrollPane(m_middleTree);
+
+ /* Builds right tree pane */
+ JScrollPane rightTreePane = new JScrollPane(m_rightTree);
+ rightTreePane.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createTitledBorder("Result"),
+ BorderFactory.createEmptyBorder(8,8,8,8)));
+
+ m_leftTabPane.setPreferredSize(
+ new Dimension( leftWindowWidth, frameHeight ));
+ middleTreePane.setPreferredSize(
+ new Dimension( middleWindowWidth, frameHeight ));
+ rightTreePane.setPreferredSize(
+ new Dimension( rightWindowWidth, frameHeight ));
+
+ /* Builds the SAX event text box */
+ m_saxEventText = new JTextField();
+
+ /* Builds the unsolved reference table */
+ m_unsolvedReferenceTable = new JTable(
+ new UnsolvedReferenceTableModel(this));
+
+ /* Builds the BufferNode information text area */
+ m_bufferNodeTextArea = new JTextArea();
+
+ /* Builds the SAX chain information label */
+ m_saxChainLabel = new JLabel();
+
+ /* Builds the left pane */
+ JPanel tabPaneWithSaxEventPane = new JPanel();
+ tabPaneWithSaxEventPane.setLayout(new BorderLayout());
+ tabPaneWithSaxEventPane.add("Center",m_leftTabPane);
+ tabPaneWithSaxEventPane.add("South",new JScrollPane(m_saxEventText));
+
+ JSplitPane leftPane =
+ new JSplitPane( JSplitPane.VERTICAL_SPLIT,
+ tabPaneWithSaxEventPane,
+ new JScrollPane(m_unsolvedReferenceTable));
+ leftPane.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createTitledBorder("Original"),
+ BorderFactory.createEmptyBorder(8,8,8,8)));
+
+ leftPane.setContinuousLayout( true );
+ leftPane.setDividerLocation( frameHeight*2/3 );
+ leftPane.setPreferredSize(
+ new Dimension( leftWindowWidth, frameHeight ));
+
+ /* Builds the middle pane */
+ JPanel bufferNodeWithSaxChainPane = new JPanel();
+ bufferNodeWithSaxChainPane.setLayout(new BorderLayout());
+ bufferNodeWithSaxChainPane.add("Center",m_bufferNodeTextArea);
+ bufferNodeWithSaxChainPane.add("South",new JScrollPane(m_saxChainLabel));
+
+ JSplitPane middlePane =
+ new JSplitPane( JSplitPane.VERTICAL_SPLIT,
+ middleTreePane,
+ new JScrollPane(bufferNodeWithSaxChainPane));
+
+ middlePane.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createTitledBorder("Insight SAXEventKeeper"),
+ BorderFactory.createEmptyBorder(8,8,8,8)));
+
+ middlePane.setContinuousLayout( true );
+ middlePane.setDividerLocation( frameHeight/2+5 );
+ middlePane.setPreferredSize(
+ new Dimension( middleWindowWidth, frameHeight ));
+
+ /* Builds the whole frame pane */
+ JSplitPane leftWithMiddlePane =
+ new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
+ leftPane,
+ middlePane );
+ leftWithMiddlePane.setContinuousLayout( true );
+ leftWithMiddlePane.setDividerLocation( leftWindowWidth );
+ leftWithMiddlePane.setPreferredSize(
+ new Dimension( leftPaneWidth + 10, frameHeight+10 ));
+
+ JSplitPane framePane =
+ new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
+ leftWithMiddlePane,
+ rightTreePane );
+
+
+ framePane.setContinuousLayout( true );
+ framePane.setDividerLocation(leftPaneWidth+10 );
+ framePane.setPreferredSize(
+ new Dimension( frameWidth + 20, frameHeight+10 ));
+
+ /* Adds all GUI components to the main panel */
+ mainPanel.setLayout(new BorderLayout());
+ mainPanel.add("Center", framePane );
+
+ m_openButton = new JButton("Open...");
+ m_openButton.addActionListener(this);
+
+ m_goButton = new JButton("Go!");
+ m_goButton.addActionListener(this);
+
+ m_stepButton = new JButton("Step");
+ m_stepButton.addActionListener(this);
+
+ m_startButton = new JButton("Start");
+ m_startButton.addActionListener(this);
+ m_startButton.setEnabled(false);
+
+ m_isExportingButton = new JCheckBox("export, not import", true);
+ m_isJavaComponentButton = new JCheckBox("use java component", false);
+
+ m_saveButton = new JButton("Save...");
+ m_saveButton.addActionListener(this);
+
+ m_batchButton = new JButton("Batch...");
+ m_batchButton.addActionListener(this);
+
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.add(m_batchButton);
+ buttonPanel.add(m_openButton);
+ buttonPanel.add(m_startButton);
+ buttonPanel.add(m_goButton);
+ buttonPanel.add(m_stepButton);
+ buttonPanel.add(m_isExportingButton);
+ buttonPanel.add(m_isJavaComponentButton);
+ buttonPanel.add(m_saveButton);
+
+ mainPanel.add("South", buttonPanel);
+
+ enableGoButton(false);
+
+ return mainPanel;
+ }
+
+ /*
+ * enables/disables the Go(and Step) button.
+ */
+ private void enableGoButton(boolean enabled)
+ {
+ m_goButton.setEnabled(enabled);
+ m_stepButton.setEnabled(enabled);
+ }
+
+ /*
+ * updates the unsolved reference information.
+ */
+ private void updatesUnsolvedReferencesInformation()
+ {
+ m_unsolvedReferenceTable.setModel(new UnsolvedReferenceTableModel(this));
+ }
+
+ /*
+ * adjusts the view of the tree in order to make the
+ * particular Node into the focus tree leaf.
+ */
+ private void updatesTree(Node node, JTree tree)
+ {
+ int i=0;
+ int currentLine = 0;
+
+ while (i<tree.getRowCount())
+ {
+ TreePath treePath = tree.getPathForRow(i);
+ tree.expandPath(treePath);
+
+ AdapterNode adapterNode = (AdapterNode)treePath.getLastPathComponent();
+
+ if (node == adapterNode.getNode())
+ {
+ tree.addSelectionPath(treePath);
+ currentLine = i;
+ }
+
+ ++i;
+ }
+
+ tree.setCellRenderer(new XMLTreeCellRanderer(node));
+ tree.scrollRowToVisible(currentLine);
+ }
+
+ /******************************************************************************
+ * action listener related methods.
+ ******************************************************************************/
+
+ /*
+ * reads in a document, either the document is a file or
+ * is a text paragraph.
+ */
+ private void openDocument()
+ {
+ if (m_leftTabPane.getSelectedIndex() == 0)
+ {
+ File f = openFile();
+ if (f != null)
+ {
+ parseFile(f);
+ }
+ }
+ else
+ {
+ String text = m_leftTextArea.getText();
+
+ try
+ {
+ parseStream(new ByteArrayInputStream(text.getBytes("UTF-8")));
+ }
+ catch(UnsupportedEncodingException e)
+ {
+ e.printStackTrace();
+ }
+
+ m_leftTabPane.setSelectedIndex(0);
+ }
+ }
+
+ /*
+ * save the result tree to a file.
+ */
+ private void saveResult()
+ {
+ saveFile();
+ }
+
+ /*
+ * selects a batch file to excute.
+ */
+ private void openBatch()
+ {
+ File f = openFile();
+ if (f != null)
+ {
+ runBatch(f);
+ }
+ }
+
+ /*
+ * makes the current operation to an end.
+ */
+ private void endMission()
+ {
+ enableGoButton(false);
+ m_parsingThread = null;
+
+ if (m_xmlSecurityFrameworkController != null)
+ {
+ m_xmlSecurityFrameworkController.endMission();
+ }
+
+ updatesUIs();
+
+ m_xmlSecurityFrameworkController = null;
+ freeComponents();
+
+ System.gc();
+ }
+
+
+ /******************************************************************************
+ * UNO component related methods
+ ******************************************************************************/
+
+ /*
+ * connects the SO server.
+ */
+ private void connectSO(String unoUrlString)
+ {
+ if (unoUrlString != null)
+ {
+ m_unoURL = new String(unoUrlString);
+ }
+
+ try
+ {
+ m_xRemoteServiceManager = getRemoteServiceManager(m_unoURL);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * creates UNO components.
+ */
+ private boolean createComponents()
+ {
+ try
+ {
+ String SEInitializer_comp;
+ String XMLSignature_comp;
+ String XMLEncryption_comp;
+ String tokenPath;
+
+ if (m_bIsJavaBased)
+ {
+ SEInitializer_comp = SEINITIALIZER_COMPONENT_JAVA;
+ XMLSignature_comp = XMLSIGNATURE_COMPONENT_JAVA;
+ XMLEncryption_comp = XMLENCRYPTION_COMPONENT_JAVA;
+ tokenPath = m_javaTokenFile;
+ }
+ else
+ {
+ SEInitializer_comp = SEINITIALIZER_COMPONENT_C;
+ XMLSignature_comp = XMLSIGNATURE_COMPONENT_C;
+ XMLEncryption_comp = XMLENCRYPTION_COMPONENT_C;
+ tokenPath = m_nssTokenPath;
+ }
+
+ Object seInitializerObj = m_xRemoteServiceManager.createInstanceWithContext(
+ SEInitializer_comp, m_xRemoteContext);
+
+ if (seInitializerObj == null)
+ {
+ freeComponents();
+ return false;
+ }
+
+ m_xSEInitializer = (XSEInitializer)UnoRuntime.queryInterface(
+ XSEInitializer.class, seInitializerObj);
+
+ m_xXMLSecurityContext = m_xSEInitializer.createSecurityContext(tokenPath);
+
+ Object xmlSignatureObj = m_xRemoteServiceManager.createInstanceWithContext(
+ XMLSignature_comp, m_xRemoteContext);
+
+ if (xmlSignatureObj == null)
+ {
+ freeComponents();
+ return false;
+ }
+
+ m_xXMLSignature = (XXMLSignature)UnoRuntime.queryInterface(
+ XXMLSignature.class, xmlSignatureObj);
+
+ Object xmlEncryptionObj = m_xRemoteServiceManager.createInstanceWithContext(
+ XMLEncryption_comp, m_xRemoteContext);
+
+ if (xmlEncryptionObj == null)
+ {
+ freeComponents();
+ return false;
+ }
+
+ m_xXMLEncryption = (XXMLEncryption)UnoRuntime.queryInterface(
+ XXMLEncryption.class, xmlEncryptionObj);
+
+ return true;
+ }
+ catch(Exception e)
+ {
+ freeComponents();
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /*
+ * frees UNO components.
+ */
+ private void freeComponents()
+ {
+ try
+ {
+ if (m_xXMLSecurityContext != null)
+ {
+ m_xSEInitializer.freeSecurityContext(m_xXMLSecurityContext);
+ m_xXMLSecurityContext = null;
+ }
+
+ m_xXMLSignature = null;
+ m_xXMLEncryption = null;
+ m_xSEInitializer = null;
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * getRemoteServiceManager
+ */
+ private XMultiComponentFactory getRemoteServiceManager(String unoUrl) throws java.lang.Exception
+ {
+ if (m_xRemoteContext == null)
+ {
+ /*
+ * First step: create local component context, get local servicemanager and
+ * ask it to create a UnoUrlResolver object with an XUnoUrlResolver interface
+ */
+ XComponentContext xLocalContext =
+ com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
+ XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
+ Object urlResolver = xLocalServiceManager.createInstanceWithContext(
+ UNOURLRESOLVER, xLocalContext );
+ /*
+ * query XUnoUrlResolver interface from urlResolver object
+ */
+ XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
+ XUnoUrlResolver.class, urlResolver );
+
+ /*
+ * Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
+ * retrieve its property DefaultContext and get the remote servicemanager
+ */
+ Object initialObject = xUnoUrlResolver.resolve( unoUrl );
+ XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, initialObject);
+ Object context = xPropertySet.getPropertyValue("DefaultContext");
+ m_xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(
+ XComponentContext.class, context);
+ }
+ return m_xRemoteContext.getServiceManager();
+ }
+
+
+ /******************************************************************************
+ * XML related methods
+ ******************************************************************************/
+
+ /*
+ * removes all empty text node inside the particular element
+ */
+ private void removeEmptyText(Node node)
+ {
+ int type = node.getNodeType();
+ NodeList children;
+ int i;
+
+ switch (type)
+ {
+ case Node.DOCUMENT_NODE:
+ case Node.ELEMENT_NODE:
+ Node child = node.getFirstChild();
+ while (child!= null)
+ {
+ Node nextSibling = child.getNextSibling();
+ int childType = child.getNodeType();
+
+ if (childType==Node.TEXT_NODE)
+ {
+ String message = child.getNodeValue().trim();
+ if (message == null || message.length()<=0)
+ {
+ node.removeChild(child);
+ }
+ }
+ else if (childType == Node.ELEMENT_NODE)
+ {
+ removeEmptyText(child);
+ }
+
+ child = nextSibling;
+ }
+ break;
+ }
+ }
+
+ /*
+ * reads a stream, and parses it into the original tree.
+ */
+ private void parseStream(InputStream is)
+ {
+ try
+ {
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ m_document = null;
+ m_startButton.setEnabled(false);
+ initUI();
+
+ /* factory.setValidating(true); */
+ /* factory.setNamespaceAware(true); */
+
+ try
+ {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ m_document = builder.parse(is);
+ m_startButton.setEnabled(true);
+ initUI();
+ }
+ catch (ParserConfigurationException pce)
+ {
+ pce.printStackTrace();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+ catch(Exception exce)
+ {
+ System.out.println("input stream Exception");
+ }
+ }
+
+
+ /******************************************************************************
+ * file operation related methods
+ ******************************************************************************/
+
+ /*
+ * opens a file, and parses it into the original tree.
+ */
+ private void parseFile(File name)
+ {
+ try
+ {
+ FileInputStream fis = new FileInputStream(name);
+ parseStream(fis);
+ fis.close();
+ }
+ catch(Exception exce)
+ {
+ System.out.println("open file Exception");
+ }
+ }
+
+
+ /*
+ * selects a file to open
+ */
+ private File openFile()
+ {
+ File rc = null;
+
+ JFileChooser fileChooser= new JFileChooser();
+
+ fileChooser.setDialogTitle("Select File To Open");
+ fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
+
+ fileChooser.setApproveButtonText("Ok");
+
+ if (m_currentDirectory == null)
+ {
+ fileChooser.rescanCurrentDirectory();
+ }
+ else
+ {
+ fileChooser.setCurrentDirectory(m_currentDirectory);
+ }
+
+ fileChooser.setFileFilter(new XMLFileFilter());
+
+ int result = fileChooser.showDialog(this,null);
+ if (result==fileChooser.APPROVE_OPTION)
+ {
+ m_currentDirectory = fileChooser.getCurrentDirectory();
+ rc = fileChooser.getSelectedFile();
+ }
+
+ return rc;
+ }
+
+ private void saveFile()
+ {
+ JFileChooser fileChooser= new JFileChooser();
+
+ fileChooser.setDialogTitle("Select File To Save");
+ fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+
+ fileChooser.setApproveButtonText("Ok");
+
+ if (m_currentDirectory == null)
+ {
+ fileChooser.rescanCurrentDirectory();
+ }
+ else
+ {
+ fileChooser.setCurrentDirectory(m_currentDirectory);
+ }
+
+ fileChooser.setFileFilter(new XMLFileFilter());
+
+ int result = fileChooser.showDialog(this,null);
+ if (result==fileChooser.APPROVE_OPTION)
+ {
+ try
+ {
+ m_currentDirectory = fileChooser.getCurrentDirectory();
+ saveFile(fileChooser.getSelectedFile());
+ }
+ catch(Exception exce)
+ {
+ System.out.println("save file Exception");
+ exce.printStackTrace();
+ }
+ }
+ }
+
+ /*
+ * excutes a batch file.
+ */
+ private void runBatch(File f)
+ {
+ FileInputStream fis = null;
+
+ try
+ {
+ fis = new FileInputStream(f);
+ StringBuffer commandBuffer = new StringBuffer();
+
+ m_logFileOutputStream = new FileOutputStream("TestTool-log.txt");
+ m_bIsBatchRunning = true;
+ int ch = 0;
+
+ while (ch != -1)
+ {
+ ch = fis.read();
+
+ if (ch != 0x0a && ch != -1)
+ {
+ if (ch != 0x0d)
+ {
+ commandBuffer.append((char)ch);
+ }
+ }
+ else
+ {
+ String command = new String(commandBuffer);
+ if (command.startsWith("Open "))
+ {
+ m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
+ String fileName = command.substring(5);
+ parseFile(new File(fileName));
+ m_logFileOutputStream.write("command end \n\n".getBytes());
+ }
+ else if (command.startsWith("Use Java Component"))
+ {
+ m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
+ m_isJavaComponentButton.setSelected(true);
+ m_logFileOutputStream.write("command end \n\n".getBytes());
+ }
+ else if (command.startsWith("Use C++ Component"))
+ {
+ m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
+ m_isJavaComponentButton.setSelected(false);
+ m_logFileOutputStream.write("command end \n\n".getBytes());
+ }
+ else if (command.startsWith("Go "))
+ {
+ m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
+ String opera = command.substring(3);
+ if (opera.equals("Sign") || opera.equals("Encrypt"))
+ {
+ m_isExportingButton.setSelected(true);
+ }
+ else
+ {
+ m_isExportingButton.setSelected(false);
+ }
+
+ startsUp();
+ if (m_parsingThread != null)
+ {
+ m_bIsUIUpdateSuppressed = true;
+ try{
+ while (m_parsingThread.nextStep());
+ endMission();
+ }
+ catch(Exception e)
+ {
+ System.out.println("exception happen during batch:"+e);
+ e.printStackTrace();
+ }
+
+ m_bIsUIUpdateSuppressed = false;
+ updatesUIs();
+ }
+ m_logFileOutputStream.write("command end \n\n".getBytes());
+ }
+ else if (command.startsWith("Save "))
+ {
+ m_logFileOutputStream.write(("start \""+command+"\" ...\n").getBytes());
+ String fileName = command.substring(5);
+ saveFile(new File(fileName));
+ m_logFileOutputStream.write("command end \n\n".getBytes());
+ }
+
+ commandBuffer = new StringBuffer();
+ }
+ }
+
+ m_bIsBatchRunning = false;
+ m_logFileOutputStream.close();
+ m_logFileOutputStream = null;
+
+ fis.close();
+ fis = null;
+ }
+ catch(java.io.IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * save the current result tree to a particular file.
+ */
+ private void saveFile(File f)
+ {
+ try{
+ FileOutputStream fos = new FileOutputStream(f);
+ SAXEventPrinter.display((Document)m_rightTreeEventCollector.getDocument(),
+ 0,fos,false);
+ fos.close();
+ }catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /******************************************************************************
+ * others
+ ******************************************************************************/
+
+ /*
+ * starts up the operation.
+ */
+ private void startsUp()
+ {
+ if (m_parsingThread != null)
+ {
+ m_parsingThread = null;
+ }
+
+ m_bIsExporting = m_isExportingButton.isSelected();
+ m_bIsJavaBased = m_isJavaComponentButton.isSelected();
+
+ if (createComponents())
+ {
+ m_rightTreeEventCollector = new SAXEventCollector(this);
+
+ m_parsingThread = new ParsingThread(
+ m_document,
+ null,
+ this);
+
+ m_xmlSecurityFrameworkController =
+ new XMLSecurityFrameworkController(
+ this,
+ m_bIsExporting,
+ m_bIsJavaBased,
+ m_rightTreeEventCollector,
+ m_parsingThread,
+ m_xXMLSecurityContext,
+ m_xXMLSignature,
+ m_xXMLEncryption,
+ m_xRemoteServiceManager,
+ m_xRemoteContext);
+
+ enableGoButton(true);
+ }
+ else
+ {
+ showMessage("Error in creating XML Security Components!");
+ }
+ }
+
+/**************************************************************************************
+ * protected methods
+ **************************************************************************************/
+
+ /******************************************************************************
+ * UI related methods
+ ******************************************************************************/
+
+ /*
+ * updates the sax chain information.
+ */
+ protected void updatesSAXChainInformation(String chainStr)
+ {
+ m_saxChainLabel.setText(chainStr);
+ }
+
+ /*
+ * update the current SAX event information.
+ */
+ protected void updatesCurrentSAXEventInformation(String event)
+ {
+ m_saxEventText.setText(event);
+ }
+
+ /*
+ * updates all information in the UI.
+ */
+ protected void updatesUIs()
+ {
+ if (!m_bIsUIUpdateSuppressed)
+ {
+ m_leftTree.clearSelection();
+ updatesTree(null, m_leftTree);
+
+ if (m_xmlSecurityFrameworkController != null)
+ {
+ String bufferNodeTreeText = m_xmlSecurityFrameworkController.getBufferNodeTreeInformation();
+ if (bufferNodeTreeText == null)
+ {
+ m_middleTree.setVisible(false);
+ m_bufferNodeTextArea.setText("No XML Security Related");
+ }
+ else
+ {
+ m_middleTreeEventCollector = new SAXEventCollector(null);
+ m_xmlSecurityFrameworkController.getDocument(m_middleTreeEventCollector);
+
+ m_middleTreeModelAdapter = new DomToTreeModelAdapter(m_middleTreeEventCollector.getDocument());
+ m_middleTree.setModel(m_middleTreeModelAdapter);
+ updatesTree(null, m_middleTree);
+ m_middleTree.setVisible(true);
+ m_bufferNodeTextArea.setText(bufferNodeTreeText);
+ }
+ }
+ else
+ {
+ m_middleTree.setVisible(false);
+ m_bufferNodeTextArea.setText("No XMLImporter/XMLExporter");
+ }
+
+ if (m_rightTreeEventCollector != null)
+ {
+ m_rightTreeModelAdapter = new DomToTreeModelAdapter((Document)m_rightTreeEventCollector.getDocument());
+ m_rightTree.setModel(m_rightTreeModelAdapter);
+ updatesTree((Node)m_rightTreeEventCollector.getCurrentElement(), m_rightTree);
+ }
+
+ updatesUnsolvedReferencesInformation();
+ }
+ }
+
+ /*
+ * shows a message.
+ */
+ protected void showMessage(String msg)
+ {
+ if (m_bIsBatchRunning)
+ {
+ try
+ {
+ if (!msg.startsWith("Message from : SAXEventKeeper"))
+ {
+ byte [] b = msg.getBytes();
+ m_logFileOutputStream.write(" ".getBytes());
+
+ for (int i=0; i<b.length; ++i)
+ {
+ m_logFileOutputStream.write(b[i]);
+ if (b[i] == '\n')
+ {
+ m_logFileOutputStream.write(" ".getBytes());
+ }
+ }
+ m_logFileOutputStream.write("\n ==============================\n".getBytes());
+ }
+ }
+ catch(IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ if (stepMode)
+ {
+ JOptionPane optionPane = new JOptionPane();
+ optionPane.showMessageDialog(this, msg, "TestTool Notification", JOptionPane.INFORMATION_MESSAGE);
+ }
+ else
+ {
+ Object[] options = { "OK", "Go back to step mode" };
+ if (1 == JOptionPane.showOptionDialog(this, msg, "TestTool Notification",
+ JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
+ null, options, options[0]))
+ {
+ stepMode = true;
+ }
+ }
+ }
+ }
+
+
+ /******************************************************************************
+ * information retrieving
+ ******************************************************************************/
+
+ /*
+ * gets all unsolved reference ids.
+ * a reference id is the value of the id attribute of an
+ * referenced element.
+ */
+ protected Vector getUnsolvedReferenceIds()
+ {
+ Vector rc;
+
+ if (m_xmlSecurityFrameworkController == null)
+ {
+ rc = new Vector();
+ }
+ else
+ {
+ rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
+ getUnsolvedReferenceIds();
+ }
+
+ return rc;
+ }
+
+ /*
+ * gets all unsolved reference keeper ids.
+ * a reference keeper id is the id which the SAXEventKeeper uses
+ * to identify the corresponding BufferNode.
+ */
+ protected Vector getUnsolvedReferenceKeeperIds()
+ {
+ Vector rc;
+
+ if (m_xmlSecurityFrameworkController == null)
+ {
+ rc = new Vector();
+ }
+ else
+ {
+ rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
+ getUnsolvedReferenceKeeperIds();
+ }
+
+ return rc;
+ }
+
+ /*
+ * gets all unsolved references' remaining numbers.
+ * a remaining number is that how many claims have not been found for
+ * a unsolved reference.
+ */
+ protected Vector getUnsolvedReferenceRefNum()
+ {
+ Vector rc;
+
+ if (m_xmlSecurityFrameworkController == null)
+ {
+ rc = new Vector();
+ }
+ else
+ {
+ rc = ((XMLSecurityFrameworkController)m_xmlSecurityFrameworkController).
+ getUnsolvedReferenceRefNum();
+ }
+
+ return rc;
+ }
+
+
+/**************************************************************************************
+ * public methods
+ **************************************************************************************/
+
+ /******************************************************************************
+ * action listener related methods.
+ ******************************************************************************/
+
+ /*
+ * action listening method.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource().equals(m_startButton))
+ {
+ endMission();
+ startsUp();
+ }
+ if (e.getSource().equals(m_goButton))
+ {
+ if (m_parsingThread != null)
+ {
+ stepMode = false;
+ boolean notOver;
+ while ( notOver = m_parsingThread.nextStep())
+ {
+ if (stepMode) break;
+ }
+
+ if (!notOver) endMission();
+ }
+ }
+ if (e.getSource().equals(m_stepButton))
+ {
+ if (m_parsingThread != null)
+ {
+ if (!m_parsingThread.nextStep())
+ {
+ endMission();
+ }
+ }
+ }
+ if (e.getSource().equals(m_openButton))
+ {
+ openDocument();
+ }
+ if (e.getSource().equals(m_saveButton))
+ {
+ saveResult();
+ }
+ if (e.getSource().equals(m_batchButton))
+ {
+ openBatch();
+ }
+ }
+
+ /*
+ * void-consturctor method
+ */
+ public TestTool()
+ {
+ getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
+
+ try
+ {
+ m_currentDirectory = new File(System.getProperty("user.dir"));
+ }
+ catch(Exception e)
+ {
+ System.out.println("getProperty error :"+e);
+ }
+ }
+
+ /*
+ * consturctor method with a specific connection URL
+ */
+ public TestTool(String connecturl)
+ {
+ this();
+ m_unoURL = new String(connecturl);
+ }
+
+ public static void main(String argv[])
+ {
+ Dimension screenSize =
+ Toolkit.getDefaultToolkit().getScreenSize();
+
+ TestTool tt;
+
+ if (argv.length < 1)
+ {
+ System.out.println("Usage: java TestTool [javaTokenFile] [nssTokenPath] [xml file]?");
+ return;
+ }
+
+ boolean hasFile = false;
+ boolean hasBatch = false;
+ String fileName = null;
+
+ if (argv.length >= 3)
+ {
+ if (argv[2].startsWith("-b"))
+ {
+ fileName = argv[2].substring(2);
+ hasBatch = true;
+ }
+ else
+ {
+ fileName = argv[2];
+ hasFile = true;
+ }
+ }
+
+ tt = new TestTool();
+ tt.m_javaTokenFile = new String(argv[0]);
+ tt.m_nssTokenPath = new String(argv[1]);
+ tt.connectSO(null);
+
+ /* Set up a GUI framework */
+ JFrame myFrame = new JFrame("XML Security Components Tester");
+ myFrame.addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {System.exit(0);}
+ }
+ );
+
+ myFrame.setContentPane(tt.buildUI(screenSize.width, screenSize.height));
+ myFrame.pack();
+ int w = screenSize.width-30;
+ int h = screenSize.height-30;
+ myFrame.setLocation(screenSize.width/2 - w/2,
+ screenSize.height/2 - h/2);
+ myFrame.setSize(w, h);
+ myFrame.setVisible(true);
+
+ if (hasFile)
+ {
+ tt.parseFile(new File(fileName));
+ }
+ else if (hasBatch)
+ {
+ tt.runBatch(new File(fileName));
+ }
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/UnsolvedReferenceTableModel.java b/xmlsecurity/tools/uno/UnsolvedReferenceTableModel.java
new file mode 100644
index 000000000000..21f17de8877d
--- /dev/null
+++ b/xmlsecurity/tools/uno/UnsolvedReferenceTableModel.java
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import javax.swing.table.AbstractTableModel;
+
+/*
+ * this class is used to maintain the unsolved reference
+ * table.
+ */
+class UnsolvedReferenceTableModel extends AbstractTableModel
+{
+ private String[] m_columnNames = {"id",
+ "refNum",
+ "EC's id"};
+
+ private TestTool m_testTool;
+
+ UnsolvedReferenceTableModel(TestTool testTool)
+ {
+ m_testTool = testTool;
+ }
+
+ public String getColumnName(int col)
+ {
+ return m_columnNames[col].toString();
+ }
+
+ public int getRowCount()
+ {
+ return m_testTool.getUnsolvedReferenceIds().size();
+ }
+
+ public int getColumnCount()
+ {
+ return m_columnNames.length;
+ }
+
+ public Object getValueAt(int row, int col)
+ {
+ if (col == 0)
+ {
+ return (String)m_testTool.getUnsolvedReferenceIds().elementAt(row);
+ }
+ else if (col == 1)
+ {
+ return ((Integer)m_testTool.getUnsolvedReferenceRefNum().elementAt(row)).toString();
+ }
+ else if (col == 2)
+ {
+ return ((Integer)m_testTool.getUnsolvedReferenceKeeperIds().elementAt(row)).toString();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public boolean isCellEditable(int row, int col)
+ {
+ return false;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/XMLFileFilter.java b/xmlsecurity/tools/uno/XMLFileFilter.java
new file mode 100644
index 000000000000..b9436cacfbda
--- /dev/null
+++ b/xmlsecurity/tools/uno/XMLFileFilter.java
@@ -0,0 +1,79 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import java.io.File;
+import javax.swing.filechooser.FileFilter;
+
+/*
+ * this class is used as a file filter for the XML file
+ * (*.xml) and the batch file (*.txt).
+ */
+class XMLFileFilter extends FileFilter
+{
+ public static String getExtension(File f)
+ {
+ String ext = null;
+ String s = f.getName();
+ int i = s.lastIndexOf('.');
+
+ if (i > 0 && i < s.length() - 1) {
+ ext = s.substring(i+1).toLowerCase();
+ }
+
+ return ext;
+ }
+
+ public boolean accept(File f)
+ {
+ boolean rc = false;
+
+ if (f.isDirectory())
+ {
+ rc = true;
+ }
+ else
+ {
+ String extension = getExtension(f);
+ if (extension != null)
+ {
+ if (extension.equals("xml") || extension.equals("txt"))
+ {
+ rc = true;
+ }
+ }
+ }
+
+ return rc;
+ }
+
+ public String getDescription()
+ {
+ return "XML and batch files (.xml,.txt)";
+ }
+}
diff --git a/xmlsecurity/tools/uno/XMLSecurityFrameworkController.java b/xmlsecurity/tools/uno/XMLSecurityFrameworkController.java
new file mode 100644
index 000000000000..058981b460b0
--- /dev/null
+++ b/xmlsecurity/tools/uno/XMLSecurityFrameworkController.java
@@ -0,0 +1,1085 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import java.util.Stack;
+import java.util.Vector;
+
+/* uno classes */
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.xml.sax.XDocumentHandler;
+import com.sun.star.xml.sax.XAttributeList;
+import com.sun.star.xml.sax.SAXException;
+
+import com.sun.star.xml.crypto.*;
+import com.sun.star.xml.crypto.sax.*;
+import com.sun.star.xml.wrapper.*;
+
+/*
+ * the XMLSecurityFrameworkController class is used to controll the xml security framework.
+ */
+public class XMLSecurityFrameworkController
+ implements XDocumentHandler, XSignatureCreationResultListener, XSignatureVerifyResultListener,
+ XEncryptionResultListener, XDecryptionResultListener, XSAXEventKeeperStatusChangeListener
+{
+ /*
+ * UNO framework component
+ */
+ private XMultiComponentFactory m_xRemoteServiceManager;
+ private XComponentContext m_xRemoteContext;
+
+ /*
+ * xml security related UNO components
+ */
+ private XSecuritySAXEventKeeper m_xSAXEventKeeper;
+ private XXMLDocumentWrapper m_xXMLDocumentWrapper;
+ private XDocumentHandler m_xOutputHandler;
+ private XXMLSecurityContext m_xXMLSecurityContext;
+ private XXMLSignature m_xXMLSignature;
+ private XXMLEncryption m_xXMLEncryption;
+
+ /*
+ * used to reserve the current SAX ancestor path
+ */
+ private Stack m_currentPath;
+
+ /*
+ * maintains all SignatureEntities.
+ */
+ private Vector m_signatureList;
+
+ /*
+ * maintains all EncryptionEntities.
+ */
+ private Vector m_encryptionList;
+
+ /*
+ * maintains all unsolved reference Ids.
+ * These ids are strings which is the value of the id attribute
+ * of the referenced element.
+ */
+ private Vector m_vUnsolvedReferenceIds;
+
+ /*
+ * maintains all unsolved reference keeper ids.
+ * The keeper id is used to uniquely identify a bufferred element
+ * by the SAXEventKeeper.
+ */
+ private Vector m_vUnsolvedReferencedKeeperIds;
+
+ /*
+ * maintains the left time that each unsolved reference can be
+ * claimed.
+ */
+ private Vector m_vUnsolvedReferenceRefNum;
+
+ /*
+ * whether exporting or importing
+ */
+ private boolean m_bIsExporting;
+
+ /*
+ * whether java or c
+ */
+ private boolean m_bIsJavaBased;
+
+ /*
+ * whether the SAXEventKeeper is blocking
+ */
+ private boolean m_bIsBlocking;
+
+ /*
+ * whether it is collecting a bufferred element
+ */
+ private boolean m_bIsInsideCollectedElement;
+
+ /*
+ * whether a SAXEventKeeper is in the SAX chain
+ */
+ private boolean m_bSAXEventKeeperIncluded;
+
+ /*
+ * the ParsingThread used to parse the document
+ */
+ private ParsingThread m_parsingThread;
+
+ /*
+ * the next document handler that will receives SAX events
+ * from the parsing thread.
+ * if the SAXEventKeeper is on the SAX chain, then this
+ * variable will be the SAXEventKeeper, otherwise, this
+ * variable will be the xOutputHandler.
+ */
+ private XDocumentHandler m_xExportHandler;
+
+ /*
+ * the TestTool used to feedback information
+ */
+ private TestTool m_testTool;
+
+ /*
+ * for encryption target
+ */
+ private boolean m_bIsEncryptionTarget;
+ private EncryptionEntity m_EncryptionForTarget;
+
+ XMLSecurityFrameworkController(
+ TestTool testTool,
+ boolean bIsExporting,
+ boolean bIsJavaBased,
+ XDocumentHandler xOutputHandler,
+ ParsingThread parsingThread,
+ XXMLSecurityContext xXMLSecurityContext,
+ XXMLSignature xXMLSignature,
+ XXMLEncryption xXMLEncryption,
+ XMultiComponentFactory xRemoteServiceManager,
+ XComponentContext xRemoteContext)
+ {
+ m_bIsExporting = bIsExporting;
+ m_bIsJavaBased = bIsJavaBased;
+
+ m_xOutputHandler = xOutputHandler;
+ m_xXMLSecurityContext = xXMLSecurityContext;
+ m_xXMLSignature = xXMLSignature;
+ m_xXMLEncryption = xXMLEncryption;
+ m_xRemoteServiceManager = xRemoteServiceManager;
+ m_xRemoteContext = xRemoteContext;
+
+ m_testTool = testTool;
+ m_parsingThread = parsingThread;
+
+ m_signatureList = new Vector();
+ m_encryptionList = new Vector();
+
+ m_vUnsolvedReferenceIds = new Vector();
+ m_vUnsolvedReferencedKeeperIds = new Vector();
+ m_vUnsolvedReferenceRefNum = new Vector();
+
+ m_xXMLDocumentWrapper = null;
+ m_xSAXEventKeeper = null;
+
+ m_bSAXEventKeeperIncluded = false;
+ m_bIsBlocking = false;
+ m_bIsInsideCollectedElement = false;
+
+ m_bIsEncryptionTarget = false;
+ m_EncryptionForTarget = null;
+
+ changeOutput();
+
+ m_currentPath = new Stack();
+
+ foundSecurityRelated();
+ }
+
+/**************************************************************************************
+ * private methods
+ **************************************************************************************/
+
+ /*
+ * changes the output document handler.
+ */
+ private void changeOutput()
+ {
+ if (m_bIsExporting)
+ {
+ m_parsingThread.setHandler(this);
+
+ /*
+ * If the SAXEventKeeper is in the SAX chain, then redirects output
+ * to the SAXEventKeeper, otherwise, to the m_xOutputHandler
+ */
+ if (m_bSAXEventKeeperIncluded)
+ {
+ m_xExportHandler = (XDocumentHandler)UnoRuntime.queryInterface(
+ XDocumentHandler.class, m_xSAXEventKeeper);
+ m_xSAXEventKeeper.setNextHandler(m_xOutputHandler);
+
+ m_testTool.updatesSAXChainInformation("XMLExporter -> SAXEventKeeper -> SAXWriter");
+ }
+ else
+ {
+ m_xExportHandler = m_xOutputHandler;
+ m_testTool.updatesSAXChainInformation("XMLExporter -> SAXWriter");
+ }
+ }
+ else
+ {
+ if (m_bSAXEventKeeperIncluded)
+ {
+ m_parsingThread.setHandler(
+ (XDocumentHandler)UnoRuntime.queryInterface(XDocumentHandler.class, m_xSAXEventKeeper));
+ m_xSAXEventKeeper.setNextHandler(this);
+ m_testTool.updatesSAXChainInformation("SAXParser -> SAXEventKeeper -> XMLImporter");
+ }
+ else
+ {
+ m_parsingThread.setHandler(this);
+ m_testTool.updatesSAXChainInformation("SAXParser -> XMLImporter");
+ }
+ m_xExportHandler = m_xOutputHandler;
+ }
+ }
+
+ /*
+ * handles the situation when a security related element is found.
+ * if the SAXEventKeeper is not initialized, then creates a
+ * SAXEventKeeper.
+ * the return value represents whether the SAXEventKeeper is newly
+ * created.
+ */
+ private boolean foundSecurityRelated()
+ {
+ if (m_xSAXEventKeeper == null)
+ {
+ m_testTool.showMessage("Message from : "+
+ (m_bIsExporting?"XMLExporter":"XMLImporter")+
+ "\n\nA security related content found, a SAXEventKeeper is created.\n ");
+
+ m_bIsBlocking = false;
+ m_bIsInsideCollectedElement = false;
+
+ try
+ {
+ /*
+ * creates an XMLDocumentWrapper component.
+ */
+ Object xmlDocumentObj = null;
+
+ if (m_bIsJavaBased)
+ {
+ xmlDocumentObj = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.XMLDOCUMENTWRAPPER_COMPONENT_JAVA, m_xRemoteContext);
+ }
+ else
+ {
+ xmlDocumentObj = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.XMLDOCUMENTWRAPPER_COMPONENT_C, m_xRemoteContext);
+ }
+
+ m_xXMLDocumentWrapper = (XXMLDocumentWrapper)UnoRuntime.queryInterface(
+ XXMLDocumentWrapper.class, xmlDocumentObj);
+
+ /*
+ * creates a SAXEventKeeper component.
+ */
+ Object saxEventKeeperObj = m_xRemoteServiceManager.createInstanceWithContext(
+ TestTool.SAXEVENTKEEPER_COMPONENT, m_xRemoteContext);
+
+ m_xSAXEventKeeper =
+ (XSecuritySAXEventKeeper)UnoRuntime.queryInterface(
+ XSecuritySAXEventKeeper.class, saxEventKeeperObj);
+
+ /*
+ * initializes the SAXEventKeeper component with the XMLDocumentWrapper component.
+ */
+ XInitialization xInitialization =
+ (XInitialization)UnoRuntime.queryInterface(
+ XInitialization.class, m_xSAXEventKeeper);
+ Object args[]=new Object[1];
+ args[0] = m_xXMLDocumentWrapper;
+ xInitialization.initialize(args);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ /*
+ * configures the SAXEventKeeper's status change listener.
+ */
+ XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster =
+ (XSAXEventKeeperStatusChangeBroadcaster)UnoRuntime.queryInterface(
+ XSAXEventKeeperStatusChangeBroadcaster.class, m_xSAXEventKeeper);
+ xSaxEventKeeperStatusChangeBroadcaster.addSAXEventKeeperStatusChangeListener(this);
+ }
+
+ boolean rc = !m_bSAXEventKeeperIncluded;
+
+ /*
+ * changes the export document handler.
+ */
+ m_bSAXEventKeeperIncluded=true;
+ changeOutput();
+
+ return rc;
+ }
+
+ /*
+ * finds key element or referenced element for a signature.
+ */
+ private void findKeyOrReference(SecurityEntity signatureEntity, String uriStr, boolean isFindingKey)
+ {
+ int i=0;
+
+ while (i<m_vUnsolvedReferenceIds.size())
+ {
+ String id = (String)m_vUnsolvedReferenceIds.elementAt(i);
+
+ if (id.equals(uriStr))
+ {
+ int refNum = ((Integer)m_vUnsolvedReferenceRefNum.elementAt(i)).intValue();
+ int keeperId = ((Integer)m_vUnsolvedReferencedKeeperIds.elementAt(i)).intValue();
+
+ if (isFindingKey)
+ {
+ /*
+ * clones a new ElementCollector for the key element.
+ */
+ int cloneKeeperId = m_xSAXEventKeeper.cloneElementCollector(
+ keeperId,
+ m_bIsExporting?
+ (ElementMarkPriority.BEFOREMODIFY):(ElementMarkPriority.AFTERMODIFY));
+
+ /*
+ * notifies the key keeper id.
+ */
+ signatureEntity.setKeyId(cloneKeeperId);
+
+ /*
+ * sets the security id for the key.
+ */
+ m_xSAXEventKeeper.setSecurityId(cloneKeeperId, signatureEntity.getSecurityId());
+
+ /*
+ * sets the resolve listener.
+ */
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(
+ cloneKeeperId,
+ signatureEntity.getReferenceListener());
+ }
+ else
+ {
+ /*
+ * clones a new ElementCollector for the referenced element.
+ */
+ int cloneKeeperId = m_xSAXEventKeeper.cloneElementCollector(
+ keeperId,
+ m_bIsExporting?
+ (ElementMarkPriority.AFTERMODIFY):(ElementMarkPriority.BEFOREMODIFY));
+
+ /*
+ * sets the security id.
+ */
+ m_xSAXEventKeeper.setSecurityId(cloneKeeperId, signatureEntity.getSecurityId());
+
+ /*
+ * sets the resolve listener.
+ */
+ XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster =
+ (XReferenceResolvedBroadcaster)UnoRuntime.queryInterface(
+ XReferenceResolvedBroadcaster.class, m_xSAXEventKeeper);
+ xReferenceResolvedBroadcaster.addReferenceResolvedListener(cloneKeeperId,
+ signatureEntity.getReferenceListener());
+
+ try{
+ XReferenceCollector xReferenceCollector =
+ (XReferenceCollector)UnoRuntime.queryInterface(
+ XReferenceCollector.class, signatureEntity.getReferenceListener());
+ xReferenceCollector.setReferenceId(cloneKeeperId);
+ }
+ catch( com.sun.star.uno.Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * if this unsolved reference reaches its max reference number, remove this reference
+ * from all vectors.
+ */
+ refNum--;
+ if (refNum == 0)
+ {
+ m_xSAXEventKeeper.removeElementCollector(keeperId);
+ m_vUnsolvedReferenceIds.remove(i);
+ m_vUnsolvedReferencedKeeperIds.remove(i);
+ m_vUnsolvedReferenceRefNum.remove(i);
+ }
+ else
+ {
+ m_vUnsolvedReferenceRefNum.setElementAt(new Integer(refNum),(i));
+ ++i;
+ }
+
+ /*
+ * If it is find a key, then no further search is needed, one
+ * signature has one key at most.
+ */
+ if (isFindingKey)
+ {
+ break;
+ }
+ }
+ else
+ {
+ ++i;
+ }
+ }
+ }
+
+ /*
+ * checks whether a startElement event represents any security related information.
+ * return true if this event can't be forwarded into the SAX chain.
+ */
+ private boolean checkSecurityElement(String localName, com.sun.star.xml.sax.XAttributeList xattribs)
+ {
+ boolean rc = false;
+
+ if (localName.equals("Signature"))
+ /*
+ * this element is a Signature element.
+ */
+ {
+ SignatureEntity signatureEntity = new SignatureEntity(
+ m_xSAXEventKeeper,
+ m_bIsExporting,
+ this,
+ m_xXMLSecurityContext,
+ m_xXMLSignature,
+ m_xXMLEncryption,
+ m_xRemoteServiceManager,
+ m_xRemoteContext);
+
+ m_signatureList.add(signatureEntity);
+ m_currentPath.push(signatureEntity);
+ }
+ else if(localName.equals("Reference"))
+ {
+ if (!m_currentPath.empty())
+ {
+ Object signedInfo = m_currentPath.pop();
+
+ if (!m_currentPath.empty())
+ {
+ Object objSignature = m_currentPath.peek();
+
+ if ((objSignature instanceof SignatureEntity) && signedInfo.toString().equals("SignedInfo"))
+ /*
+ * this element is a Reference element in a signature.
+ */
+ {
+ String uriStr = xattribs.getValueByName("URI");
+
+ if (uriStr.charAt(0) == '#')
+ {
+ uriStr = uriStr.substring(1);
+ SignatureEntity signatureEntity = (SignatureEntity)objSignature;
+
+ if (uriStr != null && uriStr.length()>0)
+ {
+ signatureEntity.addReferenceId(uriStr);
+ findKeyOrReference(signatureEntity, uriStr, false);
+ }
+ }
+ }
+ }
+ m_currentPath.push(signedInfo);
+ }
+ m_currentPath.push(localName);
+ }
+ else if(localName.equals("KeyValue") ||
+ localName.equals("KeyName") ||
+ localName.equals("X509Data") ||
+ localName.equals("EncryptedKey"))
+ {
+ if (!m_currentPath.empty())
+ {
+ Object keyInfo = m_currentPath.pop();
+
+ if (!m_currentPath.empty())
+ {
+ Object objSorE = m_currentPath.peek();
+
+ if ((objSorE instanceof SignatureEntity) && keyInfo.toString().equals("KeyInfo"))
+ /*
+ * this element is the key element of a signature.
+ */
+ {
+ SignatureEntity signatureEntity = (SignatureEntity)objSorE;
+ signatureEntity.setKeyId(0);
+ }
+ else if ((objSorE instanceof EncryptionEntity) && keyInfo.toString().equals("KeyInfo"))
+ /*
+ * this element is the key element of an encryption.
+ */
+ {
+ EncryptionEntity theEncryption = (EncryptionEntity)objSorE;
+ theEncryption.setKeyId(0);
+ }
+ }
+ m_currentPath.push(keyInfo);
+ }
+
+ m_currentPath.push(localName);
+ }
+ else if(localName.equals("RetrievalMethod"))
+ {
+ if (!m_currentPath.empty())
+ {
+ Object keyInfo = m_currentPath.pop();
+
+ if (!m_currentPath.empty())
+ {
+ Object objSorE = m_currentPath.peek();
+
+ if ((objSorE instanceof SignatureEntity) && keyInfo.toString().equals("KeyInfo"))
+ /*
+ * this element is the RetrievalMethod element in a signature,
+ * which will include the key uri of this signature.
+ */
+ {
+ String uriStr = xattribs.getValueByName("URI");
+ SignatureEntity signatureEntity = (SignatureEntity)objSorE;
+
+ if (uriStr != null && uriStr.length()>0)
+ {
+ signatureEntity.setKeyURI(uriStr);
+ findKeyOrReference(signatureEntity,uriStr, true);
+ }
+ }
+ else if ((objSorE instanceof EncryptionEntity) && keyInfo.toString().equals("KeyInfo"))
+ /*
+ * this element is the RetrievalMethod element in an encryption,
+ * which will include the key uri of this encryption.
+ */
+ {
+ String uriStr = xattribs.getValueByName("URI");
+ EncryptionEntity theEncryption = (EncryptionEntity)objSorE;
+
+ if (uriStr != null && uriStr.length()>0)
+ {
+ theEncryption.setKeyURI(uriStr);
+ findKeyOrReference(theEncryption, uriStr, true);
+ }
+ }
+ }
+ m_currentPath.push(keyInfo);
+ }
+ m_currentPath.push(localName);
+ }
+ else if (localName.equals("EncryptedData")) /* || localName.equals("EncryptedKey")) */
+ /*
+ * this element is an Encryption element.
+ */
+ {
+ EncryptionEntity theEncryption = new EncryptionEntity(
+ m_xSAXEventKeeper,
+ m_bIsExporting,
+ this,
+ m_xXMLSecurityContext,
+ m_xXMLSignature,
+ m_xXMLEncryption,
+ m_xRemoteServiceManager,
+ m_xRemoteContext);
+
+ m_encryptionList.add(theEncryption);
+
+ if (m_bIsExporting)
+ {
+ m_currentPath.push(theEncryption);
+ }
+ else
+ {
+ String uriStr = xattribs.getValueByName("keyURI");
+ if (uriStr != null && uriStr.length()>0)
+ {
+ theEncryption.setKeyURI(uriStr);
+ findKeyOrReference(theEncryption,uriStr, true);
+ }
+ else
+ {
+ theEncryption.setKeyId(0);
+ }
+
+ rc = true;
+ }
+ }
+ else
+ /*
+ * not a security related element.
+ */
+ {
+ m_currentPath.push(localName);
+ }
+
+ return rc;
+ }
+
+ /*
+ * checks whether a startElement event is referenced by any security entity.
+ */
+ private void checkReference(String localName, com.sun.star.xml.sax.XAttributeList xattribs, String id)
+ {
+ String refNumStr = xattribs.getValueByName("refNum");
+
+ if ( m_bIsEncryptionTarget )
+ {
+ m_EncryptionForTarget.setReference(m_bIsExporting);
+ m_bIsEncryptionTarget = false;
+ }
+
+ if (id != null && id.length()>0 )
+ /*
+ * only if this element has id attribute, then it can be referenced by
+ * a security entity.
+ */
+ {
+ /*
+ * if this element has an "refNum" attribute, then the value will be
+ * the max referencing number on this element, otherwise, set the max
+ * referencing number to 999.
+ */
+ int refNum = 999;
+
+ if (refNumStr != null && refNumStr.length()>0 )
+ {
+ refNum = new Integer(refNumStr).intValue();
+ }
+
+ int length;
+
+ /*
+ * searches the signature list to check whether any sigture has
+ * reference on this element.
+ */
+ length = m_signatureList.size();
+ for (int i=0; i<length; ++i)
+ {
+ SignatureEntity signatureEntity = (SignatureEntity)m_signatureList.elementAt(i);
+
+ if (signatureEntity.setReference(id, m_bIsExporting))
+ {
+ refNum--;
+ }
+
+ if (signatureEntity.setKey(id, m_bIsExporting))
+ {
+ refNum--;
+ }
+ }
+
+ /*
+ * searches the encryption list for reference.
+ */
+ length = m_encryptionList.size();
+ for (int i=0; i<length; ++i)
+ {
+ EncryptionEntity theEncryption = (EncryptionEntity)m_encryptionList.elementAt(i);
+
+ if (theEncryption.setKey(id, m_bIsExporting))
+ {
+ refNum--;
+ }
+ }
+
+ /*
+ * if the max referencing number is not reached, then add this element
+ * into the unsolved reference list.
+ */
+ if (refNum>0)
+ {
+ int keeperId;
+
+ if (localName.equals("EncryptedKey"))
+ {
+ keeperId = m_xSAXEventKeeper.addSecurityElementCollector(
+ m_bIsExporting?
+ (ElementMarkPriority.BEFOREMODIFY):(ElementMarkPriority.AFTERMODIFY),
+ true);
+ }
+ else
+ {
+ keeperId = m_xSAXEventKeeper.addSecurityElementCollector(
+ m_bIsExporting?
+ (ElementMarkPriority.AFTERMODIFY):(ElementMarkPriority.BEFOREMODIFY),
+ false);
+ }
+
+ m_vUnsolvedReferenceIds.add(id);
+ m_vUnsolvedReferencedKeeperIds.add(new Integer(keeperId));
+ m_vUnsolvedReferenceRefNum.add(new Integer(refNum));
+ }
+ }
+ }
+
+ /*
+ * configures the output handler.
+ */
+ private void setOutputHandler(XDocumentHandler handler)
+ {
+ m_xOutputHandler = handler;
+ changeOutput();
+ }
+
+
+/**************************************************************************************
+ * protected methods
+ **************************************************************************************/
+
+ /*
+ * methods used to transfer unsolved reference information.
+ */
+ protected Vector getUnsolvedReferenceIds()
+ {
+ return m_vUnsolvedReferenceIds;
+ }
+
+ protected Vector getUnsolvedReferenceKeeperIds()
+ {
+ return m_vUnsolvedReferencedKeeperIds;
+ }
+
+ protected Vector getUnsolvedReferenceRefNum()
+ {
+ return m_vUnsolvedReferenceRefNum;
+ }
+
+ protected String getBufferNodeTreeInformation()
+ {
+ if (m_xSAXEventKeeper != null)
+ {
+ return m_xSAXEventKeeper.printBufferNodeTree();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected void getDocument(XDocumentHandler handler)
+ {
+ if (m_xXMLDocumentWrapper != null)
+ {
+ try
+ {
+ m_xXMLDocumentWrapper.getTree(handler);
+ }
+ catch(SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected void endMission()
+ {
+ while (m_signatureList.size()>0 || m_encryptionList.size()>0)
+ {
+ if (m_signatureList.size()>0)
+ {
+ SignatureEntity signatureEntity = (SignatureEntity)m_signatureList.elementAt(0);
+ m_signatureList.remove(0);
+ signatureEntity.endMission();
+ }
+ else if (m_encryptionList.size()>0)
+ {
+ EncryptionEntity theEncryption = (EncryptionEntity)m_encryptionList.elementAt(0);
+ m_encryptionList.remove(0);
+ theEncryption.endMission();
+ }
+ }
+
+ while (m_vUnsolvedReferenceIds.size()>0)
+ {
+ int keeperId = ((Integer)m_vUnsolvedReferencedKeeperIds.elementAt(0)).intValue();
+ m_xSAXEventKeeper.removeElementCollector(keeperId);
+ m_vUnsolvedReferenceIds.remove(0);
+ m_vUnsolvedReferencedKeeperIds.remove(0);
+ m_vUnsolvedReferenceRefNum.remove(0);
+ }
+
+ m_xSAXEventKeeper.setNextHandler(null);
+
+ XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster =
+ (XSAXEventKeeperStatusChangeBroadcaster)UnoRuntime.queryInterface(
+ XSAXEventKeeperStatusChangeBroadcaster.class, m_xSAXEventKeeper);
+ xSaxEventKeeperStatusChangeBroadcaster.addSAXEventKeeperStatusChangeListener(null);
+
+ m_xSAXEventKeeper = null;
+ m_xXMLDocumentWrapper = null;
+ m_xOutputHandler = null;
+ m_xXMLSecurityContext = null;
+ m_xXMLSignature = null;
+ m_xXMLEncryption = null;
+
+ m_xExportHandler = null;
+ m_parsingThread.setHandler(null);
+ }
+
+/**************************************************************************************
+ * public methods
+ **************************************************************************************/
+
+ /*
+ * XDocumentHandler
+ */
+ public void startDocument()
+ {
+ try{
+ m_xExportHandler.startDocument();
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void endDocument()
+ {
+ try{
+ m_xExportHandler.endDocument();
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs)
+ {
+ try{
+ String idAttr = xattribs.getValueByName("id");
+ if (idAttr == null)
+ {
+ idAttr = xattribs.getValueByName("Id");
+ }
+
+ boolean hasIdAttr = (idAttr != null && idAttr.length()>0 );
+ boolean needResend = false;
+
+ if (hasIdAttr ||
+ (str.equals("Signature")||str.equals("EncryptedData")))/* || str.equals("EncryptedKey"))) */
+ {
+ if (foundSecurityRelated() && !m_bIsExporting)
+ {
+ needResend = true;
+ }
+ }
+
+ boolean suppressToNext = checkSecurityElement(str, xattribs);
+
+ checkReference(str, xattribs, idAttr);
+
+ if (needResend)
+ {
+ m_xSAXEventKeeper.setNextHandler(null);
+
+ XDocumentHandler saxEventKeeperHandler =
+ (XDocumentHandler)UnoRuntime.queryInterface(
+ XDocumentHandler.class, m_xSAXEventKeeper);
+ saxEventKeeperHandler.startElement(str, xattribs);
+ m_xSAXEventKeeper.setNextHandler((XDocumentHandler)this);
+ }
+
+ if (!suppressToNext)
+ {
+ m_xExportHandler.startElement(str, xattribs);
+ }
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void endElement(String str)
+ {
+ if (!m_currentPath.empty())
+ {
+ Object obj = m_currentPath.pop();
+
+ if (obj.toString().equals("SignedInfo"))
+ {
+ if (!m_currentPath.empty())
+ {
+ Object objSignature = m_currentPath.peek();
+ if (objSignature != null && objSignature instanceof SignatureEntity)
+ {
+ ((SignatureEntity)objSignature).setReferenceNumber();
+ }
+ }
+ }
+ else if (obj instanceof EncryptionEntity)
+ {
+ m_bIsEncryptionTarget = true;
+ m_EncryptionForTarget = (EncryptionEntity)obj;
+
+ }
+ }
+
+ try{
+ m_xExportHandler.endElement(str);
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void characters(String str)
+ {
+ try{
+ m_xExportHandler.characters(str);
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void ignorableWhitespace(String str)
+ {
+ }
+
+ public void processingInstruction(String aTarget, String aData)
+ {
+ try{
+ m_xExportHandler.processingInstruction(aTarget, aData);
+ }
+ catch( com.sun.star.xml.sax.SAXException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator )
+ throws com.sun.star.xml.sax.SAXException
+ {
+ }
+
+
+ /*
+ * XSignatureCreationResultListener
+ */
+ public void signatureCreated(int securityId, SecurityOperationStatus creationResult)
+ {
+ String message = new String();
+ message += "A Signature is created:";
+ message += "\nSecurity Id = "+securityId;
+ message += "\nCreation result = "+((creationResult==SecurityOperationStatus.OPERATION_SUCCEEDED)?"Succeed":"Fail");
+
+ m_testTool.showMessage("Message from : SignatureCreator\n\n"+message+"\n ");
+ }
+
+ /*
+ * XSignatureVerifyResultListener
+ */
+ public void signatureVerified(int securityId, SecurityOperationStatus verifyResult)
+ {
+ String message = new String();
+ message += "A Signature is verified:";
+ message += "\nSecurity Id = "+securityId;
+ message += "\nVerify result = "+((verifyResult==SecurityOperationStatus.OPERATION_SUCCEEDED)?"Succeed":"Fail");
+
+ m_testTool.showMessage("Message from : SignatureVerifier\n\n"+message+"\n ");
+ }
+
+ /*
+ * XEncryptionResultListener
+ */
+ public void encrypted(int securityId, SecurityOperationStatus encryptionResult)
+ {
+ String message = new String();
+ message += "An EncryptedData is encrypted:";
+ message += "\nSecurity Id = "+securityId;
+ message += "\nEncrypt result = "+((encryptionResult==SecurityOperationStatus.OPERATION_SUCCEEDED)?"Succeed":"Fail");
+
+ m_testTool.showMessage("Message from : Encryptor\n\n"+message+"\n ");
+ }
+
+ /*
+ * XDecryptionResultListener methods
+ */
+ public void decrypted(int securityId, SecurityOperationStatus decryptionResult)
+ {
+ String message = new String();
+ message += "An EncryptedData is decrypted:";
+ message += "\nSecurity Id = "+securityId;
+ message += "\nDecrypt result = "+((decryptionResult==SecurityOperationStatus.OPERATION_SUCCEEDED)?"Succeed":"Fail");
+
+ m_testTool.showMessage("Message from : Decryptor\n\n"+message+"\n ");
+ }
+
+ /*
+ * XSAXEventKeeperStatusChangeListener methods
+ */
+ public void blockingStatusChanged(boolean isBlocking)
+ {
+ m_testTool.showMessage("Message from : SAXEventKeeper\n\n"+
+ (isBlocking?"The SAX event stream is blocked.":"The SAX event stream is unblocked.")+
+ "\n ");
+
+ this.m_bIsBlocking = isBlocking;
+ }
+
+ public void collectionStatusChanged(boolean isInsideCollectedElement)
+ {
+ m_testTool.showMessage("Message from : SAXEventKeeper\n\n"+
+ (isInsideCollectedElement?"Begin to buffer data ...":"End of data bufferring.")+
+ "\n ");
+
+ /*
+ this.m_bIsInsideCollectedElement = isInsideCollectedElement;
+
+ if ( !m_bIsInsideCollectedElement && !m_bIsBlocking)
+ {
+ m_bSAXEventKeeperIncluded = false;
+ }
+ else
+ {
+ m_bSAXEventKeeperIncluded = true;
+ }
+ changeOutput();
+ */
+ }
+
+ public void bufferStatusChanged(boolean isBufferEmpty)
+ {
+ m_testTool.showMessage("Message from : SAXEventKeeper\n\n"+
+ (isBufferEmpty?"All bufferred data are released, the SAXEventKeeper is destroyed.":"buffer data appears.")+
+ "\n ");
+ /*
+ if (isBufferEmpty)
+ {
+ m_xXMLDocumentWrapper = null;
+ m_xSAXEventKeeper = null;
+ m_bSAXEventKeeperIncluded = false;
+ changeOutput();
+ }
+ */
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/XMLTreeCellRanderer.java b/xmlsecurity/tools/uno/XMLTreeCellRanderer.java
new file mode 100644
index 000000000000..77891a239853
--- /dev/null
+++ b/xmlsecurity/tools/uno/XMLTreeCellRanderer.java
@@ -0,0 +1,85 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.xml.security.uno;
+
+import javax.swing.tree.DefaultTreeCellRenderer;
+import org.w3c.dom.Node;
+import javax.swing.ImageIcon;
+import java.awt.Component;
+import javax.swing.JTree;
+
+/*
+ * a TreeCellRender which can show a graph on the current
+ * tree node.
+ */
+class XMLTreeCellRanderer extends DefaultTreeCellRenderer
+{
+ /*
+ * the icon for the current Node
+ */
+ private ImageIcon m_currentIcon;
+
+ /*
+ * the current Node
+ */
+ private Node m_currentNode;
+
+ XMLTreeCellRanderer(Node currentNode)
+ {
+ m_currentNode = currentNode;
+ m_currentIcon = new ImageIcon("current.gif");
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ super.getTreeCellRendererComponent(
+ tree, value, sel,
+ expanded, leaf, row,
+ hasFocus);
+
+ if (((AdapterNode)value).getNode() == m_currentNode)
+ {
+ setIcon(m_currentIcon);
+ setToolTipText("This is the current element.");
+ }
+ else
+ {
+ setToolTipText(null); /* no tool tip */
+ }
+
+ return this;
+ }
+}
+
diff --git a/xmlsecurity/tools/uno/current.gif b/xmlsecurity/tools/uno/current.gif
new file mode 100644
index 000000000000..92b2a025f05e
--- /dev/null
+++ b/xmlsecurity/tools/uno/current.gif
Binary files differ
diff --git a/xmlsecurity/tools/uno/makefile.mk b/xmlsecurity/tools/uno/makefile.mk
new file mode 100644
index 000000000000..e919e44ea9ee
--- /dev/null
+++ b/xmlsecurity/tools/uno/makefile.mk
@@ -0,0 +1,48 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJNAME = xmlsecurity
+TARGET = xmlsecurity-uno
+PACKAGE = com$/sun$/star$/xml$/security$/uno
+PRJ = ..$/..
+
+USE_JAVAVER:=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+JARFILES = java_uno.jar jurt.jar unoil.jar ridl.jar juh.jar
+JAVAFILES := $(shell @ls *.java)
+JAVACLASSFILES= $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)
+
+# --- Targets ------------------------------------------------------
+
+
+.INCLUDE : target.mk
+