/** * Returns the value of the specified attribute. * @param elm element node * @param name attribute to be found * @param force if set to {@code true}, an exception is thrown if the * attribute is not found * @return attribute value * @throws QueryException query exception */ final String attribute(final ANode elm, final byte[] name, final boolean force) throws QueryException { final byte[] val = elm.attribute(name); if(val == null && force) throw ZIP_INVALID_X_X.get(info, elm.qname(), name); return val == null ? null : string(val); }
/** * Parses the attributes of an element. * @param element element * @param atts map for parsed attributes */ private static void parseAtts(final ANode element, final Map<String, String> atts) { for(final ANode attr : element.attributes()) { atts.put(string(attr.name()), string(attr.string())); } }
@Override public ANode next() { if(iter == null) { final ANodeList list = new ANodeList(); ANode node = FNode.this, par = node.parent(); while(par != null) { final BasicNodeIter ir = par.children(); if(node.type != NodeType.ATT) { for(final ANode nd : ir) { if(nd.is(node)) break; } } for(final ANode nd : ir) { list.add(nd.finish()); addDesc(nd.children(), list); } node = par; par = par.parent(); } iter = list.iter(); } return iter.next(); } };
/** * Sets the info element. * @param elem info element */ public void info(final ANode elem) { info = elem.hasChildren() || elem.attributes().size() != 0 ? elem : null; }
final BasicNodeIter atts = response.attributes(); final ANode attr = atts.next(); if(attr != null) throw func.error(UNEXP_NODE_X, attr); for(final ANode n : response.children()) { for(final ANode a : n.attributes()) { final QNm qnm = a.qname(); if(qnm.eq(Q_STATUS)) sta = a.string(); else if(qnm.eq(Q_REASON) || qnm.eq(Q_MESSAGE)) msg = a.string(); else throw func.error(UNEXP_NODE_X, a); for(final ANode c : n.children()) { final byte[] nam = c.attribute(Q_NAME); final byte[] val = c.attribute(Q_VALUE); if(nam != null && val != null) { final String key = string(nam), value = string(val);
/** * Returns the value of the specified attribute or {@code null}. * @param name attribute to be found * @return attribute value or {@code null} */ public byte[] attribute(final QNm name) { final BasicNodeIter iter = attributes(); while(true) { final ANode node = iter.next(); if(node == null) return null; if(node.qname().eq(name)) return node.string(); } }
@Override public Bln item(final QueryContext qc, final InputInfo ii) throws QueryException { final byte[] lang = lc(toEmptyToken(exprs[0], qc)); final ANode node = toNode(ctxArg(1, qc), qc); for(ANode nd = node; nd != null; nd = nd.parent()) { final BasicNodeIter atts = nd.attributes(); for(ANode at; (at = atts.next()) != null;) { if(eq(at.qname().string(), LANG)) { final byte[] ln = lc(normalize(at.string())); return Bln.get(startsWith(ln, lang) && (lang.length == ln.length || ln[lang.length] == '-')); } } } return Bln.FALSE; } }
/** * Adds an entry to the pool and decreases its number of occurrence. * @param node node */ public void remove(final ANode node) { if(node.type != NodeType.ATT && node.type != NodeType.ELM) return; final int i = index(node.qname(), node.type == NodeType.ATT); cache[i].del = true; }
/** * Returns the specified attribute. * @param name attribute name * @return node or {@code null} */ private ANode attribute(final String name) { final byte[] nm = Token.token(name); for(final ANode n : nd.attributes()) { if(Token.eq(nm, n.name())) return n.finish(); } return null; } }
@Override protected final void node(final ANode item) throws IOException { final Type type = item.type; final XMLSerializer ser = xml(); if(type == NodeType.ATT) ser.attribute(item.name(), item.string(), true); else if(type == NodeType.NSP) ser.namespace(item.name(), item.string(), true); else ser.node(item); ser.out.flush(); ser.reset(); }
@Override BasicNodeIter iter(final ANode n) { return n.children(); } },
/** * Returns the string value. * @return string value */ public abstract byte[] string();
/** * Returns the value of the specified attribute or {@code null}. * @param name attribute to be found * @return attribute value */ public byte[] attribute(final byte[] name) { return attribute(new QNm(name)); }
/** * Returns all nodes with the given element name. * @param name element name * @return nodes */ final BXNList getElements(final String name) { final ANodeList nb = new ANodeList(); final byte[] nm = "*".equals(name) ? null : token(name); for(final ANode n : nd.descendant()) { if(n.type == NodeType.ELM && (nm == null || eq(nm, n.name()))) nb.add(n.finish()); } return new BXNList(nb); }
@Override public String getNodeName() { return Token.string(nd.name()); }
@Override BasicNodeIter iter(final ANode n) { return n.attributes(); } },