Package org.exist.xquery

Examples of org.exist.xquery.XPathException


        URI uri;
        try {
            uri = new URI(namespace);
        }
        catch (final URISyntaxException ex) {
            throw new XPathException("Invalid URI: " + namespace, ex);
        }
        for (final Packages pp : myParent.listPackages()) {
            final Package pkg = pp.latest();
            final ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
            if (info != null) {
View Full Code Here


        try {
            final Class clazz = Class.forName(name);
            final Module module = instantiateModule(clazz);
            final String ns = module.getNamespaceURI();
            if (!ns.equals(namespace)) {
                throw new XPathException("The namespace in the Java module " +
                    "does not match the namespace in the package descriptor: " +
                    namespace + " - " + ns);
            }
            return ctxt.loadBuiltInModule(namespace, name);
        } catch ( final ClassNotFoundException ex ) {
            throw new XPathException("Cannot find module class from EXPath repository: " + name, ex);
        } catch ( final InstantiationException ex ) {
            throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
        } catch ( final IllegalAccessException ex ) {
            throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
        } catch ( final InvocationTargetException ex ) {
            throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
        } catch ( final ClassCastException ex ) {
            throw new XPathException("The class configured in EXPath repository is not a Module: " + name, ex);
        } catch ( final IllegalArgumentException ex ) {
            throw new XPathException("Illegal argument passed to the module ctor", ex);
        }
    }
View Full Code Here

            try {
                final Constructor ctor = clazz.getConstructor();
                return (Module) ctor.newInstance();
            }
            catch (final NoSuchMethodException exx) {
                throw new XPathException("Cannot find suitable constructor " +
                    "for module from expath repository", exx);
            }
        }
    }
View Full Code Here

        // the URI
        URI uri;
        try {
            uri = new URI(namespace);
        } catch (final URISyntaxException ex) {
            throw new XPathException("Invalid URI: " + namespace, ex);
        }
        for (final Packages pp : myParent.listPackages()) {
            final Package pkg = pp.latest();
            // FIXME: Rely on having a file system storage, that's probably a bad design!
            final FileSystemResolver resolver = (FileSystemResolver) pkg.getResolver();
            final ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
            if (info != null) {
                final String f = info.getXQuery(uri);
                if (f != null) {
                    return resolver.resolveComponentAsFile(f);
                }
            }
            String sysid = null; // declared here to be used in catch
            try {
                final StreamSource src = pkg.resolve(namespace, URISpace.XQUERY);
                if (src != null) {
                    sysid = src.getSystemId();
                    return new File(new URI(sysid));
                }
            } catch (final URISyntaxException ex) {
                throw new XPathException("Error parsing the URI of the query library: " + sysid, ex);
            } catch (final PackageException ex) {
                throw new XPathException("Error resolving the query library: " + namespace, ex);
            }
        }
        return null;
    }
View Full Code Here

  public DateTimeValue(String dateTime) throws XPathException {
    super(dateTime);
    try {
      if (calendar.getXMLSchemaType() != DatatypeConstants.DATETIME) {throw new IllegalStateException();}
    } catch (final IllegalStateException e) {
      throw new XPathException("xs:dateTime instance must have all fields set");
    }
    normalize();
  }
View Full Code Here

      case Type.STRING :
        return new StringValue(getStringValue());
      case Type.UNTYPED_ATOMIC :
        return new UntypedAtomicValue(getStringValue());       
      default :
        throw new XPathException(
          "Type error: cannot cast xs:dateTime to "
            + Type.getTypeName(requiredType));
    }
  }
View Full Code Here

      case Type.YEAR_MONTH_DURATION:
        return ((YearMonthDurationValue) other).negate().plus(this);
      case Type.DAY_TIME_DURATION:
        return ((DayTimeDurationValue) other).negate().plus(this);
      default:
        throw new XPathException(
            "Operand to minus should be of type xs:dateTime, xdt:dayTimeDuration or xdt:yearMonthDuration; got: "
              + Type.getTypeName(other.getType()));
    }
  }
