Package com.caucho.util

Examples of com.caucho.util.CharBuffer


  {
    int i = 0;
    int len = elements.length();
    for (; i < len && XmlChar.isWhitespace(elements.charAt(i)); i++) {
    }
    CharBuffer cb = new CharBuffer();
    while (i < len) {
      cb.clear();

      for (; i < len && ! XmlChar.isWhitespace(elements.charAt(i)); i++) {
        cb.append(elements.charAt(i));
      }

      _strip.put(cb.toString(), "true");

      for (; i < len && XmlChar.isWhitespace(elements.charAt(i)); i++) {
      }
    }
  }
View Full Code Here


   * Returns the server name.
   */
  @Override
  public String getServerName()
  {
    CharBuffer host = getHost();
    if (host == null) {
      InetAddress addr = getConnection().getRemoteAddress();
      return addr.getHostName();
    }

    int p = host.indexOf(':');
    if (p >= 0)
      return host.substring(0, p);
    else
      return host.toString();
  }
View Full Code Here

  {
    int i = 0;
    int len = elements.length();
    for (; i < len && XmlChar.isWhitespace(elements.charAt(i)); i++) {
    }
    CharBuffer cb = new CharBuffer();
    while (i < len) {
      cb.clear();

      for (; i < len && ! XmlChar.isWhitespace(elements.charAt(i)); i++) {
        cb.append(elements.charAt(i));
      }

      _preserve.put(cb.toString(), "true");

      for (; i < len && XmlChar.isWhitespace(elements.charAt(i)); i++) {
      }
    }
  }
View Full Code Here

   * @return a string containing the XML.
   */
  public String printString(Node node)
    throws IOException
  {
    CharBuffer cb = CharBuffer.allocate();

    _os = Vfs.openWrite(cb);
    init(_os);
    try {
      ((QAbstractNode) node).print(this);
    } finally {
      flush();
      _os.close();
    }

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

  private Locator _locator;

  public SAXBuilder()
  {
    _text = new CharBuffer();
    _attributes = new QAttributes();
  }
View Full Code Here

  void init()
    throws QueryParseException
  {
    super.init();

    CharBuffer cb = new CharBuffer();

    cb.append("update ");

    FromItem item = _fromList.get(0);

    // Postgres 8.2.x accepts UPDATE statements with
    // table alias name, but Postgres 8.0.x does not.
    //
    // Also, adds portability for MySql 3.23 vs MySql 4.x/5.x
    // In MySql 3.23, UPDATE with joins are not supported.
    //
    // jpa/1201 vs jpa/1202 vs jpa/1203
    if (getMetaData().supportsUpdateTableAlias()
        && (_fromList.size() > 1)) {
      if (getMetaData().supportsUpdateTableList()) {
        // MySql: jpa/1202
        generateFromList(cb, false);
      }
      else { // Oracle: jpa/1203
        cb.append(item.getTable().getName());
        cb.append(" ");
        cb.append(item.getName());
      }
    }
    else {
      // Postgres: jpa/1201
      cb.append(item.getTable().getName());
    }

    cb.append(" set ");

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

      // cb.append(_fieldList.get(i).generateSelect(null));

      AmberExpr expr = _fieldList.get(i);

      // jpa/1202, jpa/0k15
      if (getMetaData().supportsUpdateTableAlias()
          && (_fromList.size() > 1))
        expr.generateWhere(cb);
      else
        expr.generateUpdateWhere(cb);

      cb.append("=");

      // jpa/1231
      if (getMetaData().supportsUpdateTableAlias() || hasSubQuery())
        _valueList.get(i).generateWhere(cb);
      else
        _valueList.get(i).generateUpdateWhere(cb);
    }

    String updateJoin = null;

    if (_where != null) {
      // jpa/1200 vs jpa/1201 and jpa/1231
      if (_fromList.size() == 1 && ! hasSubQuery()) {
        cb.append(" where ");

        _where.generateUpdateWhere(cb);
      }
      else {
        boolean isFirst = true;

        // jpa/1201: postgres 8.0.x/8.2.x compatibility
        if (getMetaData() instanceof PostgresMetaData) {
          item = _fromList.get(0);

          EntityType type = item.getEntityType();

          String targetId = type.getId().generateSelect(item.getName());

          cb.append(" FROM ");

          String tableName = item.getTable().getName();

          cb.append(tableName);
          cb.append(' ');
          cb.append(item.getName());

          isFirst = false;

          cb.append(" where ");

          cb.append(targetId);
          cb.append(" = ");
          cb.append(type.getId().generateSelect(item.getTable().getName()));
        }

        // jpa/1231, jpa/1202 vs jpa/1201 and jpa/1203
        if (_fromList.size() > 1
            && ! getMetaData().supportsUpdateTableList()) {
          // Postgres: jpa/1201 and Oracle: jpa/1203
          item = _fromList.get(1);

          EntityType type = item.getEntityType();

          String relatedId = type.getId().generateSelect(item.getName());

          if (isFirst) {
            isFirst = false;
            cb.append(" where ");
          }
          else
            cb.append(" and ");

          cb.append("exists (select ");

          cb.append(relatedId);

          cb.append(" from ");

          generateFromList(cb, true);

          // jpa/1231
          isFirst = true;
        }

        for (int i = 0; i < _fromList.size(); i++) {
          item = _fromList.get(i);

          AmberExpr expr = item.getJoinExpr();

          if (expr != null && ! item.isOuterJoin()) {
            // jpa/1231
            if (isFirst) {
              isFirst = false;
              cb.append(" where ");
            }
            else
              cb.append(" and ");

            expr.generateJoin(cb);
          }

          EntityType entityType = item.getEntityType();

          // jpa/0l44
          if (entityType != null) {
            AmberColumn discriminator = entityType.getDiscriminator();

            // jpa/0l43
            if (entityType instanceof SubEntityType &&
                discriminator != null) {
              // jpa/0l12, jpa/0l4b

              if (item.getTable() == discriminator.getTable()) {
                if (isFirst) {
                  isFirst = false;
                  cb.append(" where ");
                }
                else
                  cb.append(" and ");

                cb.append("(" + item.getName() + "." + discriminator.getName() + " = ");
                cb.append("'" + entityType.getDiscriminatorValue() + "')");
              }
            }
          }
        }

        if (isFirst) {
          isFirst = false;
          cb.append(" where ");
        }
        else
          cb.append(" and ");

        _where.generateWhere(cb);
      }
    } // end if (_where != null)

    // jpa/1201 vs jpa/1202
    if (_fromList.size() > 1
        && ! getMetaData().supportsUpdateTableList()) {
      cb.append(")");
    }

    _sql = cb.close();
  }
