You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2013/10/08 16:03:40 UTC
[25/62] [abbrv] [partial] Merged Apache Flex 4.9.0 release branch
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f690ea2f/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Main.java
----------------------------------------------------------------------
diff --git a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Main.java b/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Main.java
deleted file mode 100644
index bdad39a..0000000
--- a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Main.java
+++ /dev/null
@@ -1,990 +0,0 @@
-/*
-
- Copyright 2000-2003 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- */
-package org.apache.flex.forks.batik.apps.rasterizer;
-
-import java.awt.Color;
-import java.awt.geom.Rectangle2D;
-import java.io.File;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import org.apache.flex.forks.batik.transcoder.Transcoder;
-import org.apache.flex.forks.batik.util.ApplicationSecurityEnforcer;
-
-/**
- * Handles command line parameters to configure the <tt>SVGConverter</tt>
- * and rasterizer images. <br />
- *
- * Each command line option is handled by an <tt>OptionHandler</tt> which
- * is responsible for converting the option into a configuration of the
- * <tt>SVGConverter</tt> which is used to perform the conversion.
- *
- * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: Main.java,v 1.28 2004/08/18 07:12:25 vhardy Exp $
- */
-public class Main implements SVGConverterController {
- /**
- * URL for Squiggle's security policy file
- */
- public static final String RASTERIZER_SECURITY_POLICY
- = "org/apache/batik/apps/rasterizer/resources/rasterizer.policy";
-
- /**
- * Interface for handling one command line option
- */
- public static interface OptionHandler {
- /**
- * The <tt>OptionHandler</tt> should configure the <tt>SVGConverter</tt>
- * according to the value of the option.
- *
- * Should throw an IllegalArgumentException if optionValue
- * is not an acceptable option.
- */
- void handleOption(String[] optionValues, SVGConverter c);
-
- /**
- * Returns the number of values which the option handler requires.
- * This defines the length of the optionValues array passed to
- * the handler in the handleOption method
- */
- int getOptionValuesLength();
-
- /**
- * Returns the description for this option
- */
- String getOptionDescription();
- }
-
- /**
- * This abstract implementation of the <tt>OptionHandler</tt> interface
- * throws an exception if the number of arguments passed to the
- * <tt>handleOption</tt> method does not match the number of expected
- * optionValues. If the size matches, the <tt>safeHandleOption</tt>
- * method is invoked.
- * Subclasses can implement the <tt>safeHandleOption</tt> method
- * assuming that the input array size is correct.
- */
- public static abstract class AbstractOptionHandler implements OptionHandler {
-
- public void handleOption(String[] optionValues, SVGConverter c){
- int nOptions = optionValues != null? optionValues.length: 0;
- if (nOptions != getOptionValuesLength()){
- throw new IllegalArgumentException();
- }
-
- safeHandleOption(optionValues, c);
- }
-
- public abstract void safeHandleOption(String[] optionValues, SVGConverter c);
- }
-
- /**
- * Base class for options with no option value (i.e., the presence
- * of the option means something in itself. Subclasses should implement
- * the <tt>handleOption</tt> method which takes only an <tt>SVGConverter</tt>
- * as a parameter.
- */
- public static abstract class NoValueOptionHandler extends AbstractOptionHandler {
- public void safeHandleOption(String[] optionValues, SVGConverter c){
- handleOption(c);
- }
-
- public int getOptionValuesLength(){
- return 0;
- }
-
- public abstract void handleOption(SVGConverter c);
- }
-
- /**
- * Base class for options with a single option value. Subclasses should
- * provide an implementation for the <tt>handleOption</tt> method which
- * takes a <tt>String</tt> and an <tt>SVGConverter</tt> as parameters.
- */
- public static abstract class SingleValueOptionHandler extends AbstractOptionHandler {
- public void safeHandleOption(String[] optionValues, SVGConverter c){
- handleOption(optionValues[0], c);
- }
-
- public int getOptionValuesLength(){
- return 1;
- }
-
- public abstract void handleOption(String optionValue, SVGConverter c);
- }
-
- /**
- * Base class for options which expect the single optionValue to
- * be a float. Subclasses should implement the <tt>handleOption</tt>
- * method which takes a float and an <tt>SVGConverter</tt> as
- * parameters.
- */
- public static abstract class FloatOptionHandler extends SingleValueOptionHandler {
- public void handleOption(String optionValue, SVGConverter c){
- try{
- handleOption(Float.parseFloat(optionValue), c);
- } catch(NumberFormatException e){
- throw new IllegalArgumentException();
- }
- }
-
- public abstract void handleOption(float optionValue, SVGConverter c);
- }
-
- /**
- * Base class for options which expect a <tt>Rectangle</tt> optionValue.
- * Subclasses should implement the <tt>handleOption</tt> method which
- * takes a <tt>Rectangle</tt> and an <tt>SVGConverter</tt> as parameters.
- */
- public static abstract class RectangleOptionHandler extends SingleValueOptionHandler {
- public void handleOption(String optionValue, SVGConverter c){
- Rectangle2D r = parseRect(optionValue);
- if (r==null){
- throw new IllegalArgumentException();
- }
- handleOption(r, c);
- }
-
- public abstract void handleOption(Rectangle2D r, SVGConverter c);
-
- public Rectangle2D.Float parseRect(String rectValue){
- Rectangle2D.Float rect = null;
- if(rectValue != null){
- if (!rectValue.toLowerCase().endsWith("f")){
- rectValue += "f";
- }
-
- StringTokenizer st = new StringTokenizer(rectValue, ",");
- if(st.countTokens() == 4){
- String xStr = st.nextToken();
- String yStr = st.nextToken();
- String wStr = st.nextToken();
- String hStr = st.nextToken();
- float x=Float.NaN, y=Float.NaN, w=Float.NaN, h=Float.NaN;
- try {
- x = Float.parseFloat(xStr);
- y = Float.parseFloat(yStr);
- w = Float.parseFloat(wStr);
- h = Float.parseFloat(hStr);
- }catch(NumberFormatException e){
- // If an error occured, the x, y, w, h
- // values will not be valid
- }
-
- if( !Float.isNaN(x)
- &&
- !Float.isNaN(y)
- &&
- (!Float.isNaN(w) && w > 0)
- &&
- (!Float.isNaN(h) && h > 0) ){
- rect = new Rectangle2D.Float(x, y, w, h);
- }
- }
- }
- return rect;
- }
- }
-
- /**
- * Base class for options which expect a <tt>Color</tt> optionValue.
- * Subclasses should implement the <tt>handleOption</tt> method which
- * takes a <tt>Color</tt> and an <tt>SVGConverter</tt> as parameters.
- */
- public static abstract class ColorOptionHandler extends SingleValueOptionHandler {
- public void handleOption(String optionValue, SVGConverter c){
- Color color = parseARGB(optionValue);
- if (color==null){
- throw new IllegalArgumentException();
- }
- handleOption(color, c);
- }
-
- public abstract void handleOption(Color color, SVGConverter c);
-
- /**
- * Parse the input value, which should be in the following
- * format: a.r.g.b where a, r, g and b are integer values,
- * in decimal notation, between 0 and 255.
- * @return the parsed color if successful. null otherwise.
- */
- public Color parseARGB(String argbVal){
- Color c = null;
- if(argbVal != null){
- StringTokenizer st = new StringTokenizer(argbVal, ".");
- if(st.countTokens() == 4){
- String aStr = st.nextToken();
- String rStr = st.nextToken();
- String gStr = st.nextToken();
- String bStr = st.nextToken();
- int a = -1, r = -1, g = -1, b = -1;
- try {
- a = Integer.parseInt(aStr);
- r = Integer.parseInt(rStr);
- g = Integer.parseInt(gStr);
- b = Integer.parseInt(bStr);
- }catch(NumberFormatException e){
- // If an error occured, the a, r, g, b
- // values will not be in the 0-255 range
- // and the next if test will fail
- }
-
- if( a>=0 && a<=255
- &&
- r>=0 && r<=255
- &&
- g>=0 && g<=255
- &&
- b>=0 && b<=255 ){
- c = new Color(r,g,b,a);
- }
- }
- }
- return c;
- }
- }
-
-
-
- /**
- * Describes the command line options for the rasterizer
- */
- public static String USAGE =
- Messages.formatMessage("Main.usage", null);
-
- //
- // The command line options are found in the properties
- // file.
- //
-
- /**
- * Option to specify the output directory or file
- */
- public static String CL_OPTION_OUTPUT
- = Messages.get("Main.cl.option.output", "-d");
-
- public static String CL_OPTION_OUTPUT_DESCRIPTION
- = Messages.get("Main.cl.option.output.description", "No description");
-
- /**
- * Option to specify the output image's mime type
- */
- public static String CL_OPTION_MIME_TYPE
- = Messages.get("Main.cl.option.mime.type", "-m");
-
- public static String CL_OPTION_MIME_TYPE_DESCRIPTION
- = Messages.get("Main.cl.option.mime.type.description", "No description");
-
- /**
- * Option to specify the output image's width
- */
- public static String CL_OPTION_WIDTH
- = Messages.get("Main.cl.option.width", "-w");
-
- public static String CL_OPTION_WIDTH_DESCRIPTION
- = Messages.get("Main.cl.option.width.description", "No description");
-
- /**
- * Option to specify the output image's height
- */
- public static String CL_OPTION_HEIGHT
- = Messages.get("Main.cl.option.height", "-h");
-
- public static String CL_OPTION_HEIGHT_DESCRIPTION
- = Messages.get("Main.cl.option.height.description", "No description");
-
- /**
- * Option to specify the output image's maximum width.
- */
- public static String CL_OPTION_MAX_WIDTH
- = Messages.get("Main.cl.option.max.width", "-maxw");
-
- public static String CL_OPTION_MAX_WIDTH_DESCRIPTION
- = Messages.get("Main.cl.option.max.width.description", "No description");
-
- /**
- * Option to specify the output image's maximum height.
- */
- public static String CL_OPTION_MAX_HEIGHT
- = Messages.get("Main.cl.option.max.height", "-maxh");
-
- public static String CL_OPTION_MAX_HEIGHT_DESCRIPTION
- = Messages.get("Main.cl.option.max.height.description", "No description");
-
- /**
- * Option to specify the area of interest in the output
- * image.
- */
- public static String CL_OPTION_AOI
- = Messages.get("Main.cl.option.aoi", "-a");
-
- public static String CL_OPTION_AOI_DESCRIPTION
- = Messages.get("Main.cl.option.aoi.description", "No description");
-
- /**
- * Option to specify the output image's background color
- */
- public static String CL_OPTION_BACKGROUND_COLOR
- = Messages.get("Main.cl.option.background.color", "-bg");
-
- public static String CL_OPTION_BACKGROUND_COLOR_DESCRIPTION
- = Messages.get("Main.cl.option.background.color.description", "No description");
-
- /**
- * Option to specify the CSS media type when converting
- * the SVG image
- */
- public static String CL_OPTION_MEDIA_TYPE
- = Messages.get("Main.cl.option.media.type", "-cssMedia");
-
- public static String CL_OPTION_MEDIA_TYPE_DESCRIPTION
- = Messages.get("Main.cl.option.media.type.description", "No description");
-
- /**
- * Option to specify the default value for the font-family
- * CSS property when converting the SVG image
- */
- public static String CL_OPTION_DEFAULT_FONT_FAMILY
- = Messages.get("Main.cl.option.default.font.family", "-font-family");
-
- public static String CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION
- = Messages.get("Main.cl.option.default.font.family.description", "No description");
-
- /**
- * Option to specify the CSS alternate stylesheet when
- * converting the SVG images
- */
- public static String CL_OPTION_ALTERNATE_STYLESHEET
- = Messages.get("Main.cl.option.alternate.stylesheet", "-cssAlternate");
-
- public static String CL_OPTION_ALTERNATE_STYLESHEET_DESCRIPTION
- = Messages.get("Main.cl.option.alternate.stylesheet.description", "No description");
-
- /**
- * Option to specify that the converted SVG files should
- * be validated during the conversion process.
- */
- public static String CL_OPTION_VALIDATE
- = Messages.get("Main.cl.option.validate", "-validate");
-
- public static String CL_OPTION_VALIDATE_DESCRIPTION
- = Messages.get("Main.cl.option.validate.description", "No description");
-
- /**
- * Option to specify that the converted SVG files should
- * be after the dispatch of the 'onload' event.
- */
- public static String CL_OPTION_ONLOAD
- = Messages.get("Main.cl.option.onload", "-onload");
-
- public static String CL_OPTION_ONLOAD_DESCRIPTION
- = Messages.get("Main.cl.option.onload.description", "No description");
-
- /**
- * Option to specify the user language with which SVG
- * documents should be processed
- */
- public static String CL_OPTION_LANGUAGE
- = Messages.get("Main.cl.option.language", "-lang");
-
- public static String CL_OPTION_LANGUAGE_DESCRIPTION
- = Messages.get("Main.cl.option.language.description", "No description");
-
- /**
- * Option to specify an addition user stylesheet
- */
- public static String CL_OPTION_USER_STYLESHEET
- = Messages.get("Main.cl.option.user.stylesheet", "-cssUser");
-
- public static String CL_OPTION_USER_STYLESHEET_DESCRIPTION
- = Messages.get("Main.cl.option.user.stylesheet.description", "No description");
-
- /**
- * Option to specify the resolution for the output image
- */
- public static String CL_OPTION_DPI
- = Messages.get("Main.cl.option.dpi", "-dpi");
-
- public static String CL_OPTION_DPI_DESCRIPTION
- = Messages.get("Main.cl.option.dpi.description", "No description");
-
- /**
- * Option to specify the output JPEG quality
- */
- public static String CL_OPTION_QUALITY
- = Messages.get("Main.cl.option.quality", "-q");
-
- public static String CL_OPTION_QUALITY_DESCRIPTION
- = Messages.get("Main.cl.option.quality.description", "No description");
-
- /**
- * Option to specify if the PNG should be indexed.
- */
- public static String CL_OPTION_INDEXED
- = Messages.get("Main.cl.option.indexed", "-indexed");
-
- public static String CL_OPTION_INDEXED_DESCRIPTION
- = Messages.get("Main.cl.option.indexed.description", "No description");
-
- /**
- * Option to specify the set of allowed scripts
- */
- public static String CL_OPTION_ALLOWED_SCRIPTS
- = Messages.get("Main.cl.option.allowed.scripts", "-scripts");
-
- public static String CL_OPTION_ALLOWED_SCRIPTS_DESCRIPTION
- = Messages.get("Main.cl.option.allowed.scripts.description", "No description");
-
- /**
- * Option to determine whether scripts a constrained to the
- * same origin as the document referencing them.
- */
- public static String CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN
- = Messages.get("Main.cl.option.constrain.script.origin", "-anyScriptOrigin");
-
- public static String CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN_DESCRIPTION
- = Messages.get("Main.cl.option.constrain.script.origin.description", "No description");
-
- /**
- * Option to turn off secure execution of scripts
- */
- public static String CL_OPTION_SECURITY_OFF
- = Messages.get("Main.cl.option.security.off", "-scriptSecurityOff");
-
- public static String CL_OPTION_SECURITY_OFF_DESCRIPTION
- = Messages.get("Main.cl.option.security.off.description", "No description");
-
- /**
- * Static map containing all the option handlers able to analyze the
- * various options.
- */
- protected static Map optionMap = new Hashtable();
-
- /**
- * Static map containing all the mime types understood by the
- * rasterizer
- */
- protected static Map mimeTypeMap = new Hashtable();
-
- /**
- * Static initializer: adds all the option handlers to the
- * map of option handlers.
- */
- static {
- mimeTypeMap.put("image/jpg", DestinationType.JPEG);
- mimeTypeMap.put("image/jpeg", DestinationType.JPEG);
- mimeTypeMap.put("image/jpe", DestinationType.JPEG);
- mimeTypeMap.put("image/png", DestinationType.PNG);
- mimeTypeMap.put("application/pdf", DestinationType.PDF);
- mimeTypeMap.put("image/tiff", DestinationType.TIFF);
-
- optionMap.put(CL_OPTION_OUTPUT,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setDst(new File(optionValue));
- }
- public String getOptionDescription(){
- return CL_OPTION_OUTPUT_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_MIME_TYPE,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- DestinationType dstType =
- (DestinationType)mimeTypeMap.get(optionValue);
-
- if (dstType == null){
- throw new IllegalArgumentException();
- }
-
- c.setDestinationType(dstType);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_MIME_TYPE_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_WIDTH,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0){
- throw new IllegalArgumentException();
- }
-
- c.setWidth(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_WIDTH_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_HEIGHT,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0){
- throw new IllegalArgumentException();
- }
-
- c.setHeight(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_HEIGHT_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_MAX_WIDTH,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0){
- throw new IllegalArgumentException();
- }
-
- c.setMaxWidth(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_MAX_WIDTH_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_MAX_HEIGHT,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0){
- throw new IllegalArgumentException();
- }
-
- c.setMaxHeight(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_MAX_HEIGHT_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_AOI,
- new RectangleOptionHandler(){
- public void handleOption(Rectangle2D optionValue,
- SVGConverter c){
- c.setArea(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_AOI_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_BACKGROUND_COLOR,
- new ColorOptionHandler(){
- public void handleOption(Color optionValue,
- SVGConverter c){
- c.setBackgroundColor(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_BACKGROUND_COLOR_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_MEDIA_TYPE,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setMediaType(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_MEDIA_TYPE_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_DEFAULT_FONT_FAMILY,
- new SingleValueOptionHandler() {
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setDefaultFontFamily(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_ALTERNATE_STYLESHEET,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setAlternateStylesheet(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_ALTERNATE_STYLESHEET_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_USER_STYLESHEET,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setUserStylesheet(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_USER_STYLESHEET_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_LANGUAGE,
- new SingleValueOptionHandler(){
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setLanguage(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_LANGUAGE_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_DPI,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0){
- throw new IllegalArgumentException();
- }
-
- c.setPixelUnitToMillimeter
- ((2.54f/optionValue)*10);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_DPI_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_QUALITY,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if (optionValue <= 0 || optionValue >= 1){
- throw new IllegalArgumentException();
- }
-
- c.setQuality(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_QUALITY_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_INDEXED,
- new FloatOptionHandler(){
- public void handleOption(float optionValue,
- SVGConverter c){
- if ((optionValue != 1) &&
- (optionValue != 2) &&
- (optionValue != 4) &&
- (optionValue != 8))
- throw new IllegalArgumentException();
-
- c.setIndexed((int)optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_INDEXED_DESCRIPTION;
- }
- });
- optionMap.put(CL_OPTION_VALIDATE,
- new NoValueOptionHandler(){
- public void handleOption(SVGConverter c){
- c.setValidate(true);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_VALIDATE_DESCRIPTION;
- }
- });
- optionMap.put(CL_OPTION_ONLOAD,
- new NoValueOptionHandler(){
- public void handleOption(SVGConverter c){
- c.setExecuteOnload(true);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_ONLOAD_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_ALLOWED_SCRIPTS,
- new SingleValueOptionHandler() {
- public void handleOption(String optionValue,
- SVGConverter c){
- c.setAllowedScriptTypes(optionValue);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_ALLOWED_SCRIPTS_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN,
- new NoValueOptionHandler(){
- public void handleOption(SVGConverter c){
- c.setConstrainScriptOrigin(false);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN_DESCRIPTION;
- }
- });
-
- optionMap.put(CL_OPTION_SECURITY_OFF,
- new NoValueOptionHandler() {
- public void handleOption(SVGConverter c){
- c.setSecurityOff(true);
- }
-
- public String getOptionDescription(){
- return CL_OPTION_SECURITY_OFF_DESCRIPTION;
- }
- });
- }
-
- /**
- * Vector of arguments describing the conversion task to be
- * performed.
- */
- protected Vector args;
-
- public Main(String[] args){
- this.args = new Vector();
- for (int i=0; i<args.length; i++){
- this.args.addElement(args[i]);
- }
- }
-
- protected void error(String errorCode,
- Object[] errorArgs){
- System.err.println(Messages.formatMessage(errorCode,
- errorArgs));
- }
-
- //
- // Error codes generated by the rasterizer
- //
-
- /**
- * Error when there are missing option values:
- * {0} Option
- * {1} Option description
- */
- public static final String ERROR_NOT_ENOUGH_OPTION_VALUES
- = "Main.error.not.enough.option.values";
-
- /**
- * Error when an illegal option value was passed to the app
- * {0} Option
- * {1} Option description
- */
- public static final String ERROR_ILLEGAL_ARGUMENT
- = "Main.error.illegal.argument";
-
- public static final String ERROR_WHILE_CONVERTING_FILES
- = "Main.error.while.converting.files";
-
- public void execute(){
- SVGConverter c = new SVGConverter(this);
-
- Vector sources = new Vector();
-
- int nArgs = args.size();
- for (int i=0; i<nArgs; i++){
- String v = (String)args.elementAt(i);
- OptionHandler optionHandler = (OptionHandler)optionMap.get(v);
- if (optionHandler == null){
- // Assume v is a source.
- sources.addElement(v);
- } else {
- // v is an option. Extract the optionValues required
- // by the handler.
- int nOptionArgs = optionHandler.getOptionValuesLength();
- if (i + nOptionArgs >= nArgs){
- error(ERROR_NOT_ENOUGH_OPTION_VALUES, new Object[]{ v, optionHandler.getOptionDescription()});
- return;
- }
-
- String[] optionValues = new String[nOptionArgs];
- for (int j=0; j<nOptionArgs; j++){
- optionValues[j] = (String)args.elementAt(1+i+j);
- }
- i += nOptionArgs;
-
- try {
- optionHandler.handleOption(optionValues, c);
- } catch(IllegalArgumentException e){
- e.printStackTrace();
- error(ERROR_ILLEGAL_ARGUMENT,
- new Object[] { v,
- optionHandler.getOptionDescription() ,
- toString(optionValues)});
- return;
- }
- }
- }
-
- // Apply script security option
- ApplicationSecurityEnforcer securityEnforcer =
- new ApplicationSecurityEnforcer(this.getClass(),
- RASTERIZER_SECURITY_POLICY);
-
- securityEnforcer.enforceSecurity(!c.getSecurityOff());
-
- String expandedSources[] = expandSources(sources);
-
- c.setSources(expandedSources);
-
- validateConverterConfig(c);
-
- if (expandedSources== null || expandedSources.length < 1){
- System.out.println(USAGE);
- System.out.flush();
- securityEnforcer.enforceSecurity(false);
- return;
- }
-
- try {
- c.execute();
- } catch(SVGConverterException e){
- error(ERROR_WHILE_CONVERTING_FILES,
- new Object[] { e.getMessage() });
- } finally {
- System.out.flush();
- securityEnforcer.enforceSecurity(false);
- }
- }
-
- protected String toString(String[] v){
- StringBuffer sb = new StringBuffer();
- int n = v != null ? v.length:0;
- for (int i=0; i<n; i++){
- sb.append(v[i] + " ");
- }
-
- return sb.toString();
- }
-
- /**
- * Template methods which subclasses may implement to do whatever is
- * needed. For example, this can be used for test purposes.
- */
- public void validateConverterConfig(SVGConverter c){
- }
-
- /**
- * Scans the input vector and replaces directories with the list
- * of SVG files they contain
- */
- protected String[] expandSources(Vector sources){
- Vector expandedSources = new Vector();
- Iterator iter = sources.iterator();
- while (iter.hasNext()){
- String v = (String)iter.next();
- File f = new File(v);
- if (f.exists() && f.isDirectory()){
- File[] fl = f.listFiles(new SVGConverter.SVGFileFilter());
- for (int i=0; i<fl.length; i++){
- expandedSources.addElement(fl[i].getPath());
- }
- } else {
- expandedSources.addElement(v);
- }
- }
-
- String[] s = new String[expandedSources.size()];
- expandedSources.copyInto(s);
- return s;
- }
-
- public static void main(String [] args) {
- (new Main(args)).execute();
- System.exit(0);
- }
-
- //
- // SVGConverterController implementation
- //
- public static final String MESSAGE_ABOUT_TO_TRANSCODE
- = "Main.message.about.to.transcode";
-
- public static final String MESSAGE_ABOUT_TO_TRANSCODE_SOURCE
- = "Main.message.about.to.transcode.source";
-
- public static final String MESSAGE_CONVERSION_FAILED
- = "Main.message.conversion.failed";
-
- public static final String MESSAGE_CONVERSION_SUCCESS
- = "Main.message.conversion.success";
-
- public boolean proceedWithComputedTask(Transcoder transcoder,
- Map hints,
- Vector sources,
- Vector dest){
- System.out.println(Messages.formatMessage(MESSAGE_ABOUT_TO_TRANSCODE,
- new Object[]{"" + sources.size()}));
- return true;
- }
-
- public boolean proceedWithSourceTranscoding(SVGConverterSource source,
- File dest){
- System.out.print(Messages.formatMessage(MESSAGE_ABOUT_TO_TRANSCODE_SOURCE,
- new Object[]{source.toString(),
- dest.toString()}));
- return true;
- }
-
- public boolean proceedOnSourceTranscodingFailure(SVGConverterSource source,
- File dest,
- String errorCode){
- System.out.println(Messages.formatMessage(MESSAGE_CONVERSION_FAILED,
- new Object[]{errorCode}));
-
- return true;
- }
-
- public void onSourceTranscodingSuccess(SVGConverterSource source,
- File dest){
- System.out.println(Messages.formatMessage(MESSAGE_CONVERSION_SUCCESS,
- null));
- }
-}
-
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f690ea2f/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Messages.java
----------------------------------------------------------------------
diff --git a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Messages.java b/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Messages.java
deleted file mode 100644
index 027be3e..0000000
--- a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/Messages.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
-
- Copyright 2001,2003 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- */
-package org.apache.flex.forks.batik.apps.rasterizer;
-
-import java.util.Locale;
-import java.util.MissingResourceException;
-
-import org.apache.flex.forks.batik.i18n.LocalizableSupport;
-
-/**
- * This class manages the message for the bridge module.
- *
- * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: Messages.java,v 1.6 2004/08/18 07:12:26 vhardy Exp $
- */
-public class Messages {
-
- /**
- * This class does not need to be instantiated.
- */
- protected Messages() { }
-
- /**
- * The error messages bundle class name.
- */
- protected final static String RESOURCES =
- "org.apache.flex.forks.batik.apps.rasterizer.resources.Messages";
-
- /**
- * The localizable support for the error messages.
- */
- protected static LocalizableSupport localizableSupport =
- new LocalizableSupport(RESOURCES, Messages.class.getClassLoader());
-
- /**
- * Implements {@link org.apache.flex.forks.batik.i18n.Localizable#setLocale(Locale)}.
- */
- public static void setLocale(Locale l) {
- localizableSupport.setLocale(l);
- }
-
- /**
- * Implements {@link org.apache.flex.forks.batik.i18n.Localizable#getLocale()}.
- */
- public static Locale getLocale() {
- return localizableSupport.getLocale();
- }
-
- /**
- * Implements {@link
- * org.apache.flex.forks.batik.i18n.Localizable#formatMessage(String,Object[])}.
- */
- public static String formatMessage(String key, Object[] args)
- throws MissingResourceException {
- return localizableSupport.formatMessage(key, args);
- }
-
- public static String get(String key)
- throws MissingResourceException {
- return formatMessage(key, null);
- }
-
- public static String get(String key, String def){
- String value = def;
- try{
- value = get(key);
- }catch(MissingResourceException e){
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f690ea2f/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverter.java
----------------------------------------------------------------------
diff --git a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverter.java b/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverter.java
deleted file mode 100644
index 3162d74..0000000
--- a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverter.java
+++ /dev/null
@@ -1,1119 +0,0 @@
-/*
-
- Copyright 2001-2003 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- */
-package org.apache.flex.forks.batik.apps.rasterizer;
-
-import java.awt.Color;
-import java.awt.geom.Rectangle2D;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-
-import org.apache.flex.forks.batik.transcoder.Transcoder;
-import org.apache.flex.forks.batik.transcoder.TranscoderInput;
-import org.apache.flex.forks.batik.transcoder.TranscoderOutput;
-import org.apache.flex.forks.batik.transcoder.image.ImageTranscoder;
-import org.apache.flex.forks.batik.transcoder.image.JPEGTranscoder;
-import org.apache.flex.forks.batik.transcoder.image.PNGTranscoder;
-
-/**
- * This application can be used to convert SVG images to raster images.
- * <br />
- * Possible result raster image formats are PNG, JPEG, TIFF, and PDF.
- * The Batik Transcoder API is used to execute the conversion. FOP is
- * needed to be able to transcode to the PDF format<br />
- *
- * The source has to be list of files or URL (set by the <tt>setSources</tt>
- * method). <br />
- *
- * The destination can be:<br /><ul>
- * <li><b>unspecified</b>. In that case, only file sources can be converted and
- * a file in the same directory as the source will be created.</li>
- * <li><b>a directory</b>, set by the <tt>setDst</tt> method. In that case,
- * the output files are created in that destination directory</li>
- * <li><b>a file</b>. In case there is a <i>single
- * source</i>, the destination can be a single named file
- * (set with the <tt>setDst</tt> method.</li>)<br />
- * </ul>
- *
- * <hr />
- *
- * There are a number of options which control the way the image is
- * converted to the destination format:<br /><ul>
- * <li>destinationType: controls the type of conversion which should be done.
- * see the {@link DestinationType} documentation.</li>
- * <li>width/height: they control the desired width and height, in user space,
- * for the output image.</li>
- * <li>maxWidth/maxHeight: control the maximum width and height,
- * in user space, of the output image.</li>
- * <li>area: controls the specific sub-area of the image which should be
- * rendered.</li>
- * <li>backgroundColor: controls the color which is used to fill the
- * background before rendering the image</li>
- * <li>quality: relevant only for JPEG destinations, this controls the
- * encoding quality.</li>
- * <li>indexed: relevant only for PNG, controls the number of bits
- * used in writting of a palletized files.</li>
- * <li>mediaType: controls the CSS media, or list of media, for which the
- * image should be rendered.</li>
- * <li>alternate: controls the alternate CSS stylesheet to activate,
- * if any.</li>
- * <li>language: controls the user language with which the SVG document
- * should be converted.</li>
- * <li>userStylesheet: defines the user stylesheet to apply to SVG documents
- * in addition to other stylesheets referenced by or embedded in the
- * SVG documents.</li>
- * <li>pixelUnitToMillimeter: defines the size of a pixel in millimeters
- * to use when processing the SVG documents.</li>
- * </ul>
- *
- * @version $Id: SVGConverter.java,v 1.22 2005/03/27 08:58:29 cam Exp $
- * @author <a href="mailto:Henri.Ruini@nokia.com">Henri Ruini</a>
- * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- */
-public class SVGConverter {
- //
- // Error codes reported by the SVGConverter
- //
-
- //
- // Reported when no source file has been specified.
- //
- public static final String ERROR_NO_SOURCES_SPECIFIED
- = "SVGConverter.error.no.sources.specified";
-
- //
- // Reported when there is more than one valid input source
- // and no output directory has been set and the source is
- // not a file.
- //
- public static final String ERROR_CANNOT_COMPUTE_DESTINATION
- = "SVGConverter.error.cannot.compute.destination";
-
- //
- // Reported when the dst is a file and there are multiple
- // sources.
- //
- public static final String ERROR_CANNOT_USE_DST_FILE
- = "SVGConverter.error.cannot.use.dst.file";
-
- //
- // Reported when the <tt>Transcoder</tt> for the requested
- // <tt>destinationType</tt> cannot be found.
- //
- public static final String ERROR_CANNOT_ACCESS_TRANSCODER
- = "SVGConverter.error.cannot.access.transcoder";
-
- //
- // Reported when the source is found to be the same as
- // the destination. Note that it is not guaranteed that
- // this error condition will always be detected.
- //
- public static final String ERROR_SOURCE_SAME_AS_DESTINATION
- = "SVGConverter.error.source.same.as.destination";
-
- //
- // Reported when one of the sources cannot be read.
- //
- public static final String ERROR_CANNOT_READ_SOURCE
- = "SVGConverter.error.cannot.read.source";
-
- //
- // Reported when an error happens while opening a source
- // file.
- //
- public static final String ERROR_CANNOT_OPEN_SOURCE
- = "SVGConverter.error.cannot.open.source";
-
- //
- // Reported if the output is not writeable. This may
- // happen if the output file already exists and does not
- // have write permission.
- //
- public static final String ERROR_OUTPUT_NOT_WRITEABLE
- = "SVGConverter.error.output.not.writeable";
-
- //
- // Reported when an error happens while trying to open
- // the output file for writing.
- //
- public static final String ERROR_CANNOT_OPEN_OUTPUT_FILE
- = "SVGConverter.error.cannot.open.output.file";
-
- //
- // Reported when the converter was not able to create
- // the destination directory for the files.
- //
- public static final String ERROR_UNABLE_TO_CREATE_OUTPUT_DIR
- = "SVGConverter.error.unable.to.create.output.dir";
-
- //
- // Reported when an error occurs while convertion the
- // source file.
- //
- public static final String ERROR_WHILE_RASTERIZING_FILE
- = "SVGConverter.error.while.rasterizing.file";
-
- //
- // Class variables and constants
- //
-
- /** SVG file extension */
- protected static final String SVG_EXTENSION = ".svg";
-
- /** Default quality value. A value of -1 means disabled. */
- protected static final float DEFAULT_QUALITY
- = -1f;
-
- /** Maximum quality value */
- protected static final float MAXIMUM_QUALITY
- = .99F;
-
- /** Default result type */
- protected static final DestinationType DEFAULT_RESULT_TYPE
- = DestinationType.PNG;
-
- /** Default width */
- protected static final float DEFAULT_WIDTH = -1;
-
- /** Default height */
- protected static final float DEFAULT_HEIGHT = -1;
-
- /** Result type */
- protected DestinationType destinationType = DEFAULT_RESULT_TYPE;
-
- /** Output image height. */
- protected float height = DEFAULT_HEIGHT;
-
- /** Output image width. */
- protected float width = DEFAULT_WIDTH;
-
- /** Maximum output image height. */
- protected float maxHeight = DEFAULT_HEIGHT;
-
- /** Maximum output image width. */
- protected float maxWidth = DEFAULT_WIDTH;
-
- /** Output image quality. */
- protected float quality = DEFAULT_QUALITY;
-
- /** Should output Image be indexed . */
- protected int indexed = -1;
-
- /** Output AOI area. */
- protected Rectangle2D area = null;
-
- /** Language */
- protected String language = null;
-
- /** User stylesheet */
- protected String userStylesheet = null;
-
- /** Millimeters Per Pixel */
- protected float pixelUnitToMillimeter = -1f;
-
- /** Validation flag */
- protected boolean validate = false;
-
- /** Execute the 'onload' scripts flag */
- protected boolean executeOnload = false;
-
- /** Set of allowed script types. */
- protected String allowedScriptTypes = null;
-
- /** Controls whether scripts can only have the same origin as
- the document which references them. */
- protected boolean constrainScriptOrigin = true;
-
- /** Controls whether scripts should be run securely or not */
- protected boolean securityOff = false;
-
- /** Sources files or URLs */
- protected Vector sources = null;
-
- /**
- * Destination image path. Can be a file (for single source) or
- * a directory
- */
- protected File dst;
-
- /** Background color for the output images. */
- protected Color backgroundColor = null;
-
- /** Media type for which the SVG image should be rendered */
- protected String mediaType = null;
-
- /** Default value for the font-family when it is unspecified */
- protected String defaultFontFamily = null;
-
- /** Alternate stylesheet for which should be applied to the SVG */
- protected String alternateStylesheet = null;
-
- /** Contents of <tt>fileset</tt> elements. */
- protected Vector files = new Vector();
-
- /**
- * Controls some aspects of the converter's operation,
- * such as whether or not it should proceed in some
- * error situations. See {@link SVGConverterController}
- */
- protected SVGConverterController controller;
-
- //
- // Default constructor
- //
- public SVGConverter(){
- this(new DefaultSVGConverterController());
- }
-
- //
- // Constructor
- //
- public SVGConverter(SVGConverterController controller){
- if (controller == null){
- throw new IllegalArgumentException();
- }
-
- this.controller = controller;
- }
-
- //
- // Property get/set methods
- //
-
- /**
- * Sets the <tt>destinationType</tt> attribute value.
- * Should not be null.
- */
- public void setDestinationType(DestinationType destinationType) {
- if(destinationType == null){
- throw new IllegalArgumentException();
- }
- this.destinationType = destinationType;
- }
-
- public DestinationType getDestinationType(){
- return destinationType;
- }
-
- /**
- * In less than or equal to zero, the height is not
- * constrained on the output image. The height is in
- * user space.
- */
- public void setHeight(float height) {
- this.height = height;
- }
-
- public float getHeight(){
- return height;
- }
-
- /**
- * In less than or equal to zero, the width is not
- * constrained on the output image. The width is in
- * user space.
- */
- public void setWidth(float width) {
- this.width = width;
- }
-
- public float getWidth(){
- return width;
- }
-
- /**
- * If less than or equal to zero, the maximum height
- * does not have any effect on the output image.
- * The maximum height is in user space.
- */
- public void setMaxHeight(float height) {
- this.maxHeight = height;
- }
-
- public float getMaxHeight(){
- return maxHeight;
- }
-
- /**
- * If less than or equal to zero, the maximum width
- * does not have any effect on the output image.
- * The maximum width is in user space.
- */
- public void setMaxWidth(float width) {
- this.maxWidth = width;
- }
-
- public float getMaxWidth(){
- return maxWidth;
- }
-
- /**
- * Sets the JPEG encoding quality. The value should be strictly
- * less than 1. If the value is less than zero, then the maximum
- * encoding quality is used.
- */
- public void setQuality(float quality) throws IllegalArgumentException {
- if(quality >= 1){
- throw new IllegalArgumentException();
- }
-
- this.quality = quality;
- }
-
- public float getQuality(){
- return quality;
- }
-
- /**
- * Tells the PNG encoder to reduce the image to 256 colors, so the
- * PNG file is indexed.
- */
- public void setIndexed(int bits) throws IllegalArgumentException {
- this.indexed = bits;
- }
-
- public int getIndexed(){
- return indexed;
- }
-
- /**
- * Sets the user language. If the value is null, then the default (see
- * {@link org.apache.flex.forks.batik.bridge.UserAgent#getLanguages})
- * is used.
- */
- public void setLanguage(String language){
- this.language = language;
- }
-
- public String getLanguage(){
- return language;
- }
-
- /**
- * Sets the user stylesheet. May be null.
- */
- public void setUserStylesheet(String userStylesheet){
- this.userStylesheet = userStylesheet;
- }
-
- public String getUserStylesheet(){
- return userStylesheet;
- }
-
- /**
- * Sets the millimeters per pixel constant. A negative
- * value will cause the default value
- * (see {@link org.apache.flex.forks.batik.bridge.UserAgent#getPixelUnitToMillimeter})
- * to be used.
- */
- public void setPixelUnitToMillimeter(float pixelUnitToMillimeter){
- this.pixelUnitToMillimeter = pixelUnitToMillimeter;
- }
-
- public float getPixelUnitToMillimeter(){
- return pixelUnitToMillimeter;
- }
-
- /**
- * Sets the <tt>area</tt> as a Rectangle. This value can
- * be null in which case the whole image will be rendered. If the
- * area is not null, then only the portion of the image it
- * defines will be rendered.
- */
- public void setArea(Rectangle2D area){
- this.area = area;
- }
-
- public Rectangle2D getArea(){
- return area;
- }
-
- /**
- * Sets the list of individual SVG sources. The strings
- * can be either URLs or file names. Note that invalid
- * sources (e.g., read-protected files or invalid URLs)
- * will cause <tt>SVGConverterExceptions</tt> to be
- * thrown during the transcoding process (see {@link #execute});
- */
- public void setSources(String[] sources) {
- if(sources == null){
- this.sources = null;
- }
- else{
- this.sources = new Vector();
- for (int i=0; i<sources.length; i++){
- if (sources[i] != null){
- this.sources.addElement(sources[i]);
- }
- }
-
- if (this.sources.size() == 0){
- this.sources = null;
- }
- }
- }
-
- public Vector getSources(){
- return sources;
- }
-
- /**
- * When converting a single source, dst can be a file.
- * Othewise, it should be a directory.
- */
- public void setDst(File dst) {
- this.dst = dst;
- }
-
- public File getDst(){
- return dst;
- }
-
- /**
- * Sets the <tt>backgroundColor</tt> value. This can be
- * null in which case no color will be used to fill the
- * background before rendering this SVG image.
- */
- public void setBackgroundColor(Color backgroundColor){
- this.backgroundColor = backgroundColor;
- }
-
- public Color getBackgroundColor(){
- return backgroundColor;
- }
-
- /**
- * Sets the <tt>mediaType</tt> value. This value controls
- * the CSS media for which the image should be rendered. It
- * can be null, in which case no specific media selectors will
- * apply. If it is not null, it can contain space separated values
- * of the medias for which the image should be rendered. For example,
- * "screen", "print" or "scree projection" are valid values.
- */
- public void setMediaType(String mediaType){
- this.mediaType = mediaType;
- }
-
- public String getMediaType(){
- return mediaType;
- }
-
- /**
- * Sets the <tt>defaultFontFamily</tt> value. This value controls
- * the default value for the font-family CSS property when that
- * property is unspecified.
- */
- public void setDefaultFontFamily(String defaultFontFamily) {
- this.defaultFontFamily = defaultFontFamily;
- }
-
- public String getDefaultFontFamily() {
- return defaultFontFamily;
- }
-
- /**
- * Sets the <tt>alternateStyleSheet</tt> value. This value
- * controls the CSS alternate stylesheet to select in the
- * rendered SVG file(s). It may be null, in which case no alternate
- * stylesheet will be selected.
- */
- public void setAlternateStylesheet(String alternateStylesheet){
- this.alternateStylesheet = alternateStylesheet;
- }
-
- public String getAlternateStylesheet(){
- return alternateStylesheet;
- }
-
- /**
- * Defines whether or not input sources should be validated in
- * the conversion process
- */
- public void setValidate(boolean validate){
- this.validate = validate;
- }
-
- public boolean getValidate(){
- return validate;
- }
-
- /**
- * Sets whether or not scripts attached to the DOM using 'onload'
- * event attribute must be executed before rasterizing.
- *
- * @param b true means scripts will be executed
- */
- public void setExecuteOnload(boolean b){
- this.executeOnload = b;
- }
-
- /**
- * Returns true if the scripts attached to the DOM using 'onload'
- * event attribute is going to be executed before rasterizing,
- * false otherwise.
- */
- public boolean getExecuteOnload(){
- return executeOnload;
- }
-
- /**
- * Sets the set of allowed script types (i.e., the set of possible
- * values for the type attribute in the <script> element),
- * as a comma separated list of allowed values.
- */
- public void setAllowedScriptTypes(String allowedScriptTypes){
- this.allowedScriptTypes = allowedScriptTypes;
- }
-
- /**
- * Returns the list of allowed script types.
- *
- * @see #setAllowedScriptTypes
- */
- public String getAllowedScriptTypes(){
- return allowedScriptTypes;
- }
-
- /**
- * Sets whether scripts should only be loaded from the same
- * location as the documents referencing them.
- */
- public void setConstrainScriptOrigin(boolean constrainScriptOrigin){
- this.constrainScriptOrigin = constrainScriptOrigin;
- }
-
- /**
- * Returns whether scripts can only be loaded from the same
- * origin as the documents referencing them.
- */
- public boolean getConstrainScriptOrigin(){
- return constrainScriptOrigin;
- }
-
- /**
- * Sets whether or not scripts should be run securely
- */
- public void setSecurityOff(boolean securityOff){
- this.securityOff = securityOff;
- }
-
- /**
- * Returns whether or not scripts will be run securely
- */
- public boolean getSecurityOff(){
- return securityOff;
- }
-
- /**
- * Returns true if f is a File. <code>f</code> is found to be a file if
- * it exists and is a file. If it does not exist, it is declared
- * to be a file if it has the same extension as the DestinationType.
- */
- protected boolean isFile(File f){
- if (f.exists()){
- return f.isFile();
- } else {
- if (f.toString().toLowerCase().endsWith(destinationType.getExtension())){
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Starts the conversion process.
- * @throws SVGConverterException thrown if parameters are not set correctly.
- */
- public void execute() throws SVGConverterException {
- // Compute the set of SVGConverterSource from the source properties
- // (srcDir and srcFile);
- // This throws an exception if there is not at least one src file.
- Vector sources = computeSources();
-
- // Compute the destination files from dest
- Vector dstFiles = null;
- if(sources.size() == 1 && dst != null && isFile(dst)){
- dstFiles = new Vector();
- dstFiles.addElement(dst);
- }
- else{
- dstFiles = computeDstFiles(sources);
- }
-
- // Now, get the transcoder to use for the operation
- Transcoder transcoder = destinationType.getTranscoder();
- if(transcoder == null) {
- throw new SVGConverterException(ERROR_CANNOT_ACCESS_TRANSCODER,
- new Object[]{destinationType.toString()},
- true /* fatal error */);
- }
-
- // Now, compute the set of transcoding hints to use
- Map hints = computeTranscodingHints();
- transcoder.setTranscodingHints(hints);
-
- // Notify listener that task has been computed
- if(!controller.proceedWithComputedTask(transcoder,
- hints,
- sources,
- dstFiles)){
- return;
- }
-
- // Convert files one by one
- for(int i = 0 ; i < sources.size() ; i++) {
- // Get the file from the vector.
- SVGConverterSource currentFile
- = (SVGConverterSource)sources.elementAt(i);
- File outputFile = (File)dstFiles.elementAt(i);
-
- createOutputDir(outputFile);
- transcode(currentFile, outputFile, transcoder);
- }
- }
-
- /**
- * Populates a vector with destination files names
- * computed from the names of the files in the sources vector
- * and the value of the dst property
- */
- protected Vector computeDstFiles(Vector sources)
- throws SVGConverterException {
- Vector dstFiles = new Vector();
- if (dst != null) {
- if (dst.exists() && dst.isFile()) {
- throw new SVGConverterException(ERROR_CANNOT_USE_DST_FILE);
- }
-
- //
- // Either dst exist and is a directory or dst does not
- // exist and we may fail later on in createOutputDir
- //
- int n = sources.size();
- for(int i=0; i<n; i++){
- SVGConverterSource src = (SVGConverterSource)sources.elementAt(i);
- // Generate output filename from input filename.
- File outputName = new File(dst.getPath(),
- getDestinationFile(src.getName()));
- dstFiles.addElement(outputName);
-
- }
- } else {
- //
- // No destination directory has been specified.
- // Try and create files in the same directory as the
- // sources. This only work if sources are files.
- //
- int n = sources.size();
- for(int i=0; i<n; i++){
- SVGConverterSource src = (SVGConverterSource)sources.elementAt(i);
- if (!(src instanceof SVGConverterFileSource)) {
- throw new SVGConverterException(ERROR_CANNOT_COMPUTE_DESTINATION,
- new Object[]{src});
- }
-
- // Generate output filename from input filename.
- SVGConverterFileSource fs = (SVGConverterFileSource)src;
- File outputName = new File(fs.getFile().getParent(),
- getDestinationFile(src.getName()));
- dstFiles.addElement(outputName);
- }
-
- }
-
- return dstFiles;
- }
-
- /**
- * Populates a vector with the set of SVG files from the
- * srcDir if it is not null and with the sources (files or URLs)
- * if any.
- */
- protected Vector computeSources() throws SVGConverterException{
- Vector sources = new Vector();
-
- // Check that at least one source has been specified.
- if (this.sources == null){
- throw new SVGConverterException(ERROR_NO_SOURCES_SPECIFIED);
- }
-
- int n = this.sources.size();
- for (int i=0; i<n; i++){
- String sourceString = (String)(this.sources.elementAt(i));
- File file = new File(sourceString);
- if (file.exists()) {
- sources.addElement(new SVGConverterFileSource(file));
- } else {
- String[] fileNRef = getFileNRef(sourceString);
- file = new File(fileNRef[0]);
- if (file.exists()){
- sources.addElement(new SVGConverterFileSource(file, fileNRef[1]));
- } else{
- sources.addElement(new SVGConverterURLSource(sourceString));
- }
- }
- }
-
- return sources;
- }
-
- public String[] getFileNRef(String fileName){
- int n = fileName.lastIndexOf("#");
- String[] result = {fileName, ""};
- if (n > -1){
- result[0] = fileName.substring(0, n);
- if (n+1 < fileName.length()){
- result[1] = fileName.substring(n+1);
- }
- }
-
- return result;
- }
-
- // -----------------------------------------------------------------------
- // Internal methods
- // -----------------------------------------------------------------------
-
- /**
- * Computes the set of transcoding hints to use for the operation
- */
- protected Map computeTranscodingHints(){
- HashMap map = new HashMap();
-
- // Set AOI. ----------------------------------------------------------
- if (area != null) {
- map.put(ImageTranscoder.KEY_AOI, area);
- }
-
- // Set image quality. ------------------------------------------------
- if (quality > 0) {
- map.put(JPEGTranscoder.KEY_QUALITY, new Float(this.quality));
- }
-
- // Set image indexed. ------------------------------------------------
- if (indexed != -1) {
- map.put(PNGTranscoder.KEY_INDEXED, new Integer(indexed));
- }
-
- // Set image background color -----------------------------------------
- if (backgroundColor != null){
- map.put(ImageTranscoder.KEY_BACKGROUND_COLOR, backgroundColor);
- }
-
- // Set image height and width. ----------------------------------------
- if (height > 0) {
- map.put(ImageTranscoder.KEY_HEIGHT, new Float(this.height));
- }
- if (width > 0){
- map.put(ImageTranscoder.KEY_WIDTH, new Float(this.width));
- }
-
- // Set maximum height and width ---------------------------------------
- if (maxHeight > 0) {
- map.put(ImageTranscoder.KEY_MAX_HEIGHT, new Float(this.maxHeight));
- }
- if (maxWidth > 0){
- map.put(ImageTranscoder.KEY_MAX_WIDTH, new Float(this.maxWidth));
- }
-
- // Set CSS Media
- if (mediaType != null){
- map.put(ImageTranscoder.KEY_MEDIA, mediaType);
- }
-
- // Set default font-family
- if (defaultFontFamily != null) {
- map.put(ImageTranscoder.KEY_DEFAULT_FONT_FAMILY, defaultFontFamily);
- }
-
- // Set alternateStylesheet
- if (alternateStylesheet != null){
- map.put(ImageTranscoder.KEY_ALTERNATE_STYLESHEET, alternateStylesheet);
- }
-
- // Set user stylesheet
- if (userStylesheet != null){
- map.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, userStylesheet);
- }
-
- // Set the user language
- if (language != null){
- map.put(ImageTranscoder.KEY_LANGUAGE, language);
- }
-
- // Sets the millimeters per pixel
- if (pixelUnitToMillimeter > 0){
- map.put(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,
- new Float(pixelUnitToMillimeter));
- }
-
- // Set validation
- if (validate){
- map.put(ImageTranscoder.KEY_XML_PARSER_VALIDATING,
- new Boolean(validate));
- }
-
- // Set onload
- if (executeOnload) {
- map.put(ImageTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(executeOnload));
- }
-
- // Set allowed scripts
- if (allowedScriptTypes != null) {
- map.put(ImageTranscoder.KEY_ALLOWED_SCRIPT_TYPES, allowedScriptTypes);
- }
-
- // Set constrain script origin
- if (!constrainScriptOrigin) {
- map.put(ImageTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN,
- new Boolean(constrainScriptOrigin));
- }
-
- return map;
- }
-
- /**
- * Converts the input image to the result image.
- * with the given transcoder. If a failure happens, the
- * controller is notified and decides whether to proceed
- * or not. If it decides to proceed, the converter will
- * continue processing other files. Otherwise, it will
- * throw an exception.
- */
- protected void transcode(SVGConverterSource inputFile,
- File outputFile,
- Transcoder transcoder)
- throws SVGConverterException {
- TranscoderInput input = null;
- TranscoderOutput output = null;
- OutputStream outputStream = null;
-
- if (!controller.proceedWithSourceTranscoding(inputFile,
- outputFile)){
- return;
- }
-
- try {
- if (inputFile.isSameAs(outputFile.getPath())) {
- throw new SVGConverterException(ERROR_SOURCE_SAME_AS_DESTINATION,
- true /* fatal error */);
- }
-
- // Compute transcoder input.
- if (!inputFile.isReadable()) {
- throw new SVGConverterException(ERROR_CANNOT_READ_SOURCE,
- new Object[]{inputFile.getName()});
- }
-
- try {
- InputStream in = inputFile.openStream();
- in.close();
- } catch(IOException ioe) {
- throw new SVGConverterException(ERROR_CANNOT_OPEN_SOURCE,
- new Object[] {inputFile.getName(),
- ioe.toString()});
- }
-
- input = new TranscoderInput(inputFile.getURI());
-
- // Compute transcoder output.
- if (!isWriteable(outputFile)) {
- throw new SVGConverterException(ERROR_OUTPUT_NOT_WRITEABLE,
- new Object[] {outputFile.getName()});
- }
- try {
- outputStream = new FileOutputStream(outputFile);
- } catch(FileNotFoundException fnfe) {
- throw new SVGConverterException(ERROR_CANNOT_OPEN_OUTPUT_FILE,
- new Object[] {outputFile.getName()});
- }
-
- output = new TranscoderOutput(outputStream);
- } catch(SVGConverterException e){
- boolean proceed = controller.proceedOnSourceTranscodingFailure
- (inputFile, outputFile, e.getErrorCode());
- if (proceed){
- return;
- } else {
- throw e;
- }
- }
-
- // Transcode now
- boolean success = false;
- try {
- transcoder.transcode(input, output);
- success = true;
- } catch(Exception te) {
- te.printStackTrace();
- try {
- outputStream.flush();
- outputStream.close();
- } catch(IOException ioe) {}
-
- // Report error to the controller. If controller decides
- // to stop, throw an exception
- boolean proceed = controller.proceedOnSourceTranscodingFailure
- (inputFile, outputFile, ERROR_WHILE_RASTERIZING_FILE);
-
- if (!proceed){
- throw new SVGConverterException(ERROR_WHILE_RASTERIZING_FILE,
- new Object[] {outputFile.getName(),
- te.getMessage()});
- }
- }
-
- // Close streams and clean up.
- try {
- outputStream.flush();
- outputStream.close();
- } catch(IOException ioe) {
- return;
- }
-
- if (success){
- controller.onSourceTranscodingSuccess(inputFile, outputFile);
- }
- }
-
- /**
- * Get the name of the result image file.
- *
- * <P>This method modifies the result filename, it changes the existing
- * suffix to correspong the result file type. It also adds the suffix
- * if the file doesn't have one.</P>
- *
- * @param file Result file name as a String object.
- *
- * @return Name of the file. The directory of the file is not returned.
- * The returned string is empty if the parameter is not a file.
- */
- protected String getDestinationFile(String file) {
- int suffixStart; // Location of the first char of
- // the suffix in a String.
- String oldName; // Existing filename.
- String newSuffix = destinationType.getExtension();
- // New suffix.
-
- oldName = file;
- // Find the first char of the suffix.
- suffixStart = oldName.lastIndexOf(".");
- String dest = null;
- if (suffixStart != -1) {
- // Replace existing suffix.
- dest = new String(oldName.substring(0, suffixStart) + newSuffix);
- } else {
- // Add new suffix.
- dest = new String(oldName + newSuffix);
- }
-
- return dest;
- }
-
- /**
- * Creates directories for output files if needed.
- *
- * @param output Output file with path.
- *
- * @throws SVGConverterException Output directory doesn't exist and it can't be created.
- */
- protected void createOutputDir(File output)
- throws SVGConverterException {
-
- File outputDir; // Output directory object.
- boolean success = true; // false if the output directory
- // doesn't exist and it can't be created
- // true otherwise
-
-
- // Create object from output directory.
- String parentDir = output.getParent();
- if (parentDir != null){
- outputDir = new File(output.getParent());
- if (outputDir.exists() == false) {
- // Output directory doesn't exist, so create it.
- success = outputDir.mkdirs();
- } else {
- if (outputDir.isDirectory() == false) {
- // File, which have a same name as the output directory, exists.
- // Create output directory.
- success = outputDir.mkdirs();
- }
- }
- }
-
- if (!success) {
- throw new SVGConverterException(ERROR_UNABLE_TO_CREATE_OUTPUT_DIR);
- }
- }
-
- /**
- * Checks if the application is allowed to write to the file.
- *
- * @param file File to be checked.
- *
- * @return <tt>true</tt> if the file is writeable and <tt>false</tt> otherwise.
- */
- protected boolean isWriteable(File file) {
- if (file.exists()) {
- // Check the existing file.
- if (!file.canWrite()) {
- return false;
- }
- } else {
- // Check the file that doesn't exist yet.
- // Create a new file. The file is writeable if
- // the creation succeeds.
- try {
- file.createNewFile();
- } catch(IOException ioe) {
- return false;
- }
- }
- return true;
- }
-
- // -----------------------------------------------------------------------
- // Inner classes
- // -----------------------------------------------------------------------
-
- /**
- * Convenience class to filter svg files
- */
- public static class SVGFileFilter implements FileFilter {
- public static final String SVG_EXTENSION = ".svg";
-
- public boolean accept(File file){
- if (file != null && file.getName().toLowerCase().endsWith(SVG_EXTENSION)){
- return true;
- }
-
- return false;
- }
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f690ea2f/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterController.java
----------------------------------------------------------------------
diff --git a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterController.java b/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterController.java
deleted file mode 100644
index b1bac4c..0000000
--- a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterController.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-
- Copyright 2001,2003 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- */
-package org.apache.flex.forks.batik.apps.rasterizer;
-
-import java.io.File;
-import java.util.Map;
-import java.util.Vector;
-
-import org.apache.flex.forks.batik.transcoder.Transcoder;
-
-/**
- * Interface for controlling some aspectes of the
- * <tt>SVGConverter</tt> operation.
- *
- * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: SVGConverterController.java,v 1.4 2004/08/18 07:12:26 vhardy Exp $
- */
-public interface SVGConverterController {
- /**
- * Invoked when the rasterizer has computed the
- * exact description of what it should do. The controller
- * should return true if the transcoding process should
- * proceed or false otherwise.
- *
- * @param transcoder Transcoder which will be used
- * @param hints set of hints that were set on the transcoder
- * @param sources list of SVG sources it will convert.
- * @param dest list of destination file it will use
- */
- public boolean proceedWithComputedTask(Transcoder transcoder,
- Map hints,
- Vector sources,
- Vector dest);
-
- /**
- * Invoked when the rasterizer is about to start transcoding
- * of a given source.
- * The controller should return true if the source should be
- * transcoded and false otherwise.
- */
- public boolean proceedWithSourceTranscoding(SVGConverterSource source,
- File dest);
-
- /**
- * Invoked when the rasterizer got an error while
- * transcoding the input source.
- * The controller should return true if the transcoding process
- * should continue on other sources and it should return false
- * if it should not.
- *
- * @param errorCode see the {@link SVGConverter} error code descriptions.
- */
- public boolean proceedOnSourceTranscodingFailure(SVGConverterSource source,
- File dest,
- String errorCode);
-
- /**
- * Invoked when the rasterizer successfully transcoded
- * the input source.
- */
- public void onSourceTranscodingSuccess(SVGConverterSource source,
- File dest);
-
-}
-
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f690ea2f/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterException.java
----------------------------------------------------------------------
diff --git a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterException.java b/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterException.java
deleted file mode 100644
index 8d02123..0000000
--- a/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/apps/rasterizer/SVGConverterException.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-
- Copyright 2001 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- */
-package org.apache.flex.forks.batik.apps.rasterizer;
-
-/**
- * Describes an error condition in <tt>SVGConverter</tt>
- *
- * @author <a href="mailto:vincent.hardy@sun.com">Vincent Hardy</a>
- * @version $Id: SVGConverterException.java,v 1.4 2005/03/27 08:58:29 cam Exp $
- */
-public class SVGConverterException extends Exception {
- /**
- * Error code
- */
- protected String errorCode;
-
- /**
- * Additional information about the error condition
- */
- protected Object[] errorInfo;
-
- /**
- * Defines whether or not this is a fatal error condition
- */
- protected boolean isFatal;
-
- public SVGConverterException(String errorCode){
- this(errorCode, null, false);
- }
-
- public SVGConverterException(String errorCode,
- Object[] errorInfo){
- this(errorCode, errorInfo, false);
- }
-
- public SVGConverterException(String errorCode,
- Object[] errorInfo,
- boolean isFatal){
- this.errorCode = errorCode;
- this.errorInfo = errorInfo;
- this.isFatal = isFatal;
- }
-
- public SVGConverterException(String errorCode,
- boolean isFatal){
- this(errorCode, null, isFatal);
- }
-
- public boolean isFatal(){
- return isFatal;
- }
-
- public String getMessage(){
- return Messages.formatMessage(errorCode, errorInfo);
- }
-
- public String getErrorCode(){
- return errorCode;
- }
-}