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