public QName getQName() { return internal.getQName(); }
public String getAttributeValue(String name) { return internal.getAttributeValue(name); }
/** * Set the value of dir attribute */ public static <T extends Element> void setDirection(Direction direction, T element) { if (direction != Direction.UNSPECIFIED) element.setAttributeValue(DIR, direction.toString().toLowerCase()); else if (direction == Direction.UNSPECIFIED) element.setAttributeValue(DIR, ""); else if (direction == null) element.removeAttribute(DIR); }
private static <T extends Element> boolean hasDirection(T element) { String dir = element.getAttributeValue("dir"); if (dir != null && dir.length() > 0) return true; else if (dir == null) { // if the direction is unspecified on this element, // let's see if we've inherited it Base parent = element.getParentElement(); if (parent != null && parent instanceof Element) return hasDirection((Element)parent); } return false; } }
private static void writeElement(Element child, QName parentqname, JSONStream jstream) throws IOException { QName childqname = child.getQName(); String prefix = childqname.getPrefix(); jstream.startObject(); jstream.writeField("name", getName(childqname)); jstream.writeField("attributes"); List<QName> attributes = child.getAttributes(); jstream.startObject(); if (!isSameNamespace(childqname, parentqname)) { jstream.writeField("xml:base", child.getResolvedBaseUri()); writeLanguageFields(child, jstream); for (QName attr : attributes) { jstream.writeField(name); if ("".equals(attr.getPrefix()) || "xml".equals(attr.getPrefix())) { String val = child.getAttributeValue(attr); if (val != null && ("href".equalsIgnoreCase(name) || "src".equalsIgnoreCase(name) || "action" .equalsIgnoreCase(name))) { IRI base = child.getResolvedBaseUri(); if (base != null) val = base.resolve(val).toASCIIString(); jstream.endObject(); jstream.writeField("value"); jstream.writeQuoted(child.getAttributeValue(attr)); jstream.endObject();
public <T extends Element>T setText(String text) { internal.setText(text); return (T)this; }
@Override protected void runTest() throws Throwable { Element element = abdera.getFactory().newElement(new QName("test")); element.setAttributeValue(qname, "value"); assertThat(element.getAttributeValue(qname)).isEqualTo("value"); List<QName> attrs = element.getAttributes(); assertThat(attrs).hasSize(1); QName actualQName = attrs.get(0); assertThat(actualQName).isEqualTo(qname); assertThat(actualQName.getPrefix()).isEqualTo(qname.getPrefix()); } }
protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { StreamWriter sw = context.getStreamWriter(); if (!(source instanceof Element)) return; Element element = (Element)source; sw.startElement(element.getQName()); for (QName attr : element.getAttributes()) sw.writeAttribute(attr, element.getAttributeValue(attr)); XPath xpath = context.getAbdera().getXPath(); List<?> children = xpath.selectNodes("node()", element); for (Object child : children) { if (child instanceof Element) { process(child, new ObjectContext(child), context, conventions); } else if (child instanceof Comment) { Comment comment = (Comment)child; sw.writeComment(comment.getText()); } else if (child instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction)child; sw.writePI(pi.getText(), pi.getTarget()); } else if (child instanceof TextValue) { TextValue tv = (TextValue)child; sw.writeElementText(tv.getText()); } } sw.endElement(); }
@Override protected void runTest() throws Throwable { Collection collection = abdera.getFactory().newCollection(); collection.setAccept("image/png", "image/jpeg"); List<Element> children = collection.getElements(); assertThat(children).hasSize(2); assertThat(children.get(0).getQName()).isEqualTo(Constants.ACCEPT); assertThat(children.get(0).getText()).isEqualTo("image/png"); assertThat(children.get(1).getQName()).isEqualTo(Constants.ACCEPT); assertThat(children.get(1).getText()).isEqualTo("image/jpeg"); } }
public void writeTo(org.apache.abdera.writer.Writer writer, OutputStream out, WriterOptions options) throws IOException { internal.writeTo(writer, out, options); }
public <T extends Element> Document<T> getDocument() { Document<T> document = null; if (parent != null) { if (parent instanceof Element) { document = ((Element)parent).getDocument(); } else if (parent instanceof Document) { document = (Document<T>)parent; } } return document; }
public <T extends Element> T setAttributeValue(QName qname, String value) { internal.setAttributeValue(qname, value); return (T)this; }
public Object clone() { try { ElementWrapper wrapper = (ElementWrapper) super.clone(); wrapper.internal = (Element) internal.clone(); return wrapper; } catch (CloneNotSupportedException e) { // won't happen return null; } }
/** * Return the textual content of a child element using the in-scope directionality * * @param element The parent element * @param child The XML QName of the child element * @return The directionally-wrapped text of the child element */ public static <T extends Element> String getBidiChildText(T element, QName child) { Element el = element.getFirstChild(child); return (el != null) ? getBidiText(getDirection(el), el.getText()) : null; }
@SuppressWarnings("unchecked") private <T extends Element> T _sign(T element, SignatureOptions options) throws XMLSecurityException { element.setBaseUri(element.getResolvedBaseUri()); org.w3c.dom.Element dom = fomToDom((Element)element.clone(), options); org.w3c.dom.Document domdoc = dom.getOwnerDocument(); PrivateKey signingKey = options.getSigningKey(); X509Certificate cert = options.getCertificate(); PublicKey pkey = options.getPublicKey(); IRI baseUri = element.getResolvedBaseUri(); XMLSignature sig = new XMLSignature(domdoc, (baseUri != null) ? baseUri.toString() : "", options.getSigningAlgorithm());
@Override protected void runTest() throws Throwable { Element element = abdera.getFactory().newElement(new QName("test")); QName qname = new QName("urn:test", "attr", "p"); element.setAttributeValue(qname, "value"); assertThat(element.getAttributes()).containsExactly(qname); element.setAttributeValue(qname, null); assertThat(element.getAttributes()).isEmpty(); } }
public <T extends Element> List<T> getElements() { return internal.getElements(); }
public List<QName> getAttributes() { return internal.getAttributes(); }