You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2012/01/27 02:29:58 UTC

svn commit: r1236486 [32/43] - in /incubator/ooo/devtools/netbeansintegration: ./ build/ build/public-package-jars/ javahelp/ javahelp/org/ javahelp/org/openoffice/ javahelp/org/openoffice/extensions/ javahelp/org/openoffice/extensions/docs/ javahelp/o...

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ClasspathUpdater.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ClasspathUpdater.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ClasspathUpdater.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ClasspathUpdater.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,337 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: ClasspathUpdater.java,v $
+ *
+ *  $Revision: 1.6 $
+ *
+ *  last change: $Author: sg $ $Date: 2009/07/06 14:51:26 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+package org.openoffice.extensions.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.MalformedURLException;
+import java.util.Vector;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileStateInvalidException;
+import org.openide.util.Lookup;
+
+/**
+ * Class for adding the build/classes directory to the classpath to integrate
+ * compiled idl files into the Java part of the extension:
+ * adds ${build.classes.dir} to the project.properties entry 
+ */
+public class ClasspathUpdater {
+    
+    final static String LINE_ENDING = "\\";
+    
+    /** Do not instantiate */
+    private ClasspathUpdater() {
+    }
+    
+    public static void extendJavaClasspathWithIdlTypes(Project project) {
+        try {
+            if (project == null) return;
+            final FileObject projectDir = project.getProjectDirectory();
+            final FileObject distDir = projectDir.getFileObject("dist");
+            final FileObject sourceDir = projectDir.getFileObject("src");
+            final String IDL_JAR_NAME = ProjectTypeHelper.getObjectFromUnoProperties(projectDir, 
+                    "idl_types.jar").toString(); // NOI18N
+            
+            if (sourceDir != null && distDir != null) {
+                FileObject jarFile = distDir.getFileObject(
+                        IDL_JAR_NAME);
+                if (jarFile != null && jarFile.isData() && jarFile.canRead()) {
+                    Lookup lookup = project.getLookup();
+                    if (lookup == null) return;
+                    // TODO: check if ProjectClassPathModifier works.
+                    ProjectClassPathExtender extender = lookup.lookup(ProjectClassPathExtender.class);
+                    extender.addArchiveFile(jarFile);
+//                    URL jarURL1 = jarFile.getURL();
+//                    File f = FileUtil.toFile(jarFile);
+//                    URL jarURL2 = f.toURL();
+//                    try {
+//                        ProjectClassPathModifier.addRoots(
+//                            new URL[]{jarFile.getURL()}, sourceDir, ClassPath.COMPILE);
+//                    } catch (Throwable t) {
+//                        t.printStackTrace();
+//                    }
+//
+//                    try {
+//                        ProjectClassPathModifier.addRoots(
+//                            new URL[]{jarURL2}, projectDir, ClassPath.COMPILE);
+//                    } catch (Throwable t) {
+//                        t.printStackTrace();
+//                    }
+                    
+//                    ProjectClassPathModifierImplementation modImpl = project.getLookup().lookup(ProjectClassPathModifierImplementation.class);
+//                    
+//                    Class clazz = ProjectClassPathModifierImplementation.class;
+//                    Class[] cArray = clazz.getDeclaredClasses();
+//                    for (int i = 0; i < cArray.length; i++) {
+//                        Class class1 = cArray[i];
+//                        System.out.println("Clas: " + class1.toString());
+//                    }
+
+//                    File f = FileUtil.toFile(jarFile);
+//                    URL jarUrl = f.toURL();
+//                    URL jarUrl = jarFile.getURL();
+//                    Enumeration<? extends FileObject> files = sourceDir.getData(true);
+//                    while (files.hasMoreElements()) {
+//                        FileObject object = files.nextElement();
+//                        if (object.getExt().equals("java")) {
+//                            try {
+//                                ProjectClassPathModifier.addRoots(
+//                                    new URL[]{jarUrl}, object, ClassPath.COMPILE);
+//                            } catch (Throwable t) {
+//                                LogWriter.getLogWriter().printStackTrace(t);
+//                            }
+//                        }
+//                    }   
+                }
+            }
+//        } catch (FileStateInvalidException ex) {
+//            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (MalformedURLException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (FileStateInvalidException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (UnsupportedOperationException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } 
+    }
+
+    public static void removeIdlTypesFromJavaClasspath(Project project) {
+        final FileObject projectDir = project.getProjectDirectory();
+        final String IDL_JAR_NAME = ProjectTypeHelper.getObjectFromUnoProperties(projectDir, 
+                "idl_types.jar").toString(); // NOI18N
+        final String propName = "file.reference.".concat(IDL_JAR_NAME);
+        final String javacPropName = "javac.classpath";
+        Vector<String> allLines = new Vector<String>();
+        FileObject nbProject = projectDir.getFileObject("nbproject");
+        if (nbProject == null) return; // may happen when project is in process of deleting
+        FileObject projectProps = nbProject.getFileObject("project.properties");
+        if (projectProps == null) return; // may happen when project is in process of deleting
+        boolean writeOut = false;
+        // read the stuff
+        BufferedReader buf = null;
+        InputStream in = null;
+        try {
+            in = projectProps.getInputStream();
+            if (in == null) {
+                LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, "cannot get inputstream from project properties"); // NOI18N
+                return;
+            }
+            buf = new BufferedReader(new InputStreamReader(in));
+            String line = null;
+            while(buf.ready() && (line = buf.readLine()) != null) {
+                if (line.startsWith(javacPropName)) {
+                    writeOut = true;
+                    removeEntryFromClassPath(line, propName, allLines);
+                    // handle javac.classpath extending over several lines
+                    while (buf.ready() && line.endsWith(LINE_ENDING) && 
+                                (line = buf.readLine()) != null) {
+                        removeEntryFromClassPath(line, propName, allLines);
+                    }
+                }
+                else if (line.startsWith(propName)) {
+                    writeOut = true;
+                    // handle file.reference.IDL_types.jar extending over several lines
+                    while (buf.ready() && line.endsWith(LINE_ENDING) && (line = buf.readLine()) != null) {
+                        // all done in while statement...
+                    }
+                }
+                else {
+                    allLines.add(line);
+                }
+            }
+        } catch (IOException ex) {
+            writeOut = false;
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        finally { // all other exceptions produce a message box in ide: nothing will be written...
+            if (buf != null) {
+                try {
+                    buf.close();
+                } catch (IOException ex) {
+                    LogWriter.getLogWriter().printStackTrace(ex);
+                }
+            }
+            else if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ex) {
+                    LogWriter.getLogWriter().printStackTrace(ex);
+                }
+            }
+        }
+        // write out again, but only when something was changed
+        if (writeOut) {
+            OutputStream out = null;
+            BufferedWriter write = null;
+            try {
+                out = projectProps.getOutputStream();
+                write = new BufferedWriter(new OutputStreamWriter(out));
+                for (int i=0; i<allLines.size(); i++) {
+                    write.write(allLines.get(i));
+                    write.newLine();
+                }
+                write.flush();
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+            finally {
+                if (write != null) {
+                    try {
+                        write.close();
+                    } catch (IOException ex) {
+                        LogWriter.getLogWriter().printStackTrace(ex);
+                    }
+                }
+                else if (out != null) {
+                    try {
+                        out.close();
+                    } catch (IOException ex) {
+                        LogWriter.getLogWriter().printStackTrace(ex);
+                    }
+                }
+            }
+        }
+    }
+    
+    private static void removeEntryFromClassPath(String classPath, String entry, Vector<String> allLines) {
+        final String colon = ":";
+        boolean removeEndingFromLineBefore = false;
+        int index = classPath.indexOf(entry);
+        if (index > 1) {
+            if (!classPath.endsWith(LINE_ENDING)) { 
+                // last line: line before may need editing
+                removeEndingFromLineBefore = true;
+            }
+            // remove ${<entry>}
+            String firstClassPath = classPath.substring(0, index - 2);
+            String secondClassPath = classPath.substring(index + entry.length() + 1);
+            // handle ":" as separator
+            if (firstClassPath.endsWith(colon)) {
+                firstClassPath = firstClassPath.substring(0, firstClassPath.length() - 1);
+            }
+            else if (secondClassPath.startsWith(colon)) {
+                secondClassPath = secondClassPath.substring(1);
+            }
+            classPath = firstClassPath.concat(secondClassPath);
+        }
+        if (removeEndingFromLineBefore) {
+            if (classPath.trim().length() > 0) { // some classpath element left over
+                allLines.add(classPath);
+            }
+            else {  // entry was last entry in classpath
+                String lastLine = allLines.remove(allLines.size() - 1);
+                index = lastLine.indexOf(":\\");
+                if (index > 0) {
+                    lastLine = lastLine.substring(0, index);
+                }
+                else {
+                    lastLine = lastLine.substring(0, lastLine.length() - 1);
+                }
+                allLines.add(lastLine);
+            }
+        }
+        else {
+            if (classPath.trim().length() > 1) { // classpath is at least \ but maybe more...
+                allLines.add(classPath);
+            }
+        }
+    }
+    
+    /* removeIdlTypesFromJavaClasspath tested with:
+        String testValues = new String(
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=\\\n" +
+        "${build.classes.dir}:\\\n" +
+        "${libs.StarOffice8.classpath}:\\\n" +
+        "${file.reference.IDL_types.jar}");
+
+        testValues = new String(
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=\\\n" +
+        "${file.reference.IDL_types.jar}:\\\n" +
+        "${build.classes.dir}:\\\n" +
+        "${libs.StarOffice8.classpath}\n"
+        );
+
+        testValues = new String(
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=${file.reference.IDL_types.jar}:\\\n" +
+        "${build.classes.dir}:\\\n" +
+        "${libs.StarOffice8.classpath}\n"
+        );
+
+        testValues = new String(
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=\\\n" +
+        "${file.reference.IDL_types.jar}:${build.classes.dir}:\\\n" +
+        "${libs.StarOffice8.classpath}\n"
+        );
+        removeIdlTypesFromJavaClasspath(testValues);
+        testValues = new String(
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=\\\n" +
+        "${build.classes.dir}:${file.reference.IDL_types.jar}:\\\n" +
+        "${libs.StarOffice8.classpath}\n"
+        );
+
+        testValues = new String(
+        "javac.classpath=\\\n" +
+        "${file.reference.IDL_types.jar}:${build.classes.dir}:\\\n" +
+        "${libs.StarOffice8.classpath}\n" +
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n"
+        );
+
+        testValues = new String(
+        "javac.classpath=${file.reference.IDL_types.jar}\n" +
+        "file.reference.IDL_types.jar=../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n"
+        );
+
+        testValues = new String(
+        "file.reference.IDL_types.jar=\\\n" +
+        "../../../../../home/sg128468/NetBeansProjects/AddIn/dist/IDL_types.jar\n" +
+        "javac.classpath=${file.reference.IDL_types.jar}\n"
+        );
+     */ 
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileCreator.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileCreator.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileCreator.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileCreator.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,445 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: IdlFileCreator.java,v $
+ *
+ *  $Revision: 1.8 $
+ *
+ *  last change: $Author: jsc $ $Date: 2007/05/16 13:39:15 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+package org.openoffice.extensions.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import org.openide.WizardDescriptor;
+import org.openide.filesystems.FileLock;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openoffice.extensions.projecttemplates.calcaddin.datamodel.AddIn;
+import org.openoffice.extensions.util.datamodel.FunctionException;
+import org.openoffice.extensions.util.datamodel.IdlEnumeration;
+import org.openoffice.extensions.util.datamodel.Interface;
+import org.openoffice.extensions.util.datamodel.NbNodeObject;
+import org.openoffice.extensions.util.datamodel.PolyStruct;
+import org.openoffice.extensions.util.datamodel.Service;
+import org.openoffice.extensions.util.datamodel.Struct;
+import org.openoffice.extensions.util.datamodel.properties.UnknownOpenOfficeOrgLanguageIDException;
+import org.openoffice.extensions.util.datamodel.properties.UnknownOpenOfficeOrgPropertyException;
+
+/**
+ *
+ */
+public class IdlFileCreator {
+
+    private WizardDescriptor wiz;
+    private Class templateBaseClass;
+    private final String INTERFACE_TEMPLATE_NAME = "InterfaceTemplate"; // NOI18N
+    private final String ENUMERATION_TEMPLATE_NAME = "EnumerationTemplate"; // NOI18N
+    private final String STRUCT_TEMPLATE_NAME = "StructTemplate"; // NOI18N
+    private final String POLY_STRUCT_TEMPLATE_NAME = "PolyStructTemplate"; // NOI18N
+    private final String SERVICE_TEMPLATE_NAME = "ServiceTemplate"; // NOI18N
+    private final String PROPS_FILE = "Bundle.properties"; // NOI18N
+    private final String EXCEPTION_TEMPLATE_NAME = "ExceptionTemplate"; // NOI18N
+    
+    // define relation between template and data structure
+    
+    
+    public static final String[][] IDL_JAVA_TYPE_MAPPING = new String[][] {
+        {"void", "void"},
+        {"long", "int"},
+        {"double", "double"},
+        {"string", "String"},
+//        {"sequence < sequence < long > >", "int[][]"},
+//        {"sequence < sequence < double > >", "double[][]"},
+//        {"sequence < sequence < string > >", "String[][]"},
+        {"any", "Object"},
+//        {"sequence < any >", "Object[]"},
+//        {"sequence < sequence < any > >", "Object[][]"},
+        // just convenience for AddIns
+        {"com::sun::star::table::XCellRange", "XCellRange"},
+        {"com::sun::star::beans::XPropertySet", "XPropertySet"},
+        {"com::sun::star::sheet::XVolatileResult", "XVolatileResult"},
+    }; // NOI18N
+
+    public static String getIdlTypeForJavaType(String javaType) {
+        // replace dots with ::
+        if (javaType.indexOf(".") != -1) {  // NOI18N
+            javaType = javaType.replaceAll("\\.", "::"); // NOI18N
+            return javaType;
+        }
+        for (int i=0; i<IDL_JAVA_TYPE_MAPPING.length; i++) {
+            if (javaType.indexOf(IDL_JAVA_TYPE_MAPPING[i][1]) != -1) {
+                javaType = javaType.replaceAll(IDL_JAVA_TYPE_MAPPING[i][1], IDL_JAVA_TYPE_MAPPING[i][0]);
+            }
+        }
+        return javaType;
+    }
+
+    
+    private String[] template_idl;
+    private String baseDir;
+    
+    /** Creates a new instance of IdlFileCreator */
+    public IdlFileCreator(WizardDescriptor wiz, 
+            Class templateBaseClass, String baseDir) {
+        this.wiz = wiz;
+        this.templateBaseClass = templateBaseClass;
+        this.baseDir = baseDir;
+    }
+    
+    public FileObject[] createAllIdlFiles(NbNodeObject baseObject) {
+        try {
+            switch(baseObject.getType()) {
+                case NbNodeObject.SERVICE_TYPE:
+                    return createService((Service)baseObject);
+                case NbNodeObject.STRUCT_TYPE:
+                    return createStruct((Struct)baseObject);
+                case NbNodeObject.POLY_STRUCT_TYPE:
+                    return createPolyStruct((PolyStruct)baseObject);
+                case NbNodeObject.INTERFACE_TYPE:
+                    return createInterface((Interface)baseObject);
+                case NbNodeObject.ENUMERATION_TYPE:
+                    return createEnumeration((IdlEnumeration)baseObject);
+                case NbNodeObject.EXCEPTION_TYPE:
+                    return createException((FunctionException)baseObject);
+                case NbNodeObject.ADDIN_TYPE:
+                    return createAddIn((AddIn)baseObject);
+                default:  // what to do in this case? -> bug in own implementation, real bad.
+                    LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, "Unkown type."); // NOI18N
+            }
+        }
+        catch(java.lang.ClassCastException e) {
+            LogWriter.getLogWriter().printStackTrace(e);  // this must not happen!
+        }
+        return null;
+    }
+    
+    private FileObject[] createInterface(Interface ifc) {
+        // in case of office types, no files have to be generated
+        if (ifc.getType() == NbNodeObject.OFFICE_INTERFACE_TYPE) {
+            return new FileObject[0];
+        }
+        
+        Vector<FileObject> fileObjects = new Vector<FileObject>();
+
+        // craete this interface
+        FileObject o = createOneInterface(ifc);
+        if (o != null)
+            fileObjects.add(o);
+        
+        // go through this type and create all sub-interfaces
+        Interface[] aggIfcs = ifc.getAllAggregatedInterfaces();
+        for (int i=0; i<aggIfcs.length; i++) {
+            FileObject[] addObjects = createInterface(aggIfcs[i]);
+            for (int j=0; j<addObjects.length; j++) {
+                fileObjects.add(addObjects[j]);
+            }
+        }
+
+        return fileObjects.toArray(new FileObject[fileObjects.size()]);
+    }
+    
+    private FileObject createOneInterface(Interface ifc) {
+        // get the template
+        String[] interface_template_idl = ProjectCreator.readFileLinesInArray(
+                templateBaseClass, PROPS_FILE, INTERFACE_TEMPLATE_NAME);
+        try {
+            String packg = ifc.getSimpleProperty(ifc.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkgDir = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkgDir));
+            f.mkdirs();
+            // do interface
+            FileObject ifcObject = FileUtil.createData(
+                    FileUtil.toFileObject(f), 
+                    ifc.getSimpleProperty(ifc.PROPERTY_CONTAINER_NAME).concat(".idl") // NOI18N
+            );
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, ifc);
+            fillFile(aReplace, ifcObject, interface_template_idl);
+            return ifcObject;
+        }
+        catch(IOException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgLanguageIDException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgPropertyException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        return null;
+    }
+
+    private FileObject[] createService(Service service) {
+        // in case of office types, no files have to be generated
+        if (service.getType() == NbNodeObject.OFFICE_SERVICE_TYPE) {
+            return new FileObject[0];
+        }
+        // get the template
+        String[] service_template_idl = ProjectCreator.readFileLinesInArray(
+                templateBaseClass, PROPS_FILE, SERVICE_TEMPLATE_NAME);
+        
+        // go through this type and create all sub-interfaces
+        String [] ifcObjectNames = service.getAllSetObjectNames();
+        wiz.putProperty("Import", ifcObjectNames); // NOI18N
+        Vector<FileObject> fileObjects = new Vector<FileObject>();
+        if (ifcObjectNames.length == 1) { // just one interface: can be anything
+            wiz.putProperty("XMultiInheritanceInterface", getIdlTypeForJavaType(ifcObjectNames[0])); // NOI18N
+        }
+        // create the interface if it needs to be done
+        for (int i=0; i<ifcObjectNames.length; i++) {
+            Interface ifc = (Interface)service.getSetObject(ifcObjectNames[i]);
+            if (ifc != null) {
+                FileObject[] addObjects = createInterface(ifc);
+                for (int j=0; j<addObjects.length; j++) {
+                    fileObjects.add(addObjects[j]);
+                }
+            }
+        }
+
+        try {
+            String packg = service.getSimpleProperty(Service.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkg = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkg));
+            f.mkdirs();
+            String name = service.getSimpleProperty(Service.PROPERTY_CONTAINER_NAME);
+            // do service
+            FileObject serviceObject = FileUtil.createData(
+                    FileUtil.toFileObject(f), 
+                    name.concat(".idl") // NOI18N
+            );
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, service);
+            fillFile(aReplace, serviceObject, service_template_idl);
+            fileObjects.add(serviceObject);
+        }
+        catch(IOException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgLanguageIDException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgPropertyException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        return (FileObject[])fileObjects.toArray(new FileObject[fileObjects.size()]);
+    }
+    
+    private FileObject[] createEnumeration(IdlEnumeration idlEnumeration) {
+        try {
+            String packg = idlEnumeration.getSimpleProperty(idlEnumeration.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkg = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkg));
+            f.mkdirs();
+            String enumName = idlEnumeration.getSimpleProperty(IdlEnumeration.PROPERTY_CONTAINER_NAME);
+            String[] enumeration_template_idl = ProjectCreator.readFileLinesInArray(
+                    templateBaseClass, PROPS_FILE, ENUMERATION_TEMPLATE_NAME);
+            FileObject enumObject = FileUtil.createData(FileUtil.toFileObject(f), enumName.concat(".idl")); // NOI18N
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, idlEnumeration);
+            fillFile(aReplace, enumObject, enumeration_template_idl);
+            return new FileObject[]{enumObject};
+        } catch (UnknownOpenOfficeOrgLanguageIDException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (UnknownOpenOfficeOrgPropertyException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        return new FileObject[0];
+    }
+    
+    private FileObject[] createException(FunctionException exception) {
+        try {
+            String packg = exception.getSimpleProperty(exception.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkg = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkg));
+            f.mkdirs();
+            String enumName = exception.getSimpleProperty(FunctionException.PROPERTY_CONTAINER_NAME);
+            String[] enumeration_template_idl = ProjectCreator.readFileLinesInArray(
+                    templateBaseClass, PROPS_FILE, EXCEPTION_TEMPLATE_NAME);
+            FileObject enumObject = FileUtil.createData(FileUtil.toFileObject(f), enumName.concat(".idl")); // NOI18N
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, exception);
+            fillFile(aReplace, enumObject, enumeration_template_idl);
+            return new FileObject[]{enumObject};
+        } catch (UnknownOpenOfficeOrgLanguageIDException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (UnknownOpenOfficeOrgPropertyException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        return new FileObject[0];
+    }
+    
+    private FileObject[] createStruct(Struct struct) {
+        try {
+            String packg = struct.getSimpleProperty(struct.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkg = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkg));
+            f.mkdirs();
+            String enumName = struct.getSimpleProperty(struct.PROPERTY_CONTAINER_NAME);
+            String[] enumeration_template_idl = ProjectCreator.readFileLinesInArray(
+                    templateBaseClass, PROPS_FILE, STRUCT_TEMPLATE_NAME);
+            FileObject enumObject = FileUtil.createData(FileUtil.toFileObject(f), enumName.concat(".idl")); // NOI18N
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, struct);
+            fillFile(aReplace, enumObject, enumeration_template_idl);
+            return new FileObject[]{enumObject};
+        } catch (UnknownOpenOfficeOrgLanguageIDException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (UnknownOpenOfficeOrgPropertyException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        return new FileObject[0];
+    }
+    
+    private FileObject[] createPolyStruct(PolyStruct struct) {
+        try {
+            String packg = struct.getSimpleProperty(struct.PROPERTY_CONTAINER_PACKAGE);
+            getModuleFromPackage(packg);
+            String pkg = packg.replace('.', File.separatorChar);
+            File f = new File(baseDir.concat(File.separator).concat(pkg));
+            f.mkdirs();
+            String enumName = struct.getSimpleProperty(struct.PROPERTY_CONTAINER_NAME);
+            String[] enumeration_template_idl = ProjectCreator.readFileLinesInArray(
+                    templateBaseClass, PROPS_FILE, POLY_STRUCT_TEMPLATE_NAME);
+            FileObject enumObject = FileUtil.createData(FileUtil.toFileObject(f), enumName.concat(".idl")); // NOI18N
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, struct);
+            fillFile(aReplace, enumObject, enumeration_template_idl);
+            return new FileObject[]{enumObject};
+        } catch (UnknownOpenOfficeOrgLanguageIDException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (UnknownOpenOfficeOrgPropertyException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        return new FileObject[0];
+    }
+
+    private FileObject[] createAddIn(AddIn object) {
+        String packg = (String)wiz.getProperty("UnoPackage"); // NOI18N
+        getModuleFromPackage(packg);
+        String pkg = packg.replace('.', File.separatorChar);
+        
+        // get the template
+        String[] service_template_idl = ProjectCreator.readFileLinesInArray(
+                templateBaseClass, PROPS_FILE, SERVICE_TEMPLATE_NAME);
+        // get the template
+        String[] interface_template_idl = ProjectCreator.readFileLinesInArray(
+                templateBaseClass, PROPS_FILE, INTERFACE_TEMPLATE_NAME);
+        
+        try {
+            // do service
+            FileObject service = FileUtil.createData(
+                    FileUtil.toFileObject(new File(baseDir.concat(File.separator).concat(pkg))), 
+                    ((String)wiz.getProperty("mainClassName")).concat(".idl") // NOI18N
+            );
+            AdvancedReplace aReplace = new AdvancedReplace(wiz, null, null);
+            fillFile(aReplace, service, service_template_idl);
+            
+            // do interface
+            FileObject intrface = FileUtil.createData(
+                    FileUtil.toFileObject(new File(baseDir.concat(File.separator).concat(pkg))),
+                    "X".concat((String)wiz.getProperty("mainClassName")).concat(".idl") // NOI18N
+            );
+            aReplace = new AdvancedReplace(wiz, object);
+            fillFile(aReplace, intrface, interface_template_idl);
+            
+            return new FileObject[]{service, intrface};
+        }
+        catch(IOException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgLanguageIDException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        catch (UnknownOpenOfficeOrgPropertyException e) {
+            LogWriter.getLogWriter().printStackTrace(e);
+        }
+        return null;  // 2do here?
+    }
+
+    private void fillFile(AdvancedReplace replace, FileObject fo, String[] data) 
+        throws IOException, UnknownOpenOfficeOrgLanguageIDException, UnknownOpenOfficeOrgPropertyException {
+        FileLock lock = fo.lock();
+        try {
+            OutputStream out = fo.getOutputStream(lock);
+            OutputStreamWriter outWriter = new OutputStreamWriter(out);
+            try {
+                writeStringArrayInFile(outWriter, replace, data);
+            }
+            finally {
+                outWriter.close();
+            }
+        } finally {
+            lock.releaseLock();
+        }
+    }
+
+    private void writeStringArrayInFile(
+            OutputStreamWriter outWriter, AdvancedReplace aReplace, String[]data) 
+            throws IOException, UnknownOpenOfficeOrgLanguageIDException, UnknownOpenOfficeOrgPropertyException {
+        for (int i=0; i<data.length; i++) {
+            String[] nextData = aReplace.replaceVariables(data[i]);
+            if (nextData.length == 1) {
+                outWriter.write(nextData[0], 0, nextData[0].length());
+                outWriter.write("\n", 0, 1); // NOI18N
+            }
+            else if (nextData.length > 0){ // just to avoid endless recursion
+                outWriter.flush();
+                writeStringArrayInFile(outWriter, aReplace, (String[])nextData);
+            }
+        }
+        outWriter.flush();
+    }
+    
+    public void getModuleFromPackage(String pkg) {
+        String packageNameUnderscore = pkg.replace('.', '_');
+        
+        StringTokenizer t = new StringTokenizer(pkg, "."); // NOI18N
+        String packageNameModule = "module ".concat(t.nextToken()).concat(" {"); // NOI18N
+        String closeModule = "};"; // NOI18N
+        while(t.hasMoreTokens()) {
+            packageNameModule = packageNameModule.concat(" module ").concat(t.nextToken()).concat(" {"); // NOI18N
+            closeModule = closeModule.concat(" };"); // NOI18N
+        }
+        wiz.putProperty("packageNameModule", packageNameModule); // NOI18N
+        wiz.putProperty("closeModule", closeModule); // NOI18N
+        wiz.putProperty("packageNameUnderscore", packageNameUnderscore); // NOI18N
+    }
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileHelper.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileHelper.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileHelper.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/IdlFileHelper.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,202 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: IdlFileHelper.java,v $
+ *
+ *  $Revision: 1.3 $
+ *
+ *  last change: $Author: sg $ $Date: 2009/07/06 14:51:26 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+package org.openoffice.extensions.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Vector;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+//import org.openoffice.extensions.editors.unoidl.UnoIdlSyntax;
+//import org.openoffice.extensions.editors.unoidl.UnoIdlTokenContext;
+import org.openoffice.extensions.util.datamodel.Constants;
+import org.openoffice.extensions.util.datamodel.FunctionException;
+import org.openoffice.extensions.util.datamodel.IdlEnumeration;
+import org.openoffice.extensions.util.datamodel.Interface;
+import org.openoffice.extensions.util.datamodel.NbNodeObject;
+import org.openoffice.extensions.util.datamodel.Service;
+import org.openoffice.extensions.util.datamodel.Struct;
+import org.openoffice.extensions.util.typebrowser.logic.UnoTypes;
+
+/**
+ *
+ * @author sg128468
+ */
+public class IdlFileHelper {
+    
+    Enumeration m_childObjects;
+    String m_sourcePath;
+    
+    /** Creates a new instance of IdlFileHelper */
+    public IdlFileHelper(FileObject sourcePath) {
+        try {
+            m_sourcePath = FileUtil.toFile(sourcePath).getCanonicalPath();
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+            m_sourcePath = "";
+        }
+        m_childObjects = sourcePath.getChildren(true);
+    }
+    
+    public NbNodeObject[] getAllIdlFiles() {
+        Vector<NbNodeObject> nbNodeObjects = new Vector<NbNodeObject>();
+        while (m_childObjects.hasMoreElements()) {
+            try {
+                FileObject element = (FileObject)m_childObjects.nextElement();
+                if (element != null && element.isData() && element.getExt().equals("idl")) { // NOI18N
+                    int type = getType(element);
+                    NameAndPackage nameAndPackage = getNameAndPackage(element);
+                    NbNodeObject object = null;
+                    switch(type) {
+                        case UnoTypes.STRUCT_TYPE:
+                            object = new Struct(nameAndPackage.name, nameAndPackage.pkg);
+                            break;
+                        case UnoTypes.EXCEPTION_TYPE:
+                            object = new FunctionException(nameAndPackage.name, nameAndPackage.pkg);
+                            break;
+                        case UnoTypes.ENUM_TYPE:
+                            object = new IdlEnumeration(nameAndPackage.name, nameAndPackage.pkg);
+                            break;
+                        case UnoTypes.INTERFACE_TYPE:
+                            object = new Interface(nameAndPackage.name, nameAndPackage.pkg);;
+                            break;
+                        case UnoTypes.SERVICE_TYPE:
+                            object = new Service(nameAndPackage.name, nameAndPackage.pkg);
+                            break;
+                        case UnoTypes.CONSTANTS_TYPE: // not so much supported, but maybe created by hand...
+                            object = new Constants(nameAndPackage.name, nameAndPackage.pkg);
+                            break;
+                        default:
+                            LogWriter.getLogWriter().log(LogWriter.LEVEL_WARNING, 
+                                "Unkown/unsupported idl type: " + 
+                                nameAndPackage.pkg + "." + nameAndPackage.name);
+                    }
+                    if (object != null) {
+                        nbNodeObjects.add(object);
+                    }
+                }
+            }
+            catch (ClassCastException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+        return nbNodeObjects.toArray(new NbNodeObject[nbNodeObjects.size()]);
+    }
+    
+    private int getType(FileObject idlFile) {
+        int type = UnoTypes.ANY_TYPE;
+        
+        try {
+            InputStream inStream = idlFile.getInputStream();
+            InputStreamReader reader = new InputStreamReader(inStream);
+            char[] characters = new char[inStream.available()];
+            reader.read(characters, 0, characters.length);
+            UnoIdlSyntax idlSyntax = new UnoIdlSyntax(characters);
+            UnoIdlSyntax.TokenID id = UnoIdlSyntax.TokenID.CHAR;
+            int offset = 0;
+            while ( ((offset = idlSyntax.getOffset()) < characters.length - 1) &&
+                    (type == UnoTypes.ANY_TYPE) ) {  // only check till file finished
+                id = idlSyntax.parseNextToken();
+                // quite simple: the first keyword that donates a idl type is it!
+                if (id == UnoIdlSyntax.TokenID.KEYWORD) {
+                    char[] tokenChar = new char[idlSyntax.getTokenLength()];
+                    System.arraycopy(characters, offset, tokenChar, 0, tokenChar.length);
+                    String name = new String(tokenChar);
+                    if (name.equals("constants")) { // NOI18N
+                        type = UnoTypes.CONSTANTS_TYPE;
+                    }
+                    else if (name.equals("enum")) { // NOI18N
+                        type = UnoTypes.ENUM_TYPE;
+                    }
+                    else if (name.equals("exception")) { // NOI18N
+                        type = UnoTypes.EXCEPTION_TYPE;
+                    }
+                    else if (name.equals("interface")) { // NOI18N
+                        type = UnoTypes.INTERFACE_TYPE;
+                    }
+                    else if (name.equals("service")) { // NOI18N
+                        type = UnoTypes.SERVICE_TYPE;
+                    }
+                    else if (name.equals("struct")) { // NOI18N
+                        type = UnoTypes.STRUCT_TYPE;
+                    }
+                }
+            }
+        } catch (FileNotFoundException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        
+        return type;
+    }
+    
+    private NameAndPackage getNameAndPackage(FileObject element) {
+        NameAndPackage nap = new NameAndPackage();
+        try {
+            String name = FileUtil.toFile(element).getCanonicalPath();
+            // remove part till src
+            name = name.substring(m_sourcePath.length() + 1);
+            // remove extension; one dot must be there because file is not selected without .idl
+            name = name.substring(0, name.lastIndexOf('.'));
+            int index = name.lastIndexOf(File.separatorChar);
+            nap.name = name.substring(index + 1);
+            if (index != -1) {
+                nap.pkg = name.substring(0, index).replace(File.separatorChar, '.');
+            }
+            else {
+                nap.pkg = ""; // NOI18N
+            }
+            
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+            // name and package should not be null.
+            nap.name = "";  // NOI18N
+            nap.pkg = ""; // NOI18N
+        }
+        
+        return nap;
+    }
+
+    private class NameAndPackage {
+        String name;
+        String pkg;
+    }
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/LogWriter.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/LogWriter.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/LogWriter.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/LogWriter.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,490 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: LogWriter.java,v $
+ *
+ *  $Revision: 1.9 $
+ *
+ *  last change: $Author: sg $ $Date: 2008/07/02 12:47:15 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+package org.openoffice.extensions.util;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.util.Map;
+import java.util.Vector;
+import org.openide.util.NbBundle;
+import org.openoffice.extensions.config.ConfigurationSettings;
+
+/**
+ *
+ * @author sg128468
+ */
+public class LogWriter {
+    
+    static LogWriter lWriter;
+
+    public static final int LEVEL_INFO = 0;
+    public static final int LEVEL_WARNING = 4;
+    public static final int LEVEL_CRITICAL = 8;
+    public static final int LEVEL_EXCEPTION = 12;
+    
+    private static final String LEVEL_INFO_NAME_LOCALIZED = 
+        NbBundle.getMessage(LogWriter.class, "LOG_Level_info"); // NOI18N
+    private static final String LEVEL_WARNING_NAME_LOCALIZED = 
+        NbBundle.getMessage(LogWriter.class, "LOG_Level_warning"); // NOI18N
+    private static final String LEVEL_CRITICAL_NAME_LOCALIZED = 
+        NbBundle.getMessage(LogWriter.class, "LOG_Level_critical"); // NOI18N
+    private static final String LEVEL_EXCEPTION_NAME_LOCALIZED = 
+        NbBundle.getMessage(LogWriter.class, "LOG_Level_exception"); // NOI18N
+
+    private static final String LEVEL_INFO_NAME = "info";
+    private static final String LEVEL_WARNING_NAME = "warning";
+    private static final String LEVEL_CRITICAL_NAME = "critical";
+    private static final String LEVEL_EXCEPTION_NAME = "exception";
+    private static final String LEVEL_ALL_NAME = "all"; // NOI18N
+    private static final String LEVEL_INACTIVE_NAME = "inactive"; // NOI18N
+
+    // convenience for displaying the levels: only three for easier handling
+    public static final String[] getLoglevels() { 
+        return new String[] {
+            LEVEL_INFO_NAME_LOCALIZED,
+            LEVEL_WARNING_NAME_LOCALIZED,
+            LEVEL_CRITICAL_NAME_LOCALIZED,
+        };
+    };
+
+    // convenience abbreviation
+    private static final String m_ls = System.getProperty("line.separator"); // NOI18N
+    
+    // for internal use: log all
+    public static final int LEVEL_ALL = -1;
+    // for internal use: set log inactive
+    public static final int LEVEL_INACTIVE = 128468;
+    // for internal use to not confuse with exceptions
+    public static final int LEVEL_STACKTRACE = 11;
+    // level and path
+    public static final String LOG_LEVEL = "org.openoffice.nb.integration.log.level"; // NOI18N
+    public static final String LOG_PATH = "org.openoffice.nb.integration.log.path"; // NOI18N
+    
+    public static LogWriter getLogWriter() {
+        if (lWriter == null) { // should not happen, but to be save
+            String[] vals = getDefaultValues();
+            lWriter = new LogWriter(vals[0], vals[1]);
+        }
+        return lWriter;
+    }
+    
+    public static LogWriter createLogWriter(String level, String path) {
+        lWriter = new LogWriter(level, path);
+        return lWriter;
+    }
+    
+    public static String[] getDefaultValues() {
+        String level = System.getProperty(LOG_LEVEL);
+        if (level == null || level.length() == 0) {  // get environment variable as fallback
+            Map<String,String> envVars = System.getenv();
+            level = envVars.get(LOG_LEVEL.replace('.', '_')); // '.' not allowed in *ix environment vars
+            if (level == null  || level.length() == 0) {
+                level = LEVEL_ALL_NAME; // fallback to all when no level found
+            }
+        }
+        String path = System.getProperty(LOG_PATH);
+        if (path == null || level.length() == 0) {  // get environment variable as fallback
+            Map<String,String> envVars = System.getenv();
+            path = envVars.get(LOG_PATH.replace('.', '_')); // '.' not allowed in *ix environment vars
+            if (path == null || level.length() == 0) {  // fallback to system temp
+                path = System.getProperty("java.io.tmpdir");
+            }
+        }
+        return new String[] {level, path};
+    }
+    
+    private BufferedWriter m_Writer;
+    private File m_LogFile;
+    private int m_iLogLevel = 0;
+    
+    /** Creates a new instance of LogWriter 
+     * There are three possibilties: set in UI, system variable or environment variable.
+     * Possibilties are called in that order, UI settings win, then system, then environment#
+     * UI settings are persistent: once set, they are kept.
+     * Only exception: the UI settings say log is off, but system or environment say log is on - then it is on.
+     */
+    private LogWriter(String level, String path) {
+        // set level
+        setLogLevel(level);
+        // get a unique log file in path or else in temp dir
+        createLogFile(path);
+    }
+
+    /**
+     * Set the log leve to a sensible value. Return the value if it needs to
+     * be checked.
+     * @param level the log level
+     **/
+    private void setLogLevel(String level) {
+        // set level: use english names as fallback.
+        if (level == null) {
+            m_iLogLevel = LEVEL_INACTIVE;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_INFO_NAME_LOCALIZED)) {
+            m_iLogLevel = LEVEL_INFO;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_INFO_NAME)) { 
+            m_iLogLevel = LEVEL_INFO;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_WARNING_NAME_LOCALIZED)) {
+            m_iLogLevel = LEVEL_WARNING;
+        } else if(level.trim().equalsIgnoreCase(LEVEL_WARNING_NAME)) {
+            m_iLogLevel = LEVEL_WARNING;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_CRITICAL_NAME_LOCALIZED)) {
+            m_iLogLevel = LEVEL_CRITICAL;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_CRITICAL_NAME)) { 
+            m_iLogLevel = LEVEL_CRITICAL;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_EXCEPTION_NAME_LOCALIZED)) {
+            m_iLogLevel = LEVEL_EXCEPTION;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_EXCEPTION_NAME)) {
+            m_iLogLevel = LEVEL_EXCEPTION;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_INACTIVE_NAME)) { 
+            m_iLogLevel = LEVEL_INACTIVE;
+        } else if (level.trim().equalsIgnoreCase(LEVEL_ALL_NAME)) { 
+            m_iLogLevel = LEVEL_ALL;
+        } else {
+            m_iLogLevel = LEVEL_INACTIVE;
+        }
+    }
+    
+    /**
+     * Return true, if the log is active
+     **/
+    public boolean isActive() {
+        return m_iLogLevel >= LEVEL_INACTIVE;
+    }
+    
+    public String getLogFile() {
+        if (m_LogFile != null) {
+            try {
+                return m_LogFile.getCanonicalPath();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return ""; // NOI18N
+    }
+    
+    public OutputStream getLogStream(int logLevel) {
+        return new LogStream(logLevel);
+    }
+    
+    private void setLogFile(String file) {
+        if (file.equals(getLogFile())) return;
+        try {
+            if (m_Writer != null)
+                m_Writer.close();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        // set all variables to null.
+        m_LogFile = null;
+        m_Writer = null;
+        createLogFile(file);
+    }
+    
+    public void clearLogFile() {
+        try {
+            if (m_Writer != null)
+                m_Writer.close();
+            if (m_LogFile != null) {
+                m_LogFile.createNewFile();
+                m_Writer = new BufferedWriter(new FileWriter(m_LogFile));
+            }
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+        // create time stamp for empty file.
+        createTimeStamp(true);
+    }
+    
+    public void log(int level, String message) {
+        // do not log empty messages!
+        if (level >= m_iLogLevel && m_Writer != null && message != null && message.length() != 0) {
+            try {
+                final String className = getLastCalledClassName();
+                switch(level) {
+                    case LEVEL_INFO:
+                        m_Writer.write(m_ls.concat("INFO       # ").concat(className).concat(": ")); // NOI18N
+                        break;
+                    case LEVEL_WARNING:
+                        m_Writer.write(m_ls.concat("WARNING    # ").concat(className).concat(": ")); // NOI18N
+                        break;
+                    case LEVEL_CRITICAL:
+                        m_Writer.write(m_ls.concat("CRITICAL   # ").concat(className).concat(": ")); // NOI18N
+                        break;
+                    case LEVEL_STACKTRACE:
+                        m_Writer.write(m_ls.concat("STACKTRACE # : ")); // NOI18N
+                        break;
+                    case LEVEL_EXCEPTION:
+                        m_Writer.write(m_ls.concat("EXCEPTION  # : ")); // NOI18N
+                        break;
+                    default:
+                }
+                m_Writer.write(message.concat(m_ls));
+                m_Writer.flush();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * write exceptions to the log
+     */
+    public void printStackTrace(Throwable t) {
+        if (t != null)
+            log(LEVEL_EXCEPTION, t.getLocalizedMessage());
+        else
+            log(LEVEL_EXCEPTION, "Could not write Exception (was null): ".concat(getStackTrace(3))); // NOI18N
+    }
+    
+    /**
+     * print a stack trace of the last calleers until the cll of this function;
+     * depth determines how many callers will be traced. Any number
+     * is possible (e.g. MAX_INT), but of course there cannot be more than
+     * <i>all</i> callers. This has a similar level as exceptions.
+     * @param message a message printed with the stack trace
+     * @param depth the count of the trace
+     */
+    public void printStackTrace(String message, int depth) {
+        if (message != null) {
+            String msg = message.concat(m_ls).concat(getStackTrace(depth));
+            log(LEVEL_STACKTRACE, msg);
+        }
+        else {
+            log(LEVEL_STACKTRACE, ""); // NOI18N
+        }
+    }
+    
+    /**
+     * takes the last class name from the stack before this class is called,
+     * so the debug output contains this information.
+     * @returns the class name where a method from this class was called.
+     */
+    private String getLastCalledClassName() {
+        Throwable t = new Throwable();
+        t.fillInStackTrace();
+        StackTraceElement[] elements = t.getStackTrace();
+        boolean found = false;
+        String classNamePrefix = null;
+        for (int i=0; !found && i<elements.length; i++) {
+            classNamePrefix = elements[i].getClassName();
+            if (!classNamePrefix.equals(LogWriter.class.getName())) {
+                int lineNumber = elements[i].getLineNumber();
+                found = true;
+                if (lineNumber >= 0) { // cannot determine line number
+                    // classNamePrefix = classNamePrefix;
+//                }
+//                else {
+                    classNamePrefix = new StringBuffer(classNamePrefix).append(",line ").append(lineNumber).toString();  // NOI18N
+                }
+            }
+        }
+        return classNamePrefix;
+    }    
+
+    /**
+     * takes the stack trace until this class comes up,
+     * so the debug output contains this information.
+     * @returns the stack until the class  where a method from this class was called.
+     */
+    private String getStackTrace(int depth) {
+        Throwable t = new Throwable();
+        t.fillInStackTrace();
+        StackTraceElement[] elements = t.getStackTrace();
+        Vector<String> stackTrace = new Vector<String>();
+        for (int i=0; i<elements.length; i++) {
+            String classNamePrefix = elements[i].getClassName();
+            if (!classNamePrefix.equals(LogWriter.class.getName())) { 
+                if (classNamePrefix.startsWith("org.openoffice.extensions")) { // NOI18N
+                    stackTrace.add(elements[i].toString().concat(m_ls));
+                }
+            }
+        }
+        StringBuffer result = new StringBuffer();
+        int end = (stackTrace.size() - depth > 0)?
+            (stackTrace.size() - depth) : 0;
+        for (int i=stackTrace.size() - 1; i >= end; i--) {
+            result.append(stackTrace.get(i)).append(m_ls);
+        }
+        return result.toString();
+    } 
+    
+    /**
+     * Create the log file or open an existing one if path points to
+     * one. Only characteristic of a log file is, it has to be writeable.
+     */
+    private void createLogFile(String path) {
+        if (m_iLogLevel == LEVEL_INACTIVE) // don't bother with logfile when inactive
+            return;
+        
+        boolean createdNewFile = true;
+        if (path != null) {
+            File logCandidate = new File(path);
+            if (logCandidate.exists()) {
+                if (logCandidate.canWrite()) {  // no else for this one: create a new file 
+                    if (logCandidate.isDirectory()) {
+                        try {
+                            m_LogFile = File.createTempFile("OOoNBIntegration", ".log", logCandidate); // NOI18N
+                            m_Writer = new BufferedWriter(new FileWriter(m_LogFile));
+                        } catch (IOException ex) {
+                            ex.printStackTrace();
+                        }
+                    }
+                    else {
+                        m_LogFile = logCandidate;
+                        try {
+                            m_Writer = new BufferedWriter(new FileWriter(m_LogFile));
+                            createdNewFile = false;
+                        } catch (IOException ex) {
+                            ex.printStackTrace();
+                            m_LogFile = null;
+                        }
+                    }
+                }
+            }
+            else {  // log file is new, so create it
+                try {
+                    if (logCandidate.createNewFile()) {
+                        m_LogFile = logCandidate;
+                        m_Writer = new BufferedWriter(new FileWriter(m_LogFile));
+                    }
+                } catch (IOException ex) {
+                    ex.printStackTrace();
+                    m_LogFile = null;
+                }
+            }
+        }
+        // get a unique log file in path or else in temp dir
+        if (m_LogFile == null) { // don't bother with logfile when inactive
+            try {
+                File p = new File(System.getProperty("java.io.tmpdir")); // NOI18N
+                m_LogFile = File.createTempFile("OOoNBIntegration", ".log", p); // NOI18N
+                m_Writer = new BufferedWriter(new FileWriter(m_LogFile));
+            } catch (IOException ex) {
+                ex.printStackTrace();
+                m_LogFile = null;
+            }
+        }
+        // create a time stamp in the log file to indicate the new log session
+        if (m_LogFile != null)
+            createTimeStamp(createdNewFile);
+    }
+    
+    /** Create a time stamp in the log file: mark a new log session this way
+     */
+    private void createTimeStamp(boolean emptyFile) {
+        if (m_Writer == null) return; // easy exit for empty writer
+        String time = ConfigurationSettings.getTimeStamp();
+        try {
+            if (!emptyFile) {  // no need for returns when file is empty
+                m_Writer.newLine();
+                m_Writer.newLine();
+            }
+            for (int i = 0; i < 80; i++) {
+                m_Writer.write("*");
+            }
+            m_Writer.newLine();
+            m_Writer.write("* Log session started: ".concat(time).concat(
+                "                                   *"));
+            m_Writer.newLine();
+            for (int i = 0; i < 80; i++) {
+                m_Writer.write("*");
+            }
+            m_Writer.newLine();
+            m_Writer.newLine();
+            m_Writer.flush();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+    }
+    
+    /**
+     * Changes to the log settings have to be reflected in LogWriter class,
+     * so to be notified of changes, add some listeners
+     */
+    public static class LogSettingsChangeListener implements PropertyChangeListener {
+        private LogWriter mLwr;
+        public LogSettingsChangeListener(LogWriter lwr) {
+            mLwr = lwr;
+        }
+        public void propertyChange(PropertyChangeEvent evt) {
+            if (evt.getPropertyName().equals(ConfigurationSettings.KEY_LOG_LEVEL)) {
+                mLwr.setLogLevel((String)evt.getNewValue());
+            }
+            if (evt.getPropertyName().equals(ConfigurationSettings.KEY_LOG_FILE)) {
+                mLwr.setLogFile((String)evt.getNewValue());
+            }
+        }
+    }
+
+    /**
+     * Wrapper class around the log to give the logger away to others
+     */
+    private class LogStream extends OutputStream {
+        private int m_logLevel;
+        private StringWriter m_sWriter;
+        public LogStream(int logLevel) {
+            m_logLevel = logLevel;
+            m_sWriter = new StringWriter();
+        }
+        
+        @Override
+        public void write(int b) throws IOException {
+            m_sWriter.write(b);
+        }
+
+        @Override
+        public void write(byte[] b) throws IOException {
+            m_sWriter.write(new String(b));
+        }
+
+        @Override
+        public void write(byte[] b, int off, int len) throws IOException {
+            m_sWriter.write(new String(b, off, len));
+        }
+
+        @Override
+        public void flush() throws IOException {
+            LogWriter.getLogWriter().log(m_logLevel, m_sWriter.toString());
+            m_sWriter.flush();
+        }
+    }
+}
\ No newline at end of file

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ManifestCreator.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ManifestCreator.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ManifestCreator.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/ManifestCreator.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,431 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: ManifestCreator.java,v $
+ *
+ *  $Revision: 1.16 $
+ *
+ *  last change: $Author: sg $ $Date: 2009/07/06 14:51:26 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+package org.openoffice.extensions.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import org.openide.filesystems.FileLock;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ *
+ * @author ab106281
+ */
+
+
+public class ManifestCreator {
+    
+    public static String uno_typelibrary_rdb_MediaType = "application/vnd.sun.star.uno-typelibrary;type=RDB"; // NOI18N
+    public static String uno_typelibrary_java_MediaType = "application/vnd.sun.star.uno-typelibrary;type=Java"; // NOI18N
+    public static String uno_component_java_MediaType = "application/vnd.sun.star.uno-component;type=Java"; // NOI18N
+//    public static String uno_component_python_MediaType = "application/vnd.sun.star.uno-component;type=Python"; // NOI18N
+    // TODO native requires a further atribute platform 
+    public static String uno_component_native_MediaType = "application/vnd.sun.star.uno-component;type=native"; // NOI18N
+    public static String configuration_data_MediaType = "application/vnd.sun.star.configuration-data"; // NOI18N
+    public static String configuration_schema_MediaType = "application/vnd.sun.star.configuration-schema"; // NOI18N
+//    public static String package_bundle_description_MediaType = "application/vnd.sun.star.package-bundle-description"; // NOI18N
+    public static String uno_component_basic_library_MediaType = "application/vnd.sun.star.basic-library"; // NOI18N
+    public static String uno_component_dialog_library_MediaType = "application/vnd.sun.star.dialog-library"; // NOI18N
+    public static String uno_component_help_file_MediaType = "application/vnd.sun.star.help"; // NOI18N
+            
+    // TODO add further media types.
+    private static String[][] media_type_mapping = {
+        {".xcu", configuration_data_MediaType},
+        {".xcs", configuration_schema_MediaType},
+//        {".xdl", uno_component_dialog_library_MediaType},
+        {".xlb", uno_component_basic_library_MediaType},
+//        {".xhp", uno_component_help_file_MediaType},
+    }; // NOI18N
+    // with these extensions, not the file, but the directory of the file should be referenced
+    private static String[] reference_Directory = { 
+//        ".xdl", 
+//        ".xba", 
+        ".xlb",
+    }; // NOI18N
+    
+    private FileObject m_projectRoot;
+    private StringBuffer m_manifestLines;
+    
+    
+    public ManifestCreator(FileObject projectRoot) {
+        this.m_projectRoot = projectRoot;
+        this.m_manifestLines = new StringBuffer();
+        m_manifestLines.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); // NOI18N
+        //m_manifestLines.append("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">\n"); // NOI18N
+        m_manifestLines.append("<manifest:manifest xmlns:manifest=\"http://openoffice.org/2001/manifest\">\n"); // NOI18N
+    }
+    
+    public void add(String mimeType, String fullPath) {
+        m_manifestLines.append("  <manifest:file-entry manifest:media-type=\"" ); // NOI18N
+        m_manifestLines.append(mimeType);
+        m_manifestLines.append("\"\n                       manifest:full-path=\""); // NOI18N
+        m_manifestLines.append(fullPath);
+        m_manifestLines.append("\"/>\n"); // NOI18N
+    }
+    
+    public void remove(String mimeType, String fullPath) {
+        final String PATH_MANIFEST_ENTRY = "manifest:full-path=";
+        int fromIndex = 0;
+        int start = 0;
+        // idea: look for the mime type, then for the full path, if they match: delete!
+        // TODO: better algorithm taking user interaction into account
+        while ((start = m_manifestLines.indexOf("  <manifest:file-entry manifest:media-type=\"".concat(mimeType), fromIndex)) != -1) {
+            int middleIndex = m_manifestLines.indexOf(PATH_MANIFEST_ENTRY, start);
+            int tempStart = middleIndex + PATH_MANIFEST_ENTRY.length() + 1;
+            int end = tempStart + fullPath.length();
+            String pathCandidate = m_manifestLines.substring(tempStart, end);
+            if (pathCandidate.equals(fullPath)) {
+                end = end + 4;  // include \"/>\n
+                m_manifestLines.delete(start, end);
+            }
+            fromIndex = start;
+        }
+    }
+    
+    /**
+     * writes the manifest.xml to m_projectRoot/dist/META-INF/manifest.xml
+     */
+    public void flush() throws IOException {
+        m_manifestLines.append("</manifest:manifest>"); // NOI18N
+
+        FileUtil.createFolder(m_projectRoot, "src"); // NOI18N
+        
+        FileObject fo = FileUtil.createData(m_projectRoot, "src/uno-extension-manifest.xml"); // NOI18N
+        FileLock lock = fo.lock();
+        try {
+            OutputStream out = fo.getOutputStream(lock);
+            try {
+                FileUtil.copy(new ByteArrayInputStream(this.m_manifestLines.toString().getBytes()), out);
+            } finally {
+                out.close();
+            }
+        } finally {
+            lock.releaseLock();
+        }
+    }
+    
+    public void updateManifest(Properties props) {
+        String[] extensions = getExtensions(props);
+        try {
+            FileObject fo = FileUtil.createData(m_projectRoot, "src/uno-extension-manifest.xml"); // NOI18N
+
+            XMLReader parser = XMLReaderFactory.createXMLReader();
+            ManifestHandler mHandler = new ManifestHandler(extensions);
+            parser.setContentHandler(mHandler);
+            InputSource source = new InputSource(fo.getInputStream());
+            parser.parse(source);
+
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (SAXException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (NullPointerException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+
+        updateFileTypes(extensions);
+        // after handling xcu/xcs files in source directory (older projects)
+        // handle registry file
+        updateRegistryEntry();
+        updateRdbEntry();
+        updateHelpEntry();
+
+        try {
+            flush();
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+            
+    }
+
+    private void updateHelpEntry() {
+        // do not update help entry when it is already there
+        if (m_manifestLines.indexOf(
+            uno_component_help_file_MediaType) == -1) {
+
+            String helpDirName = null;
+            Object help = ProjectTypeHelper.getObjectFromUnoProperties(m_projectRoot, "help.dir");
+            if (help == null) { // just as fallback
+                helpDirName = "help";
+            }
+            helpDirName = help.toString();
+            FileObject helpDir = m_projectRoot.getFileObject(helpDirName);
+            if (helpDir != null && helpDir.isFolder()) { // no help found otherwise
+                Enumeration<? extends FileObject> fileObjectEnumeration = helpDir.getData(true);
+                while (fileObjectEnumeration.hasMoreElements()) {
+                    FileObject file = fileObjectEnumeration.nextElement();
+                    if (file.getExt().equals("xhp")) {
+                        // one entry is enough: do it when help file is found
+                        add(uno_component_help_file_MediaType, helpDirName.replaceAll("\\\\", "/")); // NOI18N
+                        return;
+                    }
+                }
+            }
+        }
+    }
+
+    private void updateRdbEntry()  {
+        final String IDL_JAR_NAME = (String)ProjectTypeHelper.getObjectFromUnoProperties(
+            m_projectRoot, "idl_types.jar"); // NOI18N
+
+        try {
+            FileObject sourceFolder = FileUtil.createFolder(m_projectRoot, "src"); // NOI18N
+            Enumeration allFiles = sourceFolder.getData(true); // get all files recursively
+            boolean notFound = true;
+            while (allFiles.hasMoreElements() && notFound) {
+                FileObject nextFile = (FileObject)allFiles.nextElement();
+                if (nextFile.getExt().equals("idl")) { // NOI18N
+                    notFound = false;   // we will hav an rdb
+                }
+            }
+            if (!notFound) { // do rdb entry.
+                if (m_manifestLines.indexOf(
+                    uno_typelibrary_rdb_MediaType) == -1) {
+                    // entry is not there, so do it.
+                    add(uno_typelibrary_rdb_MediaType, "types.rdb"); // NOI18N
+                }
+                if (m_manifestLines.indexOf(uno_typelibrary_java_MediaType) == -1
+                        && m_manifestLines.indexOf(IDL_JAR_NAME) == -1) {
+                    // maybe double media type, so look for type AND jar
+                    add(uno_typelibrary_java_MediaType, IDL_JAR_NAME);
+                }
+            }
+            else {
+                if (m_manifestLines.indexOf(
+                    uno_typelibrary_rdb_MediaType) != -1) {
+                    remove(uno_typelibrary_rdb_MediaType, "types.rdb"); // NOI18N
+                }
+                if (m_manifestLines.indexOf(uno_typelibrary_java_MediaType) != -1) {
+                    // remove handles double entries
+                    remove(uno_typelibrary_java_MediaType, IDL_JAR_NAME);
+                }
+            }
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+    }
+    
+    private void updateFileTypes(String[] extensions) {
+        // for all extensions, get all files in the source path
+        for (int i = 0; i < extensions.length; i++) {
+            String[] entries = createEntries(extensions[i]);
+            String mimeType = getMediaTypeForExtension(extensions[i]);
+            if (entries.length > 0) {
+                if (mimeType != null) {
+                    for (int j = 0; j < entries.length; j++) {
+                        add(mimeType, entries[j]);
+                    }
+                }
+                else {  
+                    // file type without mime type: will be copied in the .oxt file, 
+                    // but not referenced in the manifest.
+                    LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, 
+                        "Extension " + extensions[i] + " has an unknown mime type. Files with that extension will not be referenced in the Manifest.");
+                }
+            }
+        }
+    }
+    
+    private String getMediaTypeForExtension(String extension) {
+        for (int i = 0; i < media_type_mapping.length; i++) {
+            if (extension.equals(media_type_mapping[i][0])) {
+                return media_type_mapping[i][1];
+            }
+        }
+        return null;
+    }
+    
+    private String[] getExtensions(Properties props) {
+//        String[] result = new String[0];
+//        String extensions = props.getProperty("manifest.package.extensions"); // NOI18N
+//        if (extensions != null && extensions.length() > 0) {
+//            Vector<String> results = new Vector<String>();
+//            StringTokenizer ext = new StringTokenizer(extensions, ","); // NOI18N
+//            while(ext.hasMoreElements()) {
+//                String candidate = ext.nextToken();
+//                if (candidate.startsWith("**/*.")) {
+//                    results.add(candidate.substring(4));
+//                }
+//                else if(candidate.startsWith("*.")) {
+//                    results.add(candidate.substring(1));
+//                }
+//            }
+//            result = results.toArray(new String[results.size()]);
+//        }
+//        return result;
+        return new String[]{".xcu", ".xcs", ".xlb"};  // only return types where we have a type mapping
+    }
+    
+    /** 
+     * Add entries in the manifest file from existing files in the 
+     * source path for recognized extensions.
+     * @param _extension the extension to update
+     * @return the entries for this extension
+     */
+    private String[] createEntries(String _extension) {
+        boolean referenceDirectory = false;
+        for (int i = 0; i < reference_Directory.length; i++) {
+            if (_extension.equals(reference_Directory[i])) {
+                referenceDirectory = true;
+            }
+        }
+        Vector<String> pathEntries = new Vector<String>();
+        Enumeration dataChildren = null;
+        int fileNamePrefixLength = -1;
+        try {
+            FileObject fo = FileUtil.createData(m_projectRoot, "src"); // NOI18N
+            fileNamePrefixLength = FileUtil.toFile(fo).getCanonicalPath().length();
+            dataChildren = fo.getData(true);
+        }
+        catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        while (dataChildren != null && dataChildren.hasMoreElements()) {
+            try {
+                FileObject aDataFile = (FileObject)dataChildren.nextElement();
+                if (aDataFile.getNameExt().endsWith(_extension)) {
+                    // we have a winner
+                    if (referenceDirectory) { // enter the directory, not the file
+                        String name = FileUtil.toFile(aDataFile).getCanonicalPath();
+                        name = name.substring(fileNamePrefixLength + 1);
+                        int index = name.lastIndexOf(File.separatorChar);
+                        if (index > 0)
+                            name = name.substring(0, index);
+                        String entryName = name.replaceAll("\\\\", "/");
+                        if (!pathEntries.contains(entryName)) {
+                            pathEntries.add(entryName);
+                        }
+                    }
+                    else {
+                        String name = FileUtil.toFile(aDataFile).getCanonicalPath();
+                        name = name.substring(fileNamePrefixLength + 1);
+                        pathEntries.add(name.replaceAll("\\\\", "/"));
+                    }
+                }
+            }
+            catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+        return pathEntries.toArray(new String[pathEntries.size()]);
+    }
+
+    /**
+     * Hanlde xcu/xcs files that are located in the regitry subdirectory,
+     * i.e. ther regitry.dir referenced in the project properties.
+     */
+    private void updateRegistryEntry() {
+        String registryDirName = (String)ProjectTypeHelper.getObjectFromUnoProperties(m_projectRoot, "registry.dir");
+        if (registryDirName == null) {
+            registryDirName = "registry";
+        }
+        FileObject registryDir = m_projectRoot.getFileObject(registryDirName);
+        if (registryDir != null) {
+            try {
+                int fileNamePrefixLength = FileUtil.toFile(m_projectRoot).getCanonicalPath().length();
+                Enumeration<? extends FileObject> registryCandidate = registryDir.getChildren(true); // get all recursively
+                while (registryCandidate.hasMoreElements()) {
+                    FileObject cand = registryCandidate.nextElement();
+                    String manifestMediaType = null;
+                    if (cand.getExt().endsWith("xcu")) {
+                        manifestMediaType = configuration_data_MediaType;
+                    }
+                    else if (cand.getExt().endsWith("xcs")) {
+                        manifestMediaType = configuration_schema_MediaType;
+                    }
+                    if (manifestMediaType != null) {
+                        String path = FileUtil.toFile(cand).getCanonicalPath();
+                        path = path.substring(fileNamePrefixLength + 1);
+                        add(manifestMediaType, path.replaceAll("\\\\", "/"));
+                    }
+                }
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+    }
+    
+    /**
+     * Class for handling manifest entries. There are two kinds:
+     * entries that are left alone and entries for files that must be
+     * handled. The files to be handled are recognized at their extension.
+     * Files with a known extension are to be taken from the path they are
+     * located in the file system.
+     */
+    private class ManifestHandler extends DefaultHandler {
+        String[] extensions;
+        public ManifestHandler(String[] _extensions) {
+            extensions = _extensions;
+        }
+        @Override
+        public void startElement(String uri, String localName, 
+                String qName, Attributes attributes) throws SAXException {
+            if (!qName.equals("manifest:manifest")) { // NOI18N
+                String mimeType = attributes.getValue("manifest:media-type"); // NOI18N
+                String fullPath = attributes.getValue("manifest:full-path"); // NOI18N
+                String extension = fullPath.substring(fullPath.length() - 4);
+                boolean found = false;
+                // basic paths get excluded: will be added again later anyway
+                if (mimeType == null || mimeType.equals(uno_component_basic_library_MediaType)) {
+                    found = true;
+                }
+                for (int i = 0; i < extensions.length; i++) {
+                    if (extension.equals(extensions[i])) {  // extension that must be handled
+                        found = true;
+                    }
+                }
+                if (!found) {  // this entry is kept as it is
+                    ManifestCreator.this.add(mimeType, fullPath);
+                }
+            }
+        }
+    }
+    
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/PathExchanger.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/PathExchanger.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/PathExchanger.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/util/PathExchanger.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,61 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: PathExchanger.java,v $
+ *
+ *  $Revision: 1.3 $
+ *
+ *  last change: $Author: sg $ $Date: 2007/05/03 09:56:09 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+package org.openoffice.extensions.util;
+
+/**
+ *
+ * @author sg128468
+ */
+public class PathExchanger {
+    
+    /** Creates a new instance of PathExchanger:
+     * not allowed to use.
+     */
+    private PathExchanger() {
+    }
+    
+    public static String pathToOfficeFileUrl(String path) {
+        String retString = path.replace('\\', '/').replaceAll(" ", "%20"); // NOI18N
+        if (!retString.startsWith("file:")) { // NOI18N
+            if (retString.charAt(0) == '/') {
+                retString = "file://".concat(retString); // NOI18N
+            }
+            else {
+                retString = "file:///".concat(retString); // NOI18N
+            }
+        }
+        return retString;
+    }
+}