- Timestamp:
- 2013-06-27T17:01:15+12:00 (11 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r27617 r27719 1167 1167 File file = new File(tempDir, current.getName()); 1168 1168 current.write(file); 1169 1170 queryMap.put("md___ex.Filesize", new String[] { "" + file.length() }); 1171 queryMap.put("md___ex.Filename", new String[] { "" + current.getName() }); 1169 1172 } 1170 1173 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DepositorAction.java
r27617 r27719 1 1 package org.greenstone.gsdl3.action; 2 2 3 import java.io.BufferedWriter; 3 4 import java.io.File; 4 5 import java.io.FileWriter; 6 import java.io.IOException; 5 7 import java.io.Serializable; 6 8 import java.util.ArrayList; … … 14 16 import javax.xml.transform.stream.StreamResult; 15 17 18 import org.apache.commons.io.FileUtils; 16 19 import org.greenstone.gsdl3.util.DerbyWrapper; 17 20 import org.greenstone.gsdl3.util.GSConstants; … … 28 31 //Sub actions 29 32 private final String DE_RETRIEVE_WIZARD = "getWizard"; 33 private final String DE_DEPOSIT_FILE = "depositFile"; 30 34 31 35 public Node process(Node message) … … 46 50 47 51 int pageNum = -1; 48 boolean pa rseFail = false;52 boolean pageNumParseFail = false; 49 53 try 50 54 { … … 53 57 catch (Exception ex) 54 58 { 55 parseFail = true; 56 ex.printStackTrace(); 59 pageNumParseFail = true; 60 } 61 62 int prevPageNum = -1; 63 boolean prevPageNumFail = false; 64 try 65 { 66 prevPageNum = Integer.parseInt(((String) params.get("currentPage"))); 67 } 68 catch (Exception ex) 69 { 70 prevPageNumFail = true; 57 71 } 58 72 59 73 DerbyWrapper database = new DerbyWrapper(); 60 74 database.connectDatabase(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separatorChar + "etc" + File.separatorChar + "usersDB", false); 61 if (pa rseFail)75 if (pageNumParseFail) 62 76 { 63 77 try … … 105 119 saveString.append("]"); 106 120 107 database.addUserData(currentUsername, "DE___" + collection + "___" + pageNum + "___CACHED_VALUES", saveString.toString()); 121 if (!prevPageNumFail) 122 { 123 database.addUserData(currentUsername, "DE___" + collection + "___" + prevPageNum + "___CACHED_VALUES", saveString.toString()); 124 } 108 125 } 109 126 … … 182 199 { 183 200 Element page = this.doc.createElement("pageCache"); 184 page.setAttribute("pageNum", "" + pageNum);201 page.setAttribute("pageNum", "" + i); 185 202 String cachedValues = database.getUserData(currentUsername, "DE___" + collection + "___" + i + "___CACHED_VALUES"); 186 page.appendChild(this.doc.createTextNode(cachedValues)); 187 cachedValueElement.appendChild(page); 203 if (cachedValues != null) 204 { 205 page.appendChild(this.doc.createTextNode(cachedValues)); 206 cachedValueElement.appendChild(page); 207 } 188 208 } 189 209 } … … 212 232 } 213 233 database.closeDatabase(); 234 } 235 else if (subaction.equals(DE_DEPOSIT_FILE)) 236 { 237 String fileToAdd = (String) params.get("fileToAdd"); 238 File tempFile = new File(GlobalProperties.getGSDL3Home() + File.separator + "tmp" + File.separator + fileToAdd); 239 if (tempFile.exists()) 240 { 241 File newFileLocationDir = new File(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separator + "collect" + File.separator + collection + File.separator + "import" + File.separator + fileToAdd); 242 if (!newFileLocationDir.exists()) 243 { 244 newFileLocationDir.mkdir(); 245 } 246 File newFileLocation = new File(newFileLocationDir, fileToAdd); 247 248 try 249 { 250 FileUtils.copyFile(tempFile, newFileLocation); 251 } 252 catch (Exception ex) 253 { 254 ex.printStackTrace(); 255 GSXML.addError(this.doc, responseMessage, "Failed to copy the deposited file into the collection."); 256 return responseMessage; 257 } 258 259 String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\"><DirectoryMetadata><FileSet>"; 260 xmlString += "<FileName>" + fileToAdd + "</FileName><Description>"; 261 Iterator<String> paramIter = params.keySet().iterator(); 262 while (paramIter.hasNext()) 263 { 264 String paramName = paramIter.next(); 265 if (paramName.startsWith("md___")) 266 { 267 Object paramValue = params.get(paramName); 268 269 if (paramValue instanceof String) 270 { 271 xmlString += "<Metadata name=\"" + paramName.substring(5) + "\" mode=\"accumulate\">" + (String) paramValue + "</Metadata>"; 272 } 273 else if (paramValue instanceof HashMap) 274 { 275 HashMap<String, String> subMap = (HashMap<String, String>) paramValue; 276 Iterator<String> subKeyIter = subMap.keySet().iterator(); 277 while (subKeyIter.hasNext()) 278 { 279 String subName = subKeyIter.next(); 280 xmlString += "<Metadata name=\"" + paramName.substring(5) + "." + subName + "\" mode=\"accumulate\">" + subMap.get(subName) + "</Metadata>"; 281 } 282 } 283 } 284 } 285 xmlString += "</Description></FileSet><DirectoryMetadata>"; 286 287 File metadataFile = new File(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separator + "collect" + File.separator + collection + File.separator + "import" + File.separator + fileToAdd + File.separator + "metadata.xml"); 288 289 try 290 { 291 BufferedWriter bw = new BufferedWriter(new FileWriter(metadataFile)); 292 bw.write(xmlString); 293 bw.close(); 294 } 295 catch (Exception ex) 296 { 297 ex.printStackTrace(); 298 } 299 300 Element buildMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 301 Element buildRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, "ImportCollection", uc); 302 buildMessage.appendChild(buildRequest); 303 304 Element paramListElem = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 305 buildRequest.appendChild(paramListElem); 306 307 Element collectionParam = this.doc.createElement(GSXML.PARAM_ELEM); 308 paramListElem.appendChild(collectionParam); 309 collectionParam.setAttribute(GSXML.NAME_ATT, GSXML.COLLECTION_ATT); 310 collectionParam.setAttribute(GSXML.VALUE_ATT, collection); 311 312 Element documentsParam = this.doc.createElement(GSXML.PARAM_ELEM); 313 paramListElem.appendChild(documentsParam); 314 documentsParam.setAttribute(GSXML.NAME_ATT, "documents"); 315 documentsParam.setAttribute(GSXML.VALUE_ATT, fileToAdd); 316 317 Element buildResponseMessage = (Element) this.mr.process(buildMessage); 318 319 System.err.println("RESPONSE = " + GSXML.xmlNodeToString(buildResponseMessage)); 320 321 response.appendChild(this.doc.importNode(buildResponseMessage, true)); 322 } 323 } 324 else 325 { 326 Element depositorPage = this.doc.createElement("depositorPage"); 327 response.appendChild(depositorPage); 328 329 Element collList = getCollectionsInSite(); 330 depositorPage.appendChild(this.doc.importNode(collList, true)); 214 331 } 215 332 -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSParams.java
r27087 r27719 165 165 { 166 166 // p. is used to store previous settings 167 if (name.startsWith("p.") )167 if (name.startsWith("p.") || name.startsWith("md___")) 168 168 return false; 169 169 Param p = this.param_map.get(name); -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r27617 r27719 329 329 public static HashMap<String, Serializable> extractParams(Element xml, boolean deep, String toFind) 330 330 { 331 if (xml == null) 332 { 333 return null; 334 } 331 335 332 336 if (!xml.getNodeName().equals(PARAM_ELEM + LIST_MODIFIER)) … … 750 754 duplicate = owner.createElementNS(namespace_uri, element_name); 751 755 } 756 752 757 // Copy element attributes 753 758 if (with_attributes) … … 1294 1299 { 1295 1300 String text = e.getNodeValue(); 1296 text = text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("^[\\n\\r\\t\\s]*", "").replaceAll("[\\n\\r\\t\\s]*$", ""); 1297 sb.append(text); 1301 if (text != null) 1302 { 1303 text = text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("^[\\n\\r\\t\\s]*", "").replaceAll("[\\n\\r\\t\\s]*$", ""); 1304 sb.append(text); 1305 } 1298 1306 } 1299 1307 return; … … 1344 1352 if (children.item(i).getNodeType() == Node.TEXT_NODE && indent) 1345 1353 { 1346 if (children.item(i).getNodeValue() .trim().length() > 0)1354 if (children.item(i).getNodeValue() != null && children.item(i).getNodeValue().trim().length() > 0) 1347 1355 { 1348 1356 indentSwapped = true;
Note:
See TracChangeset
for help on using the changeset viewer.