/** Implementation for getting the indices of this class. i.e. <code>$a->foo[0]</code> */ public Value __get(Env env, Value indexV) { if (indexV.isString()) { String name = indexV.toString(); SimpleXMLElement attr = getAttribute(name); if (attr == null) return NullValue.NULL; else return wrapJava(env, _cls, attr); } else if (indexV.isLongConvertible()) { int i = indexV.toInt(); if (i == 0) return wrapJava(env, _cls, getOwner()); else if (_parent == null) return NullValue.NULL; ArrayList<SimpleXMLElement> children = _parent._children; if (children != null) { int size = children.size(); for (int j = 0; j < size; j++) { SimpleXMLElement child = children.get(j); if (child.getName().equals(getName()) && i-- == 0) return wrapJava(env, _cls, child); } } return NullValue.NULL; } else return NullValue.NULL; }
/** * Returns all the children of this node, including the attributes of this node. * * @param env * @param namespaceV * @param isPrefix */ public Value children(Env env, @Optional Value namespaceV, @Optional boolean isPrefix) { String namespace = null; if (!namespaceV.isNull()) namespace = namespaceV.toString(); SimpleXMLElement result = new SimpleXMLChildren(env, _cls, this, getName()); if (_attributes != null) { for (SimpleXMLElement attr : _attributes) { if (attr.isSameNamespace(namespace)) result.addAttribute(attr); } } if (_children != null) { for (SimpleXMLElement child : _children) { if (isPrefix) { if (child.isSamePrefix(namespace)) { result.addChild(child); } } else { if (child.isSameNamespace(namespace)) { result.addChild(child); } } } } return wrapJava(env, _cls, result); }
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; }
/** * Changes the current domain. * * @param env * @param domain * @return name of current domain after change. */ public String textdomain(Env env, @Optional Value domain) { if (! domain.isNull()) { String name = domain.toString(); setCurrentDomain(env, name); return name; } return getCurrentDomain(env).getName(); }
/** * Returns the attributes of this node. * * @param env * @param namespaceV * @param isPrefix */ public Value attributes(Env env, @Optional Value namespaceV, @Optional boolean isPrefix) { String namespace = null; if (!namespaceV.isNull()) namespace = namespaceV.toString(); SimpleXMLElement attrList = new SimpleXMLAttributeList(env, _cls, this, "#attrlist", namespace, null); if (_attributes != null) { for (SimpleXMLElement attr : _attributes) { if (attr.isSameNamespace(namespace) && !attr.isNamespaceAttribute()) attrList.addAttribute(attr); } } return wrapJava(env, _cls, attrList); }
/** Implementation for getting the indices of this class. i.e. <code>$a->foo[0]</code> */ public Value __get(Env env, Value indexV) { if (indexV.isString()) { String name = indexV.toString(); SimpleXMLElement attr = getAttribute(name); if (attr != null) return wrapJava(env, _cls, attr); else return NullValue.NULL; } else if (indexV.isLongConvertible()) { int i = indexV.toInt(); if (i < _attributes.size()) return wrapJava(env, _cls, _attributes.get(i)); return NullValue.NULL; } else return NullValue.NULL; }
/** * Adds a child to this node. * * @param env * @param name of the child node * @param value of the text node of the child * @param namespace * @return */ public Value addChild(Env env, String name, String value, @Optional Value namespaceV) { String namespace; /* if (! namespaceV.isNull()) namespace = namespaceV.toString(); else namespace = _namespace; */ namespace = namespaceV.toString(); SimpleXMLElement child = new SimpleXMLElement(env, _cls, this, name, namespace); child.setText(env.createString(value)); addChild(child); return wrapJava(env, _cls, child); }
protected static Value create( Env env, QuercusClass cls, Value data, int options, boolean dataIsUrl, Value namespaceV, boolean isPrefix) { if (data.length() == 0) { env.warning(L.l("xml data must have length greater than 0")); return BooleanValue.FALSE; } try { String namespace = null; if (!namespaceV.isNull()) namespace = namespaceV.toString(); Node node = parse(env, data, options, dataIsUrl, namespace, isPrefix); if (node == null) { return BooleanValue.FALSE; } SimpleXMLElement elt = buildNode(env, cls, null, node, namespace, isPrefix); return wrapJava(env, cls, elt); } catch (IOException e) { env.warning(e); return BooleanValue.FALSE; } catch (ParserConfigurationException e) { env.warning(e); return BooleanValue.FALSE; } catch (SAXException e) { env.warning(e); return BooleanValue.FALSE; } }
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); }
public Object marshal(Env env, Value value, Class argClass) { String name = value.toString(); return Enum.valueOf(_enumClass, name); }