Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OSType |
|
| 1.2307692307692308;1.231 | ||||
OSType$1 |
|
| 1.2307692307692308;1.231 | ||||
OSType$2 |
|
| 1.2307692307692308;1.231 | ||||
OSType$3 |
|
| 1.2307692307692308;1.231 |
1 | /** | |
2 | * Distribution License: | |
3 | * JSword is free software; you can redistribute it and/or modify it under | |
4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
5 | * as published by the Free Software Foundation. This program is distributed | |
6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
8 | * See the GNU Lesser General Public License for more details. | |
9 | * | |
10 | * The License is available on the internet at: | |
11 | * http://www.gnu.org/copyleft/lgpl.html | |
12 | * or by writing to: | |
13 | * Free Software Foundation, Inc. | |
14 | * 59 Temple Place - Suite 330 | |
15 | * Boston, MA 02111-1307, USA | |
16 | * | |
17 | * © CrossWire Bible Society, 2005 - 2016 | |
18 | * | |
19 | */ | |
20 | package org.crosswire.common.util; | |
21 | ||
22 | import java.io.File; | |
23 | import java.net.URI; | |
24 | ||
25 | /** | |
26 | * Types of Operating Systems for which specialized behavior is needed. | |
27 | * | |
28 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
29 | * @author DM Smith | |
30 | */ | |
31 | 0 | public enum OSType { |
32 | 0 | MAC ("Mac") { |
33 | @Override | |
34 | public URI getUserArea() { | |
35 | 0 | return NetUtil.lengthenURI(getUserHome(), MAC_USER_DATA_AREA); |
36 | } | |
37 | ||
38 | @Override | |
39 | public URI getUserAreaFolder(String hiddenFolderName, String visibleFolderName) { | |
40 | 0 | return NetUtil.lengthenURI(getUserArea(), visibleFolderName); |
41 | } | |
42 | }, | |
43 | ||
44 | 0 | WIN32 ("Win") { |
45 | @Override | |
46 | public URI getUserArea() { | |
47 | 0 | return NetUtil.lengthenURI(getUserHome(), WIN32_USER_DATA_AREA); |
48 | } | |
49 | ||
50 | @Override | |
51 | public URI getUserAreaFolder(String hiddenFolderName, String visibleFolderName) { | |
52 | 0 | return NetUtil.lengthenURI(getUserArea(), visibleFolderName); |
53 | } | |
54 | }, | |
55 | ||
56 | 0 | DEFAULT ("*nix") { |
57 | @Override | |
58 | public URI getUserArea() { | |
59 | 0 | return getUserHome(); |
60 | } | |
61 | ||
62 | @Override | |
63 | public URI getUserAreaFolder(String hiddenFolderName, String visibleFolderName) { | |
64 | 0 | return NetUtil.lengthenURI(getUserArea(), hiddenFolderName); |
65 | } | |
66 | }; | |
67 | ||
68 | /** | |
69 | * Simple ctor | |
70 | * | |
71 | * @param name the name of the OS | |
72 | */ | |
73 | 0 | OSType(String name) { |
74 | 0 | this.name = name; |
75 | 0 | } |
76 | ||
77 | /** | |
78 | * Get the user area for this OSType. | |
79 | * | |
80 | * @return the user area | |
81 | */ | |
82 | public abstract URI getUserArea(); | |
83 | ||
84 | /** | |
85 | * A folder in the user area. This osType will determine which to use in | |
86 | * constructing the URI to the folder. | |
87 | * | |
88 | * @param hiddenFolderName | |
89 | * is typically a "unix" hidden folder name such as .jsword. | |
90 | * @param visibleFolderName | |
91 | * is an visible folder name, such as JSword. | |
92 | * | |
93 | * @return the user area folder | |
94 | */ | |
95 | public abstract URI getUserAreaFolder(String hiddenFolderName, String visibleFolderName); | |
96 | ||
97 | /** | |
98 | * @return the URI of the user home | |
99 | */ | |
100 | public static URI getUserHome() { | |
101 | 0 | return NetUtil.getURI(new File(System.getProperty("user.home"))); |
102 | } | |
103 | ||
104 | /** | |
105 | * Get the machine's OSType. | |
106 | * | |
107 | * @return the machine's OSType | |
108 | */ | |
109 | public static OSType getOSType() { | |
110 | 0 | return osType; |
111 | } | |
112 | ||
113 | /** | |
114 | * Lookup method to convert from a String to an OSType | |
115 | * | |
116 | * @param name the name of an OSType | |
117 | * @return the OSType or DEFAULT | |
118 | */ | |
119 | public static OSType fromString(String name) { | |
120 | 0 | for (OSType v : values()) { |
121 | 0 | if (name.startsWith(v.name)) { |
122 | 0 | return v; |
123 | } | |
124 | } | |
125 | ||
126 | 0 | return DEFAULT; |
127 | } | |
128 | ||
129 | /* (non-Javadoc) | |
130 | * @see java.lang.Enum#toString() | |
131 | */ | |
132 | @Override | |
133 | public String toString() { | |
134 | 0 | return name; |
135 | } | |
136 | ||
137 | /** | |
138 | * The name of the type | |
139 | */ | |
140 | private String name; | |
141 | ||
142 | /** | |
143 | * The Windows user settings parent directory | |
144 | */ | |
145 | private static final String WIN32_USER_DATA_AREA = "Application Data"; | |
146 | ||
147 | /** | |
148 | * The Mac user settings parent directory | |
149 | */ | |
150 | private static final String MAC_USER_DATA_AREA = "Library/Application Support"; | |
151 | ||
152 | /** | |
153 | * The machine's osType | |
154 | */ | |
155 | 0 | private static OSType osType = fromString(System.getProperty("os.name")); |
156 | } |