From 2824e4dce1c2239500f865efaac23f2880b12277 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 25 Jun 2021 10:56:00 +0200 Subject: [PATCH] Remove CMS Text package. --- publishing/org.argeo.publishing.ui/bnd.bnd | 1 + .../argeo/cms/text/AbstractTextViewer.java | 888 ------------------ .../src/org/argeo/cms/text/CmsNames.java | 24 - .../argeo/cms/text/CmsTextImageManager.java | 44 - .../src/org/argeo/cms/text/CmsTypes.java | 10 - .../org/argeo/cms/text/CustomTextEditor.java | 35 - .../cms/text/IdentityTextInterpreter.java | 94 -- .../argeo/cms/text/MarkupValidatorCopy.java | 169 ---- .../src/org/argeo/cms/text/SectionTitle.java | 39 - .../argeo/cms/text/StandardTextEditor.java | 47 - .../org/argeo/cms/text/TextContextMenu.java | 134 --- .../argeo/cms/text/TextInterpreterImpl.java | 28 - .../src/org/argeo/cms/text/WikiPage.java | 65 -- .../argeo/docbook/ui/AbstractDbkViewer.java | 3 - .../org/argeo/docbook/ui/DbkContextMenu.java | 2 - .../argeo/docbook/ui/DbkTextInterpreter.java | 11 - .../argeo/docbook/ui/DocBookSectionTitle.java | 1 - .../org/argeo/docbook/ui/DocumentPage.java | 1 - .../argeo/docbook/ui/DocumentTextEditor.java | 1 - .../{cms/text => docbook/ui}/Paragraph.java | 2 +- .../text => docbook/ui}/TextEditorHeader.java | 2 +- .../text => docbook/ui}/TextInterpreter.java | 2 +- .../{cms/text => docbook/ui}/TextSection.java | 2 +- 23 files changed, 5 insertions(+), 1600 deletions(-) delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/AbstractTextViewer.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsNames.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTextImageManager.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTypes.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CustomTextEditor.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/IdentityTextInterpreter.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/MarkupValidatorCopy.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/SectionTitle.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/StandardTextEditor.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextContextMenu.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreterImpl.java delete mode 100644 publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/WikiPage.java rename publishing/org.argeo.publishing.ui/src/org/argeo/{cms/text => docbook/ui}/Paragraph.java (96%) rename publishing/org.argeo.publishing.ui/src/org/argeo/{cms/text => docbook/ui}/TextEditorHeader.java (98%) rename publishing/org.argeo.publishing.ui/src/org/argeo/{cms/text => docbook/ui}/TextInterpreter.java (89%) rename publishing/org.argeo.publishing.ui/src/org/argeo/{cms/text => docbook/ui}/TextSection.java (98%) diff --git a/publishing/org.argeo.publishing.ui/bnd.bnd b/publishing/org.argeo.publishing.ui/bnd.bnd index 5485019..3829f16 100644 --- a/publishing/org.argeo.publishing.ui/bnd.bnd +++ b/publishing/org.argeo.publishing.ui/bnd.bnd @@ -8,6 +8,7 @@ org.eclipse.swt,\ org.eclipse.jface.viewers,\ org.osgi.framework,\ org.apache.xml.serializer,\ +org.eclipse.rap.rwt,\ * Provide-Capability:\ diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/AbstractTextViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/AbstractTextViewer.java deleted file mode 100644 index 74a9c81..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/AbstractTextViewer.java +++ /dev/null @@ -1,888 +0,0 @@ -package org.argeo.cms.text; - -import static javax.jcr.Property.JCR_TITLE; -import static org.argeo.cms.ui.util.CmsUiUtils.fillWidth; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.Observer; - -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 org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.cms.CmsException; -import org.argeo.cms.ui.CmsEditable; -import org.argeo.cms.ui.CmsImageManager; -import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.cms.ui.viewers.AbstractPageViewer; -import org.argeo.cms.ui.viewers.EditablePart; -import org.argeo.cms.ui.viewers.NodePart; -import org.argeo.cms.ui.viewers.PropertyPart; -import org.argeo.cms.ui.viewers.Section; -import org.argeo.cms.ui.viewers.SectionPart; -import org.argeo.cms.ui.widgets.EditableImage; -import org.argeo.cms.ui.widgets.EditableText; -import org.argeo.cms.ui.widgets.Img; -import org.argeo.cms.ui.widgets.StyledControl; -import org.argeo.jcr.JcrUtils; -import org.eclipse.rap.fileupload.FileDetails; -import org.eclipse.rap.fileupload.FileUploadEvent; -import org.eclipse.rap.fileupload.FileUploadHandler; -import org.eclipse.rap.fileupload.FileUploadListener; -import org.eclipse.rap.rwt.RWT; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; - -/** Base class for text viewers and editors. */ -@Deprecated -public abstract class AbstractTextViewer extends AbstractPageViewer implements - CmsNames, KeyListener, Observer { - private static final long serialVersionUID = -2401274679492339668L; - private final static Log log = LogFactory.getLog(AbstractTextViewer.class); - - private final Section mainSection; - - private TextInterpreter textInterpreter = new TextInterpreterImpl(); - private CmsImageManager imageManager = CmsUiUtils.getCmsView() - .getImageManager(); - - private FileUploadListener fileUploadListener; - private TextContextMenu styledTools; - - private final boolean flat; - - protected AbstractTextViewer(Section parent, int style, - CmsEditable cmsEditable) { - super(parent, style, cmsEditable); - flat = SWT.FLAT == (style & SWT.FLAT); - - if (getCmsEditable().canEdit()) { - fileUploadListener = new FUL(); - styledTools = new TextContextMenu(this, parent.getDisplay()); - } - this.mainSection = parent; - initModelIfNeeded(mainSection.getNode()); - // layout(this.mainSection); - } - - @Override - public Control getControl() { - return mainSection; - } - - protected void refresh(Control control) throws RepositoryException { - if (!(control instanceof Section)) - return; - Section section = (Section) control; - if (section instanceof TextSection) { - CmsUiUtils.clear(section); - Node node = section.getNode(); - TextSection textSection = (TextSection) section; - if (node.hasProperty(Property.JCR_TITLE)) { - if (section.getHeader() == null) - section.createHeader(); - if (node.hasProperty(Property.JCR_TITLE)) { - SectionTitle title = newSectionTitle(textSection, node); - title.setLayoutData(CmsUiUtils.fillWidth()); - updateContent(title); - } - } - - for (NodeIterator ni = node.getNodes(CMS_P); ni.hasNext();) { - Node child = ni.nextNode(); - final SectionPart sectionPart; - if (child.isNodeType(CmsTypes.CMS_IMAGE) - || child.isNodeType(NodeType.NT_FILE)) { - sectionPart = newImg(textSection, child); - } else if (child.isNodeType(CmsTypes.CMS_STYLED)) { - sectionPart = newParagraph(textSection, child); - } else { - sectionPart = newSectionPart(textSection, child); - if (sectionPart == null) - throw new CmsException("Unsupported node " + child); - // TODO list node types in exception - } - if (sectionPart instanceof Control) - ((Control) sectionPart).setLayoutData(CmsUiUtils.fillWidth()); - } - - if (!flat) - for (NodeIterator ni = section.getNode().getNodes(CMS_H); ni - .hasNext();) { - Node child = ni.nextNode(); - if (child.isNodeType(CmsTypes.CMS_SECTION)) { - TextSection newSection = new TextSection(section, - SWT.NONE, child); - newSection.setLayoutData(CmsUiUtils.fillWidth()); - refresh(newSection); - } - } - } else { - for (Section s : section.getSubSections().values()) - refresh(s); - } - // section.layout(); - } - - /** To be overridden in order to provide additional SectionPart types */ - protected SectionPart newSectionPart(TextSection textSection, Node node) { - return null; - } - - // CRUD - protected Paragraph newParagraph(TextSection parent, Node node) - throws RepositoryException { - Paragraph paragraph = new Paragraph(parent, parent.getStyle(), node); - updateContent(paragraph); - paragraph.setLayoutData(fillWidth()); - paragraph.setMouseListener(getMouseListener()); - return paragraph; - } - - protected Img newImg(TextSection parent, Node node) - throws RepositoryException { - Img img = new Img(parent, parent.getStyle(), node) { - private static final long serialVersionUID = 1297900641952417540L; - - @Override - protected void setContainerLayoutData(Composite composite) { - composite.setLayoutData(CmsUiUtils.grabWidth(SWT.CENTER, - SWT.DEFAULT)); - } - - @Override - protected void setControlLayoutData(Control control) { - control.setLayoutData(CmsUiUtils.grabWidth(SWT.CENTER, - SWT.DEFAULT)); - } - }; - img.setLayoutData(CmsUiUtils.grabWidth(SWT.CENTER, SWT.DEFAULT)); - updateContent(img); - img.setMouseListener(getMouseListener()); - return img; - } - - protected SectionTitle newSectionTitle(TextSection parent, Node node) - throws RepositoryException { - SectionTitle title = new SectionTitle(parent.getHeader(), - parent.getStyle(), node.getProperty(JCR_TITLE)); - updateContent(title); - title.setMouseListener(getMouseListener()); - return title; - } - - protected SectionTitle prepareSectionTitle(Section newSection, - String titleText) throws RepositoryException { - Node sectionNode = newSection.getNode(); - if (!sectionNode.hasProperty(JCR_TITLE)) - sectionNode.setProperty(Property.JCR_TITLE, ""); - getTextInterpreter().write(sectionNode.getProperty(Property.JCR_TITLE), - titleText); - if (newSection.getHeader() == null) - newSection.createHeader(); - SectionTitle sectionTitle = newSectionTitle((TextSection) newSection, - sectionNode); - return sectionTitle; - } - - protected void updateContent(EditablePart part) throws RepositoryException { - if (part instanceof SectionPart) { - SectionPart sectionPart = (SectionPart) part; - Node partNode = sectionPart.getNode(); - - if (part instanceof StyledControl - && (sectionPart.getSection() instanceof TextSection)) { - TextSection section = (TextSection) sectionPart.getSection(); - StyledControl styledControl = (StyledControl) part; - if (partNode.isNodeType(CmsTypes.CMS_STYLED)) { - String style = partNode.hasProperty(CMS_STYLE) ? partNode - .getProperty(CMS_STYLE).getString() : section - .getDefaultTextStyle(); - styledControl.setStyle(style); - } - } - // use control AFTER setting style, since it may have been reset - - if (part instanceof EditableText) { - EditableText paragraph = (EditableText) part; - if (paragraph == getEdited()) - paragraph.setText(textInterpreter.read(partNode)); - else - paragraph.setText(textInterpreter.raw(partNode)); - } else if (part instanceof EditableImage) { - EditableImage editableImage = (EditableImage) part; - imageManager.load(partNode, part.getControl(), - editableImage.getPreferredImageSize()); - } - } else if (part instanceof SectionTitle) { - SectionTitle title = (SectionTitle) part; - title.setStyle(title.getSection().getTitleStyle()); - // use control AFTER setting style - if (title == getEdited()) - title.setText(textInterpreter.read(title.getProperty())); - else - title.setText(textInterpreter.raw(title.getProperty())); - } - } - - // OVERRIDDEN FROM PARENT VIEWER - @Override - protected void save(EditablePart part) throws RepositoryException { - if (part instanceof EditableText) { - EditableText et = (EditableText) part; - String text = ((Text) et.getControl()).getText(); - - String[] lines = text.split("[\r\n]+"); - assert lines.length != 0; - saveLine(part, lines[0]); - if (lines.length > 1) { - ArrayList toLayout = new ArrayList(); - if (part instanceof Paragraph) { - Paragraph currentParagraph = (Paragraph) et; - Section section = currentParagraph.getSection(); - Node sectionNode = section.getNode(); - Node currentParagraphN = currentParagraph.getNode(); - for (int i = 1; i < lines.length; i++) { - Node newNode = sectionNode.addNode(CMS_P); - newNode.addMixin(CmsTypes.CMS_STYLED); - saveLine(newNode, lines[i]); - // second node was create as last, if it is not the next - // one, it - // means there are some in between and we can take the - // one at - // index+1 for the re-order - if (newNode.getIndex() > currentParagraphN.getIndex() + 1) { - sectionNode.orderBefore(p(newNode.getIndex()), - p(currentParagraphN.getIndex() + 1)); - } - Paragraph newParagraph = newParagraph( - (TextSection) section, newNode); - newParagraph.moveBelow(currentParagraph); - toLayout.add(newParagraph); - - currentParagraph = newParagraph; - currentParagraphN = newNode; - } - persistChanges(sectionNode); - } - // TODO or rather return the created paragarphs? - layout(toLayout.toArray(new Control[toLayout.size()])); - } - } - } - - protected void saveLine(EditablePart part, String line) { - if (part instanceof NodePart) { - saveLine(((NodePart) part).getNode(), line); - } else if (part instanceof PropertyPart) { - saveLine(((PropertyPart) part).getProperty(), line); - } else { - throw new CmsException("Unsupported part " + part); - } - } - - protected void saveLine(Item item, String line) { - line = line.trim(); - textInterpreter.write(item, line); - } - - @Override - protected void prepare(EditablePart part, Object caretPosition) { - Control control = part.getControl(); - if (control instanceof Text) { - Text text = (Text) control; - if (caretPosition != null) - if (caretPosition instanceof Integer) - text.setSelection((Integer) caretPosition); - else if (caretPosition instanceof Point) { - // TODO find a way to position the caret at the right place - } - text.setData(RWT.ACTIVE_KEYS, new String[] { "BACKSPACE", "ESC", - "TAB", "SHIFT+TAB", "ALT+ARROW_LEFT", "ALT+ARROW_RIGHT", - "ALT+ARROW_UP", "ALT+ARROW_DOWN", "RETURN", "CTRL+RETURN", - "ENTER", "DELETE" }); - text.setData(RWT.CANCEL_KEYS, new String[] { "RETURN", - "ALT+ARROW_LEFT", "ALT+ARROW_RIGHT" }); - text.addKeyListener(this); - } else if (part instanceof Img) { - ((Img) part).setFileUploadListener(fileUploadListener); - } - } - - // REQUIRED BY CONTEXT MENU - void setParagraphStyle(Paragraph paragraph, String style) { - try { - Node paragraphNode = paragraph.getNode(); - paragraphNode.setProperty(CMS_STYLE, style); - persistChanges(paragraphNode); - updateContent(paragraph); - layout(paragraph); - } catch (RepositoryException e1) { - throw new CmsException("Cannot set style " + style + " on " - + paragraph, e1); - } - } - - void deletePart(SectionPart paragraph) { - try { - Node paragraphNode = paragraph.getNode(); - Section section = paragraph.getSection(); - Session session = paragraphNode.getSession(); - paragraphNode.remove(); - session.save(); - if (paragraph instanceof Control) - ((Control) paragraph).dispose(); - layout(section); - } catch (RepositoryException e1) { - throw new CmsException("Cannot delete " + paragraph, e1); - } - } - - String getRawParagraphText(Paragraph paragraph) { - return textInterpreter.raw(paragraph.getNode()); - } - - // COMMANDS - protected void splitEdit() { - checkEdited(); - try { - if (getEdited() instanceof Paragraph) { - Paragraph paragraph = (Paragraph) getEdited(); - Text text = (Text) paragraph.getControl(); - int caretPosition = text.getCaretPosition(); - String txt = text.getText(); - String first = txt.substring(0, caretPosition); - String second = txt.substring(caretPosition); - Node firstNode = paragraph.getNode(); - Node sectionNode = firstNode.getParent(); - firstNode.setProperty(CMS_CONTENT, first); - Node secondNode = sectionNode.addNode(CMS_P); - secondNode.addMixin(CmsTypes.CMS_STYLED); - // second node was create as last, if it is not the next one, it - // means there are some in between and we can take the one at - // index+1 for the re-order - if (secondNode.getIndex() > firstNode.getIndex() + 1) { - sectionNode.orderBefore(p(secondNode.getIndex()), - p(firstNode.getIndex() + 1)); - } - - // if we die in between, at least we still have the whole text - // in the first node - try { - textInterpreter.write(secondNode, second); - textInterpreter.write(firstNode, first); - } catch (Exception e) { - // so that no additional nodes are created: - JcrUtils.discardUnderlyingSessionQuietly(firstNode); - throw e; - } - - persistChanges(firstNode); - - Paragraph secondParagraph = paragraphSplitted(paragraph, - secondNode); - edit(secondParagraph, 0); - } else if (getEdited() instanceof SectionTitle) { - SectionTitle sectionTitle = (SectionTitle) getEdited(); - Text text = (Text) sectionTitle.getControl(); - String txt = text.getText(); - int caretPosition = text.getCaretPosition(); - Section section = sectionTitle.getSection(); - Node sectionNode = section.getNode(); - Node paragraphNode = sectionNode.addNode(CMS_P); - paragraphNode.addMixin(CmsTypes.CMS_STYLED); - textInterpreter.write(paragraphNode, - txt.substring(caretPosition)); - textInterpreter.write( - sectionNode.getProperty(Property.JCR_TITLE), - txt.substring(0, caretPosition)); - sectionNode.orderBefore(p(paragraphNode.getIndex()), p(1)); - persistChanges(sectionNode); - - Paragraph paragraph = sectionTitleSplitted(sectionTitle, - paragraphNode); - // section.layout(); - edit(paragraph, 0); - } - } catch (RepositoryException e) { - throw new CmsException("Cannot split " + getEdited(), e); - } - } - - protected void mergeWithPrevious() { - checkEdited(); - try { - Paragraph paragraph = (Paragraph) getEdited(); - Text text = (Text) paragraph.getControl(); - String txt = text.getText(); - Node paragraphNode = paragraph.getNode(); - if (paragraphNode.getIndex() == 1) - return;// do nothing - Node sectionNode = paragraphNode.getParent(); - Node previousNode = sectionNode - .getNode(p(paragraphNode.getIndex() - 1)); - String previousTxt = textInterpreter.read(previousNode); - textInterpreter.write(previousNode, previousTxt + txt); - paragraphNode.remove(); - persistChanges(sectionNode); - - Paragraph previousParagraph = paragraphMergedWithPrevious( - paragraph, previousNode); - edit(previousParagraph, previousTxt.length()); - } catch (RepositoryException e) { - throw new CmsException("Cannot stop editing", e); - } - } - - protected void mergeWithNext() { - checkEdited(); - try { - Paragraph paragraph = (Paragraph) getEdited(); - Text text = (Text) paragraph.getControl(); - String txt = text.getText(); - Node paragraphNode = paragraph.getNode(); - Node sectionNode = paragraphNode.getParent(); - NodeIterator paragraphNodes = sectionNode.getNodes(CMS_P); - long size = paragraphNodes.getSize(); - if (paragraphNode.getIndex() == size) - return;// do nothing - Node nextNode = sectionNode - .getNode(p(paragraphNode.getIndex() + 1)); - String nextTxt = textInterpreter.read(nextNode); - textInterpreter.write(paragraphNode, txt + nextTxt); - - Section section = paragraph.getSection(); - Paragraph removed = (Paragraph) section.getSectionPart(nextNode - .getIdentifier()); - - nextNode.remove(); - persistChanges(sectionNode); - - paragraphMergedWithNext(paragraph, removed); - edit(paragraph, txt.length()); - } catch (RepositoryException e) { - throw new CmsException("Cannot stop editing", e); - } - } - - protected synchronized void upload(EditablePart part) { - try { - if (part instanceof SectionPart) { - SectionPart sectionPart = (SectionPart) part; - Node partNode = sectionPart.getNode(); - int partIndex = partNode.getIndex(); - Section section = sectionPart.getSection(); - Node sectionNode = section.getNode(); - - if (part instanceof Paragraph) { - Node newNode = sectionNode.addNode(CMS_P, NodeType.NT_FILE); - newNode.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE); - JcrUtils.copyBytesAsFile(sectionNode, - p(newNode.getIndex()), new byte[0]); - if (partIndex < newNode.getIndex() - 1) { - // was not last - sectionNode.orderBefore(p(newNode.getIndex()), - p(partIndex - 1)); - } - // sectionNode.orderBefore(p(partNode.getIndex()), - // p(newNode.getIndex())); - persistChanges(sectionNode); - Img img = newImg((TextSection) section, newNode); - edit(img, null); - layout(img.getControl()); - } else if (part instanceof Img) { - if (getEdited() == part) - return; - edit(part, null); - layout(part.getControl()); - } - } - } catch (RepositoryException e) { - throw new CmsException("Cannot upload", e); - } - } - - protected void deepen() { - if (flat) - return; - checkEdited(); - try { - if (getEdited() instanceof Paragraph) { - Paragraph paragraph = (Paragraph) getEdited(); - Text text = (Text) paragraph.getControl(); - String txt = text.getText(); - Node paragraphNode = paragraph.getNode(); - Section section = paragraph.getSection(); - Node sectionNode = section.getNode(); - // main title - if (section == mainSection && section instanceof TextSection - && paragraphNode.getIndex() == 1 - && !sectionNode.hasProperty(JCR_TITLE)) { - SectionTitle sectionTitle = prepareSectionTitle(section, - txt); - edit(sectionTitle, 0); - return; - } - Node newSectionNode = sectionNode.addNode(CMS_H, - CmsTypes.CMS_SECTION); - sectionNode.orderBefore(h(newSectionNode.getIndex()), h(1)); - - int paragraphIndex = paragraphNode.getIndex(); - String sectionPath = sectionNode.getPath(); - String newSectionPath = newSectionNode.getPath(); - while (sectionNode.hasNode(p(paragraphIndex + 1))) { - Node parag = sectionNode.getNode(p(paragraphIndex + 1)); - sectionNode.getSession().move( - sectionPath + '/' + p(paragraphIndex + 1), - newSectionPath + '/' + CMS_P); - SectionPart sp = section.getSectionPart(parag - .getIdentifier()); - if (sp instanceof Control) - ((Control) sp).dispose(); - } - // create property - newSectionNode.setProperty(Property.JCR_TITLE, ""); - getTextInterpreter().write( - newSectionNode.getProperty(Property.JCR_TITLE), txt); - - TextSection newSection = new TextSection(section, - section.getStyle(), newSectionNode); - newSection.setLayoutData(CmsUiUtils.fillWidth()); - newSection.moveBelow(paragraph); - - // dispose - paragraphNode.remove(); - paragraph.dispose(); - - refresh(newSection); - newSection.getParent().layout(); - layout(newSection); - persistChanges(sectionNode); - } else if (getEdited() instanceof SectionTitle) { - SectionTitle sectionTitle = (SectionTitle) getEdited(); - Section section = sectionTitle.getSection(); - Section parentSection = section.getParentSection(); - if (parentSection == null) - return;// cannot deepen main section - Node sectionN = section.getNode(); - Node parentSectionN = parentSection.getNode(); - if (sectionN.getIndex() == 1) - return;// cannot deepen first section - Node previousSectionN = parentSectionN.getNode(h(sectionN - .getIndex() - 1)); - NodeIterator subSections = previousSectionN.getNodes(CMS_H); - int subsectionsCount = (int) subSections.getSize(); - previousSectionN.getSession().move( - sectionN.getPath(), - previousSectionN.getPath() + "/" - + h(subsectionsCount + 1)); - section.dispose(); - TextSection newSection = new TextSection(section, - section.getStyle(), sectionN); - refresh(newSection); - persistChanges(previousSectionN); - } - } catch (RepositoryException e) { - throw new CmsException("Cannot deepen " + getEdited(), e); - } - } - - protected void undeepen() { - if (flat) - return; - checkEdited(); - try { - if (getEdited() instanceof Paragraph) { - upload(getEdited()); - } else if (getEdited() instanceof SectionTitle) { - SectionTitle sectionTitle = (SectionTitle) getEdited(); - Section section = sectionTitle.getSection(); - Node sectionNode = section.getNode(); - Section parentSection = section.getParentSection(); - if (parentSection == null) - return;// cannot undeepen main section - - // choose in which section to merge - Section mergedSection; - if (sectionNode.getIndex() == 1) - mergedSection = section.getParentSection(); - else { - Map parentSubsections = parentSection - .getSubSections(); - ArrayList
lst = new ArrayList
( - parentSubsections.values()); - mergedSection = lst.get(sectionNode.getIndex() - 1); - } - Node mergedNode = mergedSection.getNode(); - boolean mergedHasSubSections = mergedNode.hasNode(CMS_H); - - // title as paragraph - Node newParagrapheNode = mergedNode.addNode(CMS_P); - newParagrapheNode.addMixin(CmsTypes.CMS_STYLED); - if (mergedHasSubSections) - mergedNode.orderBefore(p(newParagrapheNode.getIndex()), - h(1)); - String txt = getTextInterpreter().read( - sectionNode.getProperty(Property.JCR_TITLE)); - getTextInterpreter().write(newParagrapheNode, txt); - // move - NodeIterator paragraphs = sectionNode.getNodes(CMS_P); - while (paragraphs.hasNext()) { - Node p = paragraphs.nextNode(); - SectionPart sp = section.getSectionPart(p.getIdentifier()); - if (sp instanceof Control) - ((Control) sp).dispose(); - mergedNode.getSession().move(p.getPath(), - mergedNode.getPath() + '/' + CMS_P); - if (mergedHasSubSections) - mergedNode.orderBefore(p(p.getIndex()), h(1)); - } - - Iterator
subsections = section.getSubSections() - .values().iterator(); - // NodeIterator sections = sectionNode.getNodes(CMS_H); - while (subsections.hasNext()) { - Section subsection = subsections.next(); - Node s = subsection.getNode(); - mergedNode.getSession().move(s.getPath(), - mergedNode.getPath() + '/' + CMS_H); - subsection.dispose(); - } - - // remove section - section.getNode().remove(); - section.dispose(); - - refresh(mergedSection); - mergedSection.getParent().layout(); - layout(mergedSection); - persistChanges(mergedNode); - } - } catch (RepositoryException e) { - throw new CmsException("Cannot undeepen " + getEdited(), e); - } - } - - // UI CHANGES - protected Paragraph paragraphSplitted(Paragraph paragraph, Node newNode) - throws RepositoryException { - Section section = paragraph.getSection(); - updateContent(paragraph); - Paragraph newParagraph = newParagraph((TextSection) section, newNode); - newParagraph.setLayoutData(CmsUiUtils.fillWidth()); - newParagraph.moveBelow(paragraph); - layout(paragraph.getControl(), newParagraph.getControl()); - return newParagraph; - } - - protected Paragraph sectionTitleSplitted(SectionTitle sectionTitle, - Node newNode) throws RepositoryException { - updateContent(sectionTitle); - Paragraph newParagraph = newParagraph(sectionTitle.getSection(), - newNode); - // we assume beforeFirst is not null since there was a sectionTitle - newParagraph.moveBelow(sectionTitle.getSection().getHeader()); - layout(sectionTitle.getControl(), newParagraph.getControl()); - return newParagraph; - } - - protected Paragraph paragraphMergedWithPrevious(Paragraph removed, - Node remaining) throws RepositoryException { - Section section = removed.getSection(); - removed.dispose(); - - Paragraph paragraph = (Paragraph) section.getSectionPart(remaining - .getIdentifier()); - updateContent(paragraph); - layout(paragraph.getControl()); - return paragraph; - } - - protected void paragraphMergedWithNext(Paragraph remaining, - Paragraph removed) throws RepositoryException { - removed.dispose(); - updateContent(remaining); - layout(remaining.getControl()); - } - - // UTILITIES - protected String p(Integer index) { - StringBuilder sb = new StringBuilder(6); - sb.append(CMS_P).append('[').append(index).append(']'); - return sb.toString(); - } - - protected String h(Integer index) { - StringBuilder sb = new StringBuilder(5); - sb.append(CMS_H).append('[').append(index).append(']'); - return sb.toString(); - } - - // GETTERS / SETTERS - public Section getMainSection() { - return mainSection; - } - - public boolean isFlat() { - return flat; - } - - public TextInterpreter getTextInterpreter() { - return textInterpreter; - } - - // KEY LISTENER - @Override - public void keyPressed(KeyEvent ke) { - if (log.isTraceEnabled()) - log.trace(ke); - - if (getEdited() == null) - return; - boolean altPressed = (ke.stateMask & SWT.ALT) != 0; - boolean shiftPressed = (ke.stateMask & SWT.SHIFT) != 0; - boolean ctrlPressed = (ke.stateMask & SWT.CTRL) != 0; - - try { - // Common - if (ke.keyCode == SWT.ESC) { - cancelEdit(); - } else if (ke.character == '\r') { - splitEdit(); - } else if (ke.character == 'S') { - if (ctrlPressed) - saveEdit(); - } else if (ke.character == '\t') { - if (!shiftPressed) { - deepen(); - } else if (shiftPressed) { - undeepen(); - } - } else { - if (getEdited() instanceof Paragraph) { - Paragraph paragraph = (Paragraph) getEdited(); - Section section = paragraph.getSection(); - if (altPressed && ke.keyCode == SWT.ARROW_RIGHT) { - edit(section.nextSectionPart(paragraph), 0); - } else if (altPressed && ke.keyCode == SWT.ARROW_LEFT) { - edit(section.previousSectionPart(paragraph), 0); - } else if (ke.character == SWT.BS) { - Text text = (Text) paragraph.getControl(); - int caretPosition = text.getCaretPosition(); - if (caretPosition == 0) { - mergeWithPrevious(); - } - } else if (ke.character == SWT.DEL) { - Text text = (Text) paragraph.getControl(); - int caretPosition = text.getCaretPosition(); - int charcount = text.getCharCount(); - if (caretPosition == charcount) { - mergeWithNext(); - } - } - } - } - } catch (Exception e) { - ke.doit = false; - notifyEditionException(e); - } - } - - @Override - public void keyReleased(KeyEvent e) { - } - - // MOUSE LISTENER - @Override - protected MouseListener createMouseListener() { - return new ML(); - } - - private class ML extends MouseAdapter { - private static final long serialVersionUID = 8526890859876770905L; - - @Override - public void mouseDoubleClick(MouseEvent e) { - if (e.button == 1) { - Control source = (Control) e.getSource(); - if (getCmsEditable().canEdit()) { - if (getCmsEditable().isEditing() - && !(getEdited() instanceof Img)) { - if (source == mainSection) - return; - EditablePart part = findDataParent(source); - upload(part); - } else { - getCmsEditable().startEditing(); - } - } - } - } - - @Override - public void mouseDown(MouseEvent e) { - if (getCmsEditable().isEditing()) { - if (e.button == 1) { - Control source = (Control) e.getSource(); - EditablePart composite = findDataParent(source); - Point point = new Point(e.x, e.y); - if (!(composite instanceof Img)) - edit(composite, source.toDisplay(point)); - } else if (e.button == 3) { - EditablePart composite = findDataParent((Control) e - .getSource()); - if (styledTools != null) - styledTools.show(composite, new Point(e.x, e.y)); - } - } - } - - @Override - public void mouseUp(MouseEvent e) { - } - } - - // FILE UPLOAD LISTENER - private class FUL implements FileUploadListener { - public void uploadProgress(FileUploadEvent event) { - // TODO Monitor upload progress - } - - public void uploadFailed(FileUploadEvent event) { - throw new CmsException("Upload failed " + event, - event.getException()); - } - - public void uploadFinished(FileUploadEvent event) { - for (FileDetails file : event.getFileDetails()) { - if (log.isDebugEnabled()) - log.debug("Received: " + file.getFileName()); - } - mainSection.getDisplay().syncExec(new Runnable() { - @Override - public void run() { - saveEdit(); - } - }); - FileUploadHandler uploadHandler = (FileUploadHandler) event - .getSource(); - uploadHandler.dispose(); - } - } -} \ No newline at end of file diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsNames.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsNames.java deleted file mode 100644 index 1fb2988..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsNames.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.argeo.cms.text; - -/** JCR names. */ -public interface CmsNames { - /* - * TEXT - */ - public final static String CMS_DRAFTS = "cms:drafts"; - - public final static String CMS_P = "cms:p"; - public final static String CMS_H = "cms:h"; - - public final static String CMS_CONTENT = "cms:content"; - public final static String CMS_STYLE = "cms:style"; - - public final static String CMS_INDEX = "cms:index"; - - /* - * IMAGES - */ - public final static String CMS_IMAGE_WIDTH = "cms:imageWidth"; - public final static String CMS_IMAGE_HEIGHT = "cms:imageHeight"; - public final static String CMS_DATA = "cms:data"; -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTextImageManager.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTextImageManager.java deleted file mode 100644 index 865c2ce..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTextImageManager.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.argeo.cms.text; - -import java.io.IOException; - -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.RepositoryException; - -import org.argeo.cms.ui.util.DefaultImageManager; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; - -/** Manages only public images so far. */ -public class CmsTextImageManager extends DefaultImageManager { - @Override - public Point getImageSize(Node node) throws RepositoryException { - return new Point( - node.hasProperty(CmsNames.CMS_IMAGE_WIDTH) ? (int) node.getProperty(CmsNames.CMS_IMAGE_WIDTH).getLong() - : 0, - node.hasProperty(CmsNames.CMS_IMAGE_HEIGHT) - ? (int) node.getProperty(CmsNames.CMS_IMAGE_HEIGHT).getLong() - : 0); - } - - @Override - public Binary getImageBinary(Node node) throws RepositoryException { - Binary res = super.getImageBinary(node); - if (res == null && node.isNodeType(CmsTypes.CMS_STYLED) && node.hasProperty(CmsNames.CMS_DATA)) { - return node.getProperty(CmsNames.CMS_DATA).getBinary(); - } else { - return null; - } - } - - @Override - protected void processNewImageFile(Node context, - Node fileNode, ImageData id) - throws RepositoryException, IOException { - fileNode.addMixin(CmsTypes.CMS_IMAGE); - fileNode.setProperty(CmsNames.CMS_IMAGE_WIDTH, id.width); - fileNode.setProperty(CmsNames.CMS_IMAGE_HEIGHT, id.height); - - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTypes.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTypes.java deleted file mode 100644 index 3d856fd..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CmsTypes.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.argeo.cms.text; - -/** JCR types. */ -public interface CmsTypes { - public final static String CMS_TEXT = "cms:text"; - public final static String CMS_IMAGE = "cms:image"; - public final static String CMS_SECTION = "cms:section"; - public final static String CMS_STYLED = "cms:styled"; - -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CustomTextEditor.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CustomTextEditor.java deleted file mode 100644 index c7690c7..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/CustomTextEditor.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.argeo.cms.text; - -import static org.argeo.cms.ui.util.CmsUiUtils.fillWidth; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; - -import org.argeo.cms.ui.CmsEditable; -import org.argeo.cms.ui.viewers.Section; -import org.eclipse.swt.widgets.Composite; - -/** - * Manages hardcoded sections as an arbitrary hierarchy under the main section, - * which contains no text and no title. - */ -@Deprecated -public class CustomTextEditor extends AbstractTextViewer { - private static final long serialVersionUID = 5277789504209413500L; - - public CustomTextEditor(Composite parent, int style, Node textNode, - CmsEditable cmsEditable) throws RepositoryException { - this(new Section(parent, style, textNode), style, cmsEditable); - } - - public CustomTextEditor(Section mainSection, int style, - CmsEditable cmsEditable) throws RepositoryException { - super(mainSection, style, cmsEditable); - mainSection.setLayoutData(fillWidth()); - } - - @Override - public Section getMainSection() { - return super.getMainSection(); - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/IdentityTextInterpreter.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/IdentityTextInterpreter.java deleted file mode 100644 index ce59ed6..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/IdentityTextInterpreter.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.argeo.cms.text; - -import javax.jcr.Item; -import javax.jcr.Node; -import javax.jcr.Property; -import javax.jcr.RepositoryException; - -import org.argeo.cms.CmsException; - -/** Based on HTML with a few Wiki-like shortcuts. */ -public class IdentityTextInterpreter implements TextInterpreter, CmsNames { - - @Override - public void write(Item item, String content) { - try { - if (item instanceof Node) { - Node node = (Node) item; - if (node.isNodeType(CmsTypes.CMS_STYLED)) { - String raw = convertToStorage(node, content); - validateBeforeStoring(raw); - node.setProperty(CMS_CONTENT, raw); - } else { - throw new CmsException("Don't know how to interpret " + node); - } - } else {// property - Property property = (Property) item; - property.setValue(content); - } - // item.getSession().save(); - } catch (RepositoryException e) { - throw new CmsException("Cannot set content on " + item, e); - } - } - - @Override - public String readSimpleHtml(Item item) { - return raw(item); - } - - @Override - public String read(Item item) { - try { - String raw = raw(item); - return convertFromStorage(item, raw); - } catch (RepositoryException e) { - throw new CmsException("Cannot get " + item + " for edit", e); - } - } - - @Override - public String raw(Item item) { - try { - item.getSession().refresh(true); - if (item instanceof Node) { - Node node = (Node) item; - if (node.isNodeType(CmsTypes.CMS_STYLED)) { - // WORKAROUND FOR BROKEN PARARAPHS - if (!node.hasProperty(CMS_CONTENT)) { - node.setProperty(CMS_CONTENT, ""); - node.getSession().save(); - } - - return node.getProperty(CMS_CONTENT).getString(); - } else { - throw new CmsException("Don't know how to interpret " + node); - } - } else {// property - Property property = (Property) item; - return property.getString(); - } - } catch (RepositoryException e) { - throw new CmsException("Cannot get " + item + " content", e); - } - } - - // EXTENSIBILITY - /** - * To be overridden, in order to make sure that only valid strings are being - * stored. - */ - protected void validateBeforeStoring(String raw) { - } - - /** To be overridden, in order to support additional formatting. */ - 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 { - return content; - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/MarkupValidatorCopy.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/MarkupValidatorCopy.java deleted file mode 100644 index 1aee5d9..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/MarkupValidatorCopy.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.argeo.cms.text; - -import java.io.StringReader; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.rap.rwt.SingletonUtil; -import org.eclipse.swt.widgets.Widget; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Copy of RAP v2.3 since it is in an internal package. - */ -class MarkupValidatorCopy { - - // Used by Eclipse Scout project - public static final String MARKUP_VALIDATION_DISABLED = "org.eclipse.rap.rwt.markupValidationDisabled"; - - private static final String DTD = createDTD(); - private static final Map SUPPORTED_ELEMENTS = createSupportedElementsMap(); - private final SAXParser saxParser; - - public static MarkupValidatorCopy getInstance() { - return SingletonUtil.getSessionInstance(MarkupValidatorCopy.class); - } - - public MarkupValidatorCopy() { - saxParser = createSAXParser(); - } - - public void validate(String text) { - StringBuilder markup = new StringBuilder(); - markup.append(DTD); - markup.append(""); - markup.append(text); - markup.append(""); - InputSource inputSource = new InputSource(new StringReader(markup.toString())); - try { - saxParser.parse(inputSource, new MarkupHandler()); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw new IllegalArgumentException("Failed to parse markup text", exception); - } - } - - public static boolean isValidationDisabledFor(Widget widget) { - return Boolean.TRUE.equals(widget.getData(MARKUP_VALIDATION_DISABLED)); - } - - private static SAXParser createSAXParser() { - SAXParser result = null; - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - try { - result = parserFactory.newSAXParser(); - } catch (Exception exception) { - throw new RuntimeException("Failed to create SAX parser", exception); - } - return result; - } - - private static String createDTD() { - StringBuilder result = new StringBuilder(); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append(""); - result.append("]>"); - return result.toString(); - } - - private static Map createSupportedElementsMap() { - Map result = new HashMap(); - result.put("html", new String[0]); - result.put("br", new String[0]); - result.put("b", new String[] { "style" }); - result.put("strong", new String[] { "style" }); - result.put("i", new String[] { "style" }); - result.put("em", new String[] { "style" }); - result.put("sub", new String[] { "style" }); - result.put("sup", new String[] { "style" }); - result.put("big", new String[] { "style" }); - result.put("small", new String[] { "style" }); - result.put("del", new String[] { "style" }); - result.put("ins", new String[] { "style" }); - result.put("code", new String[] { "style" }); - result.put("samp", new String[] { "style" }); - result.put("kbd", new String[] { "style" }); - result.put("var", new String[] { "style" }); - result.put("cite", new String[] { "style" }); - result.put("dfn", new String[] { "style" }); - result.put("q", new String[] { "style" }); - result.put("abbr", new String[] { "style", "title" }); - result.put("span", new String[] { "style" }); - result.put("img", new String[] { "style", "src", "width", "height", "title", "alt" }); - result.put("a", new String[] { "style", "href", "target", "title" }); - return result; - } - - private static class MarkupHandler extends DefaultHandler { - - @Override - public void startElement(String uri, String localName, String name, Attributes attributes) { - checkSupportedElements(name, attributes); - checkSupportedAttributes(name, attributes); - checkMandatoryAttributes(name, attributes); - } - - private static void checkSupportedElements(String elementName, Attributes attributes) { - if (!SUPPORTED_ELEMENTS.containsKey(elementName)) { - throw new IllegalArgumentException("Unsupported element in markup text: " + elementName); - } - } - - private static void checkSupportedAttributes(String elementName, Attributes attributes) { - if (attributes.getLength() > 0) { - List supportedAttributes = Arrays.asList(SUPPORTED_ELEMENTS.get(elementName)); - int index = 0; - String attributeName = attributes.getQName(index); - while (attributeName != null) { - if (!supportedAttributes.contains(attributeName)) { - String message = "Unsupported attribute \"{0}\" for element \"{1}\" in markup text"; - message = MessageFormat.format(message, new Object[] { attributeName, elementName }); - throw new IllegalArgumentException(message); - } - index++; - attributeName = attributes.getQName(index); - } - } - } - - private static void checkMandatoryAttributes(String elementName, Attributes attributes) { - checkIntAttribute(elementName, attributes, "img", "width"); - checkIntAttribute(elementName, attributes, "img", "height"); - } - - private static void checkIntAttribute(String elementName, Attributes attributes, String checkedElementName, - String checkedAttributeName) { - if (checkedElementName.equals(elementName)) { - String attribute = attributes.getValue(checkedAttributeName); - try { - Integer.parseInt(attribute); - } catch (NumberFormatException exception) { - String message = "Mandatory attribute \"{0}\" for element \"{1}\" is missing or not a valid integer"; - Object[] arguments = new Object[] { checkedAttributeName, checkedElementName }; - message = MessageFormat.format(message, arguments); - throw new IllegalArgumentException(message); - } - } - } - - } - -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/SectionTitle.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/SectionTitle.java deleted file mode 100644 index 1a67c11..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/SectionTitle.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.argeo.cms.text; - -import javax.jcr.Property; -import javax.jcr.RepositoryException; - -import org.argeo.cms.ui.viewers.EditablePart; -import org.argeo.cms.ui.viewers.PropertyPart; -import org.argeo.cms.ui.widgets.EditableText; -import org.eclipse.swt.widgets.Composite; - -/** The title of a section. */ -@Deprecated -public class SectionTitle extends EditableText implements EditablePart, - PropertyPart { - private static final long serialVersionUID = -1787983154946583171L; - - private final TextSection section; - - public SectionTitle(Composite parent, int swtStyle, Property title) - throws RepositoryException { - super(parent, swtStyle, title); - section = (TextSection) TextSection.findSection(this); - } - - public TextSection getSection() { - return section; - } - - // @Override - // public Property getProperty() throws RepositoryException { - // return getSection().getNode().getProperty(Property.JCR_TITLE); - // } - - @Override - public Property getItem() throws RepositoryException { - return getProperty(); - } - -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/StandardTextEditor.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/StandardTextEditor.java deleted file mode 100644 index 3c3d16b..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/StandardTextEditor.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.argeo.cms.text; - -import static javax.jcr.Property.JCR_TITLE; - -import javax.jcr.Node; -import javax.jcr.Property; -import javax.jcr.RepositoryException; - -import org.argeo.cms.ui.CmsEditable; -import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.cms.ui.viewers.Section; -import org.eclipse.swt.widgets.Composite; - -/** Text editor where sections and subsections can be managed by the user. */ -@Deprecated -public class StandardTextEditor extends AbstractTextViewer { - private static final long serialVersionUID = 6049661610883342325L; - - public StandardTextEditor(Composite parent, int style, Node textNode, - CmsEditable cmsEditable) throws RepositoryException { - super(new TextSection(parent, style, textNode), style, cmsEditable); - refresh(); - getMainSection().setLayoutData(CmsUiUtils.fillWidth()); - } - - @Override - protected void initModel(Node textNode) throws RepositoryException { - if (isFlat()) - textNode.addNode(CMS_P).addMixin(CmsTypes.CMS_STYLED); - else - textNode.setProperty(JCR_TITLE, textNode.getName()); - } - - @Override - protected Boolean isModelInitialized(Node textNode) - throws RepositoryException { - return textNode.hasProperty(Property.JCR_TITLE) - || textNode.hasNode(CMS_P) - || (!isFlat() && textNode.hasNode(CMS_H)); - } - - @Override - public Section getMainSection() { - // TODO Auto-generated method stub - return super.getMainSection(); - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextContextMenu.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextContextMenu.java deleted file mode 100644 index f9cdbb5..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextContextMenu.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.argeo.cms.text; - -import java.util.ArrayList; -import java.util.List; - -import org.argeo.cms.ui.viewers.EditablePart; -import org.argeo.cms.ui.viewers.SectionPart; -import org.argeo.cms.ui.widgets.TextStyles; -import org.eclipse.rap.rwt.RWT; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** Dialog to edit a text part. */ -@Deprecated -class TextContextMenu extends Shell implements CmsNames, TextStyles { - private final static String[] DEFAULT_TEXT_STYLES = { - TextStyles.TEXT_DEFAULT, TextStyles.TEXT_PRE, TextStyles.TEXT_QUOTE }; - - private final AbstractTextViewer textViewer; - - private static final long serialVersionUID = -3826246895162050331L; - private List styleButtons = new ArrayList(); - - private Label deleteButton, publishButton, editButton; - - private EditablePart currentTextPart; - - public TextContextMenu(AbstractTextViewer textViewer, Display display) { - super(display, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); - this.textViewer = textViewer; - setLayout(new GridLayout()); - setData(RWT.CUSTOM_VARIANT, TEXT_STYLED_TOOLS_DIALOG); - - StyledToolMouseListener stml = new StyledToolMouseListener(); - if (textViewer.getCmsEditable().isEditing()) { - for (String style : DEFAULT_TEXT_STYLES) { - StyleButton styleButton = new StyleButton(this, SWT.WRAP); - styleButton.setData(RWT.CUSTOM_VARIANT, style); - styleButton.setData(RWT.MARKUP_ENABLED, true); - styleButton.addMouseListener(stml); - styleButtons.add(styleButton); - } - - // Delete - deleteButton = new Label(this, SWT.NONE); - deleteButton.setText("Delete"); - deleteButton.addMouseListener(stml); - - // Publish - publishButton = new Label(this, SWT.NONE); - publishButton.setText("Publish"); - publishButton.addMouseListener(stml); - } else if (textViewer.getCmsEditable().canEdit()) { - // Edit - editButton = new Label(this, SWT.NONE); - editButton.setText("Edit"); - editButton.addMouseListener(stml); - } - addShellListener(new ToolsShellListener()); - } - - public void show(EditablePart source, Point location) { - if (isVisible()) - setVisible(false); - - this.currentTextPart = source; - - if (currentTextPart instanceof Paragraph) { - final int size = 32; - String text = textViewer - .getRawParagraphText((Paragraph) currentTextPart); - String textToShow = text.length() > size ? text.substring(0, - size - 3) + "..." : text; - for (StyleButton styleButton : styleButtons) { - styleButton.setText(textToShow); - } - } - pack(); - layout(); - if (source instanceof Control) - setLocation(((Control) source).toDisplay(location.x, location.y)); - open(); - } - - class StyleButton extends Label { - private static final long serialVersionUID = 7731102609123946115L; - - public StyleButton(Composite parent, int swtStyle) { - super(parent, swtStyle); - } - - } - - class StyledToolMouseListener extends MouseAdapter { - private static final long serialVersionUID = 8516297091549329043L; - - @Override - public void mouseDown(MouseEvent e) { - Object eventSource = e.getSource(); - if (eventSource instanceof StyleButton) { - StyleButton sb = (StyleButton) e.getSource(); - String style = sb.getData(RWT.CUSTOM_VARIANT).toString(); - textViewer - .setParagraphStyle((Paragraph) currentTextPart, style); - } else if (eventSource == deleteButton) { - textViewer.deletePart((SectionPart) currentTextPart); - } else if (eventSource == editButton) { - textViewer.getCmsEditable().startEditing(); - } else if (eventSource == publishButton) { - textViewer.getCmsEditable().stopEditing(); - } - setVisible(false); - } - } - - class ToolsShellListener extends org.eclipse.swt.events.ShellAdapter { - private static final long serialVersionUID = 8432350564023247241L; - - @Override - public void shellDeactivated(ShellEvent e) { - setVisible(false); - } - - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreterImpl.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreterImpl.java deleted file mode 100644 index 813fa0f..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreterImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.argeo.cms.text; - -import javax.jcr.Item; -import javax.jcr.RepositoryException; - -/** - * Text interpreter that sanitise and validates before saving, and support CMS - * specific formatting and integration. - */ -class TextInterpreterImpl extends IdentityTextInterpreter { - private MarkupValidatorCopy markupValidator = MarkupValidatorCopy.getInstance(); - - @Override - protected void validateBeforeStoring(String raw) { - markupValidator.validate(raw); - } - - @Override - protected String convertToStorage(Item item, String content) throws RepositoryException { - return super.convertToStorage(item, content); - } - - @Override - protected String convertFromStorage(Item item, String content) throws RepositoryException { - return super.convertFromStorage(item, content); - } - -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/WikiPage.java b/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/WikiPage.java deleted file mode 100644 index ac0fe50..0000000 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/WikiPage.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.argeo.cms.text; - -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.nodetype.NodeType; - -import org.argeo.cms.ui.CmsEditable; -import org.argeo.cms.ui.CmsUiProvider; -import org.argeo.cms.ui.util.CmsLink; -import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.cms.ui.viewers.JcrVersionCmsEditable; -import org.argeo.cms.ui.widgets.ScrolledPage; -import org.argeo.jcr.JcrUtils; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -/** Display the text of the context, and provide an editor if the user can edit. */ -public class WikiPage implements CmsUiProvider, CmsNames { - @Override - public Control createUi(Composite parent, Node context) - throws RepositoryException { - CmsEditable cmsEditable = new JcrVersionCmsEditable(context); - if (cmsEditable.canEdit()) - new TextEditorHeader(cmsEditable, parent, SWT.NONE) - .setLayoutData(CmsUiUtils.fillWidth()); - - ScrolledPage page = new ScrolledPage(parent, SWT.NONE); - page.setLayout(CmsUiUtils.noSpaceGridLayout()); - GridData textGd = CmsUiUtils.fillAll(); - page.setLayoutData(textGd); - - if (context.isNodeType(CmsTypes.CMS_TEXT)) { - new StandardTextEditor(page, SWT.NONE, context, cmsEditable); - } else if (context.isNodeType(NodeType.NT_FOLDER) - || context.getPath().equals("/")) { - parent.setBackgroundMode(SWT.INHERIT_NONE); - if (context.getSession().hasPermission(context.getPath(), - Session.ACTION_ADD_NODE)) { - Node indexNode = JcrUtils.getOrAdd(context, CMS_INDEX, - CmsTypes.CMS_TEXT); - new StandardTextEditor(page, SWT.NONE, indexNode, cmsEditable); - textGd.heightHint = 400; - - for (NodeIterator ni = context.getNodes(); ni.hasNext();) { - Node textNode = ni.nextNode(); - if (textNode.isNodeType(NodeType.NT_FOLDER)) - new CmsLink(textNode.getName() + "/", - textNode.getPath()).createUi(parent, textNode); - } - for (NodeIterator ni = context.getNodes(); ni.hasNext();) { - Node textNode = ni.nextNode(); - if (textNode.isNodeType(CmsTypes.CMS_TEXT) - && !textNode.getName().equals(CMS_INDEX)) - new CmsLink(textNode.getName(), textNode.getPath()) - .createUi(parent, textNode); - } - } - } - return page; - } -} diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java index 044b675..656dd01 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java @@ -19,9 +19,6 @@ import javax.jcr.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.cms.text.Paragraph; -import org.argeo.cms.text.TextInterpreter; -import org.argeo.cms.text.TextSection; import org.argeo.cms.ui.CmsEditable; import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.cms.ui.viewers.AbstractPageViewer; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java index 77248d6..57c8356 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkContextMenu.java @@ -5,8 +5,6 @@ import java.util.List; import javax.jcr.Node; -import org.argeo.cms.text.Paragraph; -import org.argeo.cms.text.TextSection; import org.argeo.cms.ui.CmsEditable; import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.cms.ui.viewers.EditablePart; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkTextInterpreter.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkTextInterpreter.java index 1781050..d56bbf7 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkTextInterpreter.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkTextInterpreter.java @@ -7,11 +7,9 @@ import static org.argeo.docbook.DbkUtils.isDbk; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.Reader; import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.List; -import java.util.UUID; import javax.jcr.ImportUUIDBehavior; import javax.jcr.Item; @@ -20,22 +18,13 @@ import javax.jcr.NodeIterator; import javax.jcr.Property; import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; -import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.io.IOUtils; -import org.argeo.cms.text.TextInterpreter; import org.argeo.docbook.DbkAttr; import org.argeo.docbook.DbkType; import org.argeo.jcr.Jcr; import org.argeo.jcr.JcrException; -import org.argeo.jcr.JcrxType; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** Based on HTML with a few Wiki-like shortcuts. */ public class DbkTextInterpreter implements TextInterpreter { 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 index 61a9164..4a46fbb 100644 --- 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 @@ -3,7 +3,6 @@ package org.argeo.docbook.ui; import javax.jcr.Node; 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; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentPage.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentPage.java index 8ba6085..97ce2d2 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentPage.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentPage.java @@ -6,7 +6,6 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; -import org.argeo.cms.text.TextEditorHeader; import org.argeo.cms.ui.CmsEditable; import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ui.util.CmsLink; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentTextEditor.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentTextEditor.java index bac3fc3..bd7534e 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentTextEditor.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DocumentTextEditor.java @@ -3,7 +3,6 @@ package org.argeo.docbook.ui; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.cms.text.TextSection; import org.argeo.cms.ui.CmsEditable; import org.argeo.cms.ui.util.CmsUiUtils; import org.argeo.docbook.DbkUtils; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/Paragraph.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/Paragraph.java similarity index 96% rename from publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/Paragraph.java rename to publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/Paragraph.java index cfd0272..8f9542c 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/Paragraph.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/Paragraph.java @@ -1,4 +1,4 @@ -package org.argeo.cms.text; +package org.argeo.docbook.ui; import javax.jcr.Node; import javax.jcr.RepositoryException; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextEditorHeader.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextEditorHeader.java similarity index 98% rename from publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextEditorHeader.java rename to publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextEditorHeader.java index d10395b..eac75f9 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextEditorHeader.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextEditorHeader.java @@ -1,4 +1,4 @@ -package org.argeo.cms.text; +package org.argeo.docbook.ui; import java.util.Observable; import java.util.Observer; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreter.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextInterpreter.java similarity index 89% rename from publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreter.java rename to publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextInterpreter.java index 5c94e66..785d71e 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextInterpreter.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextInterpreter.java @@ -1,4 +1,4 @@ -package org.argeo.cms.text; +package org.argeo.docbook.ui; import javax.jcr.Item; diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextSection.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java similarity index 98% rename from publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextSection.java rename to publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java index 894a2cf..cb2e309 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/cms/text/TextSection.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/TextSection.java @@ -1,4 +1,4 @@ -package org.argeo.cms.text; +package org.argeo.docbook.ui; import javax.jcr.Node; -- 2.30.2