Search in sources :

Example 1 with DocuDirectory

use of digilib.io.DocuDirectory in project digilib by robcast.

the class DigilibServletConfiguration method configure.

/*
     * (non-Javadoc)
     * 
     * @see digilib.conf.DigilibConfiguration#configure()
     */
@SuppressWarnings("unchecked")
public void configure(ServletContext context) {
    DigilibServletConfiguration config = this;
    super.configure();
    /*
         * configure factories
         */
    try {
        // initialise MetaFactory
        Class<FileMeta> fileMetaClass = (Class<FileMeta>) Class.forName(config.getAsString("filemeta-class"));
        config.setValue("servlet.filemeta.class", fileMetaClass);
        MetaFactory.setFileMetaClass(fileMetaClass);
        Class<DirMeta> dirMetaClass = (Class<DirMeta>) Class.forName(config.getAsString("dirmeta-class"));
        config.setValue("servlet.dirmeta.class", dirMetaClass);
        MetaFactory.setDirMetaClass(dirMetaClass);
    } catch (ClassNotFoundException e) {
        logger.error("Error setting Metadata classes!");
    }
    if (config.getAsBoolean("use-authorization")) {
        try {
            // initialise AuthnOpsFactory
            Class<AuthnOps> authnOpsClass = (Class<AuthnOps>) Class.forName(config.getAsString("authnops-class"));
            config.setValue("servlet.authnops.class", authnOpsClass);
            AuthnOpsFactory.setAuthnOpsClass(authnOpsClass);
        } catch (ClassNotFoundException e) {
            logger.error("Error setting AuthnOps class!");
        }
        try {
            // initialise AuthzOpsFactory
            Class<AuthzOps> authzOpsClass = (Class<AuthzOps>) Class.forName(config.getAsString("authzops-class"));
            config.setValue("servlet.authzops.class", authzOpsClass);
            AuthzOpsFactory.setAuthzOpsClass(authzOpsClass);
        } catch (ClassNotFoundException e) {
            logger.error("Error setting AuthzOps class!");
        }
    }
    try {
        // initialise DocuDirectoryFactory
        Class<DocuDirectory> docuDirectoryClass = (Class<DocuDirectory>) Class.forName(config.getAsString("docudirectory-class"));
        config.setValue("servlet.docudirectory.class", docuDirectoryClass);
        DocuDirectoryFactory.setDocuDirectoryClass(docuDirectoryClass);
        DocuDirectoryFactory.setDigilibConfig(this);
    } catch (ClassNotFoundException e) {
        logger.error("Error setting DocuDirectory class!");
    }
    /*
         * configure singletons
         */
    // set up the logger
    File logConf = ServletOps.getConfigFile((File) config.getValue("log-config-file"), context);
    if (logConf != null && logConf.canRead()) {
        DOMConfigurator.configure(logConf.getAbsolutePath());
        config.setValue("log-config-file", logConf);
    }
    // say hello in the log file
    logger.info("***** Digital Image Library Configuration (version " + getVersion() + ") *****");
    try {
        // directory cache
        DocuDirCache dirCache;
        if (config.getAsBoolean("use-mapping")) {
            // with mapping file
            File mapConf = ServletOps.getConfigFile((File) config.getValue("mapping-file"), context);
            dirCache = new AliasingDocuDirCache(FileClass.IMAGE, mapConf, config);
            config.setValue("mapping-file", mapConf);
        } else {
            // without mapping
            dirCache = new DocuDirCache(FileClass.IMAGE, this);
        }
        config.setValue(DIR_CACHE_KEY, dirCache);
        // useAuthorization
        if (config.getAsBoolean("use-authorization")) {
            // set auth config file
            File authConf = ServletOps.getConfigFile((File) config.getValue("auth-file"), context);
            config.setValue("auth-file", authConf);
            // initialise AuthnOps
            AuthnOps authnOps = AuthnOpsFactory.getAuthnOpsInstance();
            authnOps.init(this);
            config.setValue(AUTHN_OP_KEY, authnOps);
            // initialise AuthzOps (requires AuthnOps)
            AuthzOps authzOps = AuthzOpsFactory.getAuthzOpsInstance();
            authzOps.init(this);
            config.setValue(AUTHZ_OP_KEY, authzOps);
        }
        // digilib worker threads
        int nt = config.getAsInt("worker-threads");
        int mt = config.getAsInt("max-waiting-threads");
        DigilibJobCenter<DocuImage> imageExecutor = new DigilibJobCenter<DocuImage>(nt, mt, false, IMAGEEXECUTOR_KEY);
        config.setValue(IMAGEEXECUTOR_KEY, imageExecutor);
        /*
             * set as the servlets main config
             */
        setContextConfig(context);
    } catch (Exception e) {
        logger.error("Error configuring digilib servlet:", e);
    }
}
Also used : AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) AuthnOps(digilib.auth.AuthnOps) AuthzOps(digilib.auth.AuthzOps) DocuImage(digilib.image.DocuImage) DigilibJobCenter(digilib.util.DigilibJobCenter) DirMeta(digilib.meta.DirMeta) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) DocuDirectory(digilib.io.DocuDirectory) AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) DocuDirCache(digilib.io.DocuDirCache) FileClass(digilib.io.FileOps.FileClass) File(java.io.File) FileMeta(digilib.meta.FileMeta)

