Package net.sf.saxon.xpath

Examples of net.sf.saxon.xpath.DynamicError


                                    new OutputStreamWriter(
                                        outputStream, javaEncoding));
                    break;
                } catch (Exception err) {
                    if (encoding.equalsIgnoreCase("UTF8")) {
                        throw new DynamicError("Failed to create a UTF8 output writer");
                    }
                    System.err.println("Encoding " + encoding + " is not supported: using UTF8");
                    encoding = "UTF8";
                    characterSet = UnicodeCharacterSet.getInstance();
                    outputProperties.put(OutputKeys.ENCODING, "UTF-8");
View Full Code Here


    {
        Object handler;
        try {
            handler = Loader.getInstance(className);
        } catch (XPathException e) {
            throw new DynamicError("Cannot load user-supplied output method " + className);
        }

        if (handler instanceof Emitter) {
            return (Emitter)handler;
        } else if (handler instanceof ContentHandler) {
            ContentHandlerProxy emitter = new ContentHandlerProxy();
            emitter.setUnderlyingContentHandler((ContentHandler)handler);
            return emitter;
        } else {
            throw new DynamicError("Failed to load emitter " + className +
                        ": it is neither an Emitter nor a SAX2 ContentHandler");
        }

    }
View Full Code Here

                            NodeInfo node = ((SingletonNode)v).getNode();
                            if (node != null) {
                                array[a++] = node;
                            }
                        } else {
                            throw new DynamicError(
                                    "Returned List contains an object that cannot be converted to an Item (" + obj.getClass() + ')');
                        }
                    }
                }
            }

            return new SequenceExtent(array);

        } else if (result instanceof Object[]) {
             Item[] array = new Item[((Object[])result).length];
             int a = 0;
             for (int i = 0; i < ((Object[])result).length; i++){
                 Object obj = ((Object[])result)[i];
                 if (obj instanceof NodeInfo) {
                     array[a++] = (NodeInfo)obj;
                 } else {
                     Value v = convertJavaObjectToXPath(obj, controller);
                     if (v!=null) {
                         if (v instanceof Item) {
                             array[a++] = (Item)v;
                         } else {
                             throw new DynamicError(
                                     "Returned array contains an object that cannot be converted to an Item (" + obj.getClass() + ')');
                         }
                     }
                 }
             }
             return new SequenceExtent(array);

        } else if (result instanceof long[]) {
             Item[] array = new Item[((long[])result).length];
             for (int i = 0; i < ((long[])result).length; i++){
                 array[i] = new IntegerValue(((long[])result)[i]);
             }
             return new SequenceExtent(array);

        } else if (result instanceof int[]) {
             Item[] array = new Item[((int[])result).length];
             for (int i = 0; i < ((int[])result).length; i++){
                 array[i] = new IntegerValue(((int[])result)[i]);
             }
             return new SequenceExtent(array);

        } else if (result instanceof short[]) {
             Item[] array = new Item[((short[])result).length];
             for (int i = 0; i < ((short[])result).length; i++){
                 array[i] = new IntegerValue(((short[])result)[i]);
             }
             return new SequenceExtent(array);

        } else if (result instanceof byte[]) {  // interpret this as unsigned bytes
             Item[] array = new Item[((byte[])result).length];
             for (int i = 0; i < ((byte[])result).length; i++){
                 array[i] = new IntegerValue(255 & (int)((byte[])result)[i]);
             }
             return new SequenceExtent(array);

        } else if (result instanceof char[]) {
             return new StringValue(new String((char[])result));

       } else if (result instanceof boolean[]) {
             Item[] array = new Item[((boolean[])result).length];
             for (int i = 0; i < ((boolean[])result).length; i++){
                 array[i] = BooleanValue.get(((boolean[])result)[i]);
             }
             return new SequenceExtent(array);

        } else if (result instanceof Source && controller != null) {
            if (result instanceof DOMSource) {
                return new SingletonNode(controller.prepareInputTree((Source)result));
            }
            try {
                Builder b = controller.makeBuilder();
                new Sender(controller.getConfiguration()).send((Source) result, b);
                return new SingletonNode(b.getCurrentDocument());
            } catch (XPathException err) {
                throw new DynamicError(err);
            }

        } else if (result instanceof org.w3c.dom.NodeList) {
            NodeList list = ((NodeList)result);
            NodeInfo[] nodes = new NodeInfo[list.getLength()];
            for (int i=0; i<list.getLength(); i++) {
                if (list.item(i) instanceof NodeInfo) {
                    nodes[i] = (NodeInfo)list.item(i);
                } else {
                    throw new DynamicError("Supplied NodeList contains non-Saxon DOM Nodes");
                }

            }
            return new SequenceExtent(nodes);
            // Note, we accept the nodes in the order returned by the function; there
            // is no requirement that this should be document order.
        } else if (result instanceof org.w3c.dom.Node) {
            throw new DynamicError("Supplied Java object is a non-Saxon DOM Node");
        } else {
            return new ObjectValue(result);
        }
    }
