You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by vh...@apache.org on 2001/04/19 01:18:18 UTC

cvs commit: xml-batik/sources/org/apache/batik/apps/rasterizer Main.java

vhardy      01/04/18 16:18:18

  Modified:    sources/org/apache/batik/apps/rasterizer Main.java
  Log:
  Temporary fix: added support for URIs and not only file names as an
  input. This app will be re-written soon.
  
  Revision  Changes    Path
  1.8       +67 -27    xml-batik/sources/org/apache/batik/apps/rasterizer/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/rasterizer/Main.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Main.java	2001/03/01 01:20:52	1.7
  +++ Main.java	2001/04/18 23:18:16	1.8
  @@ -30,7 +30,7 @@
    * A simple class that can generate images from svg documents.
    *
    * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
  - * @version $Id: Main.java,v 1.7 2001/03/01 01:20:52 vhardy Exp $
  + * @version $Id: Main.java,v 1.8 2001/04/18 23:18:16 vhardy Exp $
    */
   public class Main {
   
  @@ -129,12 +129,12 @@
               }
           }
           /*TranscoderFactory factory =
  -            ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
  -            */
  +          ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
  +        */
           ImageTranscoder t = null;
           if (mimeType.equals("image/jpg") ||
  -                mimeType.equals("image/jpeg") ||
  -                mimeType.equals("image/jpe")) {
  +            mimeType.equals("image/jpeg") ||
  +            mimeType.equals("image/jpe")) {
               t = new JPEGTranscoder();
               t.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                    "org.apache.crimson.parser.XMLReaderImpl");
  @@ -160,33 +160,73 @@
   
           for (Iterator iter = svgFiles.iterator(); iter.hasNext();) {
               String s = (String) iter.next();
  -            File f = new File(s);
  -            String uri = f.getName();
  -            if (uri.endsWith(".svg")) {
  -                uri = uri.substring(0, uri.lastIndexOf(".svg"));
  -                int k = mimeType.lastIndexOf('/');
  -                if (k > 0) {
  -                    String ext = mimeType.substring(k+1);
  -                    if (ext.length() > 0) {
  -                        uri += "."+ext;
  +            URL url = getSVGURL(s);
  +            if(url != null){
  +                String uri = url.getFile();
  +                int j = uri.lastIndexOf('/');
  +                if(j > 0){
  +                    uri = uri.substring(j);
  +                }
  +
  +                if (uri.endsWith(".svg")) {
  +                    uri = uri.substring(0, uri.lastIndexOf(".svg"));
  +                    int k = mimeType.lastIndexOf('/');
  +                    if (k > 0) {
  +                        String ext = mimeType.substring(k+1);
  +                        if (ext.length() > 0) {
  +                            uri += "."+ext;
  +                        }
  +                    } else {
  +                        uri += "."+mimeType;
                       }
  -                } else {
  -                    uri += "."+mimeType;
                   }
  -            }
  -            if (directory == null) {
  -                directory = f.getParent();
  -            }
  -            File output = new File(directory, uri);
  -            try {
  -                writeImage((ImageTranscoder)t,
  -                           f.toURL().toString(),
  -                           output.getAbsolutePath());
  -            } catch (MalformedURLException ex) {
  -                error("Bad svg file : "+s);
  +                if (directory == null) {
  +                    directory = getDirectory(s);
  +                }
  +						
  +                if (directory != null) {
  +                    File output = new File(directory, uri);
  +							
  +                    writeImage((ImageTranscoder)t,
  +                               url.toString(),
  +                               output.getAbsolutePath());
  +
  +                }
  +                else{
  +                    error("No valid output directory for : " + s);
  +                }
               }
           }
           System.exit(0);
       }
  +
  +	public static URL getSVGURL(String s) {
  +		URL url = null;
  +
  +		try{
  +			File f = new File(s);
  +			if(f.exists()){
  +				url = f.toURL();
  +			}
  +			else{
  +				url = new URL(s);
  +			}
  +		}catch(MalformedURLException e){
  +			error("Bad svg file: " + s);
  +		}
  +
  +		return url;
  +	}
  +
  +	public static String getDirectory(String s){
  +		File f = new File(s);
  +		if(f.exists()){
  +			return f.getParent();
  +		}
  +		else{
  +			return null;
  +		}
  +	}
  +
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org