- Timestamp:
- 2003-05-27T15:57:37+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionConfiguration.java
r4293 r4366 10 10 public class CollectionConfiguration { 11 11 12 13 14 15 16 17 18 19 12 private Element creator_element; 13 private Element description_element; 14 private Element maintainer_element; 15 private Element name_element; 16 private String creator; 17 private String description; 18 private String maintainer; 19 private String name; 20 20 21 22 23 24 21 public CollectionConfiguration(File file) { 22 try { 23 String filename = file.getName().toLowerCase(); 24 if(filename.endsWith(".xml")) { 25 25 26 } 27 else if(filename.endsWith(".cfg")) { 28 FileReader fr = new FileReader(file); 29 BufferedReader br = new BufferedReader(fr); 30 String command = null; 31 while((command = br.readLine()) != null) { 32 if(command.length() > 0) { 33 // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat. 34 while(command.trim().endsWith("\\")) { 35 command = command.substring(0, command.lastIndexOf("\\")); 36 String next_line = br.readLine(); 37 if(next_line != null) { 38 command = command + next_line; 39 } 40 next_line = null; 41 } 42 CommandTokenizer tokenizer = new CommandTokenizer(command); 43 if(tokenizer.countTokens() >= 2) { 44 String temp = tokenizer.nextToken(); 45 if(temp.equalsIgnoreCase("creator")) { 46 creator = tokenizer.nextToken(); 47 } 48 else if(temp.equalsIgnoreCase("maintainer")) { 49 maintainer = tokenizer.nextToken(); 50 } 51 else if(temp.equalsIgnoreCase("collectionmeta")) { 52 temp = tokenizer.nextToken(); 53 if(temp.equalsIgnoreCase("collectionname")) { 54 temp = tokenizer.nextToken(); 55 if(temp.startsWith("[") && temp.endsWith("]")) { 56 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 57 if(name == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 58 name = Utility.decodeGreenstone(tokenizer.nextToken()); 59 } 60 } 61 else if(name == null) { 62 name = Utility.decodeGreenstone(temp); 63 } 64 if(name != null && name.startsWith("\"") && name.endsWith("\"")) { 65 name = name.substring(1, name.length() - 1); 66 } 26 67 } 27 else if(filename.endsWith(".cfg")) { 28 FileReader fr = new FileReader(file); 29 BufferedReader br = new BufferedReader(fr); 30 String command = null; 31 while((command = br.readLine()) != null) { 32 if(command.length() > 0) { 33 // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat. 34 while(command.trim().endsWith("\\")) { 35 command = command.substring(0, command.lastIndexOf("\\")); 36 String next_line = br.readLine(); 37 if(next_line != null) { 38 command = command + next_line; 39 } 40 next_line = null; 41 } 42 CommandTokenizer tokenizer = new CommandTokenizer(command); 43 if(tokenizer.countTokens() >= 2) { 44 String temp = tokenizer.nextToken(); 45 if(temp.equalsIgnoreCase("creator")) { 46 creator = tokenizer.nextToken(); 47 } 48 else if(temp.equalsIgnoreCase("maintainer")) { 49 maintainer = tokenizer.nextToken(); 50 } 51 else if(temp.equalsIgnoreCase("collectionmeta")) { 52 temp = tokenizer.nextToken(); 53 if(temp.equalsIgnoreCase("collectionname")) { 54 temp = tokenizer.nextToken(); 55 if(temp.startsWith("[") && temp.endsWith("]")) { 56 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 57 if(name == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 58 name = Utility.decodeGreenstone(tokenizer.nextToken()); 59 } 60 } 61 else if(name == null) { 62 name = Utility.decodeGreenstone(temp); 63 } 64 if(name != null && name.startsWith("\"") && name.endsWith("\"")) { 65 name = name.substring(1, name.length() - 1); 66 } 67 } 68 else if(temp.equalsIgnoreCase("collectionextra")) { 69 temp = tokenizer.nextToken(); 70 ///ystem.err.println("Read: " + temp); 71 if(temp.startsWith("[") && temp.endsWith("]")) { 72 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 73 ///ystem.err.println("Try to match " + language + " to " + Gatherer.dictionary.getLanguage()); 74 if(description == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 75 description = Utility.decodeGreenstone(tokenizer.nextToken()); 76 ///ystem.err.println("Found language match, or first match: " + description); 77 } 78 } 79 else if(description == null) { 80 description = Utility.decodeGreenstone(temp); 81 ///ystem.err.println("Found first match: " + description); 82 } 83 if(description != null && description.startsWith("\"") && description.endsWith("\"")) { 84 description = description.substring(1, description.length() - 1); 85 } 86 } 87 } 88 temp = null; 89 } 90 tokenizer = null; 91 } 92 } 93 command = null; 94 br.close(); 95 br = null; 96 fr.close(); 97 fr = null; 68 else if(temp.equalsIgnoreCase("collectionextra")) { 69 temp = tokenizer.nextToken(); 70 ///ystem.err.println("Read: " + temp); 71 if(temp.startsWith("[") && temp.endsWith("]")) { 72 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 73 ///ystem.err.println("Try to match " + language + " to " + Gatherer.dictionary.getLanguage()); 74 if(description == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 75 description = Utility.decodeGreenstone(tokenizer.nextToken()); 76 ///ystem.err.println("Found language match, or first match: " + description); 77 } 78 } 79 else if(description == null) { 80 description = Utility.decodeGreenstone(temp); 81 ///ystem.err.println("Found first match: " + description); 82 } 83 if(description != null && description.startsWith("\"") && description.endsWith("\"")) { 84 description = description.substring(1, description.length() - 1); 85 } 98 86 } 87 } 88 temp = null; 89 } 90 tokenizer = null; 91 } 92 } 93 command = null; 94 br.close(); 95 br = null; 96 fr.close(); 97 fr = null; 98 } 99 99 ///ystem.err.println("Parsed collect.cfg"); 100 100 ///ystem.err.println("name = " + name); … … 102 102 ///ystem.err.println("maintainer = " + maintainer); 103 103 ///ystem.err.println("description = " + description); 104 105 106 107 108 109 104 } 105 catch(Exception error) { 106 Gatherer.println("Error in CollectionConfiguration.<init>(): " + error); 107 Gatherer.printStackTrace(error); 108 } 109 } 110 110 111 112 113 114 115 116 117 118 119 120 111 public String getCreator() { 112 String result = ""; 113 if(creator_element != null) { 114 result = MSMUtils.getValue(creator_element); 115 } 116 else if(creator != null) { 117 result = creator; 118 } 119 return result; 120 } 121 121 122 123 124 125 126 127 128 129 130 131 122 public String getDescription() { 123 String result = ""; 124 if(description_element != null) { 125 result = MSMUtils.getValue(description_element); 126 } 127 else if(description != null) { 128 result = description; 129 } 130 return result; 131 } 132 132 133 134 135 136 137 138 139 140 141 142 133 public String getMaintainer() { 134 String result = ""; 135 if(maintainer_element != null) { 136 result = MSMUtils.getValue(maintainer_element); 137 } 138 else if(maintainer != null) { 139 result = maintainer; 140 } 141 return result; 142 } 143 143 144 145 146 147 148 149 150 151 152 153 144 public String getName() { 145 String result = "Error"; 146 if(name_element != null) { 147 result = MSMUtils.getValue(name_element); 148 } 149 else if(name != null) { 150 result = name; 151 } 152 return result; 153 } 154 154 155 156 157 155 public void setName(String name) { 156 /** @todo */ 157 } 158 158 }
Note:
See TracChangeset
for help on using the changeset viewer.