Improve DocBook support.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 17 Jan 2021 11:52:28 +0000 (12:52 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 17 Jan 2021 11:52:28 +0000 (12:52 +0100)
org.argeo.suite.core/src/org/argeo/suite/core/SuiteTermsManager.java
publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/Paragraph.java
publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextSection.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/CustomDbkEditor.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkTextInterpreter.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkUtils.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java [new file with mode: 0644]
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookTypes.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/docbook.cnd

index 3c5a59fa42c5425820340017bc0ece5b2ccab93d..1362f946abf61caf3b278d55e7da363772f98d19 100644 (file)
@@ -46,6 +46,8 @@ public class SuiteTermsManager implements TermsManager {
                if (t == null) {
                        Node termsNode = Jcr.getNode(adminSession, "SELECT * FROM [{0}] WHERE NAME()=\"{1}\"",
                                        EntityType.terms.get(), typology);
                if (t == null) {
                        Node termsNode = Jcr.getNode(adminSession, "SELECT * FROM [{0}] WHERE NAME()=\"{1}\"",
                                        EntityType.terms.get(), typology);
+                       if (termsNode == null)
+                               throw new IllegalArgumentException("Typology " + typology + " not found.");
                        t = loadTypology(termsNode);
                }
                return t;
                        t = loadTypology(termsNode);
                }
                return t;
index 2189f34c89a3566859a8271a7953b7ca62d65f0a..6ff42815f261c71d16ac171c5b09a2f4a832e1c3 100644 (file)
@@ -9,6 +9,7 @@ import org.argeo.cms.ui.viewers.SectionPart;
 import org.argeo.cms.ui.widgets.EditableText;
 import org.argeo.cms.ui.widgets.TextStyles;
 
 import org.argeo.cms.ui.widgets.EditableText;
 import org.argeo.cms.ui.widgets.TextStyles;
 
+/** An editable paragraph.*/
 public class Paragraph extends EditableText implements SectionPart {
        private static final long serialVersionUID = 3746457776229542887L;
 
 public class Paragraph extends EditableText implements SectionPart {
        private static final long serialVersionUID = 3746457776229542887L;
 
index ef4bb0f38d2cbc39908320f14bcdf085e519e191..4f514bf763c4ad380262e9eb40c0863409c5ef28 100644 (file)
@@ -5,6 +5,7 @@ import javax.jcr.Node;
 import org.argeo.cms.ui.util.CmsUiUtils;
 import org.argeo.cms.ui.viewers.Section;
 import org.argeo.cms.ui.widgets.TextStyles;
 import org.argeo.cms.ui.util.CmsUiUtils;
 import org.argeo.cms.ui.viewers.Section;
 import org.argeo.cms.ui.widgets.TextStyles;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 
 public class TextSection extends Section implements CmsNames {
 import org.eclipse.swt.widgets.Composite;
 
 public class TextSection extends Section implements CmsNames {
@@ -12,6 +13,10 @@ public class TextSection extends Section implements CmsNames {
        private String defaultTextStyle = TextStyles.TEXT_DEFAULT;
        private String titleStyle;
 
        private String defaultTextStyle = TextStyles.TEXT_DEFAULT;
        private String titleStyle;
 
+       private final boolean flat;
+
+       private boolean titleReadOnly = false;
+
        public TextSection(Composite parent, int style, Node node) {
                this(parent, findSection(parent), style, node);
        }
        public TextSection(Composite parent, int style, Node node) {
                this(parent, findSection(parent), style, node);
        }
@@ -22,13 +27,18 @@ public class TextSection extends Section implements CmsNames {
 
        private TextSection(Composite parent, Section parentSection, int style, Node node) {
                super(parent, parentSection, style, node);
 
        private TextSection(Composite parent, Section parentSection, int style, Node node) {
                super(parent, parentSection, style, node);
-               CmsUiUtils.style(this, TextStyles.TEXT_SECTION);
+               flat = SWT.FLAT == (style & SWT.FLAT);
+               //CmsUiUtils.style(this, TextStyles.TEXT_SECTION);
        }
 
        public String getDefaultTextStyle() {
                return defaultTextStyle;
        }
 
        }
 
        public String getDefaultTextStyle() {
                return defaultTextStyle;
        }
 
+       public boolean isFlat() {
+               return flat;
+       }
+
        public String getTitleStyle() {
                if (titleStyle != null)
                        return titleStyle;
        public String getTitleStyle() {
                if (titleStyle != null)
                        return titleStyle;
@@ -44,4 +54,13 @@ public class TextSection extends Section implements CmsNames {
        public void setTitleStyle(String titleStyle) {
                this.titleStyle = titleStyle;
        }
        public void setTitleStyle(String titleStyle) {
                this.titleStyle = titleStyle;
        }
+
+       public boolean isTitleReadOnly() {
+               return titleReadOnly;
+       }
+
+       public void setTitleReadOnly(boolean titleReadOnly) {
+               this.titleReadOnly = titleReadOnly;
+       }
+
 }
 }
index 39ae080152dfc0ca5c58ed621b486b512553ba9b..8a527793a3d47ade95684c5e73d092dc996e6919 100644 (file)
@@ -1,6 +1,5 @@
 package org.argeo.docbook.ui;
 
 package org.argeo.docbook.ui;
 
-import static javax.jcr.Property.JCR_TITLE;
 import static org.argeo.cms.ui.util.CmsUiUtils.fillWidth;
 
 import java.util.ArrayList;
 import static org.argeo.cms.ui.util.CmsUiUtils.fillWidth;
 
 import java.util.ArrayList;
@@ -11,7 +10,6 @@ import java.util.Observer;
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
-import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
@@ -97,14 +95,13 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                        CmsUiUtils.clear(section);
                        Node node = section.getNode();
                        TextSection textSection = (TextSection) section;
                        CmsUiUtils.clear(section);
                        Node node = section.getNode();
                        TextSection textSection = (TextSection) section;
-                       if (node.hasProperty(Property.JCR_TITLE)) {
+                       if (node.hasNode(DocBookTypes.TITLE)) {
                                if (section.getHeader() == null)
                                        section.createHeader();
                                if (section.getHeader() == null)
                                        section.createHeader();
-                               if (node.hasProperty(Property.JCR_TITLE)) {
-                                       SectionTitle title = newSectionTitle(textSection, node);
-                                       title.setLayoutData(CmsUiUtils.fillWidth());
-                                       updateContent(title);
-                               }
+                               Node titleNode = node.getNode(DocBookTypes.TITLE);
+                               DocBookSectionTitle title = newSectionTitle(textSection, titleNode);
+                               title.setLayoutData(CmsUiUtils.fillWidth());
+                               updateContent(title);
                        }
 
                        for (NodeIterator ni = node.getNodes(DocBookNames.DBK_PARA); ni.hasNext();) {
                        }
 
                        for (NodeIterator ni = node.getNodes(DocBookNames.DBK_PARA); ni.hasNext();) {
@@ -125,15 +122,15 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                        ((Control) sectionPart).setLayoutData(CmsUiUtils.fillWidth());
                        }
 
                                        ((Control) sectionPart).setLayoutData(CmsUiUtils.fillWidth());
                        }
 
-                       if (!flat)
-                               for (NodeIterator ni = section.getNode().getNodes(DocBookNames.DBK_SECTION); ni.hasNext();) {
-                                       Node child = ni.nextNode();
-                                       if (child.isNodeType(DocBookTypes.SECTION)) {
-                                               TextSection newSection = new TextSection(section, SWT.NONE, child);
-                                               newSection.setLayoutData(CmsUiUtils.fillWidth());
-                                               refresh(newSection);
-                                       }
+//                     if (!flat)
+                       for (NodeIterator ni = section.getNode().getNodes(DocBookNames.DBK_SECTION); ni.hasNext();) {
+                               Node child = ni.nextNode();
+                               if (child.isNodeType(DocBookTypes.SECTION)) {
+                                       TextSection newSection = new TextSection(section, SWT.NONE, child);
+                                       newSection.setLayoutData(CmsUiUtils.fillWidth());
+                                       refresh(newSection);
                                }
                                }
+                       }
                } else {
                        for (Section s : section.getSubSections().values())
                                refresh(s);
                } else {
                        for (Section s : section.getSubSections().values())
                                refresh(s);
@@ -175,21 +172,28 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                return img;
        }
 
                return img;
        }
 
-       protected SectionTitle newSectionTitle(TextSection parent, Node node) throws RepositoryException {
-               SectionTitle title = new SectionTitle(parent.getHeader(), parent.getStyle(), node.getProperty(JCR_TITLE));
+       protected DocBookSectionTitle newSectionTitle(TextSection parent, Node titleNode) throws RepositoryException {
+               int style = parent.getStyle();
+               if (parent.isTitleReadOnly())
+                       style = style | SWT.READ_ONLY;
+               DocBookSectionTitle title = new DocBookSectionTitle(parent.getHeader(), style, titleNode);
                updateContent(title);
                title.setMouseListener(getMouseListener());
                return title;
        }
 
                updateContent(title);
                title.setMouseListener(getMouseListener());
                return title;
        }
 
-       protected SectionTitle prepareSectionTitle(Section newSection, String titleText) throws RepositoryException {
+       protected DocBookSectionTitle prepareSectionTitle(Section newSection, String titleText) throws RepositoryException {
                Node sectionNode = newSection.getNode();
                Node sectionNode = newSection.getNode();
-               if (!sectionNode.hasProperty(JCR_TITLE))
-                       sectionNode.setProperty(Property.JCR_TITLE, "");
-               getTextInterpreter().write(sectionNode.getProperty(Property.JCR_TITLE), titleText);
+               Node titleNode;
+               if (!sectionNode.hasNode(DocBookTypes.TITLE)) {
+                       titleNode = sectionNode.addNode(DocBookTypes.TITLE, DocBookTypes.TITLE);
+               } else {
+                       titleNode = sectionNode.getNode(DocBookTypes.TITLE);
+               }
+               getTextInterpreter().write(titleNode, titleText);
                if (newSection.getHeader() == null)
                        newSection.createHeader();
                if (newSection.getHeader() == null)
                        newSection.createHeader();
-               SectionTitle sectionTitle = newSectionTitle((TextSection) newSection, sectionNode);
+               DocBookSectionTitle sectionTitle = newSectionTitle((TextSection) newSection, sectionNode);
                return sectionTitle;
        }
 
                return sectionTitle;
        }
 
@@ -220,14 +224,14 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                EditableImage editableImage = (EditableImage) part;
                                imageManager.load(partNode, part.getControl(), editableImage.getPreferredImageSize());
                        }
                                EditableImage editableImage = (EditableImage) part;
                                imageManager.load(partNode, part.getControl(), editableImage.getPreferredImageSize());
                        }
-               } else if (part instanceof SectionTitle) {
-                       SectionTitle title = (SectionTitle) part;
+               } else if (part instanceof DocBookSectionTitle) {
+                       DocBookSectionTitle title = (DocBookSectionTitle) part;
                        title.setStyle(title.getSection().getTitleStyle());
                        // use control AFTER setting style
                        if (title == getEdited())
                        title.setStyle(title.getSection().getTitleStyle());
                        // use control AFTER setting style
                        if (title == getEdited())
-                               title.setText(textInterpreter.read(title.getProperty()));
+                               title.setText(textInterpreter.read(title.getNode()));
                        else
                        else
-                               title.setText(textInterpreter.raw(title.getProperty()));
+                               title.setText(textInterpreter.raw(title.getNode()));
                }
        }
 
                }
        }
 
@@ -236,6 +240,8 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
        protected void save(EditablePart part) throws RepositoryException {
                if (part instanceof EditableText) {
                        EditableText et = (EditableText) part;
        protected void save(EditablePart part) throws RepositoryException {
                if (part instanceof EditableText) {
                        EditableText et = (EditableText) part;
+                       if (!et.getEditable())
+                               return;
                        String text = ((Text) et.getControl()).getText();
 
                        String[] lines = text.split("[\r\n]+");
                        String text = ((Text) et.getControl()).getText();
 
                        String[] lines = text.split("[\r\n]+");
@@ -267,11 +273,11 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                                currentParagraph = newParagraph;
                                                currentParagraphN = newNode;
                                        }
                                                currentParagraph = newParagraph;
                                                currentParagraphN = newNode;
                                        }
-                                       persistChanges(sectionNode);
                                }
                                // TODO or rather return the created paragarphs?
                                layout(toLayout.toArray(new Control[toLayout.size()]));
                        }
                                }
                                // TODO or rather return the created paragarphs?
                                layout(toLayout.toArray(new Control[toLayout.size()]));
                        }
