Changeset 3787 for print

Show
Ignore:
Timestamp:
05/31/11 07:25:07 (12 months ago)
Author:
theuer
Message:

First Commit, Please check this one.
Fixes ticket 632
Multiple applications running with app parameter.

Location:
print/trunk/src/main/java/org/mapfish/print
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • print/trunk/src/main/java/org/mapfish/print/Transformer.java

    r3650 r3787  
    6464    public float maxGeoY; 
    6565    private final int scale; 
    66     private final int paperWidth; 
    67     private final int paperHeight; 
     66    private final float paperWidth; 
     67    private final float paperHeight; 
    6868    private float pixelPerGeoUnit; 
    6969    private float paperPosX; 
     
    8181     *            calculator. if null it is assumed that it is non-geodetic 
    8282     */ 
    83     public Transformer(float centerX, float centerY, int paperWidth, 
    84             int paperHeight, int scale, int dpi, DistanceUnit unitEnum, 
     83    public Transformer(float centerX, float centerY, float paperWidth, 
     84            float paperHeight, int scale, int dpi, DistanceUnit unitEnum, 
    8585            double rotation, String geodeticSRS) { 
    8686        this.dpi = dpi; 
  • print/trunk/src/main/java/org/mapfish/print/config/Config.java

    r3649 r3787  
    2020package org.mapfish.print.config; 
    2121 
    22 import org.apache.commons.httpclient.HostConfiguration; 
     22//import org.apache.commons.httpclient.HostConfiguration; 
    2323import org.apache.commons.httpclient.HttpClient; 
    2424import org.apache.commons.httpclient.HttpMethodBase; 
     
    3737import org.mapfish.print.map.readers.WMSServerInfo; 
    3838import org.mapfish.print.output.OutputFactory; 
    39 import org.mapfish.print.output.OutputFormat; 
     39//import org.mapfish.print.output.OutputFormat; 
    4040import org.pvalsecc.concurrent.OrderedResultsExecutor; 
    4141 
     
    6262    private TreeSet<Integer> dpis; 
    6363    private TreeSet<Integer> scales; 
     64    private String maxSvgWidth = ""; 
     65    private String maxSvgHeight = ""; 
     66    private double maxSvgW = Double.MAX_VALUE; 
     67    private double maxSvgH = Double.MAX_VALUE; 
     68     
     69    private List<String> overlayLayers = null; 
     70     
    6471    private TreeSet<String> fonts = null; 
    6572    private List<HostMatcher> hosts = new ArrayList<HostMatcher>(); 
     
    8794    private OrderedResultsExecutor<MapTileTask> mapRenderingExecutor = null; 
    8895    private MultiThreadedHttpConnectionManager connectionManager; 
    89     private TreeSet<String> formats; 
     96    private TreeSet<String> formats; // private int svgMaxWidth = -1; private int svgMaxHeight = -1; 
    9097 
    9198    public Config() { 
     
    128135        this.dpis = dpis; 
    129136    } 
    130  
     137     
     138    public void setMaxSvgWidth(String maxSvgWidth) { 
     139        this.maxSvgWidth = maxSvgWidth; 
     140        this.maxSvgW = Double.parseDouble(maxSvgWidth); 
     141    } 
     142    public String getMaxSvgWidth() { 
     143        return this.maxSvgWidth; 
     144    } 
     145    public void setMaxSvgHeight(String maxSvgHeight) { 
     146        this.maxSvgHeight = maxSvgHeight; 
     147        this.maxSvgH = Double.parseDouble(maxSvgHeight); 
     148    } 
     149    public String getMaxSvgHeight() { 
     150        return this.maxSvgHeight; 
     151    } 
     152     
     153    public double getMaxSvgW() { 
     154        return this.maxSvgW; 
     155    } 
     156    public double getMaxSvgH() { 
     157        return this.maxSvgH; 
     158    } 
     159     
    131160    public TreeSet<Integer> getDpis() { 
    132161        return dpis; 
     
    388417        this.formats = formats; 
    389418    } 
     419 
     420    public void setOverlayLayers(List<String> overlayLayers) { 
     421      this.overlayLayers = overlayLayers; 
     422    } 
     423 
     424    public List<String> getOverlayLayers() { 
     425      return overlayLayers; 
     426    } 
    390427} 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/ColumnsBlock.java

    r3397 r3787  
    3939    private List<Block> items; 
    4040    private int[] widths = null; 
     41    /* 
    4142    private int absoluteX = Integer.MIN_VALUE; 
    4243    private int absoluteY = Integer.MIN_VALUE; 
    4344    private int width = Integer.MIN_VALUE; 
     45    */ 
     46    private float absoluteX = Float.MIN_VALUE; 
     47    private float absoluteY = Float.MIN_VALUE; 
     48    private float width = Float.MIN_VALUE; 
    4449    private int nbColumns = Integer.MIN_VALUE; 
    4550    private TableConfig config = null; 
     
    8489    } 
    8590 
    86     public void setAbsoluteX(int absoluteX) { 
     91    public void setAbsoluteX(float absoluteX) { 
    8792        this.absoluteX = absoluteX; 
    8893    } 
    8994 
    90     public void setAbsoluteY(int absoluteY) { 
     95    public void setAbsoluteY(float absoluteY) { 
    9196        this.absoluteY = absoluteY; 
    9297    } 
    9398 
    94     public void setWidth(int width) { 
     99    public void setWidth(float width) { 
    95100        this.width = width; 
    96101    } 
     
    101106 
    102107    public boolean isAbsolute() { 
    103         return absoluteX != Integer.MIN_VALUE && 
    104                 absoluteY != Integer.MIN_VALUE && 
    105                 width != Integer.MIN_VALUE; 
     108        return absoluteX != Float.MIN_VALUE && 
     109                absoluteY != Float.MIN_VALUE && 
     110                width != Float.MIN_VALUE; 
    106111    } 
    107112 
     
    125130        if (items.size() < 1) throw new InvalidValueException("items", "[]"); 
    126131 
    127         if (!((absoluteX != Integer.MIN_VALUE && absoluteY != Integer.MIN_VALUE && width != Integer.MIN_VALUE) || 
    128                 (absoluteX == Integer.MIN_VALUE && absoluteY == Integer.MIN_VALUE && width == Integer.MIN_VALUE))) { 
     132        if (!((absoluteX != Float.MIN_VALUE && absoluteY != Float.MIN_VALUE && width != Float.MIN_VALUE) || 
     133                (absoluteX == Float.MIN_VALUE && absoluteY == Float.MIN_VALUE && width == Float.MIN_VALUE))) { 
    129134            throw new InvalidValueException("absoluteX, absoluteY or width", "all of them must be defined or none"); 
    130135        } 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/Layout.java

    r3641 r3787  
    2626import org.mapfish.print.RenderingContext; 
    2727import org.mapfish.print.InvalidValueException; 
    28 import org.mapfish.print.config.Config; 
    2928import org.mapfish.print.utils.PJsonArray; 
    3029import org.mapfish.print.utils.PJsonObject; 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/LegendsBlock.java

    r3748 r3787  
    2828import com.lowagie.text.pdf.PdfPCell; 
    2929import com.lowagie.text.pdf.PdfPTable; 
    30 import com.lowagie.text.pdf.PdfTemplate; 
    3130 
    32 import org.apache.batik.bridge.BridgeContext; 
    33 import org.apache.batik.bridge.GVTBuilder; 
    34 import org.apache.batik.dom.svg.SAXSVGDocumentFactory; 
    35 import org.apache.batik.gvt.GraphicsNode; 
    3631import org.apache.log4j.Logger; 
    3732import org.mapfish.print.PDFUtils; 
     
    4035import org.mapfish.print.utils.PJsonArray; 
    4136import org.mapfish.print.utils.PJsonObject; 
    42 import org.w3c.dom.svg.SVGDocument; 
    4337 
    44 import java.awt.Graphics2D; 
    4538import java.io.IOException; 
    4639import java.net.URI; 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/MapBlock.java

    r3650 r3787  
    5454 
    5555        if (isAbsolute()) { 
    56             final int absX = getAbsoluteX(context, params); 
    57             final int absY = getAbsoluteY(context, params); 
     56            final float absX = getAbsoluteX(context, params); 
     57            final float absY = getAbsoluteY(context, params); 
    5858            context.getCustomBlocks().addAbsoluteDrawer(new PDFCustomBlocks.AbsoluteDrawer() { 
    5959                public void render(PdfContentByte dc) { 
     
    9090        final float centerY; 
    9191 
    92         final int width = getWidth(context, params); 
    93         final int height = getHeight(context, params); 
     92        final float width = getWidth(context, params); 
     93        final float height = getHeight(context, params); 
    9494        final PJsonArray center = params.optJSONArray("center"); 
    9595        if (center != null) { 
     
    146146    } 
    147147 
    148     public int getHeight(RenderingContext context, PJsonObject params) { 
    149         return Integer.parseInt(PDFUtils.evalString(context, params, height)); 
     148    public float getHeight(RenderingContext context, PJsonObject params) { 
     149        return Float.parseFloat(PDFUtils.evalString(context, params, height)); 
    150150    } 
    151151 
     
    155155    } 
    156156 
    157     public int getWidth(RenderingContext context, PJsonObject params) { 
    158         return Integer.parseInt(PDFUtils.evalString(context, params, width)); 
     157    public float getWidth(RenderingContext context, PJsonObject params) { 
     158        return Float.parseFloat(PDFUtils.evalString(context, params, width)); 
    159159    } 
    160160 
     
    168168    } 
    169169 
    170     public int getAbsoluteX(RenderingContext context, PJsonObject params) { 
    171         return Integer.parseInt(PDFUtils.evalString(context, params, absoluteX)); 
     170    public float getAbsoluteX(RenderingContext context, PJsonObject params) { 
     171        //return Integer.parseInt(PDFUtils.evalString(context, params, absoluteX)); 
     172      return Float.parseFloat(PDFUtils.evalString(context, params, absoluteX)); 
    172173    } 
    173174 
     
    176177    } 
    177178 
    178     public int getAbsoluteY(RenderingContext context, PJsonObject params) { 
    179         return Integer.parseInt(PDFUtils.evalString(context, params, absoluteY)); 
     179    public float getAbsoluteY(RenderingContext context, PJsonObject params) { 
     180        return Float.parseFloat(PDFUtils.evalString(context, params, absoluteY)); 
    180181    } 
    181182 
  • print/trunk/src/main/java/org/mapfish/print/map/readers/WMSMapReader.java

    r3745 r3787  
    2020package org.mapfish.print.map.readers; 
    2121 
     22import org.apache.batik.bridge.UserAgent; 
     23import org.apache.batik.bridge.UserAgentAdapter; 
    2224import org.mapfish.print.RenderingContext; 
    2325import org.mapfish.print.Transformer; 
     
    154156        Map<String, List<String>> tileParams = new HashMap<String, List<String>>(); 
    155157        if (format.equals("image/svg+xml")) { 
    156             URIUtils.addParamOverride(tileParams, "WIDTH", Long.toString(transformer.getRotatedSvgW())); 
    157             URIUtils.addParamOverride(tileParams, "HEIGHT", Long.toString(transformer.getRotatedSvgH())); 
     158                double maxW = context.getConfig().getMaxSvgW(); // config setting in YAML called maxSvgWidth 
     159                double maxH = context.getConfig().getMaxSvgH(); // config setting in YAML called maxSvgHeight 
     160                double divisor = 1; 
     161                double width = transformer.getRotatedSvgW(); // width of the vector map 
     162                double height = transformer.getRotatedSvgH(); // height of the vector map 
     163                 
     164                if (maxW < width || maxH < height) { 
     165                        /** 
     166                         *  need to use maxW as divisor, smaller quotient for width means  
     167                         *  more constraining factor is max width  
     168                         */ 
     169                        if (maxW / maxH < width / height) { 
     170                                divisor = width / maxW; 
     171                                width = maxW; 
     172                                height = height / divisor; 
     173                        } else { 
     174                                divisor = height / maxH; 
     175                                height = maxH; 
     176                                width = width / divisor; 
     177                        } 
     178                } 
     179            URIUtils.addParamOverride(tileParams, "WIDTH", Long.toString((long) Math.round(width))); 
     180            URIUtils.addParamOverride(tileParams, "HEIGHT", Long.toString((long) Math.round(height))); 
    158181        } else { 
    159182            URIUtils.addParamOverride(tileParams, "WIDTH", Long.toString(w)); 
  • print/trunk/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java

    r3649 r3787  
    2727import java.io.File; 
    2828import java.io.FileNotFoundException; 
     29import java.util.HashMap; 
     30import java.util.Map; 
    2931 
    3032/** 
     
    3739 
    3840    private MapPrinter printer = null; 
     41    private Map<String, MapPrinter> printers = null; 
    3942    private long lastModified = 0L; 
     43    private Map<String,Long> lastModifieds = null; 
    4044 
    4145    /** 
     
    4953     * If the location is a relative path, it's taken from the servlet's root directory. 
    5054     */ 
    51     protected synchronized MapPrinter getMapPrinter() throws ServletException { 
     55    protected synchronized MapPrinter getMapPrinter(String app) throws ServletException { 
    5256        String configPath = getInitParameter("config"); 
    5357        if (configPath == null) { 
     
    5559        } 
    5660 
    57         File configFile = new File(configPath); 
     61        File configFile = null; 
     62        if (app != null) { 
     63                if (lastModifieds == null) { 
     64                        lastModifieds = new HashMap<String, Long>(); 
     65                } 
     66                try { 
     67                        printer = printers.get(app); 
     68                } catch (Exception e) { 
     69                                printer = null; 
     70                        } 
     71                configFile = new File(app +".yaml"); 
     72        } else { 
     73                configFile = new File(configPath); 
     74        } 
    5875        if (!configFile.isAbsolute()) { 
    59             configFile = new File(getServletContext().getRealPath(configPath)); 
     76                if (app != null) { 
     77                        configFile = new File(getServletContext().getRealPath(app +".yaml")); 
     78                } else { 
     79                        configFile = new File(getServletContext().getRealPath(configPath)); 
     80                } 
     81        } 
     82        if (app != null) { 
     83                try { 
     84                        lastModified = lastModifieds.get(app); 
     85                } catch (Exception e) { 
     86                                lastModified = 0L; 
     87                        } 
    6088        } 
    6189 
     
    6391            //file modified, reload it 
    6492            LOGGER.info("Configuration file modified. Reloading..."); 
    65             printer.stop(); 
     93            try { 
     94                printer.stop(); 
     95            } catch (NullPointerException npe) { 
     96                LOGGER.info("BaseMapServlet.java: printer was not stopped. This happens when a switch between applications happens."); 
     97            } 
     98             
    6699            printer = null; 
    67100        } 
     
    72105                LOGGER.info("Loading configuration file: " + configFile.getAbsolutePath()); 
    73106                printer = new MapPrinter(configFile); 
     107                if (app != null) { 
     108                        if (printers == null) { 
     109                                printers = new HashMap<String, MapPrinter>(); 
     110                        } 
     111                        printers.put(app, printer); 
     112                        lastModifieds.put(app, lastModified); 
     113                } 
    74114            } catch (FileNotFoundException e) { 
    75115                throw new ServletException("Cannot read configuration file: " + configPath, e); 
  • print/trunk/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java

    r3748 r3787  
    5151    protected static final String TEMP_FILE_PREFIX = "mapfish-print"; 
    5252    private static final String TEMP_FILE_SUFFIX = ".printout"; 
     53     
     54    private String app = null; 
    5355 
    5456    private static final int TEMP_FILE_PURGE_SECONDS = 10 * 60; 
     
    223225     */ 
    224226    protected void getInfo(HttpServletRequest req, HttpServletResponse resp, String basePath) throws ServletException, IOException { 
    225         MapPrinter printer = getMapPrinter(); 
     227        app = req.getParameter("app"); 
     228        //System.out.println("app = "+app); 
     229         
     230        MapPrinter printer = getMapPrinter(app); 
    226231        resp.setContentType("application/json; charset=utf-8"); 
    227232        final PrintWriter writer = resp.getWriter(); 
     
    240245                    json.key("printURL").value(basePath + PRINT_URL); 
    241246                    json.key("createURL").value(basePath + CREATE_URL); 
     247                    if (app != null) { 
     248                        json.key("app").value(app); 
     249                    } 
    242250                } 
    243251                json.endObject(); 
     
    263271 
    264272        PJsonObject specJson = MapPrinter.parseSpec(spec); 
     273        if (specJson.has("app")) { 
     274                app = specJson.getString("app"); 
     275        } else { 
     276                app = null; 
     277        } 
    265278 
    266279        String referer = httpServletRequest.getHeader("Referer"); 
    267280 
    268         final OutputFormat outputFormat = OutputFactory.create(getMapPrinter().getConfig(),specJson); 
     281        final OutputFormat outputFormat = OutputFactory.create(getMapPrinter(app).getConfig(),specJson); 
    269282        //create a temporary file that will contain the PDF 
    270283        final File tempJavaFile = File.createTempFile(TEMP_FILE_PREFIX, "."+outputFormat.fileSuffix()+TEMP_FILE_SUFFIX, getTempDir()); 
     
    275288            out = new FileOutputStream(tempFile); 
    276289 
    277             outputFormat.print(getMapPrinter(), specJson, out, referer); 
     290            outputFormat.print(getMapPrinter(app), specJson, out, referer); 
    278291 
    279292            return tempFile; 
     
    302315            httpServletResponse.setContentType(tempFile.contentType()); 
    303316            if (inline != true) { 
    304                 final String fileName = tempFile.getOutputFileName(getMapPrinter()); 
     317                final String fileName = tempFile.getOutputFileName(getMapPrinter(app)); 
    305318                httpServletResponse.setHeader("Content-disposition", "attachment; filename=" + fileName); 
    306319            }