Java 类org.jdom2.xpath.XPathHelper 实例源码

项目:qpp-conversion-tool    文件:QrdaXmlDecoder.java   
/**
 * Decodes the top of the XML document
 *
 * @param xmlDoc XML Document to be parsed
 * @return Root node
 */
@Override
protected Node decodeRoot(Element xmlDoc) {
    Node rootNode = new Node();
    Element rootElement = xmlDoc.getDocument().getRootElement();

    QrdaXmlDecoder rootDecoder = null;
    for (Element element : rootElement.getChildren(TEMPLATE_ID, rootElement.getNamespace())) {
        String root = element.getAttributeValue(ROOT_STRING);
        String extension = element.getAttributeValue(EXTENSION_STRING);
        TemplateId templateId = TemplateId.getTemplateId(root, extension, context);
        rootDecoder = getDecoder(templateId);
        if (rootDecoder != null) {
            rootNode.setType(templateId);
            break;
        }
    }

    if (rootDecoder != null) {
        rootDecoder.setNamespace(rootElement, rootDecoder);
        rootNode.setDefaultNsUri(rootDecoder.defaultNs.getURI());
        rootNode.setPath(XPathHelper.getAbsolutePath(rootElement));
        rootDecoder.internalDecode(rootElement, rootNode);
    } else {
        rootNode.setType(TemplateId.PLACEHOLDER);
        rootNode.setPath(XPathHelper.getAbsolutePath(rootElement));
        this.decode(rootElement, rootNode);
    }

    return rootNode;
}
项目:BPMNspector    文件:Ext002Checker.java   
private void createViolation(Attribute firstAttrib, Attribute secondAttrib,
        ValidationResult validationResult) {
    try {
        Resource firstResource = ResourceUtils
                .determineAndCreateResourceFromString(firstAttrib.getDocument().getBaseURI(), null);

        int file1Line = ((LocatedElement) firstAttrib.getParent()).getLine();
        int file1Column = ((LocatedElement) secondAttrib.getParent()).getColumn();
        String file1XPath = XPathHelper.getAbsolutePath(firstAttrib);

        Resource secondResource = ResourceUtils
                .determineAndCreateResourceFromString(secondAttrib.getDocument().getBaseURI(), null);
        int file2Line = ((LocatedElement) secondAttrib.getParent()).getLine();
        int file2Column = ((LocatedElement) secondAttrib.getParent()).getColumn();
        String file2XPath = XPathHelper.getAbsolutePath(secondAttrib);

        Location location = new Location(firstResource, new LocationCoordinate(file1Line, file1Column), file1XPath);
        Violation violation = new Violation(location, "Resources have id duplicates", CONSTRAINTNUMBER);
        validationResult.addViolation(violation);

        Location location2 = new Location(secondResource, new LocationCoordinate(file2Line, file2Column), file2XPath);
        Violation violation2 = new Violation(location2, "Resources have id duplicates", CONSTRAINTNUMBER);
        validationResult.addViolation(violation2);

        LOGGER.info("violation of constraint {} found.", CONSTRAINTNUMBER);
    } catch (ValidationException e) {
        throw new IllegalArgumentException("Invalid baseURI detected.", e);
    }
}
项目:BPMNspector    文件:ProcessImporter.java   
private Violation createViolation(BPMNProcess parent, Element importElement, String msg) {
    int line = ((LocatedElement) importElement).getLine();
    int column = ((LocatedElement) importElement).getColumn();
    String xpath = XPathHelper.getAbsolutePath(importElement);

    Location location = new Location(Paths.get(parent.getBaseURI()), new LocationCoordinate(line, column), xpath);
    return new Violation(location, msg, "EXT.001");
}
项目:BPMN-Reference-Validator    文件:BPMNReferenceValidatorImpl.java   
/**
 * Adds a found existence violation to the list.
 * 
 * @param violationList
 *            the violation list for adding the found violation
 * @param line
 *            the line of the reference in the root file
 * @param currentElement
 *            the element causing the violation
 * @param checkingReference
 *            the violated reference
 */
