Package gnu.java.lang

Examples of gnu.java.lang.CPStringBuilder


   *     will inspect certain properties of the handler, for
   *     example its encoding, in order to construct the header.
   */
  public String getHead(Handler h)
  {
    CPStringBuilder  buf;
    String        encoding;

    buf = new CPStringBuilder(80);
    buf.append("<?xml version=\"1.0\" encoding=\"");

    encoding = h.getEncoding();

    /* file.encoding is a system property with the Sun JVM, indicating
     * the platform-default file encoding. Unfortunately, the API
     * specification for java.lang.System.getProperties() does not
     * list this property.
     */
    if (encoding == null)
      encoding = System.getProperty("file.encoding");

    /* Since file.encoding is not listed with the API specification of
     * java.lang.System.getProperties(), there might be some VMs that
     * do not define this system property.  Therefore, we use UTF-8 as
     * a reasonable default. Please note that if the platform encoding
     * uses the same codepoints as US-ASCII for the US-ASCII character
     * set (e.g, 65 for A), it does not matter whether we emit the
     * wrong encoding into the XML header -- the GNU Classpath will
     * emit XML escape sequences like &#1234; for any non-ASCII
     * character.  Virtually all character encodings use the same code
     * points as US-ASCII for ASCII characters.  Probably, EBCDIC is
     * the only exception.
     */
    if (encoding == null)
      encoding = "UTF-8";
   
    /* On Windows XP localized for Swiss German (this is one of
     * my [Sascha Brawer's] test machines), the default encoding
     * has the canonical name "windows-1252". The "historical" name
     * of this encoding is "Cp1252" (see the Javadoc for the class
     * java.nio.charset.Charset for the distinction). Now, that class
     * does have a method for mapping historical to canonical encoding
     * names. However, if we used it here, we would be come dependent
     * on java.nio.*, which was only introduced with J2SE 1.4.
     * Thus, we do this little hack here. As soon as Classpath supports
     * java.nio.charset.CharSet, this hack should be replaced by
     * code that correctly canonicalizes the encoding name.
     */
    if ((encoding.length() > 2) && encoding.startsWith("Cp"))
      encoding = "windows-" + encoding.substring(2);

    buf.append(encoding);

    buf.append("\" standalone=\"no\"?>");
    buf.append(lineSep);

    /* SYSTEM is not a fully qualified URL so that validating
     * XML parsers do not need to connect to the Internet in
     * order to read in a log file.  See also the Sun Bug Parade,
     * bug #4372790, "Logging APIs: need to use relative URL for XML
     * doctype".
     */
    buf.append("<!DOCTYPE log SYSTEM \"logger.dtd\">");
    buf.append(lineSep);
    buf.append("<log>");
    buf.append(lineSep);

    return buf.toString();
  }
View Full Code Here


   *
   * @return a string identifying this event
   */
  public String paramString()
  {
    CPStringBuilder s = new CPStringBuilder();
   
    // Unlike Sun, we don't throw NullPointerException or ClassCastException
    // when source was illegally changed.
    if (id == COMPONENT_MOVED)
      s.append("COMPONENT_MOVED ");
    else if (id == COMPONENT_RESIZED)
      s.append("COMPONENT_RESIZED ");
    else if (id == COMPONENT_SHOWN)
      s.append("COMPONENT_SHOWN ");
    else if (id == COMPONENT_HIDDEN)
      s.append("COMPONENT_HIDDEN ");
    else
      return "unknown type";

    s.append("(").append(getComponent().getX()).append(",")
      .append(getComponent().getY()).append(" ")
      .append(getComponent().getWidth()).append("x")
      .append(getComponent().getHeight()).append(")");

    return s.toString();
  }
View Full Code Here

    return hash;
  }

  public String toString()
  {
    CPStringBuilder s = new CPStringBuilder("copies=").append(copies)
      .append(",defaultSelection=").append(selection).append(",destination=")
      .append(destination).append(",dialog=").append(dialog)
      .append(",fileName=").append(filename).append(",fromPage=")
      .append(getFromPage()).append(",maxPage=").append(maxPage)
      .append(",minPage=").append(minPage)
      .append(",multiple-document-handling=").append(multiple)
      .append(",page-ranges=[");
    if (pageRanges == null)
      s.append(minPage).append(':').append(minPage).append(']');
    else
      for (int i = 0; i < pageRanges.length; i++)
        s.append(pageRanges[i][0]).append(':').append(pageRanges[i][1])
          .append(',');
    s.setLength(s.length() - 1);
    return s.append("],printer=").append(printer).append(",sides=")
      .append(sides).append(",toPage=").append(getToPage()).toString();
  }
