Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for server-side creation of the html page rather than working cli…

…ent side
  • Loading branch information...
commit 041c2f226905443804ade817e42662a02b204e50 1 parent b2c80bd
@atoulme atoulme authored
View
46 src/main/java/com/intalio/web/plugin/impl/PluginServiceImpl.java
@@ -25,7 +25,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
@@ -58,26 +57,38 @@
*/
public class PluginServiceImpl implements IDiagramPluginService {
+ private static PluginServiceImpl _instance = null;
+
+ /**
+ * @param context the context needed for initialization
+ * @return the singleton of PluginServiceImpl
+ */
+ public static IDiagramPluginService getInstance(
+ ServletContext context) {
+ if (_instance == null) {
+ _instance = new PluginServiceImpl(context);
+ }
+ return _instance;
+ }
+
/**
- * The default local plugins, available to the webapp so that the default profile
- * can provision its plugins. Consumers through OSGi should use the service tracker
+ * The default local plugins, available to the webapp
+ * so that the default profile can provision its plugins.
+ * Consumers through OSGi should use the service tracker
* to get the plugins they need.
*/
private static Map<String, IDiagramPlugin> LOCAL = null;
/**
- * an object to lock over the local plugins registry.
- * Several servlets will have interest over the local plugin registry,
- * which requires the servlet context to initialize itself.
- * To avoid double initialization, we lock over this object.
+ * Initialize the local plugins registry
+ * @param context the servlet context necessary to grab
+ * the files inside the servlet.
+ * @return the set of local plugins organized by name
*/
- private static Object lock = new Object();
-
- public static Map<String, IDiagramPlugin> getLocalPluginsRegistry(ServletContext context) {
- synchronized(lock) {
- if (LOCAL == null) {
- LOCAL = initializeLocalPlugins(context);
- }
+ public static Map<String, IDiagramPlugin>
+ getLocalPluginsRegistry(ServletContext context) {
+ if (LOCAL == null) {
+ LOCAL = initializeLocalPlugins(context);
}
return LOCAL;
}
@@ -150,7 +161,12 @@
private Map<String, IDiagramPlugin> _registry = new HashMap<String, IDiagramPlugin>();
private Set<IDiagramPluginFactory> _factories = new HashSet<IDiagramPluginFactory>();
- public PluginServiceImpl(ServletContext context) {
+ /**
+ * Private constructor to make sure we respect the singleton
+ * pattern.
+ * @param context the servlet context
+ */
+ private PluginServiceImpl(ServletContext context) {
_registry.putAll(getLocalPluginsRegistry(context));
// if we are in the OSGi world:
if (getClass().getClassLoader() instanceof BundleReference) {
View
39 src/main/java/com/intalio/web/plugin/impl/PluginServiceServlet.java
@@ -39,6 +39,7 @@
import org.slf4j.LoggerFactory;
import com.intalio.web.plugin.IDiagramPlugin;
+import com.intalio.web.plugin.IDiagramPluginService;
/**
* This servlet exposes the plugins registered against the platforms.
@@ -53,18 +54,22 @@
*/
public class PluginServiceServlet extends HttpServlet {
- private static final Logger _logger = LoggerFactory.getLogger(PluginServiceServlet.class);
+ private static final Logger _logger = LoggerFactory.getLogger(
+ PluginServiceServlet.class);
private static final long serialVersionUID = -2024110864538877629L;
- private PluginServiceImpl _pluginService;
+ private IDiagramPluginService _pluginService;
public void init(ServletConfig config) throws ServletException {
super.init(config);
- _pluginService = new PluginServiceImpl(config.getServletContext());
+ _pluginService = PluginServiceImpl.getInstance(
+ config.getServletContext());
}
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ protected void doGet(HttpServletRequest req,
+ HttpServletResponse resp)
+ throws ServletException, IOException {
try {
if ((EditorHandler.oryx_path + "plugins").equals(req.getRequestURI())) {
listAllPlugins(req, resp);
@@ -76,10 +81,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}
}
- private void retrievePluginContents(HttpServletRequest req, HttpServletResponse resp) {
+ private void retrievePluginContents(HttpServletRequest req,
+ HttpServletResponse resp) {
String name = req.getParameter("name");
if (name == null) {
- name = req.getRequestURI().substring(req.getRequestURI().lastIndexOf("/")+1);
+ name = req.getRequestURI().substring(
+ req.getRequestURI().lastIndexOf("/")+1);
if (name.endsWith(".js")) {
name = name.substring(0, name.length() - ".js".length());
}
@@ -89,11 +96,13 @@ private void retrievePluginContents(HttpServletRequest req, HttpServletResponse
}
IDiagramPlugin plugin = _pluginService.findPlugin(req, name);
if (plugin == null) {
- throw new IllegalArgumentException("No plugin by the name of " + name);
+ throw new IllegalArgumentException(
+ "No plugin by the name of " + name);
}
InputStream input = plugin.getContents();
if (input == null) {
- throw new IllegalArgumentException("Plugin contents could not be found");
+ throw new IllegalArgumentException(
+ "Plugin contents could not be found");
}
try {
byte[] buffer = new byte[4096];
@@ -105,20 +114,26 @@ private void retrievePluginContents(HttpServletRequest req, HttpServletResponse
} catch (IOException e) {
_logger.error(e.getMessage(), e);
} finally {
- if (input != null) { try { input.close(); } catch(IOException e) {}};
+ if (input != null) {
+ try { input.close(); } catch(IOException e) {}
+ }
}
}
- private void listAllPlugins(HttpServletRequest req, HttpServletResponse resp) throws IOException, JSONException {
+ private void listAllPlugins(HttpServletRequest req,
+ HttpServletResponse resp)
+ throws IOException, JSONException {
JSONArray plugins = new JSONArray();
- for (IDiagramPlugin p : _pluginService.getRegisteredPlugins(req)) {
+ for (IDiagramPlugin p :
+ _pluginService.getRegisteredPlugins(req)) {
JSONObject obj = new JSONObject();
obj.put("name", p.getName());
obj.put("core", p.isCore());
JSONArray properties = new JSONArray();
if (p.getProperties() != null) {
- for (Entry<String, Object> entry : p.getProperties().entrySet()) {
+ for (Entry<String, Object> entry :
+ p.getProperties().entrySet()) {
JSONObject propObj = new JSONObject();
propObj.put(entry.getKey(), entry.getValue());
properties.put(propObj);
View
106 src/main/java/com/intalio/web/profile/impl/ProfileServiceImpl.java
@@ -50,67 +50,97 @@
*/
public class ProfileServiceImpl implements IDiagramProfileService {
- private Map<String, IDiagramProfile> _registry = new HashMap<String, IDiagramProfile>();
- private Set<IDiagramProfileFactory> _factories = new HashSet<IDiagramProfileFactory>();
+ /**
+ * the singleton instance
+ */
+ private static IDiagramProfileService _instance;
- public ProfileServiceImpl(ServletContext context) {
+ public static IDiagramProfileService getInstance(
+ ServletContext context) {
+ if (_instance == null) {
+ _instance = new ProfileServiceImpl(context);
+ }
+ return _instance;
+ }
+
+ private Map<String, IDiagramProfile> _registry =
+ new HashMap<String, IDiagramProfile>();
+ private Set<IDiagramProfileFactory> _factories =
+ new HashSet<IDiagramProfileFactory>();
+
+ /**
+ * Default constructor, private.
+ * @param context the servlet context to initialize the profile.
+ */
+ private ProfileServiceImpl(ServletContext context) {
_registry.put("default", new DefaultProfileImpl(context));
// if we are in the OSGi world:
if (getClass().getClassLoader() instanceof BundleReference) {
- final BundleContext bundleContext = ((BundleReference) getClass().getClassLoader()).getBundle().getBundleContext();
- ServiceReference[] sRefs = null;
- try {
- sRefs = bundleContext.getServiceReferences(IDiagramProfileFactory.class.getName(), null);
- } catch (InvalidSyntaxException e) {
- }
- if (sRefs != null) {
- for (ServiceReference sRef : sRefs) {
- IDiagramProfileFactory service = (IDiagramProfileFactory) bundleContext.getService(sRef);
- _factories.add(service);
- }
+ registerWithOSGiContext();
+ }
+ }
+
+ /**
+ * register the profile and look for
+ * factories in an OSGi context.
+ */
+ private void registerWithOSGiContext() {
+ BundleReference ref = (BundleReference)
+ getClass().getClassLoader();
+ final BundleContext bundleContext =
+ ref.getBundle().getBundleContext();
+ ServiceReference[] sRefs = null;
+ try {
+ sRefs = bundleContext.getServiceReferences(
+ IDiagramProfileFactory.class.getName(), null);
+ } catch (InvalidSyntaxException e) {
+ }
+ if (sRefs != null) {
+ for (ServiceReference sRef : sRefs) {
+ IDiagramProfileFactory service = (IDiagramProfileFactory) bundleContext.getService(sRef);
+ _factories.add(service);
}
- ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {
+ }
+ ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {
- public void removedService(ServiceReference reference, Object service) {
- }
+ public void removedService(ServiceReference reference, Object service) {
+ }
- public void modifiedService(ServiceReference reference, Object service) {
- }
+ public void modifiedService(ServiceReference reference, Object service) {
+ }
- public Object addingService(ServiceReference reference) {
- IDiagramProfileFactory service = (IDiagramProfileFactory) bundleContext.getService(reference);
- _factories.add(service);
- return service;
- }
- };
- ServiceTracker tracker = new ServiceTracker(bundleContext,
- IDiagramProfileFactory.class.getName(), cust);
- tracker.open();
- // register self to make the default profile available to the world:
- bundleContext.registerService(IDiagramProfileService.class.getName(), this, new Hashtable());
- }
+ public Object addingService(ServiceReference reference) {
+ IDiagramProfileFactory service = (IDiagramProfileFactory) bundleContext.getService(reference);
+ _factories.add(service);
+ return service;
+ }
+ };
+ ServiceTracker tracker = new ServiceTracker(bundleContext,
+ IDiagramProfileFactory.class.getName(), cust);
+ tracker.open();
+ // register self to make the default profile available to the world:
+ bundleContext.registerService(IDiagramProfileService.class.getName(), this, new Hashtable());
}
- private Map<String, IDiagramProfile> assemblePlugins(HttpServletRequest request) {
- Map<String, IDiagramProfile> plugins = new HashMap<String, IDiagramProfile>(_registry);
+ private Map<String, IDiagramProfile> assembleProfiles(HttpServletRequest request) {
+ Map<String, IDiagramProfile> profiles = new HashMap<String, IDiagramProfile>(_registry);
if (request != null) {
for (IDiagramProfileFactory factory : _factories) {
for (IDiagramProfile p : factory.getProfiles(request)) {
- plugins.put(p.getName(), p);
+ profiles.put(p.getName(), p);
}
}
}
- System.err.println(plugins.keySet());
- return plugins;
+ return profiles;
}
public IDiagramProfile findProfile(HttpServletRequest request, String name) {
- return assemblePlugins(request).get(name);
+ return assembleProfiles(request).get(name);
}
public Collection<IDiagramProfile> getProfiles(HttpServletRequest request) {
- return assemblePlugins(request).values();
+ return assembleProfiles(request).values();
}
View
81 src/main/java/com/intalio/web/profile/impl/ProfileServiceServlet.java
@@ -1,81 +0,0 @@
-/***************************************
- * Copyright (c) Intalio, Inc 2010
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
-****************************************/
-package com.intalio.web.profile.impl;
-
-import java.io.IOException;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import com.intalio.web.plugin.IDiagramPlugin;
-import com.intalio.web.plugin.IDiagramPluginService;
-import com.intalio.web.profile.IDiagramProfile;
-
-/**
- * The profile service servlet, to make profiles available to the editor.
- *
- * @author Antoine Toulme
- */
-public class ProfileServiceServlet extends HttpServlet {
-
- private static final long serialVersionUID = 8234640848580375543L;
-
- private ProfileServiceImpl _profileService;
-
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- _profileService = new ProfileServiceImpl(config.getServletContext());
- }
-
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- String name = req.getParameter("name");
- if (name == null) {
- throw new IllegalArgumentException("Name parameter required");
- }
-
- IDiagramProfile p = _profileService.findProfile(req, name);
- if (p == null) {
- throw new IllegalArgumentException("No profile by the name of " + name);
- }
- try {
- JSONObject profile = new JSONObject();
- profile.put("name", p.getName());
- profile.put("title", p.getTitle());
- profile.put("plugins", p.getPlugins());
- profile.put("stencilset", p.getStencilSet());
- profile.put("ssexts", p.getStencilSetExtensions());
- resp.getWriter().append(profile.toString());
- } catch (JSONException e) {
- throw new ServletException(e);
- }
-
-
-
- }
-}
View
63 src/main/java/com/intalio/web/server/ProcessDesignerEnvironmentServlet.java
@@ -1,63 +0,0 @@
-/***************************************
- * Copyright (c) Intalio, Inc 2010
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
-****************************************/
-package com.intalio.web.server;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.log4j.Logger;
-import org.oryxeditor.server.EditorHandler;
-
-/**
- * Gives the paths of the core files to load: either each of them or a compressed file.
- *
- * @author Antoine Toulme
- *
- */
-public class ProcessDesignerEnvironmentServlet extends HttpServlet {
-
- private static final long serialVersionUID = -7382042081451404613L;
-
- private static final Logger _logger = Logger.getLogger(ProcessDesignerEnvironmentServlet.class);
-
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- //TODO implement compressed strategy for production.
- FileInputStream input = new FileInputStream(getServletContext().getRealPath("/js/js_files.json"));
- try {
- byte[] buffer = new byte[4096];
- int read;
- while ((read = input.read(buffer)) != -1) {
- resp.getOutputStream().write(buffer, 0, read);
- }
- resp.setContentType("application/json");
- } catch (IOException e) {
- _logger.error(e.getMessage(), e);
- } finally {
- if (input != null) { try { input.close(); } catch(IOException e) {}};
- }
- }
-}
View
348 src/main/java/org/oryxeditor/server/EditorHandler.java
@@ -24,12 +24,11 @@
package org.oryxeditor.server;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
+import java.util.StringTokenizer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -37,204 +36,279 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import com.intalio.web.profile.IDiagramProfile;
-import com.intalio.web.profile.impl.*;
-import com.intalio.web.plugin.impl.*;
-
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
-import org.jdom.Attribute;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-/*
+import com.intalio.web.plugin.IDiagramPluginService;
+import com.intalio.web.plugin.impl.PluginServiceImpl;
+import com.intalio.web.profile.IDiagramProfile;
+import com.intalio.web.profile.IDiagramProfileService;
+import com.intalio.web.profile.impl.ProfileServiceImpl;
+
+/**
* Servlet to load plugin and Oryx stencilset
*/
-
public class EditorHandler extends HttpServlet {
private static final long serialVersionUID = -7439613152623067053L;
- private static final Logger _logger = Logger.getLogger(EditorHandler.class);
+ /**
+ * da logger
+ */
+ private static final Logger _logger =
+ Logger.getLogger(EditorHandler.class);
/**
* The base path under which the application will be made available at runtime.
- * This constant should be used throughout the application. Eventually, it could be derived from the manifest values
- * or
+ * This constant should be used throughout the application.
*/
public static final String oryx_path = "/designer/";
- /*
- *
+ /**
+ * The designer DEV flag.
+ * When set, the logging will be enabled at the javascript level
*/
- private ProfileServiceImpl _profileService = null;
- private PluginServiceImpl _pluginService = null;
+ public static final String DEV = "designer.dev";
+
+ /**
+ * The profile service, a global registry to get the
+ * profiles.
+ */
+ private IDiagramProfileService _profileService = null;
+
+ /**
+ * The plugin service, a global registry for all plugins.
+ */
+ private IDiagramPluginService _pluginService = null;
- /*
- * JDOM related object. They are initialized while reading "editor.html"
+ /**
+ * editor.html document.
*/
- private Document _doc = null; //JDOM object
- private Element _root = null; // root element
- private Element _head = null; // head element
- private int _lastscriptidx = 0; // the index of the last script element
+ private Document _doc = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
- _profileService = new ProfileServiceImpl(config.getServletContext());
- _pluginService = new PluginServiceImpl(config.getServletContext());
+ _profileService = ProfileServiceImpl.getInstance(
+ config.getServletContext());
+ _pluginService = PluginServiceImpl.getInstance(
+ config.getServletContext());
+
+ String editor_file = config.
+ getServletContext().getRealPath("/editor.html");
+ try {
+ _doc = readDocument(editor_file);
+ } catch (Exception e) {
+ throw new ServletException(
+ "Error while parsing editor.html", e);
+ }
+ if (_doc == null) {
+ _logger.error("Invalid editor.html, " +
+ "could not be read as a document.");
+ throw new ServletException("Invalid editor.html, " +
+ "could not be read as a document.");
+ }
+
+ Element root = _doc.getRootElement();
+ Element head = root.getChild("head", root.getNamespace());
+ if (head == null) {
+ _logger.error("Invalid editor.html. No html or head tag");
+ throw new ServletException("Invalid editor.html. " +
+ "No html or head tag");
+ }
}
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- FileInputStream input = new FileInputStream(getServletContext().getRealPath("/editor.html"));
-
- _lastscriptidx = 0;
-
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws ServletException, IOException {
+ Document doc = (Document) _doc.clone();
String profileName = request.getParameter("profile");
- IDiagramProfile profile = _profileService.findProfile(request, profileName);
+ IDiagramProfile profile = _profileService.findProfile(
+ request, profileName);
if (profile == null) {
- _logger.error("Empty profile object");
- throw new ServletException(); // TODO
- }
-
- String editor_file = getServletContext().getRealPath("/editor.html");
- _doc = readDocument(editor_file);
- if (_doc == null) {
- _logger.error("Invalid editor.html. Don't touch this file");
- throw new ServletException(); // TODO
- }
-
- _root = _doc.getRootElement();
- searchHead(_root); // search for the head element
- if (_head == null) {
- _logger.error("Invalid editor.html. No html or head tag");
- throw new ServletException(); // TODO
+ _logger.error("No profile with the name " + profileName
+ + " was registered");
+ throw new IllegalArgumentException(
+ "No profile with the name " + profileName +
+ " was registered");
}
- // create the script tags for environment
- FileInputStream core_scripts = new FileInputStream(getServletContext().getRealPath("/js/js_files.json"));
- String contents = null;
-
- try {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int read;
- while ((read = core_scripts.read(buffer)) != -1) {
- stream.write(buffer, 0, read);
- }
- contents = stream.toString();
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- _logger.error(e.getMessage(), e);
- }
- }
-
- /*
- * generate the script for each file in js_files.json
- */
- JSONObject obj;
+ // generate the script for each file in js_files.json
try {
- obj = new JSONObject(contents);
+ JSONObject obj = new JSONObject(readEnvFiles());
JSONArray array = obj.getJSONArray("files");
for (int i = 0 ; i < array.length() ; i++) {
- addscript(oryx_path + array.getString(i));
+ addscript(doc, oryx_path + array.getString(i), true);
}
} catch (JSONException e) {
- // TODO Auto-generated catch block
- _logger.error("invalide js_files.json");
+ _logger.error("invalid js_files.json");
_logger.error(e.getMessage(), e);
+ throw new RuntimeException("Error initializing the " +
+ "environment of the editor");
}
// generate script to setup the languages
- addscript(oryx_path + "i18n/translation_en_us.js");
+ addscript(doc, oryx_path + "i18n/translation_en_us.js",
+ true);
- // plugins.
+ // generate script tags for plugins.
+ // they are located after the initialization script.
for (String plugin : profile.getPlugins()) {
_pluginService.findPlugin(request, plugin);
- addscript(oryx_path + "plugin/" + plugin + ".js");
+ addscript(doc, oryx_path + "plugin/" + plugin + ".js",
+ false);
}
// send the updated editor.html to client
- try {
- XMLOutputter outputter = new XMLOutputter();
- Format fm = outputter.getFormat();
- outputter.setFormat(outputter.getFormat().setExpandEmptyElements(true));
- String finalDoc = outputter.outputString(_doc);
- finalDoc = finalDoc.replaceAll("xmlns=\"\"", "");
- finalDoc = finalDoc.replace("@title@", profile.getTitle());
- finalDoc = finalDoc.replace("@stencilset@", profile.getStencilSet());
- response.getWriter().write(finalDoc);
- } catch (Exception e) {
- e.printStackTrace();
- _logger.error(e.getMessage(), e);
+ response.setContentType("application/xhtml+xml");
+ XMLOutputter outputter = new XMLOutputter();
+ Format format = Format.getPrettyFormat();
+ format.setExpandEmptyElements(true);
+ outputter.setFormat(format);
+ String html = outputter.outputString(doc);
+ StringTokenizer tokenizer = new StringTokenizer(
+ html, "@", true);
+ StringBuilder resultHtml = new StringBuilder();
+ boolean tokenFound = false;
+ boolean replacementMade = false;
+ while(tokenizer.hasMoreTokens()) {
+ String elt = tokenizer.nextToken();
+ if ("title".equals(elt)) {
+ resultHtml.append(profile.getTitle());
+ replacementMade = true;
+ } else if ("stencilset".equals(elt)) {
+ resultHtml.append(profile.getStencilSet());
+ replacementMade = true;
+ } else if ("debug".equals(elt)) {
+ resultHtml.append(System.getProperty(DEV) != null);
+ replacementMade = true;
+ } else if ("profileplugins".equals(elt)) {
+ StringBuilder plugins = new StringBuilder();
+ boolean commaNeeded = false;
+ for (String ext : profile.getPlugins()) {
+ if (commaNeeded) {
+ plugins.append(",");
+ } else {
+ commaNeeded = true;
+ }
+ plugins.append("\"").append(ext).append("\"");
+ }
+ resultHtml.append(plugins.toString());
+ replacementMade = true;
+ } else if ("ssextensions".equals(elt)) {
+ StringBuilder ssexts = new StringBuilder();
+ boolean commaNeeded = false;
+ for (String ext : profile.getStencilSetExtensions()) {
+ if (commaNeeded) {
+ ssexts.append(",");
+ } else {
+ commaNeeded = true;
+ }
+ ssexts.append("\"").append(ext).append("\"");
+ }
+ resultHtml.append(ssexts.toString());
+ replacementMade = true;
+ } else if ("@".equals(elt)) {
+ if (replacementMade) {
+ tokenFound = false;
+ replacementMade = false;
+ } else {
+ tokenFound = true;
+ }
+ } else {
+ if (tokenFound) {
+ tokenFound = false;
+ resultHtml.append("@");
+ }
+ resultHtml.append(elt);
+ }
}
+
+ response.getWriter().write(resultHtml.toString());
}
- private static Document readDocument(String name) {
- try {
- SAXBuilder builder = new SAXBuilder(false);
-
- // no DTD validation
- builder.setValidation(false);
- builder.setFeature("http://xml.org/sax/features/validation", false);
- builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
- builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
-
- Document anotherDocument = builder.build(new File(name));
- return anotherDocument;
- } catch(JDOMException e) {
- _logger.error(e.getMessage(), e);
- } catch(NullPointerException e) {
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- _logger.error(e.getMessage(), e);
- } catch (Exception e) {
- _logger.error(e.getMessage(), e);
- }
-
- return null;
+ /**
+ * Reads the document from the file at the given path
+ * @param path the path to the file
+ * @return a document
+ * @throws JDOMException
+ * @throws IOException
+ */
+ private static Document readDocument(String path)
+ throws JDOMException, IOException {
+ SAXBuilder builder = new SAXBuilder(false);
+
+ // no DTD validation
+ builder.setValidation(false);
+ builder.setFeature("http://xml.org/sax/features/validation", false);
+ builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+ builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+
+ Document anotherDocument = builder.build(new File(path));
+ return anotherDocument;
}
- private void addscript(String src) {
- Element script = new Element("script");
+ /**
+ * Adds a script to the head.
+ * @param doc the document to use.
+ * @param src the location of the script
+ */
+ private void addscript(Document doc, String src, boolean isCore) {
+ Namespace nm = doc.getRootElement().getNamespace();
+ Element script = new Element("script", nm);
// set the attributes
script.setAttribute("src", src);
script.setAttribute("type", "text/javascript");
+ //add an empty text node in them
+ script.addContent("");
// put it to the right place
- _head.addContent(_lastscriptidx-1, script);
- _lastscriptidx ++;
+ Element head = doc.getRootElement().getChild("head", nm);
+
+ if (isCore) {
+ // then place it first.
+ //insert before the last script tag.
+ head.addContent(head.getContentSize() -2, script);
+ } else {
+ head.addContent(script);
+ }
+
return;
}
- /*
- * Search for the head element, as well as the last script element
- * in the file
+ /**
+ * @return read the files to be placed as core scripts
+ * from a configuration file in a json file.
+ * @throws IOException
*/
- private void searchHead(Element current) {
- if (current.getName() == "head") {
- _head = current;
- }
- if (current.getName() == "script") {
- int index = _head.indexOf(current);
- if (index > _lastscriptidx) {
- _lastscriptidx = index;
- }
- }
- List children = current.getChildren();
- Iterator iterator = children.iterator();
- while (iterator.hasNext()) {
- Element child = (Element) iterator.next();
- searchHead(child);
- }
+ private String readEnvFiles() throws IOException {
+ FileInputStream core_scripts = new FileInputStream(
+ getServletContext().getRealPath("/js/js_files.json"));
+
+ try {
+ ByteArrayOutputStream stream =
+ new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int read;
+ while ((read = core_scripts.read(buffer)) != -1) {
+ stream.write(buffer, 0, read);
+ }
+ return stream.toString();
+ } finally {
+ try {
+ core_scripts.close();
+ } catch (IOException e) {
+ _logger.error(e.getMessage(), e);
+ }
+ }
}
}
View
27 src/main/webapp/WEB-INF/web.xml
@@ -413,14 +413,6 @@
</servlet>
<servlet>
- <display-name>Profile Service Servlet</display-name>
- <servlet-name>ProfileServiceServlet</servlet-name>
- <servlet-class>
- com.intalio.web.profile.impl.ProfileServiceServlet
- </servlet-class>
- </servlet>
-
- <servlet>
<display-name>StencilSet Service Servlet</display-name>
<servlet-name>StencilSetServiceServlet</servlet-name>
<servlet-class>
@@ -428,14 +420,6 @@
</servlet-class>
</servlet>
- <servlet>
- <display-name>Process Designer Environment Servlet</display-name>
- <servlet-name>ProcessDesignerEnvironmentServlet</servlet-name>
- <servlet-class>
- com.intalio.web.server.ProcessDesignerEnvironmentServlet
- </servlet-class>
- </servlet>
-
<!-- Servlet Mappings -->
<!--
<servlet-mapping>
@@ -695,17 +679,6 @@
<url-pattern>/plugin/*</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>ProfileServiceServlet</servlet-name>
- <url-pattern>/profile</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
- <servlet-name>ProcessDesignerEnvironmentServlet</servlet-name>
- <url-pattern>/env</url-pattern>
- </servlet-mapping>
-
-
<servlet-mapping>
<servlet-name>StencilSetServiceServlet</servlet-name>
<url-pattern>/stencilset/*</url-pattern>
View
132 src/main/webapp/editor.html
@@ -1,40 +1,102 @@
<?xml version='1.0' encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:b3mn="http://b3mn.org/2007/b3mn" xmlns:ext="http://b3mn.org/2007/ext" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:atom="http://b3mn.org/2007/atom+xhtml">
- <head profile="http://purl.org/NET/erdf/profile">
- <link rel='icon' href='/designer/favicon.ico' />
- <title></title>
-
- <!-- libraries -->
+ <head profile="http://purl.org/NET/erdf/profile">
+ <link rel='icon' href='/designer/favicon.ico' />
+ <title>@title@</title>
+
+ <!-- libraries -->
- <script src="/designer/lib/prototype-1.5.1.js" type="text/javascript"></script>
- <script src="/designer/lib/path_parser.js" type="text/javascript"></script>
- <script src="/designer/lib/ext-2.0.2/adapter/ext/ext-base.js" type="text/javascript"></script>
- <script src="/designer/lib/ext-2.0.2/ext-all-debug.js" type="text/javascript"></script>
- <script src="/designer/lib/ext-2.0.2/color-field.js" type="text/javascript"></script>
- <style media="screen" type="text/css">
- @import url("/designer/lib/ext-2.0.2/resources/css/ext-all.css");
- </style>
-
- <!-- process designer -->
-
- <!-- erdf schemas -->
- <link rel="Stylesheet" media="screen" href="/designer/css/theme_norm.css" type="text/css" />
- <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
- <link rel="schema.dcTerms" href="http://purl.org/dc/terms/" />
- <link rel="schema.b3mn" href="http://b3mn.org" />
- <link rel="schema.oryx" href="http://oryx-editor.org/" />
- <link rel="schema.raziel" href="http://raziel.org/" />
- <script type="text/javascript">
- function loadscr() {
- document.getElementsByTagName('title').item(0).text = "@title@";
- ORYX.CONFIG.SSEXTS= []
- ORYX.CONFIG.SSET= "@stencilset@";
- ORYX.load;
- }
- </script>
- </head>
- <body onload="loadscr()">
- <div class='processdata' style='display:none'></div>
- </body>
+ <script src="/designer/lib/prototype-1.5.1.js" type="text/javascript">
+ </script>
+ <script src="/designer/lib/path_parser.js" type="text/javascript">
+ </script>
+ <script src="/designer/lib/ext-2.0.2/adapter/ext/ext-base.js" type="text/javascript">
+ </script>
+ <script src="/designer/lib/ext-2.0.2/ext-all.js" type="text/javascript">
+ </script>
+ <script src="/designer/lib/ext-2.0.2/color-field.js" type="text/javascript">
+ </script>
+ <style media="screen" type="text/css">
+ @import url("/designer/lib/ext-2.0.2/resources/css/ext-all.css");
+ </style>
+
+ <!-- process designer -->
+
+ <!-- erdf schemas -->
+ <link rel="Stylesheet" media="screen" href="/designer/css/theme_norm.css" type="text/css" />
+ <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
+ <link rel="schema.dcTerms" href="http://purl.org/dc/terms/" />
+ <link rel="schema.b3mn" href="http://b3mn.org" />
+ <link rel="schema.oryx" href="http://oryx-editor.org/" />
+ <link rel="schema.raziel" href="http://raziel.org/" />
+ <script type="text/javascript">
+
+ ORYX.CONFIG.SSET = "@stencilset@";
+ ORYX.CONFIG.DEV = @debug@;
+ if (ORYX.CONFIG.DEV) {
+ ORYX_LOGLEVEL = 4;
+ }
+ params = window.location.search.toQueryParams();
+
+ if (params['profile'] === undefined) {
+ params['profile'] = 'default';
+ }
+
+ ORYX.UUID = params['uuid'];
+ ORYX.PROFILE = params['profile'];
+
+ var segments = window.location.pathname.split("/").without("");
+
+ ORYX.CONFIG.ROOT_PATH = "/" + segments.first() + "/";
+ ORYX.PATH = ORYX.CONFIG.ROOT_PATH;
+
+ if (ORYX.UUID === undefined) {
+ ORYX.UUID = segments.pop();
+ }
+
+ ORYX.CONFIG.SSEXTS= [@ssextensions@].map(function(ssext) {
+ // for each of the extensions, we get the extension file and return its contents.
+ var contents = null;
+
+ new Ajax.Request(ORYX.PATH + "stencilset/" + ssext, {
+ asynchronous: false,
+ method: 'get',
+ contentType: 'application/json',
+ onSuccess: function(result) {
+ contents = result.responseText.evalJSON();
+ },
+ onFailure: function(result) {
+ alert("Could not load Process Designer"); //TODO even better logging ?
+ }
+ });
+ return contents;
+ });
+
+ new Ajax.Request(ORYX.PATH + "plugins", {
+ asynchronous: false,
+ method: 'get',
+ contentType: 'application/json',
+ onSuccess: function(result) {
+ var allPlugins = {};
+ result.responseText.evalJSON().each(function (p) {
+ allPlugins[p.name] = p;
+ }.bind(allPlugins));
+ // install the current plugins
+ ORYX.availablePlugins = [];
+ [@profileplugins@].each(function(pluginName) {
+ ORYX.availablePlugins.push(allPlugins[pluginName]);
+ }.bind(allPlugins));
+
+ },
+ onFailure: function(result) {
+ alert("Could not load Process Designer"); //TODO even better logging ?
+ }
+ });
+ </script>
+ </head>
+ <body style="overflow:hidden;">
+ <div class='processdata' style='display:none'>
+ </div>
+ </body>
</html>
View
5 src/main/webapp/js/oryx.js
@@ -37,10 +37,7 @@ var ORYX_LOGLEVEL_WARN = 2;
var ORYX_LOGLEVEL_ERROR = 1;
var ORYX_LOGLEVEL_FATAL = 0;
if (!ORYX_LOGLEVEL) {
- var ORYX_LOGLEVEL = 5;
- if (ORYX.CONFIG.DEV) {
- ORYX_LOGLEVEL = 3;
- }
+ var ORYX_LOGLEVEL = 1;
}
var ORYX_CONFIGURATION_DELAY = 100;
var ORYX_CONFIGURATION_WAIT_ATTEMPTS = 10;
Please sign in to comment.
Something went wrong with that request. Please try again.