Beiträge von hwnb

    // lese via http eine xml Datei
    // transformiere mit xsl in eine neue xml
    // importiere neue xml in db



    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.Hashtable;
    import java.util.StringTokenizer;


    import lotus.domino.AgentBase;
    import lotus.domino.AgentContext;
    import lotus.domino.Database;
    import lotus.domino.Document;
    import lotus.domino.DxlImporter;
    import lotus.domino.Session;
    import lotus.domino.Stream;


    import com.lotus.xsl.XSLProcessor;
    import com.lotus.xsl.XSLTInputSource;
    import com.lotus.xsl.XSLTResultTarget;



    public class JavaAgent extends AgentBase {
    boolean debug = true;


    public void NotesMain() {
    try {
    Session s = getSession();
    AgentContext agentContext = s.getAgentContext();
    Database db = agentContext.getCurrentDatabase();
    Document doc = agentContext.getDocumentContext();


    String qsd = doc.getItemValueString("Query_String_Decoded");
    Hashtable ht = parseQueryString(qsd);
    String param_1 = (String) ht.get("anr");
    String param_2 = (String) ht.get("nan");
    String param_3 = (String) ht.get("von");


    String Server = "http://test.schnatter.de/servlet/xmlservlet?";
    Server = Server + "&param_1=" + param_1;
    Server = Server + "&param_2=" + param_2;
    Server = Server + "&param_3=" + param_3;


    URL url = new URL(Server);


    File outDatei = new File("C:/Lotus/Domino/Data/domino/html/myxml/myxml.xml");
    FileWriter fw = new FileWriter(outDatei);
    BufferedWriter bw = new BufferedWriter(fw);


    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.setDefaultUseCaches(false);
    conn.setRequestProperty("Connection", "Keep-Alive");
    conn.setRequestProperty("Authorization", userNamePasswordBase64("user", "kennwort"));
    conn.connect();


    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
    String Line = "";
    while (null != (Line = br.readLine())) {
    bw.write(Line);
    }
    br.close();
    bw.close();
    fw.close();


    XSLProcessor xp = new XSLProcessor(new com.lotus.xml.xml4j2dom.XML4JLiaison4dom());
    com.lotus.xsl.XSLTInputSource inXML = new XSLTInputSource("C:/Lotus/Domino/Data/domino/html/myxml/myxml.xml");
    com.lotus.xsl.XSLTInputSource inXSL = new XSLTInputSource("C:/Lotus/Domino/Data/domino/html/myxml/myxml.xsl");
    FileWriter fwa = new FileWriter("C:/Lotus/Domino/Data/domino/html/myxml/myxmlout.xml");
    XSLTResultTarget result = new XSLTResultTarget(fwa);
    xp.process(inXML, inXSL, result);
    fwa.close();

    Stream stream = s.createStream();
    stream.open("C:/Lotus/Domino/Data/domino/html/myxml/myxmlout.xml");
    DxlImporter importer = s.createDxlImporter();
    importer.importDxl(stream, db);



    } catch (Exception e) {
    e.printStackTrace();
    }
    }


    /*
    * // xsl zur Umsetzung
    * <?xml version="1.0" encoding="ISO-8859-1"?>
    *
    * <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    * version="1.0" > <xsl:output method="xml"/>
    *
    * <xsl:key name="myKey" match="Bereichx" use="@type"/>
    *
    * <xsl:template match="/"> <database xmlns="http://www.lotus.com/dxl"
    * version="6.0"> <document form="MyForm">
    *
    * <xsl:for-each select="key('myKey','DATUM')">
    * <item name="Datum"><text><xsl:value-of select="." /></text></item>
    * </xsl:for-each> <xsl:for-each


    * select="key('myKey','NAME')">
    * <item name="Kunde"><text><xsl:value-of select="." /></text></item>
    * </xsl:for-each>


    * <xsl:for-each select="key('myKey','ORT')">
    * <item name="Wohnort"><text><xsl:value-of
    * select="." /></text></item>
    * </xsl:for-each>
    * </document>
    * </database>
    * </xsl:template>
    * </xsl:stylesheet>
    *
    *
    */


    /*
    * // origial xml
    * <?xml version="1.0" encoding="ISO-8859-1" ?>
    * <Start>
    * <Bereich>
    * <Bereichx type="DATUM>27.5.2005</Bereichx>
    * <Bereichx type="Name">Fritz Schnatter</Bereichx>
    * <Bereichx type="ORT">Schnatterort</Bereichx>
    * </Bereich>
    * </Start>
    */


    public void sysOut(String consoleMsg) {
    if (debug) {
    System.out.println(consoleMsg);
    }
    }


    private static String userNamePasswordBase64(String username, String password) {
    String s = username + ":" + password;


    String encs = new sun.misc.BASE64Encoder().encode(s.getBytes());


    return "Basic " + encs;
    }


    public static Hashtable parseQueryString(String queryString) {
    StringTokenizer tokens = new StringTokenizer(queryString, "&");
    Hashtable params = new Hashtable();
    while (tokens.hasMoreTokens()) {
    String token = tokens.nextToken();
    int equalIdx = token.indexOf('=');
    if (equalIdx != -1 && !token.equalsIgnoreCase("OpenAgent")) {
    String name = token.substring(0, equalIdx);
    String value = token.substring(equalIdx + 1);
    params.put(name, value);
    }
    }
    return params;
    } // end of parseQueryString


    }

    // jtds-1.0.3.jar in den Agent importieren
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;


    import lotus.domino.AgentBase;
    import lotus.domino.AgentContext;
    import lotus.domino.Database;
    import lotus.domino.DateTime;
    import lotus.domino.Document;
    import lotus.domino.DocumentCollection;
    import lotus.domino.Session;

    public class JavaAgent extends AgentBase {
    private Connection conn = null;
    Statement stmt = null;
    Document doc = null;

    public void NotesMain() {
    try {
    Session session = getSession();
    AgentContext agentContext = session.getAgentContext();


    Database db = agentContext.getCurrentDatabase();
    final String server = "192.168.100.80:1433";
    final String sqldb = "KHK";
    final String usr = "sa";
    final String pwd = "xx";
    String connStr = "jdbc:jtds:sqlserver://" + server + "/" + sqldb;
    Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection(connStr, usr, pwd);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ......


    stmt.close();
    conn.close();
    }
    catch(Exception e) {e.printStackTrace(); }
    } // main

    kostet nichts !!
    public class JavaAgent extends AgentBase {
    private Connection conn = null;
    private String driver = "com.mysql.jdbc.Driver";
    public void NotesMain() {
    try {
    Session session = getSession();
    AgentContext agentContext = session.getAgentContext();
    Database db = agentContext.getCurrentDatabase();
    final String server = "127.0.0.1:3306";
    final String usr = "user";
    final String pwd = "kennwort";


    Class.forName(driver).newInstance();
    String sqldb = "mysqldb";
    String connStr = "jdbc:mysql://" + server + "/" + sqldb;
    conn = DriverManager.getConnection(connStr, usr, pwd);
    String sql = "SELECT irgendwas FROM `tabelle";
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    ....

    Der Fehler ist normal. Datenbank und Ansichten sind getrennt zu betrachten.
    folgende Lösung führt nie zu diesem Fehler.
    S0 = "Form=\"myCluster\" & Strasse=\""
    + doc.getItemValueString("Strasse")
    + "\" & @IsMember(\"" + doc.getItemValueString("Hausnummer") + "\" ; HausNr) = 1"
    + " & Ort=\"" + doc.getItemValueString("Ort") + "\"";
    DocumentCollection dca = adb.search(S0, null, 0);


    "db.search " ist zwar langsam aber genau. Ansichtssuchen sind immer vom Index abhängig.