Package client.net.sf.saxon.ce.trans

Examples of client.net.sf.saxon.ce.trans.XPathException


        if (argument.length > pos) {
            return;
            // this can happen during optimization, if the extra argument is already present
        }
        if (argument.length != pos) {
            throw new XPathException("Too few arguments in call to " + augmentedName + "() function");
        }
        Expression[] newArgs = new Expression[pos+1];
        System.arraycopy(argument, 0, newArgs, 0, argument.length);
        RootExpression rootExpression = new RootExpression();
        ExpressionTool.copyLocationInfo(this, rootExpression);
View Full Code Here


            }
            String input = arg0.getStringValue();
            CharSequence res = re.replace(input, replacement);
            return StringValue.makeStringValue(res);
        } catch (XPathException err) {
            XPathException de = new XPathException(err);
            de.setErrorCode("FORX0002");
            de.setXPathContext(c);
            de.maybeSetLocation(getSourceLocator());
            throw de;
        }


    }
View Full Code Here

                        uri = env.getURIForPrefix(prefix);
                    }
                    StructuredQName functionName = new StructuredQName(prefix, uri, parts[1]);
                    b = (env.getFunctionLibrary().hasFunctionSignature(functionName, (int)arity));
                } catch (QNameException e) {
                    XPathException err = new XPathException(e.getMessage());
                    err.setErrorCode("XTDE1400");
                    throw err;
                } catch (XPathException e2) {
                    if ("XTDE0290".equals(e2.getErrorCodeLocalPart())) {
                        e2.setErrorCode("XTDE1400");
                    }
                    throw e2;
                }
                break;
            case TYPE_AVAILABLE:
                try {
                    String[] parts = NameChecker.getQNameParts(lexicalQName);
                    String prefix = parts[0];
                    String uri;
                    if (prefix.length() == 0) {
                        uri = env.getDefaultElementNamespace();
                    } else {
                        uri = env.getURIForPrefix(prefix);
                    }

                    int fingerprint = config.getNamePool().allocate(prefix, uri, parts[1]) & 0xfffff;
                    SchemaType type = config.getSchemaType(fingerprint);
                    b = type instanceof BuiltInAtomicType;
                } catch (QNameException e) {
                    XPathException err = new XPathException(e.getMessage());
                    err.setErrorCode("XTDE1425");
                    throw err;
                }
        }
        return Literal.makeLiteral(BooleanValue.get(b));
    }
