コード例 #1
0
ファイル: SimpleXMLElement.java プロジェクト: dlitz/resin
  /** Implementation for setting the fields of this class. i.e. <code>$a->foo = "hello"</code> */
  public void __setField(String name, Value value) {
    SimpleXMLElement child = getElement(name);

    if (child == null) {
      child = new SimpleXMLElement(_env, _cls, this, name);
      child.setText(value.toStringValue());
      addChild(child);
    } else {
      child._children = null;

      child.setText(value.toStringValue());
    }
  }
コード例 #2
0
  /**
   * Converts node tree to a valid xml string.
   *
   * @return xml string
   */
  public final Value asXML(Env env, @Optional Value filename) {
    Value value = toXML(env);

    if (!value.isString()) {
      return value;
    }

    StringValue str = value.toStringValue(env);

    if (filename.isDefault()) {
      return str;
    } else {
      Path path = env.lookupPwd(filename);

      OutputStream os = null;

      try {
        os = path.openWrite();

        str.writeTo(os);

        return BooleanValue.TRUE;
      } catch (IOException e) {
        env.warning(e);

        return BooleanValue.FALSE;
      } finally {
        if (os != null) {
          IoUtil.close(os);
        }
      }
    }
  }
コード例 #3
0
  public BinaryStream fopen(Env env, StringValue path, StringValue mode, LongValue options) {
    boolean useIncludePath = (options.toLong() & StreamModule.STREAM_USE_PATH) != 0;

    Value pathComponent = UrlModule.parse_url(env, path, UrlModule.PHP_URL_PATH);

    if (!pathComponent.isset()) {
      log.info(L.l("no path component found in '{0}'", path.toString()));
      return null;
    }

    return ZlibModule.gzopen(
        env, pathComponent.toStringValue(env), mode.toString(), useIncludePath);
  }
コード例 #4
0
ファイル: SimpleXMLElement.java プロジェクト: dlitz/resin
  private static Node parse(
      Env env, Value data, int options, boolean dataIsUrl, String namespace, boolean isPrefix)
      throws IOException, ParserConfigurationException, SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    Document document = null;

    if (dataIsUrl) {
      Path path = env.lookup(data.toStringValue());

      // PHP throws an Exception instead
      if (path == null) {
        log.log(Level.FINE, L.l("Cannot read file/URL '{0}'", data));
        env.warning(L.l("Cannot read file/URL '{0}'", data));

        return null;
      }

      ReadStream is = path.openRead();

      try {
        document = builder.parse(is);
      } finally {
        is.close();
      }
    } else {
      StringReader reader = new java.io.StringReader(data.toString());

      document = builder.parse(new InputSource(reader));
    }

    NodeList childList = document.getChildNodes();

    // php/1x70
    for (int i = 0; i < childList.getLength(); i++) {
      if (childList.item(i).getNodeType() == Node.ELEMENT_NODE) return childList.item(i);
    }

    return childList.item(0);
  }