xref: /AOO41X/main/xmlsecurity/tools/demo/JavaFlatFilter.java (revision db8598795e2025b89968fa208f4cf0f9125a6f19)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.xml.security.eval;
25 
26 import com.sun.star.registry.XRegistryKey;
27 import com.sun.star.comp.loader.FactoryHelper;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.xml.sax.InputSource;
30 import com.sun.star.xml.sax.XDocumentHandler;
31 import com.sun.star.xml.sax.XParser;
32 import com.sun.star.xml.sax.XDTDHandler;
33 import com.sun.star.xml.sax.XEntityResolver;
34 import com.sun.star.xml.sax.XErrorHandler;
35 import com.sun.star.xml.sax.XAttributeList;
36 import com.sun.star.lang.XSingleServiceFactory;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.lang.XTypeProvider;
39 import com.sun.star.lang.XServiceInfo;
40 import com.sun.star.lang.Locale;
41 
42 /*
43  * the JavaFlatFilter class is a pure java filter, which does nothing
44  * but forwarding the SAX events to the next document handler.
45  * The purpose of this class is to calculate the time consumed by
46  * the UNO C++/Java bridge during exporting/importing.
47  */
48 public class JavaFlatFilter extends Object
49         implements XDocumentHandler, XParser, XTypeProvider, XServiceInfo
50 {
51     XDocumentHandler m_xDocumentHandler;
52 
53     /* XDocumentHandler */
startDocument()54     public void startDocument()
55         throws com.sun.star.xml.sax.SAXException
56     {
57         m_xDocumentHandler.startDocument();
58     }
59 
endDocument()60     public void endDocument()
61         throws com.sun.star.xml.sax.SAXException
62     {
63         m_xDocumentHandler.endDocument();
64     }
65 
startElement(String aName, com.sun.star.xml.sax.XAttributeList xAttribs )66     public void startElement (String aName, com.sun.star.xml.sax.XAttributeList xAttribs )
67         throws com.sun.star.xml.sax.SAXException
68     {
69         m_xDocumentHandler.startElement(aName, xAttribs);
70     }
71 
endElement( String aName )72     public void endElement ( String aName )
73         throws com.sun.star.xml.sax.SAXException
74     {
75         m_xDocumentHandler.endElement(aName);
76     }
77 
characters( String aChars )78     public void characters ( String aChars )
79         throws com.sun.star.xml.sax.SAXException
80     {
81         m_xDocumentHandler.characters(aChars);
82     }
83 
ignorableWhitespace( String aWhitespaces )84     public void ignorableWhitespace ( String aWhitespaces )
85         throws com.sun.star.xml.sax.SAXException
86     {
87         m_xDocumentHandler.ignorableWhitespace(aWhitespaces);
88     }
89 
processingInstruction( String aTarget, String aData )90     public void processingInstruction ( String aTarget, String aData )
91         throws com.sun.star.xml.sax.SAXException
92     {
93         m_xDocumentHandler.processingInstruction(aTarget, aData);
94     }
95 
setDocumentLocator(com.sun.star.xml.sax.XLocator xLocator )96     public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator )
97         throws com.sun.star.xml.sax.SAXException
98     {
99         m_xDocumentHandler.setDocumentLocator(xLocator);
100     }
101 
102     /* XParser */
parseStream(InputSource strucInputSource)103     public void parseStream(InputSource strucInputSource)
104     {
105     }
106 
setDocumentHandler(XDocumentHandler xDocumentHandler)107     public void setDocumentHandler(XDocumentHandler xDocumentHandler)
108     {
109         m_xDocumentHandler = xDocumentHandler;
110     }
111 
setDTDHandler(XDTDHandler xHandler)112     public void setDTDHandler(XDTDHandler xHandler)
113     {
114     }
115 
setEntityResolver(XEntityResolver xResolver)116     public void setEntityResolver(XEntityResolver xResolver)
117     {
118     }
119 
setErrorHandler(XErrorHandler xHandler)120     public void setErrorHandler(XErrorHandler xHandler)
121     {
122     }
123 
setLocale(Locale locale)124     public void setLocale(Locale locale)
125     {
126     }
127 
128     /*
129      * XTypeProvider implementation
130      * maintain a static implementation id for all instances of JavaFlatFilter
131      * initialized by the first call to getImplementationId()
132      */
133     protected static byte[] _implementationId;
getTypes()134     public com.sun.star.uno.Type[] getTypes()
135     {
136         com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[4];
137 
138         /*
139          * instantiate Type instances for each interface you support and add them to Type[] array
140          * this object implements XServiceInfo, XTypeProvider and XSignFilter
141          */
142         retValue[0]= new com.sun.star.uno.Type( XServiceInfo.class);
143         retValue[1]= new com.sun.star.uno.Type( XTypeProvider.class);
144         retValue[2]= new com.sun.star.uno.Type( XDocumentHandler.class);
145         retValue[3]= new com.sun.star.uno.Type( XParser.class);
146 
147         /*
148          * XInterface is not needed for Java components, the UnoRuntime does its job
149          */
150 
151         return retValue;
152     }
153 
getImplementationId()154     synchronized public byte[] getImplementationId()
155     {
156         if (_implementationId == null) {
157         _implementationId= new byte[16];
158         int hash = hashCode(); // hashDode of this object
159         _implementationId[0] = (byte)(hash & 0xff);
160         _implementationId[1] = (byte)((hash >>> 8) & 0xff);
161         _implementationId[2] = (byte)((hash >>> 16) & 0xff);
162         _implementationId[3] = (byte)((hash >>>24) & 0xff);
163         }
164         return _implementationId;
165     }
166 
167 
168     /*
169      * XServiceInfo implementation
170      * hold the service name in a private static member variable of the class
171      */
172     protected static final String __serviceName = "com.sun.star.xml.crypto.eval.JavaFlatFilter";
getImplementationName( )173     public String getImplementationName( )
174     {
175         return getClass().getName();
176     }
177 
supportsService(String serviceName)178     public boolean supportsService(String serviceName)
179     {
180         boolean rc = false;
181 
182         if ( serviceName.equals( __serviceName))
183         {
184             rc = true;
185         }
186 
187         return rc;
188     }
189 
getSupportedServiceNames( )190     public String[] getSupportedServiceNames( )
191     {
192         String[] retValue= new String[0];
193         retValue[0]= __serviceName;
194         return retValue;
195     }
196 
197     /* static __getServiceFactory() implementation */
__getServiceFactory(String implName, XMultiServiceFactory multiFactory, com.sun.star.registry.XRegistryKey regKey)198     public static XSingleServiceFactory __getServiceFactory(String implName,
199         XMultiServiceFactory multiFactory,
200         com.sun.star.registry.XRegistryKey regKey)
201     {
202         com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null;
203         if (implName.equals( JavaFlatFilter.class.getName()) )
204         {
205             xSingleServiceFactory = FactoryHelper.getServiceFactory( JavaFlatFilter.class,
206                 JavaFlatFilter.__serviceName,
207                 multiFactory,
208                 regKey);
209         }
210 
211         return xSingleServiceFactory;
212     }
213 
214     /* static __writeRegistryServiceInfo implementation */
__writeRegistryServiceInfo(XRegistryKey regKey)215     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
216     {
217         return FactoryHelper.writeRegistryServiceInfo( JavaFlatFilter.class.getName(),
218                                 __serviceName,
219                                 regKey);
220     }
221 }
222