mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
12.06.2012 1e66ccf45c723c6e076285f030202f320c2dfd90
Fix OPENDJ-400.
2 files modified
95 ■■■■ changed files
opends/src/guitools/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java 29 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java 66 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2012 ForgeRock AS
 */
package org.opends.guitools.controlpanel.ui;
@@ -52,6 +53,7 @@
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.Base64;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.LDIFReader;
/**
@@ -80,6 +82,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public Component getPreferredFocusComponent()
  {
    return editableAttributes;
@@ -107,16 +110,19 @@
    editableAttributes = Utilities.createTextArea(Message.EMPTY, 20, 30);
    editableAttributes.getDocument().addDocumentListener(new DocumentListener()
    {
      @Override
      public void insertUpdate(DocumentEvent ev)
      {
        notifyListeners();
      }
      @Override
      public void changedUpdate(DocumentEvent ev)
      {
        notifyListeners();
      }
      @Override
      public void removeUpdate(DocumentEvent ev)
      {
        notifyListeners();
@@ -149,6 +155,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public void update(CustomSearchResult sr, boolean isReadOnly, TreePath path)
  {
    boolean sameEntry = false;
@@ -167,7 +174,7 @@
    StringBuilder sb = new StringBuilder();
    sb.append("dn: "+sr.getDN());
    sb.append("dn: ").append(sr.getDN());
    if (isReadOnly)
    {
@@ -177,7 +184,7 @@
        List<Object> values = sr.getAttributeValues(attrName);
        for (Object o : values)
        {
          sb.append("\n"+ getLDIFLine(attrName, o));
          sb.append("\n").append(getLDIFLine(attrName, o));
        }
      }
      final Point p1 = sameEntry ?
@@ -188,6 +195,7 @@
        /**
         * {@inheritDoc}
         */
        @Override
        public void run()
        {
          if ((p1 != null) && (readOnlyScroll.getViewport().contains(p1)))
@@ -208,7 +216,7 @@
          List<Object> values = sr.getAttributeValues(attrName);
          for (Object o : values)
          {
            sb.append("\n"+ getLDIFLine(attrName, o));
            sb.append("\n").append(getLDIFLine(attrName, o));
          }
        }
      }
@@ -223,6 +231,7 @@
        /**
         * {@inheritDoc}
         */
        @Override
        public void run()
        {
          if ((p1 != null) && (editableScroll.getViewport().contains(p1)))
@@ -255,6 +264,7 @@
        /**
         * {@inheritDoc}
         */
        @Override
        public void run()
        {
          if ((p2 != null) && (readOnlyScroll.getViewport().contains(p2)))
@@ -269,6 +279,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public GenericDialog.ButtonType getButtonType()
  {
    return GenericDialog.ButtonType.NO_BUTTON;
@@ -278,6 +289,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  protected String getDisplayedDN()
  {
    String dn = null;
@@ -298,6 +310,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  protected List<Object> getValues(String attrName)
  {
    throw new IllegalStateException("This method should not be called.");
@@ -306,6 +319,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public Entry getEntry() throws OpenDsException
  {
    Entry entry = null;
@@ -358,8 +372,17 @@
    String attrValue;
    if (o instanceof String)
    {
      //
      if (Utilities.hasControlCharaters((String)o))
      {
        attrValue = Base64.encode(StaticUtils.getBytes((String)o));
        attrName = attrName+":";
      }
      else
      {
      attrValue = (String)o;
    }
    }
    else if (o instanceof byte[])
    {
      attrValue = Base64.encode((byte[])o);
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2012 ForgeRock AS
 */
package org.opends.guitools.controlpanel.util;
@@ -52,6 +52,8 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
@@ -391,8 +393,8 @@
  {
    StringBuilder buf = new StringBuilder();
    buf.append("font-family:" + font.getName()).append(
        ";font-size:" + font.getSize() + "pt");
    buf.append("font-family:").append(font.getName())
        .append(";font-size:").append(font.getSize()).append("pt");
    if (font.isItalic())
    {
@@ -1562,6 +1564,37 @@
  }
  /**
   * Strings any potential "separator" from a given string.
   * @param s string to strip
   * @param separator  the separator string to remove
   * @return resulting string
   */
  public static String stripStringToSingleLine(String s, String separator)
  {
    String o = null;
    if (s != null)
    {
      o = s.replaceAll(separator, "");
    }
    return o;
  }
  /* The pattern for control characters */
  private static Pattern cntrl_pattern =
      Pattern.compile("\\p{Cntrl}", Pattern.MULTILINE);
  /**
   * Checks if a string contains control characters.
   * @param s : the string to check
   * @return true if s contains control characters, false otherwise
   */
  public static Boolean hasControlCharaters(String s)
  {
    Matcher m = cntrl_pattern.matcher(s);
    return m.find();
  }
  /**
   * This is a helper method that gets a String representation of the elements
   * in the Collection. The String will display the different elements separated
   * by the separator String.
@@ -1583,7 +1616,7 @@
      {
        msg.append(separator);
      }
      msg.append(m);
      msg.append(stripStringToSingleLine(m, separator));
    }
    return msg.toString();
  }
@@ -1663,9 +1696,9 @@
      Message details, Font detailsFont)
  {
    StringBuilder buf = new StringBuilder();
    String space = "&nbsp;";
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.ERROR_LARGE) + space
          + space + applyFont(title.toString(), titleFont));
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.ERROR_LARGE))
        .append(HTML_SPACE).append(HTML_SPACE)
        .append(applyFont(title.toString(), titleFont));
    if (details != null)
    {
      buf.append("<br><br>")
@@ -1687,9 +1720,9 @@
      Message details, Font detailsFont)
  {
    StringBuilder buf = new StringBuilder();
    String space = "&nbsp;";
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.INFORMATION_LARGE) +
        space + space + applyFont(title.toString(), titleFont));
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.INFORMATION_LARGE))
        .append(HTML_SPACE).append(HTML_SPACE)
        .append(applyFont(title.toString(), titleFont));
    if (details != null)
    {
      buf.append("<br><br>")
@@ -1711,9 +1744,9 @@
      Message details, Font detailsFont)
  {
    StringBuilder buf = new StringBuilder();
    String space = "&nbsp;";
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE) + space
          + space + applyFont(title.toString(), titleFont));
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE))
        .append(HTML_SPACE).append(HTML_SPACE)
        .append(applyFont(title.toString(), titleFont));
    if (details != null)
    {
      buf.append("<br><br>")
@@ -1735,9 +1768,9 @@
      Message details, Font detailsFont)
  {
    StringBuilder buf = new StringBuilder();
    String space = "&nbsp;";
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE) +
        space + space + applyFont(title.toString(), titleFont));
    buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE))
        .append(HTML_SPACE).append(HTML_SPACE)
        .append(applyFont(title.toString(), titleFont));
    if (details != null)
    {
      buf.append("<br><br>")
@@ -2547,6 +2580,7 @@
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        for (int i=0; i<pos.size(); i++)