View Full Code Here

   * @throws NullPointerException if <code>record</code>
   *         is <code>null</code>.
   */
  public String format(LogRecord record)
  {
    CPStringBuilder buf = new CPStringBuilder(180);

    if (dateFormat == null)
      dateFormat = DateFormat.getDateTimeInstance();

    buf.append(dateFormat.format(new Date(record.getMillis())));
    buf.append(' ');
    buf.append(record.getSourceClassName());
    buf.append(' ');
    buf.append(record.getSourceMethodName());
    buf.append(lineSep);

    buf.append(record.getLevel());
    buf.append(": ");
    buf.append(formatMessage(record));

    buf.append(lineSep);

    Throwable throwable = record.getThrown();
    if (throwable != null)
      {
        StringWriter sink = new StringWriter();
        throwable.printStackTrace(new PrintWriter(sink, true));
        buf.append(sink.toString());
      }

    return buf.toString();
  }
View Full Code Here

  public static String getModifiersExText(int modifiers)
  {
    modifiers &= EventModifier.NEW_MASK;
    if (modifiers == 0)
      return "";
    CPStringBuilder s = new CPStringBuilder();
    if ((modifiers & META_DOWN_MASK) != 0)
      s.append("Meta+");
    if ((modifiers & CTRL_DOWN_MASK) != 0)
      s.append("Ctrl+");
    if ((modifiers & ALT_DOWN_MASK) != 0)
      s.append("Alt+");
    if ((modifiers & SHIFT_DOWN_MASK) != 0)
      s.append("Shift+");
    if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0)
      s.append("Alt Graph+");
    if ((modifiers & BUTTON1_DOWN_MASK) != 0)
      s.append("Button1+");
    if ((modifiers & BUTTON2_DOWN_MASK) != 0)
      s.append("Button2+");
    if ((modifiers & BUTTON3_DOWN_MASK) != 0)
      s.append("Button3+");
    return s.substring(0, s.length() - 1);
  }
View Full Code Here

   *
   * @return a string identifying this event
   */
  public String paramString()
  {
    CPStringBuilder s = new CPStringBuilder();
    switch (id)
      {
      case MOUSE_CLICKED:
        s.append("MOUSE_CLICKED,(");
        break;
      case MOUSE_PRESSED:
        s.append("MOUSE_PRESSED,(");
        break;
      case MOUSE_RELEASED:
        s.append("MOUSE_RELEASED,(");
        break;
      case MOUSE_MOVED:
        s.append("MOUSE_MOVED,(");
        break;
      case MOUSE_ENTERED:
        s.append("MOUSE_ENTERED,(");
        break;
      case MOUSE_EXITED:
        s.append("MOUSE_EXITED,(");
        break;
      case MOUSE_DRAGGED:
        s.append("MOUSE_DRAGGED,(");
        break;
      case MOUSE_WHEEL:
        s.append("MOUSE_WHEEL,(");
        break;
      default:
        s.append("unknown type,(");
      }
    s.append(x).append(',').append(y).append("),button=").append(button);
    // FIXME: need a mauve test for this method
    if (modifiersEx != 0)
      s.append(",extModifiers=").append(getModifiersExText(modifiersEx));
   
    s.append(",clickCount=").append(clickCount);
    s.append(",consumed=").append(consumed);
   
    return s.toString();
  }
View Full Code Here

   * @see Map.Entry#toString()
   */
  public String toString()
  {
    Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
    CPStringBuilder r = new CPStringBuilder("{");
    for (int pos = size(); pos > 0; pos--)
      {
        Map.Entry<K, V> entry = entries.next();
        r.append(entry.getKey());
        r.append('=');
        r.append(entry.getValue());
        if (pos > 1)
          r.append(", ");
      }
    r.append("}");
    return r.toString();
  }
View Full Code Here

  {
    synchronized (lock)
      {
        if (isLoggable(Level.FINER))
          {
            CPStringBuilder buf = new CPStringBuilder(80);
            buf.append("ENTRY");
            for (int i = 0; i < params.length; i++)
              {
                buf.append(" {");
                buf.append(i);
                buf.append('}');
              }

            logp(Level.FINER, sourceClass, sourceMethod, buf.toString(), params);
          }
      }
  }
