summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment')
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java733
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java230
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile138
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu29
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu71
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile150
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx109
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx254
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx118
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx373
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml59
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu86
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile148
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java273
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu86
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile141
16 files changed, 2998 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 000000000000..24eb92a3109c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java
@@ -0,0 +1,733 @@
+/*************************************************************************
+ *
+ * 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 OfficeDev.samples.Filter;
+
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+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.Type;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.beans.PropertyValue;
+
+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;
+
+
+import com.sun.star.lang.IllegalArgumentException;
+
+/*-************************************************************************
+ @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 realy should
+ be used by selecting it in an extra filter property dialog.
+
+ So we show how a filter works fro iport/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
+ {
+ //______________________________
+ // const
+
+ // the supported service names, the first one being the service name of the component itself
+ public static final String[] m_serviceNames = { "com.sun.star.comp.ansifilter.AsciiReplaceFilter" , "com.sun.star.document.ImportFilter", "com.sun.star.document.ExportFilter" };
+
+ // filterprocess states
+ public static final int FILTERPROC_RUNS = 0;
+ public static final int FILTERPROC_BREAK = 1;
+ public 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 realy.
+ * May be usefully for own purposes.
+ *
+ * To see the output inside an office environment
+ * use "soffice ...params... >output.txt"
+ */
+ private 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 xCompContext
+ * the component context of the office
+ */
+ //ctor
+ 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 = new String() ;
+ 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
+ * automaticly 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 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 then 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 furthe information about us.
+ * Otherwhise 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 unambigous ...
+ * So we doesn'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 seams 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 = (com.sun.star.lang.XServiceInfo)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 = (com.sun.star.text.XTextDocument)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 seams 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 = (com.sun.star.lang.XServiceInfo)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 = (com.sun.star.text.XTextDocument)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 an 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 successfully or not.
+ */
+
+ 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()==false)
+ 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 a internal "condition" variable wich 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 alloed 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 occures only.
+ *
+ * @param xTarget
+ * the target text model to put the data in
+ *
+ * @param aOptions
+ * capsulate all other neccessary informations for this filter request
+ * (streams, replace values ...)
+ *
+ * @return a bool value which describes if method was successfully or not.
+ */
+ private boolean implts_import( com.sun.star.text.XTextDocument xTarget ,
+ FilterOptions aOptions )
+ {
+ measure("implts_import {");
+
+ com.sun.star.text.XSimpleText xText = (com.sun.star.text.XSimpleText)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 readed - but that doesn't matter here.
+ // Reason: somewhere cancelled this function.
+ // But check for optioanl replace request before ...
+ int nStart = 0;
+ int nEnd = -1;
+ int nLength = sText.length();
+
+ com.sun.star.text.XTextRange xCursor = (com.sun.star.text.XTextRange)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 = (com.sun.star.util.XRefreshable)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==true)
+ {
+ 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 alloed 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 occures only.
+ *
+ * @param xSource
+ * the source text model to get the data from
+ *
+ * @param aOptions
+ * capsulate all other neccessary informations for this filter request
+ * (streams, replace values ...)
+ *
+ * @return a bool value which describes if method was successfully or not.
+ */
+ private boolean implts_export( com.sun.star.text.XTextDocument xSource ,
+ FilterOptions aOptions)
+ {
+ measure("implts_export {");
+
+ com.sun.star.text.XTextRange xText = (com.sun.star.text.XSimpleText)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");
+
+ // Normaly this function isn't realy 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==true)
+ {
+ 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 Strig 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 easiear 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==true)
+ {
+ if (aOptions.m_bLower==true)
+ 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 otherwhise.
+ */
+ 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;
+ }
+
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>.
+ *
+ * @param xRegistryKey
+ * Makes structural information (except regarding tree
+ * structures) of a single registry key accessible.
+ *
+ * @return returns true if the operation succeeded
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo( com.sun.star.registry.XRegistryKey xRegistryKey )
+ {
+ return Factory.writeRegistryServiceInfo(
+ _AsciiReplaceFilter.class.getName(),
+ _AsciiReplaceFilter.m_serviceNames,
+ xRegistryKey );
+ }
+}
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 000000000000..013f93a304f5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java
@@ -0,0 +1,230 @@
+/*************************************************************************
+ *
+ * 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 OfficeDev.samples.Filter;
+
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+
+import com.sun.star.uno.Exception;
+import com.sun.star.ucb.CommandAbortedException;
+import com.sun.star.lang.IllegalArgumentException;
+
+/*-************************************************************************
+ @title helper to analyze neccessary option properties of our filter
+ @description Our filter needs some neccessary properties for working:
+ - a stream for input or output
+ - or an URL for creating such streams
+ - informations 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 occure.
+ Another reason: It wuold 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 ;
+ public 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 XMultiComponentFactory m_xMCF ;
+ private 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 xSMGR
+ * 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
+ */
+ public void analyze( boolean bImport ,
+ com.sun.star.beans.PropertyValue[] lDescriptor )
+ {
+ m_xInput = null ;
+ m_xOutput = null ;
+ m_bStreamOwner = false ;
+ m_sURL = null ;
+ m_sOld = new String();
+ m_sNew = new String();
+ 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 occure 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 setted
+ // default values for every neccessary item we need.
+ // In case this exception occures - this default exist
+ // and we can live with it.
+ }
+ }
+
+ // Decide if it's neccessary AND possible to open streams.
+ // Outside user can check for valid FilterOptions by using
+ // corresponding method isValid(). So it's not neccessary 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 realy or not.
+ * That means especialy if neccessary 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
+ * inidcates which stream member must be valid as result of this call
+ */
+ private void impl_openStreams( boolean bImport )
+ {
+ try{
+ com.sun.star.ucb.XSimpleFileAccess xHelper = (com.sun.star.ucb.XSimpleFileAccess)UnoRuntime.queryInterface(
+ com.sun.star.ucb.XSimpleFileAccess.class,
+ m_xMCF.createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_Ctx));
+ if (xHelper!=null)
+ {
+ if (bImport==true)
+ 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 ) {}
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile
new file mode 100644
index 000000000000..e84e53ed3fc0
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile
@@ -0,0 +1,138 @@
+#*************************************************************************
+#
+# 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
+include $(SETTINGS)/dk.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
+
+# 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-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) TypeDetection.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ TypeDetection.xcu
+ 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/TypeDetection.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu
new file mode 100644
index 000000000000..a03358394d72
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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. It 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 000000000000..67f8006db558
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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 000000000000..11a200398426
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile
@@ -0,0 +1,150 @@
+#*************************************************************************
+#
+# 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
+include $(SETTINGS)/dk.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_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
+
+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),$@) $<
+
+$(COMP_MAPFILE) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
+ifeq "$(OS)" "MACOSX"
+ nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
+endif
+
+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) $(STLPORTLIB) msvcrt.lib kernel32.lib
+ $(LINK_MANIFEST)
+else
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
+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-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlTypeDetection.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(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) $(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),$(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 000000000000..92c164d348c8
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx
@@ -0,0 +1,109 @@
+/*************************************************************************
+ *
+ * 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 <cppuhelper/factory.hxx>
+#include <com/sun/star/lang/XSingleServiceFactory.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"
+{
+//==================================================================================================
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+//==================================================================================================
+sal_Bool SAL_CALL component_writeInfo(
+ void * pServiceManager, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ Reference< XRegistryKey > xNewKey(
+ reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( FilterDetect_getImplementationName() ) );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+ const Sequence< OUString > & rSNL = FilterDetect_getSupportedServiceNames();
+ const OUString * pArray = rSNL.getConstArray();
+ for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+//==================================================================================================
+void * SAL_CALL component_getFactory(
+ const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void * pRet = 0;
+
+ OUString implName = OUString::createFromAscii( pImplName );
+ if ( pServiceManager && implName.equals(FilterDetect_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ FilterDetect_createInstance, FilterDetect_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+ return pRet;
+}
+
+}
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 000000000000..e7d49cb21a8c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx
@@ -0,0 +1,254 @@
+/*************************************************************************
+ *
+ * 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 <osl/diagnose.h>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#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/io/XInputStream.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+
+using namespace rtl;
+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;
+
+
+OUString SAL_CALL FilterDetect::detect(Sequence< PropertyValue >& aArguments )
+ throw( RuntimeException )
+{
+ // 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.equalsAscii("TypeName" ) )
+ aArguments[i].Value >>= sOriginalTypeName;
+ if (aName.equalsAscii("URL" ) )
+ aArguments[i].Value >>= sURL;
+ if (aName.equalsAscii("InputStream" ) )
+ aArguments[i].Value >>= xInStream;
+ }
+
+ if (!xInStream.is())
+ {
+ // open the stream if it was not suplied by the framework
+ Reference< XSimpleFileAccess > xSFI(mxMSF->createInstance(
+ OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
+ if (sURL.getLength() > 0 && xSFI.is())
+ {
+ 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
+ // conatains a clas="..." attribut 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 it's 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 sal_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 = OUString::createFromAscii("devguide_FlatXMLType_Cpp_writer");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.text-master") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.text-master"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_master");
+ else if (aMimeType.equals("application/x-vnd.oasis.openoffice.text-global") ||
+ aMimeType.equals("application/vnd.oasis.openoffice.text-global"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_master");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.spreadsheet") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.spreadsheet"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_calc");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.drawing") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.drawing"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_draw");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.presentation") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.presentation"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_impress");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.presentation") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.presentation"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_impress");
+ }
+ }
+ return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL FilterDetect::initialize( const Sequence< Any >& aArguments )
+ throw (Exception, RuntimeException)
+{
+ 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.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
+ {
+ pValue[i].Value >>= msFilterName;
+ }
+ else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "UserData" ) ) )
+ {
+ pValue[i].Value >>= msUserData;
+ }
+ else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TemplateName" ) ) )
+ {
+ pValue[i].Value>>=msTemplateName;
+ }
+ }
+ }
+}
+
+OUString FilterDetect_getImplementationName ()
+ throw (RuntimeException)
+{
+ return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "devguide.officedev.samples.filter.FlatXmlDetect" ) );
+}
+
+#define SERVICE_NAME1 "com.sun.star.document.ExtendedTypeDetection"
+
+sal_Bool SAL_CALL FilterDetect_supportsService( const OUString& ServiceName )
+ throw (RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) );
+}
+
+Sequence< OUString > SAL_CALL FilterDetect_getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ Sequence < OUString > aRet(2);
+ OUString* pArray = aRet.getArray();
+ pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
+ return aRet;
+}
+#undef SERVICE_NAME1
+#undef SERVICE_NAME2
+
+Reference< XInterface > SAL_CALL FilterDetect_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
+ throw( Exception )
+{
+ return (cppu::OWeakObject*) new FilterDetect( rSMgr );
+}
+
+// XServiceInfo
+OUString SAL_CALL FilterDetect::getImplementationName( )
+ throw (RuntimeException)
+{
+ return FilterDetect_getImplementationName();
+}
+
+sal_Bool SAL_CALL FilterDetect::supportsService( const OUString& rServiceName )
+ throw (RuntimeException)
+{
+ return FilterDetect_supportsService( rServiceName );
+}
+
+Sequence< OUString > SAL_CALL FilterDetect::getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ return FilterDetect_getSupportedServiceNames();
+}
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 000000000000..c0f423d5fd61
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx
@@ -0,0 +1,118 @@
+/*************************************************************************
+ *
+ * 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 _FILTERDETECT_HXX
+#define _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>
+
+#ifndef _CPPUHELPER_IMPLBASE4_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+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::lang::XMultiServiceFactory > mxMSF;
+ ::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 )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+ throw (::com::sun::star::uno::RuntimeException);
+
+public:
+ FilterDetect( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
+ : mxMSF( rxMSF ) {}
+
+ virtual ~FilterDetect() {}
+
+ //XExtendedFilterDetection
+ virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& lDescriptor )
+ throw( com::sun::star::uno::RuntimeException );
+
+ // XInitialization
+
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+ throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw (::com::sun::star::uno::RuntimeException);
+};
+
+
+::rtl::OUString FilterDetect_getImplementationName()
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL FilterDetect_supportsService( const ::rtl::OUString& ServiceName )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL FilterDetect_getSupportedServiceNames( )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL FilterDetect_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+ throw ( ::com::sun::star::uno::Exception );
+
+#endif
+
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 000000000000..b1cf3afbf536
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx
@@ -0,0 +1,373 @@
+/*************************************************************************
+ *
+ * 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/servicefactory.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#include <com/sun/star/lang/XComponent.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Type.hxx>
+
+#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)
+ throw(RuntimeException);
+
+ // XExportFilter
+ virtual sal_Bool SAL_CALL exporter(
+ const Sequence<PropertyValue>& aSourceData,
+ const Sequence<OUString>& msUserData)
+ throw(RuntimeException);
+
+ // XDocumentHandler
+ virtual void SAL_CALL startDocument()
+ throw (SAXException,RuntimeException);
+ virtual void SAL_CALL endDocument()
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
+ throw (SAXException,RuntimeException);
+ virtual void SAL_CALL endElement(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL characters(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL ignorableWhitespace(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL processingInstruction(const OUString& str, const OUString& str2)
+ throw (com::sun::star::xml::sax::SAXException,RuntimeException);
+ virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator)
+ throw (SAXException,RuntimeException);
+};
+
+sal_Bool XFlatXml::importer(
+ const Sequence<PropertyValue>& aSourceData,
+ const Reference<XDocumentHandler>& xHandler,
+ const Sequence<OUString>& msUserData)
+ throw (RuntimeException)
+{
+ // get information from media descriptor
+ // the imput 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.equalsAscii("InputStream"))
+ aSourceData[i].Value >>= xInputStream;
+ else if ( aName.equalsAscii("FileName"))
+ aSourceData[i].Value >>= aFileName;
+ else if ( aName.equalsAscii("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(
+ OUString::createFromAscii("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_ENSURE(0, exc.Message);
+ return sal_False;
+ }
+
+ // done
+ return sal_True;
+}
+
+sal_Bool XFlatXml::exporter(
+ const Sequence<PropertyValue>& aSourceData,
+ const Sequence<OUString>& msUserData)
+ throw (RuntimeException)
+{
+
+ // read source data
+ // we are especialy interested in the output stream
+ // since that is where our xml-writer will push the data
+ // from it's 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.equalsAscii("OutputStream"))
+ aSourceData[i].Value >>= rOutputStream;
+ else if ( aName.equalsAscii("URL" ))
+ aSourceData[i].Value >>= sURL;
+ }
+
+ if (!m_rDocumentHandler.is()) {
+ // get the document writer
+ m_rDocumentHandler = Reference<XExtendedDocumentHandler>(
+ m_rServiceFactory->createInstance(
+ OUString::createFromAscii("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 the
+// events to the XML writer that we created upon the output stream
+// that was provided by the XMLFilterAdapter
+void XFlatXml::startDocument() throw (SAXException,RuntimeException){
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->startDocument();
+}
+
+void XFlatXml::endDocument() throw (SAXException,RuntimeException){
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->endDocument();
+}
+
+void XFlatXml::startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->startElement(str, attriblist);
+}
+
+void XFlatXml::endElement(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->endElement(str);
+}
+
+void XFlatXml::characters(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->characters(str);
+}
+
+void XFlatXml::ignorableWhitespace(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ if (!m_bPrettyPrint) return;
+ m_rDocumentHandler->ignorableWhitespace(str);
+}
+
+void XFlatXml::processingInstruction(const OUString& str, const OUString& str2)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->processingInstruction(str, str2);
+}
+
+void XFlatXml::setDocumentLocator(const Reference<XLocator>& doclocator)
+ throw (SAXException, RuntimeException)
+{
+ 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::createFromAscii(
+ "devguide.officedev.samples.filter.FlatXmlCpp");
+ pNames = &seqNames;
+ }
+ }
+ return *pNames;
+}
+
+}
+
+using namespace XFlatXml;
+#define IMPLEMENTATION_NAME "devguide.officedev.samples.filter.FlatXmlCpp"
+
+
+extern "C"
+{
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ Reference< XRegistryKey > xNewKey(
+ reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
+ OUString::createFromAscii( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) );
+
+ const Sequence< OUString > & rSNL = getSupportedServiceNames();
+ const OUString * pArray = rSNL.getConstArray();
+ for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+void * SAL_CALL component_getFactory(
+ const sal_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;
+}
+
+} // extern "C"
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml
new file mode 100644
index 000000000000..9202844eef76
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+ <module-name> FlatXml </module-name>
+ <component-description>
+ <author> Aidan Butler </author>
+ <name>devguide.officedev.samples.filter.FlatXmlCpp</name>
+
+<description>
+ This component is a sample implementation, which describes how a filter may be written that uses the XmlFilterAdaptor component. This filter opens and saves Flat Xml files.
+ </description>
+ <loader-name> com.sun.star.loader.SharedLibrary </loader-name>
+ <language> c++ </language>
+ <status value="final"/>
+ <supported-service>devguide.officedev.samples.filter.FlatXmlCpp</supported-service>
+ <type>com.sun.star.lang.XSingleServiceFactory</type>
+ <type>com.sun.star.uno.XNamingService</type>
+ <type>com.sun.star.uno.XComponentContext</type>
+ <type>com.sun.star.uno.XWeak</type>
+ <type>com.sun.star.lang.XMain</type>
+ <type>com.sun.star.uno.XAggregation</type>
+ <type>com.sun.star.lang.XMultiServiceFactory</type>
+ <type>com.sun.star.lang.XSingleComponentFactory</type>
+ <type>com.sun.star.lang.XTypeProvider</type>
+ <type>com.sun.star.frame.XComponentLoader</type>
+ <type>com.sun.star.registry.XSimpleRegistry</type>
+ <type>com.sun.star.loader.XImplementationLoader</type>
+ <type>com.sun.star.registry.XImplementationRegistration</type>
+ <type>com.sun.star.lang.XComponent</type>
+ <type>com.sun.star.bridge.XBridgeFactory</type>
+ <type>com.sun.star.bridge.XUnoUrlResolver</type>
+ <type>com.sun.star.connection.XAcceptor</type>
+ <type>com.sun.star.connection.XConnector</type>
+ <type>com.sun.star.container.XHierarchicalNameAccess</type>
+ <type>com.sun.star.lang.XServiceInfo</type>
+ <type>com.sun.star.xml.sax.XDocumentHandler</type>
+ <type>com.sun.star.xml.sax.XExtendedDocumentHandler</type>
+ <type>com.sun.star.text.XTextDocument</type>
+ <type>com.sun.star.xml.XImportFilter</type>
+ <type>com.sun.star.xml.XExportFilter</type>
+ <type>com.sun.star.io.XInputStream</type>
+ <type>com.sun.star.io.XOutputStream</type>
+ <type>com.sun.star.io.XActiveDataSource</type>
+ <type>com.sun.star.io.XSeekable</type>
+ <type>com.sun.star.frame.XConfigManager</type>
+ <type>com.sun.star.xml.sax.XParser</type>
+ <type>com.sun.star.ucb.XSimpleFileAccess</type>
+ <type>com.sun.star.beans.XPropertySet</type>
+ </component-description>
+ <project-build-dependency> cppuhelper </project-build-dependency>
+ <project-build-dependency> cppu </project-build-dependency>
+ <project-build-dependency> sal </project-build-dependency>
+ <runtime-module-dependency> cppuhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> salhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> cppu$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> reg$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> store$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> sal$(UDK_MAJOR) </runtime-module-dependency>
+</module-description>
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 000000000000..8244bbd3a810
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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. It 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. It 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. It 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. It 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. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Matser</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 000000000000..09a4cfafa4dd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile
@@ -0,0 +1,148 @@
+#*************************************************************************
+#
+# 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
+include $(SETTINGS)/dk.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_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
+
+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),$@) $<
+
+$(COMP_MAPFILE) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
+ifeq "$(OS)" "MACOSX"
+ nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
+endif
+
+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) $(STLPORTLIB) msvcrt.lib kernel32.lib
+ $(LINK_MANIFEST)
+else
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
+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-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlFilter_cpp.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(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) $(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
+
+FlatXmlFilterCppExample : $(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),$(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 000000000000..cf95e1637c08
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java
@@ -0,0 +1,273 @@
+/*************************************************************************
+ *
+ * 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 java.io.*;
+import java.util.*;
+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 XMultiServiceFactory m_xServiceFactory;
+ private XExtendedDocumentHandler m_xHandler;
+ private boolean m_bPrettyPrint = true;
+
+ static private final String __serviceName = "devguide.officedev.samples.filter.FlatXmlJava";
+ static private final String __implName = "FlatXml";
+ static private final String[] __supportedServiceNames = {
+ "devguide.officedev.samples.filter.FlatXmlJava"
+ };
+
+ public FlatXml(XMultiServiceFactory f) {
+ m_xServiceFactory = f;
+ }
+
+ // --- XTypeProvider ---
+ public byte[] getImplementationId() {
+ return Integer.toString(this.hashCode()).getBytes();
+ }
+
+ // --- 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 = (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 = (XExtendedDocumentHandler)UnoRuntime.queryInterface(XExtendedDocumentHandler.class, tmpObj);
+ }
+ if (m_xHandler == null)
+ return false;
+
+ // Connect the provided output stream to the writer
+ XActiveDataSource xADSource = (XActiveDataSource)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;
+ }
+
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
+ {
+ return FactoryHelper.writeRegistryServiceInfo(__implName,
+ __serviceName, regKey);
+ }
+
+}
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 000000000000..16a04144c5e7
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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. It 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. It 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. It 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. It 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. It 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 000000000000..afd060aee7be
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile
@@ -0,0 +1,141 @@
+#*************************************************************************
+#
+# 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
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMPONENT_NAME=FlatXmlFilter_java
+OUT_COMP_CLASS = $(OUT_CLASS)/$(COMPONENT_NAME)
+COMPONENT_PACKAGE = $(OUT_BIN)/$(COMPONENT_NAME).$(UNOOXT_EXT)
+COMPONENT_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT_NAME).$(UNOOXT_EXT)")
+COMPONENT_JAR_NAME = $(COMPONENT_NAME).uno.jar
+COMPONENT_JAR = $(OUT_COMP_CLASS)/$(COMPONENT_JAR_NAME)
+COMPONENT_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT_NAME).uno.Manifest
+COMPONENT_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT_NAME)/META-INF/manifest.xml
+REGISTERFLAG = $(OUT_MISC)$(PS)devguide_$(COMPONENT_NAME)_register_component.flag
+
+JAVAFILES = \
+ FlatXml.java \
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+
+#$(COMPONENT_NAME)_CLASSFILES = FlatXml.class FlatXml$(dlr)_FlatXml.class
+
+$(COMPONENT_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
+$(COMPONENT_JAR) : $(COMPONENT_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-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMPONENT_PACKAGE) : $(COMPONENT_JAR) FlatXmlFilter_java.xcu $(COMPONENT_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ FlatXmlFilter_java.xcu
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMPONENT_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMPONENT_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 : $(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),$(COMPONENT_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))