Esempio n. 1
0
  /**
   * Runs an XPath expression on this node.
   *
   * @param env
   * @param expression
   * @return array of results
   * @throws XPathExpressionException
   */
  public Value xpath(Env env, String expression) {
    try {
      XPath xpath = XPathFactory.newInstance().newXPath();

      InputSource is = new InputSource(asXML(env).toInputStream());
      NodeList nodes = (NodeList) xpath.evaluate(expression, is, XPathConstants.NODESET);

      int nodeLength = nodes.getLength();

      if (nodeLength == 0) return NullValue.NULL;

      // There are matching nodes
      ArrayValue result = new ArrayValueImpl();
      for (int i = 0; i < nodeLength; i++) {
        Node node = nodes.item(i);

        boolean isPrefix = node.getPrefix() != null;

        SimpleXMLElement xml =
            buildNode(env, _cls, null, nodes.item(i), node.getNamespaceURI(), isPrefix);

        result.put(wrapJava(env, _cls, xml));
      }

      return result;
    } catch (XPathExpressionException e) {
      env.warning(e);
      log.log(Level.FINE, e.getMessage());

      return NullValue.NULL;
    }
  }
Esempio n. 2
0
  /** Returns an array of the defined functions. */
  public ArrayValue getDefinedFunctions() {
    ArrayValue internal = new ArrayValueImpl();

    for (String name : _funMap.keySet()) {
      internal.put(name);
    }

    return internal;
  }
Esempio n. 3
0
  public Value receive(Env env, @Optional("1") long timeout) throws JMSException {
    Message message = _consumer.receive(timeout);

    if (message == null) return BooleanValue.FALSE;

    if (message instanceof ObjectMessage) {
      Object object = ((ObjectMessage) message).getObject();

      return env.wrapJava(object);
    } else if (message instanceof TextMessage) {
      return env.createString(((TextMessage) message).getText());
    } else if (message instanceof StreamMessage) {
      Object object = ((StreamMessage) message).readObject();

      return env.wrapJava(object);
    } else if (message instanceof BytesMessage) {
      BytesMessage bytesMessage = (BytesMessage) message;
      int length = (int) bytesMessage.getBodyLength();

      StringValue bb = env.createBinaryBuilder(length);

      TempBuffer tempBuffer = TempBuffer.allocate();
      int sublen;

      while (true) {
        sublen = bytesMessage.readBytes(tempBuffer.getBuffer());

        if (sublen > 0) bb.append(tempBuffer.getBuffer(), 0, sublen);
        else break;
      }

      TempBuffer.free(tempBuffer);

      return bb;
    } else if (message instanceof MapMessage) {
      MapMessage mapMessage = (MapMessage) message;

      Enumeration mapNames = mapMessage.getMapNames();

      ArrayValue array = new ArrayValueImpl();

      while (mapNames.hasMoreElements()) {
        String name = mapNames.nextElement().toString();

        Object object = mapMessage.getObject(name);

        array.put(env.createString(name), env.wrapJava(object));
      }

      return array;
    } else {
      return BooleanValue.FALSE;
    }
  }
Esempio n. 4
0
  @EntrySet
  public Set<Map.Entry<Value, Value>> entrySet() {
    LinkedHashMap<Value, Value> map = new LinkedHashMap<Value, Value>();

    if (_attributes != null) {
      ArrayValue array = new ArrayValueImpl();

      for (SimpleXMLElement attr : _attributes) {
        StringValue value = attr._text;

        array.put(_env.createString(attr._name), value);
      }

      map.put(_env.createString("@attributes"), array);
    }

    boolean hasElement = false;
    if (_children != null) {
      for (SimpleXMLElement child : _children) {
        if (!child.isElement()) continue;

        hasElement = true;

        StringValue name = _env.createString(child.getName());
        Value oldChild = map.get(name);
        Value childValue;

        if (child._text != null) childValue = child._text;
        else childValue = wrapJava(_env, _cls, child);

        if (oldChild == null) {
          map.put(name, childValue);
        } else if (oldChild.isArray()) {
          ArrayValue array = (ArrayValue) oldChild;

          array.append(childValue);
        } else {
          ArrayValue array = new ArrayValueImpl();
          array.append(oldChild);
          array.append(childValue);

          map.put(name, array);
        }
      }
    }

    if (!hasElement && _text != null) {
      map.put(LongValue.ZERO, _text);
    }

    return map.entrySet();
  }
Esempio n. 5
0
  /**
   * @param env the PHP executing environment
   * @return array of fieldDirect objects
   */
  public Value getFieldDirectArray(Env env) {
    ArrayValue array = new ArrayValueImpl();

    try {
      int numColumns = getMetaData().getColumnCount();

      for (int i = 0; i < numColumns; i++) {
        array.put(fetchFieldDirect(env, i));
      }

      return array;
    } catch (SQLException e) {
      log.log(Level.FINE, e.toString(), e);
      return BooleanValue.FALSE;
    }
  }
Esempio n. 6
0
  /** Returns true if an extension is loaded. */
  public Value getExtensionFuncs(String name) {
    ArrayValue value = null;

    for (ModuleInfo moduleInfo : _modules.values()) {
      Set<String> extensionSet = moduleInfo.getLoadedExtensions();

      if (extensionSet.contains(name)) {
        for (String functionName : moduleInfo.getFunctions().keySet()) {
          if (value == null) value = new ArrayValueImpl();

          value.put(functionName);
        }
      }
    }

    if (value != null) return value;
    else return BooleanValue.FALSE;
  }
  public Value filter_input_array(
      Env env, int type, @Optional Value definition, @Optional("true") boolean isAddEmpty) {
    ArrayValue inputArray;

    switch (type) {
      case INPUT_POST:
        inputArray = env.getInputPostArray();
        break;
      case INPUT_GET:
        inputArray = env.getInputGetArray();
        break;
      case INPUT_COOKIE:
        inputArray = env.getInputCookieArray();
        break;
      case INPUT_ENV:
        inputArray = env.getInputEnvArray();
        break;
      default:
        return env.warning(L.l("filter input type is unknown: {0}", type));
    }

    Filter filter = getFilter(env, definition);

    ArrayValue array = new ArrayValueImpl();

    for (Map.Entry<Value, Value> entry : inputArray.entrySet()) {
      Value key = entry.getKey();
      Value value = entry.getValue();

      Value newKey = filter.filter(env, key, definition);
      Value newValue = filter.filter(env, value, definition);

      array.put(newKey, newValue);
    }

    return array;
  }