use of org.loboevolution.type.NodeType in project LoboEvolution by LoboEvolution.
the class XPathExpressionImpl method evaluate.
/**
* {@inheritDoc}
*/
@Override
public Object evaluate(Node contextNode, short type, Object result) throws XPathException, DOMException {
// If the XPathEvaluator was determined by "casting" the document
if (m_doc != null) {
// Check that the context node is owned by the same document
if (!Objects.equals(contextNode, m_doc) && !contextNode.getOwnerDocument().equals(m_doc)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, fmsg);
}
// Check that the context node is an acceptable node type
NodeType nodeType = contextNode.getNodeType();
switch(nodeType) {
case DOCUMENT_NODE:
case ELEMENT_NODE:
case ATTRIBUTE_NODE:
case TEXT_NODE:
case CDATA_SECTION_NODE:
case COMMENT_NODE:
case PROCESSING_INSTRUCTION_NODE:
break;
default:
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);
throw new UnsupportedOperationException(fmsg);
}
}
if (!XPathResultImpl.isValidType(type)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] { (int) type });
throw new XPathException(XPathException.TYPE_ERR, fmsg);
}
XPathContext xpathSupport = new XPathContext(false);
XObject xobj = null;
return new XPathResultImpl(type, xobj, contextNode, m_xpath);
}
use of org.loboevolution.type.NodeType in project LoboEvolution by LoboEvolution.
the class RBlockViewport method layoutChildren.
private void layoutChildren(NodeImpl node) {
final NodeListImpl nodeList = node.getNodeList();
if (nodeList != null) {
nodeList.forEach(nd -> {
final NodeImpl child = (NodeImpl) nd;
final NodeType nodeType = child.getNodeType();
switch(nodeType) {
case TEXT_NODE:
layoutText(child);
break;
case ELEMENT_NODE:
this.currentLine.addStyleChanger(new RStyleChanger(child));
final String nodeName = child.getNodeName().toUpperCase();
MarkupLayout ml = RLayout.elementLayout.get(HTMLTag.get(nodeName));
if (ml == null) {
ml = miscLayout;
}
ml.layoutMarkup(this, (HTMLElementImpl) child);
this.currentLine.addStyleChanger(new RStyleChanger(node));
break;
case DOCUMENT_FRAGMENT_NODE:
final DocumentFragmentImpl fragment = (DocumentFragmentImpl) child;
fragment.getNodeList().forEach(fragNode -> {
final NodeImpl fragChild = (NodeImpl) fragNode;
layoutChildren(fragChild);
});
break;
case COMMENT_NODE:
case PROCESSING_INSTRUCTION_NODE:
default:
break;
}
});
}
}
use of org.loboevolution.type.NodeType in project LoboEvolution by LoboEvolution.
the class NodeImpl method getTextContent.
/**
* {@inheritDoc}
*
* Gets the text content of this node and its descendents.
*/
@Override
public String getTextContent() {
final StringBuilder sb = new StringBuilder();
nodeList.forEach(child -> {
final NodeType type = child.getNodeType();
switch(type) {
case CDATA_SECTION_NODE:
case TEXT_NODE:
case ELEMENT_NODE:
final String textContent = child.getTextContent();
if (textContent != null) {
sb.append(textContent);
}
break;
default:
break;
}
});
return sb.toString();
}
use of org.loboevolution.type.NodeType in project LoboEvolution by LoboEvolution.
the class XPathNSResolverImpl method lookupNamespaceURI.
/**
* {@inheritDoc}
*/
@Override
public String lookupNamespaceURI(String prefix) {
String namespace = null;
if (prefix.equals("xml")) {
namespace = Constants.S_XMLNAMESPACEURI;
} else {
NodeType type;
while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == NodeType.ELEMENT_NODE) || ((type = parent.getNodeType()) == NodeType.DOCUMENT_NODE) || (type == NodeType.ENTITY_REFERENCE_NODE))) {
if (type == NodeType.DOCUMENT_NODE) {
Document document = (Document) parent;
Element docelm = document.getDocumentElement();
if (docelm != null && docelm.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return docelm.getNamespaceURI();
}
}
if (type == NodeType.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return parent.getNamespaceURI();
}
NamedNodeMap nnm = ((Element) parent).getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
use of org.loboevolution.type.NodeType in project LoboEvolution by LoboEvolution.
the class XMLSerializerImpl method getXMLString.
public static void getXMLString(Element node, boolean withoutNamespaces, StringBuffer buff, boolean endTag) {
try {
buff.append("<").append(namespace(node.getNodeName(), withoutNamespaces));
if (node.hasAttributes()) {
buff.append(" ");
NamedNodeMap attributes = node.getAttributes();
for (Attr attrItem : Nodes.iterable(attributes)) {
String name = namespace(attrItem.getNodeName(), withoutNamespaces);
String value = attrItem.getNodeValue();
buff.append(name).append("=").append("\"").append(value).append("\"");
}
}
if (node.hasChildNodes()) {
buff.append(">");
NodeList children = node.getChildNodes();
int childrenCount = children.getLength();
if (childrenCount == 1) {
Node item = children.item(0);
NodeType itemType = item.getNodeType();
if (itemType == NodeType.TEXT_NODE) {
if (item.getNodeValue() == null) {
buff.append("/>");
} else {
buff.append(item.getNodeValue());
buff.append("</").append(namespace(node.getNodeName(), withoutNamespaces)).append(">");
}
endTag = false;
}
}
NodeListImpl child = (NodeListImpl) children;
AtomicBoolean tag = new AtomicBoolean(endTag);
child.forEach(item -> {
NodeType itemType = item.getNodeType();
if (itemType == NodeType.DOCUMENT_NODE || itemType == NodeType.ELEMENT_NODE) {
getXMLString((Element) item, withoutNamespaces, buff, tag.get());
}
});
} else {
if (node.getNodeValue() == null) {
buff.append("/>");
} else {
buff.append(node.getNodeValue());
buff.append("</").append(namespace(node.getNodeName(), withoutNamespaces)).append(">");
}
endTag = false;
}
if (endTag) {
buff.append("</").append(namespace(node.getNodeName(), withoutNamespaces)).append(">");
}
} catch (Exception e) {
logger.severe(e.getMessage());
}
}
Aggregations