Package org.exist.util

Examples of org.exist.util.MimeTable


     * @param directory
     * @param targetCollection
     */
    private void storeFiles(File directory, Collection targetCollection, boolean inRootDir) {
        final File[] files = directory.listFiles();
        final MimeTable mimeTab = MimeTable.getInstance();
        final TransactionManager mgr = broker.getBrokerPool().getTransactionManager();
        for (final File file : files) {
            if (inRootDir && "repo.xml".equals(file.getName()))
                {continue;}
            if (!file.isDirectory()) {
                MimeType mime = mimeTab.getContentTypeFor(file.getName());
                if (mime == null)
                    {mime = MimeType.BINARY_TYPE;}
                final XmldbURI name = XmldbURI.create(file.getName());

                final Txn txn = mgr.beginTransaction();
View Full Code Here


      }
    }

    private void moveResource(DBBroker broker, Txn txn, DocumentImpl doc, Collection source, Collection destination, XmldbURI newName) throws PermissionDeniedException, LockException, IOException, SAXException, EXistException {
       
        final MimeTable mimeTable = MimeTable.getInstance();
       
        final boolean isXML = mimeTable.isXMLContent(newName.toString());
       
        final MimeType mimeType = mimeTable.getContentTypeFor(newName);
       
      if ( mimeType != null && !mimeType.getName().equals( doc.getMetadata().getMimeType()) ) {
            doc.getMetadata().setMimeType(mimeType.getName());
            broker.storeXMLResource(txn, doc);
View Full Code Here

                if(contentTypeEnd == -1) {
                    contentTypeEnd = responseContentType.length();
                }

                final String responseMimeType = responseContentType.substring(0, contentTypeEnd);
                final MimeTable mimeTable = MimeTable.getInstance();
                final MimeType mimeType = mimeTable.getContentType(responseMimeType);

                if(mimeType != null) {
                    returnMimeType = mimeType;
                }
            }
View Full Code Here

        String existHome = System.getProperty("exist.home");
        File existDir = existHome==null ? new File(".") : new File(existHome);
        File samples = new File(existDir,"samples/shakespeare");
        File[] files = samples.listFiles();
        MimeTable mimeTab = MimeTable.getInstance();
        for (int j = 0; j < files.length; j++) {
            MimeType mime = mimeTab.getContentTypeFor(files[j].getName());
            if(mime != null && mime.isXMLType()) {
                Resource resource = collection.createResource(files[j].getName(), "XMLResource");
                resource.setContent(files[j]);
                collection.storeResource(resource);
            }
View Full Code Here

                mgr.addConfiguration(transaction, broker, root, configuration);
            }

            File file = new File(directory);
            File[] files = file.listFiles();
            MimeTable mimeTab = MimeTable.getInstance();
            for (int j = 0; j < files.length; j++) {
                MimeType mime = mimeTab.getContentTypeFor(files[j].getName());
                if(mime != null && mime.isXMLType()) {
                    System.out.println("Storing document " + files[j].getName());
                    InputSource is = new InputSource(files[j].getAbsolutePath());
                    IndexInfo info =
                            root.validateXMLResource(transaction, broker, XmldbURI.create(files[j].getName()), is);
View Full Code Here

                 String existHome = System.getProperty("exist.home");
                 File existDir = existHome==null ? new File(".") : new File(existHome);
            File samples = new File(existDir,"samples/shakespeare");
            File[] files = samples.listFiles();
            MimeTable mimeTab = MimeTable.getInstance();
            for (int j = 0; j < files.length; j++) {
                MimeType mime = mimeTab.getContentTypeFor(files[j].getName());
                if(mime != null && mime.isXMLType())
                    loadFile(test, files[j].getAbsolutePath());
            }

            doQuery(test, "//SPEECH[SPEAKER='HAMLET']");
View Full Code Here

    final String path = new AnyURIValue(args[0].itemAt(0).getStringValue()).toString();
   
    if(path.matches("^[a-z]+://.*")) {
      //external
      final MimeTable mimeTable = MimeTable.getInstance();
      final MimeType mimeType = mimeTable.getContentTypeFor(path);
      if(mimeType != null) {
        return new StringValue(mimeType.getName());
            }
    } else {
      //database
View Full Code Here

    @Override
    public Sequence eval(Sequence args[], Sequence contextSequence) throws XPathException {

        // Get handle to Mime-type info
        final MimeTable mimeTable = MimeTable.getInstance();

        // Get first parameter
        final String pathParameter = new AnyURIValue(args[0].itemAt(0).getStringValue()).toString();

        if (pathParameter.matches("^[a-z]+://.*")) {
            throw new XPathException("Can not set mime-type for resources outside the database.");
        }

        XmldbURI pathUri = null;
        try {
            pathUri = XmldbURI.xmldbUriFor(pathParameter);
        } catch (final URISyntaxException ex) {
            logger.debug(ex.getMessage());
            throw new XPathException("Invalid path '" + pathParameter + "'");
        }

        // Verify mime-type input
        MimeType newMimeType = null;
        if (args[1].isEmpty()) {
            // No input, use default mimetype
            newMimeType = mimeTable.getContentTypeFor(pathParameter);

            if (newMimeType == null) {
                throw new XPathException("Unable to determine mimetype for '" + pathParameter + "'");
            }

        } else {
            // Mimetype is provided, check if valid
            newMimeType = mimeTable.getContentType(args[1].getStringValue());

            if (newMimeType == null) {
                throw new XPathException("mime-type '" + args[1].getStringValue() + "' is not supported.");
            }
        }

        // Get mime-type of resource
        MimeType currentMimeType = getMimeTypeStoredResource(pathUri);
        if (currentMimeType == null) {
            // stored resource has no mime-type (unexpected situation)
            // fall back to document name
            logger.debug("Resource '" + pathUri + "' has no mime-type, retrieve from document name.");
            currentMimeType = mimeTable.getContentTypeFor(pathUri);
           
            // if extension based lookup still fails
            if (currentMimeType == null) {
                throw new XPathException("Unable to determine mime-type from path '" + pathUri + "'.");
            }           
View Full Code Here

TOP

Related Classes of org.exist.util.MimeTable

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.