Changeset 1538 for MDService2
- Timestamp:
- 09/15/11 13:28:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java
r1532 r1538 29 29 public static enum RepositoryType 30 30 { 31 MD, SRU, PAZPAR, NOVALUE;31 MD, SRU, PAZPAR, NOVALUE; 32 32 33 33 public static RepositoryType toRepositoryType(String str) … … 41 41 } 42 42 } 43 43 public static enum TermsetType 44 { 45 MODEL, DCR, RR, NOVALUE; 46 47 public static TermsetType toTermsetType(String str) 48 { 49 try { 50 return valueOf(str.toUpperCase()); 51 } 52 catch (Exception ex) { 53 return NOVALUE; 54 } 55 } 56 } 44 57 private static JSONArray repositories = null; 58 private static JSONArray termsets = null; 45 59 private static JSONObject options = null; 46 60 47 public static String getRepositoryByIndex(int ind){48 String repository_name = null;49 50 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories();51 if (json.size() > ind){52 repository_name = json.getJSONObject(ind).getString("name");53 }54 return repository_name;55 56 }57 61 public static JSONArray getRepositories(){ 58 62 if (repositories == null){ … … 105 109 } 106 110 111 public static JSONArray getTermsets(){ 112 if (termsets == null ) { 113 try { 114 WorkspaceProfile.setTermsets(WorkspaceProfile.createTermsets()); 115 } catch (IOException e) { 116 // TODO Auto-generated catch block 117 e.printStackTrace(); 118 } catch (InterruptedException e) { 119 // TODO Auto-generated catch block 120 e.printStackTrace(); 121 } catch (TransformerException e) { 122 // TODO Auto-generated catch block 123 e.printStackTrace(); 124 } catch (NoStylesheetException e) { 125 // TODO Auto-generated catch block 126 e.printStackTrace(); 127 } 128 } 129 return termsets; 130 } 131 132 public static void setTermsets(JSONArray op){ 133 WorkspaceProfile.termsets = op; 134 } 135 136 107 137 public WorkspaceProfile() { 108 138 } 109 139 140 public static Boolean repositoryExists(String repository_name){ 141 142 // static repositories 143 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 144 for(int i=0;i<json.size();i++){ 145 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 146 return true; 147 } 148 } 149 150 return false; 151 152 } 153 154 public static String getRepositoryByIndex(int ind){ 155 String repository_name = null; 156 157 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 158 if (json.size() > ind){ 159 repository_name = json.getJSONObject(ind).getString("name"); 160 } 161 return repository_name; 162 163 } 164 165 public static String getRepositoryPath(String repository_name){ 166 String repository_path = null; 167 168 169 170 // static repositories 171 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 172 for(int i=0;i<json.size();i++){ 173 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 174 repository_path = json.getJSONObject(i).getString("uri"); 175 } 176 } 177 178 return repository_path; 179 180 } 181 182 public static String getRepositoryType(String repository_name){ 183 String typestr = ""; 184 185 186 // static repositories 187 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 188 for(int i=0;i<json.size();i++){ 189 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 190 typestr = json.getJSONObject(i).getString("type"); 191 } 192 } 193 194 return (typestr); 195 196 } 197 198 public static Boolean isSRURepository(String repository_name){ 199 //Boolean issru = false; 200 String typestr = getRepositoryType(repository_name); 201 202 return (typestr.equals("sru")); 203 204 } 205 206 public static String getRepositoryProperty(String repo_id, String propname){ 207 String typestr = ""; 208 209 210 // static repositories 211 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 212 for(int i=0;i<json.size();i++){ 213 if (json.getJSONObject(i).getString("id").equals(repo_id)){ 214 typestr = json.getJSONObject(i).getString(propname); 215 } 216 } 217 218 return (typestr); 219 } 220 110 221 public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 111 222 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; … … 178 289 } 179 290 180 public static Boolean repositoryExists(String repository_name){ 181 182 // static repositories 183 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 184 for(int i=0;i<json.size();i++){ 185 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 186 return true; 187 } 188 } 189 190 return false; 191 192 } 193 194 public static String getRepositoryPath(String repository_name){ 195 String repository_path = null; 196 197 198 199 // static repositories 200 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 201 for(int i=0;i<json.size();i++){ 202 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 203 repository_path = json.getJSONObject(i).getString("uri"); 204 } 205 } 206 207 return repository_path; 208 209 } 210 211 public static String getRepositoryType(String repository_name){ 212 String typestr = ""; 213 214 215 // static repositories 216 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 217 for(int i=0;i<json.size();i++){ 218 if (json.getJSONObject(i).getString("name").equals(repository_name)){ 219 typestr = json.getJSONObject(i).getString("type"); 220 } 221 } 222 223 return (typestr); 224 225 } 226 public static Boolean isSRURepository(String repository_name){ 227 //Boolean issru = false; 228 String typestr = getRepositoryType(repository_name); 229 230 return (typestr.equals("sru")); 231 232 } 233 234 235 } 236 237 291 public static String getTermsetProperty(String termset_id, String propname){ 292 String typestr = ""; 293 294 295 // static repositories 296 net.sf.json.JSONArray json = WorkspaceProfile.getTermsets(); 297 for(int i=0;i<json.size();i++){ 298 if (json.getJSONObject(i).getString("id").equals(termset_id)){ 299 typestr = json.getJSONObject(i).getString(propname); 300 } 301 } 302 303 return (typestr); 304 305 } 306 307 public static JSONArray createTermsets() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 308 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 309 File file=new File(path); 310 InputStream in = new BufferedInputStream( new FileInputStream(path));; 311 312 MDTransformer transformer = new MDTransformer(); 313 transformer.setSrcFile(file.toURI().toURL()); 314 transformer.setParams(MDTransformer.createParamsMap("xml2json")); 315 InputStream jsonstream = transformer.transformXML(in); 316 317 JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream)); 318 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 319 JSONArray array = null; 320 for (int i = 0; i < wparray.size(); ++i) { 321 JSONObject wp = wparray.getJSONObject(i); 322 if (wp.get("Termsets") != null){ 323 array = wp.getJSONArray("Termsets"); 324 break; 325 } 326 } 327 328 // termset as static variable 329 return array; 330 } 331 332 333 } 334 335
Note: See TracChangeset
for help on using the changeset viewer.