Package javax.xml.xpath

Examples of javax.xml.xpath.XPathFunctionException


     * Compile time checking for the non standard ode:splitToElements function.
     */
    public class SplitToElements implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() <= 2 || args.size() >= 5)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "splitInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("splitToElements call(context=" + _ectx + " args=" + args + ")");
            }

            String strToSplit;
            try {
                strToSplit = Helper.extractString(args.get(0));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "splitInvalidSource"), e));
            }

            // Other parameters
            String separator = (String) args.get(1);
            String localName = (String) args.get(2);
View Full Code Here


     */
    public static class CombineUrl implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            final QName FAULT_QNAME = new QName(Namespaces.ODE_EXTENSION_NS, "combineUrlInvalidSource");
            if (args.size() != 2) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid arguments"));
            }


            String base;
            try {
                base = Helper.extractString(args.get(0));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid argument: " + args.get(0), e));
            }
            String relative;
            try {
                relative = Helper.extractString(args.get(1));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid argument: " + args.get(1), e));
            }

            URL baseURL;
            try {
                baseURL = new URL(base);
            } catch (MalformedURLException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "First parameter [" + base + "] MUST point to a well-formed URL.", e));
            }
            try {
                URL combined = new URL(baseURL, relative);
                return combined.toExternalForm();
            } catch (MalformedURLException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, e.getMessage(), e));
            }
        }
View Full Code Here

            if (args.size() == 2) {
                separareParameteters = false;
            } else if (args.size() > 2 && args.size() % 2 == 1) {
                separareParameteters = true;
            } else {
                throw new XPathFunctionException(new FaultException(faultQName, "Illegal Arguments"));
            }
            try {
                uriTemplate = Helper.extractString(args.get(0));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument: URI Template expected. " + args.get(0), e));
            }
            if (separareParameteters) {
                // /!\ Do NOT get the first element
                try {
                    pairs = Helper.buildNameValueMap(args, 1);
                } catch (IllegalArgumentException e) {
                    throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
                }
            } else {
                try {
                    List elmts = (List) args.get(1);
                    Element elt = (Element) elmts.get(0);
                    pairs = Helper.extractNameValueMap(elt);
                } catch (ClassCastException e) {
                    throw new XPathFunctionException(new FaultException(faultQName, "Expected an element similar too: <foo><name1>value1</name1>name2>value2</name2>...</foo>"));
                }
            }

            try {
                if (preserveUndefinedVar) {
                    return URITemplate.expandLazily(uriTemplate, pairs);
                } else {
                    return URITemplate.expand(uriTemplate, pairs);
                }
            } catch (URIException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
            } catch (UnsupportedOperationException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
            }
        }
View Full Code Here

     */
    public static class CombineUrl implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            final QName FAULT_QNAME = new QName(Namespaces.ODE_EXTENSION_NS, "combineUrlInvalidSource");
            if (args.size() != 2) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid arguments"));
            }


            String base;
            try {
                base = Helper.extractString(args.get(0));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid argument: " + args.get(0), e));
            }
            String relative;
            try {
                relative = Helper.extractString(args.get(1));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "Invalid argument: " + args.get(1), e));
            }

            URL baseURL;
            try {
                baseURL = new URL(base);
            } catch (MalformedURLException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, "First parameter [" + base + "] MUST point to a well-formed URL.", e));
            }
            try {
                URL combined = new URL(baseURL, relative);
                return combined.toExternalForm();
            } catch (MalformedURLException e) {
                throw new XPathFunctionException(new FaultException(FAULT_QNAME, e.getMessage(), e));
            }
        }
View Full Code Here

            if (args.size() == 2) {
                separareParameteters = false;
            } else if (args.size() > 2 && args.size() % 2 == 1) {
                separareParameteters = true;
            } else {
                throw new XPathFunctionException(new FaultException(faultQName, "Illegal Arguments"));
            }
            try {
                uriTemplate = Helper.extractString(args.get(0));
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument: URI Template expected. " + args.get(0), e));
            }
            if (separareParameteters) {
                // /!\ Do NOT get the first element
                try {
                    pairs = Helper.buildNameValueMap(args, 1);
                } catch (IllegalArgumentException e) {
                    throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
                }
            } else {
                try {
                    Element elt = null;
                    if (args.get(1) instanceof List) {
                        List elmts = (List) args.get(1);
                        elt = (Element) elmts.get(0);
                    } else if (args.get(1) instanceof Element) {
                        elt = (Element) args.get(1);
                    }
                    pairs = Helper.extractNameValueMap(elt);
                } catch (ClassCastException e) {
                    throw new XPathFunctionException(new FaultException(faultQName, "Expected an element similar too: <foo><name1>value1</name1><name2>value2</name2>...</foo>"));
                }
            }

            try {
                if (preserveUndefinedVar) {
                    return URITemplate.expandLazily(uriTemplate, pairs);
                } else {
                    return URITemplate.expand(uriTemplate, pairs);
                }
            } catch (URIException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
            } catch (UnsupportedOperationException e) {
                throw new XPathFunctionException(new FaultException(faultQName, "Invalid argument", e));
            }
        }