View Full Code Here

                } else if ("collection".equals(local) && staticArgs.length <= 1) {
                    if (staticArgs.length == 0) {
                        return new Literal(EmptySequence.getInstance());
                    } else {
                        return new ErrorExpression(
                                new XPathException("No collection URIs are recognized by Saxon-CE", "FODC0002"));
                    }
                } else if ("data".equals(local) && staticArgs.length == 1) {
                    return new Atomizer(staticArgs[0]);
                } else if ("default-collation".equals(local) && staticArgs.length == 0) {
                    return new StringLiteral(env.getDefaultCollationName());
                } else if ("exactly-one".equals(local) && staticArgs.length == 1) {
                    RoleLocator role = new RoleLocator(RoleLocator.FUNCTION, "one-or-more", 1);
                    role.setErrorCode("FORG0005");
                    return CardinalityChecker.makeCardinalityChecker(staticArgs[0], StaticProperty.EXACTLY_ONE, role);    
                } else if ("idref".equals(local) && (staticArgs.length == 1 || staticArgs.length == 2)) {
                    return new Literal(EmptySequence.getInstance());
                } else if ("nilled".equals(local) && staticArgs.length == 1) {
                    return new Literal(BooleanValue.FALSE);
                } else if ("one-or-more".equals(local) && staticArgs.length == 1) {
                    RoleLocator role = new RoleLocator(RoleLocator.FUNCTION, "one-or-more", 1);
                    role.setErrorCode("FORG0004");
                    return CardinalityChecker.makeCardinalityChecker(staticArgs[0], StaticProperty.ALLOWS_ONE_OR_MORE, role);
                } else if ("static-base-uri".equals(local) && staticArgs.length == 0) {
                        String baseURI = env.getBaseURI();
                        return (baseURI == null ? Literal.makeEmptySequence() : new Literal(new AnyURIValue(baseURI)));
                } else if ("trace".equals(local) && staticArgs.length == 2) {
                    return staticArgs[0];
                } else if ("unordered".equals(local) && staticArgs.length == 1) {
                    return staticArgs[0];
                } else if ("unparsed-entity-uri".equals(local) && staticArgs.length == 1) {
                    return new StringLiteral("");
                } else if ("unparsed-entity-public-id".equals(local) && staticArgs.length == 1) {
                    return new StringLiteral("");
                } else if ("zero-or-one".equals(local) && staticArgs.length == 1) {
                    RoleLocator role = new RoleLocator(RoleLocator.FUNCTION, "zero-or-one", 1);
                    role.setErrorCode("FORG0003");
                    return CardinalityChecker.makeCardinalityChecker(staticArgs[0], StaticProperty.ALLOWS_ZERO_OR_ONE, role);
                } else if (StandardFunction.getFunction(local, -1) == null) {
                    XPathException err = new XPathException("Unknown system function " + local + "()");
                    err.setErrorCode("XPST0017");
                    err.setIsStaticError(true);
                    throw err;
                } else {
                    XPathException err = new XPathException("System function " + local + "#"+staticArgs.length +" cannot be called with "
                            + pluralArguments(staticArgs.length));
                    err.setErrorCode("XPST0017");
                    err.setIsStaticError(true);
                    throw err;
                }
            }
            if ((functionSet & entry.applicability) == 0) {
                XPathException err = new XPathException("System function " + local + "#"+staticArgs.length +" is not available with this host language");
                err.setErrorCode("XPST0017");
                err.setIsStaticError(true);
                throw err;
            }
            SystemFunction f = entry.skeleton.newInstance();
            f.setDetails(entry);
            f.setFunctionName(functionName);
View Full Code Here

    * @throws client.net.sf.saxon.ce.trans.XPathException if the number of arguments is out of range
    */

    private int checkArgumentCount(int numArgs, int min, int max, String local) throws XPathException {
        if (min==max && numArgs != min) {
            throw new XPathException("Function " + Err.wrap(local, Err.FUNCTION) + " must have "
                    + min + pluralArguments(min));
        }
        if (numArgs < min) {
            throw new XPathException("Function " + Err.wrap(local, Err.FUNCTION) + " must have at least "
                    + min + pluralArguments(min));
        }
        if (numArgs > max) {
            throw new XPathException("Function " + Err.wrap(local, Err.FUNCTION) + " must have no more than "
                    + max + pluralArguments(max));
        }
        return numArgs;
    }
View Full Code Here

    }

    public void checkArguments(ExpressionVisitor visitor) throws XPathException {
        int numArgs = argument.length;
        if (numArgs != 2 && numArgs != 5) {
            throw new XPathException("Function " + getDisplayName() +
                    " must have either two or five arguments",
                    getSourceLocator());
        }
        super.checkArguments(visitor);
    }