View Full Code Here

  }


  public String format(LogRecord record)
  {
    CPStringBuilder    buf = new CPStringBuilder(400);
    Level           level = record.getLevel();
    long            millis = record.getMillis();
    Object[]        params = record.getParameters();
    ResourceBundle  bundle = record.getResourceBundle();
    String          message;
   
    buf.append("<record>");
    buf.append(lineSep);
   
   
    appendTag(buf, 1, "date", iso8601.format(new Date(millis)));
    appendTag(buf, 1, "millis", millis);
    appendTag(buf, 1, "sequence", record.getSequenceNumber());
    appendTag(buf, 1, "logger", record.getLoggerName());

    if (level.isStandardLevel())
      appendTag(buf, 1, "level", level.toString());
    else
      appendTag(buf, 1, "level", level.intValue());

    appendTag(buf, 1, "class", record.getSourceClassName());
    appendTag(buf, 1, "method", record.getSourceMethodName());
    appendTag(buf, 1, "thread", record.getThreadID());

    /* The Sun J2SE 1.4 reference implementation does not emit the
     * message in localized form. This is in violation of the API
     * specification. The GNU Classpath implementation intentionally
     * replicates the buggy behavior of the Sun implementation, as
     * different log files might be a big nuisance to users.
     */
    try
    {
      record.setResourceBundle(null);
      message = formatMessage(record);
    }
    finally
    {
      record.setResourceBundle(bundle);
    }
    appendTag(buf, 1, "message", message);

    /* The Sun J2SE 1.4 reference implementation does not
     * emit key, catalog and param tags. This is in violation
     * of the API specification.  The Classpath implementation
     * intentionally replicates the buggy behavior of the
     * Sun implementation, as different log files might be
     * a big nuisance to users.
     *
     * FIXME: File a bug report with Sun. Insert bug number here.
     *
     *
     * key = record.getMessage();
     * if (key == null)
     *   key = "";
     *
     * if ((bundle != null) && !key.equals(message))
     * {
     *   appendTag(buf, 1, "key", key);
     *   appendTag(buf, 1, "catalog", record.getResourceBundleName());
     * }
     *
     * if (params != null)
     * {
     *   for (int i = 0; i < params.length; i++)
     *     appendTag(buf, 1, "param", params[i].toString());
     * }
     */

    /* FIXME: We have no way to obtain the stacktrace before free JVMs
     * support the corresponding method in java.lang.Throwable.  Well,
     * it would be possible to parse the output of printStackTrace,
     * but this would be pretty kludgy. Instead, we postpose the
     * implementation until Throwable has made progress.
     */
    Throwable thrown = record.getThrown();
    if (thrown != null)
    {
      buf.append("  <exception>");
      buf.append(lineSep);

      /* The API specification is not clear about what exactly
       * goes into the XML record for a thrown exception: It
       * could be the result of getMessage(), getLocalizedMessage(),
       * or toString(). Therefore, it was necessary to write a
       * Mauve testlet and run it with the Sun J2SE 1.4 reference
       * implementation. It turned out that the we need to call
       * toString().
       *
       * FIXME: File a bug report with Sun, asking for clearer
       * specs.
       */
      appendTag(buf, 2, "message", thrown.toString());

      /* FIXME: The Logging DTD specifies:
       *
       * <!ELEMENT exception (message?, frame+)>
       *
       * However, java.lang.Throwable.getStackTrace() is
       * allowed to return an empty array. So, what frame should
       * be emitted for an empty stack trace? We probably
       * should file a bug report with Sun, asking for the DTD
       * to be changed.
       */

      buf.append("  </exception>");
      buf.append(lineSep);
    }


    buf.append("</record>");
    buf.append(lineSep);

    return buf.toString();
  }
View Full Code Here

   *
   * @return a string identifying the event
   */
  public String paramString()
  {
    CPStringBuilder s
      = new CPStringBuilder(80 + (text == null ? 0
                               : text.getEndIndex() - text.getBeginIndex()));
    s.append(id == INPUT_METHOD_TEXT_CHANGED ? "INPUT_METHOD_TEXT_CHANGED, "
             : "CARET_POSITION_CHANGED, ");
    if (text == null)
      s.append("no text, 0 characters committed, caret: ");
    else
      {
        s.append('"');
        int i = text.getBeginIndex();
        int j = committedCharacterCount;
        while (--j >= 0)
          s.append(text.setIndex(i++));
        s.append("\" + \"");
        j = text.getEndIndex() - i;
        while (--j >= 0)
          s.append(text.setIndex(i++));
        s.append("\", ").append(committedCharacterCount)
          .append(" characters committed, caret: ");         
      }
    s.append(caret == null ? (Object) "no caret" : caret).append(", ")
      .append(visiblePosition == null ? (Object) "no visible position"
              : visiblePosition);
    return s.toString();
  }
View Full Code Here

TOP

Related Classes of gnu.java.lang.CPStringBuilder

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.