Package br.ufsc.labsec.utils
Class XMLParser
java.lang.Object
br.ufsc.labsec.utils.XMLParser
public class XMLParser extends Object
Classe auxiliar para tratar utilidades comuns
a documentos XML
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XMLParser.NodeListIterator<T extends Node>
-
Field Summary
-
Constructor Summary
Constructors Constructor Description XMLParser()
-
Method Summary
Modifier and Type Method Description static List<String>
collectAttributesToResolve(List<String> attrs, NodeList targetNode)
Coleta os atributos requisitados de uma nodelist alvostatic Document
createDocument(InputStream inputStream)
static List<Element>
getChildElements(Node rootElement, String namespace, String elementName)
static Element
getElementOrCreate(Element rootElement, String elementName, String namespace, Document baseDoc)
static List<Element>
getElements(Node rootElement, String namespace, String elementName)
static List<Element>
getElementsChildren(NodeList nodeList)
Responsável por tratar de todos os filhos e pegar apenas os nodos realmente (removendo elementos em branco, por exemplo)static Element
getFirstChildElement(Element element)
Responsável por pegar o primeiro filho que seja um elementostatic Element
getFirstChildElement(NodeList nodeList)
static Optional<org.apache.commons.lang3.tuple.Pair<String,String>>
getIdElement(Node node)
Responsável por pegar o "Id" de determinado elemento.static int
getIndexSibling(Node node)
Pega o índice de determinado nodostatic Element
getLastChildElement(Element element)
Responsável por pegar o último filho que seja um elementostatic Element
getLastChildElement(NodeList children)
static Document
getNewDocument()
Instancia um novoDocument
, que será usado para escrever a assinatura.static Node
getNodeFromXPath(Document document, String xpath)
static Node
getNodeFromXPath(Node node, String path)
static NodeList
getNodeListFromXPath(Node node, String path)
static NodeList
getNodesFromXPath(Node node, String path)
static Element
getNthChildElement(Element element, int nth)
Responsável por pegar o nth filho que seja um elementostatic Element
getNthChildElement(NodeList children, int nth)
Responsável por pegar o nth filho que seja um elementostatic Element
getSecondChildElement(Element element)
Responsável por pegar o segundo filho que seja um elementostatic String
getXPath(Element node)
static String
getXPath(Node node)
Determina o XPath completo a partir de um elementostatic boolean
isChildOf(Node currentElement, Node target)
static String
resolveNamespace(String path)
static Iterable<Node>
wrapNodeList(NodeList nodeList)
static <T extends Node>
Iterable<T>wrapNodeList(NodeList nodeList, Class<T> clazz)
-
Field Details
-
SCHEMA
Schema para verificação de assinaturas -
TL_SCHEMA
Schema para verificação de listas confiáveis -
QUALIFYING_PROPERTIES
- See Also:
- Constant Field Values
-
-
Constructor Details
-
XMLParser
public XMLParser()
-
-
Method Details
-
getElementsChildren
Responsável por tratar de todos os filhos e pegar apenas os nodos realmente (removendo elementos em branco, por exemplo)- Parameters:
nodeList
- Lista de elementos que devem ser parseados- Returns:
- Lista de elementos parseados
-
getFirstChildElement
-
getLastChildElement
-
wrapNodeList
-
wrapNodeList
-
getFirstChildElement
Responsável por pegar o primeiro filho que seja um elemento- Parameters:
element
- Elemento ao qual deseja pegar o primeiro filho elemento- Returns:
- Primeiro filho elemento
-
getSecondChildElement
Responsável por pegar o segundo filho que seja um elemento- Parameters:
element
- Elemento ao qual deseja pegar o primeiro filho elemento- Returns:
- Primeiro filho elemento
-
getNthChildElement
Responsável por pegar o nth filho que seja um elemento- Parameters:
element
- Elemento ao qual deseja pegar o primeiro filho elemento- Returns:
- Primeiro filho elemento
-
getNthChildElement
Responsável por pegar o nth filho que seja um elemento- Parameters:
children
- Elementos filho ao qual deseja pegar o nth- Returns:
- Primeiro filho elemento
-
getLastChildElement
Responsável por pegar o último filho que seja um elemento- Parameters:
element
- Elemento ao qual deseja pegar o último filho elemento- Returns:
- Último filho elemento
-
getIdElement
public static Optional<org.apache.commons.lang3.tuple.Pair<String,String>> getIdElement(Node node)Responsável por pegar o "Id" de determinado elemento. Esse método é necessário, pois ocorrem vários equívocos ao fazer tal atributo- Parameters:
node
- Elemento que deseja pegar o identificador ("Id")- Returns:
- Nome do atributo e valor do atributo de identificador
-
getIndexSibling
Pega o índice de determinado nodo- Parameters:
node
- Nodo que deseja pegar o índice- Returns:
- Índice do nodo dado
-
getXPath
Determina o XPath completo a partir de um elemento- Parameters:
node
- Elemento que deseja obter o XPath completo- Returns:
- XPath completo do elemento
-
getXPath
-
getNewDocument
Instancia um novoDocument
, que será usado para escrever a assinatura.- Returns:
- O objeto gerado
- Throws:
ParserConfigurationException
- Exceção em caso de erro na geração do documento
-
createDocument
public static Document createDocument(InputStream inputStream) throws ParserConfigurationException, IOException, SAXException -
getNodeFromXPath
public static Node getNodeFromXPath(Document document, @Language("XPath") String xpath) throws XPathExpressionException- Throws:
XPathExpressionException
-
getNodeFromXPath
public static Node getNodeFromXPath(Node node, @Language("XPath") String path) throws XPathExpressionException- Throws:
XPathExpressionException
-
getNodeListFromXPath
public static NodeList getNodeListFromXPath(Node node, @Language("XPath") String path) throws XPathExpressionException- Throws:
XPathExpressionException
-
getNodesFromXPath
- Throws:
XPathExpressionException
-
resolveNamespace
-
collectAttributesToResolve
public static List<String> collectAttributesToResolve(List<String> attrs, NodeList targetNode) throws PbadExceptionColeta os atributos requisitados de uma nodelist alvo- Parameters:
attrs
- os atributos a serem buscadostargetNode
- o nodo que deve conter os atributos- Returns:
- lista dos nodos encontrados
- Throws:
PbadException
-
getElementOrCreate
-
getChildElements
-
isChildOf
-
getElements
-