]>
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 "
27 Property property
= (Property
) item
;
28 property
.setValue(content
);
30 // item.getSession().save();
31 } catch (RepositoryException e
) {
32 throw new CmsException("Cannot set content on " + item
, e
);
37 public String
read(Item item
) {
39 String raw
= raw(item
);
40 return convertFromStorage(item
, raw
);
41 } catch (RepositoryException e
) {
42 throw new CmsException("Cannot get " + item
+ " for edit", e
);
47 public String
raw(Item item
) {
49 item
.getSession().refresh(true);
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();
59 return node
.getProperty(CMS_CONTENT
).getString();
61 throw new CmsException("Don't know how to interpret "
65 Property property
= (Property
) item
;
66 return property
.getString();
68 } catch (RepositoryException e
) {
69 throw new CmsException("Cannot get " + item
+ " content", e
);
75 * To be overridden, in order to make sure that only valid strings are being
78 protected void validateBeforeStoring(String raw
) {
81 /** To be overridden, in order to support additional formatting. */
82 protected String
convertToStorage(Item item
, String content
)
83 throws RepositoryException
{
88 /** To be overridden, in order to support additional formatting. */
89 protected String
convertFromStorage(Item item
, String content
)
90 throws RepositoryException
{