View Full Code Here

    }

    public class InsertInto implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() != 3)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "insertIntoInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("insertInto call(context=" + _ectx + " args=" + args + ")");
            }

            Element parentElmt;
            int position;
            List childNodes;
            try {
                if (args.get(0) instanceof List) {
                    List elmts = (List) args.get(0);
                    if (elmts.size() != 1) throw new XPathFunctionException(
                            new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                    "The bpws:insertInto function MUST be passed a single " +
                                            "element node."));
                    parentElmt = (Element) elmts.get(0);
                } else if (args.get(0) instanceof NodeWrapper) {
                    parentElmt = (Element) ((NodeWrapper) args.get(0)).getUnderlyingNode();
                } else if (args.get(0) instanceof Element) {
                    parentElmt = (Element) args.get(0);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
                position = Helper.extractInteger(args.get(1));
                if (args.get(2) instanceof List) {
                    childNodes = (List) args.get(2);
                } else if (args.get(2) instanceof NodeWrapper) {
                    Node childElmt = (Node) ((NodeWrapper) args.get(2)).getUnderlyingNode();
                    childNodes = new ArrayList<Node>();
                    childNodes.add(childElmt);
                } else if (args.get(2) instanceof Element) {
                    Node childElmt = (Node) args.get(2);
                    childNodes = new ArrayList<Node>();
                    childNodes.add(childElmt);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
                                "Invalid argument: URI Template expected. " + args.get(0), e));
            } catch (ClassCastException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                "The bpws:insertInto function MUST be passed a single " +
                                        "element node."));
            }
            Element clonedElmt = (Element) parentElmt.cloneNode(true);
View Full Code Here

    }

    public class InsertAfter implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() < 2 || args.size() > 3)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "insertAfterInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("insertAfter call(context=" + _ectx + " args=" + args + ")");
            }

            Element targetElmt;
            List<Node> siblingNodes;
            Object childArg = null, siblingsArg = null;
            try {
                if (args.size() == 2) {
                    childArg = args.get(0);
                    siblingsArg = args.get(1);
                } else {
                    childArg = args.get(1);
                    siblingsArg = args.get(2);
                }
                if (childArg instanceof List) {
                    List elmts = (List) childArg;
                    // allow insertions after a sequence of node items
                    // if (elmts.size() != 1) throw new XPathFunctionException(
                    //        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                    //                "The bpws:insertAfter function MUST be passed a single " +
                    //                        "element node."));
                    targetElmt = (Element) elmts.get(elmts.size() - 1);
                } else if (childArg instanceof NodeWrapper) {
                    targetElmt = (Element) ((NodeWrapper) childArg).getUnderlyingNode();
                } else if (childArg instanceof Element) {
                    targetElmt = (Element) childArg;
                } else {
                    throw new XPathFunctionException("Unexpected argument type: " + childArg.getClass());
                }
                if (siblingsArg instanceof List) {
                    siblingNodes = (List<Node>) siblingsArg;
                } else if (siblingsArg instanceof NodeWrapper) {
                    Node childElmt = (Node) ((NodeWrapper) siblingsArg).getUnderlyingNode();
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else if (siblingsArg instanceof Element) {
                    Node childElmt = (Node) siblingsArg;
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: " + siblingsArg.getClass());
                }
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
                                "Invalid argument: URI Template expected. " + siblingsArg, e));
            } catch (ClassCastException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                "The bpws:insertAfter function MUST be passed a single " +
                                        "element node."));
            }
            Element parentElmt = (Element) targetElmt.getParentNode();
