validateBeforeStoring(raw);
node.setProperty(CMS_CONTENT, raw);
} else {
- throw new CmsException("Don't know how to interpret "
- + node);
+ throw new CmsException("Don't know how to interpret " + node);
}
} else {// property
Property property = (Property) item;
}
}
+ @Override
+ public String readSimpleHtml(Item item) {
+ return raw(item);
+ }
+
@Override
public String read(Item item) {
try {
return node.getProperty(CMS_CONTENT).getString();
} else {
- throw new CmsException("Don't know how to interpret "
- + node);
+ throw new CmsException("Don't know how to interpret " + node);
}
} else {// property
Property property = (Property) item;
}
/** To be overridden, in order to support additional formatting. */
- protected String convertToStorage(Item item, String content)
- throws RepositoryException {
+ protected String convertToStorage(Item item, String content) throws RepositoryException {
return content;
}
/** To be overridden, in order to support additional formatting. */
- protected String convertFromStorage(Item item, String content)
- throws RepositoryException {
+ protected String convertFromStorage(Item item, String content) throws RepositoryException {
return content;
}
}
/** Convert from/to data layer to/from presentation layer. */
public interface TextInterpreter {
- public String raw(Item item);
+ String raw(Item item);
- public String read(Item item);
+ String read(Item item);
- public void write(Item item, String content);
+ String readSimpleHtml(Item item);
+
+ void write(Item item, String content);
}
* specific formatting and integration.
*/
class TextInterpreterImpl extends IdentityTextInterpreter {
- private MarkupValidatorCopy markupValidator = MarkupValidatorCopy
- .getInstance();
+ private MarkupValidatorCopy markupValidator = MarkupValidatorCopy.getInstance();
@Override
protected void validateBeforeStoring(String raw) {
}
@Override
- protected String convertToStorage(Item item, String content)
- throws RepositoryException {
+ protected String convertToStorage(Item item, String content) throws RepositoryException {
return super.convertToStorage(item, content);
}
@Override
- protected String convertFromStorage(Item item, String content)
- throws RepositoryException {
+ protected String convertFromStorage(Item item, String content) throws RepositoryException {
return super.convertFromStorage(item, content);
}
if (part instanceof EditableText) {
EditableText paragraph = (EditableText) part;
if (paragraph == getEdited())
- paragraph.setText(textInterpreter.read(partNode));
- else
paragraph.setText(textInterpreter.raw(partNode));
+ else
+ paragraph.setText(textInterpreter.readSimpleHtml(partNode));
} else if (part instanceof EditableImage) {
EditableImage editableImage = (EditableImage) part;
imageManager.load(partNode, part.getControl(), editableImage.getPreferredImageSize());
return;
String text = ((Text) et.getControl()).getText();
- String[] lines = text.split("[\r\n]+");
+ // String[] lines = text.split("[\r\n]+");
+ String[] lines = { text };
assert lines.length != 0;
saveLine(part, lines[0]);
if (lines.length > 1) {
// cancelEdit();
saveEdit();
} else if (ke.character == '\r') {
- splitEdit();
+ if (!shiftPressed)
+ splitEdit();
} else if (ke.character == 'z') {
if (ctrlPressed)
cancelEdit();
package org.argeo.docbook.ui;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
+import org.apache.commons.io.IOUtils;
import org.argeo.cms.text.TextInterpreter;
import org.argeo.jcr.Jcr;
import org.argeo.jcr.JcrException;
try {
if (item instanceof Node) {
Node node = (Node) item;
- if (node.isNodeType(DocBookTypes.PARA)||node.isNodeType(DocBookTypes.TITLE)) {
+ if (node.isNodeType(DocBookTypes.PARA) || node.isNodeType(DocBookTypes.TITLE)) {
String raw = convertToStorage(node, content);
validateBeforeStoring(raw);
Node jcrText;
item.getSession().refresh(true);
if (item instanceof Node) {
Node node = (Node) item;
- if (node.isNodeType(DocBookTypes.PARA)||node.isNodeType(DocBookTypes.TITLE)) {
+ if (node.isNodeType(DocBookTypes.PARA) || node.isNodeType(DocBookTypes.TITLE)) {
Node jcrText = node.getNode(Jcr.JCR_XMLTEXT);
String txt = jcrText.getProperty(Jcr.JCR_XMLCHARACTERS).getString();
// TODO make it more robust
- txt = txt.replace("\n", "").replace("\t", "");
+ // txt = txt.replace("\n", "").replace("\t", "");
+ txt = txt.replace("\t", " ");
return txt;
} else {
throw new IllegalArgumentException("Don't know how to interpret " + node);
}
}
+ final static int BR_LENGTH = "<br/>".length();
+
+ public String readSimpleHtml(Item item) {
+ String raw = raw(item);
+// raw = "<span style='text-align:justify'>" + raw + "</span>";
+ if (raw.length() == 0)
+ return raw;
+ try (StringReader reader = new StringReader(raw)) {
+ List<String> lines = IOUtils.readLines(reader);
+ if (lines.size() == 1)
+ return lines.get(0);
+ StringBuilder sb = new StringBuilder(raw.length() + lines.size() * BR_LENGTH);
+ for (int i = 0; i < lines.size(); i++) {
+ if (i != 0)
+ sb.append("<br/>");
+ sb.append(lines.get(i));
+ }
+ return sb.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+// String[] lines = raw.split("[\r\n]+");
+// if (lines.length == 1)
+// return lines[0];
+// StringBuilder sb = new StringBuilder(raw.length() + lines.length * BR_LENGTH);
+// for (int i = 0; i < lines.length; i++) {
+// if (i != 0)
+// sb.append("<br/>");
+// sb.append(lines[i]);
+// }
+// return sb.toString();
+ }
+
// EXTENSIBILITY
/**
* To be overridden, in order to make sure that only valid strings are being