View Full Code Here

{
    public void close() throws XPathException {
        try {
            writer.write('\n');
        } catch (java.io.IOException err) {
            throw new DynamicError(err);
        }
        super.close();
    }
View Full Code Here

        case Type.IDREF:
        case Type.ENTITY:
        case Type.NMTOKEN:
            return new RestrictedStringValue(value, requiredType);
        default:
            DynamicError err = new DynamicError("Cannot convert anyURI to " +
                                     StandardNames.getDisplayName(requiredType));
            err.setXPathContext(context);
            err.setErrorCode("FORG0001");
            throw err;
        }
    }
View Full Code Here

            return this;
        } else if (target==URI.class) {
            try {
                return new URI(value);
            } catch (URISyntaxException err) {
                throw new DynamicError("The anyURI value '" + value + "' is not an acceptable Java URI");
            }
        } else if (target==URL.class) {
            try {
                return new URL(value);
            } catch (MalformedURLException err) {
                throw new DynamicError("The anyURI value '" + value + "' is not an acceptable Java URL");
            }
        } else if (target==String.class) {
            return value;
        } else if (target==CharSequence.class) {
            return value;
        } else {
             Object o = super.convertToJava(target, config, context);
            if (o == null) {
                throw new DynamicError("Conversion of anyURI to " + target.getName() +
                        " is not supported");
            }
            return o;
        }
    }
View Full Code Here

            if (term.equals("no")) {
                // no action
            } else if (term.equals("yes")) {
                throw new TerminationException("Processing terminated by xsl:message at line " + getLineNumber());
            } else {
                DynamicError e = new DynamicError("The terminate attribute of xsl:message must be 'yes' or 'no'");
                e.setXPathContext(context);
                e.setErrorCode("XT0030");
                throw e;
            }
        }
        return null;
    }