View Full Code Here

    }

    public class InsertBefore implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() < 2 || args.size() > 3)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "insertBeforeInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("insertBefore call(context=" + _ectx + " args=" + args + ")");
            }

            Element targetElmt;
            List<Node> siblingNodes;
            Object childArg = null, siblingsArg = null;
            try {
                if (args.size() == 2) {
                    childArg = args.get(0);
                    siblingsArg = args.get(1);
                } else {
                    childArg = args.get(1);
                    siblingsArg = args.get(2);
                }
                if (childArg instanceof List) {
                    List elmts = (List) childArg;
                    // allow insertions after a sequence of node items
                    // if (elmts.size() != 1) throw new XPathFunctionException(
                    //        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                    //                "The bpws:insertBefore function MUST be passed a single " +
                    //                        "element node."));
                    targetElmt = (Element) elmts.get(0);
                } else if (childArg instanceof NodeWrapper) {
                    targetElmt = (Element) ((NodeWrapper) childArg).getUnderlyingNode();
                } else if (childArg instanceof Element) {
                    targetElmt = (Element) childArg;
                } else {
                    throw new XPathFunctionException("Unexpected argument type: " + childArg.getClass());
                }
                if (siblingsArg instanceof List) {
                    siblingNodes = (List) siblingsArg;
                } else if (siblingsArg instanceof NodeWrapper) {
                    Node childElmt = (Node) ((NodeWrapper) siblingsArg).getUnderlyingNode();
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else if (siblingsArg instanceof Element) {
                    Node childElmt = (Node) siblingsArg;
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: " + siblingsArg.getClass());
                }
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
                                "Invalid argument: URI Template expected. " + childArg, e));
            } catch (ClassCastException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                "The bpws:insertBefore function MUST be passed a single " +
                                        "element node."));
            }
            Element parentElmt = (Element) targetElmt.getParentNode();
View Full Code Here

    }

    public class InsertAsFirstInto implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() != 2)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "insertAsFirstIntoInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("insertAsFirstInto call(context=" + _ectx + " args=" + args + ")");
            }

            Element targetElmt;
            List siblingNodes;
            try {
                if (args.get(0) instanceof List) {
                    List elmts = (List) args.get(0);
                    if (elmts.size() != 1) throw new XPathFunctionException(
                            new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                    "The bpws:insertAsFirstInto function MUST be passed a single " +
                                            "element node."));
                    targetElmt = (Element) elmts.get(0);
                } else if (args.get(0) instanceof NodeWrapper) {
                    targetElmt = (Element) ((NodeWrapper) args.get(0)).getUnderlyingNode();
                } else if (args.get(0) instanceof Element) {
                    targetElmt = (Element) args.get(0);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
                if (args.get(1) instanceof List) {
                    siblingNodes = (List) args.get(1);
                } else if (args.get(1) instanceof NodeWrapper) {
                    Node childElmt = (Node) ((NodeWrapper) args.get(1)).getUnderlyingNode();
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else if (args.get(1) instanceof Element) {
                    Node childElmt = (Node) args.get(1);
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
                                "Invalid argument: URI Template expected. " + args.get(0), e));
            } catch (ClassCastException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                "The bpws:insertAsFirstInto function MUST be passed a single " +
                                        "element node."));
            }
            Element clonedElmt = (Element) targetElmt.cloneNode(true);
View Full Code Here

    }

    public class InsertAsLastInto implements XPathFunction {
        public Object evaluate(List args) throws XPathFunctionException {
            if (args.size() != 2)
                throw new XPathFunctionException(new FaultException(new QName(Namespaces.ODE_EXTENSION_NS, "insertAsLastIntoInvalidSource"), "Invalid arguments"));

            if (__log.isDebugEnabled()) {
                __log.debug("insertAsLastInto call(context=" + _ectx + " args=" + args + ")");
            }

            Element targetElmt;
            List siblingNodes;
            try {
                if (args.get(0) instanceof List) {
                    List elmts = (List) args.get(0);
                    if (elmts.size() != 1) throw new XPathFunctionException(
                            new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                    "The bpws:insertAsLastInto function MUST be passed a single " +
                                            "element node."));
                    targetElmt = (Element) elmts.get(0);
                } else if (args.get(0) instanceof NodeWrapper) {
                    targetElmt = (Element) ((NodeWrapper) args.get(0)).getUnderlyingNode();
                } else if (args.get(0) instanceof Element) {
                    targetElmt = (Element) args.get(0);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
                if (args.get(1) instanceof List) {
                    siblingNodes = (List) args.get(1);
                } else if (args.get(1) instanceof NodeWrapper) {
                    Node childElmt = (Node) ((NodeWrapper) args.get(1)).getUnderlyingNode();
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else if (args.get(1) instanceof Element) {
                    Node childElmt = (Node) args.get(1);
                    siblingNodes = new ArrayList<Node>();
                    siblingNodes.add(childElmt);
                } else {
                    throw new XPathFunctionException("Unexpected argument type: "+args.get(0).getClass());
                }
            } catch (IllegalArgumentException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnInvalidExpressionValue,
                                "Invalid argument: URI Template expected. " + args.get(0), e));
            } catch (ClassCastException e) {
                throw new XPathFunctionException(
                        new FaultException(_oxpath.getOwner().constants.qnSelectionFailure,
                                "The bpws:insertAsLastInto function MUST be passed a single " +
                                        "element node."));
            }
            Element clonedElmt = (Element) targetElmt.cloneNode(true);
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPathFunctionException

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.