Exemplo n.º 1
0
  /**
   * Returns the editor widget to use depending on the current users settings, current browser and
   * installed editors.
   *
   * <p>
   *
   * @param cms the current CmsObject
   * @param widgetDialog the dialog where the widget is used on
   * @return the editor widget to use depending on the current users settings, current browser and
   *     installed editors
   */
  private I_CmsWidget getEditorWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog) {

    if (m_editorWidget == null) {
      // get HTML widget to use from editor manager
      String widgetClassName =
          OpenCms.getWorkplaceManager()
              .getWorkplaceEditorManager()
              .getWidgetEditor(cms.getRequestContext(), widgetDialog.getUserAgent());
      boolean foundWidget = true;
      if (CmsStringUtil.isEmpty(widgetClassName)) {
        // no installed widget found, use default text area to edit HTML value
        widgetClassName = CmsTextareaWidget.class.getName();
        foundWidget = false;
      }
      try {
        if (foundWidget) {
          // get widget instance and set the widget configuration
          Class widgetClass = Class.forName(widgetClassName);
          A_CmsHtmlWidget editorWidget = (A_CmsHtmlWidget) widgetClass.newInstance();
          editorWidget.setHtmlWidgetOption(getHtmlWidgetOption());
          m_editorWidget = editorWidget;
        } else {
          // set the text area to display 15 rows for editing
          Class widgetClass = Class.forName(widgetClassName);
          I_CmsWidget editorWidget = (I_CmsWidget) widgetClass.newInstance();
          editorWidget.setConfiguration("15");
          m_editorWidget = editorWidget;
        }
      } catch (Exception e) {
        // failed to create widget instance
        LOG.error(
            Messages.get()
                .container(Messages.LOG_CREATE_HTMLWIDGET_INSTANCE_FAILED_1, widgetClassName)
                .key());
      }
    }
    return m_editorWidget;
  }
Exemplo n.º 2
0
  /**
   * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject,
   *     org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
   */
  public String getDialogWidget(
      CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {

    String id = param.getId();
    long idHash = id.hashCode();
    if (idHash < 0) {
      // negative hash codes will not work as JS variable names, so convert them
      idHash = -idHash;
      // add 2^32 to the value to ensure that it is unique
      idHash += 4294967296L;
    }
    StringBuffer result = new StringBuffer(128);
    result.append("<td class=\"xmlTd\">");
    result.append(
        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"xmlTd\">");
    result.append("<input class=\"xmlInput textInput");
    if (param.hasError()) {
      result.append(" xmlInputError");
    }
    result.append("\" value=\"");
    String value = param.getStringValue(cms);
    result.append(value);
    result.append("\" name=\"");
    result.append(id);
    result.append("\" id=\"");
    result.append(id);
    result.append("\" onkeyup=\"checkPreview('");
    result.append(id);
    result.append("');\"></td>");
    result.append(widgetDialog.dialogHorizontalSpacer(10));
    result.append(
        "<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");

    result.append(
        widgetDialog.button(
            "javascript:open"
                + getNameUpper()
                + "Gallery('"
                + A_CmsAjaxGallery.MODE_WIDGET
                + "',  '"
                + id
                + "',  '"
                + idHash
                + "');return false;",
            null,
            getNameLower() + "gallery",
            Messages.getButtonName(getNameLower()),
            widgetDialog.getButtonStyle()));
    // create preview button
    String previewClass = "hide";
    if (showPreview(value)) {
      // show button if preview is enabled
      previewClass = "show";
    }
    result.append("<td class=\"");
    result.append(previewClass);
    result.append("\" id=\"preview");
    result.append(id);
    result.append("\">");
    result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
    result.append(
        widgetDialog.button(
            "javascript:preview" + getNameUpper() + "('" + id + "');return false;",
            null,
            "preview.png",
            Messages.GUI_BUTTON_PREVIEW_0,
            widgetDialog.getButtonStyle()));
    result.append("</tr></table>");

    result.append("</td></tr></table>");

    result.append("</td>");
    result.append("</tr></table>");

    result.append("</td>");

    if (getNameLower().equals("image")) {
      // reads the configuration String for this widget
      CmsVfsImageWidgetConfiguration configuration =
          new CmsVfsImageWidgetConfiguration(cms, widgetDialog, param, getConfiguration());

      if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration.getStartup())) {
        result.append("\n<script type=\"text/javascript\">");
        result
            .append("\nvar startupFolder")
            .append(idHash)
            .append(" = \"")
            .append(configuration.getStartup())
            .append("\";");
        result
            .append("\nvar startupType")
            .append(idHash)
            .append(" = \"")
            .append(configuration.getType())
            .append("\";");
        result.append("\n</script>");
      } else {
        result.append("\n<script type=\"text/javascript\">");
        result.append("\nvar startupFolder").append(idHash).append(" = null;");
        result.append("\nvar startupType").append(idHash).append(" = null;");
        result.append("\n</script>");
      }

      // This part is not used in javascript for now
      if (configuration.isShowFormat()) {
        // create hidden field to store the matching image format value
        result.append("\n<script type=\"text/javascript\">");
        JSONArray formatsJson = new JSONArray(configuration.getFormatValues());
        result.append("\nvar imgFmts").append(idHash).append(" = ").append(formatsJson).append(";");
        result
            .append("\nvar imgFmtNames")
            .append(idHash)
            .append(" = \"")
            .append(
                CmsEncoder.escape(configuration.getSelectFormatString(), CmsEncoder.ENCODING_UTF_8))
            .append("\";");
        result.append("\nvar useFmts").append(idHash).append(" = true;");
        result.append("\n</script>");
      } else {
        result.append("\n<script type=\"text/javascript\">");
        result.append("\nvar useFmts").append(idHash).append(" = false;");
        result.append("\nvar imgFmts").append(idHash).append(" = null;");
        result.append("\nvar imgFmtNames").append(idHash).append(" = null;");
        result.append("\n</script>");
      }
    } else { // for download, link, html or table galleries
      // reads the configuration String for this widget
      CmsGalleryWidgetConfiguration configuration =
          new CmsGalleryWidgetConfiguration(cms, widgetDialog, param, getConfiguration());

      if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration.getStartup())) {
        result.append("\n<script type=\"text/javascript\">");
        result
            .append("\nvar startupFolder")
            .append(idHash)
            .append(" = \"")
            .append(configuration.getStartup())
            .append("\";");
        result
            .append("\nvar startupType")
            .append(idHash)
            .append(" = \"")
            .append(configuration.getType())
            .append("\";");
        result.append("\n</script>");
      } else {
        result.append("\n<script type=\"text/javascript\">");
        result.append("\nvar startupFolder").append(idHash).append(" = null;");
        result.append("\nvar startupType").append(idHash).append(" = null;");
        result.append("\n</script>");
      }
    }

    return result.toString();
  }