Package info.freelibrary.djatoka.util

Examples of info.freelibrary.djatoka.util.OSDCacheUtil


    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        final String ptfs = myProject.getProperties().getProperty(PAIRTREE_FS);
        final String port = myProject.getProperties().getProperty(JETTY_PORT);
        final OSDCacheUtil tiler = new OSDCacheUtil();

        // Keep track if we started Jetty to load the tiles
        boolean startedJetty = false;

        // Make sure the supplied port number is actually an integer
        try {
            Integer.parseInt(port);
        } catch (final NumberFormatException details) {
            throw new MojoExecutionException(StringUtils.format("Supplied port ({}) must be an integer", port));
        }

        // If server isn't up, start it so we can cache tiles
        if (!serverIsUp(port)) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Starting the FreeLib-Djatoka server to cache derivative image tiles");
            }

            try {
                final String message = "FreeLib-Djatoka server must be running to cache tiles";

                if (Runtime.getRuntime().exec(new String[] { "mvn", "jetty:run-forked" }).waitFor() != 0) {
                    throw new MojoFailureException(message);
                }

                if (!serverIsUp(port)) {
                    throw new MojoFailureException(message);
                }

                startedJetty = true;
            } catch (final Exception details) {
                throw new MojoExecutionException(details.getMessage(), details);
            }
        }

        // Sets the Maven loggers' levels (not the levels of loggers used by this plugin)
        MavenUtils.setLogLevels(MavenUtils.ERROR_LOG_LEVEL, MavenUtils.getMavenLoggers());

        try {
            final PairtreeRoot pairtree = new PairtreeRoot(new File(ptfs));
            final RegexFileFilter filter = new RegexFileFilter(".*");
            final String eol = System.getProperty("line.separator");
            final File[] jp2List = FileUtils.listFiles(pairtree, filter, true);

            int processed = 0;

            if (jp2List.length == 0 && LOGGER.isWarnEnabled()) {
                LOGGER.warn("There are no JP2s in the Pairtree structure");
            }

            for (final File file : jp2List) {
                final String id = PairtreeUtils.decodeID(file.getName());
                final URL url = new URL(StringUtils.format(METADATA_URL, port, id));
                final JsonNode json = MAPPER.readTree(url.openStream());

                // Pull out relevant info from our metadata service
                final int width = json.get("width").asInt();
                final int height = json.get("height").asInt();
                final String[] tilePaths = tiler.getPaths("iiif", id, 256, width, height);

                // If cache is to be overwritten, delete what's there so it will be recreated
                if (myCacheToBeOverwritten) {
                    deletePairtreeImageCache(id);
                }
View Full Code Here

TOP

Related Classes of info.freelibrary.djatoka.util.OSDCacheUtil

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.