]>
git.argeo.org Git - gpl/argeo-suite.git/blob - publishing/org.argeo.publishing.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
;
10 /** Based on HTML with a few Wiki-like shortcuts. */
11 public class IdentityTextInterpreter
implements TextInterpreter
, CmsNames
{
14 public void write(Item item
, String content
) {
16 if (item
instanceof Node
) {
17 Node node
= (Node
) item
;
18 if (node
.isNodeType(CmsTypes
.CMS_STYLED
)) {
19 String raw
= convertToStorage(node
, content
);
20 validateBeforeStoring(raw
);
21 node
.setProperty(CMS_CONTENT
, raw
);
23 throw new CmsException("Don't know how to interpret " + node
);
26 Property property
= (Property
) item
;
27 property
.setValue(content
);
29 // item.getSession().save();
30 } catch (RepositoryException e
) {
31 throw new CmsException("Cannot set content on " + item
, e
);
36 public String
readSimpleHtml(Item item
) {
41 public String
read(Item item
) {
43 String raw
= raw(item
);
44 return convertFromStorage(item
, raw
);
45 } catch (RepositoryException e
) {
46 throw new CmsException("Cannot get " + item
+ " for edit", e
);
51 public String
raw(Item item
) {
53 item
.getSession().refresh(true);
54 if (item
instanceof Node
) {
55 Node node
= (Node
) item
;
56 if (node
.isNodeType(CmsTypes
.CMS_STYLED
)) {
57 // WORKAROUND FOR BROKEN PARARAPHS
58 if (!node
.hasProperty(CMS_CONTENT
)) {
59 node
.setProperty(CMS_CONTENT
, "");
60 node
.getSession().save();
63 return node
.getProperty(CMS_CONTENT
).getString();
65 throw new CmsException("Don't know how to interpret " + node
);
68 Property property
= (Property
) item
;
69 return property
.getString();
71 } catch (RepositoryException e
) {
72 throw new CmsException("Cannot get " + item
+ " content", e
);
78 * To be overridden, in order to make sure that only valid strings are being
81 protected void validateBeforeStoring(String raw
) {
84 /** To be overridden, in order to support additional formatting. */
85 protected String
convertToStorage(Item item
, String content
) throws RepositoryException
{
90 /** To be overridden, in order to support additional formatting. */
91 protected String
convertFromStorage(Item item
, String content
) throws RepositoryException
{