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