1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSecurityFrameworkController.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.xml
.security
.uno
;
33 import java
.util
.Stack
;
34 import java
.util
.Vector
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.lang
.XMultiComponentFactory
;
39 import com
.sun
.star
.lang
.XInitialization
;
40 import com
.sun
.star
.uno
.XComponentContext
;
41 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
42 import com
.sun
.star
.xml
.sax
.XAttributeList
;
43 import com
.sun
.star
.xml
.sax
.SAXException
;
45 import com
.sun
.star
.xml
.crypto
.*;
46 import com
.sun
.star
.xml
.crypto
.sax
.*;
47 import com
.sun
.star
.xml
.wrapper
.*;
50 * the XMLSecurityFrameworkController class is used to controll the xml security framework.
52 public class XMLSecurityFrameworkController
53 implements XDocumentHandler
, XSignatureCreationResultListener
, XSignatureVerifyResultListener
,
54 XEncryptionResultListener
, XDecryptionResultListener
, XSAXEventKeeperStatusChangeListener
57 * UNO framework component
59 private XMultiComponentFactory m_xRemoteServiceManager
;
60 private XComponentContext m_xRemoteContext
;
63 * xml security related UNO components
65 private XSecuritySAXEventKeeper m_xSAXEventKeeper
;
66 private XXMLDocumentWrapper m_xXMLDocumentWrapper
;
67 private XDocumentHandler m_xOutputHandler
;
68 private XXMLSecurityContext m_xXMLSecurityContext
;
69 private XXMLSignature m_xXMLSignature
;
70 private XXMLEncryption m_xXMLEncryption
;
73 * used to reserve the current SAX ancestor path
75 private Stack m_currentPath
;
78 * maintains all SignatureEntities.
80 private Vector m_signatureList
;
83 * maintains all EncryptionEntities.
85 private Vector m_encryptionList
;
88 * maintains all unsolved reference Ids.
89 * These ids are strings which is the value of the id attribute
90 * of the referenced element.
92 private Vector m_vUnsolvedReferenceIds
;
95 * maintains all unsolved reference keeper ids.
96 * The keeper id is used to uniquely identify a bufferred element
97 * by the SAXEventKeeper.
99 private Vector m_vUnsolvedReferencedKeeperIds
;
102 * maintains the left time that each unsolved reference can be
105 private Vector m_vUnsolvedReferenceRefNum
;
108 * whether exporting or importing
110 private boolean m_bIsExporting
;
115 private boolean m_bIsJavaBased
;
118 * whether the SAXEventKeeper is blocking
120 private boolean m_bIsBlocking
;
123 * whether it is collecting a bufferred element
125 private boolean m_bIsInsideCollectedElement
;
128 * whether a SAXEventKeeper is in the SAX chain
130 private boolean m_bSAXEventKeeperIncluded
;
133 * the ParsingThread used to parse the document
135 private ParsingThread m_parsingThread
;
138 * the next document handler that will receives SAX events
139 * from the parsing thread.
140 * if the SAXEventKeeper is on the SAX chain, then this
141 * variable will be the SAXEventKeeper, otherwise, this
142 * variable will be the xOutputHandler.
144 private XDocumentHandler m_xExportHandler
;
147 * the TestTool used to feedback information
149 private TestTool m_testTool
;
152 * for encryption target
154 private boolean m_bIsEncryptionTarget
;
155 private EncryptionEntity m_EncryptionForTarget
;
157 XMLSecurityFrameworkController(
159 boolean bIsExporting
,
160 boolean bIsJavaBased
,
161 XDocumentHandler xOutputHandler
,
162 ParsingThread parsingThread
,
163 XXMLSecurityContext xXMLSecurityContext
,
164 XXMLSignature xXMLSignature
,
165 XXMLEncryption xXMLEncryption
,
166 XMultiComponentFactory xRemoteServiceManager
,
167 XComponentContext xRemoteContext
)
169 m_bIsExporting
= bIsExporting
;
170 m_bIsJavaBased
= bIsJavaBased
;
172 m_xOutputHandler
= xOutputHandler
;
173 m_xXMLSecurityContext
= xXMLSecurityContext
;
174 m_xXMLSignature
= xXMLSignature
;
175 m_xXMLEncryption
= xXMLEncryption
;
176 m_xRemoteServiceManager
= xRemoteServiceManager
;
177 m_xRemoteContext
= xRemoteContext
;
179 m_testTool
= testTool
;
180 m_parsingThread
= parsingThread
;
182 m_signatureList
= new Vector();
183 m_encryptionList
= new Vector();
185 m_vUnsolvedReferenceIds
= new Vector();
186 m_vUnsolvedReferencedKeeperIds
= new Vector();
187 m_vUnsolvedReferenceRefNum
= new Vector();
189 m_xXMLDocumentWrapper
= null;
190 m_xSAXEventKeeper
= null;
192 m_bSAXEventKeeperIncluded
= false;
193 m_bIsBlocking
= false;
194 m_bIsInsideCollectedElement
= false;
196 m_bIsEncryptionTarget
= false;
197 m_EncryptionForTarget
= null;
201 m_currentPath
= new Stack();
203 foundSecurityRelated();
206 /**************************************************************************************
208 **************************************************************************************/
211 * changes the output document handler.
213 private void changeOutput()
217 m_parsingThread
.setHandler(this);
220 * If the SAXEventKeeper is in the SAX chain, then redirects output
221 * to the SAXEventKeeper, otherwise, to the m_xOutputHandler
223 if (m_bSAXEventKeeperIncluded
)
225 m_xExportHandler
= (XDocumentHandler
)UnoRuntime
.queryInterface(
226 XDocumentHandler
.class, m_xSAXEventKeeper
);
227 m_xSAXEventKeeper
.setNextHandler(m_xOutputHandler
);
229 m_testTool
.updatesSAXChainInformation("XMLExporter -> SAXEventKeeper -> SAXWriter");
233 m_xExportHandler
= m_xOutputHandler
;
234 m_testTool
.updatesSAXChainInformation("XMLExporter -> SAXWriter");
239 if (m_bSAXEventKeeperIncluded
)
241 m_parsingThread
.setHandler(
242 (XDocumentHandler
)UnoRuntime
.queryInterface(XDocumentHandler
.class, m_xSAXEventKeeper
));
243 m_xSAXEventKeeper
.setNextHandler(this);
244 m_testTool
.updatesSAXChainInformation("SAXParser -> SAXEventKeeper -> XMLImporter");
248 m_parsingThread
.setHandler(this);
249 m_testTool
.updatesSAXChainInformation("SAXParser -> XMLImporter");
251 m_xExportHandler
= m_xOutputHandler
;
256 * handles the situation when a security related element is found.
257 * if the SAXEventKeeper is not initialized, then creates a
259 * the return value represents whether the SAXEventKeeper is newly
262 private boolean foundSecurityRelated()
264 if (m_xSAXEventKeeper
== null)
266 m_testTool
.showMessage("Message from : "+
267 (m_bIsExporting?
"XMLExporter":"XMLImporter")+
268 "\n\nA security related content found, a SAXEventKeeper is created.\n ");
270 m_bIsBlocking
= false;
271 m_bIsInsideCollectedElement
= false;
276 * creates an XMLDocumentWrapper component.
278 Object xmlDocumentObj
= null;
282 xmlDocumentObj
= m_xRemoteServiceManager
.createInstanceWithContext(
283 TestTool
.XMLDOCUMENTWRAPPER_COMPONENT_JAVA
, m_xRemoteContext
);
287 xmlDocumentObj
= m_xRemoteServiceManager
.createInstanceWithContext(
288 TestTool
.XMLDOCUMENTWRAPPER_COMPONENT_C
, m_xRemoteContext
);
291 m_xXMLDocumentWrapper
= (XXMLDocumentWrapper
)UnoRuntime
.queryInterface(
292 XXMLDocumentWrapper
.class, xmlDocumentObj
);
295 * creates a SAXEventKeeper component.
297 Object saxEventKeeperObj
= m_xRemoteServiceManager
.createInstanceWithContext(
298 TestTool
.SAXEVENTKEEPER_COMPONENT
, m_xRemoteContext
);
301 (XSecuritySAXEventKeeper
)UnoRuntime
.queryInterface(
302 XSecuritySAXEventKeeper
.class, saxEventKeeperObj
);
305 * initializes the SAXEventKeeper component with the XMLDocumentWrapper component.
307 XInitialization xInitialization
=
308 (XInitialization
)UnoRuntime
.queryInterface(
309 XInitialization
.class, m_xSAXEventKeeper
);
310 Object args
[]=new Object
[1];
311 args
[0] = m_xXMLDocumentWrapper
;
312 xInitialization
.initialize(args
);
314 catch( com
.sun
.star
.uno
.Exception e
)
320 * configures the SAXEventKeeper's status change listener.
322 XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster
=
323 (XSAXEventKeeperStatusChangeBroadcaster
)UnoRuntime
.queryInterface(
324 XSAXEventKeeperStatusChangeBroadcaster
.class, m_xSAXEventKeeper
);
325 xSaxEventKeeperStatusChangeBroadcaster
.addSAXEventKeeperStatusChangeListener(this);
328 boolean rc
= !m_bSAXEventKeeperIncluded
;
331 * changes the export document handler.
333 m_bSAXEventKeeperIncluded
=true;
340 * finds key element or referenced element for a signature.
342 private void findKeyOrReference(SecurityEntity signatureEntity
, String uriStr
, boolean isFindingKey
)
346 while (i
<m_vUnsolvedReferenceIds
.size())
348 String id
= (String
)m_vUnsolvedReferenceIds
.elementAt(i
);
350 if (id
.equals(uriStr
))
352 int refNum
= ((Integer
)m_vUnsolvedReferenceRefNum
.elementAt(i
)).intValue();
353 int keeperId
= ((Integer
)m_vUnsolvedReferencedKeeperIds
.elementAt(i
)).intValue();
358 * clones a new ElementCollector for the key element.
360 int cloneKeeperId
= m_xSAXEventKeeper
.cloneElementCollector(
363 (ElementMarkPriority
.BEFOREMODIFY
):(ElementMarkPriority
.AFTERMODIFY
));
366 * notifies the key keeper id.
368 signatureEntity
.setKeyId(cloneKeeperId
);
371 * sets the security id for the key.
373 m_xSAXEventKeeper
.setSecurityId(cloneKeeperId
, signatureEntity
.getSecurityId());
376 * sets the resolve listener.
378 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
379 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
380 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
381 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(
383 signatureEntity
.getReferenceListener());
388 * clones a new ElementCollector for the referenced element.
390 int cloneKeeperId
= m_xSAXEventKeeper
.cloneElementCollector(
393 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
));
396 * sets the security id.
398 m_xSAXEventKeeper
.setSecurityId(cloneKeeperId
, signatureEntity
.getSecurityId());
401 * sets the resolve listener.
403 XReferenceResolvedBroadcaster xReferenceResolvedBroadcaster
=
404 (XReferenceResolvedBroadcaster
)UnoRuntime
.queryInterface(
405 XReferenceResolvedBroadcaster
.class, m_xSAXEventKeeper
);
406 xReferenceResolvedBroadcaster
.addReferenceResolvedListener(cloneKeeperId
,
407 signatureEntity
.getReferenceListener());
410 XReferenceCollector xReferenceCollector
=
411 (XReferenceCollector
)UnoRuntime
.queryInterface(
412 XReferenceCollector
.class, signatureEntity
.getReferenceListener());
413 xReferenceCollector
.setReferenceId(cloneKeeperId
);
415 catch( com
.sun
.star
.uno
.Exception e
)
422 * if this unsolved reference reaches its max reference number, remove this reference
428 m_xSAXEventKeeper
.removeElementCollector(keeperId
);
429 m_vUnsolvedReferenceIds
.remove(i
);
430 m_vUnsolvedReferencedKeeperIds
.remove(i
);
431 m_vUnsolvedReferenceRefNum
.remove(i
);
435 m_vUnsolvedReferenceRefNum
.setElementAt(new Integer(refNum
),(i
));
440 * If it is find a key, then no further search is needed, one
441 * signature has one key at most.
456 * checks whether a startElement event represents any security related information.
457 * return true if this event can't be forwarded into the SAX chain.
459 private boolean checkSecurityElement(String localName
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
)
463 if (localName
.equals("Signature"))
465 * this element is a Signature element.
468 SignatureEntity signatureEntity
= new SignatureEntity(
472 m_xXMLSecurityContext
,
475 m_xRemoteServiceManager
,
478 m_signatureList
.add(signatureEntity
);
479 m_currentPath
.push(signatureEntity
);
481 else if(localName
.equals("Reference"))
483 if (!m_currentPath
.empty())
485 Object signedInfo
= m_currentPath
.pop();
487 if (!m_currentPath
.empty())
489 Object objSignature
= m_currentPath
.peek();
491 if ((objSignature
instanceof SignatureEntity
) && signedInfo
.toString().equals("SignedInfo"))
493 * this element is a Reference element in a signature.
496 String uriStr
= xattribs
.getValueByName("URI");
498 if (uriStr
.charAt(0) == '#')
500 uriStr
= uriStr
.substring(1);
501 SignatureEntity signatureEntity
= (SignatureEntity
)objSignature
;
503 if (uriStr
!= null && uriStr
.length()>0)
505 signatureEntity
.addReferenceId(uriStr
);
506 findKeyOrReference(signatureEntity
, uriStr
, false);
511 m_currentPath
.push(signedInfo
);
513 m_currentPath
.push(localName
);
515 else if(localName
.equals("KeyValue") ||
516 localName
.equals("KeyName") ||
517 localName
.equals("X509Data") ||
518 localName
.equals("EncryptedKey"))
520 if (!m_currentPath
.empty())
522 Object keyInfo
= m_currentPath
.pop();
524 if (!m_currentPath
.empty())
526 Object objSorE
= m_currentPath
.peek();
528 if ((objSorE
instanceof SignatureEntity
) && keyInfo
.toString().equals("KeyInfo"))
530 * this element is the key element of a signature.
533 SignatureEntity signatureEntity
= (SignatureEntity
)objSorE
;
534 signatureEntity
.setKeyId(0);
536 else if ((objSorE
instanceof EncryptionEntity
) && keyInfo
.toString().equals("KeyInfo"))
538 * this element is the key element of an encryption.
541 EncryptionEntity theEncryption
= (EncryptionEntity
)objSorE
;
542 theEncryption
.setKeyId(0);
545 m_currentPath
.push(keyInfo
);
548 m_currentPath
.push(localName
);
550 else if(localName
.equals("RetrievalMethod"))
552 if (!m_currentPath
.empty())
554 Object keyInfo
= m_currentPath
.pop();
556 if (!m_currentPath
.empty())
558 Object objSorE
= m_currentPath
.peek();
560 if ((objSorE
instanceof SignatureEntity
) && keyInfo
.toString().equals("KeyInfo"))
562 * this element is the RetrievalMethod element in a signature,
563 * which will include the key uri of this signature.
566 String uriStr
= xattribs
.getValueByName("URI");
567 SignatureEntity signatureEntity
= (SignatureEntity
)objSorE
;
569 if (uriStr
!= null && uriStr
.length()>0)
571 signatureEntity
.setKeyURI(uriStr
);
572 findKeyOrReference(signatureEntity
,uriStr
, true);
575 else if ((objSorE
instanceof EncryptionEntity
) && keyInfo
.toString().equals("KeyInfo"))
577 * this element is the RetrievalMethod element in an encryption,
578 * which will include the key uri of this encryption.
581 String uriStr
= xattribs
.getValueByName("URI");
582 EncryptionEntity theEncryption
= (EncryptionEntity
)objSorE
;
584 if (uriStr
!= null && uriStr
.length()>0)
586 theEncryption
.setKeyURI(uriStr
);
587 findKeyOrReference(theEncryption
, uriStr
, true);
591 m_currentPath
.push(keyInfo
);
593 m_currentPath
.push(localName
);
595 else if (localName
.equals("EncryptedData")) /* || localName.equals("EncryptedKey")) */
597 * this element is an Encryption element.
600 EncryptionEntity theEncryption
= new EncryptionEntity(
604 m_xXMLSecurityContext
,
607 m_xRemoteServiceManager
,
610 m_encryptionList
.add(theEncryption
);
614 m_currentPath
.push(theEncryption
);
618 String uriStr
= xattribs
.getValueByName("keyURI");
619 if (uriStr
!= null && uriStr
.length()>0)
621 theEncryption
.setKeyURI(uriStr
);
622 findKeyOrReference(theEncryption
,uriStr
, true);
626 theEncryption
.setKeyId(0);
634 * not a security related element.
637 m_currentPath
.push(localName
);
644 * checks whether a startElement event is referenced by any security entity.
646 private void checkReference(String localName
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
, String id
)
648 String refNumStr
= xattribs
.getValueByName("refNum");
650 if ( m_bIsEncryptionTarget
)
652 m_EncryptionForTarget
.setReference(m_bIsExporting
);
653 m_bIsEncryptionTarget
= false;
656 if (id
!= null && id
.length()>0 )
658 * only if this element has id attribute, then it can be referenced by
663 * if this element has an "refNum" attribute, then the value will be
664 * the max referencing number on this element, otherwise, set the max
665 * referencing number to 999.
669 if (refNumStr
!= null && refNumStr
.length()>0 )
671 refNum
= new Integer(refNumStr
).intValue();
677 * searches the signature list to check whether any sigture has
678 * reference on this element.
680 length
= m_signatureList
.size();
681 for (int i
=0; i
<length
; ++i
)
683 SignatureEntity signatureEntity
= (SignatureEntity
)m_signatureList
.elementAt(i
);
685 if (signatureEntity
.setReference(id
, m_bIsExporting
))
690 if (signatureEntity
.setKey(id
, m_bIsExporting
))
697 * searches the encryption list for reference.
699 length
= m_encryptionList
.size();
700 for (int i
=0; i
<length
; ++i
)
702 EncryptionEntity theEncryption
= (EncryptionEntity
)m_encryptionList
.elementAt(i
);
704 if (theEncryption
.setKey(id
, m_bIsExporting
))
711 * if the max referencing number is not reached, then add this element
712 * into the unsolved reference list.
718 if (localName
.equals("EncryptedKey"))
720 keeperId
= m_xSAXEventKeeper
.addSecurityElementCollector(
722 (ElementMarkPriority
.BEFOREMODIFY
):(ElementMarkPriority
.AFTERMODIFY
),
727 keeperId
= m_xSAXEventKeeper
.addSecurityElementCollector(
729 (ElementMarkPriority
.AFTERMODIFY
):(ElementMarkPriority
.BEFOREMODIFY
),
733 m_vUnsolvedReferenceIds
.add(id
);
734 m_vUnsolvedReferencedKeeperIds
.add(new Integer(keeperId
));
735 m_vUnsolvedReferenceRefNum
.add(new Integer(refNum
));
741 * configures the output handler.
743 private void setOutputHandler(XDocumentHandler handler
)
745 m_xOutputHandler
= handler
;
750 /**************************************************************************************
752 **************************************************************************************/
755 * methods used to transfer unsolved reference information.
757 protected Vector
getUnsolvedReferenceIds()
759 return m_vUnsolvedReferenceIds
;
762 protected Vector
getUnsolvedReferenceKeeperIds()
764 return m_vUnsolvedReferencedKeeperIds
;
767 protected Vector
getUnsolvedReferenceRefNum()
769 return m_vUnsolvedReferenceRefNum
;
772 protected String
getBufferNodeTreeInformation()
774 if (m_xSAXEventKeeper
!= null)
776 return m_xSAXEventKeeper
.printBufferNodeTree();
784 protected void getDocument(XDocumentHandler handler
)
786 if (m_xXMLDocumentWrapper
!= null)
790 m_xXMLDocumentWrapper
.getTree(handler
);
792 catch(SAXException e
)
799 protected void endMission()
801 while (m_signatureList
.size()>0 || m_encryptionList
.size()>0)
803 if (m_signatureList
.size()>0)
805 SignatureEntity signatureEntity
= (SignatureEntity
)m_signatureList
.elementAt(0);
806 m_signatureList
.remove(0);
807 signatureEntity
.endMission();
809 else if (m_encryptionList
.size()>0)
811 EncryptionEntity theEncryption
= (EncryptionEntity
)m_encryptionList
.elementAt(0);
812 m_encryptionList
.remove(0);
813 theEncryption
.endMission();
817 while (m_vUnsolvedReferenceIds
.size()>0)
819 int keeperId
= ((Integer
)m_vUnsolvedReferencedKeeperIds
.elementAt(0)).intValue();
820 m_xSAXEventKeeper
.removeElementCollector(keeperId
);
821 m_vUnsolvedReferenceIds
.remove(0);
822 m_vUnsolvedReferencedKeeperIds
.remove(0);
823 m_vUnsolvedReferenceRefNum
.remove(0);
826 m_xSAXEventKeeper
.setNextHandler(null);
828 XSAXEventKeeperStatusChangeBroadcaster xSaxEventKeeperStatusChangeBroadcaster
=
829 (XSAXEventKeeperStatusChangeBroadcaster
)UnoRuntime
.queryInterface(
830 XSAXEventKeeperStatusChangeBroadcaster
.class, m_xSAXEventKeeper
);
831 xSaxEventKeeperStatusChangeBroadcaster
.addSAXEventKeeperStatusChangeListener(null);
833 m_xSAXEventKeeper
= null;
834 m_xXMLDocumentWrapper
= null;
835 m_xOutputHandler
= null;
836 m_xXMLSecurityContext
= null;
837 m_xXMLSignature
= null;
838 m_xXMLEncryption
= null;
840 m_xExportHandler
= null;
841 m_parsingThread
.setHandler(null);
844 /**************************************************************************************
846 **************************************************************************************/
851 public void startDocument()
854 m_xExportHandler
.startDocument();
856 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
863 public void endDocument()
866 m_xExportHandler
.endDocument();
868 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
874 public void startElement (String str
, com
.sun
.star
.xml
.sax
.XAttributeList xattribs
)
877 String idAttr
= xattribs
.getValueByName("id");
880 idAttr
= xattribs
.getValueByName("Id");
883 boolean hasIdAttr
= (idAttr
!= null && idAttr
.length()>0 );
884 boolean needResend
= false;
887 (str
.equals("Signature")||str
.equals("EncryptedData")))/* || str.equals("EncryptedKey"))) */
889 if (foundSecurityRelated() && !m_bIsExporting
)
895 boolean suppressToNext
= checkSecurityElement(str
, xattribs
);
897 checkReference(str
, xattribs
, idAttr
);
901 m_xSAXEventKeeper
.setNextHandler(null);
903 XDocumentHandler saxEventKeeperHandler
=
904 (XDocumentHandler
)UnoRuntime
.queryInterface(
905 XDocumentHandler
.class, m_xSAXEventKeeper
);
906 saxEventKeeperHandler
.startElement(str
, xattribs
);
907 m_xSAXEventKeeper
.setNextHandler((XDocumentHandler
)this);
912 m_xExportHandler
.startElement(str
, xattribs
);
915 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
921 public void endElement(String str
)
923 if (!m_currentPath
.empty())
925 Object obj
= m_currentPath
.pop();
927 if (obj
.toString().equals("SignedInfo"))
929 if (!m_currentPath
.empty())
931 Object objSignature
= m_currentPath
.peek();
932 if (objSignature
!= null && objSignature
instanceof SignatureEntity
)
934 ((SignatureEntity
)objSignature
).setReferenceNumber();
938 else if (obj
instanceof EncryptionEntity
)
940 m_bIsEncryptionTarget
= true;
941 m_EncryptionForTarget
= (EncryptionEntity
)obj
;
947 m_xExportHandler
.endElement(str
);
949 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
955 public void characters(String str
)
958 m_xExportHandler
.characters(str
);
960 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
966 public void ignorableWhitespace(String str
)
970 public void processingInstruction(String aTarget
, String aData
)
973 m_xExportHandler
.processingInstruction(aTarget
, aData
);
975 catch( com
.sun
.star
.xml
.sax
.SAXException e
)
981 public void setDocumentLocator (com
.sun
.star
.xml
.sax
.XLocator xLocator
)
982 throws com
.sun
.star
.xml
.sax
.SAXException
988 * XSignatureCreationResultListener
990 public void signatureCreated(int securityId
, SecurityOperationStatus creationResult
)
992 String message
= new String();
993 message
+= "A Signature is created:";
994 message
+= "\nSecurity Id = "+securityId
;
995 message
+= "\nCreation result = "+((creationResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
997 m_testTool
.showMessage("Message from : SignatureCreator\n\n"+message
+"\n ");
1001 * XSignatureVerifyResultListener
1003 public void signatureVerified(int securityId
, SecurityOperationStatus verifyResult
)
1005 String message
= new String();
1006 message
+= "A Signature is verified:";
1007 message
+= "\nSecurity Id = "+securityId
;
1008 message
+= "\nVerify result = "+((verifyResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1010 m_testTool
.showMessage("Message from : SignatureVerifier\n\n"+message
+"\n ");
1014 * XEncryptionResultListener
1016 public void encrypted(int securityId
, SecurityOperationStatus encryptionResult
)
1018 String message
= new String();
1019 message
+= "An EncryptedData is encrypted:";
1020 message
+= "\nSecurity Id = "+securityId
;
1021 message
+= "\nEncrypt result = "+((encryptionResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1023 m_testTool
.showMessage("Message from : Encryptor\n\n"+message
+"\n ");
1027 * XDecryptionResultListener methods
1029 public void decrypted(int securityId
, SecurityOperationStatus decryptionResult
)
1031 String message
= new String();
1032 message
+= "An EncryptedData is decrypted:";
1033 message
+= "\nSecurity Id = "+securityId
;
1034 message
+= "\nDecrypt result = "+((decryptionResult
==SecurityOperationStatus
.OPERATION_SUCCEEDED
)?
"Succeed":"Fail");
1036 m_testTool
.showMessage("Message from : Decryptor\n\n"+message
+"\n ");
1040 * XSAXEventKeeperStatusChangeListener methods
1042 public void blockingStatusChanged(boolean isBlocking
)
1044 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1045 (isBlocking?
"The SAX event stream is blocked.":"The SAX event stream is unblocked.")+
1048 this.m_bIsBlocking
= isBlocking
;
1051 public void collectionStatusChanged(boolean isInsideCollectedElement
)
1053 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1054 (isInsideCollectedElement?
"Begin to buffer data ...":"End of data bufferring.")+
1058 this.m_bIsInsideCollectedElement = isInsideCollectedElement;
1060 if ( !m_bIsInsideCollectedElement && !m_bIsBlocking)
1062 m_bSAXEventKeeperIncluded = false;
1066 m_bSAXEventKeeperIncluded = true;
1072 public void bufferStatusChanged(boolean isBufferEmpty
)
1074 m_testTool
.showMessage("Message from : SAXEventKeeper\n\n"+
1075 (isBufferEmpty?
"All bufferred data are released, the SAXEventKeeper is destroyed.":"buffer data appears.")+
1080 m_xXMLDocumentWrapper = null;
1081 m_xSAXEventKeeper = null;
1082 m_bSAXEventKeeperIncluded = false;