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 | { return new GSDL3Namespace();
|
---|
14 | }
|
---|
15 |
|
---|
16 | public static METSNamespace initNamespace(String name)
|
---|
17 | { if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID))
|
---|
18 | { return new GSDL3Namespace();
|
---|
19 | }
|
---|
20 | return new SimpleNamespace(name);
|
---|
21 | }
|
---|
22 |
|
---|
23 | public static METSNamespace initNamespace(String name, METSLocation location)
|
---|
24 | { if (name.equals(GSDL3Namespace.GSDL3_NAMESPACE_ID))
|
---|
25 | { return new GSDL3Namespace(location);
|
---|
26 | }
|
---|
27 | return new SimpleNamespace(name, location);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * TODO: parse the document in based upon its namespace
|
---|
32 | */
|
---|
33 | public static METSNamespace initNamespace(String name, Element element)
|
---|
34 | { //return null;
|
---|
35 | return new SimpleNamespace(name);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public static METSNamespace parseXML(Element element)
|
---|
39 | { METSNamespace namespace = null;
|
---|
40 |
|
---|
41 | String mdType = element.getAttribute("MDType");
|
---|
42 | String mimeType = element.getAttribute("mimeType");
|
---|
43 |
|
---|
44 | if (element.getNodeName().equals("mets:mdWrap"))
|
---|
45 | { namespace = initNamespace(mdType, element);
|
---|
46 | }
|
---|
47 | else if (element.getNodeName().equals("mets:mdRef"))
|
---|
48 | { // just a file wrapper on the metadata...
|
---|
49 | String location = element.getAttribute("xlink:href");
|
---|
50 | String locationType = element.getAttribute("LOCTYPE");
|
---|
51 |
|
---|
52 | try
|
---|
53 | {
|
---|
54 | METSLocation metsLocation = new METSLocation(locationType, location);
|
---|
55 | namespace = initNamespace(mdType, metsLocation);
|
---|
56 | }
|
---|
57 | catch (java.net.MalformedURLException ex)
|
---|
58 | { // TODO: Error, should never happen in the case of Greenstone-exported XML
|
---|
59 | }
|
---|
60 | }
|
---|
61 | return namespace;
|
---|
62 | }
|
---|
63 | }
|
---|