public static Filter getFilter(Env env, Value filterIdV) { int filterId; int defaultFilterId = FILTER_UNSAFE_RAW; if (filterIdV.isDefault()) { // XXX: lookup in ini filterId = defaultFilterId; } else if (filterIdV.isArray()) { Value value = filterIdV.get(env.createString("filter")); if (value.isNull()) { filterId = defaultFilterId; } else { filterId = value.toInt(); } } else { filterId = filterIdV.toInt(); } Filter filter = _filterMap.get(filterId); if (filter == null) { throw new UnimplementedException( L.l("filter not implemented: {0} ({1})", filterIdV, filterId)); } return filter; }
/** * 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); }
private boolean setLobParameter(Env env, int index, Value value) { if (_preparedStmt == null) { return false; } try { if (value == null || value.isNull()) { _preparedStmt.setObject(index, null); } else if (value.isString()) { _preparedStmt.setBinaryStream(index, value.toInputStream(), value.length()); } else { InputStream inputStream = value.toInputStream(); if (inputStream == null) { env.warning( L.l( "type {0} ({1}) for parameter index {2} cannot be used for lob", value.getType(), value.getClass(), index)); return false; } int length = -1; if (value instanceof FileReadValue) { length = (int) ((FileReadValue) value).getLength(); if (length <= 0) length = -1; } if (length < 0) { TempBuffer tempBuffer = TempBuffer.allocate(); try { byte[] bytes = new byte[1024]; int len; while ((len = inputStream.read(bytes, 0, 1024)) != -1) tempBuffer.write(bytes, 0, len); } catch (IOException e) { env.warning(e); return false; } TempReadStream tempReadStream = new TempReadStream(tempBuffer); tempReadStream.setFreeWhenDone(true); _preparedStmt.setBinaryStream( index, new ReadStream(tempReadStream), tempBuffer.getLength()); } else { _preparedStmt.setBinaryStream(index, inputStream, length); } } } catch (SQLException e) { setError(env, e); return false; } 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); }
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; } }