1 | package org.greenstone.gsdl3.gs3build.metadata;
|
---|
2 |
|
---|
3 | import org.w3c.dom.Document;
|
---|
4 | import org.w3c.dom.Element;
|
---|
5 | import org.w3c.dom.NamedNodeMap;
|
---|
6 | import org.w3c.dom.Node;
|
---|
7 | import org.w3c.dom.NodeList;
|
---|
8 | import org.w3c.dom.Text;
|
---|
9 |
|
---|
10 | public class NamespaceFactory
|
---|
11 | {
|
---|
12 | public static METSNamespace initNamespace()
|
---|
13 | {
|
---|
14 | return new GSDL3Namespace();
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static METSNamespace initNamespace(String name)
|
---|
18 | {
|
---|
19 | if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID)) {
|
---|
20 | return new GSDL3Namespace();
|
---|
21 | }
|
---|
22 | return new SimpleNamespace(name);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public static METSNamespace initNamespace(String name, METSLocation location)
|
---|
26 | {
|
---|
27 | if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID)){
|
---|
28 | return new GSDL3Namespace(location);
|
---|
29 | }
|
---|
30 | return new SimpleNamespace(name, location);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * TODO: parse the document in based upon its namespace
|
---|
35 | */
|
---|
36 | public static METSNamespace initNamespace(String name, Element element)
|
---|
37 | {
|
---|
38 | //return null;
|
---|
39 | return new SimpleNamespace(name);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static METSNamespace parseXML(Element element)
|
---|
43 | {
|
---|
44 | METSNamespace namespace = null;
|
---|
45 |
|
---|
46 | //String mdType = element.getAttribute("MDType");
|
---|
47 | //String mdType =element.getAttribute("MDTYPE");
|
---|
48 |
|
---|
49 | String othermdType = element.getAttribute("OTHERMDTYPE");
|
---|
50 | String mimeType = element.getAttribute("mimeType");
|
---|
51 |
|
---|
52 | if (element.getNodeName().equals("mets:mdWrap")) {
|
---|
53 | namespace = initNamespace(othermdType, element);
|
---|
54 | }
|
---|
55 | else if (element.getNodeName().equals("mets:mdRef")) {
|
---|
56 | String mdType = element.getAttribute("MDType");
|
---|
57 | // just a file wrapper on the metadata...
|
---|
58 | String location = element.getAttribute("xlink:href");
|
---|
59 | String locationType = element.getAttribute("LOCTYPE");
|
---|
60 |
|
---|
61 | try {
|
---|
62 | METSLocation metsLocation = new METSLocation(locationType, location);
|
---|
63 | namespace = initNamespace(mdType, metsLocation);
|
---|
64 | }
|
---|
65 | catch (java.net.MalformedURLException ex) {
|
---|
66 | // TODO: Error, should never happen in the case of Greenstone-exported XML
|
---|
67 | }
|
---|
68 | }
|
---|
69 | return namespace;
|
---|
70 | }
|
---|
71 | }
|
---|