private void createAndAddExistenceViolation(List<Violation> violationList,
        int line, Element currentElement, Reference checkingReference) {
    String message = ViolationMessageCreator
            .createExistenceViolationMessage(currentElement.getName(),
                    checkingReference.getName(), line,
                    ViolationMessageCreator.DEFAULT_MSG,
                    XPathHelper.getAbsolutePath(currentElement), language);
    Violation violation = new Violation(CONSTRAINT_REF_EXISTENCE,
            getUriFromElement(currentElement), line,
            XPathHelper.getAbsolutePath(currentElement), message);
    violationList.add(violation);
}
项目:qpp-conversion-tool    文件:QrdaXmlDecoder.java   
/**
 * Decodes Parent element children using recursion.
 *
 * @param element parent element to be decoded
 * @param parentNode parent node to decode into
 * @return status of current decode
 */
private DecodeResult decodeChildren(final Element element, final Node parentNode) {
    setNamespace(element, this);
    Node currentNode = parentNode;

    List<Element> childElements = element.getChildren();

    for (Element childElement : childElements) {

        if (TEMPLATE_ID.equals(childElement.getName())) {
            TemplateId templateId = getTemplateId(childElement);
            QrdaXmlDecoder childDecoder = getDecoder(templateId);

            if (null == childDecoder) {
                continue;
            }
            Node childNode = new Node(templateId, parentNode);
            childNode.setDefaultNsUri(defaultNs.getURI());
            setNamespace(childElement, childDecoder);

            // the child decoder might require the entire its siblings
            DecodeResult result = childDecoder.internalDecode(element, childNode);
            if (result == DecodeResult.TREE_ESCAPED) {
                return DecodeResult.TREE_FINISHED;
            }

            childNode.setPath(XPathHelper.getAbsolutePath(element));

            parentNode.addChildNode(childNode);
            currentNode = childNode;

            DecodeResult placeholderNode = testChildDecodeResult(result, childElement, childNode);
            if (placeholderNode != null) {
                return placeholderNode;
            }
        } else {
            decode(childElement, currentNode);
        }
    }

    return null;
}
项目:BPMN-Reference-Validator    文件:BPMNReferenceValidatorImpl.java   
/**
 * Creates and adds a found reference type violation to the list of
 * violations.
 * 
 * @param violationList
 *            the violation list for adding the found violation
 * @param line
 *            the line of the reference in the root file
 * @param currentElement
 *            the element causing the violation
 * @param checkingReference
 *            the violated reference
 * @param referencedElement
 *            the actually referenced element
 * @param types
 *            a list of allowed reference types
 */
private void createAndAddReferenceTypeViolation(
        List<Violation> violationList, int line, Element currentElement,
        Reference checkingReference, Element referencedElement,
        ArrayList<String> types) {

    String message = ViolationMessageCreator.createTypeViolationMessage(
            currentElement.getName(), line, checkingReference.getName(),
            referencedElement.getName(), types.toString(), language);

    Violation violation = new Violation(CONSTRAINT_REF_TYPE,
            getUriFromElement(currentElement), line,
            XPathHelper.getAbsolutePath(currentElement), message);

    violationList.add(violation);
}
项目:BPMNspector    文件:ReferenceChecker.java   
/**
 * Adds a found existence violation to the list.
 *
 * @param validationResult
 *            the validation result for adding the found violation
 * @param line
 *            the line of the reference in the root file
 * @param column
 *            the column of the reference in the root file
 * @param currentElement
 *            the element causing the violation
 * @param checkingReference
 *            the violated reference
 * @throws ValidationException thrown if the Validation could not be created
 */
public void createAndAddExistenceViolation(ValidationResult validationResult,
                                           int line, int column, Element currentElement,
                                           Reference checkingReference) throws ValidationException {
    String message = ViolationMessageCreator
            .createExistenceViolationMessage(currentElement.getName(), checkingReference.getName(), line,
                    ViolationMessageCreator.DEFAULT_MSG, XPathHelper.getAbsolutePath(currentElement));
    Violation violation = new Violation(createLocation(line, column, currentElement), message, CONSTRAINT_REF_EXISTENCE);
    validationResult.addViolation(violation);
}