Package org.wapama.web.profile

Examples of org.wapama.web.profile.IDiagramProfile


    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);
        if (profile == null) {
            _logger.error("No profile with the name " + profileName
                    + " was registered");
            throw new IllegalArgumentException(
                    "No profile with the name " + profileName +
                        " was registered");
        }

        //output env javascript files
        if (System.getProperty(DEV) != null) {
            for (String jsFile : _envFiles) {
                addScript(doc, wapama_path + jsFile, true);
            }
        } else {
            addScript(doc, wapama_path + "jsc/env_combined.js", true);
        }
       
     // get language from cookie
        String lang = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("locale".equals(cookie.getName())) {
                lang = cookie.getValue().trim();
                break;
            }
        }
        // i18n message resource file name
        String i18nJsFile = null;
        if ("de_DE".equals(lang)) {
            i18nJsFile = "i18n/translation_de.js";
        } else if ("ru".equals(lang)){
            i18nJsFile = "i18n/translation_ru.js";
        } else if ("es".equals(lang)){
            i18nJsFile = "i18n/translation_es.js";
        } else if ("ja_JP".equals(lang)){
            i18nJsFile = "i18n/translation_ja.js";
        } else {
            i18nJsFile = "i18n/translation_en_us.js";
        }
        // generate script to setup the languages
        addScript(doc, wapama_path + i18nJsFile, 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 (System.getProperty(DEV) == null) {
                // 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 (System.getProperty(DEV) != null) {
            for (IDiagramPlugin jsFile : _pluginfiles.get(profileName)) {
                addScript(doc, wapama_path + "plugin/" + jsFile.getName()
                        + ".js", true);
            }
        } else {
            addScript(doc,
                    wapama_path + "jsc/plugins_" + profileName + ".js",
                    false);
        }
       
        for (IDiagramPlugin uncompressed :
                _uncompressedPlugins.get(profileName)) {
            addScript(doc, wapama_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(System.getProperty(DEV) != null);
                replacementMade = true;
            } else if ("autosaveinterval".equals(elt)) {
                resultHtml.append(autoSaveInt);
                replacementMade = true;
            } else if ("autosavedefault".equals(elt)) {
                resultHtml.append(autoSaveOn);
                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;
                    }
View Full Code Here


    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      String uuid = req.getParameter("uuid");
        if (uuid == null) {
            throw new ServletException("uuid parameter required");
        }
        IDiagramProfile profile = getProfile(req, req.getParameter("profile"));
        ByteArrayInputStream input = new ByteArrayInputStream(
            _repository.load(req, uuid, profile.getSerializedModelExtension()));
        byte[] buffer = new byte[4096];
        int read;

        while ((read = input.read(buffer)) != -1) {
            resp.getOutputStream().write(buffer, 0, read);
View Full Code Here

            if (_logger.isDebugEnabled()) {
                _logger.debug("Calling UUIDBasedRepositoryServlet doPost()...");
                _logger.debug("autosave: " + autosave);
            }
           
            IDiagramProfile profile = getProfile(req, profileName);
            if (_logger.isDebugEnabled()) {
                _logger.debug("Begin saving the diagram");
            }
            _repository.save(req, uuid, json, svg, profile, autosave);
            if (_logger.isDebugEnabled()) {
View Full Code Here

    /**
     * FIXME this needs to go as it duplicates part of the functionality for
     * profiles resolution. We should only write this code once.
     */
    private IDiagramProfile getProfile(HttpServletRequest req, String profileName) {
        IDiagramProfile profile = null;
        // get the profile, either through the OSGi DS or by using the default one:
        if (getClass().getClassLoader() instanceof BundleReference) {
            BundleContext bundleContext = ((BundleReference) getClass().getClassLoader()).getBundle().getBundleContext();
            ServiceReference ref = bundleContext.getServiceReference(IDiagramProfileService.class.getName());
            if (ref == null) {
View Full Code Here

TOP

Related Classes of org.wapama.web.profile.IDiagramProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.