]>
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 node
.setProperty(CMS_CONTENT
, raw
);
24 throw new CmsException("Don't know how to interpret "
28 Property property
= (Property
) item
;
29 property
.setValue(content
);
31 item
.getSession().save();
32 } catch (RepositoryException e
) {
33 throw new CmsException("Cannot set content on " + item
, e
);
38 public String
read(Item item
) {
40 String raw
= raw(item
);
41 return convertFromStorage(item
, raw
);
42 } catch (RepositoryException e
) {
43 throw new CmsException("Cannot get " + item
+ " for edit", e
);
48 public String
raw(Item item
) {
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
);
73 protected String
convertToStorage(Item item
, String content
)
74 throws RepositoryException
{
79 protected String
convertFromStorage(Item item
, String content
)
80 throws RepositoryException
{