lenya/src/java/org/apache/lenya/cms/ant PublicationTask.java,NONE,1.1 StaticHTMLExporter.java,NONE,1.1

Andreas Hartmann <[email protected]>
Newsgroups gmane.comp.cms.wyona.cvs
Message-ID <[email protected]>
Update of /repository/lenya/src/java/org/apache/lenya/cms/ant
In directory erbium:/tmp/cvs-serv25863/src/java/org/apache/lenya/cms/ant

Added Files:
	PublicationTask.java StaticHTMLExporter.java 
Log Message:
- added new project parameters to AntTask
- added PublicationTask and Ant-based StaticHTMLExporter

--- NEW FILE: PublicationTask.java ---
/*
 * PublicationTask.java
 *
 * Created on 6. Mai 2003, 18:08
 */

package org.apache.lenya.cms.ant;

import java.io.File;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.task.AntTask;
import org.apache.tools.ant.Task;

/**
 *
 * @author  andreas
 */
public abstract class PublicationTask
    extends Task {
    
    /** Creates a new instance of PublicationTask */
    public PublicationTask() {
    }
    
    protected File getPublicationDirectory() {
        return new File(getProject().getProperty(AntTask.PUBLICATION_DIRECTORY));
    }
    
    protected String getPublicationId() {
        return getProject().getProperty(AntTask.PUBLICATION_ID);
    }
    
    protected File getServletContext() {
        return new File(getProject().getProperty(AntTask.SERVLET_CONTEXT_PATH));
    }
    
}

--- NEW FILE: StaticHTMLExporter.java ---
/*
 * StaticHTMLExporter.java
 *
 * Created on 6. Mai 2003, 18:00
 */

package org.apache.lenya.cms.ant;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.lenya.cms.publishing.ExportException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 *
 * @author  andreas
 */
public class StaticHTMLExporter
    extends PublicationTask {
    
    /** Creates a new instance of StaticHTMLExporter */
    public StaticHTMLExporter() {
    }
    
    private String serverURL;
    
    protected URL getServer()
        throws MalformedURLException {
        return new URL(serverURL);
    }
    
    public void setServer(String serverURL) {
        this.serverURL = serverURL;
    }
    
    private String path;
    
    protected String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    private String uris;
    
    protected String[] getUris() {
        return uris.split(",");
    }
    
    public void setUris(String uris) {
        this.uris = uris;
    }
    
    private String expression;
    
    protected String getExpression() {
        return expression;
    }
    
    public void setExpression(String expression) {
        this.expression = expression;
    }
    
    private String replacement;
    
    protected String getReplacement() {
        return replacement;
    }
    
    public void setReplacement(String replacement) {
        this.replacement = replacement;
    }
    
    public void export(URL serverURI, File publicationDirectory, String exportPath,
        String[] uris, String substituteExpression, String substituteReplacement)
        throws ExportException {
        try {
            File exportDirectory;
            if (new File(exportPath).isAbsolute()) {
                exportDirectory = new File(exportPath);
            }
            else {
                exportDirectory = new File(publicationDirectory, exportPath);
            }
            
            if (!exportDirectory.exists()) {
                exportDirectory.mkdirs();
            }

            org.apache.lenya.net.WGet wget = new org.apache.lenya.net.WGet();
            wget.setDirectoryPrefix(exportDirectory.getAbsolutePath());

            String fullServerURI = serverURI.toString();

            for (int i = 0; i < uris.length; i++) {
                URL uri = new URL(fullServerURI + uris[i]);
                wget.download(uri, substituteExpression, substituteReplacement);
                log("Exported URI: " + uri);
            }
        } catch (Exception e) {
            throw new ExportException(e);
        }
    }
    
    public void execute()
        throws BuildException {
            
        try {
            log("Server URL: " + getServer());
            log("Publication ID: " + getPublication().getId());
            log("Export directory: " + getPath());
            log("URIs: " + uris);
            log("Substitute expression: " + getExpression());
            log("Substitute replacement: " + getReplacement());

            export(
                getServer(),
                getPublicationDirectory(),
                getPath(),
                getUris(),
                getExpression(),
                getReplacement());
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }

}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.