Source code: com/obinary/cms/core/MetaData.java
1 /**
2 *
3 * Magnolia and its source-code is licensed under the LGPL.
4 * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5 * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6 * you are required to provide proper attribution to obinary.
7 * If you reproduce or distribute the document without making any substantive modifications to its content,
8 * please use the following attribution line:
9 *
10 * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11 *
12 * */
13
14
15
16
17
18
19 package com.obinary.cms.core;
20
21
22
23 import javax.jcr.*;
24 import java.util.GregorianCalendar;
25 import java.util.TimeZone;
26 import java.util.Calendar;
27 import java.util.Date;
28
29
30 /**
31 * Date: Apr 28, 2003
32 * Time: 11:20:59 AM
33 * @author Sameer Charles
34 * @author Marcel Salathe
35 * @version 1.0
36 */
37
38
39
40 public class MetaData {
41
42
43
44
45 /**
46 * Top level atoms viewed as metadata of the specified content
47 * these must be set by the authoring system itself, but could be
48 * changed via custom templates if neccessary.
49 * */
50 private static final String TITLE = "title";
51 private static final String CREATION_DATE = "creationdate";
52 private static final String LAST_MODIFIED = "lastmodified";
53 private static final String LAST_ACTION = "lastaction";
54 private static final String AUTHOR_ID = "authorid";
55 private static final String ACTIVATOR_ID = "activatorid";
56 private static final String START_TIME = "starttime";
57 private static final String END_TIME = "endtime";
58 private static final String TEMPLATE = "template";
59 private static final String TEMPLATE_TYPE = "templatetype";
60 private static final String ACTIVATED = "activated";
61 private static final String SEQUENCE_POS = "sequenceposition";
62
63
64 public static final String ACTIVATION_INFO = ".activationInfo";
65
66
67 /* current working node */
68 private Node node;
69
70
71
72
73 /**
74 * Package private constructor
75 *
76 * @param workingNode current <code>Node</code> on which <code>MetaData</code> is requested
77 */
78 MetaData (Node workingNode) {
79 this.node = workingNode;
80 }
81
82
83
84 /**
85 * constructor
86 *
87 * @param workingNode current <code>Node</code> on which <code>MetaData</code> is requested
88 * @param containerName under which this data is saved
89 */
90 MetaData (Node workingNode, String containerName) throws RepositoryException {
91 try {
92 this.node = workingNode.getNode(workingNode.getPath()+"/"+containerName);
93 } catch (ElementNotFoundException e) {
94 this.node = workingNode.addNode(workingNode.getPath()+"/"+containerName);
95 }
96 }
97
98
99
100 /**
101 * <p>part of metadata, same as name of actual storage node<br>
102 * this value is unique at the hierarchy level context</p>
103 *
104 * @return String value of the requested metadata
105 */
106 public String getLabel() {
107 return this.node.getName();
108 }
109
110
111
112 /**
113 * <p>part of metadata , could be used as html header</p>
114 *
115 * @return String value of the requested metadata
116 */
117 public String getTitle() {
118 try {
119 return (new Atom(this.node, TITLE)).getValue().getString();
120 } catch (ElementNotFoundException ee) {return ""; }
121 catch (RepositoryException re) {return ""; }
122 }
123
124
125
126 /**
127 * <p>part of metadata, could be used as html header</p>
128 *
129 * @param value
130 */
131 public void setTitle(String value) {
132 try {
133 (new Atom(this.node, TITLE)).setValue(value);
134 } catch (ElementNotFoundException ee) {
135 try {
136 (new Atom(this.node, TITLE, true)).setValue(value);
137 } catch (RepositoryException e) {}
138 } catch (RepositoryException re) {}
139 }
140
141
142
143 /**
144 * <p>part of metadata, adds creation date of the current node</p>
145 *
146 */
147 public void setCreationDate() {
148 GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getDefault());
149 try {
150 (new Atom(this.node, CREATION_DATE)).setValue(creationDate);
151 } catch (ElementNotFoundException ee) {
152 try {
153 (new Atom(this.node, CREATION_DATE, true)).setValue(creationDate);
154 } catch (RepositoryException e ) {}
155 } catch (RepositoryException re) {}
156 }
157
158
159
160 /**
161 * <p>part of metadata, get creation date of the current node</p>
162 *
163 * @return Calendar
164 */
165 public Calendar getCreationDate() {
166 try {
167 return (new Atom(this.node, CREATION_DATE)).getValue().getDate();
168 } catch (ElementNotFoundException ee) {return null; }
169 catch (RepositoryException re) {return null; }
170 }
171
172
173
174
175 /**
176 * <p>part of metadata, adds sequence number of the current node</p>
177 *
178 */
179 public void setSequencePosition(long seqPos) {
180 if (seqPos==0) {
181 Date now = new Date();
182 seqPos=now.getTime();
183 }
184 try {
185 (new Atom(this.node, SEQUENCE_POS)).setValue(seqPos);
186
187 } catch (ElementNotFoundException ee) {
188 try {
189 (new Atom(this.node, SEQUENCE_POS, true)).setValue(seqPos);
190 } catch (RepositoryException e ) {}
191 } catch (RepositoryException re) {}
192 }
193
194
195 /**
196 * <p>part of metadata, adds sequence number of the current node</p>
197 *
198 */
199 public void setSequencePosition() {
200 setSequencePosition(0);
201 }
202
203
204 /**
205 * <p>part of metadata, get sequence position of the current node</p>
206 *
207 * @return long
208 */
209 public long getSequencePosition() {
210 try {
211 return (new Atom(this.node, SEQUENCE_POS)).getLong();
212 } catch (ElementNotFoundException ee) {
213 Calendar cd=getCreationDate();
214 return cd.getTimeInMillis();
215 }
216 catch (RepositoryException re) {return 0; }
217 // } catch (ElementNotFoundException ee) {return null; }
218 // catch (RepositoryException re) {return null; }
219 }
220
221
222
223
224
225
226 /**
227 * <p>part of metadata, adds activated status of the current node</p>
228 *
229 */
230 public void setActivated() {
231 try {
232 (new Atom(this.node, ACTIVATED)).setValue(true);
233 } catch (ElementNotFoundException ee) {
234 try {
235 (new Atom(this.node, ACTIVATED, true)).setValue(true);
236 } catch (RepositoryException e ) {}
237 }
238 catch (RepositoryException re) {}
239 }
240
241
242
243 /**
244 * <p>part of metadata, adds activated status of the current node</p>
245 *
246 */
247 public void setUnActivated() {
248 try {
249 (new Atom(this.node, ACTIVATED)).setValue(false);
250 } catch (ElementNotFoundException ee) {
251 try {
252 (new Atom(this.node, ACTIVATED, true)).setValue(false);
253 } catch (RepositoryException e ) {}
254 }
255 catch (RepositoryException re) {}
256 }
257
258
259
260 /**
261 * <p>part of metadata, get last activated status of the current node</p>
262 *
263 * @return Calendar
264 */
265 public boolean getIsActivated() {
266 try {
267 return (new Atom(this.node, ACTIVATED)).getBoolean();
268 } catch (RepositoryException re) {return false;}
269 }
270
271
272
273 /**
274 * <p>part of metadata, adds activated date of the current node</p>
275 *
276 */
277 public void setLastActivationActionDate() {
278 GregorianCalendar currentDate = new GregorianCalendar(TimeZone.getDefault());
279 try {
280 (new Atom(this.node, LAST_ACTION)).setValue(currentDate);
281 } catch (ElementNotFoundException ee) {
282 try {
283 (new Atom(this.node, LAST_ACTION, true)).setValue(currentDate);
284 } catch (RepositoryException e ) {}
285 }
286 catch (RepositoryException re) {}
287 }
288
289
290
291 /**
292 * <p>part of metadata, get last activated/de- date of the current node</p>
293 *
294 * @return Calendar
295 */
296 public Calendar getLastActionDate() {
297 try {
298 return (new Atom(this.node, LAST_ACTION)).getValue().getDate();
299 } catch (ElementNotFoundException ee) {return null; }
300 catch (RepositoryException re) {return null; }
301 }
302
303
304
305 /**
306 * <p>part of metadata, adds modification date of the current node</p>
307 *
308 */
309 public void setModificationDate() {
310 GregorianCalendar currentDate = new GregorianCalendar(TimeZone.getDefault());
311 try {
312 (new Atom(this.node, LAST_MODIFIED)).setValue(currentDate);
313 } catch (ElementNotFoundException ee) {
314 try {
315 (new Atom(this.node, LAST_MODIFIED, true)).setValue(currentDate);
316 } catch (RepositoryException e ) {}
317 }
318 catch (RepositoryException re) {}
319 }
320
321
322
323 /**
324 * <p>part of metadata, get last modified date of the current node</p>
325 *
326 * @return Calendar
327 */
328 public Calendar getModificationDate() {
329 try {
330 return (new Atom(this.node, LAST_MODIFIED)).getValue().getDate();
331 } catch (ElementNotFoundException ee) {return null; }
332 catch (RepositoryException re) {return null; }
333 }
334
335
336
337 /**
338 * <p>part of metadata , last known author of this node</p>
339 *
340 * @return String value of the requested metadata
341 */
342 public String getAuthorId() {
343 try {
344 return (new Atom(this.node, AUTHOR_ID)).getValue().getString();
345 } catch (ElementNotFoundException ee) {return ""; }
346 catch (RepositoryException re) {return ""; }
347 }
348
349
350
351 /**
352 * <p>part of metadata, current logged-in author who did some action on this page</p>
353 *
354 * @param value
355 */
356 public void setAuthorId(String value) {
357 try {
358 (new Atom(this.node, AUTHOR_ID)).setValue(value);
359 } catch (ElementNotFoundException ee) {
360 try {
361 (new Atom(this.node, AUTHOR_ID, true)).setValue(value);
362 } catch (RepositoryException e ) {}
363 }
364 catch (RepositoryException re) {}
365 }
366
367
368
369 /**
370 * <p>part of metadata , last known activator of this node</p>
371 *
372 * @return String value of the requested metadata
373 */
374 public String getActivatorId() {
375 try {
376 return (new Atom(this.node, ACTIVATOR_ID)).getValue().getString();
377 } catch (ElementNotFoundException ee) {return ""; }
378 catch (RepositoryException re) {return ""; }
379 }
380
381
382
383 /**
384 * <p>part of metadata, current logged-in author who last activated this page</p>
385 *
386 * @param value
387 */
388 public void setActivatorId(String value) {
389 try {
390 (new Atom(this.node, ACTIVATOR_ID)).setValue(value);
391 } catch (ElementNotFoundException ee) {
392 try {
393 (new Atom(this.node, ACTIVATOR_ID, true)).setValue(value);
394 } catch (RepositoryException e ) {}
395 }
396 catch (RepositoryException re) {}
397 }
398
399
400
401
402 /**
403 * <p>part of metadata, node activation time</p>
404 *
405 */
406 public void setStartTime(Calendar startTime) {
407 try {
408 (new Atom(this.node, START_TIME)).setValue(startTime);
409 } catch (ElementNotFoundException ee) {
410 try {
411 (new Atom(this.node, START_TIME, true)).setValue(startTime);
412 } catch (RepositoryException e) {}
413 }
414 catch (RepositoryException re) {}
415 }
416
417
418
419 /**
420 * <p>part of metadata, node activation time</p>
421 *
422 * @return Calendar
423 */
424 public Calendar getStartTime() {
425 try {
426 return (new Atom(this.node, START_TIME)).getValue().getDate();
427 } catch (ElementNotFoundException ee) {return null; }
428 catch (RepositoryException re) {return null; }
429 }
430
431
432
433 /**
434 * <p>part of metadata, node de-activation time</p>
435 *
436 */
437 public void setEndTime(Calendar startTime) {
438 try {
439 (new Atom(this.node, END_TIME)).setValue(startTime);
440 } catch (ElementNotFoundException ee) {
441 try {
442 (new Atom(this.node, END_TIME, true)).setValue(startTime);
443 } catch (RepositoryException e) {}
444 }
445 catch (RepositoryException re) {}
446 }
447
448
449
450 /**
451 * <p>part of metadata, node de-activation time</p>
452 *
453 * @return Calendar
454 */
455 public Calendar getEndTime() {
456 try {
457 return (new Atom(this.node, END_TIME)).getValue().getDate();
458 } catch (ElementNotFoundException ee) {return null; }
459 catch (RepositoryException re) {return null; }
460 }
461
462
463
464 /**
465 * <p>part of metadata , template which will be used to render content of this node</p>
466 *
467 * @return String value of the requested metadata
468 */
469 public String getTemplate() {
470 try {
471 return (new Atom(this.node, TEMPLATE)).getValue().getString();
472 } catch (ElementNotFoundException ee) {return ""; }
473 catch (RepositoryException re) {return ""; }
474 }
475
476
477
478 /**
479 * <p>part of metadata, template which will be used to render content of this node</p>
480 *
481 * @param value
482 */
483 public void setTemplate(String value) {
484 try {
485 (new Atom(this.node, TEMPLATE)).setValue(value);
486 } catch (ElementNotFoundException ee) {
487 try {
488 (new Atom(this.node, TEMPLATE, true)).setValue(value);
489 } catch (RepositoryException e) {}
490 }
491 catch (RepositoryException re) {}
492 }
493
494
495
496 /**
497 * <p>part of metadata, template type : JSP - Servlet - _xxx_</p>
498 *
499 * @param value
500 */
501 public void setTemplateType(String value) {
502 try {
503 (new Atom(this.node, TEMPLATE_TYPE)).setValue(value);
504 } catch (ElementNotFoundException ee) {
505 try {
506 (new Atom(this.node, TEMPLATE_TYPE, true)).setValue(value);
507 } catch (RepositoryException e) {}
508 }
509 catch (RepositoryException re) {}
510 }
511
512
513
514
515 }