Package com.volantis.mcs.xml.xpath

Examples of com.volantis.mcs.xml.xpath.XPath


    public XPath getXPath(IMarker marker) {

        // retrieve the XPath string from the marker
        String xPathStr = null;
        String namespaces = null;
        XPath result = null// return value

        try { //try to get the attributes.
            xPathStr = (String) marker.getAttribute(XPath.class.getName());
            namespaces = (String) marker.
                    getAttribute(MarkerGeneratingErrorReporter.
                            NAMESPACES_ATTRIBUTE);
        } catch (CoreException ce) {
            // just report the error and return
            EclipseCommonPlugin.handleError(ABPlugin.getDefault(), ce);
            xPathStr = null;
        }

        if (xPathStr != null) {

            // get cached XPath if it exists
            result = (XPath) xPathMappings.get(xPathStr);

            if (result == null) { //if an XPath does not exist in the cache
                try {
                    // create an XPath to find the problem markers
                    XPath queryPath = new XPath(xPathStr, namespaces);
                    // find the problem markers. This potentially throws a CoreException
                    IMarker[] markers =
                            PolicyUtils.findProblemMarkers(resource, queryPath);

                    if ((markers == null) || (markers.length == 0)) {
View Full Code Here


     * type of IMarker.PROBLEM and a message created using the
     * ValidationMessageBuilder associated with this ErrorReporter.
     */
    // rest of javadoc inherited
    public void reportError(ErrorDetails details) {
        XPath xPath = details.getXPath();
        String key = details.getKey();
        Element invalidElement = details.getInvalidElement();

        assert xPath != null;
        assert key != null;

        try {
            if (!censoredErrors.isCensored(xPath.getExternalForm(), key)) {
                IMarker[] markers =
                        PolicyUtils.findProblemMarkers(resource, xPath);
                if (markers.length == 0) {

                    String xPathStr = xPath.getExternalForm();
                    // store away the XPath in the map
                    xPathMappings.put(xPathStr, xPath);
                    IMarker marker = resource.createMarker(IMarker.PROBLEM);

                    marker.setAttribute(XPath.class.getName(), xPathStr);
                    marker.setAttribute(NAMESPACES_ATTRIBUTE,
                            xPath.getNamespacesString());
                    marker.setAttribute(IMarker.MESSAGE, createMessage(
                            details));
                    marker.setAttribute(IMarker.LOCATION,
                            getLocationDetailsString(invalidElement));
                    marker.setAttribute(IMarker.SEVERITY,
View Full Code Here

     * @param details the ErrorDetails
     * @return an array of string arguments
     */
    private String[] createFormatArgs(ErrorDetails details) {

        XPath xPath = details.getXPath();
        String param = details.getParam();
        String key = details.getKey();

        String[] args = null;
        if (key == FaultTypes.UNKNOWN_INVALID_XML) {
            // the arg is simply the xpath and the error param
            args = new String[]{xPath.getExternalForm(), param};
        } else if (key == FaultTypes.MISSING_ATTRIBUTE) {
            args = new String[]{getPropertyLabel(param)};
        } else if (FaultTypes.DUPLICATE_ASSET.equals(key)) {
            // currently the duplicate asset message takes no args
            args = null;
        } else if (FaultTypes.DUPLICATE_NAME.equals(key)) {
            Element element = details.getInvalidElement();
            String elementName;
            try {
                if (element == null) {
                    element = xPath.getElement(rootElement);
                }
                elementName =
                        getElementLabel(element.getAttributeValue("name"));

            } catch (XPathException e) {
View Full Code Here

                xPathBuffer.append("ancestor::").//$NON-NLS-1$
                        append(MCSNamespace.DEVICE_DEFINITIONS.getPrefix()).
                        append(':').
                        append(DeviceRepositorySchemaConstants.
                        CATEGORY_ELEMENT_NAME);
                XPath categoryXPath = new XPath(xPathBuffer.toString(),
                        new Namespace[]{MCSNamespace.DEVICE_DEFINITIONS});
                try {
                    categoryElement =
                            categoryXPath.selectSingleElement(selectedElement);
                } catch (XPathException e) {
                    EclipseCommonPlugin.handleError(ABPlugin.getDefault(), e);
                }
            } else if (selectedElement.getName().
                    equals(DeviceRepositorySchemaConstants.
View Full Code Here

            public void reportError(ErrorDetails details) {
                String key = details.getKey();

                if (key == null) {
                    Attributes attributes = details.getAttributes();
                    XPath currentPath = details.getXPath();
                    String errorMessage = details.getMessage();

                    // check to see if a ParserError matches
                    boolean matched = false;
                    for (int j = 0; j < parserErrors.size() && !matched; j++) {
                        ParserError parserError =
                                (ParserError) parserErrors.get(j);
                        String errorParam = parserError.matchedArgument(
                                attributes, errorMessage);

                        if (errorParam != null) {
                            // found a match if the error parameter is not null
                            matched = true;
                            XPath errorPath = currentPath;
                            if (parserError.isAttribute()) {
                                // append the attribute to the path.
                                errorPath = new XPath(currentPath,
                                        "@" + errorParam);
                            }
                            // Modify the error details to include key/param
                            details.setXPath(errorPath);
                            details.setKey(parserError.getKey());
View Full Code Here


            // Validate that the element has content that is non-whitespace
            Iterator contents = element.getContent().iterator();
            if (!contents.hasNext()) {
                ErrorDetails details = new ErrorDetails(element, new XPath(element),
                        null, FaultTypes.WHITESPACE, null, null);
                errorReporter.reportError(details);
            } else {
                Text text = (Text) contents.next();
                String value = text.getText();
                if (value.length() == 0) {
                    ErrorDetails details = new ErrorDetails(element, new XPath(element),
                            null, FaultTypes.WHITESPACE, null, null);
                    errorReporter.reportError(details);
                } else {
                    // Ensure that the value is a number that is comprized only
                    // of digits and is either 6 or 8 digits in length
                    boolean valid = value.length() == 6 || value.length() == 8;
                    if (valid) {
                        for (int i = 0; i < value.length() && valid; i++) {
                            valid = Character.isDigit(value.charAt(i));
                        }
                    }

                    if (!valid) {
                        ErrorDetails details = new ErrorDetails(
                                element, new XPath(element), null, INVALID_TAC_NUMBER,
                                null, null);
                        errorReporter.reportError(details);
                    }
                }
            }
View Full Code Here

        namespaces[0] = Namespace.getNamespace(PREFIX,
                                               namespaceURI);

        this.ancestorElementName = ancestorElementName;

        xpath = new XPath(
            new StringBuffer("ancestor::"). //$NON-NLS-1$
            append(PREFIX).
            append(':').
            append(ancestorElementName).toString(),
            namespaces);
View Full Code Here

     *                      reported
     */
    protected void report(ErrorReporter errorReporter,
                          Element element) {
        if (errorReporter != null) {
            ErrorDetails details = new ErrorDetails(element, new XPath(element),
                    null, errorKey, ancestorElementName, null);
            errorReporter.reportError(details);
        }
    }
View Full Code Here

     * an ODOMAttribute) has any errors.
     */
    // rest of javadoc inherited
    public Image decorateImage(Image image, Object element) {
        checkObject(element);
        final XPath xPath = new ODOMXPath((ODOMObservable) element);
        Image decoratedImage = image;
        try {
            IMarker markers[] = problemMarkerFinder.findProblemMarkers(
                    resource, xPath);
           
View Full Code Here

        if (expectedAncestor == null) {
            assertNull("Ancestor should be null",
                       actualAncestor);
        } else if (actualAncestor == null) {
            fail("Expected ancestor (" +
                 new XPath(expectedAncestor).getExternalForm() +
                 ") not found");
        } else {
            assertSame("Expected ancestor (" +
                       new XPath(expectedAncestor).getExternalForm() +
                       ") not the same as the actual (" +
                       new XPath(actualAncestor).getExternalForm() + ")",
                       expectedAncestor,
                       actualAncestor);
        }
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.xml.xpath.XPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.