Search in sources :

Example 11 with FileOpException

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

the class JAIDocuImage method identify.

/* Check image size and type and store in ImageFile f */
public ImageInput identify(ImageInput input) throws IOException {
    this.input = input;
    // try parent method first
    ImageInput imf = super.identify(input);
    if (imf != null) {
        return imf;
    }
    /*
		 * try JAI
		 */
    logger.debug("identifying (JAI) " + input);
    try {
        RenderedOp img = null;
        if (input.hasFile()) {
            String t = FileOps.mimeForFile(input.getFile());
            input.setMimetype(t);
            img = JAI.create("fileload", input.getFile().getAbsolutePath());
        } else if (input.hasInputStream()) {
            img = JAI.create("stream", input.getInputStream());
        // FIXME: where do we get the mimetype?
        } else {
            throw new FileOpException("unable to get data for image!");
        }
        ImageSize d = new ImageSize(img.getWidth(), img.getHeight());
        input.setSize(d);
        logger.debug("image size: " + d);
        return input;
    } catch (Exception e) {
        throw new FileOpException("ERROR: unable to identify image!");
    }
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ImageInput(digilib.io.ImageInput) ImageSize(digilib.util.ImageSize) FileOpException(digilib.io.FileOpException) IOException(java.io.IOException) FileOpException(digilib.io.FileOpException)

Example 12 with FileOpException

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

the class JAIImageLoaderDocuImage method getReader.

/* Get an ImageReader for the image file. */
public ImageReader getReader(ImageInput input) throws IOException {
    logger.debug("get ImageReader for " + input);
    if (this.reader != null) {
        if (this.input == input) {
            // it was the same input
            logger.debug("reusing Reader");
            return reader;
        }
        // clean up old reader
        logger.debug("cleaning Reader!");
        dispose();
    }
    this.input = input;
    ImageInputStream istream = null;
    if (input.hasImageInputStream()) {
        // stream input
        istream = input.getImageInputStream();
    } else if (input.hasFile()) {
        // file only input
        RandomAccessFile rf = new RandomAccessFile(input.getFile(), "r");
        istream = new FileImageInputStream(rf);
    } else {
        throw new FileOpException("Unable to get data from ImageInput");
    }
    Iterator<ImageReader> readers;
    String mt = input.getMimetype();
    if (mt == null) {
        logger.debug("No mime-type. Trying automagic.");
        readers = ImageIO.getImageReaders(istream);
    } else {
        logger.debug("File type:" + mt);
        readers = ImageIO.getImageReadersByMIMEType(mt);
    }
    if (!readers.hasNext()) {
        throw new FileOpException("Can't find Reader to load File!");
    }
    reader = readers.next();
    logger.debug("ImageIO: this reader: " + reader.getClass());
    /* are there more readers? */
    /* while (readers.hasNext()) {
            logger.debug("ImageIO: next reader: " + readers.next().getClass());
        } */
    reader.setInput(istream);
    return reader;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) RandomAccessFile(java.io.RandomAccessFile) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) FileOpException(digilib.io.FileOpException) ImageReader(javax.imageio.ImageReader)

Example 13 with FileOpException

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

the class JAIImageLoaderDocuImage method loadSubimage.

/* Load an image file into the Object. */
public void loadSubimage(ImageInput ii, Rectangle region, int prescale) throws FileOpException {
    logger.debug("loadSubimage: " + ii.getFile());
    // System.gc();
    try {
        if ((reader == null) || (imgFile != ii.getFile())) {
            getReader(ii);
        }
        ImageReadParam readParam = reader.getDefaultReadParam();
        readParam.setSourceRegion(region);
        readParam.setSourceSubsampling(prescale, prescale, 0, 0);
        img = reader.read(0, readParam);
    /* JAI imageread seems to ignore the readParam :-(
			ImageInputStream istream = (ImageInputStream) reader.getInput();
			ParameterBlockJAI pb = new ParameterBlockJAI("imageread");
			pb.setParameter("Input", istream);
			pb.setParameter("ReadParam", readParam);
			pb.setParameter("Reader", reader);
			img = JAI.create("imageread", pb);
			*/
    } catch (IOException e) {
        throw new FileOpException("Unable to load File!");
    }
    if (img == null) {
        throw new FileOpException("Unable to load File!");
    }
    imgFile = ii.getFile();
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) FileOpException(digilib.io.FileOpException) IOException(java.io.IOException)

Example 14 with FileOpException

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