View Full Code Here

            try {
                String[] parts = Name.getQNameParts(rawName);
                prefix = parts[0];
                localName = parts[1];
            } catch (QNameException err) {
                DynamicError err1 = new DynamicError("Invalid attribute name: " + rawName, this);
                err1.setErrorCode("XT0850");
                err1.setXPathContext(context);
                context.getController().recoverableError(err1);
                return -1;
            }
            if (rawName.equals("xmlns")) {
                if (namespace==null) {
                    DynamicError err = new DynamicError("Invalid attribute name: " + rawName, this);
                    err.setErrorCode("XT0850");
                    err.setXPathContext(context);
                    context.getController().recoverableError(err);
                    return -1;
                }
            }
            if (prefix.equals("xmlns")) {
                if (namespace==null) {
                    DynamicError err = new DynamicError("Invalid attribute name: " + rawName, this);
                    err.setErrorCode("XT0850");
                    err.setXPathContext(context);
                    context.getController().recoverableError(err);
                    return -1;
                } else {
                    // ignore the prefix "xmlns"
                    prefix = "";
                }
            }

        } else if (attributeName instanceof QNameValue) {
            // this is allowed in XQuery
            localName = ((QNameValue)nameValue).getLocalName();
            String namespaceURI = ((QNameValue)nameValue).getNamespaceURI();
            namespace = new StringValue(namespaceURI);
            if (namespaceURI.equals("")) {
                prefix = "";
            } else {
                // we need to allocate a prefix. Any one will do; if it's a duplicate,
                // a different one will be substituted
                prefix = pool.suggestPrefixForURI(namespaceURI);
                if (prefix == null) {
                    prefix = "nsq0";
                }
            }

        }

        String uri;

        if (namespace==null) {
          if ("".equals(prefix)) {
            uri = "";
          } else {
                uri = nsContext.getURIForPrefix(prefix, false);
                if (uri==null) {
                    DynamicError err = new DynamicError("Undeclared prefix in attribute name: " + prefix, this);
                    err.setErrorCode("XT0860");
                    err.setXPathContext(context);
                    context.getController().recoverableError(err);
                    return -1;
              }
          }
View Full Code Here

    public void close() throws XPathException {
        super.close();
        DocumentInfo doc = builder.getCurrentDocument();
        if (doc==null) {
            throw new DynamicError("No source document has been built");
        }
        doc.getNamePool().allocateDocumentNumber(doc);
        try {
            controller.transformDocument(doc, result);
        } catch (TransformerException e) {
View Full Code Here

                    if ("0".equals(val) || "false".equals(val)) {
                        return BooleanValue.FALSE;
                    } else if ("1".equals(val) || "true".equals(val)) {
                        return BooleanValue.TRUE;
                    } else {
                        DynamicError err = new DynamicError(
                                "The string " + Err.wrap(val, Err.VALUE) + " cannot be cast to a boolean");
                        err.setXPathContext(context);
                        err.setErrorCode("FORG0001");
                        throw err;
                    }
                }
                case Type.NUMBER:
                case Type.DOUBLE:
                    return new DoubleValue(value);
                case Type.INTEGER:
                    return IntegerValue.stringToInteger(value);

                case Type.NON_POSITIVE_INTEGER:
                case Type.NEGATIVE_INTEGER:
                case Type.LONG:
                case Type.INT:
                case Type.SHORT:
                case Type.BYTE:
                case Type.NON_NEGATIVE_INTEGER:
                case Type.POSITIVE_INTEGER:
                case Type.UNSIGNED_LONG:
                case Type.UNSIGNED_INT:
                case Type.UNSIGNED_SHORT:
                case Type.UNSIGNED_BYTE:
                    NumericValue iv = IntegerValue.stringToInteger(value);
                    AtomicType subtype = (AtomicType) BuiltInSchemaFactory.getSchemaType(requiredType);
                    if (iv instanceof IntegerValue) {
                        ((IntegerValue)iv).setSubType(subtype);
                        return iv;
                    } else {
                        return DerivedAtomicValue.makeValue(iv, value.toString(), subtype, true);
                    }
                case Type.DECIMAL:
                    return new DecimalValue(value);
                case Type.FLOAT:
                    return new FloatValue(value);
                case Type.DATE:
                    return new DateValue(value);
                case Type.DATE_TIME:
                    return new DateTimeValue(value);
                case Type.TIME:
                    return new TimeValue(value);
                case Type.G_YEAR:
                    return new GYearValue(value);
                case Type.G_YEAR_MONTH:
                    return new GYearMonthValue(value);
                case Type.G_MONTH:
                    return new GMonthValue(value);
                case Type.G_MONTH_DAY:
                    return new GMonthDayValue(value);
                case Type.G_DAY:
                    return new GDayValue(value);
                case Type.DURATION:
                    return new DurationValue(value);
                case Type.YEAR_MONTH_DURATION:
                    return new MonthDurationValue(value);
                case Type.DAY_TIME_DURATION:
                    return new SecondsDurationValue(value);
                case Type.UNTYPED_ATOMIC:
                case Type.ANY_SIMPLE_TYPE:
                    return new UntypedAtomicValue(value);
                case Type.STRING:
                case Type.ATOMIC:
                case Type.ITEM:
                    return this;
                case Type.NORMALIZED_STRING:
                case Type.TOKEN:
                case Type.LANGUAGE:
                case Type.NAME:
                case Type.NCNAME:
                case Type.ID:
                case Type.IDREF:
                case Type.ENTITY:
                case Type.NMTOKEN:
                    return new RestrictedStringValue(value, requiredType);
                case Type.ANY_URI:
                    return new AnyURIValue(value);
                case Type.HEX_BINARY:
                    return new HexBinaryValue(value);
                case Type.BASE64_BINARY:
                    return new Base64BinaryValue(value);
                default:
                    throw new DynamicError("Cannot convert string to " + StandardNames.getDisplayName(requiredType));
            }
        } catch (DynamicError err) {
            err.setXPathContext(context);
            err.setErrorCode("FORG0001");
            throw err;
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.xpath.DynamicError

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.