예제 #1
0
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    _profileService = ProfileServiceImpl.INSTANCE;
    _profileService.init(config.getServletContext());
    _pluginService = PluginServiceImpl.getInstance(config.getServletContext());
    _preProcessingService = PreprocessingServiceImpl.INSTANCE;
    _preProcessingService.init(config.getServletContext());

    _devMode =
        Boolean.parseBoolean(
            System.getProperty(DEV) == null
                ? config.getInitParameter(DEV)
                : System.getProperty(DEV));
    _preProcess =
        Boolean.parseBoolean(
            System.getProperty(PREPROCESS) == null
                ? config.getInitParameter(PREPROCESS)
                : System.getProperty(PREPROCESS));
    _designerVersion = readDesignerVersion(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");
    }

    try {
      initEnvFiles(getServletContext(), config);
    } catch (IOException e) {
      throw new ServletException(e);
    }
  }
예제 #2
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Document doc = (Document) _doc.clone();
    String profileName = request.getParameter("profile");
    if (profileName == null || profileName.length() < 1) {
      // default to jbpm
      profileName = "jbpm";
    }
    IDiagramProfile profile = _profileService.findProfile(request, profileName);
    if (profile == null) {
      _logger.error("No profile with the name " + profileName + " was registered");
      throw new IllegalArgumentException(
          "No profile with the name " + profileName + " was registered");
    }

    IDiagramPreprocessingUnit preprocessingUnit = null;
    if (_preProcess) {
      if (_logger.isInfoEnabled()) {
        _logger.info("Performing diagram information pre-processing steps. ");
      }
      preprocessingUnit = _preProcessingService.findPreprocessingUnit(request, profile);
      preprocessingUnit.preprocess(request, response, profile);
    }

    // output env javascript files
    if (_devMode) {
      for (String jsFile : _envFiles) {
        addScript(doc, oryx_path + jsFile, true);
      }
    } else {
      addScript(doc, oryx_path + "jsc/env_combined.js", true);
    }

    // generate script tags for plugins.
    // they are located after the initialization script.

    if (_pluginfiles.get(profileName) == null) {
      List<IDiagramPlugin> compressed = new ArrayList<IDiagramPlugin>();
      List<IDiagramPlugin> uncompressed = new ArrayList<IDiagramPlugin>();
      _pluginfiles.put(profileName, compressed);
      _uncompressedPlugins.put(profileName, uncompressed);
      for (String pluginName : profile.getPlugins()) {
        IDiagramPlugin plugin = _pluginService.findPlugin(request, pluginName);
        if (plugin == null) {
          _logger.warn(
              "Could not find the plugin "
                  + pluginName
                  + " requested by the profile "
                  + profile.getName());
          continue;
        }
        if (plugin.isCompressable()) {
          compressed.add(plugin);
        } else {
          uncompressed.add(plugin);
        }
      }

      if (!_devMode) {
        // let's call the compression routine
        String rs = compressJS(_pluginfiles.get(profileName), getServletContext());
        try {
          FileWriter w =
              new FileWriter(getServletContext().getRealPath("jsc/plugins_" + profileName + ".js"));
          w.write(rs.toString());
          w.close();
        } catch (Exception e) {
          _logger.error(e.getMessage(), e);
        }
      }
    }

    if (_devMode) {
      for (IDiagramPlugin jsFile : _pluginfiles.get(profileName)) {
        addScript(doc, oryx_path + "plugin/" + jsFile.getName() + ".js", true);
      }
    } else {
      addScript(doc, oryx_path + "jsc/plugins_" + profileName + ".js", false);
    }

    for (IDiagramPlugin uncompressed : _uncompressedPlugins.get(profileName)) {
      addScript(doc, oryx_path + "plugin/" + uncompressed.getName() + ".js", false);
    }

    // send the updated editor.html to client
    if (!isIE(request)) {
      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;

    IDiagramPreference pref = PREFERENCE_FACTORY.createPreference(request);
    int autoSaveInt = pref.getAutosaveInterval();
    boolean autoSaveOn = pref.isAutoSaveEnabled();

    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(_devMode);
        replacementMade = true;
      } else if ("autosaveinterval".equals(elt)) {
        resultHtml.append(autoSaveInt);
        replacementMade = true;
      } else if ("autosavedefault".equals(elt)) {
        resultHtml.append(autoSaveOn);
        replacementMade = true;
      } else if ("preprocessing".equals(elt)) {
        resultHtml.append(preprocessingUnit == null ? "" : preprocessingUnit.getOutData());
        replacementMade = true;
      } else if ("externalprotocol".equals(elt)) {
        resultHtml.append(ExternalInfo.getExternalProtocol(profile));
        replacementMade = true;
      } else if ("externalhost".equals(elt)) {
        resultHtml.append(ExternalInfo.getExternalHost(profile));
        replacementMade = true;
      } else if ("externalsubdomain".equals(elt)) {
        resultHtml.append(
            profile
                .getExternalLoadURLSubdomain()
                .substring(0, profile.getExternalLoadURLSubdomain().indexOf("/")));
        replacementMade = true;
      } else if ("designerversion".equals(elt)) {
        resultHtml.append(_designerVersion);
        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());
  }