+                       persistChanges(et.getNode());
                }
        }
 
                }
        }
 
@@ -383,8 +389,8 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
 
                                Paragraph secondParagraph = paragraphSplitted(paragraph, secondNode);
                                edit(secondParagraph, 0);
 
                                Paragraph secondParagraph = paragraphSplitted(paragraph, secondNode);
                                edit(secondParagraph, 0);
-                       } else if (getEdited() instanceof SectionTitle) {
-                               SectionTitle sectionTitle = (SectionTitle) getEdited();
+                       } else if (getEdited() instanceof DocBookSectionTitle) {
+                               DocBookSectionTitle sectionTitle = (DocBookSectionTitle) getEdited();
                                Text text = (Text) sectionTitle.getControl();
                                String txt = text.getText();
                                int caretPosition = text.getCaretPosition();
                                Text text = (Text) sectionTitle.getControl();
                                String txt = text.getText();
                                int caretPosition = text.getCaretPosition();
@@ -394,7 +400,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                // paragraphNode.addMixin(CmsTypes.CMS_STYLED);
 
                                textInterpreter.write(paragraphNode, txt.substring(caretPosition));
                                // paragraphNode.addMixin(CmsTypes.CMS_STYLED);
 
                                textInterpreter.write(paragraphNode, txt.substring(caretPosition));
-                               textInterpreter.write(sectionNode.getProperty(Property.JCR_TITLE), txt.substring(0, caretPosition));
+                               textInterpreter.write(sectionNode.getNode(DocBookTypes.TITLE), txt.substring(0, caretPosition));
                                sectionNode.orderBefore(p(paragraphNode.getIndex()), p(1));
                                persistChanges(sectionNode);
 
                                sectionNode.orderBefore(p(paragraphNode.getIndex()), p(1));
                                persistChanges(sectionNode);
 
@@ -509,13 +515,13 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                Node sectionNode = section.getNode();
                                // main title
                                if (section == mainSection && section instanceof TextSection && paragraphNode.getIndex() == 1
                                Node sectionNode = section.getNode();
                                // main title
                                if (section == mainSection && section instanceof TextSection && paragraphNode.getIndex() == 1
-                                               && !sectionNode.hasProperty(JCR_TITLE)) {
-                                       SectionTitle sectionTitle = prepareSectionTitle(section, txt);
+                                               && !sectionNode.hasNode(DocBookTypes.TITLE)) {
+                                       DocBookSectionTitle sectionTitle = prepareSectionTitle(section, txt);
                                        edit(sectionTitle, 0);
                                        return;
                                }
                                Node newSectionNode = sectionNode.addNode(DocBookNames.DBK_SECTION, DocBookTypes.SECTION);
                                        edit(sectionTitle, 0);
                                        return;
                                }
                                Node newSectionNode = sectionNode.addNode(DocBookNames.DBK_SECTION, DocBookTypes.SECTION);
-                               newSectionNode.addMixin(NodeType.MIX_TITLE);
+                               // newSectionNode.addMixin(NodeType.MIX_TITLE);
                                sectionNode.orderBefore(h(newSectionNode.getIndex()), h(1));
 
                                int paragraphIndex = paragraphNode.getIndex();
                                sectionNode.orderBefore(h(newSectionNode.getIndex()), h(1));
 
                                int paragraphIndex = paragraphNode.getIndex();
@@ -529,9 +535,9 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                        if (sp instanceof Control)
                                                ((Control) sp).dispose();
                                }
                                        if (sp instanceof Control)
                                                ((Control) sp).dispose();
                                }
