Exemplo 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;
    }
  }
Exemplo 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;
  }
Exemplo 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;
    }
  }
Exemplo n.º 4
0
  public boolean send(@NotNull Value value, @Optional JMSQueue replyTo) throws JMSException {
    Message message = null;

    if (value.isArray()) {
      message = _session.createMapMessage();

      ArrayValue array = (ArrayValue) value;

      Set<Map.Entry<Value, Value>> entrySet = array.entrySet();

      for (Map.Entry<Value, Value> entry : entrySet) {
        if (entry.getValue() instanceof BinaryValue) {
          byte[] bytes = ((BinaryValue) entry.getValue()).toBytes();

          ((MapMessage) message).setBytes(entry.getKey().toString(), bytes);
        } else {
          // every primitive except for bytes can be translated from a string
          ((MapMessage) message).setString(entry.getKey().toString(), entry.getValue().toString());
        }
      }
    } else if (value instanceof BinaryValue) {
      message = _session.createBytesMessage();

      byte[] bytes = ((BinaryValue) value).toBytes();

      ((BytesMessage) message).writeBytes(bytes);
    } else if (value.isLongConvertible()) {
      message = _session.createStreamMessage();

      ((StreamMessage) message).writeLong(value.toLong());
    } else if (value.isDoubleConvertible()) {
      message = _session.createStreamMessage();

      ((StreamMessage) message).writeDouble(value.toDouble());
    } else if (value.toJavaObject() instanceof String) {
      message = _session.createTextMessage();

      ((TextMessage) message).setText(value.toString());
    } else if (value.toJavaObject() instanceof Serializable) {
      message = _session.createObjectMessage();

      ((ObjectMessage) message).setObject((Serializable) value.toJavaObject());
    } else {
      return false;
    }

    if (replyTo != null) message.setJMSReplyTo(replyTo._destination);

    _producer.send(message);

    return true;
  }
Exemplo 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;
    }
  }
Exemplo 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;
  }
Exemplo n.º 7
0
  /** Sets an ini file. */
  public void setIniFile(Path path) {
    // XXX: Not sure why this dependency would be useful
    // Environment.addDependency(new Depend(path));

    if (path.canRead()) {
      Env env = new Env(this);

      Value result = FileModule.parse_ini_file(env, path, false);

      if (result instanceof ArrayValue) {
        ArrayValue array = (ArrayValue) result;

        for (Map.Entry<Value, Value> entry : array.entrySet()) {
          setIni(entry.getKey().toString(), entry.getValue().toString());
        }
      }

      _iniFile = path;
    }
  }
  public static String gae_users_create_login_url(
      Env env,
      String destinationUrl,
      @Optional String authDomain,
      @Optional String federatedIdentity,
      @Optional Value attributesRequest) {
    Set<String> attributeSet = null;

    if (!attributesRequest.isDefault()) {
      attributeSet = new HashSet<String>();

      ArrayValue array = attributesRequest.toArrayValue(env);

      for (Map.Entry<Value, Value> entrySet : array.entrySet()) {
        attributeSet.add(entrySet.getValue().toString());
      }
    }

    return GaeUserService.createLoginURL(
        destinationUrl, authDomain, federatedIdentity, attributeSet);
  }
Exemplo n.º 9
0
  private void getNamespaces(Env env, ArrayValue array) {
    if (_namespaceMap != null) {
      for (Map.Entry<String, String> entry : _namespaceMap.entrySet()) {
        StringValue name = env.createString(entry.getKey());
        StringValue uri = env.createString(entry.getValue());

        SimpleXMLAttribute attr = new SimpleXMLAttribute(env, _cls, this, entry.getKey());
        attr.setText(uri);

        array.append(name, env.wrapJava(attr));
      }
    }
  }
  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;
  }
  public static Value filter_input(
      Env env, int type, StringValue name, @Optional Value filterIdV, @Optional Value flagV) {
    ArrayValue array;

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

    Filter filter = getFilter(env, filterIdV);

    Value value = array.get(name);

    if (value == UnsetValue.UNSET) {
      int flags = AbstractFilter.getFlags(env, flagV);

      if ((flags & FILTER_NULL_ON_FAILURE) > 0) {
        return BooleanValue.FALSE;
      } else {
        return NullValue.NULL;
      }
    }

    return filter.filter(env, value, flagV);
  }
Exemplo n.º 12
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();
  }