1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package org.openoffice.idesupport;
24 
25 import java.io.File;
26 import java.net.URLDecoder;
27 
28 public class OfficeInstallation implements java.io.Serializable {
29 
30     private String name;
31     private String path;
32     private String url;
33     private boolean hasFW = false;
34     private boolean supportsFW = false;
35 
36     public static final String FILE_URL_PREFIX = SVersionRCFile.FILE_URL_PREFIX;
37 
OfficeInstallation(String path)38     public OfficeInstallation(String path) {
39         this(path, path);
40     }
41 
OfficeInstallation(String name, String path)42     public OfficeInstallation(String name, String path) {
43 
44         this.name = name;
45 
46         if (path.startsWith(FILE_URL_PREFIX)) {
47             this.url = path;
48             path = URLDecoder.decode(path);
49             path = path.substring(FILE_URL_PREFIX.length());
50 
51             if (System.getProperty("os.name").startsWith("Windows"))
52                 path = path.replace('/', File.separatorChar);
53 
54             this.path = path;
55         }
56         else {
57             this.path = path;
58 
59             if (System.getProperty("os.name").startsWith("Windows"))
60                 path = path.replace(File.separatorChar, '/');
61 
62             this.url = FILE_URL_PREFIX + path;
63         }
64     }
65 
getName()66     public String getName() {
67         return name;
68     }
69 
getPath()70     public String getPath() {
71         return path;
72     }
73 
getPath(String name)74     public String getPath(String name) {
75         if (!name.startsWith(File.separator))
76             name = File.separator + name;
77 
78         return path + name;
79     }
80 
getURL()81     public String getURL() {
82         return url;
83     }
84 
getURL(String name)85     public String getURL(String name) {
86         if (System.getProperty("os.name").startsWith("Windows"))
87             name = name.replace(File.separatorChar, '/');
88 
89         if (!name.startsWith("/"))
90             name = "/" + name;
91 
92         return url + name;
93     }
94 
hasFramework()95     public boolean hasFramework() {
96         return hasFW;
97     }
98 
supportsFramework()99     public boolean supportsFramework() {
100         return true;
101     }
102 
toString()103     public String toString() {
104         return getName();
105     }
106 }
107