Examples of CharBuffer


Examples of com.caucho.util.CharBuffer

  }

  private void parseArgs(Element elt, String arg)
    throws IOException, XslParseException
  {
    CharBuffer cb = CharBuffer.allocate();
    String key = null;
    boolean isFirst = true;
    int ch;
   
    for (ch = read(); ch >= 0 && ch != ')'; ch = read()) {
      cb.append((char) ch);
     
      switch (ch) {
      case '(':
        lexToRparen(cb);
        cb.append(')');
        break;

      case '"': case '\'':
        lexString(cb, ch);
        break;
       
      case '=':
        ch = read();
        if (ch == '>') {
          cb.setLength(cb.length() - 1);
          key = cb.toString().trim();
          cb.clear();
        }
        else {
          peek = ch;
        }
        break;
       
      case ',':
        cb.setLength(cb.length() - 1);
        if (key != null)
          elt.setAttribute(key, cb.toString());
        else if (arg != null && isFirst)
          elt.setAttribute(arg, cb.toString());
        else
          throw error(L.l("unexpected arg `{0}'", cb));
        cb.clear();
        isFirst = false;
        key = null;
        break;
      }

    }

    if (ch != ')')
      throw error(L.l("expected `{0}' at {1}", ")", badChar(ch)));

    if (key != null)
      elt.setAttribute(key, cb.close());
    else if (arg != null && cb.length() > 0 && isFirst)
      elt.setAttribute(arg, cb.close());
    else if (cb.length() > 0)
      throw error(L.l("unexpected arg `{0}'", cb));
  }
View Full Code Here

Examples of com.caucho.util.CharBuffer

  private void parseContentType(Node parent, String contentType)
    throws IOException, XslParseException
  {
    CharCursor cursor = new StringCharCursor(contentType);

    CharBuffer buf = new CharBuffer();
    wsScanner.skip(cursor);
    delimScanner.scan(cursor, buf);

    if (buf.length() <= 0)
      return;

    Element output = xsl.createElementNS(XSLNS, "xsl:output");
    parent.appendChild(output);
    output.setAttribute("media-type", buf.toString());
    delimScanner.skip(cursor);

    buf.clear();
    delimScanner.scan(cursor, buf);
    wsScanner.skip(cursor);
    if (cursor.current() == '=' && buf.toString().equals("charset")) {
      delimScanner.skip(cursor);
      buf.clear();
      delimScanner.scan(cursor, buf);
      if (buf.length() > 0) {
        output.setAttribute("encoding", Encoding.getMimeName(buf.toString()));
        is.setEncoding(buf.toString());
      }
    }
  }
View Full Code Here

Examples of com.caucho.util.CharBuffer

    return AuthorizationResult.DENY;
  }

  public String toString()
  {
    CharBuffer cb = new CharBuffer();

    cb.append(getClass().getSimpleName());
    cb.append("[");
    for (int i = 0; i < _roles.length; i++) {
      if (i != 0)
        cb.append(',');
      cb.append(_roles[i]);
    }
    cb.append("]");
   
    return cb.close();
  }
View Full Code Here

Examples of com.caucho.util.CharBuffer

   * Parses the access log string.
   */
  private ArrayList<Segment> parseFormat(String format)
  {
    ArrayList<Segment> segments = new ArrayList<Segment>();
    CharBuffer cb = new CharBuffer();

    int i = 0;
    while (i < _format.length()) {
      char ch = _format.charAt(i++);

      if (ch != '%' || i >= _format.length()) {
        cb.append((char) ch);
        continue;
      }

      String arg = null;
      ch = _format.charAt(i++);
      if (ch == '>')
        ch = _format.charAt(i++);
      else if (ch == '{') {
        if (cb.length() > 0)
          segments.add(new Segment(this, Segment.TEXT, cb.toString()));
        cb.clear();
        while (i < _format.length() && _format.charAt(i++) != '}')
          cb.append(_format.charAt(i - 1));
        arg = cb.toString();
        cb.clear();

        ch = _format.charAt(i++);
      }

      switch (ch) {
      case 'b': case 'c':
      case 'h': case 'i': case 'l': case 'n':
      case 'r': case 's':
      case 'T': case 'D': case 'o':
      case 'u': case 'U':
      case 'v': case 'S':
        if (cb.length() > 0)
          segments.add(new Segment(this, Segment.TEXT, cb.toString()));
        cb.clear();
        segments.add(new Segment(this, ch, arg));
        break;

      case 't':
        if (cb.length() > 0)
          segments.add(new Segment(this, Segment.TEXT, cb.toString()));
        cb.clear();
        if (arg != null)
          _timeFormat = arg;
        segments.add(new Segment(this, ch, arg));
        break;

      default:
        cb.append('%');
        i--;
        break;
      }
    }

    cb.append(CauchoSystem.getNewlineString());
    segments.add(new Segment(this, Segment.TEXT, cb.toString()));

    return segments;
  }