Example 2 with DocuDirectory

use of digilib.io.DocuDirectory in project digilib by robcast.

the class ScalerNoThread method getLastModified.

/**
 * Returns modification time relevant to the request for caching.
 *
 * @see javax.servlet.http.HttpServlet#getLastModified(javax.servlet.http.HttpServletRequest)
 */
public long getLastModified(HttpServletRequest request) {
    accountlog.debug("GetLastModified from " + request.getRemoteAddr() + " for " + request.getQueryString());
    long mtime = -1;
    // create new request
    DigilibServletRequest dlReq = new DigilibServletRequest(request, dlConfig);
    DocuDirectory dd = dirCache.getDirectory(dlReq.getFilePath());
    if (dd != null) {
        mtime = dd.getDirMTime() / 1000 * 1000;
    }
    logger.debug("  returns " + mtime);
    return mtime;
}
Also used : DigilibServletRequest(digilib.conf.DigilibServletRequest) DocuDirectory(digilib.io.DocuDirectory)

Example 3 with DocuDirectory

use of digilib.io.DocuDirectory in project digilib by robcast.

the class IndexMetaDirMeta method readParentMeta.

/**
 * Read metadata from all known parent directories.
 * @param dir
 */
public void readParentMeta(DocuDirectory dir) {
    // check the parent directories for additional file meta
    Directory pd = dir.getParent();
    String path = dir.getDir().getName();
    while (pd != null) {
        DocuDirectory dd = (DocuDirectory) pd;
        dd.checkMeta();
        IndexMetaDirMeta dm = (IndexMetaDirMeta) dd.getMeta();
        if (dm.hasUnresolvedFileMeta()) {
            readFileMeta(dir, dm.getUnresolvedFileMeta(), path);
        }
        // prepend parent dir path
        path = pd.getDir().getName() + "/" + path;
        // become next parent
        pd = pd.getParent();
    }
}
Also used : DocuDirectory(digilib.io.DocuDirectory) DocuDirectory(digilib.io.DocuDirectory) Directory(digilib.io.Directory)

Example 4 with DocuDirectory

use of digilib.io.DocuDirectory in project digilib by robcast.

the class IndexMetaFileMeta method checkMeta.

@Override
public void checkMeta(DocuDirent file) {
    if (metaChecked)
        return;
    if (fileMeta == null) {
        // try to read metadata file
        readMeta(file);
        if (fileMeta == null) {
            // try directory metadata
            DocuDirectory dd = (DocuDirectory) file.getParent();
            // running checkmeta also distributes meta to files
            dd.checkMeta();
            if (fileMeta == null) {
                if (dd.getMeta().getDirMeta() != null) {
                    fileMeta = dd.getMeta().getDirMeta();
                } else {
                    // try parent directory metadata (just one level up)
                    DocuDirectory pdd = (DocuDirectory) dd.getParent();
                    if (pdd != null) {
                        pdd.checkMeta();
                        if (fileMeta == null) {
                            fileMeta = pdd.getMeta().getDirMeta();
                        }
                    }
                }
            }
        }
    }
    metaChecked = true;
}
Also used : DocuDirectory(digilib.io.DocuDirectory)

Example 5 with DocuDirectory

use of digilib.io.DocuDirectory in project digilib by robcast.

the class DocumentBean method getNumPages.

/**
 * get the number of image pages/files in the directory
 */
public int getNumPages(DigilibServletRequest request) throws Exception {
    logger.debug("getNumPages");
    DocuDirectory dd = (dirCache != null) ? dirCache.getDirectory(request.getFilePath()) : null;
    if (dd != null) {
        return dd.size();
    }
    return 0;
}
Also used : DocuDirectory(digilib.io.DocuDirectory)

Aggregations

DocuDirectory (digilib.io.DocuDirectory)10 DigilibServletRequest (digilib.conf.DigilibServletRequest)4 IOException (java.io.IOException)4 AuthOpException (digilib.auth.AuthOpException)3 ImageOpException (digilib.image.ImageOpException)3 File (java.io.File)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 AuthnOps (digilib.auth.AuthnOps)1 AuthzOps (digilib.auth.AuthzOps)1 DocuImage (digilib.image.DocuImage)1 ImageJobDescription (digilib.image.ImageJobDescription)1 AliasingDocuDirCache (digilib.io.AliasingDocuDirCache)1 Directory (digilib.io.Directory)1 DocuDirCache (digilib.io.DocuDirCache)1 FileClass (digilib.io.FileOps.FileClass)1 ImageInput (digilib.io.ImageInput)1 ImageSet (digilib.io.ImageSet)1 DirMeta (digilib.meta.DirMeta)1 FileMeta (digilib.meta.FileMeta)1