IssueZilla 10024 - improve generation of paths and urls for office installation

This commit is contained in:
Tomas O'Connor
2003-01-16 10:42:48 +00:00
parent 5dcd5f1a60
commit dbae842f90
4 changed files with 317 additions and 223 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: SVersionRCFile.java,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: toconnor $ $Date: 2002-11-26 16:57:59 $
* last change: $Author: toconnor $ $Date: 2003-01-16 11:42:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,6 +63,7 @@ package org.openoffice.idesupport;
import java.io.*;
import java.util.*;
import java.net.URLDecoder;
public class SVersionRCFile {
@@ -77,29 +78,59 @@ public class SVersionRCFile {
System.getProperty("os.name").startsWith("Windows") == true ?
"file:///" : "file://";
private static final String PKGCHK =
System.getProperty("os.name").startsWith("Windows") == true ?
"pkgchk.exe" : "pkgchk";
private static final String VERSIONS_LINE = "[Versions]";
private static final String UNOILJAR = "skip_registration" + File.separator + "unoil.jar";
private static final String UNOPACKAGEDIR = File.separator + "user" +
File.separator + "uno_packages" +
File.separator + "cache" +
File.separator + "uno_packages";
private static final String UNOILJAR =
"skip_registration" + File.separator + "unoil.jar";
private static final String UNOPACKAGEDIR =
File.separator + "user" + File.separator + "uno_packages" +
File.separator + "cache" + File.separator + "uno_packages";
/* Make sure this is in LowerCase !!!!! */
private static final String SCRIPTF = "scriptf";
private File file = null;
private static final HashMap files = new HashMap(3);
private File sverionrc = null;
private long lastModified = 0;
public SVersionRCFile() {
this(DEFAULT_NAME);
}
public SVersionRCFile(String name) {
file = new File(name);
sverionrc = new File(name);
System.out.println("Created new SVersionRCFile: " + name);
}
public static SVersionRCFile createInstance() {
return(createInstance(DEFAULT_NAME));
}
public static SVersionRCFile createInstance(String name) {
SVersionRCFile result = null;
synchronized(SVersionRCFile.class) {
result = (SVersionRCFile)files.get(name);
if (result == null) {
result = new SVersionRCFile(name);
files.put(name, result);
}
}
return result;
}
public Hashtable getVersions() throws IOException {
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
br = new BufferedReader(new FileReader(sverionrc));
}
catch (FileNotFoundException fnfe) {
throw new IOException(fnfe.getMessage());
@@ -127,29 +158,13 @@ public class SVersionRCFile {
String name = tokens.nextToken();
String path = tokens.nextToken();
if (path.startsWith(FILE_URL_PREFIX) == true) {
path = java.net.URLDecoder.decode(path);
path = path.substring(FILE_URL_PREFIX.length());
if (System.getProperty("os.name").startsWith("Windows"))
path = path.replace('/', File.separatorChar);
}
if (isValidPath(path) == true)
versions.put(name, path);
OfficeInstallation oi = new OfficeInstallation(name, path);
if (oi.supportsFramework())
versions.put(name, oi.getPath());
}
return versions;
}
private boolean isValidPath(String path) {
// System.out.println("Testing: " + path);
File file = new File(path + File.separator + "program");
if (file.exists())
return true;
return false;
}
public static String getPathForUnoil(String officeInstall)
{
File unopkgdir = new File(officeInstall, UNOPACKAGEDIR);
@@ -180,7 +195,83 @@ public class SVersionRCFile {
return null;
}
/* public static void main(String[] args) {
public static class OfficeInstallation {
private String name;
private String path;
private String url;
private boolean hasFW = false;
private boolean supportsFW = false;
public OfficeInstallation(String path) {
this("Office", 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;
}
File f = new File(this.path + File.separator + "program" +
File.separator + PKGCHK);
if (f.exists())
supportsFW = true;
}
public String getPath() {
return path;
}
public String getPath(String name) {
if (!name.startsWith(File.separator))
name = File.separator + name;
return path + name;
}
public String getURL() {
return url;
}
public String getURL(String name) {
if (System.getProperty("os.name").startsWith("Windows"))
name = name.replace(File.separatorChar, '/');
if (!name.startsWith("/"))
name = "/" + name;
return url + name;
}
public boolean hasFramework() {
return hasFW;
}
public boolean supportsFramework() {
return supportsFW;
}
}
public static void main(String[] args) {
SVersionRCFile ov;
Hashtable versions;
@@ -201,8 +292,9 @@ public class SVersionRCFile {
while (enum.hasMoreElements()) {
String name = (String)enum.nextElement();
System.out.println("Name: " + name + ", Path: " +
(String)versions.get(name));
OfficeInstallation oi = (OfficeInstallation)versions.get(name);
System.out.println("Name: " + name + ", Path: " + oi.getPath() +
", URL: " + oi.getURL());
}
}
} */
}

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: DeployParcelAction.java,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: toconnor $ $Date: 2002-11-13 17:29:52 $
* last change: $Author: toconnor $ $Date: 2003-01-16 11:42:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -193,7 +193,7 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup
}
void addNotify () {
SVersionRCFile rcfile = new SVersionRCFile();
SVersionRCFile rcfile = SVersionRCFile.createInstance();
try {
versions = rcfile.getVersions();

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: OfficeSettings.java,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: toconnor $ $Date: 2002-11-26 12:46:47 $
* last change: $Author: toconnor $ $Date: 2003-01-16 11:42:47 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -91,7 +91,7 @@ public class OfficeSettings extends SystemOption {
setWarnAfterDirDeploy(true);
setWarnBeforeMount(true);
SVersionRCFile sversion = new SVersionRCFile();
SVersionRCFile sversion = SVersionRCFile.createInstance();
try {
Hashtable versions = sversion.getVersions();
@@ -114,7 +114,7 @@ public class OfficeSettings extends SystemOption {
// if no office version is found try a default value
setOfficeDirectory(System.getProperty("user.home") +
System.getProperty("file.separator") + "OpenOffice643C");
System.getProperty("file.separator") + "OpenOffice.org643");
}
public String displayName() {

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ManifestParser.java,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:39 $
* last change: $Author: toconnor $ $Date: 2003-01-16 11:42:48 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -75,6 +75,7 @@ import org.openide.xml.XMLUtil;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.idesupport.xml.XMLParser;
import org.openoffice.idesupport.SVersionRCFile;
public class ManifestParser implements XMLParser {
@@ -98,13 +99,14 @@ public class ManifestParser implements XMLParser {
Document result = null;
try {
SVersionRCFile.OfficeInstallation oi =
new SVersionRCFile.OfficeInstallation(
OfficeSettings.getDefault().getOfficeDirectory());
String id = oi.getURL("share/dtd/officedocument/1_0/");
is = new InputSource(inputStream);
is.setSystemId("file://" +
OfficeSettings.getDefault().getOfficeDirectory() +
File.separator + "share" +
File.separator + "dtd" +
File.separator + "officedocument" +
File.separator + "1_0" + File.separator);
is.setSystemId(id);
result = XMLUtil.parse(is, false, false, null, null);
}
catch (IOException ioe) {