You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2001/06/21 15:35:11 UTC

cvs commit: xml-fop/src/org/apache/fop/tools/anttasks Fop.java

keiron      01/06/21 06:35:11

  Modified:    src/org/apache/fop/tools/anttasks Fop.java
  Log:
  handles baseDir (with a capital D)
  properly as suggested by
  Anthony Tagunov <at...@nnt.ru>
  
  Revision  Changes    Path
  1.7       +132 -172  xml-fop/src/org/apache/fop/tools/anttasks/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/tools/anttasks/Fop.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Fop.java	2001/04/12 00:12:49	1.6
  +++ Fop.java	2001/06/21 13:35:10	1.7
  @@ -1,52 +1,7 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  -    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Fop" and  "Apache Software Foundation"  must not be used to
  -    endorse  or promote  products derived  from this  software without  prior
  -    written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - James Tauber <jt...@jtauber.com>. For more  information on the Apache
  - Software Foundation, please see <http://www.apache.org/>.
  -
  +/* $Id: Fop.java,v 1.7 2001/06/21 13:35:10 keiron Exp $
  + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * For details on use and redistribution please refer to the
  + * LICENSE file included with these sources.
    */
   
   package org.apache.fop.tools.anttasks;
  @@ -81,11 +36,10 @@
    * <ul>
    *   <li>fofile -> formatting objects file to be transformed</li>
    *   <li>pdffile -> output filename</li>
  - *   <li>basedir -> directory to work from</li>
  + *   <li>baseDir -> directory to work from</li>
    *   <li>messagelevel -> (info | verbose | debug) level to output non-error messages</li>
    * </ul>
    */
  -
   public class Fop extends Task {
       File foFile;
       File pdfFile;
  @@ -104,11 +58,11 @@
        * Gets the input file
        */
       public File getFofile() {
  -	if(foFile == null) {
  -	    log("fofile attribute is not set", Project.MSG_ERR);
  -	    throw new BuildException("fofile attribute is not set");
  -	}
  -	return foFile;
  +        if (foFile == null) {
  +            log("fofile attribute is not set", Project.MSG_ERR);
  +            throw new BuildException("fofile attribute is not set");
  +        }
  +        return foFile;
       }
   
       /**
  @@ -123,11 +77,11 @@
        * Sets the output file
        */
       public File getPdffile() {
  -	if(pdfFile == null) {
  -	    log("pdffile attribute is not set", Project.MSG_ERR);
  -	    throw new BuildException("pdffile attribute is not set");
  -	}
  -	return pdfFile;
  +        if (pdfFile == null) {
  +            log("pdffile attribute is not set", Project.MSG_ERR);
  +            throw new BuildException("pdffile attribute is not set");
  +        }
  +        return pdfFile;
       }
   
       /**
  @@ -135,16 +89,17 @@
        * @param String (info | verbose | debug)
        */
       public void setMessagelevel(String messageLevel) {
  -	if(messageLevel.equalsIgnoreCase("info")) {
  -	    messageType = Project.MSG_INFO;
  -	} else if(messageLevel.equalsIgnoreCase("verbose")) {
  -	    messageType = Project.MSG_VERBOSE;
  -	} else if(messageLevel.equalsIgnoreCase("debug")) {
  -	    messageType = Project.MSG_DEBUG;
  -	} else {
  -	    log("messagelevel set to unknown value \"" + messageLevel + "\"", Project.MSG_ERR);
  -	    throw new BuildException("unknown messagelevel");
  -	}
  +        if (messageLevel.equalsIgnoreCase("info")) {
  +            messageType = Project.MSG_INFO;
  +        } else if (messageLevel.equalsIgnoreCase("verbose")) {
  +            messageType = Project.MSG_VERBOSE;
  +        } else if (messageLevel.equalsIgnoreCase("debug")) {
  +            messageType = Project.MSG_DEBUG;
  +        } else {
  +            log("messagelevel set to unknown value \"" + messageLevel +
  +                "\"", Project.MSG_ERR);
  +            throw new BuildException("unknown messagelevel");
  +        }
       }
   
       /**
  @@ -152,36 +107,35 @@
        * representing the current message level.
        */
       public int getMessageType() {
  -	return messageType;
  +        return messageType;
       }
  -    
  +
       /**
        * Sets the base directory; currently ignored
        * @param File to use as a working directory
        */
       public void setBasedir(File baseDir) {
  -	this.baseDir = baseDir;
  +        this.baseDir = baseDir;
       }
   
       /**
        * Gets the base directory
        */
       public File getBasedir() {
  -	return (baseDir != null) ? baseDir : project.resolveFile(".");
  +        return (baseDir != null) ? baseDir : project.resolveFile(".");
       }
   
       /**
        * Starts execution of this task
        */
       public void execute () throws BuildException {
  -	try {
  -	    Starter starter = new FOPTaskStarter(this);
  -	    starter.run();
  -	}
  -	catch (FOPException ex) {
  -	    throw new BuildException(ex);
  -	}
  -	
  +        try {
  +            Starter starter = new FOPTaskStarter(this);
  +            starter.run();
  +        } catch (FOPException ex) {
  +            throw new BuildException(ex);
  +        }
  +
       }
   }
   
  @@ -189,45 +143,48 @@
       Fop task;
       MessageLogger logger;
   
  -    FOPTaskStarter(Fop task) 
  -	throws FOPException
  -    {
  -	this.task = task;
  -	MessageHandler.setOutputMethod(MessageHandler.EVENT);
  -	logger = new MessageLogger(new MessageHandler(), task);
  -	logger.setMessageLevel(task.getMessageType());
  -    }
  -
  -    public void run () 
  -	throws FOPException
  -    {
  -	Configuration.put("basedir", task.getBasedir());
  -
  -	InputHandler inputHandler = new FOInputHandler(task.getFofile());
  -	XMLReader parser = inputHandler.getParser();
  -	setParserFeatures(parser);
  -	
  -	FileOutputStream pdfOut = null;
  -	try {
  -	    pdfOut = new FileOutputStream(task.getPdffile());
  -	}catch(Exception ex) {
  -	    MessageHandler.errorln("Failed to open " + task.getPdffile());
  -	    throw new BuildException(ex);
  -	}
  -
  -	task.log("Using base directory: " + Configuration.getValue("basedir"), Project.MSG_DEBUG);
  -	task.log(task.getFofile().getName() + " -> " + task.getPdffile().getName(), Project.MSG_INFO);
  -
  -	try {
  -	    Driver driver = new Driver(inputHandler.getInputSource(), pdfOut);
  -	    driver.setRenderer(Driver.RENDER_PDF);
  -	    driver.setXMLReader(parser);
  -	    driver.run();
  -	} catch (Exception ex) {
  -	    MessageHandler.logln("Error: " + ex.getMessage());
  -	    throw new BuildException(ex);
  -	}
  -	logger.die();
  +    FOPTaskStarter(Fop task) throws FOPException {
  +        this.task = task;
  +        MessageHandler.setOutputMethod(MessageHandler.EVENT);
  +        logger = new MessageLogger(new MessageHandler(), task);
  +        logger.setMessageLevel(task.getMessageType());
  +    }
  +
  +    public void run () throws FOPException {
  +        try {
  +            Configuration.put("baseDir", task.getBasedir().toURL().toExternalForm());
  +        } catch (Exception e) {
  +            task.log("Error setting base directory", Project.MSG_DEBUG);
  +        }
  +
  +        InputHandler inputHandler = new FOInputHandler(task.getFofile());
  +        XMLReader parser = inputHandler.getParser();
  +        setParserFeatures(parser);
  +
  +        FileOutputStream pdfOut = null;
  +        try {
  +            pdfOut = new FileOutputStream(task.getPdffile());
  +        } catch (Exception ex) {
  +            MessageHandler.errorln("Failed to open " + task.getPdffile());
  +            throw new BuildException(ex);
  +        }
  +
  +        task.log("Using base directory: " +
  +                 Configuration.getValue("baseDir"), Project.MSG_DEBUG);
  +        task.log(task.getFofile().getName() + " -> " +
  +                 task.getPdffile().getName(), Project.MSG_INFO);
  +
  +        try {
  +            Driver driver =
  +              new Driver(inputHandler.getInputSource(), pdfOut);
  +            driver.setRenderer(Driver.RENDER_PDF);
  +            driver.setXMLReader(parser);
  +            driver.run();
  +        } catch (Exception ex) {
  +            MessageHandler.logln("Error: " + ex.getMessage());
  +            throw new BuildException(ex);
  +        }
  +        logger.die();
       }
   }
   
  @@ -241,71 +198,74 @@
       boolean performCaching = true;
   
       MessageLogger(MessageHandler handler, Task task) {
  -	this(handler, task, Project.MSG_VERBOSE);
  +        this(handler, task, Project.MSG_VERBOSE);
       }
  -	
  +
       MessageLogger(MessageHandler handler, Task task, int messageLevel) {
  -	this.handler = handler;
  -	this.task = task;
  -	setMessageLevel(messageLevel);
  -	handler.addListener(this);
  +        this.handler = handler;
  +        this.task = task;
  +        setMessageLevel(messageLevel);
  +        handler.addListener(this);
       }
   
       public void setMessageLevel(int messageLevel) {
  -	this.messageLevel = messageLevel;
  +        this.messageLevel = messageLevel;
       }
  -   
  +
       public int getMessageLevel() {
  -	return messageLevel;
  +        return messageLevel;
       }
   
       public void processMessage(MessageEvent event) {
  -	task.log("Logger got message: \"" + event.getMessage() + "\"", Project.MSG_DEBUG);
  +        task.log("Logger got message: \"" + event.getMessage() + "\"",
  +                 Project.MSG_DEBUG);
   
  -	boolean flushed = false;
  -	
  -	if(!flushed) {
  -	    int messageLevel;
  -	    if(event.getMessageType() == MessageEvent.ERROR) {
  -		messageLevel = Project.MSG_ERR;
  -	    } else {
  -		messageLevel = this.messageLevel;
  -	    }
  -	    if(messageLevel != lastMessageLevel) {
  -		flush();
  -		flushed = true;
  -	    }
  -	    lastMessageLevel = messageLevel;
  -	}
  -
  -	cache.append(event.getMessage());
  -
  -	if(!performCaching) {
  -	    flush();
  -	    flushed = true;
  -	}
  -
  -	for(int i = 0; !flushed && i < breakChars.length(); i++) {
  -	    if(event.getMessage().lastIndexOf(breakChars.charAt(i)) != -1) {
  -		flush();
  -		flushed = true;
  -	    }
  -	}
  +        boolean flushed = false;
  +
  +        if (!flushed) {
  +            int messageLevel;
  +            if (event.getMessageType() == MessageEvent.ERROR) {
  +                messageLevel = Project.MSG_ERR;
  +            } else {
  +                messageLevel = this.messageLevel;
  +            }
  +            if (messageLevel != lastMessageLevel) {
  +                flush();
  +                flushed = true;
  +            }
  +            lastMessageLevel = messageLevel;
  +        }
  +
  +        cache.append(event.getMessage());
  +
  +        if (!performCaching) {
  +            flush();
  +            flushed = true;
  +        }
  +
  +        for (int i = 0; !flushed && i < breakChars.length(); i++) {
  +            if (event.getMessage().lastIndexOf(breakChars.charAt(i)) !=
  +                    -1) {
  +                flush();
  +                flushed = true;
  +            }
  +        }
       }
  -    
  +
       public void flush() {
  -	StringTokenizer output = new StringTokenizer(cache.toString(), "\n", false);
  -	while(output.hasMoreElements()) {
  -	    task.log(output.nextElement().toString(), lastMessageLevel);
  -	}
  -	cache.setLength(0);
  +        StringTokenizer output =
  +          new StringTokenizer(cache.toString(), "\n", false);
  +        while (output.hasMoreElements()) {
  +            task.log(output.nextElement().toString(), lastMessageLevel);
  +        }
  +        cache.setLength(0);
       }
   
       public void die() {
  -	flush();
  -	// because MessageHandler is static this has to be done
  -	// or you can get duplicate messages if there are
  -	// multiple <fop> tags in a buildfile
  -	handler.removeListener(this);
  +        flush();
  +        // because MessageHandler is static this has to be done
  +        // or you can get duplicate messages if there are
  +        // multiple <fop> tags in a buildfile
  +        handler.removeListener(this);
       }
   }
  
  
  

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