Package chrriis.common.WebServer

Examples of chrriis.common.WebServer.WebServerContent


  }

  protected static WebServerContent getWebServerContent(final HTTPRequest httpRequest) {
    // We dynamically generate the page using the embedded web server.
    if("header-viewer.html".equals(httpRequest.getResourcePath())) {
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          StringBuilder sb = new StringBuilder();
          sb.append("<html><body><h1>HTTP Headers</h1><table border=\"1\">");
          Map<String, String> headerMap = httpRequest.getHeaderMap();
View Full Code Here


  }

  protected static WebServerContent getWebServerContent(final HTTPRequest httpRequest) {
    // We dynamically generate the page using the embedded web server.
    if("header-viewer.html".equals(httpRequest.getResourcePath())) {
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          StringBuilder sb = new StringBuilder();
          sb.append("<html><body>");
          sb.append("<h1>HTTP Headers</h1><table border=\"1\">");
View Full Code Here

  private static final String LS = Utils.LINE_SEPARATOR;

  public WebServerContent getWebServerContent(final HTTPRequest httpRequest, final String resourcePath, final int instanceID) {
    if("index.html".equals(resourcePath)) {
      return new WebServerContent() {
        @Override
        public String getContentType() {
          int index = resourcePath.lastIndexOf('.');
          return getDefaultMimeType(index == -1? null: resourcePath.substring(index));
        }
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <head>" + LS +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" + LS +
            "    <style type=\"text/css\">" + LS +
            "      body, form {margin: 0; padding: 0; overflow: auto;}" + LS +
            "    </style>" + LS +
            "    <script type=\"text/javascript\" src=\"fckeditor.js\"></script>" + LS +
            "    <script type=\"text/javascript\">" + LS +
            // We override the FCK editor function because on Linux this may return false if navigator.product is empty (instead of "Gecko")
            "      function FCKeditor_IsCompatibleBrowser() {" + LS +
            "        return true;" + LS +
            "      }" + LS +
            "      var sendCommand = " + JWebBrowser.COMMAND_FUNCTION + ";" + LS +
            "      var htmlContent;" + LS +
            "      var htmlDirtyTracker;" + LS +
            "      var isDirtyTrackingActive = true;" + LS +
            "      function JH_checkDirty() {" + LS +
            "        var inst = FCKeditorAPI.GetInstance('" + EDITOR_INSTANCE + "');" + LS +
            "        if(htmlContent == null) {" + LS +
            "          try {" + LS +
            "            htmlContent = inst.GetHTML();" + LS +
            "          } catch(e) {" + LS +
            "          }" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        } else {" + LS +
            "          try {" + LS +
            "            var newHtmlContent = inst.GetHTML();" + LS +
            "            if(newHtmlContent != htmlContent) {" + LS +
            "              htmlContent = null;" + LS +
            "              htmlDirtyTracker = null;" + LS +
            "              sendCommand('[Chrriis]JH_setDirty');" + LS +
            "            } else {" + LS +
            "              htmlContent = newHtmlContent;" + LS +
            "              htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "            }" + LS +
            "          } catch(e) {" + LS +
            "            htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "          }" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_clearDirtyIndicator() {" + LS +
            "        if(htmlDirtyTracker) {" + LS +
            "          clearTimeout(htmlDirtyTracker);" + LS +
            "        }" + LS +
            "        htmlContent = null;" + LS +
            "        if(isDirtyTrackingActive) {" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_setDirtyTrackingActive(isActive) {" + LS +
            "        isDirtyTrackingActive = isActive;" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_setData(html) {" + LS +
            "        var inst = FCKeditorAPI.GetInstance('" + EDITOR_INSTANCE + "');" + LS +
            "        inst.SetHTML(decodeURIComponent(html));" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_sendData() {" + LS +
            "        document.jhtml_form.action = 'jhtml_sendData';" + LS +
            "        document.jhtml_form.submit();" + LS +
            "        return false;" + LS +
            "      }" + LS +
            "      function JH_doSave() {" + LS +
            "        document.jhtml_form.action = 'jhtml_save';" + LS +
            "        document.jhtml_form.submit();" + LS +
            "        return false;" + LS +
            "      }" + LS +
            "      function createEditor() {" + LS +
            "        var oFCKeditor = new FCKeditor('" + EDITOR_INSTANCE + "');" + LS +
            "        oFCKeditor.Width = \"100%\";" + LS +
            "        oFCKeditor.Height = \"100%\";" + LS +
            "        oFCKeditor.BasePath = \"\";" + LS +
            (customJavascriptConfiguration != null? "        oFCKeditor.Config[\"CustomConfigurationsPath\"] = '" + WebServer.getDefaultWebServer().getDynamicContentURL(JHTMLEditor.class.getName(), String.valueOf(instanceID), "customConfigurationScript.js") + "';" + LS: "") +
            "        oFCKeditor.Create();" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function FCKeditor_OnComplete(editorInstance) {" + LS +
            "        editorInstance.LinkedField.form.onsubmit = JH_doSave;" + LS +
            "        sendCommand('[Chrriis]JH_setLoaded');" + LS +
            "      }" + LS +
            "    </script>" + LS +
            "  </head>" + LS +
            "  <body>" + LS +
            "  <iframe style=\"display:none;\" name=\"j_iframe\"></iframe>" + LS +
            "  <form name=\"jhtml_form\" method=\"POST\" target=\"j_iframe\">" + LS +
            "    <script type=\"text/javascript\">" + LS +
            "      createEditor();" + LS +
            "    </script>" +
            "</form>" + LS + // No space at the begining of this line or else a scrollbar appears.
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("customConfigurationScript.js".equals(resourcePath)) {
      return new WebServerContent () {
        @Override
        public String getContentType () {
          return getDefaultMimeType(".js");
        }
        @Override
        public InputStream getInputStream () {
          return getInputStream(customJavascriptConfiguration);
        }
      };
    }
    if("jhtml_save".equals(resourcePath)) {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          String html = JHTMLEditor.convertLinksToLocal(httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE));
          HTMLEditorSaveEvent e = null;
          for(HTMLEditorListener listener: htmlEditor.getHTMLEditorListeners()) {
            if(e == null) {
              e = new HTMLEditorSaveEvent(htmlEditor, html);
            }
            listener.saveHTML(e);
          }
        }
      });
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Save successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("jhtml_sendData".equals(resourcePath)) {
      String data = httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE);
      tempResult = data;
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Send data successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("editor/filemanager/connectors/php/upload.php".equals(resourcePath)) {
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <head>" + LS +
            "    <script type=\"text/javascript\">" + LS +
            "      alert('upload to local system are not allowed...');" + LS +
            "    </script>" + LS +
            "  </head>" + LS +
            "  <body>" + LS +
            "    Upload successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("editor/filemanager/connectors/php/connector.php".equals(resourcePath)) {
      Map<String, String> queryParameterMap = httpRequest.getQueryParameterMap();
      String command = queryParameterMap.get("Command");
      String content = null;
      if("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) {
        final String type = queryParameterMap.get("Type");
        String currentDir = queryParameterMap.get("CurrentFolder");
        File[] roots = File.listRoots();
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
        sb.append("<Connector command=\"").append(command).append("\" resourceType=\"").append(type).append("\">");
        sb.append("<CurrentFolder path=\"").append(currentDir).append("\" url=\"").append(WebServer.getDefaultWebServer().getResourcePathURL(currentDir, "")).append("\" />");
//        try {
//          sb.append("<CurrentFolder path=\"").append(currentDir).append("\" url=\"").append(new File(currentDir).toURI().toURL()).append("\" />");
//        } catch (MalformedURLException e) {
//        }
        if(("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) && currentDir.equals("/") && roots.length > 1) {
          sb.append("<Folders>");
          for(File file: roots) {
            String rootPath = file.getAbsolutePath();
            if(Utils.IS_WINDOWS && rootPath.endsWith("\\")) {
              rootPath = rootPath.substring(0, rootPath.length() - 1);
            }
            sb.append("<Folder name=\"").append(Utils.escapeXML(rootPath)).append("\"/>");
          }
          sb.append("</Folders>");
        } else {
          if("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) {
            sb.append("<Folders>");
            for(File file: new File(currentDir).listFiles(new FileFilter() {
              public boolean accept(File pathname) {
                return !pathname.isFile() && !pathname.isHidden() && pathname.listFiles() != null;
              }
            })) {
              sb.append("<Folder name=\"").append(Utils.escapeXML(file.getName())).append("\"/>");
            }
            sb.append("</Folders>");
          }
          if("GetFoldersAndFiles".equals(command)) {
            sb.append("<Files>");
            for(File file: new File(currentDir).listFiles(new FileFilter() {
              public boolean accept(File pathname) {
                if(!pathname.isFile()) {
                  return false;
                }
                if("Image".equals(type)) {
                  String name = pathname.getName().toLowerCase();
                  return
                  name.endsWith(".bmp") ||
                  name.endsWith(".jpg") ||
                  name.endsWith(".gif") ||
                  name.endsWith(".png");
                }
                if("Flash".equals(type)) {
                  String name = pathname.getName().toLowerCase();
                  return name.endsWith(".swf");
                }
                return true;
              }
            })) {
              sb.append("<File name=\"").append(Utils.escapeXML(file.getName())).append("\" size=\"").append(file.length() / 1000).append("\"/>");
            }
            sb.append("</Files>");
          }
        }
        sb.append("</Connector>");
        content = sb.toString();
      }
      final String content_ = content;
      return new WebServerContent() {
        @Override
        public String getContentType() {
          return "text/xml; charset=utf-8";
        }
        @Override
View Full Code Here

  static final String LS = Utils.LINE_SEPARATOR;


  public WebServerContent getWebServerContent(final HTTPRequest httpRequest, final String resourcePath, final int instanceID) {
    if("index.html".equals(resourcePath)) {
      return new WebServerContent() {
        @Override
        public String getContentType() {
          int index = resourcePath.lastIndexOf('.');
          return getDefaultMimeType(index == -1? null: resourcePath.substring(index));
        }
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <head>" + LS +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" + LS +
            "    <style type=\"text/css\">" + LS +
            "      body, form {margin: 0; padding: 0; overflow: auto;}" + LS +
            "    </style>" + LS +
            "    <script type=\"text/javascript\" src=\"ckeditor.js\"></script>" + LS +
            "    <script type=\"text/javascript\">" + LS +
            "      var sendCommand = " + JWebBrowser.COMMAND_FUNCTION + ";" + LS +
            "      var htmlContent;" + LS +
            "      var htmlDirtyTracker;" + LS +
            "      var isDirtyTrackingActive = true;" + LS +
            "      function JH_checkDirty() {" + LS +
            "        var oEditor = CKEDITOR.instances." + EDITOR_INSTANCE + ";" + LS +
            "        if(htmlContent == null) {" + LS +
            "          try {" + LS +
            "            htmlContent = oEditor.getData();" + LS +
            "          } catch(e) {" + LS +
            "          }" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        } else {" + LS +
            "          try {" + LS +
            "            var newHtmlContent = oEditor.getData();" + LS +
            "            if(newHtmlContent != htmlContent) {" + LS +
            "              htmlContent = null;" + LS +
            "              htmlDirtyTracker = null;" + LS +
            "              sendCommand('[Chrriis]JH_setDirty');" + LS +
            "            } else {" + LS +
            "              htmlContent = newHtmlContent;" + LS +
            "              htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "            }" + LS +
            "          } catch(e) {" + LS +
            "            htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "          }" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_clearDirtyIndicator() {" + LS +
            "        if(htmlDirtyTracker) {" + LS +
            "          clearTimeout(htmlDirtyTracker);" + LS +
            "        }" + LS +
            "        htmlContent = null;" + LS +
            "        if(isDirtyTrackingActive) {" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_setDirtyTrackingActive(isActive) {" + LS +
            "        isDirtyTrackingActive = isActive;" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_setData(html) {" + LS +
            "        var oEditor = CKEDITOR.instances." + EDITOR_INSTANCE + ";" + LS +
            "        oEditor.setData(decodeURIComponent(html));" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_sendData() {" + LS +
            "        document.jhtml_form.action = 'jhtml_sendData';" + LS +
            "        document.jhtml_form.submit();" + LS +
            "        document.jhtml_form.action = 'jhtml_save';" + LS +
            "        return false;" + LS +
            "      }" + LS +
            "      function JH_doSave() {" + LS +
            "        document.jhtml_form.action = 'jhtml_save';" + LS +
            "        document.jhtml_form.submit();" + LS +
            "        return false;" + LS +
            "      }" + LS +
            "      CKEDITOR.on('instanceReady'," + LS +
            "         function(evt) {" + LS +
            "          var editor = evt.editor;" + LS +
            "          editor.execCommand('maximize');" + LS +
            "          JH_clearDirtyIndicator();" + LS +
            "          sendCommand('[Chrriis]JH_setLoaded');" + LS +
            "         });" + LS +
            "    </script>" + LS +
            "  </head>" + LS +
            "  <body>" + LS +
            "    <iframe style=\"display:none;\" id=\"j_iframe\" name=\"j_iframe\"></iframe>" + LS +
            "    <form name=\"jhtml_form\" method=\"POST\" target=\"j_iframe\" action=\"jhtml_save\">" + LS +
            "      <textarea name=\"" + EDITOR_INSTANCE + "\">&lt;p&gt;&lt;/p&gt;</textarea>" + LS +
            "      <script type=\"text/javascript\">" + LS +
            "        CKEDITOR.replace('" + EDITOR_INSTANCE + "'" +
            (customOptions != null? "," + "{" + LS + customOptions + LS + "        });": ");") + LS +
            "      </script>" + LS +
            "    </form>" + LS +
            "  </body>" + LS +
            "</html>";
            return getInputStream(content);
        }
      };
    }
//    if("customConfigurationScript.js".equals(resourcePath)) {
//      return new WebServerContent () {
//        @Override
//        public String getContentType () {
//          return getDefaultMimeType(".js");
//        }
//        @Override
//        public InputStream getInputStream () {
//          return getInputStream(customJavascriptConfiguration);
//        }
//      };
//    }
    if("jhtml_save".equals(resourcePath)) {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          String html = JHTMLEditor.convertLinksToLocal(httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE));
          HTMLEditorSaveEvent e = null;
          for(HTMLEditorListener listener: htmlEditor.getHTMLEditorListeners()) {
            if(e == null) {
              e = new HTMLEditorSaveEvent(htmlEditor, html);
            }
            listener.saveHTML(e);
          }
        }
      });
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Save successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }

    if("jhtml_sendData".equals(resourcePath)) {
      String data = httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE);
      tempResult = data;
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Send data successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("editor/filemanager/connectors/php/upload.php".equals(resourcePath)) {
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <head>" + LS +
            "    <script type=\"text/javascript\">" + LS +
            "      alert('upload to local system are not allowed...');" + LS +
            "    </script>" + LS +
            "  </head>" + LS +
            "  <body>" + LS +
            "    Upload successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("editor/filemanager/connectors/php/connector.php".equals(resourcePath)) {
      Map<String, String> queryParameterMap = httpRequest.getQueryParameterMap();
      String command = queryParameterMap.get("Command");
      String content = null;
      if("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) {
        final String type = queryParameterMap.get("Type");
        String currentDir = queryParameterMap.get("CurrentFolder");
        File[] roots = File.listRoots();
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
        sb.append("<Connector command=\"").append(command).append("\" resourceType=\"").append(type).append("\">");
        sb.append("<CurrentFolder path=\"").append(currentDir).append("\" url=\"").append(WebServer.getDefaultWebServer().getResourcePathURL(currentDir, "")).append("\" />");
//        try {
//          sb.append("<CurrentFolder path=\"").append(currentDir).append("\" url=\"").append(new File(currentDir).toURI().toURL()).append("\" />");
//        } catch (MalformedURLException e) {
//        }
        if(("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) && currentDir.equals("/") && roots.length > 1) {
          sb.append("<Folders>");
          for(File file: roots) {
            String rootPath = file.getAbsolutePath();
            if(Utils.IS_WINDOWS && rootPath.endsWith("\\")) {
              rootPath = rootPath.substring(0, rootPath.length() - 1);
            }
            sb.append("<Folder name=\"").append(Utils.escapeXML(rootPath)).append("\"/>");
          }
          sb.append("</Folders>");
        } else {
          if("GetFoldersAndFiles".equals(command) || "GetFolders".equals(command)) {
            sb.append("<Folders>");
            for(File file: new File(currentDir).listFiles(new FileFilter() {
              public boolean accept(File pathname) {
                return !pathname.isFile() && !pathname.isHidden() && pathname.listFiles() != null;
              }
            })) {
              sb.append("<Folder name=\"").append(Utils.escapeXML(file.getName())).append("\"/>");
            }
            sb.append("</Folders>");
          }
          if("GetFoldersAndFiles".equals(command)) {
            sb.append("<Files>");
            for(File file: new File(currentDir).listFiles(new FileFilter() {
              public boolean accept(File pathname) {
                if(!pathname.isFile()) {
                  return false;
                }
                if("Image".equals(type)) {
                  String name = pathname.getName().toLowerCase();
                  return
                  name.endsWith(".bmp") ||
                  name.endsWith(".jpg") ||
                  name.endsWith(".gif") ||
                  name.endsWith(".png");
                }
                if("Flash".equals(type)) {
                  String name = pathname.getName().toLowerCase();
                  return name.endsWith(".swf");
                }
                return true;
              }
            })) {
              sb.append("<File name=\"").append(Utils.escapeXML(file.getName())).append("\" size=\"").append(file.length() / 1000).append("\"/>");
            }
            sb.append("</Files>");
          }
        }
        sb.append("</Connector>");
        content = sb.toString();
      }
      final String content_ = content;
      return new WebServerContent() {
        @Override
        public String getContentType() {
          return "text/xml; charset=utf-8";
        }
        @Override
View Full Code Here

    });
  }

  public WebServerContent getWebServerContent(final HTTPRequest httpRequest, final String resourcePath, final int instanceID) {
    if ("index.html".equals (resourcePath)) {
      return new WebServerContent() {
        @Override
        public String getContentType() {
          int index = resourcePath.lastIndexOf('.');
          return getDefaultMimeType(index == -1? null: resourcePath.substring(index));
        }
        @Override
        public InputStream getInputStream () {
          String content =
            "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + LS +
            "  <head>" + LS +
            "    <title></title>" + LS +
            (customHTMLHeaders != null? customHTMLHeaders + LS: "") +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" + LS +
            "    <style type=\"text/css\">" + LS +
            "      body, form {margin: 0; padding: 0; overflow: auto;}" + LS +
            "    </style>" + LS +
            "    <script type=\"text/javascript\" src=\"tiny_mce.js\"></script>" + LS +
            "    <script type=\"text/javascript\">" + LS +
            "      function debug (text) {" + LS +
            "        document.getElementById ('debug').innerHTML = text;" + LS +
            "      }" + LS +
//            "      window.onerror = function (e) {" + LS +
//            "        var text = '';" + LS +
//            "        if (typeof e == 'string') {" + LS +
//            "          text = e;" + LS +
//            "        } else {" +
//            "          for (var x in e) {" + LS +
//            "            text += x+': '+e[x]+'\\n';" + LS +
//            "          }" + LS +
//            "        }" + LS +
//            "        debug (text);" + LS +
//            "      };" + LS +
            "      var sendCommand = " + JWebBrowser.COMMAND_FUNCTION + ";" + LS +
            "      var htmlContent;" + LS +
            "      var htmlDirtyTracker;" + LS +
            "      var isDirtyTrackingActive = true;" + LS +
            "      function JH_checkDirty() {" + LS +
            "        var inst = tinyMCE.get ('" + EDITOR_INSTANCE + "');" + LS +
            "        if(htmlContent == null) {" + LS +
            "          try {" + LS +
            "            htmlContent = inst.getContent();" + LS +
            "          } catch(e) {" + LS +
            "          }" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        } else {" + LS +
            "          try {" + LS +
            "            var newHtmlContent = inst.getContent();" + LS +
            "            if(newHtmlContent != htmlContent) {" + LS +
            "              htmlContent = null;" + LS +
            "              htmlDirtyTracker = null;" + LS +
            "              sendCommand('[Chrriis]JH_setDirty');" + LS +
            "            } else {" + LS +
            "              htmlContent = newHtmlContent;" + LS +
            "              htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "            }" + LS +
            "          } catch(e) {" + LS +
            "            htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "          }" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_clearDirtyIndicator() {" + LS +
            "        if(htmlDirtyTracker) {" + LS +
            "          clearTimeout(htmlDirtyTracker);" + LS +
            "        }" + LS +
            "        htmlContent = null;" + LS +
            "        if(isDirtyTrackingActive) {" + LS +
            "          htmlDirtyTracker = setTimeout('JH_checkDirty()', 1000);" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function JH_setDirtyTrackingActive(isActive) {" + LS +
            "        isDirtyTrackingActive = isActive;" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_setData (html) {" + LS +
            "        tinyMCE.get ('" + EDITOR_INSTANCE + "').setContent (decodeURIComponent (html));" + LS +
            "        JH_clearDirtyIndicator();" + LS +
            "      }" + LS +
            "      function JH_sendData () {" + LS +
            "        tinyMCE.get ('" + EDITOR_INSTANCE + "').save ();" + LS +
            "        document.jhtml_form.action = 'jhtml_sendData';" + LS +
            "        document.jhtml_form.submit ();" + LS +
            "      }" + LS +
            "      function JH_doSave () {" + LS +
            "        tinyMCE.get ('" + EDITOR_INSTANCE + "').save ();" + LS +
            "        document.jhtml_form.action = 'jhtml_save';" + LS +
            "        document.jhtml_form.submit ();" + LS +
            "        return false;" + LS +
            "      }" + LS +
            "      var opts = {" + LS +
            "        mode: 'exact'," + LS +
            "        elements: '" + EDITOR_INSTANCE + "'," + LS +
            "        theme: 'advanced'," + LS +
            "        save_onsavecallback : 'JH_doSave'," + LS +
            "        setup: function (ed) {" + LS +
            "          ed.onInit.add (function (ed) {" + LS +
            "            sendCommand ('[Chrriis]JH_setLoaded');" + LS +
            "          });" + LS +
            "        }" + LS +
            "      };" + LS +
            (customOptions != null? "      var addOpts = {" + LS + customOptions + LS + "      };" + LS + "      for (var x in addOpts) {" + LS + "        opts[x] = addOpts[x];" + LS + "      }" + LS: "") +
            "      tinyMCE.init (opts);" + LS +
            "      JH_clearDirtyIndicator();" + LS +
            "    </script>" + LS +
            "  </head>" + LS +
            "  <body>" + LS +
            "    <div id=\"debug\"></div>" + LS +
            "    <iframe style=\"display:none;\" name=\"j_iframe\"></iframe>" + LS +
            "    <form name=\"jhtml_form\" method=\"POST\" target=\"j_iframe\">" + LS +
            "      <textarea name=\"" + EDITOR_INSTANCE + "\" id=\"" + EDITOR_INSTANCE + "\" style=\"width:100%;height:100%\"></textarea>" + LS +
            "    </form>" + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("jhtml_save".equals(resourcePath)) {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          String html = JHTMLEditor.convertLinksToLocal(httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE));
          HTMLEditorSaveEvent e = null;
          for(HTMLEditorListener listener: htmlEditor.getHTMLEditorListeners()) {
            if(e == null) {
              e = new HTMLEditorSaveEvent(htmlEditor, html);
            }
            listener.saveHTML(e);
          }
        }
      });
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Save successful." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("jhtml_sendData".equals(resourcePath)) {
      String data = httpRequest.getHTTPPostDataArray()[0].getHeaderMap().get(EDITOR_INSTANCE);
      tempResult = data;
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
View Full Code Here

    resourcePath = resourcePath.substring(index + 1);
    String type = resourcePath;
    if("html".equals(type)) {
      final WebBrowserObject component = (WebBrowserObject)ObjectRegistry.getInstance().get(instanceID);
      if(component == null) {
        return new WebServerContent() {
          @Override
          public InputStream getInputStream() {
            return getInputStream("<html><body></body></html>");
          }
        };
      }
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String javascriptDefinitions = component.getJavascriptDefinitions();
          javascriptDefinitions = javascriptDefinitions == null? "": javascriptDefinitions + LS;
          String additionalHeadDefinitions = component.getAdditionalHeadDefinitions();
          additionalHeadDefinitions = additionalHeadDefinitions == null? "": additionalHeadDefinitions + LS;
          String content =
            "<html>" + LS +
            "  <head>" + LS +
            "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" + LS +
            "    <script language=\"JavaScript\" type=\"text/javascript\">" + LS +
            "      <!--" + LS +
            "      var sendCommand = " + JWebBrowser.COMMAND_FUNCTION + ";" + LS +
            "      function postCommand(command) {" + LS +
            "        var elements = new Array();" + LS +
            "        for(var i=1; i<arguments.length; i++) {" + LS +
            "          var element = document.createElement('input');" + LS +
            "          element.type='text';" + LS +
            "          element.name='j_arg' + (i-1);" + LS +
            "          element.value=arguments[i];" + LS +
            "          document.createElement('j_arg' + (i-1));" + LS +
            "          elements[i-1] = element;" + LS +
            "          document.j_form.appendChild(element);" + LS +
            "        }" + LS +
            "        document.j_form.j_command.value = command;" + LS +
            "        document.j_form.submit();" + LS +
            "        for(var i=0; i<elements.length; i++) {" + LS +
            "          document.j_form.removeChild(elements[i]);" + LS +
            "        }" + LS +
            "      }" + LS +
            "      function getEmbeddedObject() {" + LS +
            "        var movieName = \"" + getEmbeddedObjectJavascriptName() + "\";" + LS +
            "        if(window.document[movieName]) {" + LS +
            "          return window.document[movieName];" + LS +
            "        }" + LS +
            "        if(navigator.appName.indexOf(\"Microsoft Internet\") == -1) {" + LS +
            "          if(document.embeds && document.embeds[movieName]) {" + LS +
            "            return document.embeds[movieName];" + LS +
            "          }" + LS +
            "        } else {" + LS +
            "          return document.getElementById(movieName);" + LS +
            "        }" + LS +
            "      }" + LS +
            javascriptDefinitions +
            "      //-->" + LS +
            "    </script>" + LS +
            "    <style type=\"text/css\">" + LS +
            "      html { background-color: " + webBrowserObject.backgroundColor + "; }" + LS +
            "      html, object, embed, div, body, table { width: 100%; height: 100%; min-height: 100%; margin: 0; padding: 0; overflow: hidden; text-align: center; }" + LS +
            "      object, embed, div { position: absolute; left:0; top:0;}" + LS +
            "      td { vertical-align: middle; }" + LS +
            "    </style>" + LS +
            additionalHeadDefinitions +
            "  </head>" + LS +
            "  <body height=\"*\">" + LS +
            "    <iframe style=\"display:none;\" name=\"j_iframe\"></iframe>" + LS +
            "    <form style=\"display:none;\" name=\"j_form\" action=\"" + WebServer.getDefaultWebServer().getDynamicContentURL(WebBrowserObject.class.getName(), "postCommand/" + instanceID) + "\" method=\"POST\" target=\"j_iframe\">" + LS +
            "      <input name=\"j_command\" type=\"text\"></input>" + LS +
            "    </form>" + LS +
            "    <script src=\"" + WebServer.getDefaultWebServer().getDynamicContentURL(WebBrowserObject.class.getName(), String.valueOf(instanceID), "js") + "\"></script>" + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    if("js".equals(type)) {
      String url = webBrowserObject.resourcePath;
      // local files may have some security restrictions depending on the plugin, so let's ask the plugin for a valid URL.
      File file = Utils.getLocalFile(url);
      if(file != null) {
        url = webBrowserObject.getLocalFileURL(file);
      }
      final String escapedURL = Utils.escapeXML(url);
      final String encodedURL = Utils.encodeURL(url);
      return new WebServerContent() {
        @Override
        public String getContentType() {
          return getDefaultMimeType(".js");
        }
        @Override
        public InputStream getInputStream() {
          ObjectHTMLConfiguration objectHtmlConfiguration = webBrowserObject.getObjectHtmlConfiguration();
          StringBuilder objectParameters = new StringBuilder();
          StringBuilder embedParameters = new StringBuilder();
          Map<String, String> parameters = objectHtmlConfiguration.getHTMLParameters();
          HashMap<String, String> htmlParameters = parameters == null? new HashMap<String, String>(): new HashMap<String, String>(parameters);
          String windowsParamName = objectHtmlConfiguration.getWindowsParamName();
          String paramName = objectHtmlConfiguration.getParamName();
          htmlParameters.remove("width");
          htmlParameters.remove("height");
          htmlParameters.remove("type");
          htmlParameters.remove("name");
          if(windowsParamName != null) {
            htmlParameters.remove(windowsParamName);
          }
          if(paramName != null) {
            htmlParameters.remove(paramName);
          }
          for(Entry<String, String> param: htmlParameters.entrySet()) {
            String name = Utils.escapeXML(param.getKey());
            String value = Utils.escapeXML(param.getValue());
            embedParameters.append(' ').append(name).append("=\"").append(value).append("\"");
            objectParameters.append("window.document.write('  <param name=\"").append(name).append("\" value=\"").append(value).append("\"/>');" + LS);
          }
          String version = objectHtmlConfiguration.getVersion();
          String versionParameter = version != null? " version=\"" + version + "\"": "";
          String embeddedObjectJavascriptName = getEmbeddedObjectJavascriptName();
          String content =
            "<!--" + LS +
            "window.document.write('<object classid=\"clsid:" + objectHtmlConfiguration.getWindowsClassID() + "\" id=\"" + embeddedObjectJavascriptName + "\" codebase=\"" + objectHtmlConfiguration.getWindowsInstallationURL() + "\" events=\"true\">');" + LS +
            (windowsParamName == null? "": "window.document.write('  <param name=\"" + windowsParamName + "\" value=\"' + decodeURIComponent('" + encodedURL + "') + '\"/>');" + LS) +
            objectParameters +
            "window.document.write('  <embed" + embedParameters + " name=\"" + embeddedObjectJavascriptName + "\"" + (paramName == null? "": " " + paramName + "=\"" + escapedURL + "\"") + " type=\"" + objectHtmlConfiguration.getMimeType() + "\" pluginspage=\"" + objectHtmlConfiguration.getInstallationURL() + "\"" + versionParameter+ ">');" + LS +
            "window.document.write('  </embed>');" + LS +
            "window.document.write('</object>');" + LS +
            "var embeddedObject = getEmbeddedObject();" + LS +
            "embeddedObject.style.width = '100%';" + LS +
            "embeddedObject.style.height = '100%';" + LS +
            "sendCommand('[Chrriis]WB_setLoaded');" + LS +
            "window.document.attachEvent(\"onkeydown\", function() {" + LS +
            "  switch (event.keyCode) {" + LS +
                 // F5
            "    case 116 :" + LS +
            "      event.returnValue = false;" + LS +
            "      event.keyCode = 0;" + LS +
            "      break;" + LS +
            "  }" + LS +
            "});" + LS +
            "//-->" + LS;
          return getInputStream(content);
        }
      };
    }
    if("postCommand".equals(type)) {
      HTTPData postData = httpRequest.getHTTPPostDataArray()[0];
      Map<String, String> headerMap = postData.getHeaderMap();
      int size = headerMap.size();
      final String command = headerMap.get("j_command");
      final String[] arguments = new String[size - 1];
      for(int i=0; i<arguments.length; i++) {
        arguments[i] = headerMap.get("j_arg" + i);
      }
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          WebBrowserListener[] webBrowserListeners = webBrowserObject.webBrowser.getWebBrowserListeners();
          WebBrowserCommandEvent e = null;
          for(int i=webBrowserListeners.length-1; i>= 0; i--) {
            if(e == null) {
              e = new WebBrowserCommandEvent(webBrowserObject.webBrowser, command, arguments);
            }
            webBrowserListeners[i].commandReceived(e);
          }
        }
      });
      return new WebServerContent() {
        @Override
        public InputStream getInputStream() {
          String content =
            "<html>" + LS +
            "  <body>" + LS +
            "    Command sent successfully." + LS +
            "  </body>" + LS +
            "</html>" + LS;
          return getInputStream(content);
        }
      };
    }
    final String resource = resourcePath;
    return new WebServerContent() {
      @Override
      public InputStream getInputStream() {
        try {
          String url = webBrowserObject.resourcePath;
          // local files may have some security restrictions depending on the plugin, so let's ask the plugin for a valid URL.
View Full Code Here

  }

  private static final String LS = Utils.LINE_SEPARATOR;

  protected static WebServerContent getWebServerContent(HTTPRequest httpRequest) {
    return new WebServerContent() {
      @Override
      public InputStream getInputStream() {
        String content =
          "<html>" + LS +
          "  <head>" + LS +
View Full Code Here

TOP

Related Classes of chrriis.common.WebServer.WebServerContent

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.