package pt.utl.ist.fenix.tools.file.dspace; import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.ArrayList; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.tree.BaseElement; import pt.utl.ist.fenix.tools.file.FileSetMetaData; import pt.utl.ist.fenix.tools.file.XMLSerializable; public class ChangeItemMetaDataRequest implements Serializable,XMLSerializable { String itemHandler; Collection metaData; public ChangeItemMetaDataRequest() { super(); } public ChangeItemMetaDataRequest(String itemHandler, Collection metaData) { this(); this.itemHandler = itemHandler; this.metaData = metaData; } public String getItemHandler() { return itemHandler; } public void setItemHandler(String itemHandler) { this.itemHandler = itemHandler; } public Collection getMetaData() { return metaData; } private void addMetaDataElement(FileSetMetaData metaDataElement) { if(this.metaData==null) { this.metaData = new ArrayList(); } this.metaData.add(metaDataElement); } public void setMetaData(Collection metaData) { this.metaData = metaData; } public String toXMLString() { return toXML().asXML(); } public Element toXML() { Element fileSetPermissionChangeElement = new BaseElement("itemMetaDataRequest"); fileSetPermissionChangeElement.addElement("itemHandler").setText(getItemHandler()); Element metaDataElement = fileSetPermissionChangeElement.addElement("metaData"); for(FileSetMetaData metaData : getMetaData()) { metaDataElement.add(metaData.toXML()); } return fileSetPermissionChangeElement; } public static ChangeItemMetaDataRequest createFromXml(String xml) { ChangeItemMetaDataRequest request = new ChangeItemMetaDataRequest(); request.fromXMLString(xml); return request; } public void fromXMLString(String xml) { try { fromXML(DocumentHelper.parseText(xml).getRootElement()); } catch (DocumentException e) { throw new RuntimeException(e); } } public void fromXML(Element xmlElement) { this.itemHandler = xmlElement.element("itemHandler").getText(); for(Element element : (List)xmlElement.element("metaData").elements("filesetmetadata")) { FileSetMetaData metaDataElement = new FileSetMetaData(); metaDataElement.fromXML(element); addMetaDataElement(metaDataElement); } } }