1 18 package org.apache.batik.apps.rasterizer; 19 20 import java.awt.Color ; 21 import java.awt.geom.Rectangle2D ; 22 import java.io.File ; 23 import java.util.Hashtable ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 29 import org.apache.batik.transcoder.Transcoder; 30 import org.apache.batik.util.ApplicationSecurityEnforcer; 31 32 43 public class Main implements SVGConverterController { 44 47 public static final String RASTERIZER_SECURITY_POLICY 48 = "org/apache/batik/apps/rasterizer/resources/rasterizer.policy"; 49 50 53 public static interface OptionHandler { 54 61 void handleOption(String [] optionValues, SVGConverter c); 62 63 68 int getOptionValuesLength(); 69 70 73 String getOptionDescription(); 74 } 75 76 85 public static abstract class AbstractOptionHandler implements OptionHandler { 86 87 public void handleOption(String [] optionValues, SVGConverter c){ 88 int nOptions = optionValues != null? optionValues.length: 0; 89 if (nOptions != getOptionValuesLength()){ 90 throw new IllegalArgumentException (); 91 } 92 93 safeHandleOption(optionValues, c); 94 } 95 96 public abstract void safeHandleOption(String [] optionValues, SVGConverter c); 97 } 98 99 105 public static abstract class NoValueOptionHandler extends AbstractOptionHandler { 106 public void safeHandleOption(String [] optionValues, SVGConverter c){ 107 handleOption(c); 108 } 109 110 public int getOptionValuesLength(){ 111 return 0; 112 } 113 114 public abstract void handleOption(SVGConverter c); 115 } 116 117 122 public static abstract class SingleValueOptionHandler extends AbstractOptionHandler { 123 public void safeHandleOption(String [] optionValues, SVGConverter c){ 124 handleOption(optionValues[0], c); 125 } 126 127 public int getOptionValuesLength(){ 128 return 1; 129 } 130 131 public abstract void handleOption(String optionValue, SVGConverter c); 132 } 133 134 140 public static abstract class FloatOptionHandler extends SingleValueOptionHandler { 141 public void handleOption(String optionValue, SVGConverter c){ 142 try{ 143 handleOption(Float.parseFloat(optionValue), c); 144 } catch(NumberFormatException e){ 145 throw new IllegalArgumentException (); 146 } 147 } 148 149 public abstract void handleOption(float optionValue, SVGConverter c); 150 } 151 152 157 public static abstract class RectangleOptionHandler extends SingleValueOptionHandler { 158 public void handleOption(String optionValue, SVGConverter c){ 159 Rectangle2D r = parseRect(optionValue); 160 if (r==null){ 161 throw new IllegalArgumentException (); 162 } 163 handleOption(r, c); 164 } 165 166 public abstract void handleOption(Rectangle2D r, SVGConverter c); 167 168 public Rectangle2D.Float parseRect(String rectValue){ 169 Rectangle2D.Float rect = null; 170 if(rectValue != null){ 171 if (!rectValue.toLowerCase().endsWith("f")){ 172 rectValue += "f"; 173 } 174 175 StringTokenizer st = new StringTokenizer (rectValue, ","); 176 if(st.countTokens() == 4){ 177 String xStr = st.nextToken(); 178 String yStr = st.nextToken(); 179 String wStr = st.nextToken(); 180 String hStr = st.nextToken(); 181 float x=Float.NaN, y=Float.NaN, w=Float.NaN, h=Float.NaN; 182 try { 183 x = Float.parseFloat(xStr); 184 y = Float.parseFloat(yStr); 185 w = Float.parseFloat(wStr); 186 h = Float.parseFloat(hStr); 187 }catch(NumberFormatException e){ 188 } 191 192 if( !Float.isNaN(x) 193 && 194 !Float.isNaN(y) 195 && 196 (!Float.isNaN(w) && w > 0) 197 && 198 (!Float.isNaN(h) && h > 0) ){ 199 rect = new Rectangle2D.Float (x, y, w, h); 200 } 201 } 202 } 203 return rect; 204 } 205 } 206 207 212 public static abstract class ColorOptionHandler extends SingleValueOptionHandler { 213 public void handleOption(String optionValue, SVGConverter c){ 214 Color color = parseARGB(optionValue); 215 if (color==null){ 216 throw new IllegalArgumentException (); 217 } 218 handleOption(color, c); 219 } 220 221 public abstract void handleOption(Color color, SVGConverter c); 222 223 229 public Color parseARGB(String argbVal){ 230 Color c = null; 231 if(argbVal != null){ 232 StringTokenizer st = new StringTokenizer (argbVal, "."); 233 if(st.countTokens() == 4){ 234 String aStr = st.nextToken(); 235 String rStr = st.nextToken(); 236 String gStr = st.nextToken(); 237 String bStr = st.nextToken(); 238 int a = -1, r = -1, g = -1, b = -1; 239 try { 240 a = Integer.parseInt(aStr); 241 r = Integer.parseInt(rStr); 242 g = Integer.parseInt(gStr); 243 b = Integer.parseInt(bStr); 244 }catch(NumberFormatException e){ 245 } 249 250 if( a>=0 && a<=255 251 && 252 r>=0 && r<=255 253 && 254 g>=0 && g<=255 255 && 256 b>=0 && b<=255 ){ 257 c = new Color (r,g,b,a); 258 } 259 } 260 } 261 return c; 262 } 263 } 264 265 266 267 270 public static String USAGE = 271 Messages.formatMessage("Main.usage", null); 272 273 278 281 public static String CL_OPTION_OUTPUT 282 = Messages.get("Main.cl.option.output", "-d"); 283 284 public static String CL_OPTION_OUTPUT_DESCRIPTION 285 = Messages.get("Main.cl.option.output.description", "No description"); 286 287 290 public static String CL_OPTION_MIME_TYPE 291 = Messages.get("Main.cl.option.mime.type", "-m"); 292 293 public static String CL_OPTION_MIME_TYPE_DESCRIPTION 294 = Messages.get("Main.cl.option.mime.type.description", "No description"); 295 296 299 public static String CL_OPTION_WIDTH 300 = Messages.get("Main.cl.option.width", "-w"); 301 302 public static String CL_OPTION_WIDTH_DESCRIPTION 303 = Messages.get("Main.cl.option.width.description", "No description"); 304 305 308 public static String CL_OPTION_HEIGHT 309 = Messages.get("Main.cl.option.height", "-h"); 310 311 public static String CL_OPTION_HEIGHT_DESCRIPTION 312 = Messages.get("Main.cl.option.height.description", "No description"); 313 314 317 public static String CL_OPTION_MAX_WIDTH 318 = Messages.get("Main.cl.option.max.width", "-maxw"); 319 320 public static String CL_OPTION_MAX_WIDTH_DESCRIPTION 321 = Messages.get("Main.cl.option.max.width.description", "No description"); 322 323 326 public static String CL_OPTION_MAX_HEIGHT 327 = Messages.get("Main.cl.option.max.height", "-maxh"); 328 329 public static String CL_OPTION_MAX_HEIGHT_DESCRIPTION 330 = Messages.get("Main.cl.option.max.height.description", "No description"); 331 332 336 public static String CL_OPTION_AOI 337 = Messages.get("Main.cl.option.aoi", "-a"); 338 339 public static String CL_OPTION_AOI_DESCRIPTION 340 = Messages.get("Main.cl.option.aoi.description", "No description"); 341 342 345 public static String CL_OPTION_BACKGROUND_COLOR 346 = Messages.get("Main.cl.option.background.color", "-bg"); 347 348 public static String CL_OPTION_BACKGROUND_COLOR_DESCRIPTION 349 = Messages.get("Main.cl.option.background.color.description", "No description"); 350 351 355 public static String CL_OPTION_MEDIA_TYPE 356 = Messages.get("Main.cl.option.media.type", "-cssMedia"); 357 358 public static String CL_OPTION_MEDIA_TYPE_DESCRIPTION 359 = Messages.get("Main.cl.option.media.type.description", "No description"); 360 361 365 public static String CL_OPTION_DEFAULT_FONT_FAMILY 366 = Messages.get("Main.cl.option.default.font.family", "-font-family"); 367 368 public static String CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION 369 = Messages.get("Main.cl.option.default.font.family.description", "No description"); 370 371 375 public static String CL_OPTION_ALTERNATE_STYLESHEET 376 = Messages.get("Main.cl.option.alternate.stylesheet", "-cssAlternate"); 377 378 public static String CL_OPTION_ALTERNATE_STYLESHEET_DESCRIPTION 379 = Messages.get("Main.cl.option.alternate.stylesheet.description", "No description"); 380 381 385 public static String CL_OPTION_VALIDATE 386 = Messages.get("Main.cl.option.validate", "-validate"); 387 388 public static String CL_OPTION_VALIDATE_DESCRIPTION 389 = Messages.get("Main.cl.option.validate.description", "No description"); 390 391 395 public static String CL_OPTION_ONLOAD 396 = Messages.get("Main.cl.option.onload", "-onload"); 397 398 public static String CL_OPTION_ONLOAD_DESCRIPTION 399 = Messages.get("Main.cl.option.onload.description", "No description"); 400 401 405 public static String CL_OPTION_LANGUAGE 406 = Messages.get("Main.cl.option.language", "-lang"); 407 408 public static String CL_OPTION_LANGUAGE_DESCRIPTION 409 = Messages.get("Main.cl.option.language.description", "No description"); 410 411 414 public static String CL_OPTION_USER_STYLESHEET 415 = Messages.get("Main.cl.option.user.stylesheet", "-cssUser"); 416 417 public static String CL_OPTION_USER_STYLESHEET_DESCRIPTION 418 = Messages.get("Main.cl.option.user.stylesheet.description", "No description"); 419 420 423 public static String CL_OPTION_DPI 424 = Messages.get("Main.cl.option.dpi", "-dpi"); 425 426 public static String CL_OPTION_DPI_DESCRIPTION 427 = Messages.get("Main.cl.option.dpi.description", "No description"); 428 429 432 public static String CL_OPTION_QUALITY 433 = Messages.get("Main.cl.option.quality", "-q"); 434 435 public static String CL_OPTION_QUALITY_DESCRIPTION 436 = Messages.get("Main.cl.option.quality.description", "No description"); 437 438 441 public static String CL_OPTION_INDEXED 442 = Messages.get("Main.cl.option.indexed", "-indexed"); 443 444 public static String CL_OPTION_INDEXED_DESCRIPTION 445 = Messages.get("Main.cl.option.indexed.description", "No description"); 446 447 450 public static String CL_OPTION_ALLOWED_SCRIPTS 451 = Messages.get("Main.cl.option.allowed.scripts", "-scripts"); 452 453 public static String CL_OPTION_ALLOWED_SCRIPTS_DESCRIPTION 454 = Messages.get("Main.cl.option.allowed.scripts.description", "No description"); 455 456 460 public static String CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN 461 = Messages.get("Main.cl.option.constrain.script.origin", "-anyScriptOrigin"); 462 463 public static String CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN_DESCRIPTION 464 = Messages.get("Main.cl.option.constrain.script.origin.description", "No description"); 465 466 469 public static String CL_OPTION_SECURITY_OFF 470 = Messages.get("Main.cl.option.security.off", "-scriptSecurityOff"); 471 472 public static String CL_OPTION_SECURITY_OFF_DESCRIPTION 473 = Messages.get("Main.cl.option.security.off.description", "No description"); 474 475 479 protected static Map optionMap = new Hashtable (); 480 481 485 protected static Map mimeTypeMap = new Hashtable (); 486 487 491 static { 492 mimeTypeMap.put("image/jpg", DestinationType.JPEG); 493 mimeTypeMap.put("image/jpeg", DestinationType.JPEG); 494 mimeTypeMap.put("image/jpe", DestinationType.JPEG); 495 mimeTypeMap.put("image/png", DestinationType.PNG); 496 mimeTypeMap.put("application/pdf", DestinationType.PDF); 497 mimeTypeMap.put("image/tiff", DestinationType.TIFF); 498 499 optionMap.put(CL_OPTION_OUTPUT, 500 new SingleValueOptionHandler(){ 501 public void handleOption(String optionValue, 502 SVGConverter c){ 503 c.setDst(new File (optionValue)); 504 } 505 public String getOptionDescription(){ 506 return CL_OPTION_OUTPUT_DESCRIPTION; 507 } 508 }); 509 510 optionMap.put(CL_OPTION_MIME_TYPE, 511 new SingleValueOptionHandler(){ 512 public void handleOption(String optionValue, 513 SVGConverter c){ 514 DestinationType dstType = 515 (DestinationType)mimeTypeMap.get(optionValue); 516 517 if (dstType == null){ 518 throw new IllegalArgumentException (); 519 } 520 521 c.setDestinationType(dstType); 522 } 523 524 public String getOptionDescription(){ 525 return CL_OPTION_MIME_TYPE_DESCRIPTION; 526 } 527 }); 528 529 optionMap.put(CL_OPTION_WIDTH, 530 new FloatOptionHandler(){ 531 public void handleOption(float optionValue, 532 SVGConverter c){ 533 if (optionValue <= 0){ 534 throw new IllegalArgumentException (); 535 } 536 537 c.setWidth(optionValue); 538 } 539 540 public String getOptionDescription(){ 541 return CL_OPTION_WIDTH_DESCRIPTION; 542 } 543 }); 544 545 optionMap.put(CL_OPTION_HEIGHT, 546 new FloatOptionHandler(){ 547 public void handleOption(float optionValue, 548 SVGConverter c){ 549 if (optionValue <= 0){ 550 throw new IllegalArgumentException (); 551 } 552 553 c.setHeight(optionValue); 554 } 555 556 public String getOptionDescription(){ 557 return CL_OPTION_HEIGHT_DESCRIPTION; 558 } 559 }); 560 561 optionMap.put(CL_OPTION_MAX_WIDTH, 562 new FloatOptionHandler(){ 563 public void handleOption(float optionValue, 564 SVGConverter c){ 565 if (optionValue <= 0){ 566 throw new IllegalArgumentException (); 567 } 568 569 c.setMaxWidth(optionValue); 570 } 571 572 public String getOptionDescription(){ 573 return CL_OPTION_MAX_WIDTH_DESCRIPTION; 574 } 575 }); 576 577 optionMap.put(CL_OPTION_MAX_HEIGHT, 578 new FloatOptionHandler(){ 579 public void handleOption(float optionValue, 580 SVGConverter c){ 581 if (optionValue <= 0){ 582 throw new IllegalArgumentException (); 583 } 584 585 c.setMaxHeight(optionValue); 586 } 587 588 public String getOptionDescription(){ 589 return CL_OPTION_MAX_HEIGHT_DESCRIPTION; 590 } 591 }); 592 593 optionMap.put(CL_OPTION_AOI, 594 new RectangleOptionHandler(){ 595 public void handleOption(Rectangle2D optionValue, 596 SVGConverter c){ 597 c.setArea(optionValue); 598 } 599 600 public String getOptionDescription(){ 601 return CL_OPTION_AOI_DESCRIPTION; 602 } 603 }); 604 605 optionMap.put(CL_OPTION_BACKGROUND_COLOR, 606 new ColorOptionHandler(){ 607 public void handleOption(Color optionValue, 608 SVGConverter c){ 609 c.setBackgroundColor(optionValue); 610 } 611 612 public String getOptionDescription(){ 613 return CL_OPTION_BACKGROUND_COLOR_DESCRIPTION; 614 } 615 }); 616 617 optionMap.put(CL_OPTION_MEDIA_TYPE, 618 new SingleValueOptionHandler(){ 619 public void handleOption(String optionValue, 620 SVGConverter c){ 621 c.setMediaType(optionValue); 622 } 623 624 public String getOptionDescription(){ 625 return CL_OPTION_MEDIA_TYPE_DESCRIPTION; 626 } 627 }); 628 629 optionMap.put(CL_OPTION_DEFAULT_FONT_FAMILY, 630 new SingleValueOptionHandler() { 631 public void handleOption(String optionValue, 632 SVGConverter c){ 633 c.setDefaultFontFamily(optionValue); 634 } 635 636 public String getOptionDescription(){ 637 return CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION; 638 } 639 }); 640 641 optionMap.put(CL_OPTION_ALTERNATE_STYLESHEET, 642 new SingleValueOptionHandler(){ 643 public void handleOption(String optionValue, 644 SVGConverter c){ 645 c.setAlternateStylesheet(optionValue); 646 } 647 648 public String getOptionDescription(){ 649 return CL_OPTION_ALTERNATE_STYLESHEET_DESCRIPTION; 650 } 651 }); 652 653 optionMap.put(CL_OPTION_USER_STYLESHEET, 654 new SingleValueOptionHandler(){ 655 public void handleOption(String optionValue, 656 SVGConverter c){ 657 c.setUserStylesheet(optionValue); 658 } 659 660 public String getOptionDescription(){ 661 return CL_OPTION_USER_STYLESHEET_DESCRIPTION; 662 } 663 }); 664 665 optionMap.put(CL_OPTION_LANGUAGE, 666 new SingleValueOptionHandler(){ 667 public void handleOption(String optionValue, 668 SVGConverter c){ 669 c.setLanguage(optionValue); 670 } 671 672 public String getOptionDescription(){ 673 return CL_OPTION_LANGUAGE_DESCRIPTION; 674 } 675 }); 676 677 optionMap.put(CL_OPTION_DPI, 678 new FloatOptionHandler(){ 679 public void handleOption(float optionValue, 680 SVGConverter c){ 681 if (optionValue <= 0){ 682 throw new IllegalArgumentException (); 683 } 684 685 c.setPixelUnitToMillimeter 686 ((2.54f/optionValue)*10); 687 } 688 689 public String getOptionDescription(){ 690 return CL_OPTION_DPI_DESCRIPTION; 691 } 692 }); 693 694 optionMap.put(CL_OPTION_QUALITY, 695 new FloatOptionHandler(){ 696 public void handleOption(float optionValue, 697 SVGConverter c){ 698 if (optionValue <= 0 || optionValue >= 1){ 699 throw new IllegalArgumentException (); 700 } 701 702 c.setQuality(optionValue); 703 } 704 705 public String getOptionDescription(){ 706 return CL_OPTION_QUALITY_DESCRIPTION; 707 } 708 }); 709 710 optionMap.put(CL_OPTION_INDEXED, 711 new FloatOptionHandler(){ 712 public void handleOption(float optionValue, 713 SVGConverter c){ 714 if ((optionValue != 1) && 715 (optionValue != 2) && 716 (optionValue != 4) && 717 (optionValue != 8)) 718 throw new IllegalArgumentException (); 719 720 c.setIndexed((int)optionValue); 721 } 722 723 public String getOptionDescription(){ 724 return CL_OPTION_INDEXED_DESCRIPTION; 725 } 726 }); 727 optionMap.put(CL_OPTION_VALIDATE, 728 new NoValueOptionHandler(){ 729 public void handleOption(SVGConverter c){ 730 c.setValidate(true); 731 } 732 733 public String getOptionDescription(){ 734 return CL_OPTION_VALIDATE_DESCRIPTION; 735 } 736 }); 737 optionMap.put(CL_OPTION_ONLOAD, 738 new NoValueOptionHandler(){ 739 public void handleOption(SVGConverter c){ 740 c.setExecuteOnload(true); 741 } 742 743 public String getOptionDescription(){ 744 return CL_OPTION_ONLOAD_DESCRIPTION; 745 } 746 }); 747 748 optionMap.put(CL_OPTION_ALLOWED_SCRIPTS, 749 new SingleValueOptionHandler() { 750 public void handleOption(String optionValue, 751 SVGConverter c){ 752 c.setAllowedScriptTypes(optionValue); 753 } 754 755 public String getOptionDescription(){ 756 return CL_OPTION_ALLOWED_SCRIPTS_DESCRIPTION; 757 } 758 }); 759 760 optionMap.put(CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN, 761 new NoValueOptionHandler(){ 762 public void handleOption(SVGConverter c){ 763 c.setConstrainScriptOrigin(false); 764 } 765 766 public String getOptionDescription(){ 767 return CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN_DESCRIPTION; 768 } 769 }); 770 771 optionMap.put(CL_OPTION_SECURITY_OFF, 772 new NoValueOptionHandler() { 773 public void handleOption(SVGConverter c){ 774 c.setSecurityOff(true); 775 } 776 777 public String getOptionDescription(){ 778 return CL_OPTION_SECURITY_OFF_DESCRIPTION; 779 } 780 }); 781 } 782 783 787 protected Vector args; 788 789 public Main(String [] args){ 790 this.args = new Vector (); 791 for (int i=0; i<args.length; i++){ 792 this.args.addElement(args[i]); 793 } 794 } 795 796 protected void error(String errorCode, 797 Object [] errorArgs){ 798 System.err.println(Messages.formatMessage(errorCode, 799 errorArgs)); 800 } 801 802 806 811 public static final String ERROR_NOT_ENOUGH_OPTION_VALUES 812 = "Main.error.not.enough.option.values"; 813 814 819 public static final String ERROR_ILLEGAL_ARGUMENT 820 = "Main.error.illegal.argument"; 821 822 public static final String ERROR_WHILE_CONVERTING_FILES 823 = "Main.error.while.converting.files"; 824 825 public void execute(){ 826 SVGConverter c = new SVGConverter(this); 827 828 Vector sources = new Vector (); 829 830 int nArgs = args.size(); 831 for (int i=0; i<nArgs; i++){ 832 String v = (String )args.elementAt(i); 833 OptionHandler optionHandler = (OptionHandler)optionMap.get(v); 834 if (optionHandler == null){ 835 sources.addElement(v); 837 } else { 838 int nOptionArgs = optionHandler.getOptionValuesLength(); 841 if (i + nOptionArgs >= nArgs){ 842 error(ERROR_NOT_ENOUGH_OPTION_VALUES, new Object []{ v, optionHandler.getOptionDescription()}); 843 return; 844 } 845 846 String [] optionValues = new String [nOptionArgs]; 847 for (int j=0; j<nOptionArgs; j++){ 848 optionValues[j] = (String )args.elementAt(1+i+j); 849 } 850 i += nOptionArgs; 851 852 try { 853 optionHandler.handleOption(optionValues, c); 854 } catch(IllegalArgumentException e){ 855 e.printStackTrace(); 856 error(ERROR_ILLEGAL_ARGUMENT, 857 new Object [] { v, 858 optionHandler.getOptionDescription() , 859 toString(optionValues)}); 860 return; 861 } 862 } 863 } 864 865 ApplicationSecurityEnforcer securityEnforcer = 867 new ApplicationSecurityEnforcer(this.getClass(), 868 RASTERIZER_SECURITY_POLICY); 869 870 securityEnforcer.enforceSecurity(!c.getSecurityOff()); 871 872 String expandedSources[] = expandSources(sources); 873 874 c.setSources(expandedSources); 875 876 validateConverterConfig(c); 877 878 if (expandedSources== null || expandedSources.length < 1){ 879 System.out.println(USAGE); 880 System.out.flush(); 881 securityEnforcer.enforceSecurity(false); 882 return; 883 } 884 885 try { 886 c.execute(); 887 } catch(SVGConverterException e){ 888 error(ERROR_WHILE_CONVERTING_FILES, 889 new Object [] { e.getMessage() }); 890 } finally { 891 System.out.flush(); 892 securityEnforcer.enforceSecurity(false); 893 } 894 } 895 896 protected String toString(String [] v){ 897 StringBuffer sb = new StringBuffer (); 898 int n = v != null ? v.length:0; 899 for (int i=0; i<n; i++){ 900 sb.append(v[i] + " "); 901 } 902 903 return sb.toString(); 904 } 905 906 910 public void validateConverterConfig(SVGConverter c){ 911 } 912 913 917 protected String [] expandSources(Vector sources){ 918 Vector expandedSources = new Vector (); 919 Iterator iter = sources.iterator(); 920 while (iter.hasNext()){ 921 String v = (String )iter.next(); 922 File f = new File (v); 923 if (f.exists() && f.isDirectory()){ 924 File [] fl = f.listFiles(new SVGConverter.SVGFileFilter()); 925 for (int i=0; i<fl.length; i++){ 926 expandedSources.addElement(fl[i].getPath()); 927 } 928 } else { 929 expandedSources.addElement(v); 930 } 931 } 932 933 String [] s = new String [expandedSources.size()]; 934 expandedSources.copyInto(s); 935 return s; 936 } 937 938 public static void main(String [] args) { 939 (new Main(args)).execute(); 940 System.exit(0); 941 } 942 943 public static final String MESSAGE_ABOUT_TO_TRANSCODE 947 = "Main.message.about.to.transcode"; 948 949 public static final String MESSAGE_ABOUT_TO_TRANSCODE_SOURCE 950 = "Main.message.about.to.transcode.source"; 951 952 public static final String MESSAGE_CONVERSION_FAILED 953 = "Main.message.conversion.failed"; 954 955 public static final String MESSAGE_CONVERSION_SUCCESS 956 = "Main.message.conversion.success"; 957 958 public boolean proceedWithComputedTask(Transcoder transcoder, 959 Map hints, 960 Vector sources, 961 Vector dest){ 962 System.out.println(Messages.formatMessage(MESSAGE_ABOUT_TO_TRANSCODE, 963 new Object []{"" + sources.size()})); 964 return true; 965 } 966 967 public boolean proceedWithSourceTranscoding(SVGConverterSource source, 968 File dest){ 969 System.out.print(Messages.formatMessage(MESSAGE_ABOUT_TO_TRANSCODE_SOURCE, 970 new Object []{source.toString(), 971 dest.toString()})); 972 return true; 973 } 974 975 public boolean proceedOnSourceTranscodingFailure(SVGConverterSource source, 976 File dest, 977 String errorCode){ 978 System.out.println(Messages.formatMessage(MESSAGE_CONVERSION_FAILED, 979 new Object []{errorCode})); 980 981 return true; 982 } 983 984 public void onSourceTranscodingSuccess(SVGConverterSource source, 985 File dest){ 986 System.out.println(Messages.formatMessage(MESSAGE_CONVERSION_SUCCESS, 987 null)); 988 } 989 } 990 991 | Popular Tags |