Changeset 3826

Show
Ignore:
Timestamp:
06/29/11 07:17:42 (11 months ago)
Author:
theuer
Message:

p=theuer, r=theuer (closes #639)

Also, added some code to debug #638

Location:
print/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • print/trunk/.gitignore

    r3404 r3826  
    1 .gradle 
     1.gradle/ 
    22build/ 
    33.DS_Store 
    44.classpath 
    5 .project 
     5.project/ 
    66.settings/ 
     7depfile.txt 
     8docs 
     9lib/ 
     10print-lib/ 
     11print-servlet/ 
     12print-standalone/ 
     13samples/ 
     14todo 
     15.svn/ 
     16src/main/webapp/.smap.yaml.swp 
     17src/main/webapp/Copy of configVector.yaml 
     18src/main/webapp/portal.yaml~ 
     19src/main/webapp/smap.yaml~ 
     20build.sbt 
  • print/trunk/build.gradle

    r3825 r3826  
    5757} 
    5858 
    59 task standalone (dependsOn: test, type: Jar) { 
     59task standalone (type: Jar) { 
    6060  baseName = "print-standalone" 
    6161 
  • print/trunk/src/main/java/org/mapfish/print/PDFUtils.java

    r3789 r3826  
    3636import org.apache.batik.gvt.GraphicsNode; 
    3737import org.apache.batik.util.XMLResourceDescriptor; 
    38 import org.apache.commons.httpclient.*; 
    3938import org.apache.commons.httpclient.Header; 
    4039import org.apache.commons.httpclient.cookie.CookiePolicy; 
     
    5150import java.net.URI; 
    5251import java.net.URL; 
    53 import java.net.URLConnection; 
    5452import java.text.SimpleDateFormat; 
    5553import java.util.Date; 
     
    484482                } 
    485483                return myOffset; 
     484        } 
     485         
     486        public static Chunk createImageChunkFromSVG(RenderingContext context, String iconItem, double maxIconWidth, double maxIconHeight) throws IOException { 
     487                return new Chunk(PDFUtils.createImageFromSVG(context, iconItem, maxIconWidth, maxIconHeight), 0f, 0f, true);             
    486488        } 
    487489 
  • print/trunk/src/main/java/org/mapfish/print/config/Config.java

    r3789 r3826  
    7575    private int globalParallelFetches = 5; 
    7676    private int perHostParallelFetches = 5; 
    77     private int socketTimeout = 3*60*1000; 
    78     private int connectionTimeout = 30*1000; 
     77    private int socketTimeout = 40*60*1000; // 40 minutes //3*60*1000; 
     78    private int connectionTimeout = 40*60*1000; // 40 minutes //30*1000; 
    7979 
    8080    private boolean tilecacheMerging = false; 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/ColumnsBlock.java

    r3789 r3826  
    4444    private int width = Integer.MIN_VALUE; 
    4545    */ 
    46     private float absoluteX = Float.MIN_VALUE; 
    47     private float absoluteY = Float.MIN_VALUE; 
    48     private float width = Float.MIN_VALUE; 
     46    private double absoluteX = Double.MIN_VALUE; 
     47    private double absoluteY = Double.MIN_VALUE; 
     48    private double width = Double.MIN_VALUE; 
    4949    private int nbColumns = Integer.MIN_VALUE; 
    5050    private TableConfig config = null; 
     
    5757                    final PdfPTable table = PDFUtils.buildTable(items, params, context, nbColumns, config); 
    5858                    if (table != null) { 
    59                         table.setTotalWidth(width); 
     59                        table.setTotalWidth((float) width); 
    6060                        table.setLockedWidth(true); 
    6161 
     
    6464                        } 
    6565 
    66                         table.writeSelectedRows(0, -1, absoluteX, absoluteY, dc); 
     66                        table.writeSelectedRows(0, -1, (float) absoluteX, (float) absoluteY, dc); 
    6767                    } 
    6868                } 
     
    8989    } 
    9090 
    91     public void setAbsoluteX(float absoluteX) { 
     91    public void setAbsoluteX(double absoluteX) { 
    9292        this.absoluteX = absoluteX; 
    9393    } 
    9494 
    95     public void setAbsoluteY(float absoluteY) { 
     95    public void setAbsoluteY(double absoluteY) { 
    9696        this.absoluteY = absoluteY; 
    9797    } 
     
    106106 
    107107    public boolean isAbsolute() { 
    108         return absoluteX != Float.MIN_VALUE && 
    109                 absoluteY != Float.MIN_VALUE && 
    110                 width != Float.MIN_VALUE; 
     108        return absoluteX != Double.MIN_VALUE && 
     109                absoluteY != Double.MIN_VALUE && 
     110                width != Double.MIN_VALUE; 
    111111    } 
    112112 
     
    130130        if (items.size() < 1) throw new InvalidValueException("items", "[]"); 
    131131 
    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))) { 
     132        if (!((absoluteX != Double.MIN_VALUE && absoluteY != Double.MIN_VALUE && width != Double.MIN_VALUE) || 
     133                (absoluteX == Double.MIN_VALUE && absoluteY == Double.MIN_VALUE && width == Double.MIN_VALUE))) { 
    134134            throw new InvalidValueException("absoluteX, absoluteY or width", "all of them must be defined or none"); 
    135135        } 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/LegendsBlock.java

    r3789 r3826  
    2323import com.lowagie.text.Font; 
    2424import com.lowagie.text.FontFactory; 
    25 import com.lowagie.text.Image; 
    2625import com.lowagie.text.Paragraph; 
    2726import com.lowagie.text.pdf.BaseFont; 
     
    9493        final PJsonArray icons = node.optJSONArray("icons"); 
    9594 
    96         Image image = null; 
    97  
    9895        final Paragraph result = new Paragraph(); 
    9996        result.setFont(pdfFont); 
    10097        if (icon != null) { 
    101             result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0.0f)); 
    102             result.add(" "); 
     98                try { 
     99                        if (icon.indexOf("image%2Fsvg%2Bxml") != -1) { // TaODO: make this cleaner 
     100                                result.add(PDFUtils.createImageChunkFromSVG(context, icon, maxIconWidth, maxIconHeight)); 
     101                        } else { 
     102                                result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(icon), 0.0f)); 
     103                        } 
     104                    result.add(" "); 
     105                } catch (IOException ioe) { 
     106                LOGGER.warn("Failed to load " + icon + " with " + ioe.getMessage()); 
     107            } catch (InvalidValueException e) { 
     108                LOGGER.warn("Failed to create image chunk: " + e.getMessage()); 
     109            } 
    103110        } 
    104111        if (icons != null) { 
     
    107114                try { 
    108115                    if (iconItem.indexOf("image%2Fsvg%2Bxml") != -1) { // TaODO: make this cleaner 
    109                         image = PDFUtils.createImageFromSVG(context, iconItem, maxIconWidth, maxIconHeight); 
     116                        result.add(PDFUtils.createImageChunkFromSVG(context, iconItem, maxIconWidth, maxIconHeight)); 
    110117                    } else { 
    111118                        result.add(PDFUtils.createImageChunk(context, maxIconWidth, maxIconHeight, URI.create(iconItem), 0.0f)); 
     
    119126            } 
    120127        } 
    121         result.add(name); 
    122128 
    123129        final PdfPCell cell = new PdfPCell(result); 
     
    125131        cell.setPadding(0f); 
    126132        cell.setPaddingLeft((float) indent); 
    127         if (image != null) { 
    128             cell.addElement(image); 
    129         } 
     133 
     134        result.add(name); 
    130135 
    131136        if (getBackgroundColorVal(context, params) != null) { 
  • print/trunk/src/main/java/org/mapfish/print/config/layout/MapBlock.java

    r3789 r3826  
    186186 
    187187    public void printClientConfig(JSONWriter json) throws JSONException { 
     188        /** 
     189         * Changed width and height to be double from int to accomodate double values in yaml config 
     190         */ 
    188191        json.object(); 
    189         int w; 
     192        double w; //int w; 
    190193        try { 
    191             w = Integer.parseInt(width); 
     194                w = Math.round(Double.parseDouble(width)); //w = Integer.parseInt(width); 
    192195        } catch (NumberFormatException e) { 
    193196            w = 0; 
     
    195198        json.key("width").value(w); 
    196199 
    197         int h; 
     200        double h; //int h; 
    198201        try { 
    199             h = Integer.parseInt(height); 
     202                h = Math.round(Double.parseDouble(height)); //h = Integer.parseInt(height); 
    200203        } catch (NumberFormatException e) { 
    201204            h = 0; 
  • print/trunk/src/main/java/org/mapfish/print/map/readers/WMSServerInfo.java

    r3789 r3826  
    8888            } catch (Exception e) { 
    8989                LOGGER.info("Error while getting capabilities for "+uri+". The print module will assume it's a standard WMS."); 
     90                String stackTrace = ""; 
     91                for (StackTraceElement el : e.getStackTrace()) { 
     92                        stackTrace += el.toString() +"\n"; 
     93                } 
     94                LOGGER.info(stackTrace); 
    9095                result = new WMSServerInfo(); 
    9196            } 
  • print/trunk/src/main/java/org/mapfish/print/map/renderers/SVGTileRenderer.java

    r3789 r3826  
    5656    public static final Logger LOGGER = Logger.getLogger(SVGTileRenderer.class); 
    5757 
    58     private static final Document svgZoomOut; 
     58    private static Document svgZoomOut; 
    5959 
    6060    static { 
     61        makeSvgZoomOut(); 
     62    } 
     63    private static void makeSvgZoomOut() { 
    6164        DOMParser parser = new DOMParser(); 
    6265        String svgZoomFileName = "svgZoomOut.xsl"; 
     
    140143        final float zoomFactor = transformer.getSvgFactor() * context.getStyleFactor(); 
    141144        if (svgZoomOut != null && zoomFactor != 1.0f) { 
     145                javax.xml.transform.Transformer xslt = null; 
    142146            try { 
    143147                DOMResult transformedSvg = new DOMResult(); 
    144148                final TransformerFactory factory = TransformerFactory.newInstance(); 
    145                 javax.xml.transform.Transformer xslt = factory.newTransformer(new DOMSource(svgZoomOut)); 
     149                if (svgZoomOut.getTextContent() == null) { 
     150                        makeSvgZoomOut(); // a bit of a hack 
     151                } 
     152                xslt = factory.newTransformer(new DOMSource(svgZoomOut)); 
    146153 
    147154                //TODO: may want a different zoom factor in function of the layer and the type (symbol, line or font) 
     
    168175 
    169176            } catch (Exception e) { 
     177                if (xslt == null) { 
     178                        // some more information about the error 
     179                        LOGGER.error("xslt = NULL, zoomFactor = "+  
     180                                        zoomFactor +", svgZoomOut = "+ svgZoomOut 
     181                                        +"\nsvgZoomOut.getTextContent() = "+ svgZoomOut.getTextContent() 
     182                                        +"\nsvgZoomOut.getChildNodes().getLength() = "+ svgZoomOut.getChildNodes().getLength()); 
     183                } 
     184                 
    170185                context.addError(e); 
    171186                return null; 
  • print/trunk/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java

    r3789 r3826  
    4141    private Map<String, MapPrinter> printers = null; 
    4242    private long lastModified = 0L; 
     43    private long defaultLastModified = 0L; 
    4344    private Map<String,Long> lastModifieds = null; 
    4445 
     
    5859            throw new ServletException("Missing configuration in web.xml 'web-app/servlet/init-param[param-name=config]' or 'web-app/context-param[param-name=config]'"); 
    5960        } 
     61        //String debugPath = ""; 
    6062 
    6163        File configFile = null; 
     
    6365                if (lastModifieds == null) { 
    6466                        lastModifieds = new HashMap<String, Long>(); 
     67                        //debugPath += "new HashMap\n"; 
    6568                } 
    66                 try { 
    67                         printer = printers.get(app); 
    68                 } catch (Exception e) { 
    69                                 printer = null; 
    70                         } 
     69                if (printers instanceof HashMap &&  printers.containsKey(app)) { 
     70                        printer = printers.get(app); 
     71                        //debugPath += "get printer from hashmap\n"; 
     72                } else { 
     73                        printer = null; 
     74                        //debugPath += "printer = null 1\n"; 
     75                } 
    7176                configFile = new File(app +".yaml"); 
    7277        } else { 
    7378                configFile = new File(configPath); 
     79                //debugPath += "configFile = new ..., 1\n"; 
    7480        } 
    7581        if (!configFile.isAbsolute()) { 
    7682                if (app != null) { 
     83                        //debugPath += "config is absolute app = "+app+"\n"; 
    7784                        configFile = new File(getServletContext().getRealPath(app +".yaml")); 
    7885                } else { 
    7986                        configFile = new File(getServletContext().getRealPath(configPath)); 
     87                        //debugPath += "config is absolute app DEFAULT\n"; 
    8088                } 
    8189        } 
    8290        if (app != null) { 
    83                 try { 
     91                if (lastModifieds instanceof HashMap && lastModifieds.containsKey(app)) { 
    8492                        lastModified = lastModifieds.get(app); 
    85                 } catch (Exception e) { 
    86                                 lastModified = 0L; 
    87                         } 
     93                        //debugPath += "app = "+app+" lastModifieds has key and gotten: "+ lastModified +"\n"; 
     94                } else { 
     95                        lastModified = 0L; 
     96                        //debugPath += "app = "+app+" lastModifieds has NOT key and gotten: "+ lastModified +" (0L)\n"; 
     97                } 
     98        } else { 
     99                lastModified = defaultLastModified; // this is a fix for when configuration files have changed 
     100                //debugPath += "app = NULL lastModifieds from defaultLastModified: "+ lastModified +"\n"; 
    88101        } 
    89102 
     
    93106            try { 
    94107                printer.stop(); 
     108                 
     109                //debugPath += "printer stopped, setting NULL\n"; 
    95110            } catch (NullPointerException npe) { 
    96                 LOGGER.info("BaseMapServlet.java: printer was not stopped. This happens when a switch between applications happens."); 
     111                LOGGER.info("BaseMapServlet.java: printer was not stopped. This happens when a switch between applications happens.\n"+ npe); 
    97112            } 
    98113             
    99114            printer = null; 
     115            if (app != null) { 
     116                LOGGER.info("Printer for "+ app +" stopped"); 
     117                printers.put(app, null); 
     118            } 
    100119        } 
    101120 
    102121        if (printer == null) { 
    103122            lastModified = configFile.lastModified(); 
     123            //debugPath += "printer == null, lastModified from configFile = "+lastModified+"\n"; 
    104124            try { 
    105125                LOGGER.info("Loading configuration file: " + configFile.getAbsolutePath()); 
     
    108128                        if (printers == null) { 
    109129                                printers = new HashMap<String, MapPrinter>(); 
     130                                //debugPath += "printers = new HashMap , printer == null, app = "+app+"\n"; 
    110131                        } 
    111132                        printers.put(app, printer); 
    112133                        lastModifieds.put(app, lastModified); 
     134                        //debugPath += "putting app = "+app+" HashMaps: printer and lastModified: "+lastModified+"\n"; 
     135                } else { 
     136                        defaultLastModified = lastModified; // need this for default application 
     137                        //debugPath += "defaultLastModified = "+defaultLastModified+" 123\n"; 
    113138                } 
    114139            } catch (FileNotFoundException e) { 
     
    116141            } 
    117142        } 
     143         
     144        //LOGGER.info(debugPath); 
     145        /* 
     146        try { 
     147            if (app == null) { 
     148                throw new Exception("Just to see the stack trace"); 
     149            } 
     150                throw new Exception("Just to see the stack trace"); 
     151        } catch (Exception e) { 
     152                StackTraceElement stelements[] = e.getStackTrace(); 
     153                for (StackTraceElement s : stelements) { 
     154                        LOGGER.warn("StackTraceElement ASD: "+ s.toString()); 
     155                } 
     156                //LOGGER.warn("app == NULL:\n"+ e.getStackTrace()); 
     157        } 
     158        */ 
    118159        return printer; 
    119160    } 
  • print/trunk/src/main/webapp/WEB-INF/web.xml

    r3397 r3826  
    99    <init-param> 
    1010      <param-name>config</param-name> 
    11       <param-value>config.yaml</param-value> 
     11      <param-value>configVector.yaml</param-value> 
    1212    </init-param> 
    1313  </servlet> 
  • print/trunk/src/main/webapp/config.yaml

    r3649 r3826  
    4545    host: demo.mapfish.org 
    4646    port: 80 
     47  - !dnsMatch 
     48    host: basemap-web.zen.landcareresearch.co.nz 
     49    port: 80 
    4750 
    4851# the default fileName for the files downloaded from the servlet