String step = req.getParameter("step");
String policyName = req.getParameter("dsCollection");
String productTypeName = req.getParameter("ds");
// instantiate product type object
CurationPolicyManager cpm = new CurationPolicyManager(this.policyDirPath,
this.stagingAreaPath);
Map<String, ProductType> types = cpm.getProductTypes(policyName);
// get metadata hash table
ProductType cpt = types.get(productTypeName);
// get all submitted form values
Enumeration formKeys = req.getParameterNames();
// update metadata value from POST form
String keyName;
while (formKeys.hasMoreElements()) {
String keyField = (String) formKeys.nextElement();
// extract the metadata id from the form field
String[] tokens = keyField.split("_");
if (tokens.length == 2 && cpt.getTypeMetadata().containsKey(tokens[1])) {
keyName = tokens[1];
// get the submitted values for that key
String[] formValues = req.getParameterValues(keyField);
// save new value
// PubMedID requires HTML entity encoding because
// of hyperlinks in the metadata field.
// TODO: create an external XML file that contains key names
// TODO: like PubMedID that indicate whether or not the value of the key
// TODO: should be HTML encoded
if (keyName.equals("PubMedID")) {
cpt.getTypeMetadata().replaceMetadata(keyName,
StringEscapeUtils.escapeHtml(formValues[0]));
} else
cpt.getTypeMetadata().replaceMetadata(keyName, formValues[0]);
}
}
// build policy file path
String policyDirectory = PathUtils.replaceEnvVariables(this
.getServletContext().getInitParameter(POLICY_UPLOAD_PATH));
String policyPath = policyDirectory;
String policyFile = policyPath + "/" + policyName + "/product-types.xml";
LOG.log(Level.INFO, "updating CAS policy at: [" + policyFile + "]");
// serialize all CasProductType instances from metaDataItems hashtable
try {
CurationXmlStructFactory.writeProductTypeXmlDocument(cpm
.typesToList(types), policyFile);
} catch (Exception e) {
throw new ServletException(
"error writing product type xml document! Message: " + e.getMessage());