View Full Code Here

            while (i < format.length() && format.charAt(i) != '[') {
                sb.append(format.charAt(i));
                if (format.charAt(i) == ']') {
                    i++;
                    if (i == format.length() || format.charAt(i) != ']') {
                        XPathException e = new XPathException("Closing ']' in date picture must be written as ']]'");
                        e.setErrorCode("XTDE1340");
                        e.setXPathContext(context);
                        throw e;
                    }
                }
                i++;
            }
            if (i == format.length()) {
                break;
            }
            // look for '[['
            i++;
            if (i < format.length() && format.charAt(i) == '[') {
                sb.append('[');
                i++;
            } else {
                int close = (i < format.length() ? format.indexOf("]", i) : -1);
                if (close == -1) {
                    XPathException e = new XPathException("Date format contains a '[' with no matching ']'");
                    e.setErrorCode("XTDE1340");
                    e.setXPathContext(context);
                    throw e;
                }
                String componentFormat = format.substring(i, close);
                sb.append(formatComponent(value, Whitespace.removeAllWhitespace(componentFormat),
                        numberer, country, context));
View Full Code Here

        boolean ignoreTime = (value instanceof DateValue);
        DateTimeValue dtvalue = value.toDateTime();

        MatchResult matcher = componentPattern.exec(specifier.toString());
        if (matcher == null) {
            XPathException error = new XPathException("Unrecognized date/time component [" + specifier + ']');
            error.setErrorCode("XTDE1340");
            error.setXPathContext(context);
            throw error;
        }
        String component = matcher.getGroup(1);
        if (component == null) {
            component = "";
        }
        String format = matcher.getGroup(2);
        if (format==null) {
            format = "";
        }
        boolean defaultFormat = false;
        if ("".equals(format) || format.startsWith(",")) {
            defaultFormat = true;
            switch (component.charAt(0) ) {
                case 'F':
                    format = "Nn" + format;
                    break;
                case 'P':
                    format = 'n' + format;
                    break;
                case 'C':
                case 'E':
                    format = 'N' + format;
                    break;
                case 'm':
                case 's':
                    format = "01" + format;
                    break;
                default:
                    format = '1' + format;
            }
        }

        switch (component.charAt(0)) {
        case'Y':       // year
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain a year component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int year = dtvalue.getYear();
                if (year < 0) {
                    year = 1 - year;
                }
                return formatNumber(component, year, format, defaultFormat, numberer, context);
            }
        case'M':       // month
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain a month component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int month = dtvalue.getMonth();
                return formatNumber(component, month, format, defaultFormat, numberer, context);
            }
        case'D':       // day in month
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain a day component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int day = dtvalue.getDay();
                return formatNumber(component, day, format, defaultFormat, numberer, context);
            }
        case'd':       // day in year
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain a day component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int day = DateValue.getDayWithinYear(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay());
                return formatNumber(component, day, format, defaultFormat, numberer, context);
            }
        case'W':       // week of year
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): cannot obtain the week number from an xs:time value");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int week = DateValue.getWeekNumber(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay());
                return formatNumber(component, week, format, defaultFormat, numberer, context);
            }
        case'w':       // week in month
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): cannot obtain the week number from an xs:time value");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int week = DateValue.getWeekNumberWithinMonth(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay());
                return formatNumber(component, week, format, defaultFormat, numberer, context);
            }
        case'H':       // hour in day
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain an hour component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                IntegerValue hour = (IntegerValue)value.getComponent(Component.HOURS);
                return formatNumber(component, (int)hour.intValue(), format, defaultFormat, numberer, context);
            }
        case'h':       // hour in half-day (12 hour clock)
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain an hour component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                IntegerValue hour = (IntegerValue)value.getComponent(Component.HOURS);
                int hr = (int)hour.intValue();
                if (hr > 12) {
                    hr = hr - 12;
                }
                if (hr == 0) {
                    hr = 12;
                }
                return formatNumber(component, hr, format, defaultFormat, numberer, context);
            }
        case'm':       // minutes
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain a minutes component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                IntegerValue min = (IntegerValue)value.getComponent(Component.MINUTES);
                return formatNumber(component, (int)min.intValue(), format, defaultFormat, numberer, context);
            }
        case's':       // seconds
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain a seconds component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                IntegerValue sec = (IntegerValue)value.getComponent(Component.WHOLE_SECONDS);
                return formatNumber(component, (int)sec.intValue(), format, defaultFormat, numberer, context);
            }
        case'f':       // fractional seconds
            // ignore the format
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain a fractional seconds component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int micros = (int)((IntegerValue)value.getComponent(Component.MICROSECONDS)).intValue();
                return formatNumber(component, micros, format, defaultFormat, numberer, context);
            }
        case'Z':       // timezone in +hh:mm format, unless format=N in which case use timezone name
            if (value.hasTimezone()) {
                return getNamedTimeZone(value.toDateTime(), country, format);
            } else {
                return "";
            }
        case'z':       // timezone
            if (value.hasTimezone()) {
                int tz = value.getTimezoneInMinutes();
                FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.TINY);
                fsb.append("GMT");
                if (tz != 0) {
                    CalendarValue.appendTimezone(tz, fsb);
                }
                int comma = format.indexOf(',');
                int min = 0;
                if (comma > 0) {
                    String widths = format.substring(comma);
                    int[] range = getWidths(widths);
                    min = range[0];
                }
                if (min < 6) {
                    if (tz % 60 == 0) {
                        // No minutes component in timezone
                        fsb.setLength(fsb.length() - 3);
                    }
                }
                if (min < fsb.length() - 3) {
                    if (fsb.charAt(4) == '0') {
                        fsb.removeCharAt(4);
                    }
                }
                return fsb;
            } else {
                return "";
            }
        case'F':       // day of week
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain day-of-week component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int day = DateValue.getDayOfWeek(dtvalue.getYear(), dtvalue.getMonth(), dtvalue.getDay());
                return formatNumber(component, day, format, defaultFormat, numberer, context);
            }
        case'P':       // am/pm marker
            if (ignoreTime) {
                XPathException error = new XPathException("In formatDate(): an xs:date value does not contain an am/pm component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int minuteOfDay = dtvalue.getHour() * 60 + dtvalue.getMinute();
                return formatNumber(component, minuteOfDay, format, defaultFormat, numberer, context);
            }
        case'C':       // calendar
            return numberer.getCalendarName("AD");
        case'E':       // era
            if (ignoreDate) {
                XPathException error = new XPathException("In formatTime(): an xs:time value does not contain an AD/BC component");
                error.setErrorCode("XTDE1350");
                error.setXPathContext(context);
                throw error;
            } else {
                int year = dtvalue.getYear();
                return numberer.getEraName(year);
            }
        default:
            XPathException e = new XPathException("Unknown formatDate/time component specifier '" + format.charAt(0) + '\'');
            e.setErrorCode("XTDE1340");
            e.setXPathContext(context);
            throw e;
        }
    }