View Full Code Here

    }

    public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathException
    {
        if(!context.getEffectiveUser().hasDbaRole()) {
            throw new XPathException("You must be a DBA to retrieve a backup");
        }

        final String exportDir = args[0].getStringValue();
        File   dir       = new File( exportDir );

        if( !dir.isAbsolute() ) {
            dir = new File( (String)context.getBroker().getConfiguration().getProperty( BrokerPool.PROPERTY_DATA_DIR ), exportDir );
        }
        final String name       = args[1].getStringValue();
        final File   backupFile = new File( dir, name );

        if( !backupFile.canRead() ) {
            return( Sequence.EMPTY_SEQUENCE );
        }

        if( !name.endsWith( ".zip" ) ) {
            throw( new XPathException( this, "for security reasons, the function only allows " + "reading zipped backup archives" ) );
        }

        try {
            final ZipArchiveBackupDescriptor descriptor = new ZipArchiveBackupDescriptor( backupFile );
            final Properties                 properties = descriptor.getProperties();

            if( ( properties == null ) || ( properties.size() == 0 ) ) {
                throw( new XPathException( this, "the file does not see to be a valid backup archive" ) );
            }
        }
        catch( final IOException e ) {
            throw( new XPathException( this, "the file does not see to be a valid backup archive" ) );
        }

        // directly stream the backup contents to the HTTP response
        final ResponseModule myModule = (ResponseModule)context.getModule( ResponseModule.NAMESPACE_URI );

        // response object is read from global variable $response
        final Variable       respVar  = myModule.resolveVariable( ResponseModule.RESPONSE_VAR );

        if( respVar == null ) {
            throw( new XPathException( this, "No response object found in the current XQuery context." ) );
        }

        if( respVar.getValue().getItemType() != Type.JAVA_OBJECT ) {
            throw( new XPathException( this, "Variable $response is not bound to an Java object." ) );
        }
        final JavaObjectValue respValue = (JavaObjectValue)respVar.getValue().itemAt( 0 );

        if( !"org.exist.http.servlets.HttpResponseWrapper".equals( respValue.getObject().getClass().getName() ) ) {
            throw( new XPathException( this, signature.toString() + " can only be used within the EXistServlet or XQueryServlet" ) );
        }
        final ResponseWrapper response = (ResponseWrapper)respValue.getObject();

        response.setContentType( "application/zip" );
        response.setHeader("Content-Length", String.valueOf(backupFile.length()));
        try {
            final InputStream  is  = new FileInputStream( backupFile );
            final OutputStream os  = response.getOutputStream();
            final byte[]       buf = new byte[4096];
            int          c;

            while( ( c = is.read( buf ) ) > -1 ) {
                os.write( buf, 0, c );
            }
            is.close();
            os.close();
            response.flushBuffer();
        }
        catch( final IOException e ) {
            throw( new XPathException( this, "An IO error occurred while reading the backup archive" ) );
        }
        return( Sequence.EMPTY_SEQUENCE );
    }
View Full Code Here

            uri = uri.substring("java:".length());
            try {
                final Class<?> collatorClass = Class.forName(uri);
                if (!Collator.class.isAssignableFrom(collatorClass)) {
                    logger.error("The specified collator class is not a subclass of java.text.Collator");
                    throw new XPathException(
                            "The specified collator class is not a subclass of java.text.Collator");
                }
                return (Collator) collatorClass.newInstance();
            } catch (final Exception e) {
                logger.error("The specified collator class " + uri + " could not be found");
                throw new XPathException(
                        ErrorCodes.FOCH0002,
                        "The specified collator class " + uri + " could not be found", e);
            }
        } else if (CODEPOINT.equals(uri)) {
          return null;
        } else {
            logger.error("Unknown collation : '" + uri + "'");
            throw new XPathException(ErrorCodes.FOCH0002, "Unknown collation : '" + uri + "'");
        }
    }
View Full Code Here

            else if (strength.length() == 0 || "identical".equals(strength))
                // the default setting
                {collator.setStrength(Collator.IDENTICAL);}
            else {
                logger.error("Collation strength should be either 'primary', 'secondary', 'tertiary' or 'identical");
                throw new XPathException(
                        "Collation strength should be either 'primary', 'secondary', 'tertiary' or 'identical");

            }

        }

        if (decomposition != null) {
            if ("none".equals(decomposition))
                {collator.setDecomposition(Collator.NO_DECOMPOSITION);}
            else if ("full".equals(decomposition))
                {collator.setDecomposition(Collator.FULL_DECOMPOSITION);}
            else if (decomposition.length() == 0
                    || "standard".equals(decomposition))
                // the default setting
                {collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);}
            else {
                logger.error("Collation decomposition should be either 'none', 'full' or 'standard");
                throw new XPathException(
                        "Collation decomposition should be either 'none', 'full' or 'standard");
            }

        }
View Full Code Here

TOP

Related Classes of org.exist.xquery.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.