incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ar...@apache.org
Subject svn commit: r1236486 [14/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...
Date Fri, 27 Jan 2012 01:29:58 GMT
Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UnoPropertiesAction.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UnoPropertiesAction.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UnoPropertiesAction.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UnoPropertiesAction.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,116 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: UnoPropertiesAction.java,v $
+ *
+ *  $Revision: 1.2 $
+ *
+ *  last change: $Author: sg $ $Date: 2008/10/07 10:30:37 $
+ *
+ *  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.projecttemplates.actions;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JMenuItem;
+import org.netbeans.api.project.Project;
+import org.openide.awt.DynamicMenuContent;
+import org.openide.awt.Mnemonics;
+import org.openide.util.ContextAwareAction;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.actions.Presenter;
+import org.openoffice.extensions.util.ProjectTypeHelper;
+
+
+/**
+ *
+ */
+public class UnoPropertiesAction extends AbstractAction implements ContextAwareAction {
+
+    private static Process officeProcess;
+    
+    private ContextAction contextAction;
+    public void actionPerformed(ActionEvent e) {assert false;}
+    
+    public Action createContextAwareInstance(Lookup context) {
+        return new ContextAction(context);
+    }
+    
+    private boolean enable(Project p) {
+        assert p != null;        
+        // check if it is a special office extension project
+        return ProjectTypeHelper.isExtensionProject(p);
+    }
+    
+    private String labelFor(Project p) {
+        assert p != null;    
+        
+        return NbBundle.getMessage(DebugAction.class, "CTL_UnoPropertiesAction");
+    }
+    
+    private void perform(Project p) {
+        assert p != null;
+//        UnoPropertiesPanel.start(p);
+    }
+    
+    private final class ContextAction extends AbstractAction implements Presenter.Popup {
+        private final Project m_project;
+        
+        public ContextAction(Lookup context) {
+            Project p = (Project) context.lookup(Project.class);
+            m_project = (p != null && enable(p)) ? p : null;
+        }
+        
+        public void actionPerformed(ActionEvent e) {
+            perform(m_project);
+        }
+        
+        public JMenuItem getPopupPresenter() {
+            class Presenter extends JMenuItem implements DynamicMenuContent {
+                public Presenter() {
+                    super(ContextAction.this);
+                }
+                public JComponent[] getMenuPresenters() {
+                    if (m_project != null) {
+                        Mnemonics.setLocalizedText(this, labelFor(m_project));
+                        return new JComponent[] {this};
+                    } else {
+                        return new JComponent[0];
+                    }
+                }
+                public JComponent[] synchMenuPresenters(JComponent[] items) {
+                    return getMenuPresenters();
+                }
+            }
+            return new Presenter();
+        }
+    }
+}
\ No newline at end of file

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateExternalJarProperties.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateExternalJarProperties.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateExternalJarProperties.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateExternalJarProperties.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,206 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: UpdateExternalJarProperties.java,v $
+ *
+ *  $Revision: 1.9 $
+ *
+ *  last change: $Author: sg $ $Date: 2009/02/13 09:10:55 $
+ *
+ *  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.projecttemplates.actions;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.PropertyResourceBundle;
+import java.util.Vector;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.openide.filesystems.FileLock;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openoffice.extensions.config.LibraryManager;
+import org.openoffice.extensions.util.LogWriter;
+import org.openoffice.extensions.util.ProjectTypeHelper;
+
+/**
+ * Update Java System properties for usage of external Jars in extensions
+ * and copy the jars in the dist directory.
+ * This class is used by every Action available for extensions.
+ * At the time of writing: debug, deploy, package
+ * 
+ */
+public class UpdateExternalJarProperties {
+    
+    /** 
+     * Only static methods: do not create
+     */
+    private UpdateExternalJarProperties() {
+    }
+
+    /**
+     * copy any additional referenced jars into the project for packaging 
+     * with the extension
+     * @param projectDir The project root directory
+     */
+    public static void copyAdditionalJars(FileObject projectDir) 
+                                throws IOException, URISyntaxException {
+        Vector<File> jars = new Vector<File>();
+        FileObject sourceRoot = FileUtil.createFolder(projectDir, "src"); // NOI18N
+        ClassPath cp = ClassPath.getClassPath(sourceRoot, ClassPath.COMPILE);
+
+        final String IDL_JAR_NAME = (String)ProjectTypeHelper.getObjectFromUnoProperties(
+                projectDir, "idl_types.jar"); // NOI18N
+        List<ClassPath.Entry> cpEntries = cp.entries();
+        // get the jars from classpath
+        for (Iterator<ClassPath.Entry> it = cpEntries.iterator(); it.hasNext(); ) {
+            ClassPath.Entry entry = it.next();
+            URL url = entry.getURL();
+            
+            String urlString = url.toString();
+
+            if (urlString.startsWith("jar:")) { // NOI18N
+                /* ResourceManager.class resides in a jar file. Strip it down to the 'file:' part */
+                urlString = urlString.substring(4, urlString.lastIndexOf('!'));
+                File jarFile = new File(new URI(urlString));
+                if (jarFile.exists()              // no broken references
+                        && IDL_JAR_NAME != null && urlString.indexOf(IDL_JAR_NAME) == -1) { // no idl types, get packed anyway
+                    boolean addFile = true;
+                    // do not add office jars
+                    for (int i = 0; i < LibraryManager.JAR_LIBRARIES.length; i++) {
+                        addFile &= (urlString.indexOf(LibraryManager.JAR_LIBRARIES[i]) == -1);
+                    }
+                    if (addFile) {
+                        jars.add(jarFile);
+                    }
+                }
+            }
+        }
+        String externalJarDir = null;
+        try {
+            FileObject f = projectDir.getFileObject("nbproject").getFileObject("project-uno", "properties"); // NOI18N
+            if (f != null) {
+                InputStream in = null;
+                try {
+                    in = f.getInputStream();
+                    PropertyResourceBundle unoProjectProps = new PropertyResourceBundle(in);
+                    externalJarDir = (String)unoProjectProps.handleGetObject("external.jar.dir"); // NOI18N
+                }
+                catch (IOException ex) {
+                    LogWriter.getLogWriter().printStackTrace(ex);
+                }
+                finally {
+                    if (in != null) {
+                        try {
+                            in.close();
+                        }
+                        catch (IOException ex) {
+                            LogWriter.getLogWriter().printStackTrace(ex);
+                        }
+                    }
+                }
+            }
+        }
+        finally {
+            // fallback name if property file cannot be read
+            if (externalJarDir == null || externalJarDir.length() == 0)
+                externalJarDir = "lib"; // NOI18N
+            System.setProperty("external.jar.dir", externalJarDir); // NOI18N
+        }
+        // copy the files
+        if (jars.size() != 0) {
+            FileObject dist = FileUtil.createFolder(projectDir, "dist"); // NOI18N
+            FileObject jarDirectory = FileUtil.createFolder(dist, externalJarDir);
+            FileObject[] entries = jarDirectory.getChildren();
+            // delete the jar files from that directory
+            for (int i = 0; i < entries.length; i++) {
+                FileLock lock = entries[i].lock();
+                try {
+                    entries[i].delete(lock);
+                }
+                finally {
+                    lock.releaseLock();
+                }
+            }
+            // copy
+            StringBuffer jarReference = new StringBuffer();
+            for (int i = 0; i < jars.size(); i++) {
+                File jarFile = jars.get(i);
+                FileObject sourceJar = FileUtil.toFileObject(jarFile);
+                FileUtil.copyFile(sourceJar, jarDirectory, sourceJar.getName());
+                if (i > 0) {
+                    jarReference.append(" "); // NOI18N
+                }
+                jarReference.append(externalJarDir).append("/").append(jarFile.getName()); // NOI18N
+            }
+            // write property for the classpath to the jars
+            Properties props = new Properties();
+            props.setProperty("external.jars", jarReference.toString()); // NOI18N
+            FileObject propsOut = FileUtil.createData(jarDirectory, "jars.properties"); // NOI18N
+            FileLock lock = propsOut.lock();
+            try {
+                OutputStream stream = propsOut.getOutputStream(lock);
+                try {
+                    props.store(stream, 
+                            "PackageActionDescription"); // NOI18N
+                }
+                finally {
+                    stream.close();
+                }
+            }
+            finally {
+                lock.releaseLock();
+            }
+        }
+        else {
+            // delete the external jars
+            FileObject dist = projectDir.getFileObject("dist"); // NOI18N
+            if (dist != null) {
+                FileObject jarDir = dist.getFileObject(externalJarDir);
+                if (jarDir != null) {
+                    // remove dir if it exists: this happens, 
+                    // when all external jars are dereferenced
+                    FileLock lock = jarDir.lock();
+                    try {
+                        jarDir.delete(lock);
+                    }
+                    finally {
+                        lock.releaseLock();
+                    }
+                }
+            }
+        }
+    }
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateProject.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateProject.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateProject.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/UpdateProject.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,351 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: UpdateProject.java,v $
+ *
+ *  $Revision: 1.7 $
+ *
+ *  last change: $Author: sg $ $Date: 2008/10/20 14:37:41 $
+ *
+ *  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.projecttemplates.actions;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.URLConnection;
+import java.util.MissingResourceException;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.openide.filesystems.FileLock;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.NbBundle;
+import org.openide.xml.XMLUtil;
+import org.openoffice.extensions.config.ConfigurationSettings;
+import org.openoffice.extensions.util.LogWriter;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Update all relevant file in a OOo project to the newest version,
+ * if this is necessary to support new features.
+ */
+public class UpdateProject {
+    
+    private FileObject m_projectRoot;
+    private String m_sVersionString;
+    private String m_sProjectName;
+    
+    public static void updateProject(FileObject projectRoot, String versionString, String projectName) {
+        UpdateProject up = new UpdateProject(projectRoot, versionString, projectName);
+        up.updateProject();
+        
+    }
+    
+    /** Creates a new instance of UpdateProject
+     * Do not instantiate, therefore private
+     */
+    private UpdateProject(FileObject projectRoot, String versionString, String projectName) {
+        m_projectRoot = projectRoot;
+        m_sVersionString = versionString;
+        m_sProjectName = projectName;
+    }
+    
+    private void updateProject() {
+        FileObject propsFile = m_projectRoot.getFileObject("nbproject/project-uno.properties"); // NOI18N
+        Properties props = new Properties();
+        try {
+            File f = FileUtil.toFile(propsFile);
+            FileInputStream fileIn = new FileInputStream(f);
+            props.load(fileIn);
+            fileIn.close();
+            String projTypes = props.getProperty("uno.project.type"); // NOI18N
+            String zipFileName = NbBundle.getMessage(UpdateProject.class, projTypes); // NOI18N
+            if (zipFileName != null) {  // try to get the file...
+                java.net.URL url = this.getClass().getResource("/".concat(zipFileName)); // NOI18N
+                URLConnection con = url.openConnection();
+                InputStream in = con.getInputStream();
+                changeProjectFiles(in);
+            }
+        } catch (FileNotFoundException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (MissingResourceException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (NullPointerException ex)  {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+    }
+    
+    private void changeProjectFiles(InputStream source) {
+        try {
+            ZipInputStream str = new ZipInputStream(source);
+            ZipEntry entry;
+            try {
+                while ((entry = str.getNextEntry()) != null) {
+                    if (entry.isDirectory()) {
+                        // in this template we don't have to change any paths
+                        continue;
+                    } else {
+                        if (entry.getName().endsWith("build-uno-impl.xml")) { // NOI18N
+                            // stream must be copied, or str is destroyed
+                            ByteArrayOutputStream temp = new ByteArrayOutputStream ((int) entry.getSize());
+                            FileUtil.copy (str, temp);
+                            byte[] buf = temp.toByteArray();
+                            ByteArrayInputStream stream = new ByteArrayInputStream(buf);
+                            handleBuildUnoXmlFile(stream);
+                        }
+                        else if (entry.getName().endsWith("project-uno.properties")) { // NOI18N
+                            handleUnoPropertiesFile(str);
+                        }
+                        else if (entry.getName().endsWith("CentralRegistrationClass.java")) { // NOI18N
+                            handleCentralregistrationClass(str);
+                        }
+                    }
+                }
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        } finally {
+            try {
+                source.close();
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+    }
+    
+    private void handleBuildUnoXmlFile(InputStream inStream) {
+        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        OutputStream outStream = null;
+        try {
+            DocumentBuilder builder = builderFactory.newDocumentBuilder();
+            Document newBuildUnoXmlDoc = builder.parse(inStream);
+            
+            // update the version string
+            NodeList propList = newBuildUnoXmlDoc.getElementsByTagName(ProjectVersion.PROPERTY_NAME);
+            for (int i = 0; i < propList.getLength(); i++) {
+                Node licenseNode = propList.item(i);
+                NamedNodeMap idAttr = licenseNode.getAttributes();
+                Node acceptValueNode = idAttr.getNamedItem(ProjectVersion.NAME_NAME);
+                if (acceptValueNode == null) continue;
+                String propName = acceptValueNode.getNodeValue();
+                if (ProjectVersion.UNO_VERSION_NAME.equals(propName)) {
+                    Node valueNode = idAttr.getNamedItem(ProjectVersion.VALUE_NAME);
+                    valueNode.setNodeValue(m_sVersionString);
+                }
+            }
+            
+            // update the project name; only one project element
+            NodeList projectList = newBuildUnoXmlDoc.getElementsByTagName(ProjectVersion.PROJECT_NAME);
+            Node projectNode = projectList.item(0);
+            NamedNodeMap projectAttributes = projectNode.getAttributes();
+            Node projectName = projectAttributes.getNamedItem(ProjectVersion.NAME_NAME);
+            projectName.setNodeValue(m_sProjectName);
+            
+            // write the stuff back
+            FileObject fo = m_projectRoot.getFileObject("nbproject").getFileObject("build-uno-impl", "xml"); // NOI18N
+
+            FileLock lock = fo.lock();
+            // Transmit the request document
+            outStream = fo.getOutputStream(lock);
+
+            XMLUtil.write(newBuildUnoXmlDoc, outStream, "UTF-8"); // NOI18N
+
+            lock.releaseLock();
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (SAXException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        } catch (ParserConfigurationException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        finally {
+            try {
+                if (outStream != null)
+                    outStream.close();
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+    }
+    
+    private void handleUnoPropertiesFile(InputStream inStream) {
+        FileObject fo = m_projectRoot.getFileObject("nbproject").getFileObject("project-uno", "properties"); // NOI18N
+        Properties newProps = new Properties();
+        try {
+            // load the new props from template
+            newProps.load(inStream);
+            
+            // load the existing props
+            InputStream in = fo.getInputStream();
+            newProps.load(in);
+            in.close();
+            
+            // update new variables that have __PlaceHolder__ settings as default
+            String sIdlTypes = newProps.getProperty("idl_types.jar");
+            if (sIdlTypes.equals("__ProjectName___IDL_types.jar")) {
+                // replace __ProjectName__
+                String projectName = newProps.getProperty("project.name");
+                sIdlTypes = sIdlTypes.replace("__ProjectName__", projectName);
+            }
+            newProps.setProperty("idl_types.jar", sIdlTypes);
+            String startupOptions = newProps.getProperty("office.startup.options");
+            if (startupOptions.equals("__StartupOptions__")) {
+                startupOptions = "";
+            }
+            newProps.setProperty("office.startup.options", startupOptions);
+            FileLock lock = fo.lock();
+            try {
+                OutputStream out = fo.getOutputStream(lock);
+                newProps.store(out, null);
+                out.close();
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+            finally {
+                lock.releaseLock();
+            }
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+    }
+    
+    private void handleCentralregistrationClass(InputStream inStream) {
+        FileObject projectUnoProps = m_projectRoot.getFileObject("nbproject").getFileObject("project-uno", "properties"); // NOI18N
+        Properties props = new Properties();
+        try {
+            // load the existing props
+            InputStream in = projectUnoProps.getInputStream();
+            props.load(in);
+            in.close();
+            String centralRegClass = props.getProperty("central.registration.class"); // NOI18N
+            // entry exists, do nothing
+            if (centralRegClass == null || centralRegClass.length() == 0 || centralRegClass.equals("__CentralRegistrationClass__")) { // NOI18N
+                String packageName = props.getProperty("registration.classname"); // NOI18N
+                if (packageName == null) packageName = "";
+                // get the first package structure here
+                int index = packageName.indexOf(' ');
+                if (index != - 1) {
+                    packageName = packageName.substring(0, index);
+                }
+                index = packageName.lastIndexOf('.');
+                if (index != -1) {
+                    packageName = packageName.substring(0, index);
+                }
+                String fileName = packageName.concat(".CentralRegistrationClass"); // NOI18N
+                
+                // write correct properties back
+                props.setProperty("central.registration.class", fileName); // NOI18N
+                FileLock lock = projectUnoProps.lock();
+                try {
+                    OutputStream out = projectUnoProps.getOutputStream(lock);
+                    props.store(out, null);
+                    out.close();
+                } catch (IOException ex) {
+                    LogWriter.getLogWriter().printStackTrace(ex);
+                }
+                finally {
+                    lock.releaseLock();
+                }
+                
+                // write central registration class file object...
+                FileObject targetFolderObject = FileUtil.createFolder(
+                    m_projectRoot.getFileObject("src"), packageName.replace('.', '/')); // NOI18N
+                
+                FileObject targetFileObject = null;
+                try {
+                    targetFileObject = targetFolderObject.createData("CentralRegistrationClass", "java");
+                } catch (IOException ex) {
+                    LogWriter.getLogWriter().printStackTrace(ex);
+                }
+                
+                if (targetFileObject != null) {  // do not overwrite something existing
+                    BufferedReader buf = new BufferedReader(new InputStreamReader(inStream));
+                    lock = targetFileObject.lock();
+                    try {
+                        OutputStream out = targetFileObject.getOutputStream(lock);
+                        BufferedWriter write = new BufferedWriter(new OutputStreamWriter(out));
+                        while (buf.ready()) {
+                            String line = buf.readLine();
+                            line = replaceLine(line, packageName);
+                            write.write(line, 0, line.length());
+                            write.newLine();
+                        }
+                        write.close();
+                    } catch (IOException ex) {
+                        LogWriter.getLogWriter().printStackTrace(ex);
+                    }
+                    finally {
+                        lock.releaseLock();
+                    }
+                }
+                else {
+                    LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, "File " + packageName.concat(".CentralRegistrationClass.java")
+                        + " already exists in directory structure and is not overwritten. " + 
+                        "Registration is supposed to fail."); // NOI18N
+                }
+                
+            }
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+    }
+    
+    private String replaceLine(String line, String packageName) {
+        // replace the three things that can occur here
+        if (line.indexOf("__UnoPackage__") != -1) {
+            line = line.replaceAll("__UnoPackage__", packageName);
+        }
+        if (line.indexOf("__TimeStamp__") != -1) {
+            line = line.replaceAll("__TimeStamp__", ConfigurationSettings.getTimeStamp());
+        }
+        if (line.indexOf("__UserName__") != -1) {
+            line = line.replaceAll("__UserName__", ConfigurationSettings.getSettings().getUser());
+        }
+        return line;
+    }
+}

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle.properties
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle.properties?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle.properties (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle.properties Fri Jan 27 01:29:33 2012
@@ -0,0 +1,87 @@
+#LBL_Button_AddDialog=&Add...
+#LBL_Button_New=&New...
+#LBL_Button_Edit=&Edit...
+#LBL_Button_Add=&Add
+#LBL_Button_Delete=&Delete
+#LBL_Button_DeleteDialoge=&Delete...
+
+# panel Version
+#TITLE_Version=Extension Management
+#TXT_Version_Tooltip=Give your extension a unique identifier and a version number.
+#LBL_Extension_Identifier=Extension Identifier:
+#LBL_Extension_Version=Extension Version:
+#TXT_VersionUniqueHint=The identifier of the extension must be unique:\n\
+#it is used to identify the extension when it is registered in OpenOffice.org.
+
+#panel Dependency
+#TITLE_Dependency=Dependency
+#TXT_Dependency_Tooltip=Set the dependency of your extension on a specific OpenOffice.org version.
+#LBL_OOo_Version_Number=OpenOffice.org Version Number:
+#LBL_OOo_Version_Name=OpenOffice.org Version Name:
+
+#panel Update
+#TITLE_Update=Update
+#TXT_Update_Tooltip=Add one ore more URLs for updating your extension to newer versions.
+#LBL_Update_Urls=Update URLs
+
+#panel License
+#TITLE_License=License
+#TXT_License_Tooltip=Add a (localized) license text to your extension.
+#LABEL_LicenseName=License Name
+#LABEL_Locale=Locale
+#LABEL_DefaultLicense=Default
+#LABEL_Accepted=License must be accepted by
+#LBL_FileChooserTitle=Select License Files
+#MSG_File_Description=TXT files only
+#ERROR_MissingLicense=This License file does not exist:
+#ERROR_DoubleLicense=This License name is doubled:
+#ERROR_DoubleLocale=This Locale is doubled:
+#MSG_DeleteFiles=Also delete these files in the source path:
+
+#ERROR_Genreal_=There entered values are illegal.
+
+#LBL_Accepted=
+
+#TP_InitialSettings_Description=
+
+PropsPanel.FileChooserTitle=Select File
+EditAndOpenPanel.jButton1.text=...
+EditTextContentPanel.jFileLabel.text=Editing: 
+PropsPanel.jLabelDisplayName.text=Display &Name:
+PropsPanel.jLabelDescription.text=&Description:
+PropsPanel.jLabelPublisherName.text=&Publisher Name:
+PropsPanel.jLabelPublisherLink.text=Publi&sher Link:
+PropsPanel.jLabelLicense.text=License:
+PropsPanel.jLabelIcon.text=Default &Icon:
+PropsPanel.Browse.text=&Browse...
+PropsPanel.Browse.text2=B&rowse...
+PropsPanel.Browse.text3=Br&owse...
+PropsPanel.Browse.text4=Bro&wse...
+PropsPanel.jLabelCurrentLocale.text=&Current Locale:
+PropsPanel.jLabelDefaultLocale.text=Default &Locale:
+PropsPanel.jDescriptionField.text=
+PropsPanel.jLicenseField.text=
+PropsPanel.jIconField.text=
+PropsPanel.jLabel1.text=Accept License:
+PropsPanel.jRadioButtonUser.text=&User
+PropsPanel.jRadioButtonAdmin.text=&Admin
+PropsPanel.EditLicense.Title=Edit license file
+PropsPanel.EditDescription.Title=Edit description file
+PropsPanel.ShowIcon.Title=Extension icon
+PropsPanel.ShowIcon.ErrorMessage=No icon file available
+PropsPanel.jLabelIcon1.text=&High Definition Icon:
+VersionPanel.jIdentifierLabel.text=Unique &Identifier:
+VersionPanel.jVersionLabel.text=&Version:
+VersionPanel.jDepValue.text=&Dependency Version:
+VersionPanel.jDepName.text=Dependency Name:
+VersionPanel.jUpdate.text=&Update URLs:
+
+VerifyData.ErrorMessage.Identifier=Identifiers should be of the form 'org.yourorg.here.MainProjectName'
+VerifyData.ErrorMessage.Version=Version should be of the form <major>.<minor>.<micro>, e.g. '1.1.4'
+VerifyData.ErrorMessage.DepVersion=Dependency should be of the form '3.0', meaning OpenOffice.org 3.0
+#in the following messages, $1 will be replaced by a locale name
+VerifyData.ErrorMessage.DisplayName=Display Name entry missing for locale: $1
+VerifyData.ErrorMessage.Description=Description entry missing for locale: $1
+VerifyData.ErrorMessage.License=License entry missing for locale: $1
+VerifyData.ErrorMessage.Publisher=Publisher entry missing for locale: $1
+

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_ja.properties
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_ja.properties?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_ja.properties (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_ja.properties Fri Jan 27 01:29:33 2012
@@ -0,0 +1,81 @@
+# panel Version
+# TITLE_Version=Extension Management
+TITLE_Version=\u62e1\u5f35\u306e\u7ba1\u7406
+# TXT_Version_Tooltip=Give your extension a unique identifier and a version number.
+TXT_Version_Tooltip=\u62e1\u5f35\u306b\u4e00\u610f\u306e\u8b58\u5225\u5b50\u3068\u30d0\u30fc\u30b8\u30e7\u30f3\u756a\u53f7\u3092\u4ed8\u3051\u3066\u304f\u3060\u3055\u3044\u3002
+# LBL_Extension_Identifier=Extension Identifier:
+LBL_Extension_Identifier=\u62e1\u5f35\u306e\u8b58\u5225\u5b50:
+# LBL_Extension_Version=Extension Version:
+LBL_Extension_Version=\u62e1\u5f35\u306e\u30d0\u30fc\u30b8\u30e7\u30f3:
+# TXT_VersionUniqueHint=The identifier of the extension must be unique:\n\
+# it is used to identify the extension when it is registered in OpenOffice.org.
+
+TXT_VersionUniqueHint=\u62e1\u5f35\u306e\u8b58\u5225\u5b50\u306f\u4e00\u610f\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059:\n\
+\u62e1\u5f35\u306e\u8b58\u5225\u5b50\u306f\u3001OpenOffice.org \u306b\u767b\u9332\u3055\u308c\u308b\u3068\u304d\u306b\u3001\u62e1\u5f35\u3092\u8b58\u5225\u3059\u308b\u306e\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
+
+#panel Dependency
+# TITLE_Dependency=Dependency
+TITLE_Dependency=\u4f9d\u5b58\u6027
+# TXT_Dependency_Tooltip=Set the dependency of your extension on a specific OpenOffice.org version.
+TXT_Dependency_Tooltip=\u7279\u5b9a\u306e OpenOffice.org \u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306e\u62e1\u5f35\u306e\u4f9d\u5b58\u6027\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002
+# LBL_OOo_Version_Number=OpenOffice.org Version Number:
+LBL_OOo_Version_Number=OpenOffice.org \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u756a\u53f7:
+# LBL_OOo_Version_Name=OpenOffice.org Version Name:
+LBL_OOo_Version_Name=OpenOffice.org \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u540d:
+
+#panel Update
+# TITLE_Update=Update
+TITLE_Update=\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8
+# TXT_Update_Tooltip=Add one ore more URLs for updating your extensionto newer versions.
+TXT_Update_Tooltip=\u62e1\u5f35\u3092\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u305f\u3081\u306e 1 \u3064\u4ee5\u4e0a\u306e URL \u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002
+
+# LBL_Update_Urls=Update URLs
+LBL_Update_Urls=URL \u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8
+
+#panel License
+# TITLE_License=License
+TITLE_License=\u30e9\u30a4\u30bb\u30f3\u30b9
+# TXT_License_Tooltip=Add a (localized) license text to your extension.
+TXT_License_Tooltip=\u62e1\u5f35\u306b (\u30ed\u30fc\u30ab\u30e9\u30a4\u30ba\u3055\u308c\u305f) \u4f7f\u7528\u8a31\u8afe\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002
+# LABEL_LicenseName=License Name
+LABEL_LicenseName=\u30e9\u30a4\u30bb\u30f3\u30b9\u540d
+# LABEL_Locale=Locale
+LABEL_Locale=\u30ed\u30b1\u30fc\u30eb
+# LABEL_DefaultLicense=Default
+LABEL_DefaultLicense=\u30c7\u30d5\u30a9\u30eb\u30c8
+# LABEL_Accepted=License must be accepted by
+LABEL_Accepted=\u540c\u610f\u304c\u5fc5\u8981\u306a\u30e9\u30a4\u30bb\u30f3\u30b9
+# LBL_FileChooserTitle=Select License Files
+LBL_FileChooserTitle=\u30e9\u30a4\u30bb\u30f3\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u9078\u629e
+# MSG_File_Description=TXT files only
+MSG_File_Description=TXT \u30d5\u30a1\u30a4\u30eb\u306e\u307f
+# ERROR_MissingLicense=This License file does not exist:
+ERROR_MissingLicense=\u3053\u306e\u30e9\u30a4\u30bb\u30f3\u30b9\u30d5\u30a1\u30a4\u30eb\u306f\u5b58\u5728\u3057\u307e\u305b\u3093:
+# ERROR_DoubleLicense=This License name is doubled:
+ERROR_DoubleLicense=\u3053\u306e\u30e9\u30a4\u30bb\u30f3\u30b9\u540d\u306f\u91cd\u8907\u3057\u3066\u3044\u307e\u3059:
+# ERROR_DoubleLocale=This Locale is doubled:
+ERROR_DoubleLocale=\u3053\u306e\u30ed\u30b1\u30fc\u30eb\u306f\u91cd\u8907\u3057\u3066\u3044\u307e\u3059:
+# MSG_DeleteFiles=Also delete these files in the source path:
+MSG_DeleteFiles=\u30bd\u30fc\u30b9\u30d1\u30b9\u306e\u3053\u308c\u3089\u306e\u30d5\u30a1\u30a4\u30eb\u3082\u524a\u9664:
+
+# general
+# LBL_Button_AddDialog=&Add...
+LBL_Button_AddDialog=\u8ffd\u52a0(&A)...
+# LBL_Button_New=&New...
+LBL_Button_New=\u65b0\u898f(&N)...
+# LBL_Button_Edit=&Edit...
+LBL_Button_Edit=\u7de8\u96c6(&E)...
+# LBL_Button_Add=&Add
+LBL_Button_Add=\u8ffd\u52a0(&A)
+# LBL_Button_Delete=&Delete
+LBL_Button_Delete=\u524a\u9664(&D)
+# LBL_Button_DeleteDialoge=&Delete...
+LBL_Button_DeleteDialoge=\u524a\u9664(&D)...
+
+# ERROR_Genreal_=There entered values are illegal.
+ERROR_Genreal_=\u5165\u529b\u3055\u308c\u305f\u5024\u304c\u4e0d\u6b63\u3067\u3059\u3002
+
+# LBL_Accepted=
+LBL_Accepted=
+
+

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_pt_BR.properties
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_pt_BR.properties?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_pt_BR.properties (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_pt_BR.properties Fri Jan 27 01:29:33 2012
@@ -0,0 +1,45 @@
+LBL_Button_AddDialog=&Add...
+LBL_Button_New=&New...
+LBL_Button_Edit=&Edit...
+LBL_Button_Add=&Add
+LBL_Button_Delete=&Delete
+LBL_Button_DeleteDialoge=&Delete...
+
+# panel Version
+TITLE_Version=Extension Management
+TXT_Version_Tooltip=Give your extension a unique identifier and a version number.
+LBL_Extension_Identifier=Extension Identifier:
+LBL_Extension_Version=Extension Version:
+TXT_VersionUniqueHint=The identifier of the extension must be unique:\n\
+it is used to identify the extension when it is registered in OpenOffice.org.
+
+#panel Dependency
+TITLE_Dependency=Dependency
+TXT_Dependency_Tooltip=Set the dependency of your extension on a specific OpenOffice.org version.
+LBL_OOo_Version_Number=OpenOffice.org Version Number:
+LBL_OOo_Version_Name=OpenOffice.org Version Name:
+
+#panel Update
+TITLE_Update=Update
+TXT_Update_Tooltip=Add one ore more URLs for updating your extension to newer versions.
+LBL_Update_Urls=Update URLs
+
+#panel License
+TITLE_License=License
+TXT_License_Tooltip=Add a (localized) license text to your extension.
+LABEL_LicenseName=License Name
+LABEL_Locale=Locale
+LABEL_DefaultLicense=Default
+LABEL_Accepted=License must be accepted by
+LBL_FileChooserTitle=Select License Files
+MSG_File_Description=TXT files only
+ERROR_MissingLicense=This License file does not exist:
+ERROR_DoubleLicense=This License name is doubled:
+ERROR_DoubleLocale=This Locale is doubled:
+MSG_DeleteFiles=Also delete these files in the source path:
+
+ERROR_Genreal_=There entered values are illegal.
+
+LBL_Accepted=
+
+TP_InitialSettings_Description=

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_zh_CN.properties
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_zh_CN.properties?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_zh_CN.properties (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/Bundle_zh_CN.properties Fri Jan 27 01:29:33 2012
@@ -0,0 +1,44 @@
+# panel Version
+TITLE_Version=\u6269\u5c55\u7ec4\u4ef6\u7ba1\u7406
+TXT_Version_Tooltip=\u7ed9\u4e88\u60a8\u7684\u6269\u5c55\u7ec4\u4ef6\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\u548c\u7248\u672c\u53f7\u3002
+LBL_Extension_Identifier=\u6269\u5c55\u7ec4\u4ef6\u6807\u8bc6\u7b26\uff1a
+LBL_Extension_Version=\u6269\u5c55\u7ec4\u4ef6\u7248\u672c\u53f7\uff1a
+TXT_VersionUniqueHint=\u6269\u5c55\u7ec4\u4ef6\u7684\u6807\u8bc6\u7b26\u5fc5\u987b\u662f\u552f\u4e00\u7684\uff1a\n\
+\u5728 OpenOffice.org \u6ce8\u518c\u8be5\u6807\u8bc6\u7b26\u540e\uff0c\u5b83\u5c06\u7528\u4e8e\u8bc6\u522b\u6269\u5c55\u7ec4\u4ef6\u3002
+
+#panel Dependency
+TITLE_Dependency=\u4f9d\u8d56\u5173\u7cfb
+TXT_Dependency_Tooltip=\u5c06\u60a8\u7684\u6269\u5c55\u7ec4\u4ef6\u8bbe\u7f6e\u4e3a\u4f9d\u8d56\u4e8e\u67d0\u4e2a\u7279\u5b9a\u7684 OpenOffice.org \u7248\u672c\u3002
+LBL_OOo_Version_Number=OpenOffice.org \u7248\u672c\u53f7\uff1a
+LBL_OOo_Version_Name=OpenOffice.org \u7248\u672c\u540d\u79f0\uff1a
+
+#panel Update
+TITLE_Update=\u66f4\u65b0
+TXT_Update_Tooltip=\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a URL \u4ee5\u4fbf\u66f4\u65b0\u6269\u5c55\u7ec4\u4ef6\u7684\u7248\u672c\u3002
+LBL_Update_Urls=\u66f4\u65b0 URL
+
+#panel License
+TITLE_License=\u8bb8\u53ef\u8bc1
+TXT_License_Tooltip=\u4e3a\u60a8\u7684\u6269\u5c55\u7ec4\u4ef6\u6dfb\u52a0\uff08\u672c\u5730\u5316\u7684\uff09\u8bb8\u53ef\u8bc1\u6587\u672c\u3002
+LABEL_LicenseName=\u8bb8\u53ef\u8bc1\u540d\u79f0
+LABEL_Locale=\u8bed\u8a00\u73af\u5883
+LABEL_DefaultLicense=\u7f3a\u7701
+LABEL_Accepted=\u5fc5\u987b\u6309\u4e0b\u5217\u65b9\u5f0f\u63a5\u53d7\u8bb8\u53ef\u8bc1\u534f\u8bae
+LBL_FileChooserTitle=\u9009\u62e9\u8bb8\u53ef\u8bc1\u6587\u4ef6
+MSG_File_Description=\u4ec5\u9650 TXT \u6587\u4ef6
+ERROR_MissingLicense=\u6b64\u8bb8\u53ef\u8bc1\u6587\u4ef6\u4e0d\u5b58\u5728\uff1a
+ERROR_DoubleLicense=\u6b64\u8bb8\u53ef\u8bc1\u91cd\u540d\uff1a
+ERROR_DoubleLocale=\u6b64\u8bed\u8a00\u73af\u5883\u91cd\u590d\uff1a
+MSG_DeleteFiles=\u540c\u65f6\u4ece\u6e90\u8def\u5f84\u4e2d\u5220\u9664\u8fd9\u4e9b\u6587\u4ef6\uff1a
+
+# general
+LBL_Button_AddDialog=\u6dfb\u52a0(&A)...
+LBL_Button_New=\u65b0\u5efa(&N)...
+LBL_Button_Edit=\u7f16\u8f91(&E)...
+LBL_Button_Add=\u6dfb\u52a0(&A)...
+LBL_Button_Delete=\u5220\u9664(&D)
+LBL_Button_DeleteDialoge=\u5220\u9664(&D)...
+
+ERROR_Genreal_=\u8be5\u5904\u8f93\u5165\u7684\u503c\u975e\u6cd5\u3002
+
+LBL_Accepted=

Added: incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/DataHandler.java
URL: http://svn.apache.org/viewvc/incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/DataHandler.java?rev=1236486&view=auto
==============================================================================
--- incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/DataHandler.java (added)
+++ incubator/ooo/devtools/netbeansintegration/src/org/openoffice/extensions/projecttemplates/actions/panel/DataHandler.java Fri Jan 27 01:29:33 2012
@@ -0,0 +1,457 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: DataHandler.java,v $
+ *
+ *  $Revision: 1.7 $
+ *
+ *  last change: $Author: jsc $ $Date: 2009/07/16 11:38:30 $
+ *
+ *  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.projecttemplates.actions.panel;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openoffice.extensions.util.LogWriter;
+import org.openoffice.extensions.util.ProjectTypeHelper;
+import org.openoffice.extensions.util.datamodel.localization.LanguageDefinition;
+
+/**
+ * This class consolidates handling of data that goes to decsription.xml. 
+ * The class is mostly just a wrapper around datat structures and the
+ * handler classes for the description.xml file. 
+ */
+public class DataHandler {
+    private FileObject m_ProjectDir;
+    private DescriptionXmlHandler m_DXmlHandler;
+    private HashMap<String, GenericDescriptionProperty>table;
+
+    
+    public DataHandler(FileObject projectDir) {
+        m_ProjectDir = projectDir;
+        // clear resident data
+        table = new HashMap<String, GenericDescriptionProperty>();
+        // description handler last
+        m_DXmlHandler = new DescriptionXmlHandler(m_ProjectDir, this);
+        
+        // initialize locale if nothing can be obtained from description.xml
+        if (m_DXmlHandler.getDefaultLocale() == null) {
+            m_DXmlHandler.setDefaultLocale(
+                    LanguageDefinition.getLanguageShortNameForId(
+                    LanguageDefinition.LANGUAGE_ID_en));
+        }
+    }
+    
+    // TODO: think of method to remove unchecked warning
+    @SuppressWarnings("unchecked")
+    public void clearAll() {
+        Collection<GenericDescriptionProperty> c = table.values();
+        for (Iterator<GenericDescriptionProperty> it = c.iterator(); it.hasNext();) {
+            GenericDescriptionProperty<String> genericDescriptionProperty = it.next();
+            synchronized(genericDescriptionProperty) { 
+                genericDescriptionProperty.clear();
+            }
+        }
+        table.clear();
+    }
+
+    // TODO: think of method to remove unchecked warning
+    @SuppressWarnings("unchecked")
+    public GenericDescriptionProperty<String> getGenericStringProperty(String name) {
+        GenericDescriptionProperty<String> item = table.get(name);
+        if (item == null) {
+            item = new GenericDescriptionProperty<String>(name);
+            table.put(name, item);
+        }
+        return item;
+    }
+
+    // TODO: think of method to remove unchecked warning
+    @SuppressWarnings("unchecked")
+    public GenericDescriptionProperty<String[]> getGenericStringArrayProperty(String name) {
+        GenericDescriptionProperty<String[]> item = table.get(name);
+        if (item == null) {
+            item = new GenericDescriptionProperty<String[]>(name);
+            table.put(name, item);
+        }
+        return item;
+    }
+
+    public boolean hasDataForLocale(String locale) {
+        Collection<GenericDescriptionProperty> c = table.values();
+        for (Iterator<GenericDescriptionProperty> it = c.iterator(); it.hasNext();) {
+            GenericDescriptionProperty genericDescriptionProperty = it.next();
+            Object o = genericDescriptionProperty.getPropertyForLocale(locale);
+            if (o != null) {
+                // do not recognize publisher link!
+                if (genericDescriptionProperty.getName().equals("publisher")) {
+                    String[]object = (String[])genericDescriptionProperty.getPropertyForLocale(locale);
+                    if (object[0] != null && object[0].length() > 0) {
+                        return true;
+                    }
+                }
+                else {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
+    public GenericDescriptionProperty<String> getDisplayData() {
+         return m_DXmlHandler.getDisplayData();
+    }
+
+    public void setDisplayData(GenericDescriptionProperty<String> data) {
+         m_DXmlHandler.setDisplayData(data);
+    }
+
+    public void setLicenseFiles(GenericDescriptionProperty<String> data) {
+         m_DXmlHandler.setLicenseFiles(data);
+    }
+
+    public GenericDescriptionProperty<String> getLicenseFiles() {
+         return m_DXmlHandler.getLicenseFiles();
+    }
+
+    public boolean getLicenseAcceptByUser() {
+        String acceptby = m_DXmlHandler.getAcceptBy();
+        return (acceptby != null && acceptby.equals("user")); // NOI18N
+    }
+    
+    public boolean hasLicenseFiles() {
+        GenericDescriptionProperty<String> licenses = m_DXmlHandler.getLicenseFiles();
+        if (licenses.getSize() > 0) {
+            return true;
+        }
+        return false;
+    }
+    
+    public void setLicenseAcceptByUser(boolean acceptbyuser) {
+        m_DXmlHandler.setAcceptBy(acceptbyuser?"user":"admin"); // NOI18N
+    }
+    
+    public void setPublisherData(GenericDescriptionProperty<String[]> data) {
+         m_DXmlHandler.setPublisherData(data);
+    }
+    
+    public GenericDescriptionProperty<String[]> getPublisherData() {
+         return m_DXmlHandler.getPublisherData();
+    }
+    
+    public void setDescriptionData(GenericDescriptionProperty<String> data) {
+        m_DXmlHandler.setDescriptionData(data);
+    }
+    
+    public GenericDescriptionProperty<String> getDescriptionData() {
+        return m_DXmlHandler.getDescriptionData();
+    }
+    
+    public void setVersion(String version) {
+        m_DXmlHandler.setExtensionVersion(version);
+    }
+    
+    public String getVersion() {
+        return m_DXmlHandler.getExtensionVersion();
+    }
+    
+    public void setIdentifier(String identifier) {
+        m_DXmlHandler.setExtensionIdentifier(identifier);
+    }
+    
+    public String getIdentifier() {
+        return m_DXmlHandler.getExtensionIdentifier();
+    }
+    
+    public String getDefaultShortLocale() {
+        return m_DXmlHandler.getDefaultLocale();
+    }
+    
+    public void setDefaultShortLocale(String locale) {
+        m_DXmlHandler.setDefaultLocale(locale);
+    }
+    
+    public void setDependencyName(String dependencyName) {
+        m_DXmlHandler.setDependencyName(dependencyName);
+    }
+    
+    public String getDependencyName() {
+        return m_DXmlHandler.getDependencyName();
+    }
+    
+    public void setDependencyNumber(String value) {
+        m_DXmlHandler.setDependencyNumber(value);
+    }
+    
+    public String getDependencyNumber() {
+        return m_DXmlHandler.getDependencyNumber();
+    }
+    
+    public void setUpdateURLs(String[] urls) {
+        m_DXmlHandler.setUpdateURLs(urls);
+    }
+    
+    public String[] getUpdateURLs() {
+        return m_DXmlHandler.getUpdateURLs();
+    }
+    
+    public void setIconFile(String iconFile) {
+        m_DXmlHandler.setDefaultIconName(iconFile);
+    }
+    
+    public String getIconFile() {
+        return m_DXmlHandler.getDefaultIconName();
+    }
+    
+    public void setHighDefIconFile(String iconFile) {
+        m_DXmlHandler.setHighContrastIconName(iconFile);
+    }
+    
+    public String getHighDefIconFile() {
+        return m_DXmlHandler.getHighContrastIconName();
+    }
+    
+    public FileObject getProjectDir() {
+        return m_ProjectDir;
+    }
+            
+    /**
+     * Trigger storing back the changes in properties panels: this is called by
+     * OOoCustomizerProvider which has 
+     */
+    public void store() {
+        copyFiles();
+        // make sure default locale is first.
+        String localeName = m_DXmlHandler.getDefaultLocale();
+        getPublisherData().setDefaultLocale(localeName);
+        getDisplayData().setDefaultLocale(localeName);
+        getLicenseFiles().setDefaultLocale(localeName);
+        getDescriptionData().setDefaultLocale(localeName);
+        
+        m_DXmlHandler.writeDescriptionXml();
+    }
+    
+    private void copyFiles() {
+        // copy description files
+        String propKey = "description.dir"; // NOI18N
+        String descriptionDir = (String)ProjectTypeHelper.getObjectFromUnoProperties(m_ProjectDir, propKey);
+        GenericDescriptionProperty<String> descriptionFiles = getDescriptionData();
+        ArrayList<Integer> deleteDescriptionIndexes = new ArrayList<Integer>();
+        for (int i = 0; i < descriptionFiles.getSize(); i++) {
+            String object = descriptionFiles.getProperty(i);
+            String name = getNameFromSource(object);
+            // if file could not be copied, do not refer to it in xml file
+            if (copyOneFile(object, descriptionDir, name)) {
+                descriptionFiles.setProperty(i, descriptionDir.concat("/").concat(name));
+            }
+            else {
+                // do not change size in loop which relies on it!
+                deleteDescriptionIndexes.add(i);
+            }
+        }
+        // delete from list now: traverse from top to bottom to prevent index out of bounds exception
+        for (int i = deleteDescriptionIndexes.size() - 1; i >= 0; i--) {
+            Integer integer = deleteDescriptionIndexes.get(i);
+            descriptionFiles.deletePropertyAndLocale(integer);
+        }
+
+        // copy license files
+        propKey = "licenses.dir"; // NOI18N
+        String licenseDir = (String)ProjectTypeHelper.getObjectFromUnoProperties(m_ProjectDir, propKey);
+        GenericDescriptionProperty<String> licenseFiles = getLicenseFiles();
+        ArrayList<Integer> deleteLicenseIndexes = new ArrayList<Integer>();
+        // if file could not be copied, do not refer to it in xml file
+        for (int i = 0; i < licenseFiles.getSize(); i++) {
+            String object = licenseFiles.getProperty(i);
+            String name = getNameFromSource(object);
+            if (copyOneFile(object, licenseDir, name)) {
+                licenseFiles.setProperty(i, licenseDir.concat("/").concat(name));
+            }
+            else {
+                // do not change size in loop which relies on it!
+                deleteLicenseIndexes.add(i);
+            }
+        }
+        // delete from list now: traverse from top to bottom to prevent index out of bounds exception
+        for (int i = deleteLicenseIndexes.size() - 1; i >= 0; i--) {
+            Integer integer = deleteLicenseIndexes.get(i);
+            licenseFiles.deletePropertyAndLocale(integer);
+        }
+        
+        // copy icon files
+        propKey = "images.dir"; // NOI18N
+        String imagesDir = (String)ProjectTypeHelper.getObjectFromUnoProperties(m_ProjectDir, propKey);
+        File iconFile = getProjectOrSystemPath(getIconFile());
+        if (iconFile != null) {
+            try {
+                String fileName = iconFile.getCanonicalPath();
+                String name = getNameFromSource(fileName);
+                if (copyOneFile(fileName, imagesDir, name)) {
+                    // add to description handler
+                    m_DXmlHandler.setDefaultIconName(imagesDir.concat("/").concat(name));
+                }
+                else {
+                    m_DXmlHandler.setDefaultIconName(null);
+                }
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+        iconFile = getProjectOrSystemPath(getHighDefIconFile());
+        if (iconFile != null) {
+            try {
+                String fileName = iconFile.getCanonicalPath();
+                String name = getNameFromSource(fileName);
+                if (copyOneFile(fileName, imagesDir, name)) {
+                    // add to description handler
+                    m_DXmlHandler.setHighContrastIconName(imagesDir.concat("/").concat(name));
+                }
+                else {
+                    m_DXmlHandler.setHighContrastIconName(null);
+                }
+            } catch (IOException ex) {
+                LogWriter.getLogWriter().printStackTrace(ex);
+            }
+        }
+    }
+    
+    private boolean copyOneFile(String source, String target, String name) {
+        // initial test
+        if (source == null || target == null || name == null) {
+            return false;
+        }
+        File sourceFile = getProjectOrSystemPath(source);
+        File targetDir = getOrCreateProjectSubDir(target);
+        // some cases where copying will not be done
+        if (sourceFile == null || targetDir == null) {
+            return false;
+        }
+        if (targetDir.equals(sourceFile.getParentFile())) {
+            // target file already there: everything is ok
+            return true;
+        }
+        if (!targetDir.exists() && !targetDir.canWrite()) {
+            // target dir is not writeable: fail.
+            return false;
+        }
+        FileObject sourceFileObject = FileUtil.toFileObject(sourceFile);
+        FileObject targetDirObject = FileUtil.toFileObject(targetDir);
+        if (sourceFileObject == null || targetDirObject == null) {
+            // do not try copying with null objects
+            return false;
+        }
+        FileObject targetFileObject = targetDirObject.getFileObject(name);
+        if (targetFileObject != null && targetFileObject.isValid()) {  // file to copy is already there: do nothing
+            return true;
+        }
+        
+        // construct proper name
+        int index = name.lastIndexOf('.');
+        if (index >= 0) {
+            name = name.substring(0, index);
+        }
+        try {
+            FileUtil.copyFile(sourceFileObject, targetDirObject, name);
+            return true;
+        } catch (IOException ex) {
+            LogWriter.getLogWriter().printStackTrace(ex);
+        }
+        return false;
+    }
+
+    /**
+     * Get the name from a path give as string
+     * @param source a system path like c:\temp\document.txt
+     * @return the name of the file, e.g. document.txt
+     */
+    private String getNameFromSource(String source) {
+        if (source != null && source.length() > 0) {
+            // next line call is somewhat called twice in one copying process: improve algorithm?
+            File f = getProjectOrSystemPath(source);
+            if (f != null)
+                return f.getName();
+        }
+        return null;
+    }
+    
+    /**
+     * Return the subdirectory (can also be a directory structure) in the
+     * project folder. The directory is created if it not yet exists.
+     * @param dirName The directory or a structure with "/" as path separator
+     * @return the new directory as file, null if the directory does not 
+     * exist and could not be created
+     */
+    private File getOrCreateProjectSubDir(String dirName) {
+        if (dirName != null) {
+            FileObject newObject = m_ProjectDir.getFileObject(dirName);
+            if (newObject == null) {
+                File projectDir = FileUtil.toFile(m_ProjectDir);
+                File newFile = new File(projectDir, dirName);
+                if (newFile.mkdir()) return newFile;
+            }
+            else{
+                return FileUtil.toFile(newObject);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Get the complete path to a file in the project file system or in the
+     * system.
+     * @param localOrSystemPath local path in project or system path
+     * @return the absolute path
+     */
+    public File getProjectOrSystemPath(String localOrSystemPath) {
+        File file = null;
+        if (localOrSystemPath != null && localOrSystemPath.length() > 0) {
+            // try to find the file in project subdirectory
+            FileObject localFolder = m_ProjectDir.getFileObject(localOrSystemPath);
+            if (localFolder != null) {
+                File f = FileUtil.toFile(localFolder);
+                if (f != null && f.canRead()) {
+                    file = f;
+                }
+            }
+            if (file == null) { // first try did not work
+                // read file directly
+                File f = new File(localOrSystemPath);
+                if (f != null && f.canRead()) {
+                    file = f;
+                }
+            }
+        }
+        return file;
+    }
+    
+}



Mime
View raw message