1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | * MetaData.java - part of the demo-client for Greenstone 3, of the
|
---|
4 | * Greenstone digital library suite from the New Zealand Digital Library
|
---|
5 | * Project at the * University of Waikato, New Zealand.
|
---|
6 | * <BR><BR>
|
---|
7 | * Copyright (C) 2008 New Zealand Digital Library Project
|
---|
8 | * <BR><BR>
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | * <BR><BR>
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *########################################################################
|
---|
19 | */
|
---|
20 |
|
---|
21 | package org.greenstone.gs3client.data;
|
---|
22 |
|
---|
23 | import org.greenstone.gsdl3.util.GSXML;
|
---|
24 | import org.w3c.dom.Element;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Stores the name, value and value of body textnode of a simple <metadata>
|
---|
28 | * element. <metadata name="str" value="str">bodyvalue</metadata>
|
---|
29 | * @author ak19
|
---|
30 | */
|
---|
31 | public class MetaData {
|
---|
32 | /* Data fields in a <metadata> element */
|
---|
33 | /** Name attribute of a <metadata> */
|
---|
34 | public final String name;
|
---|
35 | /** Value attribute of a <metadata> - this may or may not be there */
|
---|
36 | public final String value;
|
---|
37 | /** Text node content of a <metadata> - the textnode may be empty, in
|
---|
38 | * which case this will be set to "" */
|
---|
39 | public final String bodyText;
|
---|
40 |
|
---|
41 | /** Constructor that creates a MetaData object from a
|
---|
42 | * <metadata></metadata> element by setting its members fields
|
---|
43 | * using info extracted from the element.
|
---|
44 | * @param metadataTag is the <metadata> element whose data is used
|
---|
45 | * to construct this MetaData object */
|
---|
46 | public MetaData(Element metadataTag){
|
---|
47 | // we'd definitely have a name attribute, but to be safe:
|
---|
48 | this.name = metadataTag.hasAttribute(GSXML.NAME_ATT) ?
|
---|
49 | metadataTag.getAttribute(GSXML.NAME_ATT) : "";
|
---|
50 | //value need to be present
|
---|
51 | this.value = metadataTag.hasAttribute(GSXML.VALUE_ATT) ?
|
---|
52 | metadataTag.getAttribute(GSXML.VALUE_ATT) : "";
|
---|
53 |
|
---|
54 | // Look for any values nested inside <metadata></metadata>:
|
---|
55 | if(metadataTag.hasChildNodes())
|
---|
56 | // && metadataTag.getFirstChild() != null
|
---|
57 | // get its textnode's text:
|
---|
58 | this.bodyText = metadataTag.getFirstChild().getNodeValue();
|
---|
59 | else this.bodyText = "";
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** @return the name of this Metadata object. Useful when adding MetaData
|
---|
63 | * objects to a JList or JCombobox */
|
---|
64 | public String toString() { return name; }
|
---|
65 |
|
---|
66 | /** @return a String displaying the contents of this MetaData object.
|
---|
67 | * Useful for debugging purposes.*/
|
---|
68 | public String show() {
|
---|
69 | StringBuffer buf = new StringBuffer("name: " + name);
|
---|
70 | if(!value.equals(""))
|
---|
71 | buf.append(" -value: " + value);
|
---|
72 | if(!bodyText.equals(""))
|
---|
73 | buf.append(" -bodyText: " + bodyText);
|
---|
74 | return buf.toString();
|
---|
75 | }
|
---|
76 | } |
---|