1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package com.sun.star.xml.security.eval; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 31*cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper; 32*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33*cdf0e10cSrcweir import com.sun.star.xml.sax.InputSource; 34*cdf0e10cSrcweir import com.sun.star.xml.sax.XDocumentHandler; 35*cdf0e10cSrcweir import com.sun.star.xml.sax.XParser; 36*cdf0e10cSrcweir import com.sun.star.xml.sax.XDTDHandler; 37*cdf0e10cSrcweir import com.sun.star.xml.sax.XEntityResolver; 38*cdf0e10cSrcweir import com.sun.star.xml.sax.XErrorHandler; 39*cdf0e10cSrcweir import com.sun.star.xml.sax.XAttributeList; 40*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 41*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 42*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 43*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 44*cdf0e10cSrcweir import com.sun.star.lang.Locale; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /* 47*cdf0e10cSrcweir * the JavaFlatFilter class is a pure java filter, which does nothing 48*cdf0e10cSrcweir * but forwarding the SAX events to the next document handler. 49*cdf0e10cSrcweir * The purpose of this class is to calculate the time consumed by 50*cdf0e10cSrcweir * the UNO C++/Java bridge during exporting/importing. 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir public class JavaFlatFilter extends Object 53*cdf0e10cSrcweir implements XDocumentHandler, XParser, XTypeProvider, XServiceInfo 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir XDocumentHandler m_xDocumentHandler; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /* XDocumentHandler */ 58*cdf0e10cSrcweir public void startDocument() 59*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir m_xDocumentHandler.startDocument(); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir public void endDocument() 65*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir m_xDocumentHandler.endDocument(); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir public void startElement (String aName, com.sun.star.xml.sax.XAttributeList xAttribs ) 71*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir m_xDocumentHandler.startElement(aName, xAttribs); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir public void endElement ( String aName ) 77*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir m_xDocumentHandler.endElement(aName); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir public void characters ( String aChars ) 83*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir m_xDocumentHandler.characters(aChars); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir public void ignorableWhitespace ( String aWhitespaces ) 89*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir m_xDocumentHandler.ignorableWhitespace(aWhitespaces); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir public void processingInstruction ( String aTarget, String aData ) 95*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir m_xDocumentHandler.processingInstruction(aTarget, aData); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir public void setDocumentLocator (com.sun.star.xml.sax.XLocator xLocator ) 101*cdf0e10cSrcweir throws com.sun.star.xml.sax.SAXException 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir m_xDocumentHandler.setDocumentLocator(xLocator); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /* XParser */ 107*cdf0e10cSrcweir public void parseStream(InputSource strucInputSource) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir public void setDocumentHandler(XDocumentHandler xDocumentHandler) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir m_xDocumentHandler = xDocumentHandler; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir public void setDTDHandler(XDTDHandler xHandler) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir public void setEntityResolver(XEntityResolver xResolver) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir public void setErrorHandler(XErrorHandler xHandler) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir public void setLocale(Locale locale) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir /* 133*cdf0e10cSrcweir * XTypeProvider implementation 134*cdf0e10cSrcweir * maintain a static implementation id for all instances of JavaFlatFilter 135*cdf0e10cSrcweir * initialized by the first call to getImplementationId() 136*cdf0e10cSrcweir */ 137*cdf0e10cSrcweir protected static byte[] _implementationId; 138*cdf0e10cSrcweir public com.sun.star.uno.Type[] getTypes() 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[4]; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /* 143*cdf0e10cSrcweir * instantiate Type instances for each interface you support and add them to Type[] array 144*cdf0e10cSrcweir * this object implements XServiceInfo, XTypeProvider and XSignFilter 145*cdf0e10cSrcweir */ 146*cdf0e10cSrcweir retValue[0]= new com.sun.star.uno.Type( XServiceInfo.class); 147*cdf0e10cSrcweir retValue[1]= new com.sun.star.uno.Type( XTypeProvider.class); 148*cdf0e10cSrcweir retValue[2]= new com.sun.star.uno.Type( XDocumentHandler.class); 149*cdf0e10cSrcweir retValue[3]= new com.sun.star.uno.Type( XParser.class); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir /* 152*cdf0e10cSrcweir * XInterface is not needed for Java components, the UnoRuntime does its job 153*cdf0e10cSrcweir */ 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir return retValue; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir synchronized public byte[] getImplementationId() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir if (_implementationId == null) { 161*cdf0e10cSrcweir _implementationId= new byte[16]; 162*cdf0e10cSrcweir int hash = hashCode(); // hashDode of this object 163*cdf0e10cSrcweir _implementationId[0] = (byte)(hash & 0xff); 164*cdf0e10cSrcweir _implementationId[1] = (byte)((hash >>> 8) & 0xff); 165*cdf0e10cSrcweir _implementationId[2] = (byte)((hash >>> 16) & 0xff); 166*cdf0e10cSrcweir _implementationId[3] = (byte)((hash >>>24) & 0xff); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir return _implementationId; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir /* 173*cdf0e10cSrcweir * XServiceInfo implementation 174*cdf0e10cSrcweir * hold the service name in a private static member variable of the class 175*cdf0e10cSrcweir */ 176*cdf0e10cSrcweir protected static final String __serviceName = "com.sun.star.xml.crypto.eval.JavaFlatFilter"; 177*cdf0e10cSrcweir public String getImplementationName( ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir return getClass().getName(); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir public boolean supportsService(String serviceName) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir boolean rc = false; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir if ( serviceName.equals( __serviceName)) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir rc = true; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir return rc; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir public String[] getSupportedServiceNames( ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir String[] retValue= new String[0]; 197*cdf0e10cSrcweir retValue[0]= __serviceName; 198*cdf0e10cSrcweir return retValue; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir /* static __getServiceFactory() implementation */ 202*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory(String implName, 203*cdf0e10cSrcweir XMultiServiceFactory multiFactory, 204*cdf0e10cSrcweir com.sun.star.registry.XRegistryKey regKey) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir com.sun.star.lang.XSingleServiceFactory xSingleServiceFactory = null; 207*cdf0e10cSrcweir if (implName.equals( JavaFlatFilter.class.getName()) ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir xSingleServiceFactory = FactoryHelper.getServiceFactory( JavaFlatFilter.class, 210*cdf0e10cSrcweir JavaFlatFilter.__serviceName, 211*cdf0e10cSrcweir multiFactory, 212*cdf0e10cSrcweir regKey); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir return xSingleServiceFactory; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir /* static __writeRegistryServiceInfo implementation */ 219*cdf0e10cSrcweir public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir return FactoryHelper.writeRegistryServiceInfo( JavaFlatFilter.class.getName(), 222*cdf0e10cSrcweir __serviceName, 223*cdf0e10cSrcweir regKey); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir } 226