1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.services.wcm.search;
18
19 import java.io.InputStream;
20 import java.util.Calendar;
21
22 import javax.jcr.AccessDeniedException;
23 import javax.jcr.InvalidItemStateException;
24 import javax.jcr.Item;
25 import javax.jcr.ItemExistsException;
26 import javax.jcr.ItemNotFoundException;
27 import javax.jcr.ItemVisitor;
28 import javax.jcr.MergeException;
29 import javax.jcr.NoSuchWorkspaceException;
30 import javax.jcr.Node;
31 import javax.jcr.NodeIterator;
32 import javax.jcr.PathNotFoundException;
33 import javax.jcr.Property;
34 import javax.jcr.PropertyIterator;
35 import javax.jcr.ReferentialIntegrityException;
36 import javax.jcr.RepositoryException;
37 import javax.jcr.Session;
38 import javax.jcr.UnsupportedRepositoryOperationException;
39 import javax.jcr.Value;
40 import javax.jcr.ValueFormatException;
41 import javax.jcr.lock.Lock;
42 import javax.jcr.lock.LockException;
43 import javax.jcr.nodetype.ConstraintViolationException;
44 import javax.jcr.nodetype.NoSuchNodeTypeException;
45 import javax.jcr.nodetype.NodeDefinition;
46 import javax.jcr.nodetype.NodeType;
47 import javax.jcr.query.Row;
48 import javax.jcr.version.Version;
49 import javax.jcr.version.VersionException;
50 import javax.jcr.version.VersionHistory;
51 import org.apache.commons.lang.StringEscapeUtils;
52 import org.exoplatform.services.wcm.core.NodeLocation;
53
54
55
56
57
58
59
60 public class ResultNode implements Node{
61
62
63 private NodeLocation nodeLocation;
64
65
66 private float score;
67
68
69 private String excerpt;
70
71
72 private String userNavigationURI;
73
74
75
76
77
78
79
80
81
82 public ResultNode(Node node, Row row) throws RepositoryException{
83 this.nodeLocation = NodeLocation.getNodeLocationByNode(node);
84 if(row != null) {
85 Value excerpt = row.getValue("rep:excerpt(.)");
86 this.excerpt = excerpt == null ? "" : excerpt.getString();
87 this.score = row.getValue("jcr:score").getLong();
88 }
89 }
90
91 public ResultNode(Node node, float score, String excerpt) {
92 this.nodeLocation = NodeLocation.getNodeLocationByNode(node);
93 this.excerpt = excerpt;
94 this.score = score;
95 }
96
97 public ResultNode(Node node, Row row, String userNavURI) throws RepositoryException {
98 this.nodeLocation = NodeLocation.getNodeLocationByNode(node);
99 this.userNavigationURI = userNavURI;
100 Value excerpt = row.getValue("rep:excerpt(.)");
101 this.excerpt = excerpt == null ? "" : excerpt.getString();
102 this.score = row.getValue("jcr:score").getLong();
103 }
104
105
106
107
108
109
110 public Node getNode() { return NodeLocation.getNodeByLocation(nodeLocation); }
111
112
113
114
115
116
117 public void setNode(Node node) { this.nodeLocation = NodeLocation.getNodeLocationByNode(node); }
118
119
120
121
122 public void setUserNavigationURI(String userNavigationURI) {
123 this.userNavigationURI = userNavigationURI;
124 }
125
126
127
128
129 public String getUserNavigationURI() {
130 return userNavigationURI;
131 }
132
133
134
135
136
137
138 public float getScore() { return score; }
139
140
141
142
143
144
145 public void setScore(float score) { this.score = score; }
146
147
148
149
150
151
152 public String getExcerpt() {
153 excerpt = StringEscapeUtils.unescapeHtml(excerpt);
154 return excerpt;
155 }
156
157 public String getEditor() {
158 String editor = null;
159 try {
160 if (getNode().hasProperty("exo:owner")) {
161 editor = getNode().getProperty("exo:owner").getString();
162 }
163 } catch (Exception ex) {
164 editor = null;
165 }
166 return editor;
167 }
168
169
170
171
172
173
174 public void setExcerpt(String excerpt) {
175 this.excerpt = excerpt;
176 }
177
178
179
180
181
182
183
184
185 public String getTitle() throws Exception {
186 if(getNode().hasProperty("exo:title")) {
187 return getNode().getProperty("exo:title").getString();
188 }
189 return getNode().getName();
190 }
191
192
193
194
195
196
197
198
199 public String getSummary() throws Exception {
200 if(getNode().hasProperty("exo:summary")) {
201 return getNode().getProperty("exo:summary").getString();
202 }
203 return null;
204 }
205
206
207
208
209
210
211
212 public String getDescription() throws Exception {
213 if (getNode().hasProperty("exo:metaDescription")) {
214 return getNode().getProperty("exo:metaDescription").getString();
215 }
216 return null;
217 }
218
219
220
221
222 public void addMixin(String name) throws NoSuchNodeTypeException, VersionException,
223 ConstraintViolationException, LockException, RepositoryException {
224 throw new ConstraintViolationException("Unsupported this method");
225 }
226
227
228
229
230 public Node addNode(String name) throws ItemExistsException, PathNotFoundException,
231 VersionException, ConstraintViolationException, LockException, RepositoryException {
232 throw new ConstraintViolationException("Unsupported this method");
233 }
234
235
236
237
238 public Node addNode(String name, String type) throws ItemExistsException,
239 PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException,
240 ConstraintViolationException, RepositoryException {
241 throw new ConstraintViolationException("Unsupported this method");
242 }
243
244
245
246
247 public boolean canAddMixin(String name) throws NoSuchNodeTypeException, RepositoryException {
248 throw new ConstraintViolationException("Unsupported this method");
249 }
250
251
252
253
254 public void cancelMerge(Version version) throws VersionException, InvalidItemStateException,
255 UnsupportedRepositoryOperationException, RepositoryException {
256 throw new ConstraintViolationException("Unsupported this method");
257 }
258
259
260
261
262 public Version checkin() throws VersionException, UnsupportedRepositoryOperationException,
263 InvalidItemStateException, LockException, RepositoryException {
264 throw new ConstraintViolationException("Unsupported this method");
265 }
266
267
268
269
270 public void checkout() throws UnsupportedRepositoryOperationException, LockException,
271 RepositoryException {
272 throw new ConstraintViolationException("Unsupported this method");
273 }
274
275
276
277
278 public void doneMerge(Version version) throws VersionException, InvalidItemStateException,
279 UnsupportedRepositoryOperationException, RepositoryException {
280 throw new ConstraintViolationException("Unsupported this method");
281 }
282
283
284
285
286 public Version getBaseVersion() throws UnsupportedRepositoryOperationException,
287 RepositoryException {
288 return getNode().getBaseVersion();
289 }
290
291
292
293
294 public String getCorrespondingNodePath(String nodePath) throws ItemNotFoundException,
295 NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
296 return getNode().getCorrespondingNodePath(nodePath);
297 }
298
299
300
301
302 public NodeDefinition getDefinition() throws RepositoryException {
303 return getNode().getDefinition();
304 }
305
306
307
308
309 public int getIndex() throws RepositoryException {
310 return getNode().getIndex();
311 }
312
313
314
315
316 public Lock getLock() throws UnsupportedRepositoryOperationException, LockException,
317 AccessDeniedException, RepositoryException {
318 return getNode().getLock();
319 }
320
321
322
323
324 public NodeType[] getMixinNodeTypes() throws RepositoryException {
325 return getNode().getMixinNodeTypes();
326 }
327
328
329
330
331 public Node getNode(String name) throws PathNotFoundException, RepositoryException {
332 return getNode().getNode(name);
333 }
334
335
336
337
338 public NodeIterator getNodes() throws RepositoryException {
339 return getNode().getNodes();
340 }
341
342
343
344
345 public NodeIterator getNodes(String name) throws RepositoryException {
346 return getNode().getNodes(name);
347 }
348
349
350
351
352 public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
353 return getNode().getPrimaryItem();
354 }
355
356
357
358
359 public NodeType getPrimaryNodeType() throws RepositoryException {
360 return getNode().getPrimaryNodeType();
361 }
362
363
364
365
366 public PropertyIterator getProperties() throws RepositoryException {
367 return getNode().getProperties();
368 }
369
370
371
372
373 public PropertyIterator getProperties(String name) throws RepositoryException {
374 return getNode().getProperties(name);
375 }
376
377
378
379
380 public PropertyIterator getReferences() throws RepositoryException {
381 return getNode().getReferences();
382 }
383
384
385
386
387 public String getUUID() throws UnsupportedRepositoryOperationException, RepositoryException {
388 return getNode().getUUID();
389 }
390
391
392
393
394 public VersionHistory getVersionHistory() throws UnsupportedRepositoryOperationException,
395 RepositoryException {
396 return getNode().getVersionHistory();
397 }
398
399
400
401
402 public boolean hasNode(String name) throws RepositoryException {
403 return getNode().hasNode(name);
404 }
405
406
407
408
409 public boolean hasNodes() throws RepositoryException {
410 return getNode().hasNodes();
411 }
412
413
414
415
416 public boolean hasProperties() throws RepositoryException {
417 return getNode().hasProperties();
418 }
419
420
421
422
423 public boolean hasProperty(String name) throws RepositoryException {
424 return getNode().hasProperty(name);
425 }
426
427
428
429
430 public boolean holdsLock() throws RepositoryException {
431 return getNode().holdsLock();
432 }
433
434
435
436
437 public boolean isCheckedOut() throws RepositoryException {
438 return getNode().isCheckedOut();
439 }
440
441
442
443
444 public boolean isLocked() throws RepositoryException {
445 return getNode().isLocked();
446 }
447
448
449
450
451 public boolean isNodeType(String type) throws RepositoryException {
452 return getNode().isNodeType(type);
453 }
454
455
456
457
458 public Lock lock(boolean arg0, boolean arg1) throws UnsupportedRepositoryOperationException,
459 LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
460 throw new UnsupportedRepositoryOperationException("Unsupported this method");
461 }
462
463
464
465
466 public NodeIterator merge(String arg0, boolean arg1) throws NoSuchWorkspaceException,
467 AccessDeniedException, MergeException, LockException, InvalidItemStateException,
468 RepositoryException {
469 throw new RepositoryException("Unsupported this method");
470 }
471
472
473
474
475 public void orderBefore(String arg0, String arg1)
476 throws UnsupportedRepositoryOperationException, VersionException,
477 ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
478 getNode().orderBefore(arg0, arg1);
479 }
480
481
482
483
484 public void removeMixin(String arg0) throws NoSuchNodeTypeException, VersionException,
485 ConstraintViolationException, LockException, RepositoryException {
486 throw new RepositoryException("Unsupported this method");
487 }
488
489
490
491
492 public void restore(String arg0, boolean arg1) throws VersionException, ItemExistsException,
493 UnsupportedRepositoryOperationException, LockException, InvalidItemStateException,
494 RepositoryException {
495 throw new RepositoryException("Unsupported this method");
496 }
497
498
499
500
501 public void restore(Version arg0, boolean arg1) throws VersionException, ItemExistsException,
502 UnsupportedRepositoryOperationException, LockException, RepositoryException {
503 throw new RepositoryException("Unsupported this method");
504 }
505
506
507
508
509 public void restore(Version arg0, String arg1, boolean arg2) throws PathNotFoundException,
510 ItemExistsException, VersionException, ConstraintViolationException,
511 UnsupportedRepositoryOperationException, LockException, InvalidItemStateException,
512 RepositoryException {
513 throw new RepositoryException("Unsupported this method");
514 }
515
516
517
518
519 public void restoreByLabel(String arg0, boolean arg1) throws VersionException,
520 ItemExistsException, UnsupportedRepositoryOperationException, LockException,
521 InvalidItemStateException, RepositoryException {
522 throw new RepositoryException("Unsupported this method");
523 }
524
525
526
527
528 public Property setProperty(String arg0, Value arg1) throws ValueFormatException,
529 VersionException, LockException, ConstraintViolationException, RepositoryException {
530 throw new RepositoryException("Unsupported this method");
531 }
532
533
534
535
536 public Property setProperty(String arg0, Value[] arg1) throws ValueFormatException,
537 VersionException, LockException, ConstraintViolationException, RepositoryException {
538 throw new RepositoryException("Unsupported this method");
539 }
540
541
542
543
544 public Property setProperty(String arg0, String[] arg1) throws ValueFormatException,
545 VersionException, LockException, ConstraintViolationException, RepositoryException {
546 throw new RepositoryException("Unsupported this method");
547 }
548
549
550
551
552 public Property setProperty(String arg0, String arg1) throws ValueFormatException,
553 VersionException, LockException, ConstraintViolationException, RepositoryException {
554 throw new RepositoryException("Unsupported this method");
555 }
556
557
558
559
560 public Property setProperty(String arg0, InputStream arg1) throws ValueFormatException,
561 VersionException, LockException, ConstraintViolationException, RepositoryException {
562 throw new RepositoryException("Unsupported this method");
563 }
564
565
566
567
568 public Property setProperty(String arg0, boolean arg1) throws ValueFormatException,
569 VersionException, LockException, ConstraintViolationException, RepositoryException {
570 throw new RepositoryException("Unsupported this method");
571 }
572
573
574
575
576 public Property setProperty(String arg0, double arg1) throws ValueFormatException,
577 VersionException, LockException, ConstraintViolationException, RepositoryException {
578 throw new RepositoryException("Unsupported this method");
579 }
580
581
582
583
584 public Property setProperty(String arg0, long arg1) throws ValueFormatException,
585 VersionException, LockException, ConstraintViolationException, RepositoryException {
586 throw new RepositoryException("Unsupported this method");
587 }
588
589
590
591
592 public Property setProperty(String arg0, Calendar arg1) throws ValueFormatException,
593 VersionException, LockException, ConstraintViolationException, RepositoryException {
594 throw new RepositoryException("Unsupported this method");
595 }
596
597
598
599
600 public Property setProperty(String arg0, Node arg1) throws ValueFormatException,
601 VersionException, LockException, ConstraintViolationException, RepositoryException {
602 throw new RepositoryException("Unsupported this method");
603 }
604
605
606
607
608 public Property setProperty(String arg0, Value arg1, int arg2) throws ValueFormatException,
609 VersionException, LockException, ConstraintViolationException, RepositoryException {
610 throw new RepositoryException("Unsupported this method");
611 }
612
613
614
615
616 public Property setProperty(String arg0, Value[] arg1, int arg2) throws ValueFormatException,
617 VersionException, LockException, ConstraintViolationException, RepositoryException {
618 throw new RepositoryException("Unsupported this method");
619 }
620
621
622
623
624 public Property setProperty(String arg0, String[] arg1, int arg2) throws ValueFormatException,
625 VersionException, LockException, ConstraintViolationException, RepositoryException {
626 throw new RepositoryException("Unsupported this method");
627 }
628
629
630
631
632 public Property setProperty(String arg0, String arg1, int arg2) throws ValueFormatException,
633 VersionException, LockException, ConstraintViolationException, RepositoryException {
634 throw new RepositoryException("Unsupported this method");
635 }
636
637
638
639
640 public void unlock() throws UnsupportedRepositoryOperationException, LockException,
641 AccessDeniedException, InvalidItemStateException, RepositoryException {
642 throw new RepositoryException("Unsupported this method");
643 }
644
645
646
647
648 public void update(String arg0) throws NoSuchWorkspaceException, AccessDeniedException,
649 LockException, InvalidItemStateException, RepositoryException {
650 throw new RepositoryException("Unsupported this method");
651 }
652
653
654
655
656 public void accept(ItemVisitor arg0) throws RepositoryException {
657 getNode().accept(arg0);
658 }
659
660
661
662
663 public Item getAncestor(int arg0) throws ItemNotFoundException, AccessDeniedException,
664 RepositoryException {
665 return getNode().getAncestor(arg0);
666 }
667
668
669
670
671 public int getDepth() throws RepositoryException {
672 return getNode().getDepth();
673 }
674
675
676
677
678 public String getName() throws RepositoryException {
679 return getNode().getName();
680 }
681
682
683
684
685 public boolean isModified() {
686 return getNode().isModified();
687 }
688
689
690
691
692 public boolean isNew() {
693 return getNode().isNew();
694 }
695
696
697
698
699 public boolean isNode() {
700 return getNode().isNode();
701 }
702
703
704
705
706 public boolean isSame(Item arg0) throws RepositoryException {
707 return getNode().isSame(arg0);
708 }
709
710
711
712
713 public void refresh(boolean arg0) throws InvalidItemStateException, RepositoryException {
714 getNode().refresh(arg0);
715 }
716
717
718
719
720 public void remove() throws VersionException, LockException, ConstraintViolationException,
721 RepositoryException {
722 throw new RepositoryException("Unsupported this method");
723 }
724
725
726
727
728 public void save() throws AccessDeniedException, ItemExistsException,
729 ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException,
730 VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
731 throw new RepositoryException("Unsupported this method");
732 }
733
734
735
736
737 public Property getProperty(String arg0) throws PathNotFoundException, RepositoryException {
738 return getNode().getProperty(arg0);
739 }
740
741
742
743
744 public Node getParent() throws ItemNotFoundException, AccessDeniedException,
745 RepositoryException {
746 return getNode().getParent();
747 }
748
749
750
751
752 public String getPath() throws RepositoryException {
753 return getNode().getPath();
754 }
755
756
757
758
759 public Session getSession() throws RepositoryException {
760 return getNode().getSession();
761 }
762
763
764
765
766 @Override
767 public boolean equals(Object obj) {
768 try {
769 ResultNode resNode = (ResultNode)obj;
770 if(getNode().getPath().equals(resNode.getNode().getPath())) return true;
771 } catch(Exception e) {
772 return false;
773 }
774 return false;
775 }
776
777 @Override
778 public int hashCode() {
779 return nodeLocation.hashCode();
780 }
781 }