String deleteCustom = req.getParameter("deleteCustom");
// add attribute
if (attrName.length() > 0 && col.isMetaEnabled() && updateAttr == null) {
try {
MetaData newMeta = col.getCollectionMeta();
newMeta.setAttribute(attrName, attrValue);
col.setCollectionMeta(newMeta);
attrName = "";
attrValue = "";
} catch (DBException e1) {
log.error(e1);
printError("Cannot add Attribute " + attrName + ": " + e1.getMessage(), output);
}
} else if (updateAttr != null && updateAttr.length() > 0 && col.isMetaEnabled()) {
attrName = updateAttr;
try {
attrValue = (String) col.getCollectionMeta().getAttribute(attrName);
} catch (DBException e) {
log.error(e);
attrValue = "";
}
} else if (deleteAttr != null && deleteAttr.length() > 0 && col.isMetaEnabled()) {
try {
MetaData delMeta = col.getCollectionMeta();
delMeta.removeAttribute(deleteAttr);
col.setCollectionMeta(delMeta);
} catch (DBException e) {
log.error(e);
printError("Cannot delete Attribute " + deleteAttr + ": " + e.getMessage(), output);
}
} else if (custom != null && custom.length() > 0 && col.isMetaEnabled()) {
try {
MetaData customMeta = col.getCollectionMeta();
Document customDoc = DOMParser.toDocument(custom);
customMeta.setCustomDocument(customDoc);
col.setCollectionMeta(customMeta);
} catch (DBException e) {
log.error(e);
printError("Cannot add/update Custom: " + e.getMessage(), output);
} catch (XindiceException e) {
log.error(e);
printError("Cannot add/update Custom: " + e.getMessage(), output);
}
} else if (deleteCustom != null && deleteCustom.length() > 0 && col.isMetaEnabled()) {
try {
MetaData customMeta = col.getCollectionMeta();
if (customMeta != null) {
customMeta.setCustomDocument(null);
col.setCollectionMeta(customMeta);
}
} catch (DBException e) {
log.error(e);
printError("Cannot delete Custom: " + e.getMessage(), output);
}
} else if (req.getMethod().equalsIgnoreCase("POST")) {
byte[] content = new byte[0];
try {
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
// Set upload parameters
upload.setSizeMax(-1);
upload.setFileItemFactory(new DiskFileItemFactory());
// Process the uploaded fields
Iterator i = upload.parseRequest(req).iterator();
while (i.hasNext()) {
FileItem item = (FileItem) i.next();
if (!item.isFormField()) {
if (item.getFieldName().equals("customfile")) {
content = item.get();
}
}
item.delete();
}
} catch (FileUploadException e) {
log.error(e);
}
if (content.length > 0) {
Document customDoc;
try {
customDoc = DOMParser.toDocument(content);
} catch (XindiceException e1) { // document fragment ?
log.error(e1);
StringBuffer newContent = new StringBuffer();
newContent.append("<custom>").append(new String(content)).append("</custom>");
try {
customDoc = DOMParser.toDocument(newContent.toString());
} catch (XindiceException e2) { // no xml content
log.error(e2);
printError("Cannot parse Custom: " + e2.getMessage(), output);
customDoc = null;
}
}
if (customDoc != null) {
if (!customDoc.getDocumentElement().getNodeName().equals("custom")) {
Document newCustomDoc = new DocumentImpl();
Element customEle = newCustomDoc.createElement("custom");
customEle.appendChild(customDoc.getDocumentElement());
newCustomDoc.appendChild(customEle);
customDoc = newCustomDoc;
}
try {
MetaData customMeta = col.getCollectionMeta();
customMeta.setCustomDocument(customDoc);
col.setCollectionMeta(customMeta);
} catch (DBException e2) {
log.error(e2);
printError("Cannot create Custom: " + e2.getMessage(), output);
}
}
}
}
printStartTable("Add/Update Metadata Attribute", output);
printStartSingleTableBox(output);
output.print(META_ATTR_UPDATE_FORM_START);
output.print(attrName);
output.print(META_ATTR_UPDATE_FORM_MIDDLE);
output.print(attrValue);
output.print(META_ATTR_UPDATE_FORM_END);
printEndSingleTableBox(output);
printEndTable(output);
output.println("<br />\n");
if (col.isMetaEnabled()) {
MetaData metaData;
try {
metaData = col.getCollectionMeta();
} catch (DBException e) {
log.error(e);
metaData = null;