diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
17 files changed, 2906 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java new file mode 100644 index 000000000..5ab5fb3b1 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java @@ -0,0 +1,702 @@ +/* -*- 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. + * + *************************************************************************/ + +package FilterDevelopment.AsciiFilter; + +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.AnyConverter; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.container.XNamed; +import com.sun.star.document.XImporter; +import com.sun.star.document.XExporter; +import com.sun.star.document.XFilter; + +/*-************************************************************************ + @title implements a filter to import pure ascii text files + @description This filter can use an existing In/OutputStream of given + MediaDescriptor or use an existing URL instead of that + to open the file directly. But for second case the local + file system will be used only. There is no support for remote. + + During import/export special functionality can be used to + e.g. to change some characters inside the file content + or replace some strings (no using of regular expressions!). + User can decide at runtime which functionality really should + be used by selecting it in an extra filter property dialog. + + So we show how a filter works for import/export, use or create + streams and how a filter can offer properties for filtering + which can be edit by the user. + ************************************************************************-*/ + +public class AsciiReplaceFilter +{ + public static class _AsciiReplaceFilter extends WeakBase + implements XInitialization , + XServiceInfo , + XNamed , + XImporter , + XExporter , + XFilter + { + + + // the supported service names, the first one being the service name of the component itself + private static final String[] m_serviceNames = { "com.sun.star.comp.ansifilter.AsciiReplaceFilter" , "com.sun.star.document.ImportFilter", "com.sun.star.document.ExportFilter" }; + + // filterprocess states + private static final int FILTERPROC_RUNS = 0; + private static final int FILTERPROC_BREAK = 1; + private static final int FILTERPROC_STOPPED = 2; + + + // member + + + /// The initial component context, that gives access to the service manager, supported singletons, ... + private XComponentContext m_Ctx; + /// The service manager, that gives access to all registered services and which is passed to the FilterOptions class for instantiating a ucb service + private XMultiComponentFactory m_xMCF; + /// we must provide our name + private String m_sInternalName; + /// saved document reference for import or export (depends on other member m_bImport!) + private com.sun.star.text.XTextDocument m_xDocument; + /// because we implement an import AND an export filter, we must know which one is required + private boolean m_bImport; + // we need a flag to cancel any running filter operation + private int m_nFilterProcState; + + + // native interface + /** + * special debug helper to get an idea how expensive + * the implemented filter operations are really. + * May be useful for own purposes. + * + * To see the output inside an office environment + * use "soffice ...params... >output.txt" + */ + private final long m_nStart; + private long m_nLast ; + + private void measure( String sText ) + { + long nNow = System.currentTimeMillis(); + System.err.println(sText+"\t"+(nNow-m_nStart)+"\t"+(nNow-m_nLast)); + m_nLast = nNow; + } + + + // native interface + /** + * The constructor to initialize every instance + * + * @param Context + * the component context of the office + */ + public _AsciiReplaceFilter(XComponentContext Context ) + { + measure("ctor started"); + try + { + m_Ctx = Context ; + m_xMCF = m_Ctx.getServiceManager() ; + } + catch( Exception e ) + { + e.printStackTrace(); + } + + // these are safe, thus no errorhandling needed: + m_sInternalName = "" ; + m_xDocument = null ; + m_bImport = true ; + m_nFilterProcState = FILTERPROC_STOPPED ; + + m_nLast = System.currentTimeMillis(); + m_nStart = m_nLast; + } + + + // interface XInitialization + /** + * used for initializing after creation + * If an instance of this service is created by UNO we will be called + * automatically after that to get optional parameters of this creation call. + * E.g.: The service com.sun.star.document.FilterFactory use such mechanism + * to pass our own configuration data to this instance. + * + * @param lArguments + * This array of arbitrary objects represent our own filter configuration + * and may optional given parameters of the createWithArguments() call. + * + * @throws com.sun.star.uno.Exception + * Every exception will not be handled, but will be + * passed to the caller. + */ + public void initialize( Object[] lArguments ) throws com.sun.star.uno.Exception + { + measure("initialize {"); + + if (lArguments.length<1) + return; + + // lArguments[0] = own configuration data + com.sun.star.beans.PropertyValue[] lConfig = (com.sun.star.beans.PropertyValue[])lArguments[0]; + + /* + // lArguments[1..n] = optional arguments of create request + for (int n=1; n<lArguments.length; ++n) + { + } + */ + + // analyze own configuration data for our own internal filter name! + // Important for generic filter services, which are registered more than once. + // They can use this information to find out, which specialization of it + // is required. + for (int i=0; i<lConfig.length; ++i) + { + if (lConfig[i].Name.equals("Name")) + { + synchronized(this) + { + try + { + m_sInternalName = AnyConverter.toString(lConfig[i].Value); + } + catch(com.sun.star.lang.IllegalArgumentException exConvert) {} + } + } + } + + measure("} initialize"); + } + + + // interface XNamed + /** + * For external user of us we must provide our internal filter name + * (which is registered inside configuration package TypeDetection). + * User will be able then to ask there for further information about us. + * Otherwise we must implement a full featured XPropertySet... + * + * @return our internal filter name of configuration + */ + public String getName() + { + synchronized(this) + { + return m_sInternalName; + } + } + + /** + * It's not allowed for us - neither very easy to change our internal + * name during runtime of an office. Because every filter name must + * be unambiguous... + * So we don't implement this method here. + */ + public void setName( String sName ) + { + } + + + // interface XImporter + /** + * This interface is used to tell us: "you will be used for importing a document". + * We must save the given model reference to use it inside our own filter request. + * + * @param xDocument + * the document model for importing + * + * @throw IllegalArgumentException + * if given document isn't the right one or seems to be corrupt + */ + public void setTargetDocument( com.sun.star.lang.XComponent xDocument ) throws com.sun.star.lang.IllegalArgumentException + { + measure("setTargetDocument {"); + + if (xDocument==null) + throw new com.sun.star.lang.IllegalArgumentException("null reference detected"); + + com.sun.star.lang.XServiceInfo xInfo = UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo.class, xDocument); + if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") ) + throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" ); + + // safe it as target document for import + // Don't forget to mark this filter used for importing too + synchronized(this) + { + m_xDocument = UnoRuntime.queryInterface( + com.sun.star.text.XTextDocument.class, xDocument); + m_bImport = true; + } + + measure("} setTargetDocument"); + } + + + // interface XExporter + /** + * This interface is used to tell us: "you will be used for exporting a document". + * We must save the given model reference to use it inside our own filter request. + * + * @param xDocument + * the document model for exporting + * + * @throw IllegalArgumentException + * if given document isn't the right one or seems to be corrupt + */ + public void setSourceDocument( com.sun.star.lang.XComponent xDocument ) throws com.sun.star.lang.IllegalArgumentException + { + measure("setSourceDocument {"); + + if (xDocument==null) + throw new com.sun.star.lang.IllegalArgumentException( "null reference given" ); + + com.sun.star.lang.XServiceInfo xInfo = UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo.class, xDocument); + if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") ) + throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" ); + + // safe it as source document for export + // Don't forget to mark this filter used for exporting too + synchronized(this) + { + m_xDocument = UnoRuntime.queryInterface( + com.sun.star.text.XTextDocument.class, xDocument); + m_bImport = false; + } + + measure("} setSourceDocument"); + } + + + + // interface XFilter + /** + * Implements the real filter method. We detect if it must be an import or an export. + * Depends on that we use an existing stream (given inside the MediaDescriptor) + * or open it by using a URL (must be a part of the descriptor too). + * + * @param lDescriptor + * the MediaDescriptor which describes the document + * + * @return a bool value which describes if method was successful. + */ + + public boolean filter( com.sun.star.beans.PropertyValue[] lDescriptor ) + { + measure("filter {"); + + // first get state of filter operation (import/export) + // and try to create or get corresponding streams + // Means: analyze given MediaDescriptor + // By the way: use synchronized section to get some copies of other + // internal states too. + FilterOptions aOptions = null ; + boolean bImport = false; + com.sun.star.text.XTextDocument xText = null ; + synchronized(this) + { + aOptions = new FilterOptions(m_xMCF, m_Ctx, m_bImport, lDescriptor); + bImport = m_bImport; + xText = m_xDocument; + } + + measure("options analyzed"); + + if (!aOptions.isValid()) + return false; + + // start real filtering + boolean bState = false; + if (bImport) + bState = implts_import( xText, aOptions ); + else + bState = implts_export( xText, aOptions ); + + measure("} filter"); + + return bState; + } + + /** + * Makes the filter process breakable. To do so the outside code may use threads. + * We use an internal "condition" variable which is queried by the real filter method on + * every loop they do. So it's more a polling mechanism. + */ + public void cancel() + { + measure("cancel {"); + + synchronized(this) + { + if (m_nFilterProcState==FILTERPROC_RUNS) + m_nFilterProcState=FILTERPROC_BREAK; + } + + while (true) + { + synchronized(this) + { + if (m_nFilterProcState==FILTERPROC_STOPPED) + break; + } + } + + measure("} cancel"); + } + + + // private helper + /** + * This helper function imports a simple ascii text file into + * a text model. We copy every letter to the document. + * But if some optional filter options are given + * we make some changes: replace chars or complete strings. + * + * Note: It's not allowed for a filter to seek inside the stream. + * Because the outside frameloader has to set the stream position + * right and a filter must read till EOF occurs only. + * + * @param xTarget + * the target text model to put the data in + * + * @param aOptions + * capsulate all other necessary information for this filter request + * (streams, replace values ...) + * + * @return a bool value which describes if method was successful. + */ + private boolean implts_import( com.sun.star.text.XTextDocument xTarget , + FilterOptions aOptions ) + { + measure("implts_import {"); + + com.sun.star.text.XSimpleText xText = UnoRuntime.queryInterface( + com.sun.star.text.XSimpleText.class, + xTarget.getText()); + + measure("cast XSimpleText"); + + boolean bBreaked = false; + + try + { + StringBuffer sBuffer = new StringBuffer(100000); + byte[][] lData = new byte[1][]; + int nRead = aOptions.m_xInput.readBytes( lData, 4096 ); + + measure("read first bytes"); + + while (nRead>0 && !bBreaked) + { + // copy data from stream to temp. buffer + sBuffer.append( new String(lData[0]) ); + measure("buffer append ["+nRead+"]"); + + nRead = aOptions.m_xInput.readBytes( lData, 2048 ); + measure("read next bytes"); + + // check for cancelled filter proc on every loop! + synchronized(this) + { + if (m_nFilterProcState==FILTERPROC_BREAK) + { + m_nFilterProcState = FILTERPROC_STOPPED; + return false; + } + } + measure("break check"); + } + + // Make some replacements inside the buffer. + String sText = implts_replace( sBuffer, aOptions ); + measure("replace"); + + // copy current buffer to the document model. + // Create a new paragraph for every line inside original file. + // May not all data could be read - but that doesn't matter here. + // Reason: somewhere cancelled this function. + // But check for optional replace request before... + int nStart = 0; + int nEnd = -1; + int nLength = sText.length(); + + com.sun.star.text.XTextRange xCursor = UnoRuntime.queryInterface( + com.sun.star.text.XTextRange.class, + xText.createTextCursor()); + + while (true) + { + nEnd = sText.indexOf('\n',nStart); + + if (nEnd==-1 && nStart<nLength) + nEnd = nLength; + + if (nEnd==-1) + break; + + String sLine = sText.substring(nStart,nEnd); + nStart = nEnd+1; + + xText.insertString(xCursor,sLine,false); + xText.insertControlCharacter(xCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false); + + // check for cancelled filter proc on every loop! + synchronized(this) + { + if (m_nFilterProcState==FILTERPROC_BREAK) + { + m_nFilterProcState = FILTERPROC_STOPPED; + return false; + } + } + measure("break check"); + } + + measure("set on model"); + + // with refreshing the document we are on the safe-side, otherwise the first time the filter is used the document is not fully shown (flaw!). + com.sun.star.util.XRefreshable xRefresh = UnoRuntime.queryInterface( + com.sun.star.util.XRefreshable.class, + xTarget); + xRefresh.refresh(); + + // If we created used stream - we must close it too. + if (aOptions.m_bStreamOwner) + { + aOptions.m_xInput.closeInput(); + measure("stream close"); + } + } + catch(com.sun.star.lang.IllegalArgumentException exArgument ) { bBreaked = true; } + catch(com.sun.star.io.BufferSizeExceededException exExceed ) { bBreaked = true; } + catch(com.sun.star.io.NotConnectedException exConnect ) { bBreaked = true; } + catch(com.sun.star.io.IOException exIO ) { bBreaked = true; } + + + + measure("} implts_import"); + + return !bBreaked; + } + + /** + * This helper function exports a simple ansi text file from + * a text model. We copy every letter from the document. + * There are no checks. + * + * Note: It's not allowed for a filter to seek inside the stream. + * Because the outside frameloader has to set the stream position + * right and a filter must read till EOF occurs only. + * + * @param xSource + * the source text model to get the data from + * + * @param aOptions + * capsulate all other necessary information for this filter request + * (streams, replace values ...) + * + * @return a bool value which describes if method was successful. + */ + private boolean implts_export( com.sun.star.text.XTextDocument xSource , + FilterOptions aOptions) + { + measure("implts_export {"); + + com.sun.star.text.XTextRange xText = UnoRuntime.queryInterface( + com.sun.star.text.XSimpleText.class, + xSource.getText()); + + measure("cast XTextRange"); + + boolean bBreaked = false; + + try + { + StringBuffer sBuffer = new StringBuffer(xText.getString()); + String sText = implts_replace(sBuffer,aOptions); + + measure("get text from model"); + + // Normally this function isn't really cancelable + // But we following operation can be very expensive. So + // this place is the last one to stop it. + synchronized(this) + { + if (m_nFilterProcState==FILTERPROC_BREAK) + { + m_nFilterProcState = FILTERPROC_STOPPED; + return false; + } + } + + aOptions.m_xOutput.writeBytes(sText.getBytes()); + aOptions.m_xOutput.flush(); + + measure("written to file"); + + // If we created used stream - we must close it too. + if (aOptions.m_bStreamOwner) + { + aOptions.m_xOutput.closeOutput(); + measure("stream close"); + } + } + catch(com.sun.star.io.BufferSizeExceededException exExceed ) { bBreaked = true; } + catch(com.sun.star.io.NotConnectedException exConnect ) { bBreaked = true; } + catch(com.sun.star.io.IOException exIO ) { bBreaked = true; } + + measure("} implts_export"); + + return !bBreaked; + } + + /** + * helper function to convert the used StringBuffer into a String value. + * And we use this chance to have a look on optional filter options + * which can invite replacing of strings. + */ + private String implts_replace( StringBuffer rBuffer, FilterOptions aOptions ) + { + // replace complete strings first + // Because its easier on a buffer then on a string + if ( ! aOptions.m_sOld.equals(aOptions.m_sNew) ) + { + int nStart = rBuffer.indexOf(aOptions.m_sOld); + int nLength = aOptions.m_sNew.length(); + int nEnd = nStart+nLength; + while (nStart!=-1) + { + rBuffer.replace(nStart,nEnd,aOptions.m_sNew); + nStart = rBuffer.indexOf(aOptions.m_sOld,nEnd); + nEnd = nStart+nLength; + } + } + + // convert buffer into return format [string] + // and convert to lower or upper case if required. + String sResult = rBuffer.toString(); + if (aOptions.m_bCaseChange) + { + if (aOptions.m_bLower) + sResult = sResult.toLowerCase(); + else + sResult = sResult.toUpperCase(); + } + + return sResult; + } + + + + // interface XServiceInfo + /** + * This method returns an array of all supported service names. + * + * @return Array of supported service names. + */ + public String[] getSupportedServiceNames() + { + return m_serviceNames; + } + + /** + * This method returns true, if the given service will be + * supported by this component. + * + * @param sService + * the requested service name + * + * @return True, if the given service name will be supported; + * False otherwise. + */ + public boolean supportsService( String sService ) + { + return ( + sService.equals( m_serviceNames[0] ) || + sService.equals( m_serviceNames[1] ) || + sService.equals( m_serviceNames[2] ) + ); + } + + /** + * Return the real class name of the component + * + * @return Class name of the component. + */ + public String getImplementationName() + { + return _AsciiReplaceFilter.class.getName(); + } + + + } + // end of inner class, the wrapper class just has the two methods required for registering the component + + /** + * Gives a factory for creating the service. + * This method is called by the <code>JavaLoader</code> + * + * @param sImplName + * The implementation name of the component. + * + * @return Returns a <code>XSingleComponentFactory</code> for + * creating the component. + * + * @see com.sun.star.comp.loader.JavaLoader + */ + + public static XSingleComponentFactory __getComponentFactory(String sImplName) + { + XSingleComponentFactory xFactory = null; + + if ( sImplName.equals( _AsciiReplaceFilter.class.getName() ) ) + xFactory = com.sun.star.lib.uno.helper.Factory.createComponentFactory(_AsciiReplaceFilter.class, + _AsciiReplaceFilter.m_serviceNames); + return xFactory; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java new file mode 100644 index 000000000..18c45da85 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java @@ -0,0 +1,225 @@ +/* -*- 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. + * + *************************************************************************/ + +package FilterDevelopment.AsciiFilter; + +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; + +/*-************************************************************************ + @title helper to analyze necessary option properties of our filter + @description Our filter needs some necessary properties for working: + - a stream for input or output + - or a URL for creating such streams + - information about required action on filtering + + @attention This class mustn't be threadsafe - because instances of it + are used temp. only - not as members. So no concurrent access + should occur. + Another reason: it would be very difficult to safe every + access on our internal member. To do so - we must implement + special methods instead of allowing pure member access. + ************************************************************************-*/ + +public class FilterOptions +{ + + // public member to provide these options to our outside filter class + public com.sun.star.io.XInputStream m_xInput ; + public com.sun.star.io.XOutputStream m_xOutput ; + public boolean m_bStreamOwner ; + private String m_sURL ; + public String m_sOld ; + public String m_sNew ; + public boolean m_bCaseChange ; + public boolean m_bLower ; + + + // private members for internal things + private final XMultiComponentFactory m_xMCF; + private final XComponentContext m_Ctx; + + + // interface + /** + * creates a new instance of this class + * It use the given MediaDescriptor to find right + * properties for initialization of the internal members. + * To do so it use another interface method analyze() + * which can be used after creation of an object instance + * to set a new descriptor here. + * + * @param xMCF + * we need it to create special help service top open + * streams in case they are not already a part of given + * MediaDescriptor + * + * @param bImport + * we must know which stream member should be valid initialized + * + * @param lDescriptor + * the initial MediaDescriptor to set internal member from it + */ + public FilterOptions( XMultiComponentFactory xMCF , + XComponentContext Context , + boolean bImport , + com.sun.star.beans.PropertyValue[] lDescriptor ) + { + m_xMCF = xMCF; + m_Ctx = Context; + analyze(bImport, lDescriptor); + } + + /** + * analyze given MediaDescriptor to find values for our internal member + * It reset all members to defaults before - to prevent us against + * mixed descriptor values! + * + * @param bImport + * we must know which stream member should be valid initialized + * + * @param lDescriptor + * the new MediaDescriptor to set internal member from it + */ + private void analyze( boolean bImport , + com.sun.star.beans.PropertyValue[] lDescriptor ) + { + m_xInput = null ; + m_xOutput = null ; + m_bStreamOwner = false ; + m_sURL = null ; + m_sOld = ""; + m_sNew = ""; + m_bCaseChange = false ; + m_bLower = false ; + + for ( int i=0; i<lDescriptor.length; ++i ) + { + try + { + if (lDescriptor[i].Name.equals("FileName")) + m_sURL = AnyConverter.toString(lDescriptor[i].Value); + else + if (lDescriptor[i].Name.equals("InputStream")) + m_xInput = (com.sun.star.io.XInputStream)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.io.XInputStream.class), lDescriptor[i].Value); + else + if (lDescriptor[i].Name.equals("OutputStream")) + m_xOutput = (com.sun.star.io.XOutputStream)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.io.XOutputStream.class), lDescriptor[i].Value); + else + if (lDescriptor[i].Name.equals("FilterData")) + { + com.sun.star.beans.PropertyValue[] lFilterProps = (com.sun.star.beans.PropertyValue[])AnyConverter.toArray(lDescriptor[i].Value); + int nCount = lFilterProps.length; + for (int p=0; p<nCount; ++p) + { + if (lFilterProps[p].Name.equals("OldString")) + m_sOld = AnyConverter.toString(lFilterProps[p].Value); + else + if (lFilterProps[p].Name.equals("NewString")) + m_sNew = AnyConverter.toString(lFilterProps[p].Value); + else + if (lFilterProps[p].Name.equals("LowerCase")) + { + m_bLower = AnyConverter.toBoolean(lFilterProps[p].Value); + m_bCaseChange = true; // Set it after m_bLower - because an exception can occur and we must use default values then! + } + } + } + } + catch(com.sun.star.lang.IllegalArgumentException exConvert) + { + // ONE argument has the wrong type + // But I think we mustn't react here - because we set + // default values for every necessary item we need. + // In case this exception occurs - this default exist + // and we can live with it. + } + } + + // Decide if it's necessary AND possible to open streams. + // Outside user can check for valid FilterOptions by using + // corresponding method isValid(). So it's not necessary to + // handle this error here in any case. + if (m_xInput==null && m_xOutput==null && m_sURL!=null) + impl_openStreams(bImport); + } + + /** + * with this method it's possible for the outside filter to decide + * if he can use this FilterOptions really or not. + * That means especially if necessary streams are available or not. + */ + public boolean isValid() + { + return(m_xInput!=null || m_xOutput!=null); + } + + + // helper + /** + * In case we couldn't found any valid stream inside the given MediaDescriptor, + * we must create it. Then we use a special helper service in combination + * with an existing URL to open a stream for reading or writing. It depends + * from given parameter bImport. + * + * Note: This method doesn't check for a valid URL. It must be done before. + * + * @param bImport + * indicates which stream member must be valid as result of this call + */ + private void impl_openStreams( boolean bImport ) + { + try{ + com.sun.star.ucb.XSimpleFileAccess xHelper = UnoRuntime.queryInterface( + com.sun.star.ucb.XSimpleFileAccess.class, + m_xMCF.createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_Ctx)); + if (xHelper!=null) + { + if (bImport) + m_xInput = xHelper.openFileRead(m_sURL); + else + m_xOutput = xHelper.openFileWrite(m_sURL); + } + + m_bStreamOwner = (m_xInput!=null || m_xOutput!=null); + } + catch(com.sun.star.ucb.CommandAbortedException exAborted) {} + catch(com.sun.star.uno.Exception exUno ) {} + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile new file mode 100644 index 000000000..507f6cac4 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile @@ -0,0 +1,139 @@ +#************************************************************************* +# +# 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 OfficeDevFilter example of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +SAMPLE_NAME=OfficeDevAsciiFilterExample +SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME) +SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME) + +COMP_NAME=SampleFilter +COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(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 = $(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME) +COMP_MANIFESTFILE = $(SAMPLE_GEN_OUT)/$(COMP_NAME).uno.Manifest +COMP_UNOPKG_MANIFEST = $(SAMPLE_GEN_OUT)/$(COMP_NAME)/META-INF/manifest.xml +COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_component.flag +COMP_COMPONENTS=$(COMP_NAME).components + +# often the java files are structured in a hierarchy similar to the package, +# for the example we know the package +PACKAGE = OfficeDev/samples/Filter + +COMP_JAVAFILES = \ + FilterOptions.java \ + AsciiReplaceFilter.java + +COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/$(PACKAGE)/%.class,$(COMP_JAVAFILES)) + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(COMP_CLASS_OUT)) + + +# Targets +.PHONY: ALL +ALL : $(SAMPLE_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(SAMPLE_GEN_OUT)/%.Manifest : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo RegistrationClassName: $(subst /,.,$(PACKAGE)).AsciiReplaceFilter> $@ + +$(COMP_CLASSFILES) : $(COMP_JAVAFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES) + +# rule for component jar file +$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMP_CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) . + +# rule for component package manifest +$(SAMPLE_GEN_OUT)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @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)TypeDetection.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) TypeDetection.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_ZIP) $@ TypeDetection.xcu + $(SDK_ZIP) -u $@ $(COMP_COMPONENTS) + cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F) + cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(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 + +$(SAMPLE_NAME) : $(COMP_REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The "$(QM)$(COMP_NAME)$(QM)" Java component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You can use the "$(QM)ASCII Replace$(QM)" filter in your office installation, see the + @echo example description. + @echo -------------------------------------------------------------------------------- + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/SampleFilter.components b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/SampleFilter.components new file mode 100644 index 000000000..6b2545df9 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/SampleFilter.components @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components xmlns="http://openoffice.org/2010/uno-components"> + <component loader="com.sun.star.loader.Java2" uri="SampleFilter.uno.jar"> + <implementation name="FilterDevelopment.AsciiFilter.AsciiReplaceFilter$_AsciiReplaceFilter"> + <service name="com.sun.star.comp.ansifilter.AsciiReplaceFilter"/> + <service name="com.sun.star.document.ImportFilter"/> + <service name="com.sun.star.document.ExportFilter"/> + </implementation> + </component> +</components> diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu new file mode 100644 index 000000000..c2eb32ef2 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="TypeDetection" oor:package="org.openoffice.Office"> + <node oor:name="Types"> + <node oor:name="ascii" oor:op="replace"> + <prop oor:name="Data" oor:type="xs:string"> + <value>0,text/plain,,,txt,0</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">ASCII</value> + </prop> + </node> + </node> + <node oor:name="Filters"> + <node oor:name="Ascii_Replace" oor:op="replace"> + <prop oor:name="Data" oor:type="xs:string"> + <value>0,ascii,com.sun.star.text.TextDocument,com.sun.star.comp.ansifilter.AsciiReplaceFilter,268959747,,0,,</value> + </prop> + <prop oor:name="Installed" oor:type="xs:boolean"> + <value>true</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="en-US">ASCII Replace</value> + <value xml:lang="de">ASCII Konvertierung</value> + </prop> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu new file mode 100644 index 000000000..2ac9a2440 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd"> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Types"> + <node oor:name="Types"> + <node oor:name="devguide_FlatXMLType_Cpp_calc" oor:op="replace"> + <prop oor:name="UIOrder"><value>0</value></prop> + <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>fods</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_calc</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">DevGuide FlatXML Calc</value> + </prop> + <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop> + </node> + <node oor:name="devguide_FlatXMLType_Cpp_draw" oor:op="replace"> + <prop oor:name="UIOrder"><value>0</value></prop> + <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>fodg</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_draw</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">DevGuide FlatXML Draw</value> + </prop> + <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop> + </node> + <node oor:name="devguide_FlatXMLType_Cpp_impress" oor:op="replace"> + <prop oor:name="UIOrder"><value>0</value></prop> + <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>fodp</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_impress</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">DevGuide FlatXML Impress</value> + </prop> + <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop> + </node> + <node oor:name="devguide_FlatXMLType_Cpp_writer" oor:op="replace"> + <prop oor:name="UIOrder"><value>0</value></prop> + <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>fodt</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_writer</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">DevGuide FlatXML Writer</value> + </prop> + <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop> + </node> + <node oor:name="devguide_FlatXMLType_Cpp_master" oor:op="replace"> + <prop oor:name="UIOrder"><value>0</value></prop> + <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>fodm</value></prop> + <prop oor:name="MediaType"/> + <prop oor:name="Preferred"><value>false</value></prop> + <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_master</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">DevGuide FlatXML Master</value> + </prop> + <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile new file mode 100644 index 000000000..2a9e24186 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile @@ -0,0 +1,155 @@ +#************************************************************************* +# +# 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 filterdetection component for the FlatXmlFilter of the Developers Guide. + +PRJ=../../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +COMP_NAME=FlatXmlTypeDetection +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) +COMP_RDB_NAME = $(COMP_NAME).uno.rdb +COMP_RDB = $(OUT_COMP_GEN)/$(COMP_RDB_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml +COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components + +REGISTERFLAG = $(OUT_MISC)/devguide_$(COMP_NAME)_register_component.flag + +CXXFILES = filterdetect.cxx \ + fdcomp.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + XMLFilterDetect + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib $(LIBO_SDK_LDFLAGS_STDLIBS) + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +# rule for component package manifest +$(OUT_COMP_GEN)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @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)FlatXmlTypeDetection.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +$(COMP_COMPONENTS) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)devguide.officedev.samples.filter.FlatXmlDetect$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)com.sun.star.document.ExtendedTypeDetection$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlTypeDetection.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(SDK_ZIP) $@ FlatXmlTypeDetection.xcu + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_NAME).components + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F) + cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(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 + +XMLFilterDetect : $(REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The FlatXMLFilterDetection component is installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You will use this component implicitly in your office installation when you have + @echo installed a FlatXMLFilter component C++ or Java. + @echo -------------------------------------------------------------------------------- + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_COMPONENTS)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx new file mode 100644 index 000000000..37b7a9360 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#include <stdio.h> + +#include <osl/mutex.hxx> +#include <osl/thread.h> +#include <uno/lbnames.h> +#include <cppuhelper/factory.hxx> +#include <com/sun/star/lang/XSingleComponentFactory.hpp> + +#include "filterdetect.hxx" + +using namespace ::rtl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; + +extern "C" +{ +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + OUString implName = OUString::createFromAscii( pImplName ); + if ( pServiceManager && implName.equals(FilterDetect_getImplementationName()) ) + { + Reference< XSingleComponentFactory > xFactory( createSingleComponentFactory( + FilterDetect_createInstance, + OUString::createFromAscii( pImplName ), + FilterDetect_getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + return pRet; +} + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx new file mode 100644 index 000000000..f51e29941 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx @@ -0,0 +1,239 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#include "filterdetect.hxx" +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/InputSource.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/xml/XImportFilter.hpp> +#include <com/sun/star/xml/XExportFilter.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/task/XStatusIndicatorFactory.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/XStyleLoader.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <cppuhelper/supportsservice.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star::document; +using namespace com::sun::star::lang; +using namespace com::sun::star::io; +using namespace com::sun::star::beans; +using namespace com::sun::star::xml::sax; +using namespace com::sun::star::xml; +using namespace com::sun::star::task; +using namespace com::sun::star::frame; +using namespace com::sun::star::container; +using namespace com::sun::star::ucb; + +using ::rtl::OUString; +using ::rtl::OString; + + +OUString SAL_CALL FilterDetect::detect(Sequence< PropertyValue >& aArguments ) +{ + // type name to return + OUString sOriginalTypeName; + OUString sTypeName; + OUString sURL; + // stream of the document to be detected + Reference< XInputStream > xInStream; + for ( sal_Int32 i = 0 ; i < aArguments.getLength(); i++) + { + OUString aName = aArguments[i].Name; + if ( aName == "TypeName" ) + aArguments[i].Value >>= sOriginalTypeName; + if ( aName == "URL" ) + aArguments[i].Value >>= sURL; + if ( aName == "InputStream" ) + aArguments[i].Value >>= xInStream; + } + + if (!xInStream.is()) + { + // open the stream if it was not supplied by the framework + Reference< XSimpleFileAccess3 > xSFI(SimpleFileAccess::create(mxContext)); + if (sURL.getLength() > 0) + { + try + { + xInStream = xSFI->openFileRead( sURL); + } + catch( Exception& ) + { + return sTypeName; + } + } else { + // failed to access UCB + return sTypeName; + } + } + + // flatxml starts with an office:document element. this element + // contains a class="..." attribute by which we can deduct the + // type of document that is to be loaded + + // WARNING: + // parsing the plain text of the document is an easy way to do this + // but not the purest solution, since namespaces and other xml details + // may lead to another syntactic expression of the same document. + // this example works for the way the office serializes its XML stream + // but might need extension for other data sources... + static OString aDocToken("office:document"); + // static OString aClassToken("office:class=\""); + static OString aMimeTypeToken("office:mimetype=\""); + + sal_Int32 nHeadSize = 4096; + Sequence< sal_Int8 > aHeadData(nHeadSize); + + // rewind seekable stream + Reference< XSeekable > xSeek(xInStream, UNO_QUERY); + if (xSeek.is()) + xSeek->seek(0); + + long bytestRead = xInStream->readBytes(aHeadData, nHeadSize); + + OString aHead = OString((const char *)aHeadData.getConstArray(), bytestRead).toAsciiLowerCase(); + + // check for document element of flatxml format + if (aHead.indexOf(aDocToken) >= 0) + { + // read document class + sal_Int32 n = aHead.indexOf(aMimeTypeToken); + if (n >= 0) + { + n += aMimeTypeToken.getLength(); + OString aMimeType = aHead.copy(n, aHead.indexOf('\"', n) - n); + // return type for class found + if (aMimeType.equals("application/x-vnd.oasis.opendocument.text") || + aMimeType.equals("application/vnd.oasis.opendocument.text")) + sTypeName = "devguide_FlatXMLType_Cpp_writer"; + else if (aMimeType.equals("application/x-vnd.oasis.opendocument.text-master") || + aMimeType.equals("application/vnd.oasis.opendocument.text-master")) + sTypeName = "devguide_FlatXMLType_Cpp_master"; + else if (aMimeType.equals("application/x-vnd.oasis.openoffice.text-global") || + aMimeType.equals("application/vnd.oasis.openoffice.text-global")) + sTypeName = "devguide_FlatXMLType_Cpp_master"; + else if (aMimeType.equals("application/x-vnd.oasis.opendocument.spreadsheet") || + aMimeType.equals("application/vnd.oasis.opendocument.spreadsheet")) + sTypeName = "devguide_FlatXMLType_Cpp_calc"; + else if (aMimeType.equals("application/x-vnd.oasis.opendocument.drawing") || + aMimeType.equals("application/vnd.oasis.opendocument.drawing")) + sTypeName = "devguide_FlatXMLType_Cpp_draw"; + else if (aMimeType.equals("application/x-vnd.oasis.opendocument.presentation") || + aMimeType.equals("application/vnd.oasis.opendocument.presentation")) + sTypeName = "devguide_FlatXMLType_Cpp_impress"; + } + } + return sTypeName; +} + + +// XInitialization +void SAL_CALL FilterDetect::initialize( const Sequence< Any >& aArguments ) +{ + Sequence < PropertyValue > aAnySeq; + sal_Int32 nLength = aArguments.getLength(); + if ( nLength && ( aArguments[0] >>= aAnySeq ) ) + { + const PropertyValue * pValue = aAnySeq.getConstArray(); + nLength = aAnySeq.getLength(); + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + if ( pValue[i].Name == "Type" ) + { + pValue[i].Value >>= msFilterName; + } + else if ( pValue[i].Name == "UserData" ) + { + pValue[i].Value >>= msUserData; + } + else if ( pValue[i].Name == "TemplateName" ) + { + pValue[i].Value>>=msTemplateName; + } + } + } +} + +OUString FilterDetect_getImplementationName () +{ + return OUString( "devguide.officedev.samples.filter.FlatXmlDetect" ); +} + +#define SERVICE_NAME1 "com.sun.star.document.ExtendedTypeDetection" + +Sequence< OUString > SAL_CALL FilterDetect_getSupportedServiceNames( ) +{ + Sequence < OUString > aRet(2); + OUString* pArray = aRet.getArray(); + pArray[0] = OUString ( SERVICE_NAME1 ); + return aRet; +} +#undef SERVICE_NAME1 +#undef SERVICE_NAME2 + +Reference< XInterface > SAL_CALL FilterDetect_createInstance( const Reference< XComponentContext > & rContext) +{ + return (cppu::OWeakObject*) new FilterDetect( rContext ); +} + +// XServiceInfo +OUString SAL_CALL FilterDetect::getImplementationName( ) +{ + return FilterDetect_getImplementationName(); +} + +sal_Bool SAL_CALL FilterDetect::supportsService( const OUString& rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > SAL_CALL FilterDetect::getSupportedServiceNames( ) +{ + return FilterDetect_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx new file mode 100644 index 000000000..cf17157e7 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#ifndef INCLUDED_EXAMPLES_OFFICEDEV_FILTERDEVELOPMENT_FLATXMLFILTERDETECTION_FILTERDETECT_HXX +#define INCLUDED_EXAMPLES_OFFICEDEV_FILTERDEVELOPMENT_FLATXMLFILTERDETECTION_FILTERDETECT_HXX + + +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase5.hxx> + +#include <cppuhelper/implbase3.hxx> + +namespace com { namespace sun { namespace star { namespace uno { + class XComponentContext; +} } } } + +enum FilterType +{ + FILTER_IMPORT, + FILTER_EXPORT +}; + +/* This component will be instantiated for both import or export. Whether it calls + * setSourceDocument or setTargetDocument determines which Impl function the filter + * member calls */ +class FilterDetect : public cppu::WeakImplHelper3 <com::sun::star::document::XExtendedFilterDetection, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc; + ::rtl::OUString msFilterName; + ::com::sun::star::uno::Sequence< ::rtl::OUString > msUserData; + ::rtl::OUString msTemplateName; + + sal_Bool SAL_CALL exportImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ); + + sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ); + +public: + FilterDetect( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &rxContext) + : mxContext( rxContext ) {} + + virtual ~FilterDetect() {} + + //XExtendedFilterDetection + virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& lDescriptor ); + + // XInitialization + + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); +}; + + +::rtl::OUString FilterDetect_getImplementationName(); + +sal_Bool SAL_CALL FilterDetect_supportsService( const ::rtl::OUString& ServiceName ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL FilterDetect_getSupportedServiceNames( ); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL FilterDetect_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rContext); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx new file mode 100644 index 000000000..8b53c0ad7 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; 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. + * + *************************************************************************/ + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <osl/diagnose.h> +#include <uno/lbnames.h> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + +#include <com/sun/star/beans/PropertyValue.hpp> + +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/xml/sax/InputSource.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/xml/XImportFilter.hpp> +#include <com/sun/star/xml/XExportFilter.hpp> + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <com/sun/star/io/XSeekable.hpp> + +using namespace ::rtl; +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::xml; +using namespace ::com::sun::star::xml::sax; + +namespace XFlatXml { + +class XFlatXml : public WeakImplHelper3< XImportFilter, XExportFilter, XDocumentHandler> +{ +private: + // the UNO ServiceFactory + Reference< XMultiServiceFactory > m_rServiceFactory; + + // DocumentHandler interface of the css::xml::sax::Writer service + Reference < XExtendedDocumentHandler > m_rDocumentHandler; + + // controls pretty-printing + sal_Bool m_bPrettyPrint; + +public: + + // ctor... + XFlatXml( const Reference< XMultiServiceFactory > &r ) + : m_rServiceFactory(r) + , m_bPrettyPrint(sal_True) + {} + + // XImportFilter + virtual sal_Bool SAL_CALL importer( + const Sequence<PropertyValue>& aSourceData, + const Reference<XDocumentHandler>& xHandler, + const Sequence<OUString>& msUserData); + + // XExportFilter + virtual sal_Bool SAL_CALL exporter( + const Sequence<PropertyValue>& aSourceData, + const Sequence<OUString>& msUserData); + + // XDocumentHandler + virtual void SAL_CALL startDocument(); + virtual void SAL_CALL endDocument(); + virtual void SAL_CALL startElement(const OUString& str, const Reference<XAttributeList>& attriblist); + virtual void SAL_CALL endElement(const OUString& str); + virtual void SAL_CALL characters(const OUString& str); + virtual void SAL_CALL ignorableWhitespace(const OUString& str); + virtual void SAL_CALL processingInstruction(const OUString& str, const OUString& str2); + virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator); +}; + +sal_Bool XFlatXml::importer( + const Sequence<PropertyValue>& aSourceData, + const Reference<XDocumentHandler>& xHandler, + const Sequence<OUString>& msUserData) +{ + // get information from media descriptor + // the input stream that represents the imported file + // is most important here since we need to supply it to + // the sax parser that drives the supplied document handler + sal_Int32 nLength = aSourceData.getLength(); + OUString aName, aFileName, aURL; + Reference< XInputStream > xInputStream; + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + aName = aSourceData[i].Name; + if ( aName == "InputStream" ) + aSourceData[i].Value >>= xInputStream; + else if ( aName == "FileName" ) + aSourceData[i].Value >>= aFileName; + else if ( aName == "URL" ) + aSourceData[i].Value >>= aURL; + } + + // we need an input stream + OSL_ASSERT(xInputStream.is()); + if (!xInputStream.is()) return sal_False; + + // rewind seekable stream + Reference< XSeekable > xSeek(xInputStream, UNO_QUERY); + if (xSeek.is()) + xSeek->seek(0); + + + // create SAX parser that will read the document file + // and provide events to xHandler passed to this call + Reference < XParser > xSaxParser( m_rServiceFactory->createInstance( + "com.sun.star.xml.sax.Parser"), UNO_QUERY ); + OSL_ASSERT(xSaxParser.is()); + if(!xSaxParser.is())return sal_False; + + // let the parser try to send the sax event to the document handler + try + { + InputSource aInput; + aInput.sSystemId = aURL; + aInput.sPublicId = aURL; + aInput.aInputStream = xInputStream; + xSaxParser->setDocumentHandler(xHandler); + xSaxParser->parseStream(aInput); + } + catch( Exception &exc) + { + // something went wrong + OSL_FAIL(rtl::OUStringToOString(exc.Message,RTL_TEXTENCODING_UTF8).getStr()); + return sal_False; + } + + // done + return sal_True; +} + +sal_Bool XFlatXml::exporter( + const Sequence<PropertyValue>& aSourceData, + const Sequence<OUString>& msUserData) +{ + + // read source data + // we are especially interested in the output stream + // since that is where our xml-writer will push the data + // from its data-source interface + OUString aName, sURL; + Reference<XOutputStream> rOutputStream; + sal_Int32 nLength = aSourceData.getLength(); + for ( sal_Int32 i = 0 ; i < nLength; i++) + { + aName = aSourceData[i].Name; + if ( aName == "OutputStream" ) + aSourceData[i].Value >>= rOutputStream; + else if ( aName == "URL" ) + aSourceData[i].Value >>= sURL; + } + + if (!m_rDocumentHandler.is()) { + // get the document writer + m_rDocumentHandler = Reference<XExtendedDocumentHandler>( + m_rServiceFactory->createInstance("com.sun.star.xml.sax.Writer"), + UNO_QUERY); + OSL_ASSERT(m_rDocumentHandler.is()); + if (!m_rDocumentHandler.is()) return sal_False; + } + // get data source interface ... + Reference< XActiveDataSource > rDataSource(m_rDocumentHandler, UNO_QUERY); + OSL_ASSERT(rDataSource.is()); + if (!rDataSource.is()) return sal_False; + OSL_ASSERT(rOutputStream.is()); + if (!rOutputStream.is()) return sal_False; + // ... and set output stream + rDataSource->setOutputStream(rOutputStream); + + return sal_True; +} + +// for the DocumentHandler implementation, we just proxy the +// events to the XML writer that we created upon the output stream +// that was provided by the XMLFilterAdapter +void XFlatXml::startDocument(){ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->startDocument(); +} + +void XFlatXml::endDocument(){ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->endDocument(); +} + +void XFlatXml::startElement(const OUString& str, const Reference<XAttributeList>& attriblist) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->startElement(str, attriblist); +} + +void XFlatXml::endElement(const OUString& str) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->endElement(str); +} + +void XFlatXml::characters(const OUString& str) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->characters(str); +} + +void XFlatXml::ignorableWhitespace(const OUString& str) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + if (!m_bPrettyPrint) return; + m_rDocumentHandler->ignorableWhitespace(str); +} + +void XFlatXml::processingInstruction(const OUString& str, const OUString& str2) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->processingInstruction(str, str2); +} + +void XFlatXml::setDocumentLocator(const Reference<XLocator>& doclocator) +{ + OSL_ASSERT(m_rDocumentHandler.is()); + m_rDocumentHandler->setDocumentLocator(doclocator); +} + + +// Component management + +Reference< XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r) +{ + return Reference< XInterface >(( OWeakObject *)new XFlatXml(r)); +} + +Sequence< OUString > getSupportedServiceNames() +{ + static Sequence < OUString > *pNames = 0; + if( ! pNames ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !pNames ) + { + static Sequence< OUString > seqNames(1); + seqNames.getArray()[0] = OUString( + "devguide.officedev.samples.filter.FlatXmlCpp"); + pNames = &seqNames; + } + } + return *pNames; +} + +} + +using namespace XFlatXml; +#define IMPLEMENTATION_NAME "devguide.officedev.samples.filter.FlatXmlCpp" + + +extern "C" +{ +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString::createFromAscii( pImplName ), + CreateInstance, getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + return pRet; +} + +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + char const ** ppEnvTypeName, uno_Environment **) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +} // extern "C" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu new file mode 100644 index 000000000..7113a16e1 --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd"> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Filter"> + <node oor:name="Filters"> + <node oor:name="devguide_FlatXMLFilter_Cpp_calc" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_calc</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Calc</value> + <value xml:lang="en-US">DevGuide FlatXML Calc</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Cpp_draw" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_draw</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.DrawingLayer.XMLOasisImporter,com.sun.star.comp.DrawingLayer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Draw</value> + <value xml:lang="en-US">DevGuide FlatXML Draw</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Cpp_impress" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_impress</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.presentation.PresentationDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Impress.XMLOasisImporter,com.sun.star.comp.Impress.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Impress</value> + <value xml:lang="en-US">DevGuide FlatXML Impress</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Cpp_writer" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_writer</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Writer</value> + <value xml:lang="en-US">DevGuide FlatXML Writer</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Cpp_master" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_master</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.text.GlobalDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Master</value> + <value xml:lang="en-US">DevGuide FlatXML Master</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile new file mode 100644 index 000000000..73e4b7e2a --- /dev/null +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile @@ -0,0 +1,153 @@ +#************************************************************************* +# +# 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 C++ 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_cpp +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml +COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components + +COMP_REGISTERFLAG = $(OUT_MISC)/devguide_$(COMP_NAME)_register_component.flag + +CXXFILES = FlatXml.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + +# Targets +.PHONY: ALL +ALL : \ + FlatXmlFilterCppExample + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) msvcprt.lib $(LIBO_SDK_LDFLAGS_STDLIBS) + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STC++LIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +# rule for component package manifest +$(OUT_COMP_GEN)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @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_cpp.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +$(COMP_COMPONENTS) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)devguide.officedev.samples.filter.FlatXmlCpp$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)devguide.officedev.samples.filter.FlatXmlCpp$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlFilter_cpp.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(SDK_ZIP) $@ FlatXmlFilter_cpp.xcu + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_NAME).components + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F) + cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(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 + +FlatXmlFilterCppExample : $(COMP_REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The C++ 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 -------------------------------------------------------------------------------- + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_COMPONENTS))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<components xmlns="http://openoffice.org/2010/uno-components"> + <component loader="com.sun.star.loader.Java2" uri="FlatXmlFilter_java.uno.jar"> + <implementation name="FlatXml"> + <service name="devguide.officedev.samples.filter.FlatXmlJava"/> + </implementation> + </component> +</components> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd"> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Filter"> + <node oor:name="Filters"> + <node oor:name="devguide_FlatXMLFilter_Java_calc" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_calc</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Calc</value> + <value xml:lang="en-US">DevGuide FlatXML Calc</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Java_draw" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_draw</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.DrawingLayer.XMLOasisImporter,com.sun.star.comp.DrawingLayer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Draw</value> + <value xml:lang="en-US">DevGuide FlatXML Draw</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Java_impress" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_impress</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.presentation.PresentationDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Impress.XMLOasisImporter,com.sun.star.comp.Impress.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Impress</value> + <value xml:lang="en-US">DevGuide FlatXML Impress</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Java_writer" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_writer</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Writer</value> + <value xml:lang="en-US">DevGuide FlatXML Writer</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + <node oor:name="devguide_FlatXMLFilter_Java_master" oor:op="replace"> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_master</value></prop> + <prop oor:name="DocumentService"><value>com.sun.star.text.GlobalDocument</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="UIName"> + <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. If it is not necessary. --> + <value xml:lang="x-no-translate"></value> + <value xml:lang="de">DevGuide FlatXML Master</value> + <value xml:lang="en-US">DevGuide FlatXML Master</value> + </prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop> + </node> + </node> +</oor:component-data> 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) $(<F) $($(basename $(basename $(@F)))_CLASSFILES) + +# rule for component package manifest +$(OUT_COMP_CLASS)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @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) $(<F) + cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(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))) |