the class PDFTitlePage method getInfoXmlReader.

/**
 * @param pdfji
 * @return
 */
protected DigilibInfoReader getInfoXmlReader(PDFRequest pdfji) {
    try {
        // try to load ../presentation/info.xml
        File imgDir = pdfji.getImageJobInformation().getFileDirectory().getDir();
        File docDir = imgDir.getParentFile();
        File infoFn = new File(new File(docDir, "presentation"), "info.xml");
        return new DigilibInfoReader(infoFn.getAbsolutePath());
    } catch (FileOpException e) {
        logger.warn("info.xml not found");
    } catch (IOException e) {
        logger.warn("image directory for info.xml not found");
    } catch (ImageOpException e) {
        logger.warn("problem with parameters for info.xml");
    }
    return null;
}
Also used : ImageOpException(digilib.image.ImageOpException) FileOpException(digilib.io.FileOpException) IOException(java.io.IOException) File(java.io.File)

Example 15 with FileOpException

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

the class MetaAccessAuthzOps method rolesForPath.

/**
 * Return authorization roles needed for request.
 *
 * Returns the list of authorization roles that are needed to access the
 * specified path. No list means the path is free.
 *
 * The location information of the request is also considered.
 *
 * @param request
 *            ServletRequest with address information.
 * @throws AuthOpException
 *             Exception thrown on error.
 * @return List of Strings with role names.
 */
@Override
public List<String> rolesForPath(DigilibServletRequest dlRequest) throws AuthOpException {
    DocuDirent imgs;
    try {
        // try to get image file from JobDescription
        ImageJobDescription ticket = dlRequest.getJobDescription();
        if (ticket != null) {
            imgs = (DocuDirent) ticket.getImageSet();
        } else {
            // try to get image file from DirCache
            DigilibConfiguration config = dlRequest.getDigilibConfig();
            DocuDirCache cache = (DocuDirCache) config.getValue(DigilibServletConfiguration.DIR_CACHE_KEY);
            imgs = cache.getFile(dlRequest.getFilePath(), dlRequest.getAsInt("pn"));
        }
    } catch (FileOpException e) {
        throw new AuthOpException("No file for auth check!");
    }
    /*
         * get access restrictions from metadata
         */
    String access = null;
    try {
        imgs.checkMeta();
        MetadataMap meta = imgs.getMeta().getFileMeta();
        if (meta != null) {
            access = meta.get("access");
        }
    } catch (Exception e) {
        logger.error("Error getting access meta for file!");
    }
    if (access == null) {
        // no access tag - use default
        logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(default)");
        return defaultRoles;
    } else if (access.equalsIgnoreCase("free")) {
        // access free
        logger.debug("Roles required for " + imgs.getName() + ": (free)");
        return null;
    }
    // get required roles
    if (rolesMap.containsKey(access)) {
        List<String> required = rolesMap.get(access);
        logger.debug("Roles required for " + imgs.getName() + ": " + required);
        return required;
    } else {
        // no mapping to role
        logger.error("Error: no role for access type '" + access + "'");
        // use default
        logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(substituted default)");
        return defaultRoles;
    }
}
Also used : MetadataMap(digilib.meta.MetadataMap) ImageJobDescription(digilib.image.ImageJobDescription) DigilibConfiguration(digilib.conf.DigilibConfiguration) FileOpException(digilib.io.FileOpException) DocuDirent(digilib.io.DocuDirent) DocuDirCache(digilib.io.DocuDirCache) FileOpException(digilib.io.FileOpException)

Aggregations

FileOpException (digilib.io.FileOpException)18 IOException (java.io.IOException)10 ImageInput (digilib.io.ImageInput)4 ImageSize (digilib.util.ImageSize)3 ParameterBlock (java.awt.image.renderable.ParameterBlock)3 File (java.io.File)3 ImageSet (digilib.io.ImageSet)2 BufferedImage (java.awt.image.BufferedImage)2 FileInputStream (java.io.FileInputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 ImageReadParam (javax.imageio.ImageReadParam)2 ImageReader (javax.imageio.ImageReader)2 FileImageInputStream (javax.imageio.stream.FileImageInputStream)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 FormatException (loci.formats.FormatException)2 DigilibConfiguration (digilib.conf.DigilibConfiguration)1 ImageJobDescription (digilib.image.ImageJobDescription)1 ImageOpException (digilib.image.ImageOpException)1 DocuDirCache (digilib.io.DocuDirCache)1 DocuDirent (digilib.io.DocuDirent)1