// 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 + "¶m_1=" + param_1;
Server = Server + "¶m_2=" + param_2;
Server = Server + "¶m_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
}