Kaydet (Commit) a1552a0e authored tarafından David Ostrovsky's avatar David Ostrovsky Kaydeden (comit) Stephan Bergmann

Scripting: Remove org package

Change-Id: If0b6ac87b5d53da43557dee5824e9413a260ba7c
Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 87bf3fb4
Manifest-Version: 1.0
OpenIDE-Module: org.openoffice.netbeans.modules.office/1
OpenIDE-Module-Name: Office Support
OpenIDE-Module-Short-Description: Scripting Support for Office Documents
OpenIDE-Module-Localizing-Bundle: org/openoffice/netbeans/modules/office/Bundle.properties
OpenIDE-Module-Specification-Version: 0.2
OpenIDE-Module-Implementation-Version: 0.2
OpenIDE-Module-Install: org/openoffice/netbeans/modules/office/utils/OfficeModule.class
OpenIDE-Module-Layer: org/openoffice/netbeans/modules/office/resources/layer.xml
Name: org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.class
OpenIDE-Module-Class: Loader
Name: org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.class
OpenIDE-Module-Class: Loader
Name: org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.class
Install-Before: org.openide.loaders.XMLDataObject, org.netbeans.modules.xml.core.XMLDataObject
OpenIDE-Module-Class: Loader
Name: org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.class
Install-Before: org.openoffice.netbeans.modules.office.loader.ParcelDescriptorDataLoader
OpenIDE-Module-Class: Loader
Name: org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.class
OpenIDE-Module-Class: Loader
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.io.File;
import java.util.ArrayList;
import org.openoffice.idesupport.zip.ParcelZipper;
import com.sun.star.script.framework.container.ScriptEntry;
public class ExtensionFinder implements MethodFinder {
private String[] extensions;
private String language;
public ExtensionFinder(String language, String[] extensions) {
this.language = language;
this.extensions = extensions;
}
public ScriptEntry[] findMethods(File basedir) {
String parcelName;
ArrayList<ScriptEntry> files = new ArrayList<ScriptEntry>(10);
ScriptEntry[] empty = new ScriptEntry[0];
if (basedir == null || !basedir.exists() ||
!basedir.isDirectory())
return empty;
parcelName = basedir.getName();
if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME))
parcelName = basedir.getParentFile().getName();
findFiles(files, basedir, parcelName);
if (files.size() != 0)
return files.toArray(empty);
return empty;
}
private void findFiles(ArrayList<ScriptEntry> list, File basedir,
String parcelName) {
File[] children = basedir.listFiles();
File f;
for (int i = 0; i < children.length; i++) {
f = children[i];
if (f.isDirectory())
findFiles(list, f, parcelName);
else {
for (int j = 0; j < extensions.length; j++) {
if (f.getName().endsWith(extensions[j])) {
ScriptEntry entry = new ScriptEntry(language,
f.getName(), parcelName);
list.add(entry);
break;
}
}
}
}
}
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.openoffice.idesupport.zip.ParcelZipper;
import com.sun.star.script.framework.container.ScriptEntry;
public class JavaFinder implements MethodFinder {
private static JavaFinder finder;
private static final String JAVA_SUFFIX = ".java";
private static final String CLASS_SUFFIX = ".class";
private static final String FIRST_PARAM =
"drafts.com.sun.star.script.framework.runtime.XScriptContext";
private List<String> classpath = null;
private JavaFinder() {}
private JavaFinder(List<String> classpath) {
this.classpath = classpath;
}
public static JavaFinder getInstance(List<String> classpath) {
return new JavaFinder(classpath);
}
public ScriptEntry[] findMethods(File basedir) {
String parcelName;
ArrayList<ScriptEntry> result = new ArrayList<ScriptEntry>(10);
ScriptEntry[] empty = new ScriptEntry[0];
if (basedir == null || !basedir.exists() ||
!basedir.isDirectory())
return empty;
parcelName = basedir.getName();
if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME))
parcelName = basedir.getParentFile().getName();
String[] classNames = findClassNames(basedir);
if (classNames != null && classNames.length != 0) {
ClassLoader classloader;
if (classpath == null)
classloader = getClassLoader(basedir);
else
classloader = getClassLoader();
for (int i = 0; i < classNames.length; i++) {
try {
Class clazz = classloader.loadClass(classNames[i]);
Method[] methods = clazz.getDeclaredMethods();
for (int k = 0; k < methods.length; k++) {
if (Modifier.isPublic(methods[k].getModifiers())) {
Class[] params = methods[k].getParameterTypes();
if (params.length > 0) {
if (params[0].getName().equals(FIRST_PARAM)) {
ScriptEntry entry =
new ScriptEntry(classNames[i] + "." +
methods[k].getName(), parcelName);
result.add(entry);
}
}
}
}
} catch (ClassNotFoundException e) {
System.err.println("Caught ClassNotFoundException loading: "
+ classNames[i]);
continue;
} catch (NoClassDefFoundError nc) {
System.err.println("Caught NoClassDefFoundErr loading: " +
classNames[i]);
continue;
}
}
}
if (result.size() != 0)
return result.toArray(empty);
return empty;
}
private ClassLoader getClassLoader() {
int len = classpath.size();
ArrayList<URL> urls = new ArrayList<URL>(len);
for (int i = 0; i < len; i++) {
try {
String s = classpath.get(i);
s = SVersionRCFile.toFileURL(s);
if (s != null)
urls.add(new URL(s));
} catch (MalformedURLException mue) {
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]));
}
private ClassLoader getClassLoader(File basedir) {
ArrayList<File> files = findFiles(basedir, ".jar");
files.add(basedir);
try {
Iterator<OfficeInstallation> offices =
SVersionRCFile.createInstance().getVersions();
while (offices.hasNext()) {
OfficeInstallation oi = offices.next();
String unoil = SVersionRCFile.getPathForUnoil(oi.getPath());
if (unoil != null) {
files.add(new File(unoil, "unoil.jar"));
break;
}
}
} catch (IOException ioe) {
return null;
}
URL[] urls = new URL[files.size()];
String urlpath;
File f;
for (int i = 0; i < urls.length; i++) {
try {
f = files.get(i);
urlpath = SVersionRCFile.toFileURL(f.getAbsolutePath());
if (urlpath != null)
urls[i] = new URL(urlpath);
} catch (MalformedURLException mue) {
// do nothing, go on to next file
}
}
return new URLClassLoader(urls);
}
private ArrayList<File> findFiles(File basedir, String suffix) {
ArrayList<File> result = new ArrayList<File>();
File[] children = basedir.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].isDirectory())
result.addAll(findFiles(children[i], suffix));
else if (children[i].getName().endsWith(suffix))
result.add(children[i]);
}
return result;
}
private String[] findClassNames(File basedir) {
ArrayList<File> classFiles = findFiles(basedir, CLASS_SUFFIX);
if(classFiles == null || classFiles.isEmpty())
return null;
ArrayList<File> javaFiles = findFiles(basedir, JAVA_SUFFIX);
if (javaFiles == null || javaFiles.size() == 0)
return null;
ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i < classFiles.size(); i++) {
File classFile = classFiles.get(i);
String className = classFile.getName();
className = className.substring(0, className.lastIndexOf(CLASS_SUFFIX));
boolean finished = false;
for (int j = 0; j < javaFiles.size() && !finished; j++) {
File javaFile = javaFiles.get(j);
String javaName = javaFile.getName();
javaName = javaName.substring(0, javaName.lastIndexOf(JAVA_SUFFIX));
if (javaName.equals(className)) {
String path = classFile.getAbsolutePath();
path = path.substring(basedir.getAbsolutePath().length() + 1);
path = path.replace(File.separatorChar, '.');
path = path.substring(0, path.lastIndexOf(CLASS_SUFFIX));
result.add(path);
javaFiles.remove(j);
finished = true;
}
}
}
return result.toArray(new String[result.size()]);
}
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.net.ConnectException;
/**
* LocalOffice represents a connection to the local office.
*
* This class allows to get access to some scripting framework
* related functionality of the locally running office. The
* office has to be started with options appropriate for establishing
* local connection.
*/
public abstract class LocalOffice
{
/**
* Connects to the running office.
*
* @param officePath is a platform specific path string
* to the office distribution.
* @param port is a communication port.
*/
protected abstract void connect(String officePath, int port)
throws ConnectException;
/**
* Closes the connection to the running office.
*/
public abstract void disconnect();
/**
* Refresh the script storage.
*
* @param uri is an identifier of storage has to be refreshed.
*/
public abstract void refreshStorage(String uri);
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.io.File;
import com.sun.star.script.framework.container.ScriptEntry;
public interface MethodFinder {
ScriptEntry[] findMethods(File basedir);
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.openoffice.idesupport.zip.ParcelZipper;
public class OfficeDocument {
public static final String PARCEL_PREFIX_DIR =
ParcelZipper.PARCEL_PREFIX_DIR;
public static final String[] OFFICE_EXTENSIONS =
{".sxc" , ".sxw", ".sxi", ".sxd"};
public static final String OFFICE_PRODUCT_NAME = "OpenOffice.org";
private File file = null;
public OfficeDocument(File file) throws IllegalArgumentException {
if (!file.exists() || file.isDirectory() || !isOfficeFile(file)) {
throw new IllegalArgumentException("This is not a valid " +
OFFICE_PRODUCT_NAME + " document.");
}
this.file = file;
}
private boolean isOfficeFile(File file) {
for (int i = 0; i < OFFICE_EXTENSIONS.length; i++)
if (file.getName().endsWith(OFFICE_EXTENSIONS[i]))
return true;
return false;
}
public Iterator<String> getParcels() {
ArrayList<String> parcels = new ArrayList<String>();
ZipFile zp = null;
try {
zp = new ZipFile(this.file);
for (Enumeration enumer = zp.entries(); enumer.hasMoreElements();) {
ZipEntry ze = (ZipEntry)enumer.nextElement();
if (ze.getName().endsWith(ParcelZipper.PARCEL_DESCRIPTOR_XML)) {
String tmp = ze.getName();
int end = tmp.lastIndexOf('/');
tmp = tmp.substring(0, end);
String parcelName = ze.getName().substring(0, end);
parcels.add(parcelName);
}
}
} catch (ZipException ze) {
ze.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (zp != null) {
try {
zp.close();
} catch (IOException asdf) {
}
}
}
return parcels.iterator();
}
public boolean removeParcel(String parcelName) {
try {
ParcelZipper.getParcelZipper().removeParcel(file, parcelName);
} catch (IOException ioe) {
ioe.printStackTrace();
return false;
}
return true;
}
}
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package org.openoffice.idesupport;
import java.io.File;
import java.net.URLDecoder;
public class OfficeInstallation implements java.io.Serializable {
private String name;
private String path;
private String url;
private boolean hasFW = false;
private static final String FILE_URL_PREFIX = SVersionRCFile.FILE_URL_PREFIX;
public OfficeInstallation(String path) {
this(path, path);
}
public OfficeInstallation(String name, String path) {
this.name = name;
if (path.startsWith(FILE_URL_PREFIX)) {
this.url = path;
path = URLDecoder.decode(path);
path = path.substring(FILE_URL_PREFIX.length());
if (System.getProperty("os.name").startsWith("Windows"))
path = path.replace('/', File.separatorChar);
this.path = path;
} else {
this.path = path;
if (System.getProperty("os.name").startsWith("Windows"))
path = path.replace(File.separatorChar, '/');
this.url = FILE_URL_PREFIX + path;
}
}
public String getName() {
return name;
}
public String getPath() {
return path;
}
public String getURL() {
return url;
}