View Full Code Here

   
    if (context != null && (url == null || ! url.startsWith("/")))
      throw new JspException(L.l("URL '{0}' must start with '/'",
                                 url));
   
    CharBuffer value = new CharBuffer();

    if (url == null)
      url = "";

    int slash = url.indexOf('/');
    int colon = url.indexOf(':');

    if (colon > 0 && colon < slash) {
      value.append(url);
    }
    else if (slash == 0) {
      HttpServletRequest request;
      request = (HttpServletRequest) pageContext.getRequest();

      if (context != null) {
        if (context.length() > 1)
          value.append(context);

        value.append(url);
      }
      else {
        value.append(request.getContextPath());
        value.append(url);
      }
    }
    else {
      if (context != null) {
        value.append(context);
        value.append(url);
      }
      else
        value.append(url);
    }

    return value;
  }
View Full Code Here

    generateWhere(cb);
  }

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

    cb.append('(');
    cb.append(_expr);

    if (_isNot)
      cb.append(" NOT");

    cb.append(" LIKE ");

    cb.append(_value);

    cb.append(')');

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

    }
  }

  private String escapeXml(String data)
  {
    CharBuffer cb = CharBuffer.allocate();
    for (int i = 0; i < data.length(); i++) {
      char ch = data.charAt(i);

      switch (ch) {
      case '<':
        cb.append("&lt;");
        break;
      case '>':
        cb.append("&gt;");
        break;
      case '&':
        cb.append("&amp;");
        break;
      default:
        cb.append(ch);
        break;
      }
    }

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

      if (cache != null)
        _localCache.put(uri, cache);
    }
   
    if (cache == null) {
      CharBuffer cb = new CharBuffer();
      String servletPath;

      if (cauchoReq != null)
        servletPath = cauchoReq.getPageServletPath();
      else if (isInclude)
        servletPath = (String) req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
      else
        servletPath = req.getServletPath();

      if (servletPath != null)
        cb.append(servletPath);

      String pathInfo;
      if (cauchoReq != null)
        pathInfo = cauchoReq.getPagePathInfo();
      else if (isInclude)
        pathInfo
          = (String) req.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
      else
        pathInfo = req.getPathInfo();

      if (pathInfo != null)
        cb.append(pathInfo);

      String relPath = cb.toString();

      if (_isCaseInsensitive)
        relPath = relPath.toLowerCase(Locale.ENGLISH);

      filename = getServletContext().getRealPath(relPath);
View Full Code Here

TOP

Related Classes of com.caucho.util.CharBuffer

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.