]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/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 if (item
instanceof Node
) {
52 Node node
= (Node
) item
;
53 if (node
.isNodeType(CmsTypes
.CMS_STYLED
)) {
54 // WORKAROUND FOR BROKEN PARARAPHS
55 if (!node
.hasProperty(CMS_CONTENT
)) {
56 node
.setProperty(CMS_CONTENT
, "");
57 node
.getSession().save();
60 return node
.getProperty(CMS_CONTENT
).getString();
62 throw new CmsException("Don't know how to interpret "
66 Property property
= (Property
) item
;
67 return property
.getString();
69 } catch (RepositoryException e
) {
70 throw new CmsException("Cannot get " + item
+ " content", e
);
76 * To be overridden, in order to make sure that only valid strings are being
79 protected void validateBeforeStoring(String raw
) {
82 /** To be overridden, in order to support additional formatting. */
83 protected String
convertToStorage(Item item
, String content
)
84 throws RepositoryException
{
89 /** To be overridden, in order to support additional formatting. */
90 protected String
convertFromStorage(Item item
, String content
)
91 throws RepositoryException
{