[opencms] [opencms-dev] Create a scheduled job from jsp

Luis Rodriguez Fernandez luis.rodriguez at fundacionctic.org
Wed Sep 7 15:41:36 CEST 2005


Thanks for your code. This solution let me load the static content for the mail (the head, for example), but doesn´t make with the dynamic content, the jsp in this case because it doesn' t call to the jsp engine.

Thanks. Luis 

-----Mensaje original-----
De: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] En nombre de Jorge González
Enviado el: miércoles, 07 de septiembre de 2005 12:11
Para: 'The OpenCms mailing list'
Asunto: RE: [opencms] [opencms-dev] Create a scheduled job from jsp

So, the real problem is calling an url from a java code and get the resulting html (whith all the formatting css, headers, and other stuff in it), then put this html code into one email and send it, isn't it ?

This code gets the html (or jsp) from you site and stores in a local file...



wget.java
--------------------------
import java.io.*;
import java.net.*;
import java.util.Vector;

/** This class does a simple HTTP GET and writes the retrieved content to a local file
 * 
 * @author Brian Pipa - http://pipasoft.com
 * @version 1.0
 */
public class wget {

    static final String FS = File.separator;

    /** This method does the actual GET
     * 
     * @param theUrl The URL to retrieve
     * @param filename the local file to save to
     * @exception IOException 
     */
    public void get(String theUrl, String filename) throws IOException
    {
        try {
            URL gotoUrl = new URL(theUrl);
            InputStreamReader isr = new InputStreamReader(gotoUrl.openStream());
            BufferedReader in = new BufferedReader(isr);

            StringBuffer sb = new StringBuffer();
            String inputLine;
            boolean isFirst = true;
            
            //grab the contents at the URL
            while ((inputLine = in.readLine()) != null){
                sb.append(inputLine+"\r\n");
            }
            //write it locally
            createAFile(filename, sb.toString());
        }
        catch (MalformedURLException mue) {
            mue.printStackTrace();
        }
        catch (IOException ioe) {
            throw ioe;
        }
    }

    //creates a local file
    /** Writes a String to a local file
     * 
     * @param outfile the file to write to
     * @param content the contents of the file
     * @exception IOException 
     */
    public static void createAFile(String outfile, String content) throws IOException {
        FileOutputStream fileoutputstream = new FileOutputStream(outfile);
        DataOutputStream dataoutputstream = new DataOutputStream(fileoutputstream);
        dataoutputstream.writeBytes(content);
        dataoutputstream.flush();
        dataoutputstream.close();
    }

    /** The main method.
     * 
     * @param args 
     */
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("\nUsage: java wget URL localfilename");
            System.out.println("Example: java wget http://google.com google.html");
            System.exit(1);
        }
        try {
            wget httpGetter = new wget();
            httpGetter.get(args[0], args[1]);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}



More information about the opencms-dev mailing list