Package org.mapfish.print

Examples of org.mapfish.print.MapPrinter


            @RequestParam(value = "url", defaultValue = "") final String baseUrl,
            @RequestParam(value = "var", defaultValue = "") final String jsonpVar,
            final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {

        final MapPrinter printer;
        try {
            printer = this.printerFactory.create(DEFAULT_CONFIGURATION_FILE_KEY);
        } catch (NoSuchAppException e) {
            error(resp, e.getMessage(), HttpStatus.NOT_FOUND);
            return;
View Full Code Here


        if (specJson.has("app")) {
            appId = specJson.getString("app");
        } else {
            appId = DEFAULT_CONFIGURATION_FILE_KEY;
        }
        MapPrinter mapPrinter = this.printerFactory.create(appId);
        PJsonObject updatedSpecJson = null;
        try {
            updatedSpecJson = OldAPIRequestConverter.convert(specJson, mapPrinter.getConfiguration());

            String format = updatedSpecJson.optString(MapPrinterServlet.JSON_OUTPUT_FORMAT, "pdf");
            final String jobReferenceId = this.primaryApiServlet.createAndSubmitPrintJob(appId, format,
                    updatedSpecJson.getInternalObj().toString(), httpServletRequest,
                    httpServletResponse);
View Full Code Here

    @Override
    public final PrintJobStatus call() throws Exception {
        SecurityContextHolder.setContext(this.securityContext);
        Timer.Context timer = this.metricRegistry.timer(getClass().getName() + " call()").time();
        PJsonObject spec = null;
        MapPrinter mapPrinter = null;
        try {
            spec = PrintJob.this.requestData;
            mapPrinter = PrintJob.this.mapPrinterFactory.create(getAppId());
            final MapPrinter finalMapPrinter = mapPrinter;
            URI reportURI = withOpenOutputStream(new PrintAction() {
                @Override
                public void run(final OutputStream outputStream) throws Throwable {
                    finalMapPrinter.print(PrintJob.this.requestData, outputStream);
                }
            });

            this.metricRegistry.counter(getClass().getName() + "success").inc();
            LOGGER.debug("Successfully completed print job" + this.referenceId + "\n" + this.requestData);
View Full Code Here

            lastModified = this.configurationFileLastModifiedTimes.get(finalApp);
        } else {
            lastModified = 0L;
        }

        MapPrinter printer = this.printers.get(finalApp);

        Optional<Long> configFileLastModified = this.configFileLoader.lastModified(configFile);
        if (configFileLastModified.isPresent() && configFileLastModified.get() > lastModified) {
            // file modified, reload it
            LOGGER.info("Configuration file modified. Reloading...");

            this.printers.remove(finalApp);
            printer = null;
        }

        if (printer == null) {
            if (configFileLastModified.isPresent()) {
                this.configurationFileLastModifiedTimes.put(finalApp, configFileLastModified.get());
            }

            try {
                LOGGER.info("Loading configuration file: " + configFile);
                printer = this.applicationContext.getBean(MapPrinter.class);
                byte[] bytes = this.configFileLoader.loadFile(configFile);
                printer.setConfiguration(configFile, bytes);

                this.printers.put(finalApp, printer);
            } catch (Throwable e) {
                if (e instanceof ClosedByInterruptException) {
                    // because of a bug in the JDK, the interrupted status might not be set
View Full Code Here

            @PathVariable final String appId,
            @RequestParam(value = "pretty", defaultValue = "false") final boolean pretty,
            @RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
            final HttpServletResponse capabilitiesResponse) throws ServletException,
            IOException, JSONException {
        MapPrinter printer;
        try {
            printer = this.printerFactory.create(appId);
        } catch (NoSuchAppException e) {
            error(capabilitiesResponse, e.getMessage(), HttpStatus.NOT_FOUND);
            return;
        }

        setContentType(capabilitiesResponse, jsonpCallback);

        final Writer writer;
        final ByteArrayOutputStream prettyPrintBuffer = new ByteArrayOutputStream();
        if (pretty) {
            writer = new OutputStreamWriter(prettyPrintBuffer, Constants.DEFAULT_CHARSET);
        } else {
            writer = capabilitiesResponse.getWriter();
        }

        try {
            if (!pretty && !Strings.isNullOrEmpty(jsonpCallback)) {
                writer.append(jsonpCallback + "(");
            }

            JSONWriter json = new JSONWriter(writer);
            try {
                json.object();
                {
                    json.key(JSON_APP).value(appId);
                    printer.printClientConfig(json);
                }
                {
                    json.key("formats");
                    Set<String> formats = printer.getOutputFormatsNames();
                    json.array();
                    for (String format : formats) {
                        json.value(format);
                    }
                    json.endArray();
View Full Code Here

            final HttpServletResponse getExampleResponse) throws ServletException,
            IOException {

        PrintWriter writer = null;
        try {
            final MapPrinter mapPrinter = this.printerFactory.create(appId);
            final Iterable<File> children = Files.fileTreeTraverser().children(mapPrinter.getConfiguration().getDirectory());
            JSONObject allExamples = new JSONObject();

            for (File child : children) {
                final String requestDataPrefix = "requestData";
                if (child.isFile() && child.getName().startsWith(requestDataPrefix) && child.getName().endsWith(".json")) {
View Full Code Here

        job.setRequestData(specJson);
        job.setSecurityContext(SecurityContextHolder.getContext());

        // check that we have authorization and configure the job so it can only be access by users with sufficient authorization
        final String templateName = specJson.getString(Constants.JSON_LAYOUT_KEY);
        final MapPrinter mapPrinter = this.mapPrinterFactory.create(appId);
        final Template template = mapPrinter.getConfiguration().getTemplate(templateName);
        job.configureAccess(template);

        try {
            this.jobManager.submit(job);
        } catch (RuntimeException exc) {
View Full Code Here

TOP

Related Classes of org.mapfish.print.MapPrinter

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.