From: Mathieu Baudier Date: Wed, 1 Jan 2020 11:12:00 +0000 (+0100) Subject: Introduce examples. X-Git-Tag: argeo-commons-2.1.85~51 X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=cb244985c93c4003dee97ad26eed7fb814f71986 Introduce examples. --- diff --git a/demo/cms-e4-rap.properties b/demo/cms-e4-rap.properties index e8f245840..785b4b620 100644 --- a/demo/cms-e4-rap.properties +++ b/demo/cms-e4-rap.properties @@ -14,6 +14,9 @@ org.argeo.cms argeo.osgi.start.5.node=\ org.argeo.cms.e4.rap +argeo.osgi.start.5.example=\ +org.argeo.example.cms.e4 + # Local argeo.node.repo.type=h2 org.osgi.service.http.port=7070 diff --git a/example/org.argeo.example.cms.e4/.classpath b/example/org.argeo.example.cms.e4/.classpath new file mode 100644 index 000000000..e801ebfb4 --- /dev/null +++ b/example/org.argeo.example.cms.e4/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/example/org.argeo.example.cms.e4/.gitignore b/example/org.argeo.example.cms.e4/.gitignore new file mode 100644 index 000000000..09e3bc9b2 --- /dev/null +++ b/example/org.argeo.example.cms.e4/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/example/org.argeo.example.cms.e4/.project b/example/org.argeo.example.cms.e4/.project new file mode 100644 index 000000000..a5d18ddb9 --- /dev/null +++ b/example/org.argeo.example.cms.e4/.project @@ -0,0 +1,33 @@ + + + org.argeo.example.cms.e4 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/example/org.argeo.example.cms.e4/META-INF/.gitignore b/example/org.argeo.example.cms.e4/META-INF/.gitignore new file mode 100644 index 000000000..4854a41b9 --- /dev/null +++ b/example/org.argeo.example.cms.e4/META-INF/.gitignore @@ -0,0 +1 @@ +/MANIFEST.MF diff --git a/example/org.argeo.example.cms.e4/OSGI-INF/cms-example-rap.xml b/example/org.argeo.example.cms.e4/OSGI-INF/cms-example-rap.xml new file mode 100644 index 000000000..4fb099adf --- /dev/null +++ b/example/org.argeo.example.cms.e4/OSGI-INF/cms-example-rap.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/example/org.argeo.example.cms.e4/bnd.bnd b/example/org.argeo.example.cms.e4/bnd.bnd new file mode 100644 index 000000000..ffcf95d94 --- /dev/null +++ b/example/org.argeo.example.cms.e4/bnd.bnd @@ -0,0 +1,4 @@ + +Service-Component: OSGI-INF/cms-example-rap.xml + +Import-Package: org.argeo.cms.e4.rap,* \ No newline at end of file diff --git a/example/org.argeo.example.cms.e4/build.properties b/example/org.argeo.example.cms.e4/build.properties new file mode 100644 index 000000000..92a7ee74b --- /dev/null +++ b/example/org.argeo.example.cms.e4/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/cms-example-rap.xml +source.. = src/ diff --git a/example/org.argeo.example.cms.e4/e4xmi/text.e4xmi b/example/org.argeo.example.cms.e4/e4xmi/text.e4xmi new file mode 100644 index 000000000..1ecd7fc59 --- /dev/null +++ b/example/org.argeo.example.cms.e4/e4xmi/text.e4xmi @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/org.argeo.example.cms.e4/pom.xml b/example/org.argeo.example.cms.e4/pom.xml new file mode 100644 index 000000000..ec0872172 --- /dev/null +++ b/example/org.argeo.example.cms.e4/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + org.argeo.commons.example + argeo-commons-example + 2.1.85-SNAPSHOT + .. + + org.argeo.example.cms.e4 + Example CMS E4 + jar + + + org.argeo.commons + org.argeo.cms.ui + 2.1.85-SNAPSHOT + + + + + org.argeo.commons + org.argeo.eclipse.ui.rap + 2.1.85-SNAPSHOT + provided + + + org.argeo.tp + argeo-tp-rap-e4 + ${version.argeo-tp} + pom + provided + + + \ No newline at end of file diff --git a/example/org.argeo.example.data/.project b/example/org.argeo.example.data/.project new file mode 100644 index 000000000..3ead5b0f9 --- /dev/null +++ b/example/org.argeo.example.data/.project @@ -0,0 +1,22 @@ + + + org.argeo.example.data + + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + + diff --git a/example/org.argeo.example.data/META-INF/.gitignore b/example/org.argeo.example.data/META-INF/.gitignore new file mode 100644 index 000000000..4854a41b9 --- /dev/null +++ b/example/org.argeo.example.data/META-INF/.gitignore @@ -0,0 +1 @@ +/MANIFEST.MF diff --git a/example/org.argeo.example.data/build.properties b/example/org.argeo.example.data/build.properties new file mode 100644 index 000000000..5f22cdd44 --- /dev/null +++ b/example/org.argeo.example.data/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/example/org.argeo.example.data/text/LoremIpsum-flat.dbk.xml b/example/org.argeo.example.data/text/LoremIpsum-flat.dbk.xml new file mode 100644 index 000000000..a851f3d93 --- /dev/null +++ b/example/org.argeo.example.data/text/LoremIpsum-flat.dbk.xml @@ -0,0 +1,61 @@ + +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus + sed dolor nisl. Nullam vitae odio sagittis, cursus urna ut, fringilla + dui. Nunc aliquet laoreet ligula ut lobortis. Suspendisse at elit sed + ipsum volutpat aliquet ut ac lacus. Cras eget vulputate dolor, sed + faucibus ante. Donec sagittis, augue sed consectetur viverra, dolor + nisi efficitur erat, non pellentesque purus libero ac tortor. Aenean + ac augue eget lectus vulputate ullamcorper. Cras a erat massa. Nam + malesuada tortor vel ullamcorper interdum. Quisque lacinia tristique + quam, quis tristique mauris pellentesque eu. Maecenas sit amet dui sed + nulla vehicula vehicula. Sed nibh sapien, rutrum vestibulum diam nec, + vulputate volutpat ipsum. Class aptent taciti sociosqu ad litora + torquent per conubia nostra, per inceptos himenaeos. + + Donec vitae sodales turpis, et congue nisl. Donec a scelerisque + justo. Quisque posuere bibendum nibh, ac gravida nunc sollicitudin + ultricies. Maecenas blandit urna in massa luctus placerat. Nam ornare + orci quis ligula dignissim placerat. Sed quis elit ultrices, volutpat + est vitae, mollis turpis. Donec vel efficitur urna. Vivamus sit amet + vehicula lacus. Donec nec dui erat. Proin congue ac odio ut congue. + Nunc porta dui ac leo accumsan, non rutrum enim luctus. Sed semper + risus et augue pretium, sit amet viverra eros placerat. Sed in + lobortis nulla. Donec consequat, nunc egestas blandit imperdiet, + lectus felis mattis est, quis lobortis magna augue non odio. + Vestibulum vel mattis nibh, non facilisis orci. + + Proin id leo est. Quisque laoreet molestie sodales. Phasellus + volutpat elit metus, a placerat tellus hendrerit vitae. Aenean quis + odio pharetra, consectetur tortor et, fermentum dolor. Mauris vel + auctor enim. Donec leo nulla, finibus id lectus nec, dictum gravida + quam. Sed scelerisque leo ligula, sit amet viverra mauris convallis + posuere. Mauris pulvinar, est id lacinia cursus, lacus nisi vehicula + erat, nec ornare ante dolor auctor mauris. Quisque sed congue elit. + + Aenean porttitor eget purus a cursus. Maecenas viverra libero + tellus, eget imperdiet dui suscipit at. Cras vel felis in ante + fringilla suscipit. Phasellus ornare arcu ligula, sed venenatis turpis + commodo quis. Integer tortor nisl, faucibus mollis nulla sed, rhoncus + elementum leo. Vestibulum ante ipsum primis in faucibus orci luctus et + ultrices posuere cubilia Curae; Praesent placerat ullamcorper commodo. + Morbi vel mollis lectus. Suspendisse potenti. Donec quis cursus + tortor. Etiam turpis tellus, vehicula a urna et, convallis semper + lectus. Phasellus fermentum est ac euismod congue. + + Vivamus non nisl vel ipsum porta molestie pharetra et mi. Sed + volutpat, mauris et euismod ultricies, turpis ex maximus augue, nec + tempus neque elit non velit. Mauris elementum, urna eget luctus + molestie, nunc sapien molestie odio, vel vehicula dolor massa at eros. + Etiam magna dui, pulvinar at purus non, suscipit imperdiet mi. + Vestibulum nec quam risus. Integer dui sapien, tincidunt id augue et, + iaculis porttitor felis. Donec quis enim vel tellus euismod molestie. + Fusce venenatis nunc nec dui molestie, sit amet porttitor elit + feugiat. Quisque eu odio placerat, maximus lectus at, fringilla dolor. + Nam a mollis purus. Curabitur eu lorem nisl. Suspendisse enim eros, + rutrum quis egestas ac, fringilla sollicitudin velit. Praesent + faucibus neque eu ligula pellentesque porta in in nibh. Ut vitae + mauris ac ante pharetra blandit non in dui. Ut euismod quam et diam + imperdiet, eu mollis ex pulvinar. + +
\ No newline at end of file diff --git a/example/org.argeo.example.data/text/empty.dbk.xml b/example/org.argeo.example.data/text/empty.dbk.xml new file mode 100644 index 000000000..71c262407 --- /dev/null +++ b/example/org.argeo.example.data/text/empty.dbk.xml @@ -0,0 +1,7 @@ + +
+ +
\ No newline at end of file diff --git a/example/pom.xml b/example/pom.xml new file mode 100644 index 000000000..3bb73425a --- /dev/null +++ b/example/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + org.argeo.commons + argeo-commons + 2.1.85-SNAPSHOT + .. + + org.argeo.commons.example + argeo-commons-example + Commons Example + pom + + org.argeo.example.cms.e4 + + \ No newline at end of file diff --git a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/AbstractRapE4App.java b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/AbstractRapE4App.java index c293f1ab0..8bf16a265 100644 --- a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/AbstractRapE4App.java +++ b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/AbstractRapE4App.java @@ -10,6 +10,7 @@ import org.eclipse.rap.rwt.application.Application.OperationMode; import org.eclipse.rap.rwt.application.ApplicationConfiguration; import org.eclipse.rap.rwt.application.ExceptionHandler; import org.eclipse.rap.rwt.client.WebClient; +import org.osgi.framework.BundleContext; /** Base class for CMS RAP applications. */ public abstract class AbstractRapE4App implements ApplicationConfiguration { @@ -17,7 +18,18 @@ public abstract class AbstractRapE4App implements ApplicationConfiguration { private String path; private String lifeCycleUri = "bundleclass://org.argeo.cms.e4.rap/org.argeo.cms.e4.rap.CmsLoginLifecycle"; - Map baseProperties = new HashMap(); + private Map baseProperties = new HashMap(); + + private BundleContext bundleContext; + private final static String CONTEXT_NAME_PROPERTY = "contextName"; + private String contextName; + + /** + * To be overridden in order to add multiple entry points, directly or using + * {@link #addE4EntryPoint(Application, String, String, Map)}. + */ + protected void addEntryPoints(Application application) { + } public void configure(Application application) { application.setExceptionHandler(new ExceptionHandler() { @@ -35,14 +47,6 @@ public abstract class AbstractRapE4App implements ApplicationConfiguration { } } - /** - * To be overridden in order to add multiple entry points, directly or using - * {@link #addE4EntryPoint(Application, String, String, Map)}. - */ - protected void addEntryPoints(Application application) { - - } - protected Map getBaseProperties() { return baseProperties; } @@ -97,12 +101,28 @@ public abstract class AbstractRapE4App implements ApplicationConfiguration { this.lifeCycleUri = lifeCycleUri; } - public void init(Map properties) { + protected BundleContext getBundleContext() { + return bundleContext; + } + + protected String getContextName() { + return contextName; + } + + public void init(BundleContext bundleContext, Map properties) { + this.bundleContext = bundleContext; for (String key : properties.keySet()) { Object value = properties.get(key); if (value != null) baseProperties.put(key, value.toString()); } + + if (properties.containsKey(CONTEXT_NAME_PROPERTY)) { + assert properties.get(CONTEXT_NAME_PROPERTY) != null; + contextName = properties.get(CONTEXT_NAME_PROPERTY).toString(); + } else { + contextName = ""; + } } public void destroy(Map properties) { diff --git a/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/SimpleRapE4App.java b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/SimpleRapE4App.java new file mode 100644 index 000000000..12c4f6336 --- /dev/null +++ b/org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/SimpleRapE4App.java @@ -0,0 +1,33 @@ +package org.argeo.cms.e4.rap; + +import java.util.Enumeration; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.rap.rwt.application.Application; +import org.osgi.framework.Bundle; + +/** Simple RAP app which loads all e4xmi files. */ +public class SimpleRapE4App extends AbstractRapE4App { + private final static Log log = LogFactory.getLog(SimpleRapE4App.class); + + private String baseE4xmi = "/e4xmi"; + + @Override + protected void addEntryPoints(Application application) { + Bundle bundle = getBundleContext().getBundle(); + Enumeration paths = bundle.getEntryPaths(baseE4xmi); + while (paths.hasMoreElements()) { + String p = paths.nextElement(); + if (p.endsWith(".e4xmi")) { + String e4xmiPath = bundle.getSymbolicName() + '/' + p; + String name = '/' + FilenameUtils.removeExtension(FilenameUtils.getName(p)); + addE4EntryPoint(application, name, e4xmiPath, getBaseProperties()); + if (log.isDebugEnabled()) + log.debug("Registered " + e4xmiPath + " as " + getContextName() + name); + } + } + } + +} diff --git a/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/CmsDocBookEditor.java b/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/CmsDocBookEditor.java index b39feab14..ae77e1e5b 100644 --- a/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/CmsDocBookEditor.java +++ b/org.argeo.cms.e4/src/org/argeo/cms/e4/parts/CmsDocBookEditor.java @@ -1,21 +1,27 @@ package org.argeo.cms.e4.parts; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Map; import java.util.Observable; import java.util.Observer; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.inject.Inject; +import javax.jcr.ImportUUIDBehavior; import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; -import javax.jcr.nodetype.NodeType; +import org.apache.commons.logging.Log; import org.argeo.cms.CmsException; import org.argeo.cms.text.DocumentTextEditor; import org.argeo.cms.viewers.JcrVersionCmsEditable; import org.argeo.jcr.JcrUtils; +import org.argeo.jcr.docbook.DocBookNames; import org.argeo.jcr.docbook.DocBookTypes; import org.eclipse.e4.ui.di.Persist; import org.eclipse.e4.ui.model.application.ui.basic.MPart; @@ -37,16 +43,41 @@ public class CmsDocBookEditor implements Observer { public void createUI(Composite parent) { try { parent.setLayout(new GridLayout()); - session = repository.login(); - JcrUtils.loginOrCreateWorkspace(repository, "demo"); - Node textNode = JcrUtils.getOrAdd(session.getRootNode(), "article", DocBookTypes.ARTICLE); - if (textNode.isCheckedOut()) - textNode.addMixin(NodeType.MIX_TITLE); + // session = repository.login(); + session = JcrUtils.loginOrCreateWorkspace(repository, "example"); +// Node textNode = JcrUtils.getOrAdd(session.getRootNode(), "article", DocBookTypes.ARTICLE); +// if (textNode.isCheckedOut()) +// textNode.addMixin(NodeType.MIX_TITLE); + + String textNodeName = "docbook"; + if (session.getRootNode().hasNode(textNodeName)) + session.getRootNode().getNode(textNodeName).remove(); + + Node textNode = JcrUtils.getOrAdd(session.getRootNode(), textNodeName, DocBookTypes.BOOK); + Map properties = mpart.getProperties(); + String defaultContentUri = properties.get("defaultContentUri"); + if (textNode.hasNode(DocBookNames.DBK_ARTICLE)) + textNode.getNode(DocBookNames.DBK_ARTICLE).remove(); + if (defaultContentUri != null && !textNode.hasNode(DocBookNames.DBK_ARTICLE)) + try { + URL url = new URL(defaultContentUri); + try (InputStream in = url.openStream()) { + session.importXML(textNode.getPath(), in, + ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); + } + Node dbkNode = textNode.getNode(DocBookNames.DBK_ARTICLE); + if (dbkNode.isNodeType(DocBookTypes.ARTICLE)) + System.out.println(dbkNode + " is an article"); + } catch (IOException e) { + e.printStackTrace(); + } + cmsEditable = new JcrVersionCmsEditable(textNode); if (session.hasPendingChanges()) session.save(); cmsEditable.addObserver(this); - DocumentTextEditor textEditor = new DocumentTextEditor(parent, SWT.NONE, textNode, cmsEditable); + DocumentTextEditor textEditor = new DocumentTextEditor(parent, SWT.NONE, + textNode.getNode(DocBookNames.DBK_ARTICLE), cmsEditable); mpart.setDirty(isDirty()); } catch (RepositoryException e) { throw new CmsException("Cannot create text editor", e); diff --git a/org.argeo.cms.ui/src/org/argeo/cms/viewers/AbstractPageViewer.java b/org.argeo.cms.ui/src/org/argeo/cms/viewers/AbstractPageViewer.java index 492203b44..eaaf4bc3f 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/viewers/AbstractPageViewer.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/viewers/AbstractPageViewer.java @@ -280,9 +280,9 @@ public abstract class AbstractPageViewer extends ContentViewer implements Observ if (e instanceof IllegalArgumentException) if (e.getCause() instanceof SAXParseException) eToLog = e.getCause(); - log.error(eToLog.getMessage()); - if (log.isTraceEnabled()) - log.trace("Full stack of " + eToLog.getMessage(), e); + log.error(eToLog.getMessage(), eToLog); +// if (log.isTraceEnabled()) +// log.trace("Full stack of " + eToLog.getMessage(), e); // TODO Light error notification popup } diff --git a/pom.xml b/pom.xml index 93900e68c..100105e49 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,8 @@ org.argeo.ext.jackrabbit org.argeo.ext.equinox.jetty + + example legacy