View Full Code Here

Examples of com.caucho.util.CharBuffer

    if (length < 2 + offset ||
        uri.charAt(offset) != '/' ||
        uri.charAt(offset + 1) != '/')
      throw new RuntimeException(L.l("bad scheme in `{0}'", uri));

    CharBuffer buf = CharBuffer.allocate();
    int i = 2 + offset;
    int ch = 0;
    for (; i < length && (ch = uri.charAt(i)) != ':' && ch != '/' && ch != '?';
         i++) {
      buf.append((char) ch);
    }

    String host = buf.close();
    if (host.length() == 0)
      throw new RuntimeException(L.l("bad host in `{0}'", uri));

    int port = 0;
    if (ch == ':') {
View Full Code Here

Examples of com.caucho.util.CharBuffer

            crc64 = Crc64.generate(crc64, pattern);
          }
        }
      }

      CharBuffer cb = new CharBuffer();
      Base64.encode(cb, crc64);
      String newETag = cb.close();
      host.setConfigETag(newETag);
   
      writeString(os, HMUX_ETAG, host.getConfigETag());
    }
    else {
View Full Code Here

Examples of com.caucho.util.CharBuffer

    return _matchPatterns.size() - 1;
  }

  String getName(String tag)
  {
    CharBuffer newTag = new CharBuffer();

    for (int i = 0; i < tag.length(); i++) {
      int ch = tag.charAt(i);
      switch (ch) {
      case ' ':
      case '\t':
      case '\r':
      case '\n':
      case '(':
      case ')':
        break;

      case ':':
      case '.':
      case '|':
        newTag.append('_');
        break;

      default:
        if (ch >= 'a' && ch <= 'z' ||
            ch >= 'A' && ch <= 'Z' ||
            ch >= '0' && ch <= '9')
          newTag.append((char) ch);
      }
    }
    tag = newTag.toString();

    if (_names.get(tag) == null) {
      _names.put(tag, tag);
      return tag;
    }
View Full Code Here

Examples of com.caucho.util.CharBuffer

   * @param elt the containing element.  Needed for namespaces.
   */
  void generateString(String string, int mode, Element elt)
    throws Exception
  {
    CharBuffer cb = new CharBuffer();
    int i = 0;
    boolean first = true;
    int length = string.length();

    for (; i < length; i++) {
      char ch = string.charAt(i);

      if (ch == '\n') {
        cb.append("\\n");
      }
      else if (ch == '"') {
        cb.append("\\\"");
      }
      else if (ch == '{' && i + 1 < length) {
        // {{ is treated as a single {
        if (string.charAt(i + 1) == '{') {
          cb.append('{');
          i++;
        }
        // the value is computed from an XPath expr
        else {
          // print the gathered text if any
          if (mode == ',') {
            if (cb.length() > 0)
              println("out.print(\"" + cb.toString() + "\");");
          }
          else {
            if (! first)
              print((char) mode);

            if (cb.length() > 0) {
              print("\"");
              print(cb.toString());
              print("\"");
              print((char) mode);
            }
          }

          // scan the contents of '{' ... '}'
          cb.clear();
          for (i++; i < length && string.charAt(i) != '}'; i++)
            cb.append(string.charAt(i));

          // and add the results
          if (mode == ',')
            printStringExpr(cb.toString(), elt);
          else
            stringExpr(cb.toString(), elt);
          cb.clear();
          first = false;
        }
      }
      // }} is treated as a single }
      else if (ch == '}' && i + 1 < length) {
        if (string.charAt(i + 1) == '}') {
          cb.append('}');
          i++;
        }
        else
          cb.append('}');
      }
      // <#= interpolates
      else if (i + 2 < length && ch == '<' &&
               string.charAt(i + 1) == '#' &&
               string.charAt(i + 2) == '=') {
        // print the gathered text if any
        if (mode == ',') {
          if (cb.length() > 0)
            println("out.print(\"" + cb.toString() + "\");");
        }
        else {
          if (! first)
            print((char) mode);

          if (cb.length() > 0) {
            print("\"");
            print(cb.toString());
            print("\"");
            print((char) mode);
          }
        }

        // scan the contents of '{' ... '}'
        cb.clear();
        for (i += 3;
             i + 1 < length && string.charAt(i) != '#' &&
               string.charAt(i + 1) != '>';
             i++)
          cb.append(string.charAt(i));

        i++;

        // and add the results
        if (mode == ',')
          println("out.print(" + cb + ");");
        else {
          print("(" + cb + ")");
        }
        cb.clear();
        first = false;
      }
      else
        cb.append((char) ch);
    }

    // add any trailing text
    if (cb.length() > 0) {
      if (mode == ',')
        println("out.print(\"" + cb + "\");");
      else {
        if (! first)
          print((char) mode);
View Full Code Here

Examples of com.caucho.util.CharBuffer

    }
  }

  public String toString()
  {
    CharBuffer cb = CharBuffer.allocate();
    cb.append("(");

    for (int i = 0; i < _exprList.size(); i++) {
      if (i != 0)
        cb.append(" AND ");

      cb.append(_exprList.get(i));
    }

    cb.append(")");

    return cb.close();
  }
View Full Code Here

Examples of com.caucho.util.CharBuffer

   * @return the variable storing the generated string.
   */
  String generateStringVar(String string, Element elt)
    throws Exception
  {
    CharBuffer cb = new CharBuffer();
    int i = 0;
    boolean first = true;
    int length = string.length();

    String strVar = "_xsl_str" + _unique++;

    if (string.indexOf('{') < 0 &&
        string.indexOf('}') < 0) {
      print("String " + strVar + " = \"");
      printString(string);
      println("\";");
     
      return strVar;
    }
    else if (string.lastIndexOf('{') == 0 &&
        string.indexOf('}') == string.length() - 1) {
      println("String " + strVar + " = \"\";");
      string = string.substring(1, string.length() - 1);
     
      addStringExpr(strVar, string, elt, true);
      return strVar;
    }

   
    String cbVar = "_xsl_cb" + _unique++;

    println("com.caucho.util.CharBuffer " + cbVar +
            " = com.caucho.util.CharBuffer.allocate();");

    for (; i < length; i++) {
      char ch = string.charAt(i);

      if (ch == '\n') {
        cb.append("\\n");
      }
      else if (ch == '"') {
        cb.append("\\\"");
      }
      else if (ch == '{' && i + 1 < length) {
        // {{ is treated as a single {
        if (string.charAt(i + 1) == '{') {
          cb.append('{');
          i++;
        }
        // the value is computed from an XPath expr
        else {
          // print the gathered text if any
          if (cb.length() > 0)
            println(cbVar + ".append(\"" + cb.toString() + "\");");

          // scan the contents of '{' ... '}'
          cb.clear();
          for (i++; i < length && string.charAt(i) != '}'; i++)
            cb.append(string.charAt(i));

          // and add the results
          addStringExpr(cbVar, cb.toString(), elt, false);
         
          cb.clear();
          first = false;
        }
      }
      // }} is treated as a single }
      else if (ch == '}' && i + 1 < length) {
        if (string.charAt(i + 1) == '}') {
          cb.append('}');
          i++;
        }
        else
          cb.append('}');
      }
      // <#= interpolates
      else if (i + 2 < length && ch == '<' &&
               string.charAt(i + 1) == '#' &&
               string.charAt(i + 2) == '=') {
        // print the gathered text if any
        if (cb.length() > 0)
          println(cbVar + ".append(\"" + cb.toString() + "\");");

        // scan the contents of '<#=' ... '#>'
        cb.clear();
        for (i += 3;
             i + 1 < length && string.charAt(i) != '#' &&
               string.charAt(i + 1) != '>';
             i++)
          cb.append(string.charAt(i));

        i++;

        // and add the results
        println(cbVar + ".append(" + cb + ");");
        cb.clear();
        first = false;
      }
      else
        cb.append((char) ch);
    }

    // add any trailing text
    if (cb.length() > 0)
      println(cbVar + ".append(\"" + cb + "\");");

    println("String " + strVar + " = " + cbVar + ".close();");

    return strVar;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.