View Full Code Here

    private static CharSequence formatNumber(String component, int value,
                                             String format, boolean defaultFormat, Numberer numberer, XPathContext context)
    throws XPathException {
        MatchResult matcher = formatPattern.exec(format);
        if (matcher == null) {
            XPathException error = new XPathException("Unrecognized format picture [" + component + format + ']');
            error.setErrorCode("XTDE1340");
            error.setXPathContext(context);
            throw error;
        }
        //String primary = matcher.group(1);
        //String modifier = matcher.group(2);      
        String primary = matcher.getGroup(1);
        if (primary == null) {
            primary = "";
        }

        String modifier = null;
        if (primary.endsWith("t")) {
            primary = primary.substring(0, primary.length()-1);
            modifier = "t";
        } else if (primary.endsWith("o")) {
            primary = primary.substring(0, primary.length()-1);
            modifier = "o";
        }
        String letterValue = ("t".equals(modifier) ? "traditional" : null);
        String ordinal = ("o".equals(modifier) ? numberer.getOrdinalSuffixForDateTime(component) : null);
        String widths = matcher.getGroup(2);
        if (widths == null) {
            widths = "";
        }
        if (!alphanumericPattern.test(primary)) {
            XPathException error = new XPathException("In format picture at '" + primary +
                    "', primary format must be alphanumeric");
            error.setErrorCode("XTDE1340");
            error.setXPathContext(context);
            throw error;
        }
        int min = 1;
        int max = Integer.MAX_VALUE;
       
View Full Code Here

                        max = Integer.MAX_VALUE;
                    } else {
                        max = Integer.parseInt(smax);
                    }
                } else {
                    XPathException error = new XPathException("Unrecognized width specifier " + Err.wrap(widths, Err.VALUE));
                    error.setErrorCode("XTDE1340");
                    throw error;
                }
            }

            if (min>max && max!=-1) {
                XPathException e = new XPathException("Minimum width in date/time picture exceeds maximum width");
                e.setErrorCode("XTDE1340");
                throw e;
            }
            int[] result = new int[2];
            result[0] = min;
            result[1] = max;
            return result;
        } catch (NumberFormatException err) {
            XPathException e = new XPathException("Invalid integer used as width in date/time picture");
            e.setErrorCode("XTDE1340");
            throw e;
        }
    }
View Full Code Here

TOP

Related Classes of client.net.sf.saxon.ce.trans.XPathException

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.