-                               // create property
-                               newSectionNode.setProperty(Property.JCR_TITLE, "");
-                               getTextInterpreter().write(newSectionNode.getProperty(Property.JCR_TITLE), txt);
+                               // create title
+                               Node titleNode = newSectionNode.addNode(DocBookTypes.TITLE, DocBookTypes.TITLE);
+                               getTextInterpreter().write(titleNode, txt);
 
                                TextSection newSection = new TextSection(section, section.getStyle(), newSectionNode);
                                newSection.setLayoutData(CmsUiUtils.fillWidth());
 
                                TextSection newSection = new TextSection(section, section.getStyle(), newSectionNode);
                                newSection.setLayoutData(CmsUiUtils.fillWidth());
@@ -545,8 +551,8 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                newSection.getParent().layout();
                                layout(newSection);
                                persistChanges(sectionNode);
                                newSection.getParent().layout();
                                layout(newSection);
                                persistChanges(sectionNode);
-                       } else if (getEdited() instanceof SectionTitle) {
-                               SectionTitle sectionTitle = (SectionTitle) getEdited();
+                       } else if (getEdited() instanceof DocBookSectionTitle) {
+                               DocBookSectionTitle sectionTitle = (DocBookSectionTitle) getEdited();
                                Section section = sectionTitle.getSection();
                                Section parentSection = section.getParentSection();
                                if (parentSection == null)
                                Section section = sectionTitle.getSection();
                                Section parentSection = section.getParentSection();
                                if (parentSection == null)
@@ -602,7 +608,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                                // newParagrapheNode.addMixin(CmsTypes.CMS_STYLED);
                                if (mergedHasSubSections)
                                        mergedNode.orderBefore(p(newParagrapheNode.getIndex()), h(1));
                                // newParagrapheNode.addMixin(CmsTypes.CMS_STYLED);
                                if (mergedHasSubSections)
                                        mergedNode.orderBefore(p(newParagrapheNode.getIndex()), h(1));
-                               String txt = getTextInterpreter().read(sectionNode.getProperty(Property.JCR_TITLE));
+                               String txt = getTextInterpreter().read(sectionNode.getNode(DocBookTypes.TITLE));
                                getTextInterpreter().write(newParagrapheNode, txt);
                                // move
                                NodeIterator paragraphs = sectionNode.getNodes(DocBookNames.DBK_PARA);
                                getTextInterpreter().write(newParagrapheNode, txt);
                                // move
                                NodeIterator paragraphs = sectionNode.getNodes(DocBookNames.DBK_PARA);
@@ -650,7 +656,8 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                return newParagraph;
        }
 
                return newParagraph;
        }
 
