]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/text/IdentityTextInterpreter.java
Add LDAP to CMS target platform
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / text / IdentityTextInterpreter.java
1 package org.argeo.cms.text;
2
3 import javax.jcr.Item;
4 import javax.jcr.Node;
5 import javax.jcr.Property;
6 import javax.jcr.RepositoryException;
7
8 import org.argeo.cms.CmsException;
9 import org.argeo.cms.CmsNames;
10 import org.argeo.cms.CmsTypes;
11
12 /** Based on HTML with a few Wiki-like shortcuts. */
13 public class IdentityTextInterpreter implements TextInterpreter, CmsNames {
14
15 @Override
16 public void write(Item item, String content) {
17 try {
18 if (item instanceof Node) {
19 Node node = (Node) item;
20 if (node.isNodeType(CmsTypes.CMS_STYLED)) {
21 String raw = convertToStorage(node, content);
22 node.setProperty(CMS_CONTENT, raw);
23 } else {
24 throw new CmsException("Don't know how to interpret "
25 + node);
26 }
27 } else {// property
28 Property property = (Property) item;
29 property.setValue(content);
30 }
31 item.getSession().save();
32 } catch (RepositoryException e) {
33 throw new CmsException("Cannot set content on " + item, e);
34 }
35 }
36
37 @Override
38 public String read(Item item) {
39 try {
40 String raw = raw(item);
41 return convertFromStorage(item, raw);
42 } catch (RepositoryException e) {
43 throw new CmsException("Cannot get " + item + " for edit", e);
44 }
45 }
46
47 @Override
48 public String raw(Item item) {
49 try {
50 if (item instanceof Node) {
51 Node node = (Node) item;
52 if (node.isNodeType(CmsTypes.CMS_STYLED)) {
53 // WORKAROUND FOR BROKEN PARARAPHS
54 if (!node.hasProperty(CMS_CONTENT)) {
55 node.setProperty(CMS_CONTENT, "");
56 node.getSession().save();
57 }
58
59 return node.getProperty(CMS_CONTENT).getString();
60 } else {
61 throw new CmsException("Don't know how to interpret "
62 + node);
63 }
64 } else {// property
65 Property property = (Property) item;
66 return property.getString();
67 }
68 } catch (RepositoryException e) {
69 throw new CmsException("Cannot get " + item + " content", e);
70 }
71 }
72
73 protected String convertToStorage(Item item, String content)
74 throws RepositoryException {
75 return content;
76
77 }
78
79 protected String convertFromStorage(Item item, String content)
80 throws RepositoryException {
81 return content;
82 }
83 }