]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/text/IdentityTextInterpreter.java
1 package org
.argeo
.cms
.text
;
5 import javax
.jcr
.Property
;
6 import javax
.jcr
.RepositoryException
;
8 import org
.argeo
.cms
.CmsException
;
9 import org
.argeo
.cms
.CmsNames
;
10 import org
.argeo
.cms
.CmsTypes
;
12 /** Based on HTML with a few Wiki-like shortcuts. */
13 public class IdentityTextInterpreter
implements TextInterpreter
, CmsNames
{
16 public void write(Item item
, String content
) {
18 if (item
instanceof Node
) {
19 Node node
= (Node
) item
;
20 if (node
.isNodeType(CmsTypes
.CMS_STYLED
)) {
21 String raw
= convertToStorage(node
, content
);
22 validateBeforeStoring(raw
);
23 node
.setProperty(CMS_CONTENT
, raw
);
25 throw new CmsException("Don't know how to interpret "
29 Property property
= (Property
) item
;
30 property
.setValue(content
);
32 // item.getSession().save();
33 } catch (RepositoryException e
) {
34 throw new CmsException("Cannot set content on " + item
, e
);
39 public String
read(Item item
) {
41 String raw
= raw(item
);
42 return convertFromStorage(item
, raw
);
43 } catch (RepositoryException e
) {
44 throw new CmsException("Cannot get " + item
+ " for edit", e
);
49 public String
raw(Item item
) {
51 item
.getSession().refresh(true);
52 if (item
instanceof Node
) {
53 Node node
= (Node
) item
;
54 if (node
.isNodeType(CmsTypes
.CMS_STYLED
)) {
55 // WORKAROUND FOR BROKEN PARARAPHS
56 if (!node
.hasProperty(CMS_CONTENT
)) {
57 node
.setProperty(CMS_CONTENT
, "");
58 node
.getSession().save();
61 return node
.getProperty(CMS_CONTENT
).getString();
63 throw new CmsException("Don't know how to interpret "
67 Property property
= (Property
) item
;
68 return property
.getString();
70 } catch (RepositoryException e
) {
71 throw new CmsException("Cannot get " + item
+ " content", e
);
77 * To be overridden, in order to make sure that only valid strings are being
80 protected void validateBeforeStoring(String raw
) {
83 /** To be overridden, in order to support additional formatting. */
84 protected String
convertToStorage(Item item
, String content
)
85 throws RepositoryException
{
90 /** To be overridden, in order to support additional formatting. */
91 protected String
convertFromStorage(Item item
, String content
)
92 throws RepositoryException
{