1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.admininterface;
35
36 import info.magnolia.cms.beans.runtime.Document;
37 import info.magnolia.cms.beans.runtime.FileProperties;
38 import info.magnolia.cms.beans.runtime.MultipartForm;
39 import info.magnolia.cms.core.Content;
40 import info.magnolia.cms.core.HierarchyManager;
41 import info.magnolia.cms.core.ItemType;
42 import info.magnolia.cms.core.NodeData;
43 import info.magnolia.cms.core.Path;
44 import info.magnolia.cms.gui.control.ControlImpl;
45 import info.magnolia.cms.gui.control.File;
46 import info.magnolia.cms.gui.fckeditor.FCKEditorTmpFiles;
47 import info.magnolia.cms.security.AccessDeniedException;
48 import info.magnolia.cms.security.Digester;
49 import info.magnolia.cms.util.ContentUtil;
50 import info.magnolia.cms.util.DateUtil;
51 import info.magnolia.cms.util.ExclusiveWrite;
52 import info.magnolia.cms.util.NodeDataUtil;
53 import info.magnolia.context.MgnlContext;
54 import info.magnolia.link.LinkUtil;
55 import info.magnolia.objectfactory.Classes;
56 import info.magnolia.objectfactory.Components;
57 import info.magnolia.objectfactory.MgnlInstantiationException;
58 import info.magnolia.repository.RepositoryConstants;
59
60 import java.io.FileInputStream;
61 import java.io.FileNotFoundException;
62 import java.io.IOException;
63 import java.io.InputStream;
64 import java.util.ArrayList;
65 import java.util.Calendar;
66 import java.util.GregorianCalendar;
67 import java.util.Iterator;
68 import java.util.List;
69 import java.util.Map;
70 import java.util.TimeZone;
71 import java.util.regex.Matcher;
72 import java.util.regex.Pattern;
73
74 import javax.jcr.Node;
75 import javax.jcr.PathNotFoundException;
76 import javax.jcr.PropertyType;
77 import javax.jcr.RepositoryException;
78 import javax.jcr.Value;
79 import javax.jcr.ValueFactory;
80
81 import org.apache.commons.codec.binary.Base64;
82 import org.apache.commons.io.FileUtils;
83 import org.apache.commons.io.IOUtils;
84 import org.apache.commons.lang.StringUtils;
85 import org.devlib.schmidt.imageinfo.ImageInfo;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 public class SaveHandlerImpl implements SaveHandler {
127
128
129
130
131 public static Logger log = LoggerFactory.getLogger(SaveHandlerImpl.class);
132
133
134
135
136 private MultipartForm form;
137
138
139
140
141 private boolean create;
142
143 private ItemType creationItemType = ItemType.CONTENTNODE;
144 private ItemType collectionNodeCreationItemType = ItemType.CONTENTNODE;
145
146
147
148
149 private String repository = RepositoryConstants.WEBSITE;
150
151
152
153
154 private String path;
155
156
157
158
159 private String nodeCollectionName;
160
161
162
163
164 private String nodeName;
165
166
167
168
169 private String paragraph;
170
171
172
173
174 public SaveHandlerImpl() {
175 }
176
177
178
179
180
181 @Override
182 public void init(MultipartForm form) {
183 this.setForm(form);
184 }
185
186
187
188
189 @Override
190 public boolean save() {
191
192 String[] saveInfos = getForm().getParameterValues("mgnlSaveInfo");
193
194 if (saveInfos == null) {
195 log.info("Nothing to save, mgnlSaveInfo parameter not found.");
196 return true;
197 }
198
199 synchronized (ExclusiveWrite.getInstance()) {
200
201 String path = this.getPath();
202
203 HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository());
204 try {
205
206 Content page = this.getPageNode(hm);
207
208 if (page == null) {
209
210 return false;
211 }
212
213 Content node = this.getSaveNode(hm, page);
214
215
216 this.setNodeName(node.getName());
217 if (StringUtils.isEmpty(node.getMetaData().getTemplate())) {
218 node.getMetaData().setTemplate(this.getParagraph());
219 }
220
221
222 for (int i = 0; i < saveInfos.length; i++) {
223 String saveInfo = saveInfos[i];
224 processSaveInfo(node, saveInfo);
225 }
226
227
228 try {
229 MultipartForm form = getForm();
230 Map docs = form.getDocuments();
231 Iterator iter = docs.keySet().iterator();
232 while (iter.hasNext()) {
233 form.getDocument((String) iter.next()).delete();
234 }
235 }
236 catch (Exception e) {
237 log.error("Could not delete temp documents from form");
238 }
239
240 log.debug("Saving {}", path);
241
242
243 node.updateMetaData();
244
245
246
247 if (this.getRepository().equals(RepositoryConstants.WEBSITE)) {
248 while (node.getItemType().equals(ItemType.CONTENTNODE)) {
249 node = node.getParent();
250 node.updateMetaData();
251 }
252 }
253
254 hm.save();
255 }
256 catch (RepositoryException re) {
257 log.error(re.getMessage(), re);
258 return false;
259 }
260 }
261 return true;
262 }
263
264
265
266
267
268
269
270
271
272 protected void processSaveInfo(Content node, String saveInfo) throws PathNotFoundException, RepositoryException,
273 AccessDeniedException {
274
275 String name;
276 int type = PropertyType.STRING;
277 int valueType = ControlImpl.VALUETYPE_SINGLE;
278 int isRichEditValue = 0;
279 int encoding = ControlImpl.ENCRYPTION_NO;
280 String[] values = {StringUtils.EMPTY};
281 if (StringUtils.contains(saveInfo, ',')) {
282 String[] info = StringUtils.split(saveInfo, ',');
283 name = info[0];
284 if (info.length >= 2) {
285 type = PropertyType.valueFromName(info[1]);
286 }
287 if (info.length >= 3) {
288 valueType = Integer.valueOf(info[2]).intValue();
289 }
290 if (info.length >= 4) {
291 isRichEditValue = Integer.valueOf(info[3]).intValue();
292 }
293 if (info.length >= 5) {
294 encoding = Integer.valueOf(info[4]).intValue();
295 }
296 }
297 else {
298 name = saveInfo;
299 }
300
301
302 String customSaveHandler = this.getForm().getParameter(name + "_saveHandler");
303 if (!StringUtils.isEmpty(customSaveHandler)) {
304 try {
305 Class cshClazz = Classes.getClassFactory().forName(customSaveHandler);
306 if (!FieldSaveHandler.class.isAssignableFrom(cshClazz)) {
307 log.error("Class {} must implement the FieldSaveHandler interface", cshClazz);
308 throw new ClassCastException("Class " + cshClazz + " must implement the FieldSaveHandler interface");
309 }
310 else {
311 FieldSaveHandler csh = (FieldSaveHandler)Components.newInstance(cshClazz);
312 HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(RepositoryConstants.CONFIG);
313
314 String configPath = this.getForm().getParameter(name + "_configNode");
315 Content configNode = null;
316 if (StringUtils.isNotEmpty(configPath))
317 {
318 configNode = hm.getContent(configPath);
319 }
320
321 csh.save(
322 node,
323 configNode,
324 name,
325 getForm(),
326 type,
327 valueType,
328 isRichEditValue,
329 encoding);
330 }
331 }
332 catch (ClassNotFoundException e) {
333 log.error("Error loading class " + customSaveHandler, e);
334 }
335 catch (MgnlInstantiationException e) {
336 log.error("Error creating instance of class " + customSaveHandler, e);
337 }
338 }
339 else
340
341
342 if (type == PropertyType.BINARY) {
343 processBinary(node, name);
344 }
345 else {
346 values = getForm().getParameterValues(name);
347 if (valueType == ControlImpl.VALUETYPE_MULTIPLE) {
348 processMultiple(node, name, type, values);
349 }
350 else if (isRichEditValue != ControlImpl.RICHEDIT_NONE) {
351 processRichEdit(node, name, type, isRichEditValue, encoding, values);
352 }
353 else if (type == PropertyType.DATE) {
354 processDate(node, name, type, valueType, encoding, values);
355 }
356 else {
357 processCommon(node, name, type, valueType, encoding, values);
358 }
359 }
360 }
361
362 protected void processDate(Content node, String name, int type, int valueType, int encoding, String[] values) {
363 try {
364 if (StringUtils.isEmpty(values[0])) {
365 log.debug("Date has no value. Deleting node data {}", name);
366 if (node.hasNodeData(name)) {
367 node.deleteNodeData(name);
368 }
369 }
370 else {
371 Calendar utc = DateUtil.getUTCCalendarFromDialogString(values[0]);
372 NodeDataUtil.getOrCreate(node, name).setValue(utc);
373 }
374 }
375 catch (Exception e) {
376 log.error("Could not update date value of node:" + node.getHandle() + " of property:" + name, e);
377 }
378 }
379
380
381
382
383
384
385
386
387
388
389
390
391
392 protected void processRichEdit(Content node, String name, int type, int isRichEditValue, int encoding,
393 String[] values) throws PathNotFoundException, RepositoryException, AccessDeniedException {
394 String valueStr = StringUtils.EMPTY;
395 if (values != null) {
396 valueStr = values[0];
397 }
398
399 valueStr = cleanLineBreaks(valueStr, isRichEditValue);
400
401 if (isRichEditValue == ControlImpl.RICHEDIT_FCK) {
402
403 valueStr = valueStr.replaceAll("<span scaytid=\"\\d*\" scayt_word=\".*?\">(.*?)</span>", "$1");
404 valueStr = updateLinks(node, name, valueStr);
405 }
406
407 processString(node, name, type, encoding, values, valueStr);
408 }
409
410
411
412
413
414
415
416
417
418 protected String cleanLineBreaks(String valueStr, int isRichEditValue) {
419 valueStr = StringUtils.replace(valueStr, "\r\n", " ");
420 valueStr = StringUtils.replace(valueStr, "\n", " ");
421
422
423 valueStr = StringUtils.replace(valueStr, "</br>", StringUtils.EMPTY);
424 valueStr = StringUtils.replace(valueStr, "<br>", "<br/>");
425 valueStr = StringUtils.replace(valueStr, "<BR>", "<br />");
426 valueStr = StringUtils.replace(valueStr, "<br/>", "<br />");
427 valueStr = StringUtils.replace(valueStr, "<P><br />", "<P>");
428
429
430 if (isRichEditValue != ControlImpl.RICHEDIT_FCK) {
431 valueStr = replacePByBr(valueStr, "p");
432 }
433 return valueStr;
434 }
435
436
437
438
439
440
441
442
443
444
445
446
447 protected String updateLinks(Content node, String name, String valueStr) throws AccessDeniedException,
448 RepositoryException, PathNotFoundException {
449
450
451 HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository());
452
453 Pattern imageOrDowloadPattern = Pattern.compile("(<(a|img|embed)[^>]+(href|src)[ ]*=[ ]*\")([^\"]*)(\"[^>]*>)");
454 Pattern tmpFilePattern = Pattern.compile("/tmp/fckeditor/([^/]*)/[^\"]*");
455
456 Content filesNode = ContentUtil.getOrCreateContent(node, name + "_files", ItemType.CONTENTNODE);
457
458
459 List usedFiles = new ArrayList();
460
461
462 Matcher imageOrDowloadMatcher = imageOrDowloadPattern.matcher(valueStr);
463 StringBuffer res = new StringBuffer();
464 while (imageOrDowloadMatcher.find()) {
465 String src = imageOrDowloadMatcher.group(4);
466
467 String link = StringUtils.removeStart(src, MgnlContext.getContextPath());
468
469
470 Matcher tmpFileMatcher = tmpFilePattern.matcher(src);
471
472 if (tmpFileMatcher.find()) {
473 String uuid = tmpFileMatcher.group(1);
474
475 Document doc = FCKEditorTmpFiles.getDocument(uuid);
476 String fileNodeName = Path.getUniqueLabel(hm, filesNode.getHandle(), "file");
477 SaveHandlerImpl.saveDocument(filesNode, doc, fileNodeName, "", "");
478 link = filesNode.getHandle() + "/" + fileNodeName + "/" + doc.getFileNameWithExtension();
479 doc.delete();
480 try {
481 FileUtils.deleteDirectory(new java.io.File(Path.getTempDirectory() + "/fckeditor/" + uuid));
482 }
483 catch (IOException e) {
484 log.error("can't delete tmp file [" + Path.getTempDirectory() + "/fckeditor/" + uuid + "]");
485 }
486 }
487
488
489 link = StringUtils.replace(link, "$", "\\$");
490
491 imageOrDowloadMatcher.appendReplacement(res, "$1" + link + "$5");
492 if (link.startsWith(filesNode.getHandle())) {
493 String fileNodeName = StringUtils.removeStart(link, filesNode.getHandle() + "/");
494 fileNodeName = StringUtils.substringBefore(fileNodeName, "/");
495 usedFiles.add(fileNodeName);
496 }
497 }
498
499
500 for (Iterator iter = filesNode.getNodeDataCollection().iterator(); iter.hasNext();) {
501 NodeData fileNodeData = (NodeData) iter.next();
502 if (!usedFiles.contains(fileNodeData.getName())) {
503 fileNodeData.delete();
504 }
505 }
506
507 imageOrDowloadMatcher.appendTail(res);
508 valueStr = res.toString();
509
510
511 valueStr = LinkUtil.convertAbsoluteLinksToUUIDs(valueStr);
512
513 return valueStr;
514 }
515
516
517
518
519
520
521
522
523
524
525
526
527
528 protected void processCommon(Content node, String name, int type, int valueType, int encoding, String[] values)
529 throws PathNotFoundException, RepositoryException, AccessDeniedException {
530 String valueStr = StringUtils.EMPTY;
531 if (values != null) {
532 valueStr = values[0];
533 }
534
535 processString(node, name, type, encoding, values, valueStr);
536 }
537
538
539
540
541
542
543
544
545
546
547
548
549
550 protected void processString(Content node, String name, int type, int encoding, String[] values, String valueStr)
551 throws PathNotFoundException, RepositoryException, AccessDeniedException {
552
553 boolean remove = false;
554 boolean write = false;
555 if (encoding == ControlImpl.ENCRYPTION_NO_ENCODING_BASE64) {
556 if (StringUtils.isNotBlank(valueStr)) {
557 valueStr = new String(Base64.encodeBase64(valueStr.getBytes()));
558 write = true;
559 }
560 } else if (encoding == ControlImpl.ENCRYPTION_HASH_SHA) {
561 if (StringUtils.isNotEmpty(valueStr)) {
562 valueStr = Digester.getSHA1Hex(valueStr);
563 write = true;
564 }
565 } else if (encoding == ControlImpl.ENCRYPTION_HASH_BCRYPT) {
566 if (StringUtils.isNotEmpty(valueStr)) {
567 valueStr = Digester.getBCrypt(valueStr);
568 write = true;
569 }
570 } else {
571
572 if (values == null || StringUtils.isEmpty(valueStr)) {
573 remove = true;
574 } else {
575 write = true;
576 }
577 }
578 if (remove) {
579 processRemoveCommon(node, name);
580 }
581 else if (write) {
582 processWriteCommon(node, name, valueStr, type);
583 }
584 }
585
586
587
588
589 protected void processRemoveCommon(Content node, String name) throws PathNotFoundException, RepositoryException {
590 NodeData data = node.getNodeData(name);
591
592 if (data.isExist()) {
593 node.deleteNodeData(name);
594 }
595 }
596
597
598
599
600
601
602
603
604
605 protected void processWriteCommon(Content node, String name, String valueStr, int type)
606 throws AccessDeniedException, RepositoryException {
607 Value value = this.getValue(valueStr, type);
608 if (null != value) {
609 NodeData data = NodeDataUtil.getOrCreate(node, name);
610 data.setValue(value);
611 }
612 }
613
614
615
616
617
618
619
620
621
622
623
624 protected void processMultiple(Content node, String name, int type, String[] values) throws RepositoryException,
625 PathNotFoundException, AccessDeniedException {
626
627 try {
628 node.delete(name);
629 }
630 catch (PathNotFoundException e) {
631 if (log.isDebugEnabled()) {
632 log.debug("Exception caught: " + e.getMessage(), e);
633 }
634 }
635 if (values != null && values.length != 0) {
636 Content multiNode = node.createContent(name, ItemType.CONTENTNODE);
637 try {
638
639 multiNode.deleteNodeData("creationdate");
640 }
641 catch (RepositoryException re) {
642 if (log.isDebugEnabled()) {
643 log.debug("Exception caught: " + re.getMessage(), re);
644 }
645 }
646 for (int j = 0; j < values.length; j++) {
647 String valueStr = values[j];
648 if (StringUtils.isNotEmpty(valueStr)) {
649 Value value = this.getValue(valueStr, type);
650 multiNode.createNodeData(Integer.toString(j)).setValue(value);
651 }
652 }
653 }
654 }
655
656
657
658
659
660
661
662
663
664 protected void processBinary(Content node, String name) throws PathNotFoundException, RepositoryException,
665 AccessDeniedException {
666 Document doc = getForm().getDocument(name);
667 if (doc == null && getForm().getParameter(name + "_" + File.REMOVE) != null) {
668 try {
669 node.deleteNodeData(name);
670 }
671 catch (RepositoryException re) {
672 if (log.isDebugEnabled()) {
673 log.debug("Exception caught: " + re.getMessage(), re);
674 }
675 }
676 }
677 else {
678 String fileName = getForm().getParameter(name + "_" + FileProperties.PROPERTY_FILENAME);
679 String template = getForm().getParameter(name + "_" + FileProperties.PROPERTY_TEMPLATE);
680
681 SaveHandlerImpl.saveDocument(node, doc, name, fileName, template);
682 }
683 }
684
685
686
687
688
689
690 public Value getValue(String s) {
691 return this.getValue(s, PropertyType.STRING);
692 }
693
694
695
696
697
698
699 public Value getValue(long l) {
700 HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository());
701 ValueFactory valueFactory;
702 try {
703 valueFactory = hm.getWorkspace().getSession().getValueFactory();
704 }
705 catch (RepositoryException e) {
706 throw new RuntimeException(e);
707 }
708 return valueFactory.createValue(l);
709 }
710
711
712
713
714
715
716
717 public Value getValue(String valueStr, int type) {
718
719 ValueFactory valueFactory = null;
720
721 HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository());
722 try {
723 valueFactory = hm.getWorkspace().getSession().getValueFactory();
724 }
725 catch (RepositoryException e) {
726 throw new RuntimeException(e);
727 }
728
729 Value value = null;
730
731 if (type == PropertyType.REFERENCE) {
732 try {
733 Node referencedNode = hm.getWorkspace().getSession().getNodeByUUID(valueStr);
734
735 value = valueFactory.createValue(referencedNode);
736 }
737 catch (RepositoryException re) {
738 if (log.isDebugEnabled()) {
739 log.debug("Cannot retrieve the referenced node by UUID: " + valueStr, re);
740 }
741 }
742 }
743 else {
744 value = NodeDataUtil.createValue(valueStr, type, valueFactory);
745 }
746
747 return value;
748 }
749
750
751
752
753
754 protected static String replacePByBr(final String value, String tagName) {
755
756 if (StringUtils.isBlank(value)) {
757 return value;
758 }
759
760 String fixedValue = value;
761
762 String pre = "<" + tagName + ">";
763 String post = "</" + tagName + ">";
764
765
766 if (fixedValue.endsWith(post)) {
767 fixedValue = StringUtils.substringBeforeLast(fixedValue, post);
768 }
769
770 fixedValue = StringUtils.replace(fixedValue, pre + " " + post, "\n ");
771 fixedValue = StringUtils.replace(fixedValue, pre, StringUtils.EMPTY);
772 fixedValue = StringUtils.replace(fixedValue, post, "\n\n ");
773
774 if (!tagName.equals(tagName.toUpperCase())) {
775 fixedValue = replacePByBr(fixedValue, tagName.toUpperCase());
776 }
777 return fixedValue;
778 }
779
780
781
782
783 @Override
784 public boolean isCreate() {
785 return create;
786 }
787
788
789
790
791 @Override
792 public void setCreate(boolean create) {
793 this.create = create;
794 }
795
796
797
798
799 @Override
800 public ItemType getCreationItemType() {
801 return creationItemType;
802 }
803
804
805
806
807 @Override
808 public void setCreationItemType(ItemType creationItemType) {
809 this.creationItemType = creationItemType;
810 }
811
812 @Override
813 public ItemType getCollectionNodeCreationItemType() {
814 return collectionNodeCreationItemType;
815 }
816
817 @Override
818 public void setCollectionNodeCreationItemType(ItemType collectionNodeCreationItemType) {
819 this.collectionNodeCreationItemType = collectionNodeCreationItemType;
820 }
821
822
823
824
825 protected MultipartForm getForm() {
826 return form;
827 }
828
829
830
831
832
833 protected void setForm(MultipartForm form) {
834 this.form = form;
835 }
836
837
838
839
840
841 @Override
842 public void setRepository(String repository) {
843 this.repository = repository;
844 }
845
846
847
848
849
850 @Override
851 public String getRepository() {
852 return repository;
853 }
854
855
856
857
858
859
860
861
862
863 protected Content getPageNode(HierarchyManager hm) throws RepositoryException, AccessDeniedException,
864 PathNotFoundException {
865 Content page = null;
866 String path = this.getPath();
867 try {
868 page = hm.getContent(path);
869 }
870 catch (RepositoryException e) {
871 if (this.isCreate()) {
872 String parentPath = StringUtils.substringBeforeLast(path, "/");
873 String label = StringUtils.substringAfterLast(path, "/");
874 if (StringUtils.isEmpty(parentPath)) {
875 page = hm.getRoot();
876 }
877 else {
878 page = hm.getContent(parentPath);
879 }
880 page = page.createContent(label, this.getCreationItemType());
881 }
882 else {
883 log.error("Tried to save a not existing node with path {}. use create = true to force creation", path);
884 }
885 }
886
887 return page;
888 }
889
890
891
892
893
894
895
896
897
898
899 protected Content getSaveNode(HierarchyManager hm, Content rootNode) throws AccessDeniedException,
900 RepositoryException {
901 Content node = null;
902
903
904 Content nodeCollection = null;
905 if (StringUtils.isNotEmpty(this.getNodeCollectionName())) {
906 try {
907 nodeCollection = rootNode.getContent(this.getNodeCollectionName());
908 }
909 catch (RepositoryException re) {
910
911 nodeCollection = rootNode.createContent(this.getNodeCollectionName(), this.getCollectionNodeCreationItemType());
912 log.debug("Create - {}" + nodeCollection.getHandle());
913 }
914 }
915 else {
916 nodeCollection = rootNode;
917 }
918
919
920 if (StringUtils.isNotEmpty(this.getNodeName())) {
921 try {
922 node = nodeCollection.getContent(this.getNodeName());
923 }
924 catch (RepositoryException re) {
925
926 if (this.getNodeName().equals("mgnlNew")) {
927 this.setNodeName(Path.getUniqueLabel(hm, nodeCollection.getHandle(), "0"));
928 }
929 node = nodeCollection.createContent(this.getNodeName(), this.getCreationItemType());
930 }
931 }
932 else {
933 node = nodeCollection;
934 }
935 return node;
936 }
937
938
939
940
941
942
943
944
945
946
947
948
949 public static void saveDocument(Content node, Document doc, String name, String fileName, String template)
950 throws PathNotFoundException, RepositoryException, AccessDeniedException {
951
952 NodeData data = node.getNodeData(name);
953 if (doc != null) {
954 if (!data.isExist()) {
955 data = node.createNodeData(name, PropertyType.BINARY);
956
957 log.debug("creating under - {}", node.getHandle());
958 log.debug("creating node data for binary store - {}", name);
959
960 }
961 data.setValue(doc.getStream());
962 log.debug("Node data updated");
963 }
964 if (data != null) {
965 if (fileName == null || fileName.equals(StringUtils.EMPTY)) {
966 fileName = doc.getFileName();
967 }
968 data.setAttribute(FileProperties.PROPERTY_FILENAME, fileName);
969 if (doc != null) {
970 data.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, doc.getType());
971
972 Calendar value = new GregorianCalendar(TimeZone.getDefault());
973 data.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, value);
974
975 data.setAttribute(FileProperties.PROPERTY_SIZE, Long.toString(doc.getLength()));
976
977 data.setAttribute(FileProperties.PROPERTY_EXTENSION, doc.getExtension());
978
979 data.setAttribute(FileProperties.PROPERTY_TEMPLATE, template);
980
981 InputStream raf = null;
982 try {
983 ImageInfo ii = new ImageInfo();
984 raf = new FileInputStream(doc.getFile());
985 ii.setInput(raf);
986 if (ii.check()) {
987 data.setAttribute(FileProperties.PROPERTY_WIDTH, Long.toString(ii.getWidth()));
988 data.setAttribute(FileProperties.PROPERTY_HEIGHT, Long.toString(ii.getHeight()));
989
990 }
991 }
992 catch (FileNotFoundException e) {
993 log.error("FileNotFoundException caught when parsing {}, image data will not be available", doc
994 .getFile()
995 .getAbsolutePath());
996 }
997 finally {
998 IOUtils.closeQuietly(raf);
999 }
1000
1001
1002
1003
1004
1005 }
1006 }
1007
1008 }
1009
1010
1011
1012
1013 @Override
1014 public String getNodeCollectionName() {
1015 return this.nodeCollectionName;
1016 }
1017
1018
1019
1020
1021 @Override
1022 public void setNodeCollectionName(String nodeCollectionName) {
1023 this.nodeCollectionName = nodeCollectionName;
1024 }
1025
1026
1027
1028
1029 @Override
1030 public String getNodeName() {
1031 return this.nodeName;
1032 }
1033
1034
1035
1036
1037 @Override
1038 public void setNodeName(String nodeName) {
1039 this.nodeName = nodeName;
1040 }
1041
1042
1043
1044
1045 @Override
1046 public String getParagraph() {
1047 return this.paragraph;
1048 }
1049
1050
1051
1052
1053 @Override
1054 public void setParagraph(String paragraph) {
1055 this.paragraph = paragraph;
1056 }
1057
1058
1059
1060
1061 @Override
1062 public String getPath() {
1063 return this.path;
1064 }
1065
1066
1067
1068
1069 @Override
1070 public void setPath(String path) {
1071 this.path = path;
1072 }
1073
1074 }