Search in sources :

Example 1 with DocuImage

use of digilib.image.DocuImage 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 DocuImage

use of digilib.image.DocuImage in project digilib by robcast.

the class PDFStreamWorker method addImage.

/**
 * adds an image to the document.
 *
 * @param doc
 * @param iji
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws IOException
 * @throws DocumentException
 */
public Document addImage(Document doc, ImageJobDescription iji) throws InterruptedException, ExecutionException, IOException, DocumentException {
    // create image worker
    ImageWorker job = new ImageWorker(dlConfig, iji);
    // submit
    Future<DocuImage> jobTicket = imageJobCenter.submit(job);
    // wait for result
    DocuImage img = jobTicket.get();
    // scale the image
    Image pdfimg = Image.getInstance(img.getAwtImage(), null);
    float docW = PageSize.A4.getWidth() - 2 * PageSize.A4.getBorder();
    float docH = PageSize.A4.getHeight() - 2 * PageSize.A4.getBorder();
    // fit the image to the page
    pdfimg.scaleToFit(docW, docH);
    // add to PDF
    doc.add(pdfimg);
    return doc;
}
Also used : ImageWorker(digilib.image.ImageWorker) DocuImage(digilib.image.DocuImage) DocuImage(digilib.image.DocuImage) Image(com.itextpdf.text.Image)

Example 3 with DocuImage

use of digilib.image.DocuImage in project digilib by robcast.

the class PDFCache method init.

@SuppressWarnings("unchecked")
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    System.out.println("***** Digital Image Library Image PDF-Cache Servlet (version " + version + ") *****");
    // say hello in the log file
    logger.info("***** Digital Image Library Image PDF-Cache Servlet (version " + version + ") *****");
    ServletContext context = getServletContext();
    dlConfig = PDFServletConfiguration.getCurrentConfig(context);
    if (dlConfig == null) {
        // no Configuration
        throw new ServletException("No Configuration!");
    }
    workDir = dlConfig.getAsFile(PDFServletConfiguration.PDF_WORKDIR_KEY);
    cacheDir = dlConfig.getAsFile(PDFServletConfiguration.PDF_CACHEDIR_KEY);
    if (!workDir.isDirectory()) {
        throw new ServletException("Configuration error: problem with pdf-temp-dir=" + workDir);
    }
    if (!cacheDir.isDirectory()) {
        throw new ServletException("Configuration error: problem with pdf-cache-dir=" + cacheDir);
    }
    pdfJobCenter = (DigilibJobCenter<File>) dlConfig.getValue(PDFServletConfiguration.PDF_EXECUTOR_KEY);
    pdfImageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig.getValue(PDFServletConfiguration.PDF_IMAGEEXECUTOR_KEY);
    // register this instance globally
    context.setAttribute(instanceKey, this);
}
Also used : ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) DocuImage(digilib.image.DocuImage) File(java.io.File)

Example 4 with DocuImage

use of digilib.image.DocuImage in project digilib by robcast.

the class Scaler method init.

/**
 * Initialisation on first run.
 *
 * @throws ServletException
 *
 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
 */
@SuppressWarnings("unchecked")
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    System.out.println("***** Digital Image Library Image Scaler Servlet (version " + version + ") *****");
    // say hello in the log file
    logger.info("***** Digital Image Library Image Scaler Servlet (version " + version + ") *****");
    // get our ServletContext
    ServletContext context = config.getServletContext();
    // see if there is a Configuration instance
    dlConfig = DigilibServlet3Configuration.getCurrentConfig(context);
    if (dlConfig == null) {
        // no Configuration
        throw new ServletException("No Configuration!");
    }
    // log DocuImage version
    logger.info("Scaler uses " + dlConfig.getValue("servlet.docuimage.version"));
    // set our AuthOps
    useAuthorization = dlConfig.getAsBoolean("use-authorization");
    authzOp = (AuthzOps) dlConfig.getValue(DigilibServletConfiguration.AUTHZ_OP_KEY);
    // DocuDirCache instance
    dirCache = (DocuDirCache) dlConfig.getValue(DigilibServletConfiguration.DIR_CACHE_KEY);
    // Executor
    imageJobCenter = (DigilibJobCenter<DocuImage>) dlConfig.getValue("servlet.worker.imageexecutor");
    // configure ServletOps
    ServletOps.setDlConfig(dlConfig);
    denyImgFile = ServletOps.getFile(dlConfig.getAsFile("denied-image"), context);
    errorImgFile = ServletOps.getFile(dlConfig.getAsFile("error-image"), context);
    notfoundImgFile = ServletOps.getFile(dlConfig.getAsFile("notfound-image"), context);
    sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed");
    try {
        defaultErrMsgType = ErrMsg.valueOf(dlConfig.getAsString("default-errmsg-type"));
    } catch (Exception e) {
    // nothing to do
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) DocuImage(digilib.image.DocuImage) ImageOpException(digilib.image.ImageOpException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AuthOpException(digilib.auth.AuthOpException)

Example 5 with DocuImage

use of digilib.image.DocuImage in project digilib by robcast.

the class DigilibServletConfiguration method contextDestroyed.

/**
 * Clean up local resources
 */
public void contextDestroyed(ServletContextEvent cte) {
    logger.info("DigilibServletConfiguration shutting down.");
    // get current config from servlet context
    ServletContext context = cte.getServletContext();
    DigilibServletConfiguration config = getContextConfig(context);
    @SuppressWarnings("unchecked") DigilibJobCenter<DocuImage> imageExecutor = (DigilibJobCenter<DocuImage>) config.getValue(IMAGEEXECUTOR_KEY);
    if (imageExecutor != null) {
        // shut down image thread pool
        List<Runnable> rj = imageExecutor.shutdownNow();
        int nrj = rj.size();
        if (nrj > 0) {
            logger.error("Still running threads when shutting down image job queue: " + nrj);
        }
    }
}
Also used : ServletContext(javax.servlet.ServletContext) DocuImage(digilib.image.DocuImage) DigilibJobCenter(digilib.util.DigilibJobCenter)

Aggregations

DocuImage (digilib.image.DocuImage)11 IOException (java.io.IOException)5 DigilibJobCenter (digilib.util.DigilibJobCenter)4 ServletContext (javax.servlet.ServletContext)4 ServletException (javax.servlet.ServletException)4 ImageOpException (digilib.image.ImageOpException)3 File (java.io.File)3 AuthOpException (digilib.auth.AuthOpException)2 ImageWorker (digilib.image.ImageWorker)2 Image (com.itextpdf.text.Image)1 AuthnOps (digilib.auth.AuthnOps)1 AuthzOps (digilib.auth.AuthzOps)1 DigilibServletRequest (digilib.conf.DigilibServletRequest)1 ImageJobDescription (digilib.image.ImageJobDescription)1 AliasingDocuDirCache (digilib.io.AliasingDocuDirCache)1 DocuDirCache (digilib.io.DocuDirCache)1 DocuDirectory (digilib.io.DocuDirectory)1 FileClass (digilib.io.FileOps.FileClass)1 ImageInput (digilib.io.ImageInput)1 DirMeta (digilib.meta.DirMeta)1