Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Code to download attachments from lotus notes

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Code to download attachments from lotus notes

    I need to write a java application which can download attachments from lotus notes. I have a mailbox configured which gets only attachment based mails.
    Is this possible? If yes, then please help me..

    I have a code which is like this ...


    import lotus.domino.*;
    public class NotesJavaShell extends AgentBase{
     
    // Public fields.
     
    // Local vars
    private Session session;
    private Database database;  
     
    // Constructors
     
    public NotesJavaShell(){    // default constructor, without run context
        }
    public NotesJavaShell(Session s, Database d) { // when we know the run context
        this.session = s; 
        this.database = d;
        }
     
    // Start here when run from Eclipse.
    public static void main(String[] args) {    
        //System.out.println(System.getProperty("java.library.path"));
     
        Session sess=null; 
        Database db=null;
        NotesJavaShell ag;
     
        // Initialize Notes
        NotesThread.sinitThread(); 
     
        try {
            sess = NotesFactory.createSession();  // start a Notes session
            db = sess.getDatabase("", Constants.DEFAULT_HOME_DB);  // simulate home database for agent
            ag = new NotesJavaShell(sess, db);  // simulate agent object with session and database
            ag.NotesMain();   // call main routine of agent
            }
        catch(NotesException ne) {
            System.out.println(ne.id + " " + ne.text);
            }
        catch (Exception e) {
            e.printStackTrace();
            }
        finally {
            try { 
                if (db != null) db.recycle(); 
                if (sess != null) sess.recycle(); 
                }
            catch (Exception x) {}
            NotesThread.stermThread();
            }           
     
    } // end main
     
     
    // This routine is called however the code is run: from Eclipse or agent launch within Notes/Domino.
    public void NotesMain()
    {
        Log notesLog=null;
        Session sess=null;
        Database db=null;
        AgentContext ac=null;
        Utilities util;
        int logLevel;
     
        try {
            if (this.session != null)   // Already have an agent context.  
                {
                sess = this.session;
                db = this.database;
                }
            else {  // Need to get agent context.  
                sess = this.getSession();
                if (sess==null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get current session at start of agent.");
                ac = sess.getAgentContext();
                if (ac==null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get agent context at start of agent.");
                db = ac.getCurrentDatabase();
                if (db==null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not get current database at start of agent.");
                }
            }
        catch(NotesException ne) {
            System.out.println(ne.id + " " + ne.text);
            return;
            }
        catch (Exception e) {
            e.printStackTrace();
            return;
            }
        finally {};
     
        // The truly common code, however we are invoked.
        try {
     
            // Get utilities.
            util = new Utilities();     
     
            // Record the session so other objects can use it.
            util.setSession(sess);
     
            // Find all the runtime parameters.
            util.readParameters();
     
            // Start a Notes log.
            notesLog = util.getNotesLog();
            logLevel = util.getLogLevel();
            if (Constants.CONSOLE_OUTPUT) System.out.println("Agent started. " + Constants.BUILD_STAMP);
            if (logLevel >= Constants.LOG_LEVEL_BRIEF) notesLog.logAction ("Agent started. " + Constants.BUILD_STAMP);  
     
            // ******* Do the real work here ********
     
            System.out.println (db.getTitle());  // print title of home database, to prove we got the agent context correctly
     
            // ******* Do the real work here ********
     
            // All done with no errors.
            if (logLevel >= Constants.LOG_LEVEL_BRIEF) notesLog.logAction ("Agent done with no errors.");
            if (Constants.CONSOLE_OUTPUT) System.out.println("Agent done with no errors.");
            } // try
     
     
        // Catch Notes exceptions from main code.
        catch(NotesException ne) {
            if (Constants.CONSOLE_OUTPUT) System.out.println("Notes error code " + ne.id + ". " + ne.text);
            try {
                notesLog.logError (ne.id, ne.text);  // Notes log may not be valid, but give it a try
                }
            catch (Exception x) {}
            }
     
        // Catch non-Notes exceptions from main code.
        catch (Exception x) {
            if (Constants.CONSOLE_OUTPUT) System.out.println("Error: " + x.getMessage());
            if (Constants.CONSOLE_OUTPUT)   x.printStackTrace();
            try {
                notesLog.logError (NotesError.NOTES_ERR_ERROR, x.getMessage());  // Notes log may not be valid, but give it a try
                }
            catch (Exception x2) {}
            }
     
        // Do cleanup from main code block.
        finally { 
            try {
                if (notesLog!=null) notesLog.close(); 
                if (notesLog!=null) notesLog.recycle(); 
                // cannot recycle the AgentContext, Session or Database, since they may have been passed in by Notes.
                }
            catch (Exception x){}
            } // finally
     
    } // NotesMain
    } // main class
     
    import lotus.domino.*;
    public class Utilities {
     
    // Class fields, shared by all objects.
     
    private static Session session;  
    private static Log notesLog = null;     
    private static String logDbPath = "";  
    private static String logName = "";  
    private static int logLevel;  
     
    // Constructor
    Utilities () {
    }
     
    // Hold Notes session info so all objects can share it.
    public void setSession (Session s) {
        session = s;
        }
    public Session getSession () {
        return(session);
        }
     
    // Return the Notes log, or start a new one.
    public Log getNotesLog () throws NotesException {
        if (notesLog != null)
                return(notesLog);
        else {
            notesLog = session.createLog(logName);
            if (notesLog==null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not create NotesLog object in NotesSession.");
            notesLog.openNotesLog(Constants.LOG_SERVER, logDbPath);
            return(notesLog);
            }
        }
     
    // Get all program parameters, storing them in class variables here.
    public void readParameters() throws NotesException{
     
        Database configDb;
        View configView = null;
        Document configDoc = null;
        String configDbPath = "";
        String logLevelString = "";  
     
        // Get the Notes.ini variable that holds the filename of the configuration database.
        configDbPath = session.getEnvironmentString(Constants.CONFIG_DB_INI, false); // not system var, add $
     
        // If the INI is not found, use the default path for the config db.
        if (configDbPath.compareTo("")==0) configDbPath = Constants.CONFIG_DB_DEFAULT;
     
        // Open the config db.
        configDb = session.getDatabase(Constants.CONFIG_SERVER, configDbPath); 
        if (!(configDb.isOpen())) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not open configuration database " + configDbPath + ".");
     
        // Open the view of configuration documents.
        configView = configDb.getView(Constants.CONFIG_VIEW); 
        if (configView == null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not open view " + Constants.CONFIG_VIEW + " in the configuration database " + configDbPath + ".");
     
        // Get the configurations that relates to logging.
     
        configDoc = configView.getDocumentByKey(Constants.CONFIG_LOOKUP_LOGDB);
        if (configDoc == null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGDB + " in the configuration database " + configDbPath + ".");
        logDbPath = configDoc.getItemValueString(Constants.CONFIG_VALUE_FIELD);
        if (logDbPath.compareTo("")==0) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGDB + " in the configuration database " + configDbPath + ".");
        if (configDoc!=null) configDoc.recycle();
     
        configDoc = configView.getDocumentByKey(Constants.CONFIG_LOOKUP_LOGNAME);
        if (configDoc == null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGNAME + " in the configuration database " + configDbPath + ".");
        logName = configDoc.getItemValueString(Constants.CONFIG_VALUE_FIELD);
        if (logName.compareTo("")==0) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGNAME + " in the configuration database " + configDbPath + ".");
        if (configDoc!=null) configDoc.recycle();
     
        configDoc = configView.getDocumentByKey(Constants.CONFIG_LOOKUP_LOGLEVEL);
        if (configDoc == null) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGLEVEL + " in the configuration database " + configDbPath + ".");
        logLevelString = configDoc.getItemValueString(Constants.CONFIG_VALUE_FIELD);
        if (logLevelString.compareTo("")==0) throw new NotesException(NotesError.NOTES_ERR_ERROR, "Could not find the setting " + Constants.CONFIG_LOOKUP_LOGLEVEL + " in the configuration database " + configDbPath + ".");
        if (configDoc!=null) configDoc.recycle();
     
        // Change the logging level to a number.
        if (logLevelString.compareToIgnoreCase(Constants.LOG_LEVEL_ERROR_STRING)==0) 
            logLevel = Constants.LOG_LEVEL_ERROR;
        else if (logLevelString.compareToIgnoreCase(Constants.LOG_LEVEL_BRIEF_STRING)==0) 
            logLevel = Constants.LOG_LEVEL_BRIEF;
        else if (logLevelString.compareToIgnoreCase(Constants.LOG_LEVEL_FULL_STRING)==0) 
            logLevel = Constants.LOG_LEVEL_FULL;
        else
            logLevel = Constants.LOG_LEVEL_ERROR;
     
     
        // ***** Get other setup parameters here. *********
     
     
        // Clean up.
        if (configDoc!=null) configDoc.recycle();
        if (configView!=null) configView.recycle();
        if (configDb!=null) configDb.recycle();
     
        } // readParameters()
     
     
    // Simple getItems() for configuration. Some settings don't need a get(), if it is only used
    // within this class to define a larger parameter.
     
    public int getLogLevel () {
        return(logLevel);
        }
     
    // ***** Add getItems() for other setup parameters here. *********
    }
     
    public class Constants {
     
    // Version stamp.
     
    final static String BUILD_STAMP = "Build 5, dated 04 June 2010.";
     
    /* 
     * For test setup. 
     */
     
    final static boolean CONSOLE_OUTPUT = true;
    final static String DEFAULT_HOME_DB = "names.nsf"; // when running from Eclipse, the "home" db of the agent
     
    /* 
     * Parameters that are NOT user configurable. 
     */
     
    // Assume all databases are on current machine.
    final static String CONFIG_SERVER = "";       
    final static String LOG_SERVER = "";
    final static String SOURCE_SERVER = "";
     
    // Logging control
    final static String LOG_LEVEL_NONE_STRING = "0";  // not implemented, we always do at least ERROR logging
    final static String LOG_LEVEL_ERROR_STRING = "1";
    final static String LOG_LEVEL_BRIEF_STRING = "2";
    final static String LOG_LEVEL_FULL_STRING = "3";
    final static int LOG_LEVEL_NONE = 0;  
    final static int LOG_LEVEL_ERROR = 1;
    final static int LOG_LEVEL_BRIEF = 2;
    final static int LOG_LEVEL_FULL = 3;
     
    // ********** Add other non-user-configurable parameters here. **********
     
    /* 
     * To get parameters that ARE user configurable. 
     */
     
    final static String CONFIG_DB_INI = "NotesJavaSetup";   
    final static String CONFIG_DB_DEFAULT = "notes_java_setup.nsf";   
    final static String CONFIG_VIEW = "SettingsByName";             
    final static String CONFIG_VALUE_FIELD = "Values";
     
    final static String CONFIG_LOOKUP_LOGDB = "Log Database";
    final static String CONFIG_LOOKUP_LOGNAME = "Log Name";
    final static String CONFIG_LOOKUP_LOGLEVEL = "Log Level";
     
    // ********** Add the names of other user-configurable parameters here. These are the parameter names
    // ********** as they appear in the configuration database. *********
     
    // Constructor
    Constants () {}
    }

    As I said i have a mail box configured.. What should I place in config_server, log_server, source_server? Please Help..

    I am getting an error as : Notes error code 4000. Could not open configuration database
    Last edited by singhnk; July 10th, 2014 at 11:07 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Java Code to download attachments from lotus notes

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Notes error code 4000. Could not open configuration database
    Not many people will have the package that this code uses. You will have to read its API doc to see what that error means.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Code to download attachments from lotus notes

    Is their a different method to achieve this. Please Help.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Java Code to download attachments from lotus notes

    Sorry, I don't know anything about lotus notes.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to read rawitemdata from lotus notes file(dxl)
    By sravan8888 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: June 25th, 2013, 01:04 PM
  2. Need Help with java revision notes app
    By 06williamsl in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 10th, 2012, 09:53 AM
  3. Downloading the file in Lotus Symphony spreadsheet format (ods)
    By chinnu in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 13th, 2011, 03:47 AM
  4. Error in Lectures notes(please help)
    By Pulse_Irl in forum AWT / Java Swing
    Replies: 1
    Last Post: October 12th, 2010, 01:48 PM

Tags for this Thread