Debian Codegraph @

src/java/org/astrogrid/samp/Metadata.java

raw
1 package org.astrogrid.samp;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.util.Map;
6
7 /**
8 * Represents the application metadata associated with a SAMP client.
9 *
10 * @author Mark Taylor
11 * @since 14 Jul 2008
12 */
13 public class Metadata extends SampMap {
14
15 /** Key for application name. */
16 public static final String NAME_KEY = "samp.name";
17
18 /** Key for short description of the application in plain text. */
19 public static final String DESCTEXT_KEY = "samp.description.text";
20
21 /** Key for description of the application in HTML. */
22 public static final String DESCHTML_KEY = "samp.description.html";
23
24 /** Key for the URL of an icon in png, gif or jpeg format. */
25 public static final String ICONURL_KEY = "samp.icon.url";
26
27 /** Key for the URL of a documentation web page. */
28 public static final String DOCURL_KEY = "samp.documentation.url";
29
30 private static final String[] KNOWN_KEYS = new String[] {
31 NAME_KEY,
32 DESCTEXT_KEY,
33 DESCHTML_KEY,
34 ICONURL_KEY,
35 DOCURL_KEY,
36 };
37
38 /**
39 * Constructs an empty Metadata map.
40 */
41 public Metadata() {
42 super( KNOWN_KEYS );
43 }
44
45 /**
46 * Constructs a Metadata map based on a given map.
47 *
48 * @param map map containing initial values for this object
49 */
50 public Metadata( Map map ) {
51 this();
52 putAll( map );
53 }
54
55 /**
56 * Sets the value for the application's name.
57 *
58 * @param name value for {@link #NAME_KEY} key
59 */
60 public void setName( String name ) {
61 put( NAME_KEY, name );
62 }
63
64 /**
65 * Returns the value for the application's name.
66 *
67 * @return value for {@link #NAME_KEY} key
68 */
69 public String getName() {
70 return (String) get( NAME_KEY );
71 }
72
73 /**
74 * Sets a short description of the application.
75 *
76 * @param txt value for {@link #DESCTEXT_KEY} key
77 */
78 public void setDescriptionText( String txt ) {
79 put( DESCTEXT_KEY, txt );
80 }
81
82 /**
83 * Returns a short description of the application.
84 *
85 * @return value for {@link #DESCTEXT_KEY} key
86 */
87 public String getDescriptionText() {
88 return (String) get( DESCTEXT_KEY );
89 }
90
91 /**
92 * Sets an HTML description of the application.
93 *
94 * @param html value for {@link #DESCHTML_KEY} key
95 */
96 public void setDescriptionHtml( String html ) {
97 put( DESCHTML_KEY, html );
98 }
99
100 /**
101 * Returns an HTML description of the application.
102 *
103 * @return value for {@link #DESCHTML_KEY} key
104 */
105 public String getDescriptionHtml() {
106 return (String) get( DESCHTML_KEY );
107 }
108
109 /**
110 * Sets a URL for a gif, png or jpeg icon identifying the application.
111 *
112 * @param url value for {@link #ICONURL_KEY} key
113 */
114 public void setIconUrl( String url ) {
115 put( ICONURL_KEY, url );
116 }
117
118 /**
119 * Returns a URL for a gif, png or jpeg icon identifying the application.
120 *
121 * @return value for {@link #ICONURL_KEY} key
122 */
123 public URL getIconUrl() {
124 return getUrl( ICONURL_KEY );
125 }
126
127 /**
128 * Sets a URL for a documentation web page.
129 *
130 * @param url value for {@link #DOCURL_KEY} key
131 */
132 public void setDocumentationUrl( String url ) {
133 put( DOCURL_KEY, url );
134 }
135
136 /**
137 * Returns a URL for a documentation web page.
138 *
139 * @return value for {@link #DOCURL_KEY} key
140 */
141 public URL getDocumentationUrl() {
142 return getUrl( DOCURL_KEY );
143 }
144
145 public void check() {
146 super.check();
147 SampUtils.checkUrl( getString( DOCURL_KEY ) );
148 SampUtils.checkUrl( getString( ICONURL_KEY ) );
149 }
150
151 /**
152 * Returns a given map as a Metadata object.
153 *
154 * @param map map
155 * @return metadata
156 */
157 public static Metadata asMetadata( Map map ) {
158 return ( map instanceof Metadata || map == null )
159 ? (Metadata) map
160 : new Metadata( map );
161 }
162 }