- Timestamp:
- 05/31/11 07:25:07 (12 months ago)
- Location:
- print/trunk/src/main/java/org/mapfish/print
- Files:
-
- 9 modified
-
Transformer.java (modified) (2 diffs)
-
config/Config.java (modified) (6 diffs)
-
config/layout/ColumnsBlock.java (modified) (4 diffs)
-
config/layout/Layout.java (modified) (1 diff)
-
config/layout/LegendsBlock.java (modified) (2 diffs)
-
config/layout/MapBlock.java (modified) (6 diffs)
-
map/readers/WMSMapReader.java (modified) (2 diffs)
-
servlet/BaseMapServlet.java (modified) (6 diffs)
-
servlet/MapPrinterServlet.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
print/trunk/src/main/java/org/mapfish/print/Transformer.java
r3650 r3787 64 64 public float maxGeoY; 65 65 private final int scale; 66 private final int paperWidth;67 private final int paperHeight;66 private final float paperWidth; 67 private final float paperHeight; 68 68 private float pixelPerGeoUnit; 69 69 private float paperPosX; … … 81 81 * calculator. if null it is assumed that it is non-geodetic 82 82 */ 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, 85 85 double rotation, String geodeticSRS) { 86 86 this.dpi = dpi; -
print/trunk/src/main/java/org/mapfish/print/config/Config.java
r3649 r3787 20 20 package org.mapfish.print.config; 21 21 22 import org.apache.commons.httpclient.HostConfiguration;22 //import org.apache.commons.httpclient.HostConfiguration; 23 23 import org.apache.commons.httpclient.HttpClient; 24 24 import org.apache.commons.httpclient.HttpMethodBase; … … 37 37 import org.mapfish.print.map.readers.WMSServerInfo; 38 38 import org.mapfish.print.output.OutputFactory; 39 import org.mapfish.print.output.OutputFormat;39 //import org.mapfish.print.output.OutputFormat; 40 40 import org.pvalsecc.concurrent.OrderedResultsExecutor; 41 41 … … 62 62 private TreeSet<Integer> dpis; 63 63 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 64 71 private TreeSet<String> fonts = null; 65 72 private List<HostMatcher> hosts = new ArrayList<HostMatcher>(); … … 87 94 private OrderedResultsExecutor<MapTileTask> mapRenderingExecutor = null; 88 95 private MultiThreadedHttpConnectionManager connectionManager; 89 private TreeSet<String> formats; 96 private TreeSet<String> formats; // private int svgMaxWidth = -1; private int svgMaxHeight = -1; 90 97 91 98 public Config() { … … 128 135 this.dpis = dpis; 129 136 } 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 131 160 public TreeSet<Integer> getDpis() { 132 161 return dpis; … … 388 417 this.formats = formats; 389 418 } 419 420 public void setOverlayLayers(List<String> overlayLayers) { 421 this.overlayLayers = overlayLayers; 422 } 423 424 public List<String> getOverlayLayers() { 425 return overlayLayers; 426 } 390 427 } -
print/trunk/src/main/java/org/mapfish/print/config/layout/ColumnsBlock.java
r3397 r3787 39 39 private List<Block> items; 40 40 private int[] widths = null; 41 /* 41 42 private int absoluteX = Integer.MIN_VALUE; 42 43 private int absoluteY = Integer.MIN_VALUE; 43 44 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; 44 49 private int nbColumns = Integer.MIN_VALUE; 45 50 private TableConfig config = null; … … 84 89 } 85 90 86 public void setAbsoluteX( int absoluteX) {91 public void setAbsoluteX(float absoluteX) { 87 92 this.absoluteX = absoluteX; 88 93 } 89 94 90 public void setAbsoluteY( int absoluteY) {95 public void setAbsoluteY(float absoluteY) { 91 96 this.absoluteY = absoluteY; 92 97 } 93 98 94 public void setWidth( int width) {99 public void setWidth(float width) { 95 100 this.width = width; 96 101 } … … 101 106 102 107 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; 106 111 } 107 112 … … 125 130 if (items.size() < 1) throw new InvalidValueException("items", "[]"); 126 131 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))) { 129 134 throw new InvalidValueException("absoluteX, absoluteY or width", "all of them must be defined or none"); 130 135 } -
print/trunk/src/main/java/org/mapfish/print/config/layout/Layout.java
r3641 r3787 26 26 import org.mapfish.print.RenderingContext; 27 27 import org.mapfish.print.InvalidValueException; 28 import org.mapfish.print.config.Config;29 28 import org.mapfish.print.utils.PJsonArray; 30 29 import org.mapfish.print.utils.PJsonObject; -
print/trunk/src/main/java/org/mapfish/print/config/layout/LegendsBlock.java
r3748 r3787 28 28 import com.lowagie.text.pdf.PdfPCell; 29 29 import com.lowagie.text.pdf.PdfPTable; 30 import com.lowagie.text.pdf.PdfTemplate;31 30 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;36 31 import org.apache.log4j.Logger; 37 32 import org.mapfish.print.PDFUtils; … … 40 35 import org.mapfish.print.utils.PJsonArray; 41 36 import org.mapfish.print.utils.PJsonObject; 42 import org.w3c.dom.svg.SVGDocument;43 37 44 import java.awt.Graphics2D;45 38 import java.io.IOException; 46 39 import java.net.URI; -
print/trunk/src/main/java/org/mapfish/print/config/layout/MapBlock.java
r3650 r3787 54 54 55 55 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); 58 58 context.getCustomBlocks().addAbsoluteDrawer(new PDFCustomBlocks.AbsoluteDrawer() { 59 59 public void render(PdfContentByte dc) { … … 90 90 final float centerY; 91 91 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); 94 94 final PJsonArray center = params.optJSONArray("center"); 95 95 if (center != null) { … … 146 146 } 147 147 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)); 150 150 } 151 151 … … 155 155 } 156 156 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)); 159 159 } 160 160 … … 168 168 } 169 169 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)); 172 173 } 173 174 … … 176 177 } 177 178 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)); 180 181 } 181 182 -
print/trunk/src/main/java/org/mapfish/print/map/readers/WMSMapReader.java
r3745 r3787 20 20 package org.mapfish.print.map.readers; 21 21 22 import org.apache.batik.bridge.UserAgent; 23 import org.apache.batik.bridge.UserAgentAdapter; 22 24 import org.mapfish.print.RenderingContext; 23 25 import org.mapfish.print.Transformer; … … 154 156 Map<String, List<String>> tileParams = new HashMap<String, List<String>>(); 155 157 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))); 158 181 } else { 159 182 URIUtils.addParamOverride(tileParams, "WIDTH", Long.toString(w)); -
print/trunk/src/main/java/org/mapfish/print/servlet/BaseMapServlet.java
r3649 r3787 27 27 import java.io.File; 28 28 import java.io.FileNotFoundException; 29 import java.util.HashMap; 30 import java.util.Map; 29 31 30 32 /** … … 37 39 38 40 private MapPrinter printer = null; 41 private Map<String, MapPrinter> printers = null; 39 42 private long lastModified = 0L; 43 private Map<String,Long> lastModifieds = null; 40 44 41 45 /** … … 49 53 * If the location is a relative path, it's taken from the servlet's root directory. 50 54 */ 51 protected synchronized MapPrinter getMapPrinter( ) throws ServletException {55 protected synchronized MapPrinter getMapPrinter(String app) throws ServletException { 52 56 String configPath = getInitParameter("config"); 53 57 if (configPath == null) { … … 55 59 } 56 60 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 } 58 75 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 } 60 88 } 61 89 … … 63 91 //file modified, reload it 64 92 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 66 99 printer = null; 67 100 } … … 72 105 LOGGER.info("Loading configuration file: " + configFile.getAbsolutePath()); 73 106 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 } 74 114 } catch (FileNotFoundException e) { 75 115 throw new ServletException("Cannot read configuration file: " + configPath, e); -
print/trunk/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java
r3748 r3787 51 51 protected static final String TEMP_FILE_PREFIX = "mapfish-print"; 52 52 private static final String TEMP_FILE_SUFFIX = ".printout"; 53 54 private String app = null; 53 55 54 56 private static final int TEMP_FILE_PURGE_SECONDS = 10 * 60; … … 223 225 */ 224 226 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); 226 231 resp.setContentType("application/json; charset=utf-8"); 227 232 final PrintWriter writer = resp.getWriter(); … … 240 245 json.key("printURL").value(basePath + PRINT_URL); 241 246 json.key("createURL").value(basePath + CREATE_URL); 247 if (app != null) { 248 json.key("app").value(app); 249 } 242 250 } 243 251 json.endObject(); … … 263 271 264 272 PJsonObject specJson = MapPrinter.parseSpec(spec); 273 if (specJson.has("app")) { 274 app = specJson.getString("app"); 275 } else { 276 app = null; 277 } 265 278 266 279 String referer = httpServletRequest.getHeader("Referer"); 267 280 268 final OutputFormat outputFormat = OutputFactory.create(getMapPrinter( ).getConfig(),specJson);281 final OutputFormat outputFormat = OutputFactory.create(getMapPrinter(app).getConfig(),specJson); 269 282 //create a temporary file that will contain the PDF 270 283 final File tempJavaFile = File.createTempFile(TEMP_FILE_PREFIX, "."+outputFormat.fileSuffix()+TEMP_FILE_SUFFIX, getTempDir()); … … 275 288 out = new FileOutputStream(tempFile); 276 289 277 outputFormat.print(getMapPrinter( ), specJson, out, referer);290 outputFormat.print(getMapPrinter(app), specJson, out, referer); 278 291 279 292 return tempFile; … … 302 315 httpServletResponse.setContentType(tempFile.contentType()); 303 316 if (inline != true) { 304 final String fileName = tempFile.getOutputFileName(getMapPrinter( ));317 final String fileName = tempFile.getOutputFileName(getMapPrinter(app)); 305 318 httpServletResponse.setHeader("Content-disposition", "attachment; filename=" + fileName); 306 319 }
