Changeset 4451
- Timestamp:
- 2003-06-03T12:41:41+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MSMProfiler.java
r4365 r4451 210 210 // While we're at it save the profiles. 211 211 try { 212 212 // Create backup. 213 213 if(profile_file.exists()) { 214 214 File backup = new File(profile_file.getAbsolutePath() + "~"); … … 219 219 backup = null; 220 220 } 221 // Build the profile document. 222 StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 223 buffer.append("<!DOCTYPE Profiles [\n"); 224 buffer.append("<!ELEMENT Profiles (Action*)>\n"); 225 buffer.append("<!ELEMENT Action (#PCDATA)>\n"); 226 buffer.append("<!ATTLIST Action\n"); 227 buffer.append(" collection CDATA #REQUIRED\n"); 228 buffer.append(" source CDATA #REQUIRED\n"); 229 buffer.append(" target CDATA \"\">\n"); 230 buffer.append("]>\n"); 231 buffer.append("<Profiles>\n"); 221 222 // read in the default profile file - has all the dtd in it 223 Document document = Utility.parse(Utility.PROFILE_TEMPLATE, true); 224 if(document == null) { 225 Gatherer.println("Error in MSMProfiler.save(): couldn't find and parse the profile template file!"); 226 return; 227 } 228 229 230 // Add the current profile info into the document 231 Element profile_elem = document.getDocumentElement(); 232 232 233 Iterator iterator_key_one = profiles.keySet().iterator(); 233 234 while(iterator_key_one.hasNext()) { … … 238 239 String key_two = (String) iterator_key_two.next(); 239 240 String value = (String) map.get(key_two); 240 buffer.append(" <Action collection=\""); 241 buffer.append(key_one); 242 buffer.append("\" source=\""); 243 buffer.append(key_two); 244 buffer.append("\" target=\""); 245 buffer.append(value); 246 buffer.append("\"> </Action>\n"); 241 Element action = document.createElement("Action"); 242 profile_elem.appendChild(action); 243 action.setAttribute("collection", key_one); 244 action.setAttribute("source", key_two); 245 action.setAttribute("target", value); 247 246 key_two = null; 248 247 value = null; … … 253 252 } 254 253 iterator_key_one = null; 255 buffer.append("</Profiles>"); 256 String buffer_str = buffer.toString(); 257 buffer = null; 258 // Now write it to file. 259 FileOutputStream fos = new FileOutputStream(profile_file); 260 OutputStreamWriter osw = new OutputStreamWriter(fos); 261 int position = 0; 262 int BLOCK_SIZE = 1024; 263 // Write x block sized chunks to file. 264 while(position + BLOCK_SIZE < buffer_str.length()) { 265 osw.write(buffer_str, position, BLOCK_SIZE); 266 position = position + BLOCK_SIZE; 267 } 268 // Write the remainder of the buffer. 269 if(position < buffer_str.length()) { 270 osw.write(buffer_str, position, buffer_str.length() - position); 271 } 272 osw.close(); 273 fos.close(); 274 fos = null; 275 osw = null; 276 buffer_str = null; 254 255 // Now write it to file. 256 Utility.export(document, profile_file); 277 257 } 278 258 catch (Exception error) {
Note:
See TracChangeset
for help on using the changeset viewer.