Tabnine Logo
StructuredNode
Code IndexAdd Tabnine to your IDE (free)

How to use
StructuredNode
in
sirius.kernel.xml

Best Java code snippets using sirius.kernel.xml.StructuredNode (Showing top 17 results out of 315)

origin: stackoverflow.com

XMLReader r = new XMLReader();
 r.addHandler("node", new NodeHandler() {
  @Override
  public void process(StructuredNode node) {
   System.out.println(node.queryString("name"));
   System.out.println(node.queryValue("price").asDouble(0d));
  }
 });
 r.parse(new FileInputStream("src/examples/test.xml"));
origin: com.scireum/sirius-kernel

/**
 * Returns a given node at the relative path.
 *
 * @param xpath the xpath used to retrieve the resulting node
 * @return the node returned by the given xpath expression
 * @throws IllegalArgumentException if an invalid xpath was given
 */
@Nullable
public StructuredNode queryNode(String xpath) {
  try {
    Node result = (Node) compile(xpath).evaluate(node, XPathConstants.NODE);
    if (result == null) {
      return null;
    }
    return new StructuredNode(result);
  } catch (XPathExpressionException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: com.scireum/sirius-kernel

@Override
public StructuredNode getNode(String xpath) throws XPathExpressionException {
  return node.queryNode(xpath);
}
origin: com.scireum/sirius-kernel

/**
 * Queries a {@link sirius.kernel.commons.Value} by evaluating the given xpath.
 *
 * @param path the xpath used to retrieve property
 * @return a Value wrapping the value returned by the given xpath expression
 * @throws java.lang.IllegalArgumentException if an invalid xpath was given
 */
@Nonnull
public Value queryValue(String path) {
  return Value.of(queryString(path));
}
origin: com.scireum/sirius-kernel

/**
 * Iterates through the sub-tree and invokes the appropriate handler for each child node.
 *
 * @param nodeHandler     the handler invoked for each element node
 * @param textNodeHandler the handler invoked for each text node
 */
public void visit(@Nullable Consumer<StructuredNode> nodeHandler, @Nullable Consumer<Node> textNodeHandler) {
  if (node.getNodeType() == Node.TEXT_NODE) {
    if (textNodeHandler != null) {
      textNodeHandler.accept(node);
    }
  } else if (node.getNodeType() == Node.ELEMENT_NODE) {
    if (nodeHandler != null) {
      nodeHandler.accept(this);
    }
    getChildren().forEach(c -> c.visit(nodeHandler, textNodeHandler));
  }
}
origin: scireum/s3ninja

  int number = part.queryValue("PartNumber").asInt(0);
  parts.put(number, new File(getUploadDir(uploadId), String.valueOf(number)));
});
origin: com.scireum/sirius-kernel

/**
 * Creates a new XMLStructuredInput for the given stream.
 *
 * @param in    the InputStream containing the xml data.
 * @param close determines whether the stream should be closed after parsing or not
 * @throws IOException if an io error occurs while parsing the input xml
 */
public XMLStructuredInput(InputStream in, boolean close) throws IOException {
  try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(in);
    node = StructuredNode.of(doc.getDocumentElement());
    if (close) {
      in.close();
    }
  } catch (ParserConfigurationException | SAXException e) {
    throw new IOException(e);
  }
}
origin: com.scireum/sirius-kernel

/**
 * Wraps the given W3C node into a structured node.
 *
 * @param node the node to wrap
 * @return a wrapped instance of the given node
 */
@Nonnull
public static StructuredNode of(@Nonnull Node node) {
  return new StructuredNode(node);
}
origin: com.scireum/sirius-kernel

@Override
public String toString() {
  return node == null ? "" : node.toString();
}
origin: com.scireum/sirius-kernel

/**
 * Returns the value of the attribute with the given name.
 *
 * @return a {@link Value} filled with the attribute value if an attribute exists for the given name, an empty {@link Value} otherwise.
 */
@Nonnull
public Value getAttribute(String name) {
  NamedNodeMap attributes = getNode().getAttributes();
  if (attributes != null) {
    Node attribute = attributes.getNamedItem(name);
    if (attribute != null) {
      return Value.of(attribute.getNodeValue());
    }
  }
  return Value.EMPTY;
}
origin: com.scireum/sirius-kernel

