package org.greenstone.gsdl3.gs3build.metadata; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; public class NamespaceFactory { public static METSNamespace initNamespace() { return new GSDL3Namespace(); } public static METSNamespace initNamespace(String name) { if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID)) { return new GSDL3Namespace(); } return new SimpleNamespace(name); } public static METSNamespace initNamespace(String name, METSLocation location) { if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID)){ return new GSDL3Namespace(location); } return new SimpleNamespace(name, location); } /** * TODO: parse the document in based upon its namespace */ public static METSNamespace initNamespace(String name, Element element) { //return null; return new SimpleNamespace(name); } public static METSNamespace parseXML(Element element) { METSNamespace namespace = null; //String mdType = element.getAttribute("MDType"); //String mdType =element.getAttribute("MDTYPE"); String othermdType = element.getAttribute("OTHERMDTYPE"); String mimeType = element.getAttribute("mimeType"); if (element.getNodeName().equals("mets:mdWrap")) { namespace = initNamespace(othermdType, element); } else if (element.getNodeName().equals("mets:mdRef")) { String mdType = element.getAttribute("MDType"); // just a file wrapper on the metadata... String location = element.getAttribute("xlink:href"); String locationType = element.getAttribute("LOCTYPE"); try { METSLocation metsLocation = new METSLocation(locationType, location); namespace = initNamespace(mdType, metsLocation); } catch (java.net.MalformedURLException ex) { // TODO: Error, should never happen in the case of Greenstone-exported XML } } return namespace; } }