Package mailerg

Source Code of mailerg.Params

/* Read gmail box and save in db PostgresQL.
    Copyright (C) 2008  Sergiy Soroka

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      */
package mailerg;
import java.io.IOException;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.ParsingException;
import nu.xom.ValidityException;


public class Params {
static public String DBUser;
static public String DBPassword;
static public String MailUser;
static public String MailPassword;
static public String DB;
static public String Host;
static public String Table;
 
Params(){
//open xml file and read data
   String url ="parameters.xml";
   Builder builder = new Builder();
   try {
    Document document = builder.build(url);
    for( int i=0;i<document.getRootElement().getChildCount();i++){
      if (((Element) document.getRootElement().getChild(i)).getLocalName()=="MailUser")
        MailUser=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="MailPassword")
        MailPassword=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DBUser")
        DBUser=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DBPassword")
        DBPassword=document.getRootElement().getChild(i).getValue();     
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DB")
        DB=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DBHost")
        Host=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="Table")
        Table=document.getRootElement().getChild(i).getValue();     
    }
  } catch (ValidityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (ParsingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  }
/**
* @param args
*/
public static void main(String[] args) {
   String url ="properties.xml";
   Builder builder = new Builder();
   try {
    Document document = builder.build(url);
   
    System.out.println(document.getRootElement().getChildElements().size());
    for( int i=0;i<document.getRootElement().getChildCount();i++){
      if (((Element) document.getRootElement().getChild(i)).getLocalName()=="MailUser")
        MailUser=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="MailPassword")
        MailPassword=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DBUser")
        DBUser=document.getRootElement().getChild(i).getValue();
      else if (((Element) document.getRootElement().getChild(i)).getLocalName()=="DBPassword")
        DBPassword=document.getRootElement().getChild(i).getValue();     
    }
   
   
   
   
  } catch (ValidityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (ParsingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}
}
TOP

Related Classes of mailerg.Params

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.