コード例 #1
0
  /**
   * @see org.opencms.widgets.I_CmsWidget#setEditorValue(org.opencms.file.CmsObject, java.util.Map,
   *     org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
   */
  public void setEditorValue(
      CmsObject cms,
      Map formParameters,
      I_CmsWidgetDialog widgetDialog,
      I_CmsWidgetParameter param) {

    String[] values = (String[]) formParameters.get(param.getId());
    if ((values != null) && (values.length > 0)) {
      String val = CmsEncoder.decode(values[0], CmsEncoder.ENCODING_UTF_8);
      param.setStringValue(cms, val);
    }
  }
コード例 #2
0
  /**
   * Internal action method.
   *
   * <p>
   *
   * @param setting the setting to look up
   * @param defaultValue the default value
   * @param escape if the result String should be HTML escaped or not
   * @param req the current request
   * @return the value of the element setting or <code>null</code> if not found
   */
  public static String elementSettingTagAction(
      String setting, String defaultValue, boolean escape, ServletRequest req) {

    String value = elementSettingTagAction(req).get(setting);
    if (value == null) {
      value = defaultValue;
    }
    if (escape) {
      // HTML escape the value
      value = CmsEncoder.escapeHtml(value);
    }
    return value;
  }
コード例 #3
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();
  }
コード例 #4
0
  /**
   * Returns the HTML for the dialog input form to comment the images.
   *
   * <p>
   *
   * @return the HTML for the dialog input form to comment the images
   */
  public String buildDialogForm() {

    StringBuffer result = new StringBuffer(16384);
    Iterator i = getImages().iterator();

    result.append("<div style=\"height: 450px; padding: 4px; overflow: auto;\">");

    while (i.hasNext()) {
      CmsResource res = (CmsResource) i.next();
      String imageName = res.getName();
      String propertySuffix = "" + imageName.hashCode();
      result.append(dialogBlockStart(imageName));
      result.append("<table border=\"0\">\n");
      result.append("<tr>\n\t<td style=\"vertical-align: top;\">");
      // create image tag
      result.append("<img src=\"");
      StringBuffer link = new StringBuffer(256);
      link.append(getCms().getSitePath(res));
      link.append(getImageScaler().toRequestParam());
      result.append(getJsp().link(link.toString()));
      result.append("\" border=\"0\" alt=\"\" width=\"");
      result.append(getImageScaler().getWidth());
      result.append("\" height=\"");
      result.append(getImageScaler().getHeight());
      result.append("\">");

      result.append("</td>\n");
      result.append("\t<td class=\"maxwidth\" style=\"vertical-align: top;\">\n");

      result.append("\t\t<table border=\"0\">\n");

      // build title property input row
      String title = "";
      try {
        title =
            getCms()
                .readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TITLE, false)
                .getValue();
      } catch (CmsException e) {
        // log, should never happen
        if (LOG.isErrorEnabled()) {
          LOG.error(e.getLocalizedMessage(getLocale()));
        }
      }
      result.append("\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap;\" unselectable=\"on\">");
      result.append(key(Messages.GUI_LABEL_TITLE_0));
      result.append(":</td>\n\t\t\t<td class=\"maxwidth\">");
      result.append("<input type=\"text\" class=\"maxwidth\" name=\"");
      result.append(PREFIX_TITLE);
      result.append(propertySuffix);
      result.append("\" value=\"");
      if (CmsStringUtil.isNotEmpty(title)) {
        result.append(CmsEncoder.escapeXml(title));
      }
      result.append("\">");
      result.append("</td>\n\t\t</tr>\n");

      // build description property input row
      String description = "";
      try {
        description =
            getCms()
                .readPropertyObject(res, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false)
                .getValue();
      } catch (CmsException e) {
        // log, should never happen
        if (LOG.isErrorEnabled()) {
          LOG.error(e.getLocalizedMessage(getLocale()));
        }
      }
      result.append(
          "\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap; vertical-align: top;\" unselectable=\"on\">");
      result.append(key(Messages.GUI_LABEL_DESCRIPTION_0));
      result.append(":</td>\n\t\t\t<td style=\"vertical-align: top; height: 110px;\">");
      result.append("<textarea rows=\"8\" class=\"maxwidth\" style=\"overflow: auto;\" name=\"");
      result.append(PREFIX_DESCRIPTION);
      result.append(propertySuffix);
      result.append("\">");
      if (CmsStringUtil.isNotEmpty(description)) {
        result.append(CmsEncoder.escapeXml(description));
      }
      result.append("</textarea>");
      result.append("</td>\n\t\t</tr>\n");

      result.append("\t\t</table>\n");

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

      if (i.hasNext()) {
        // append spacer if another entry follows
        result.append(dialogSpacer());
      }
    }

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

    return result.toString();
  }