-       protected Paragraph sectionTitleSplitted(SectionTitle sectionTitle, Node newNode) throws RepositoryException {
+       protected Paragraph sectionTitleSplitted(DocBookSectionTitle sectionTitle, Node newNode)
+                       throws RepositoryException {
                updateContent(sectionTitle);
                Paragraph newParagraph = newParagraph(sectionTitle.getSection(), newNode);
                // we assume beforeFirst is not null since there was a sectionTitle
                updateContent(sectionTitle);
                Paragraph newParagraph = newParagraph(sectionTitle.getSection(), newNode);
                // we assume beforeFirst is not null since there was a sectionTitle
index 801cd1c2981ec6e00cf72fd827fb30172b775abb..561b1e13b7e24d0412f392eeb4e808442c894542 100644 (file)
@@ -13,12 +13,11 @@ import org.eclipse.swt.widgets.Composite;
 public class CustomDbkEditor extends AbstractDbkViewer {
        private static final long serialVersionUID = 656302500183820802L;
 
 public class CustomDbkEditor extends AbstractDbkViewer {
        private static final long serialVersionUID = 656302500183820802L;
 
-       protected CustomDbkEditor(Composite parent, int style, Node textNode, CmsEditable cmsEditable) {
+       public CustomDbkEditor(Composite parent, int style, Node textNode, CmsEditable cmsEditable) {
                this(new Section(parent, style, textNode), style, cmsEditable);
        }
 
                this(new Section(parent, style, textNode), style, cmsEditable);
        }
 
-       protected CustomDbkEditor(Section parent, int style, CmsEditable cmsEditable) {
+       public CustomDbkEditor(Section parent, int style, CmsEditable cmsEditable) {
                super(parent, style, cmsEditable);
        }
                super(parent, style, cmsEditable);
        }
-
 }
 }
index 51af55e46f02544b1f983515330a914dc57c3ac3..6ca50251835557481d1340b7277cad9a06562389 100644 (file)
@@ -18,7 +18,7 @@ public class DbkTextInterpreter implements TextInterpreter {
                try {
                        if (item instanceof Node) {
                                Node node = (Node) item;
                try {
                        if (item instanceof Node) {
                                Node node = (Node) item;
-                               if (node.isNodeType(DocBookTypes.PARA)) {
+                               if (node.isNodeType(DocBookTypes.PARA)||node.isNodeType(DocBookTypes.TITLE)) {
                                        String raw = convertToStorage(node, content);
                                        validateBeforeStoring(raw);
                                        Node jcrText;
                                        String raw = convertToStorage(node, content);
                                        validateBeforeStoring(raw);
                                        Node jcrText;
@@ -56,7 +56,7 @@ public class DbkTextInterpreter implements TextInterpreter {
                        item.getSession().refresh(true);
                        if (item instanceof Node) {
                                Node node = (Node) item;
                        item.getSession().refresh(true);
                        if (item instanceof Node) {
                                Node node = (Node) item;
-                               if (node.isNodeType(DocBookTypes.PARA)) {
+                               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
                                        Node jcrText = node.getNode(Jcr.JCR_XMLTEXT);
                                        String txt = jcrText.getProperty(Jcr.JCR_XMLCHARACTERS).getString();
                                        // TODO make it more robust
index b53c30552044bf8f084b3c143f8e5a5ebad53ba8..ee675d26e5aa77428f63ee774aafca7bab3d0530 100644 (file)
@@ -1,7 +1,10 @@
 package org.argeo.docbook.ui;
 
 import javax.jcr.Node;
 package org.argeo.docbook.ui;
 
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 
 
+import org.argeo.jcr.JcrException;
+import org.argeo.jcr.JcrUtils;
 import org.argeo.jcr.JcrxApi;
 
 /** Utilities around DocBook. */
 import org.argeo.jcr.JcrxApi;
 
 /** Utilities around DocBook. */
@@ -10,6 +13,25 @@ public class DbkUtils {
                return JcrxApi.getXmlValue(node, DocBookTypes.TITLE);
        }
 
                return JcrxApi.getXmlValue(node, DocBookTypes.TITLE);
        }
 
+       public static void setTitle(Node node, String txt) {
+               try {
+                       Node titleNode = JcrUtils.getOrAdd(node, DocBookTypes.TITLE, DocBookTypes.TITLE);
+                       JcrxApi.setXmlValue(node, titleNode, txt);
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot add empty paragraph to " + node, e);
+               }
+       }
+
+       public static Node addParagraph(Node node, String txt) {
+               try {
+                       Node para = node.addNode(DocBookTypes.PARA, DocBookTypes.PARA);
+                       JcrxApi.setXmlValue(node, para, txt);
+                       return para;
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot add empty paragraph to " + node, e);
+               }
+       }
+
        /** Singleton. */
        private DbkUtils() {
        }
        /** Singleton. */
        private DbkUtils() {
        }
diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocBookSectionTitle.java
new file mode 100644 (file)
index 0000000..fcde875
--- /dev/null
@@ -0,0 +1,33 @@
+package org.argeo.docbook.ui;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.argeo.cms.text.TextSection;
+import org.argeo.cms.ui.viewers.EditablePart;
+import org.argeo.cms.ui.viewers.NodePart;
+import org.argeo.cms.ui.widgets.EditableText;
+import org.eclipse.swt.widgets.Composite;
+
+/** The title of a section, based on an XML text node. */
+public class DocBookSectionTitle extends EditableText implements EditablePart, NodePart {
+       private static final long serialVersionUID = -1787983154946583171L;
+
+       private final TextSection section;
+
+       public DocBookSectionTitle(Composite parent, int swtStyle, Node titleNode) throws RepositoryException {
+               super(parent, swtStyle, titleNode);
+               section = (TextSection) TextSection.findSection(this);
+       }
+
+       public TextSection getSection() {
+               return section;
+       }
+
+       @Override
+       public Node getItem() throws RepositoryException {
+               return getNode();
+       }
+
+}
index 03721b23085f13fa3af9f776e57c4535168caba4..aa37c164dff713b581c0374ede2117fc11977e6f 100644 (file)
@@ -4,6 +4,7 @@ public interface DocBookTypes {
        public final static String BOOK = "dbk:book";
        public final static String ARTICLE = "dbk:article";
        public final static String TITLE = "dbk:title";
        public final static String BOOK = "dbk:book";
        public final static String ARTICLE = "dbk:article";
        public final static String TITLE = "dbk:title";
+       public final static String INFO = "dbk:info";
        public final static String SECTION = "dbk:section";
        public final static String PARA = "dbk:para";
 //     public final static String XMLTEXT = "dbk:xmltext";
        public final static String SECTION = "dbk:section";
        public final static String PARA = "dbk:para";
 //     public final static String XMLTEXT = "dbk:xmltext";
index 0398c2596575ef089dcc78dfce31f7bfefd67114..3c44533309ca75130bbf0e11e8657f3f61a784fc 100644 (file)
@@ -255,6 +255,7 @@ orderable
  + dbk:orgname (dbk:orgname) = dbk:orgname *
  + dbk:subtitle (dbk:subtitle) = dbk:subtitle *
  + dbk:title (dbk:title) = dbk:title *
  + dbk:orgname (dbk:orgname) = dbk:orgname *
  + dbk:subtitle (dbk:subtitle) = dbk:subtitle *
  + dbk:title (dbk:title) = dbk:title *
+ + * (nt:base) = nt:unstructured *
 
 [dbk:inlinemediaobject] > argeodbk:base, argeodbk:linkingAttributes
  + dbk:alt (dbk:alt) = dbk:alt
 
 [dbk:inlinemediaobject] > argeodbk:base, argeodbk:linkingAttributes
  + dbk:alt (dbk:alt) = dbk:alt