44import java .net .URL ;
55
66import com .eclipsesource .json .JsonObject ;
7- import com .eclipsesource .json .JsonValue ;
87
98/**
109 * The class represents one instance of a file representation.
1110 */
1211public class Representation {
1312
13+ /**
14+ * Used to validate if the hints header has (near) valid value.
15+ */
16+ protected static final String X_REP_HINTS_PATTERN = "^(?:\\ [[a-z0-9_]+(?:\\ ?[a-z0-9_]+\\ =[a-z0-9_]+(?:"
17+ + "\\ |[a-z0-9_]+)*(?:&[a-z0-9_]+\\ =[a-z0-9_]+(?:\\ |[a-z0-9_]+)*)*)?(?:,[a-z0-9_]+(?:\\ ?[a-z0-9_]+\\ =[a-z0-9_]+"
18+ + "(?:\\ |[a-z0-9_]+)*(?:&[a-z0-9_]+\\ =[a-z0-9_]+(?:\\ |[a-z0-9_]+)*)*)?)*\\ ])+$" ;
19+
1420 private String representation ;
15- private Properties properties ;
16- private Metadata metadata ;
17- private String assetPath ;
21+ private JsonObject properties ;
22+ private JsonObject metadata ;
1823 private Info info ;
1924 private Content content ;
2025 private Status status ;
@@ -28,11 +33,9 @@ public Representation(JsonObject representationJson) {
2833 if (member .getName ().equals ("representation" )) {
2934 this .representation = member .getValue ().asString ();
3035 } else if (member .getName ().equals ("properties" )) {
31- this .properties = new Properties ( member .getValue ().asObject () );
36+ this .properties = member .getValue ().asObject ();
3237 } else if (member .getName ().equals ("metadata" )) {
33- this .metadata = new Metadata (member .getValue ().asObject ());
34- } else if (member .getName ().equals ("assetPath" )) {
35- this .assetPath = member .getValue ().asString ();
38+ this .metadata = member .getValue ().asObject ();
3639 } else if (member .getName ().equals ("info" )) {
3740 this .info = new Info (member .getValue ().asObject ());
3841 } else if (member .getName ().equals ("content" )) {
@@ -56,30 +59,21 @@ public String getRepresentation() {
5659 /**
5760 * Get representation's set of static properties to distinguish between subtypes of a given representation,
5861 * for example, different sizes of jpg's. Each representation has its own set of properties.
59- * @return properties of representation
62+ * @return properties of representation as JsonObject
6063 */
61- public Properties getProperties () {
64+ public JsonObject getProperties () {
6265 return this .properties ;
6366 }
6467
6568 /**
6669 * Get representation's metadata.
6770 *
68- * @return metadata
71+ * @return metadataas JsonObject
6972 */
70- public Metadata getMetadata () {
73+ public JsonObject getMetadata () {
7174 return this .metadata ;
7275 }
7376
74- /**
75- * Get representation's asset path.
76- *
77- * @return The values used to substitute for asset_path in the content.url_template.
78- */
79- public String getAssetPath () {
80- return this .assetPath ;
81- }
82-
8377 /**
8478 * Get Info which has an opaque URL which will return status information about the file.
8579 * It may change over time and should not be hard-coded or cached.
@@ -105,97 +99,6 @@ public Status getStatus() {
10599 return this .status ;
106100 }
107101
108- /**
109- * A set of static properties to distinguish between subtypes of a given representation,
110- * for example, different sizes of jpg's. Each representation has its own set of properties.
111- */
112- public class Properties {
113-
114- private String dimensions ;
115- private String paged ;
116- private String thumb ;
117-
118- /**
119- * Construct a representation's properties.
120- * @param members json object
121- */
122- public Properties (JsonObject members ) {
123- for (JsonObject .Member member : members ) {
124- if (member .getName ().equals ("dimensions" )) {
125- this .dimensions = member .getValue ().asString ();
126- } else if (member .getName ().equals ("paged" )) {
127- this .paged = member .getValue ().asString ();
128- } else if (member .getName ().equals ("thumb" )) {
129- this .thumb = member .getValue ().asString ();
130- }
131- }
132- }
133-
134- /**
135- * Get dimensions of representation.
136- * @return dimensions
137- */
138- public String getDimensions () {
139- return this .dimensions ;
140- }
141-
142- /**
143- * Get whether or not multiple pages are supported or not.
144- * @return paged value
145- */
146- public String getPaged () {
147- return this .paged ;
148- }
149-
150- /**
151- * When true, down-sampling options are used to produce a better image.
152- * @return thumb value
153- */
154- public String getThumb () {
155- return this .thumb ;
156- }
157- }
158-
159- /**
160- * Representation's metadata which is a set of dynamic properties about this specific representation of this
161- * specific file. Metadata is different for each representation subtype.
162- */
163- public class Metadata {
164-
165- private int pages ;
166- private JsonObject jsonObject ;
167-
168- /**
169- * Construct a representation's metadata.
170- * @param members json object
171- */
172- public Metadata (JsonObject members ) {
173- for (JsonObject .Member member : members ) {
174- if (member .getName ().equals ("pages" )) {
175- this .pages = member .getValue ().asInt ();
176- }
177- }
178- this .jsonObject = members ;
179- }
180-
181- /**
182- * No. of pages in a multi-page representation.
183- * @return no. of pages
184- */
185- public int getPages () {
186- return this .pages ;
187- }
188-
189- /**
190- * Returns a json value for any field in a repreentation's metadata.
191- * @param field the field that designates the key
192- * @return the metadata property value.
193- */
194- public JsonValue get (String field ) {
195- return this .jsonObject .get (field );
196- }
197- }
198-
199102 /**
200103 * Representation's info URL.
201104 */
0 commit comments