From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../FlatXmlFilter_java/FlatXml.java | 267 +++++++++++++++++++++ .../FlatXmlFilter_java.components | 8 + .../FlatXmlFilter_java/FlatXmlFilter_java.xcu | 103 ++++++++ .../FilterDevelopment/FlatXmlFilter_java/Makefile | 142 +++++++++++ 4 files changed, 520 insertions(+) create mode 100644 odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java create mode 100644 odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.components create mode 100644 odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu create mode 100644 odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile (limited to 'odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java') diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java new file mode 100644 index 000000000..6ba341977 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java @@ -0,0 +1,267 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +import com.sun.star.uno.*; +import com.sun.star.lang.*; +import com.sun.star.beans.*; + +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.registry.XRegistryKey; + +import com.sun.star.xml.*; +import com.sun.star.xml.sax.*; + +import com.sun.star.io.XInputStream; +import com.sun.star.io.XOutputStream; +import com.sun.star.io.XActiveDataSource; + + + +public class FlatXml implements XImportFilter, XExportFilter, XServiceName, + XServiceInfo, XDocumentHandler, XTypeProvider +{ + + /* + * private data members + */ + private final XMultiServiceFactory m_xServiceFactory; + private XExtendedDocumentHandler m_xHandler; + private static final boolean m_bPrettyPrint = true; + + private static final String __serviceName = "devguide.officedev.samples.filter.FlatXmlJava"; + private static final String __implName = "FlatXml"; + private static final String[] __supportedServiceNames = { + "devguide.officedev.samples.filter.FlatXmlJava" + }; + + public FlatXml(XMultiServiceFactory f) { + m_xServiceFactory = f; + } + + // --- XTypeProvider --- + public byte[] getImplementationId() { + return new byte[0]; + } + + // --- XServiceName --- + public String getServiceName() { + return __serviceName; + } + + // --- XServiceInfo --- + public boolean supportsService(String sName) { + for (int i = 0; i < __supportedServiceNames.length; i++) { + if (__supportedServiceNames[i].equals(sName)) return true; + } + return false; + } + public String getImplementationName() { + return this.getClass().getName(); + } + public String[] getSupportedServiceNames() { + return __supportedServiceNames; + } + + public com.sun.star.uno.Type[] getTypes() { + Type[] typeReturn = {}; + try { + typeReturn = new Type[] { + new Type( XTypeProvider.class ), + new Type( XExportFilter.class ), + new Type( XImportFilter.class ), + new Type( XServiceName.class ), + new Type( XServiceInfo.class ) + }; + } catch( java.lang.Exception exception ) { + return null; + } + return typeReturn; + } + + public boolean importer(PropertyValue[] aSourceData, XDocumentHandler xDocHandler, String[] msUserData) + throws com.sun.star.uno.RuntimeException, com.sun.star.lang.IllegalArgumentException + { + String sName = null; + String sFileName = null; + String sURL = null; + com.sun.star.io.XInputStream xin = null; + + try { + + for (int i = 0 ; i < aSourceData.length; i++) + { + sName = aSourceData[i].Name; + if (sName.equals("InputStream")) + xin = (XInputStream)AnyConverter.toObject(XInputStream.class, aSourceData[i].Value); + if (sName.equals("URL")) + sURL=(String)AnyConverter.toObject(String.class, aSourceData[i].Value); + if (sName.equals("FileName")) + sFileName=(String)AnyConverter.toObject(String.class, aSourceData[i].Value); + } + + Object tmpObj=m_xServiceFactory.createInstance("com.sun.star.xml.sax.Parser"); + if (tmpObj == null) return false; + + XParser xParser = UnoRuntime.queryInterface(XParser.class , tmpObj); + if (xParser == null) return false; + + InputSource aInput = new InputSource(); + aInput.sSystemId = sURL; + aInput.aInputStream =xin; + xParser.setDocumentHandler ( xDocHandler ); + xParser.parseStream ( aInput ); + } catch (com.sun.star.uno.Exception e){ + e.printStackTrace(); + return false; + } + + // done... + return true; + } + + public boolean exporter(PropertyValue[] aSourceData, String[] msUserData) + throws com.sun.star.uno.RuntimeException, com.sun.star.lang.IllegalArgumentException + { + try { + String sURL = null; + String sName = null; + XOutputStream xos = null; + + // get interesting values from sourceData + for (int i = 0 ; i < aSourceData.length; i++) + { + sName = aSourceData[i].Name; + if (sName.equals("OutputStream")) + xos = (XOutputStream)AnyConverter.toObject(XOutputStream.class, aSourceData[i].Value); + if (sName.equals("URL")) + sURL=(String)AnyConverter.toObject(String.class, aSourceData[i].Value); + } + + // prepare the XML writer + Object tmpObj = null; + if (m_xHandler == null) + { + tmpObj = m_xServiceFactory.createInstance("com.sun.star.xml.sax.Writer"); + if (tmpObj != null) + m_xHandler = UnoRuntime.queryInterface(XExtendedDocumentHandler.class, tmpObj); + } + if (m_xHandler == null) + return false; + + // Connect the provided output stream to the writer + XActiveDataSource xADSource = UnoRuntime.queryInterface( + XActiveDataSource.class, m_xHandler); + + if (xADSource != null && xos != null) + xADSource.setOutputStream(xos); + else + return false; + } catch (com.sun.star.uno.Exception e){ + return false; + } + + // done ... + return true; + } + + public void startDocument () + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.startDocument(); + } + + public void endDocument() + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.endDocument(); + } + + public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs) + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.startElement(str, xattribs); + } + + public void endElement(String str) + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.endElement(str); + } + + public void characters(String str) + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.characters(str); + } + + public void ignorableWhitespace(String str) + throws com.sun.star.xml.sax.SAXException + { + if (!m_bPrettyPrint) return; + else m_xHandler.ignorableWhitespace(str); + } + + public void processingInstruction(String aTarget, String aData) + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.processingInstruction(aTarget, aData); + } + + public void setDocumentLocator(XLocator xLocator) + throws com.sun.star.xml.sax.SAXException + { + m_xHandler.setDocumentLocator(xLocator); + } + + + // component management + + public static XSingleServiceFactory __getServiceFactory(String implName, + XMultiServiceFactory multiFactory, XRegistryKey regKey) + { + XSingleServiceFactory xSingleServiceFactory = null; + if (implName.equals(__implName) ) { + try { + xSingleServiceFactory = FactoryHelper.getServiceFactory( + Class.forName(implName), __serviceName, multiFactory, regKey); + } catch (java.lang.ClassNotFoundException e) { + return null; + } + } + return xSingleServiceFactory; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.components b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.components new file mode 100644 index 000000000..87359c3ec --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.components @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu new file mode 100644 index 000000000..8bb6e2350 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu @@ -0,0 +1,103 @@ + + + + + + + 0 + devguide_FlatXMLType_Cpp_calc + com.sun.star.sheet.SpreadsheetDocument + + devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter + com.sun.star.comp.Writer.XmlFilterAdaptor + + + + + DevGuide FlatXML Calc + DevGuide FlatXML Calc + + IMPORT EXPORT ALIEN 3RDPARTYFILTER + + + 0 + devguide_FlatXMLType_Cpp_draw + com.sun.star.drawing.DrawingDocument + + devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.DrawingLayer.XMLOasisImporter,com.sun.star.comp.DrawingLayer.XMLOasisExporter + com.sun.star.comp.Writer.XmlFilterAdaptor + + + + + DevGuide FlatXML Draw + DevGuide FlatXML Draw + + IMPORT EXPORT ALIEN 3RDPARTYFILTER + + + 0 + devguide_FlatXMLType_Cpp_impress + com.sun.star.presentation.PresentationDocument + + devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Impress.XMLOasisImporter,com.sun.star.comp.Impress.XMLOasisExporter + com.sun.star.comp.Writer.XmlFilterAdaptor + + + + + DevGuide FlatXML Impress + DevGuide FlatXML Impress + + IMPORT EXPORT ALIEN 3RDPARTYFILTER + + + 0 + devguide_FlatXMLType_Cpp_writer + com.sun.star.text.TextDocument + + devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter + com.sun.star.comp.Writer.XmlFilterAdaptor + + + + + DevGuide FlatXML Writer + DevGuide FlatXML Writer + + IMPORT EXPORT ALIEN 3RDPARTYFILTER + + + 0 + devguide_FlatXMLType_Cpp_master + com.sun.star.text.GlobalDocument + + devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter + com.sun.star.comp.Writer.XmlFilterAdaptor + + + + + DevGuide FlatXML Master + DevGuide FlatXML Master + + IMPORT EXPORT ALIEN 3RDPARTYFILTER + + + diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile new file mode 100644 index 000000000..58366b7d5 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile @@ -0,0 +1,142 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the Java FlatXMLFilter component example of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMP_NAME=FlatXmlFilter_java +OUT_COMP_CLASS = $(OUT_CLASS)/$(COMP_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_JAR_NAME = $(COMP_NAME).uno.jar +COMP_JAR = $(OUT_COMP_CLASS)/$(COMP_JAR_NAME) +COMP_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest +COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml +COMP_REGISTERFLAG = $(OUT_MISC)$(PS)devguide_$(COMP_NAME)_register_component.flag +COMP_COMPONENTS=$(COMP_NAME).components + +JAVAFILES = \ + FlatXml.java \ + +CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES)) + + +#$(COMP_NAME)_CLASSFILES = FlatXml.class FlatXml$(dlr)_FlatXml.class + +$(COMP_NAME)_CLASSFILES = *.class + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(OUT_COMP_CLASS)) + + +# Targets +.PHONY: ALL +ALL : \ + FlatXmlFilterJavaExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_CLASS)/%.Manifest : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo RegistrationClassName: FlatXml> $@ + +$(CLASSFILES) : $(JAVAFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES) + +# rule for component jar file +$(COMP_JAR) : $(COMP_MANIFESTFILE) $(CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $( $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)FlatXmlFilter_java.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_COMPONENTS)$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(COMP_JAR) FlatXmlFilter_java.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_ZIP) $@ FlatXmlFilter_java.xcu + $(SDK_ZIP) -u $@ $(COMP_COMPONENTS) + cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $( $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +FlatXmlFilterJavaExample : $(COMP_REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The Java FlatXmlFilter component is installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You can use the filters "$(QM)DevGuide FlatXML ...$(QM)" inside your office installation + @echo after you have installed the "$(QM)FlatXmlTypeDetection.uno.pkg"$(QM) as well. + @echo -------------------------------------------------------------------------------- + +%.run: $(OUT_COMP_CLASS)/%.class + $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@) + +%.local: $(OUT_COMP_CLASS)/%.class + $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@) local + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG))) -- cgit v1.2.3