/**
 * Queries a string via the given XPath. All contained XML is converted to a
 * string.
 *
 * @param path the xpath used to retrieve the xml sub tree
 * @return a string representing the xml sub-tree returned by the given xpath expression
 * @throws IllegalArgumentException if an invalid xpath was given
 */
@Nullable
public String queryXMLString(String path) {
  try {
    XPath xpath = XPATH.newXPath();
    Object result = xpath.evaluate(path, node, XPathConstants.NODE);
    if (result == null) {
      return null;
    }
    if (result instanceof Node) {
      return serializeNodeAsXML((Node) result);
    }
    return result.toString().trim();
  } catch (XPathExpressionException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: com.scireum/sirius-kernel

/**
 * Returns the property at the given relative path as string.
 *
 * @param path the xpath used to retrieve property
 * @return a string representation of the value returned by the given xpath expression
 * @throws IllegalArgumentException if an invalid xpath was given
 */
@Nullable
public String queryString(String path) {
  try {
    Object result = compile(path).evaluate(node, XPathConstants.NODE);
    if (result == null) {
      return null;
    }
    if (result instanceof Node) {
      String s = ((Node) result).getTextContent();
      if (s != null) {
        return s.trim();
      }
      return s;
    }
    return result.toString().trim();
  } catch (XPathExpressionException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: com.scireum/sirius-kernel

/**
 * Checks whether a node is not reachable or has empty content via the given
 * XPath.
 *
 * @param path the xpath to be checked
 * @return <tt>true</tt> if no node or a empty property was found, <tt>false</tt> otherwise
 * @throws IllegalArgumentException if an invalid xpath was given
 */
public boolean isEmpty(String path) {
  return Strings.isEmpty(queryString(path));
}
origin: com.scireum/sirius-kernel

private boolean nodeUp() {
  if (isComplete()) {
    nodeHandler.process(StructuredNode.of(root));
    return true;
  }
  currentNode = currentNode.getParentNode();
  return false;
}
origin: com.scireum/sirius-kernel

/**
 * Returns a list of all children of this DOM node.
 *
 * @return a list containing all children of this node. If no children exist, an empty list will be returned.
 */
@Nonnull
public List<StructuredNode> getChildren() {
  NodeList result = node.getChildNodes();
  List<StructuredNode> resultList = new ArrayList<>(result.getLength());
  for (int i = 0; i < result.getLength(); i++) {
    resultList.add(new StructuredNode(result.item(i)));
  }
  return resultList;
}
origin: com.scireum/sirius-kernel

/**
 * Checks whether a node or non-empty content is reachable via the given
 * XPath.
 *
 * @param path the xpath to be checked
 * @return <tt>true</tt> if a node or non empty property was found, <tt>false</tt> otherwise
 * @throws IllegalArgumentException if an invalid xpath was given
 */
public boolean isFilled(String path) {
  return Strings.isFilled(queryString(path));
}
origin: com.scireum/sirius-kernel

/**
 * Returns a list of nodes at the relative path.
 *
 * @param xpath the xpath used to retrieve the resulting nodes
 * @return the list of nodes returned by the given xpath expression
 * @throws IllegalArgumentException if an invalid xpath was given
 */
@Nonnull
public List<StructuredNode> queryNodeList(String xpath) {
  try {
    NodeList result = (NodeList) compile(xpath).evaluate(node, XPathConstants.NODESET);
    List<StructuredNode> resultList = new ArrayList<>(result.getLength());
    for (int i = 0; i < result.getLength(); i++) {
      resultList.add(new StructuredNode(result.item(i)));
    }
    return resultList;
  } catch (XPathExpressionException e) {
    throw new IllegalArgumentException(e);
  }
}
sirius.kernel.xmlStructuredNode

Javadoc

Represents a structured node, which is part of a StructuredInput.

This is basically a XML node which can be queried using xpath.

Most used methods

  • queryString
    Returns the property at the given relative path as string.
  • queryValue
    Queries a sirius.kernel.commons.Value by evaluating the given xpath.
  • <init>
    Wraps the given node
  • compile
  • getChildren
    Returns a list of all children of this DOM node.
  • getNode
    Returns the underlying W3C Node.
  • of
    Wraps the given W3C node into a structured node.
  • queryNode
    Returns a given node at the relative path.
  • serializeNodeAsXML
  • toString
  • visit
    Iterates through the sub-tree and invokes the appropriate handler for each child node.
  • visit

Popular in Java

  • Reading from database using SQL prepared statement
  • findViewById (Activity)
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now