Compare commits
2 Commits
master
...
userinfo_g
| Author | SHA1 | Date |
|---|---|---|
|
|
b93642403d | 2 years ago |
|
|
3935ddfd5b | 2 years ago |
2628 changed files with 486969 additions and 1996731 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,262 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.InvalidKeyException; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.security.SignatureException; |
||||||
|
import java.security.spec.InvalidKeySpecException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.ConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.DriverManagerConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolableConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
import org.apache.commons.pool.impl.GenericObjectPool; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.NamedObjectI; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
import de.memtext.util.DSAHandler; |
||||||
|
|
||||||
|
/** |
||||||
|
* A new Connection pool making use of Jakarta Commons dbcp. |
||||||
|
*/ |
||||||
|
public class MemtextPool extends GenericObjectPool implements NamedObjectI { |
||||||
|
|
||||||
|
private String name, subpath; |
||||||
|
private String nameNoAppendix; |
||||||
|
|
||||||
|
private Properties props = new Properties(); |
||||||
|
private String privateKeyEncoded = null; |
||||||
|
private String publicKeyEncoded = null; |
||||||
|
private DSAHandler dsaHandler; |
||||||
|
|
||||||
|
public MemtextPool(String name, String nameAppendix, String subpath) |
||||||
|
throws SQLException, IOException, DBServletException { |
||||||
|
this.subpath = subpath; |
||||||
|
nameNoAppendix = name; |
||||||
|
this.setName(name + nameAppendix); |
||||||
|
try { |
||||||
|
readPropertiesAndUrl(); |
||||||
|
System.out |
||||||
|
.print(" (" + props.getProperty("connectionURL") + ") .."); |
||||||
|
} catch (Exception e) { |
||||||
|
System.out |
||||||
|
.println("Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException( |
||||||
|
"Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
} |
||||||
|
try { |
||||||
|
|
||||||
|
Class.forName(props.getProperty("driverName")); |
||||||
|
} catch (ClassNotFoundException e1) { |
||||||
|
throw new DBServletException("Treiber " |
||||||
|
+ props.getProperty("driverName") |
||||||
|
+ " nicht gefunden. Ggfs. nach tomcat/common/lib kopieren."); |
||||||
|
} |
||||||
|
|
||||||
|
initLogging(); |
||||||
|
this.setTestOnBorrow(true); |
||||||
|
|
||||||
|
int minIdle = 5; |
||||||
|
if (props.getProperty("minIdle") != null |
||||||
|
&& !props.getProperty("minIdle").trim().equals("")) { |
||||||
|
minIdle = Integer.parseInt(props.getProperty("minIdle")); |
||||||
|
} |
||||||
|
this.setMinIdle(minIdle); |
||||||
|
int maxIdle = -1; |
||||||
|
if (props.getProperty("maxIdle") != null |
||||||
|
&& !props.getProperty("maxIdle").trim().equals("")) { |
||||||
|
maxIdle = Integer.parseInt(props.getProperty("maxIdle")); |
||||||
|
} |
||||||
|
if (maxIdle != -1) |
||||||
|
setMaxIdle(maxIdle); |
||||||
|
|
||||||
|
int maxActive = -1; |
||||||
|
if (props.getProperty("maxActive") != null |
||||||
|
&& !props.getProperty("maxActive").trim().equals("")) { |
||||||
|
maxActive = Integer.parseInt(props.getProperty("maxActive")); |
||||||
|
} |
||||||
|
if (maxActive != -1) |
||||||
|
setMaxActive(maxActive); |
||||||
|
|
||||||
|
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( |
||||||
|
props.getProperty("connectionURL"), props); |
||||||
|
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( |
||||||
|
connectionFactory, this, null, "select count(*) from xdummy;" //validationQuery
|
||||||
|
, false, true); |
||||||
|
int i = 1; |
||||||
|
try { |
||||||
|
// PoolingDriver driver = new PoolingDriver();
|
||||||
|
Class.forName("org.apache.commons.dbcp.PoolingDriver"); |
||||||
|
} catch (ClassNotFoundException e2) { |
||||||
|
throw new DBServletException( |
||||||
|
"ConnectionPool Klasse org.apache.commons.dbcp.PoolingDriver nicht gefunden.\ncommons-dbcp nach tomcat/common/lib stellen."); |
||||||
|
} |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
driver.registerPool(this.getName(), this); |
||||||
|
|
||||||
|
Object x = driver.getConnectionPool(this.getName()); |
||||||
|
try { |
||||||
|
Connection con = this.getConnection(); |
||||||
|
Statement st = con.createStatement(); |
||||||
|
ResultSet rs = st |
||||||
|
.executeQuery("select value from properties where name='privatekey'"); |
||||||
|
while (rs.next()) { |
||||||
|
privateKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
rs = st |
||||||
|
.executeQuery("select value from properties where name='publickey'"); |
||||||
|
while (rs.next()) { |
||||||
|
publicKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
con.close(); |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
String msg = "Fehler beim Aufbau des ConnectionPools "; |
||||||
|
if (!getName().startsWith("default")) |
||||||
|
msg += " für Mandant: " + getName(); |
||||||
|
msg += "\nKonnte keine Connection aus dem Pool holen.\n" + e; |
||||||
|
|
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
if (privateKeyEncoded != null) |
||||||
|
initDSAHandler(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void initLogging() throws IOException { |
||||||
|
/* |
||||||
|
* LogUtils.initRawFile("superx_" + getName(), getLogDir() + "/superx_" + |
||||||
|
* name + ".log", 2000, 1, false, true); LogUtils.initRawFile("superx_" + |
||||||
|
* getName() + "_xml", getLogDir() + "/superx_" + name + "_xml.log", |
||||||
|
* 2000, 1, false, true); |
||||||
|
* |
||||||
|
* Level lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelSQL") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelSQL")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* sqlLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelSQL"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + |
||||||
|
* getName()).setLevel(lev); lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelXML") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelXML")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* XMLLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelXML"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + getName() + |
||||||
|
* "_xml").setLevel(lev); |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
public static String getLogDir() { |
||||||
|
String tomcat_home = System.getProperty("catalina.home"); //tomcat 4
|
||||||
|
// and 5
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = System.getProperty("tomcat.home"); //tomcat 3.x
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = "/home/superx/webserver/tomcat"; |
||||||
|
|
||||||
|
return tomcat_home + "/logs"; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Properties getProperties() { |
||||||
|
return props; |
||||||
|
} |
||||||
|
|
||||||
|
private void readPropertiesAndUrl() throws Exception { |
||||||
|
String propname = "db_" + nameNoAppendix + ".properties"; |
||||||
|
if (nameNoAppendix.equals("default")) |
||||||
|
propname = "db.properties"; |
||||||
|
|
||||||
|
java.net.URL url = MemtextPool.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent() + System.getProperty("file.separator"); |
||||||
|
if (subpath != null) |
||||||
|
pfad += subpath + System.getProperty("file.separator"); |
||||||
|
props = PropsReader.prepareProps(new File(pfad + propname)); |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public void close() throws SQLException { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
driver.closePool(this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException { |
||||||
|
return DriverManager.getConnection("jdbc:apache:commons:dbcp:" |
||||||
|
+ this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void init() throws TransformerConfigurationException, |
||||||
|
KeyParentEqualException, SQLException, DBServletException { |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
} |
||||||
|
|
||||||
|
private void initDSAHandler() throws DBServletException { |
||||||
|
//privateKey wird ggfs. im Konstruktur bei Connection-Test, public key
|
||||||
|
// aus properties eingelesen
|
||||||
|
if (privateKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"privatekey war null - properties-table auf Eintrag überprüfen"); |
||||||
|
if (publicKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"publickey war null - properties-table prüfen"); |
||||||
|
try { |
||||||
|
dsaHandler = new DSAHandler(privateKeyEncoded, publicKeyEncoded); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasDSAHandler() { |
||||||
|
return dsaHandler != null; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean verifiy(String data, String signature) |
||||||
|
throws InvalidKeyException, NoSuchAlgorithmException, |
||||||
|
InvalidKeySpecException, SignatureException { |
||||||
|
if (dsaHandler == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"DSAHandler ist null, public und private key definition prüfen"); |
||||||
|
return dsaHandler.verify(data, signature); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public String getPrivateKey() { |
||||||
|
return privateKeyEncoded; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 as SxPool
|
||||||
@ -0,0 +1,197 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.reflect.Constructor; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Iterator; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.coll.NamedObjectSet; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
|
||||||
|
|
||||||
|
public class MemtextPools extends NamedObjectSet { |
||||||
|
|
||||||
|
private NamedObjectSet pools = new NamedObjectSet(); |
||||||
|
|
||||||
|
public MemtextPools() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized Connection getConnection(String poolname) |
||||||
|
throws SQLException { |
||||||
|
if (pools.size() == 0) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool gefunden."); |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new SQLException("Kein ConnectionPool für Mandant:" |
||||||
|
+ poolname + " gefunden"); |
||||||
|
String pooldrv = "jdbc:apache:commons:dbcp:" + poolname; |
||||||
|
if (DriverManager.getDriver(pooldrv) == null) { |
||||||
|
String msg = "Kein ConnectionPool gefunden "; |
||||||
|
if (!poolname.equals("default")) |
||||||
|
msg += " für Mandant " + poolname; |
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
return DriverManager.getConnection(pooldrv); |
||||||
|
} |
||||||
|
|
||||||
|
public MemtextPool get(String poolname) { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool (" + poolname |
||||||
|
+ ") vorhanden"); |
||||||
|
return (MemtextPool) pools.getByName(poolname); |
||||||
|
} |
||||||
|
|
||||||
|
/* void initDefaultOnly() throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
pools.add(new MemtextPool("default")); |
||||||
|
} |
||||||
|
*/ |
||||||
|
/** |
||||||
|
* wenn mehrfach benutzt wird (ConnectionPools für SuperX und Joolap) |
||||||
|
* mind ein sollte namensappendix haben, damit unterscheidbar - |
||||||
|
* sonst wird z.B. Pool für joolap "default" von später erzeugten Pool für superx "default" |
||||||
|
* überschrieben! |
||||||
|
*/ |
||||||
|
public void init(String subpath,Class poolclass, String nameAppendix) throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
if (nameAppendix==null) nameAppendix=""; |
||||||
|
Class[] params = new Class[2]; |
||||||
|
params[0] = String.class; |
||||||
|
params[1] = String.class; |
||||||
|
Constructor constructor; |
||||||
|
try { |
||||||
|
constructor = poolclass.getConstructor(params); |
||||||
|
|
||||||
|
String db_extfile = "mandanten.cfg"; |
||||||
|
if (db_extfile.indexOf(File.separator) == -1) { |
||||||
|
java.net.URL url = MemtextPools.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent(); |
||||||
|
if (subpath!=null) pfad+=File.separator+subpath; |
||||||
|
db_extfile = pfad + File.separator+db_extfile; ; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
File f = new File(db_extfile); |
||||||
|
if (!f.exists()) { |
||||||
|
//einfach nur normale db.properties (default)
|
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool"); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = "default";//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println(" OK"); |
||||||
|
System.out.println(" public/private key "+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} else { //mehrereMandanten
|
||||||
|
FileReader fr = new FileReader(f); |
||||||
|
BufferedReader bfr = new BufferedReader(fr); |
||||||
|
String line; |
||||||
|
while ((line = bfr.readLine()) != null) { |
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool für " |
||||||
|
+ line); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = line;//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println("OK"); |
||||||
|
System.out.println(" public/private key"+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} |
||||||
|
bfr.close(); |
||||||
|
fr.close(); |
||||||
|
} |
||||||
|
} catch (SecurityException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (NoSuchMethodException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalArgumentException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InstantiationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalAccessException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InvocationTargetException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Destroys all ConnectionPools |
||||||
|
* |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void closeAll() throws Exception { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool pool = (MemtextPool) it.next(); |
||||||
|
pool.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void main(String args[]) { |
||||||
|
try { |
||||||
|
init("xx",MemtextPool.class, null); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void invalidate(String poolname, Connection con) |
||||||
|
throws DBServletException { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new DBServletException( |
||||||
|
"Kann Connection nicht invalidieren - kein ConnectionPool " |
||||||
|
+ poolname + " gefunden."); |
||||||
|
try { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
//driver.invalidateConnection(con);
|
||||||
|
driver.getConnectionPool(poolname).invalidateObject(con); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException("Invalidating connection failed -" + e); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void resetAllPools() |
||||||
|
throws TransformerConfigurationException, KeyParentEqualException, |
||||||
|
SQLException, DBServletException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.init(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.clearLogFiles(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 als SxPools
|
||||||
@ -0,0 +1,122 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.search.FlagTerm; |
||||||
|
|
||||||
|
import de.memtext.util.LogUtils; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPool; |
||||||
|
|
||||||
|
public abstract class AbstractAriel extends Thread { |
||||||
|
// this is defined as private static method to use as little memory as possible,
|
||||||
|
// it would be neglectable in moder computers to create it every time the method
|
||||||
|
// runs, GarbargeCollection would easily do the job
|
||||||
|
// yet I define it that way out of respect for the programmers of beginning in
|
||||||
|
// the 50ies/60ies or whenever
|
||||||
|
// private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), true); // ja ich weiß, flagUnseen
|
||||||
|
Flags seen = new Flags(Flags.Flag.RECENT); |
||||||
|
private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false); |
||||||
|
static Flags flagsContainingOnlySeen=new Flags(Flags.Flag.SEEN); |
||||||
|
protected Logger logger=null; |
||||||
|
// wird bisher nicht
|
||||||
|
// benötigt, aber ist doch
|
||||||
|
// klar, dass ich das gleich
|
||||||
|
// nutzen will, dass nervt,
|
||||||
|
// dass die Meldung jetzt
|
||||||
|
// kommt
|
||||||
|
private boolean isActive = true; |
||||||
|
private int interval = 10; |
||||||
|
protected SxMail sxmail; |
||||||
|
|
||||||
|
public AbstractAriel() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target) { |
||||||
|
super(target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(String name) { |
||||||
|
super(name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target) { |
||||||
|
super(group, target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, String name) { |
||||||
|
super(group, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target, String name) { |
||||||
|
super(target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name) { |
||||||
|
super(group, target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name, long stackSize) { |
||||||
|
super(group, target, name, stackSize); |
||||||
|
} |
||||||
|
|
||||||
|
public void initLogging()throws IOException |
||||||
|
{ |
||||||
|
String filename=SxPool.getLogDir() + "/superx_" |
||||||
|
+ getArielName() + ".log"; |
||||||
|
LogUtils.initRawFile("superx_" + getArielName(), filename, 20000, 1, true, true); |
||||||
|
System.out.println("Superx Mail logging in "+filename); |
||||||
|
logger=Logger.getLogger("superx_" + getArielName()); |
||||||
|
Level lev = Level.SEVERE; |
||||||
|
logger.setLevel(lev); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
public String getArielName() |
||||||
|
{ |
||||||
|
return "mail"; |
||||||
|
} |
||||||
|
public void run() { |
||||||
|
while (isActive) { |
||||||
|
try { |
||||||
|
Thread.sleep(interval * 1000); |
||||||
|
|
||||||
|
} catch (InterruptedException e) { |
||||||
|
// e.printStackTrace();
|
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
|
||||||
|
logger.log(Level.INFO,"SuperX is checking mails for new heartbeats..."); |
||||||
|
|
||||||
|
|
||||||
|
Folder inbox=sxmail.getInbox(); |
||||||
|
//if (inbox.hasNewMessages())
|
||||||
|
processNewMessages(inbox.getMessages()); // processed messages will be deleted -> don#t need inbox.search(flagUnseen)); // former first attempt was : processNewMessages(inbox.getMessages()); // should be in differnt colour (<- British English)
|
||||||
|
|
||||||
|
sxmail.closeInbox(); //deletes marked mails
|
||||||
|
} catch (Exception e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
abstract void processNewMessages(Message[] messages) throws MessagingException, IOException, SQLException; |
||||||
|
|
||||||
|
public void setActive(boolean isActive) { |
||||||
|
this.isActive=isActive; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,96 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Session; |
||||||
|
import javax.mail.Store; |
||||||
|
import javax.mail.Transport; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.InternetAddress; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
public class Checker { |
||||||
|
|
||||||
|
public static void check(Session emailSession, String user, String password) |
||||||
|
throws MessagingException, IOException { |
||||||
|
|
||||||
|
// create the POP3 store object and connect with the pop server
|
||||||
|
// pop3s wichtig -> vermutlich secure
|
||||||
|
Store store = emailSession.getStore("pop3s"); |
||||||
|
store.connect(emailSession.getProperty("mail.pop3.host"), user, password); |
||||||
|
|
||||||
|
Folder emailFolder = store.getFolder("INBOX"); |
||||||
|
emailFolder.open(Folder.READ_ONLY); |
||||||
|
|
||||||
|
// messages werden geholt, können nur ausgelesen werden, wenn Folder noch open
|
||||||
|
// ist!
|
||||||
|
Message[] messages = emailFolder.getMessages(); |
||||||
|
|
||||||
|
System.out.println("messages.length---" + messages.length); |
||||||
|
|
||||||
|
for (int i = 0, n = messages.length; i < n; i++) { |
||||||
|
Message message = messages[i]; |
||||||
|
System.out.println("---------------------------------"); |
||||||
|
System.out.println("Email Number " + (i + 1)); |
||||||
|
System.out.println("Subject: " + message.getSubject()); |
||||||
|
System.out.println("From: " + message.getFrom()[0]); |
||||||
|
System.out.println("Text: " + message.getContent().toString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
// close the store and folder objects
|
||||||
|
emailFolder.close(false); |
||||||
|
store.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void send(Session emailSession, String user, String recipient, String subject, String text, |
||||||
|
String password) throws AddressException, MessagingException { |
||||||
|
MimeMessage replyMessage = new MimeMessage(emailSession); |
||||||
|
// replyMessage = (MimeMessage) message.reply(false);
|
||||||
|
replyMessage.setFrom(new InternetAddress(user)); |
||||||
|
replyMessage.setRecipients(Message.RecipientType.TO, recipient); |
||||||
|
replyMessage.setSubject(subject); |
||||||
|
replyMessage.setText(text); |
||||||
|
Transport t = emailSession.getTransport("smtp"); |
||||||
|
t.connect(user, password); |
||||||
|
t.sendMessage(replyMessage, replyMessage.getAllRecipients()); |
||||||
|
System.out.println("Message sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
private static Session initSession(String pophost, String smtphost) { |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties.put("mail.pop3.host", pophost); |
||||||
|
properties.put("mail.pop3.port", "995"); |
||||||
|
properties.put("mail.pop3.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.auth", "true"); |
||||||
|
properties.put("mail.smtp.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.host", smtphost); |
||||||
|
properties.put("mail.smtp.port", "25"); |
||||||
|
return Session.getDefaultInstance(properties); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
Session session = initSession("pop3.strato.de", "smtp.strato.de"); |
||||||
|
String username = "heartbeat@mbisping.de"; |
||||||
|
String password = "$Anfang1200"; |
||||||
|
|
||||||
|
try { |
||||||
|
check(session, username, password); |
||||||
|
send(session, username, "danielq@memtext.de", "From Düsseldorf with fun...", "This is the memtext's first digitial 'heartbeat' :-)\n send via java mail - \nThanks and see you around :-)", |
||||||
|
password); |
||||||
|
} catch (MessagingException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IOException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,293 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
import javax.mail.BodyPart; |
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Multipart; |
||||||
|
import javax.mail.Part; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
import clover.com.atlassian.extras.common.org.springframework.util.StringUtils; |
||||||
|
import de.memtext.db.DbUtils; |
||||||
|
import de.memtext.util.FileUtils; |
||||||
|
import de.memtext.util.MailUtils; |
||||||
|
import de.superx.servlet.SuperXManager; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPools; |
||||||
|
|
||||||
|
public class NewHeartBeatAriel extends AbstractAriel { |
||||||
|
private static final Pattern pHbtId = Pattern.compile("@hbt:\\d*@"); |
||||||
|
|
||||||
|
public NewHeartBeatAriel(SxMail sxmail) throws IOException { |
||||||
|
this.sxmail = sxmail; |
||||||
|
initLogging(); |
||||||
|
} |
||||||
|
|
||||||
|
void processNewMessages(Message newMessages[]) throws MessagingException, IOException, SQLException { |
||||||
|
|
||||||
|
|
||||||
|
logger.log(Level.INFO," found " + newMessages.length + " new messages"); |
||||||
|
for (int i = 0, n = newMessages.length; i < n; i++) { |
||||||
|
Message aNewMessage = newMessages[i]; |
||||||
|
|
||||||
|
String content = MailUtils.getContent(aNewMessage); |
||||||
|
if (content.indexOf("@hbt:") == -1) |
||||||
|
createNewHeartBeat(aNewMessage, content); |
||||||
|
else |
||||||
|
appendToHeartBeat(aNewMessage, content); |
||||||
|
// had thought setting via inbox nessary, but that's only the preferred way to
|
||||||
|
// set flags for group of messages since some mail implementations by have
|
||||||
|
// optimized support for groups of messages
|
||||||
|
// inbox.setFlags(new Message[] {message}, , true);
|
||||||
|
// message.setFlags(flagsContainingOnlySeen, true);
|
||||||
|
// unseen wäre schöner, mailapi.jar aktualisieren bei HIS Antrag
|
||||||
|
// nötig,vielleicht klappt mit delete
|
||||||
|
aNewMessage.setFlag(Flags.Flag.DELETED, true); // AbstractAriel.run ruft sxmail.closeInbox() auf mit
|
||||||
|
// Anweisung zu löschen
|
||||||
|
|
||||||
|
// sorry to bother you, Garbage collector , need message only to times, hey or
|
||||||
|
// doesn't that matter anyway since only a simple reference (like in good old
|
||||||
|
// C), but clearer/easier to read if line Message message=.. was superfolous
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void appendToHeartBeat(Message message, String content) |
||||||
|
throws SQLException, IOException, MessagingException { |
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
|
int hbtTid = -1; |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
boolean isHbtFoundInDb = false; |
||||||
|
String feedbackSubject = ""; |
||||||
|
Matcher m = pHbtId.matcher(content); |
||||||
|
boolean foundHbtTag=m.find(); |
||||||
|
if (foundHbtTag) { |
||||||
|
String hbtIdString = content.substring(m.start() + 5, m.end() - 1); |
||||||
|
content=content.replaceAll("@hbt:\\d*@", ""); |
||||||
|
try { |
||||||
|
hbtTid = Integer.parseInt(hbtIdString); |
||||||
|
if (DbUtils.getInt(con, "select count(*) from hbt_heartbeat where tid=?", hbtTid) > 0) |
||||||
|
isHbtFoundInDb = true; |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
result.append(" hbt:" + hbtIdString |
||||||
|
+ " konnte nicht in integer transformiert werden, Nachricht wird zwischengespeichert"); |
||||||
|
isHbtFoundInDb = false; |
||||||
|
} |
||||||
|
if (isHbtFoundInDb) { |
||||||
|
// TODO ggfs. mehrer Topics
|
||||||
|
int maxTopic = DbUtils.getInt(con, "select max(tid) from hbt_topic where hbt_id=?", hbtTid); |
||||||
|
// int maxNote = DbUtils.getInt(stm, "select max(tid) from hbt_note where
|
||||||
|
// hbt_id=" + hbtTid + " hbt_topic_id=" + maxTopic);
|
||||||
|
int newNoteId = createNote(con, stm, hbtTid, maxTopic, message, content); |
||||||
|
feedbackSubject = "Your new note was added to Heartbeat " + hbtTid; |
||||||
|
result.append("Feel free to view this HeartBeat by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_viewer.jsp?tid=" + hbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!foundHbtTag || !isHbtFoundInDb) { |
||||||
|
feedbackSubject = "Sorry, target hbt found found ..."; |
||||||
|
PreparedStatement pst=con.prepareStatement("insert into hbt_tmp_note (note) values (?)"); |
||||||
|
pst.setString(1,content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId=DbUtils.getInt(stm, "select max(tid) from hbt_tmp_note"); |
||||||
|
result.append("you can select the right hbt_id by visiting " + sxmail.getWTFAI()+"/servlet/SuperXmlMaske?tid=60040?note_id="+newNoteId); |
||||||
|
} |
||||||
|
stm.close(); |
||||||
|
con.close(); |
||||||
|
sendFeedbackEmail(feedbackSubject, result.toString(), message); |
||||||
|
} |
||||||
|
|
||||||
|
private void createNewHeartBeat(Message inMessage, String content) |
||||||
|
throws SQLException, MessagingException, IOException { |
||||||
|
int newHbtTid = performHbtInsert(inMessage, content); |
||||||
|
String text = "Feel free to complete this heartbeat's details by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_edit.jsp?tid=" + newHbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"; |
||||||
|
sendFeedbackEmail("Your new digital heartbeat has been created ...", text, inMessage); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Performs the creation of a new HeartBeat in the database |
||||||
|
* |
||||||
|
* @param message |
||||||
|
* @return newHbtTid |
||||||
|
* @throws SQLException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private int performHbtInsert(Message m, String content) throws SQLException, IOException, MessagingException { |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
|
||||||
|
int newHbtTid = createHbt(con, stm, content, m.getSubject()); |
||||||
|
int newTopicId = createTopic(stm, newHbtTid); |
||||||
|
createNote(con, stm, newHbtTid, newTopicId, m, content); |
||||||
|
con.close(); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
private int createHbt(Connection dbConnection, Statement stm, String content, String subject) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String primary_customer_id = identifyPrimaryCustomerId(dbConnection, stm, content); |
||||||
|
String name = StringUtils.replace(subject, "'", "''");// for SQL insert
|
||||||
|
// Sql insert - fuck prepared statements, nobody hacks this, I don't give a
|
||||||
|
// shit, not worth my extra time or effort, I want to get things done now while
|
||||||
|
// having fun :-)
|
||||||
|
stm.execute("select sp_update_sequence('hbt_heartbeat')"); |
||||||
|
String insertSql = "INSERT INTO hbt_heartbeat \n" + "( primary_customer_id,name," + " created_at, \n" |
||||||
|
+ " status \n" + ") \n" + "VALUES \n" + "( " + primary_customer_id + ",'" + name + "', " |
||||||
|
+ " today(), \n" + " 1 \n" + ") " + ""; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newHbtTid = DbUtils.getInt(stm, "select max(tid) from hbt_heartbeat"); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* Wenn im Text der weitergeleiteten Email der Absender mit @@ markiert ist, |
||||||
|
* z.B. @@hiber@his.de@@, diesen auslesen zugehörige Organisation auslesen |
||||||
|
* |
||||||
|
* @param m |
||||||
|
* @return String null oder key_apnr z.B. '1001' |
||||||
|
* @throws IOException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
private String identifyPrimaryCustomerId(Connection con, Statement stm, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String result = "null"; |
||||||
|
int pos1 = content.indexOf("@@"); |
||||||
|
int pos2 = content.substring(pos1 + 2).indexOf("@@"); |
||||||
|
if (pos1 > -1 && pos2 > -1) { |
||||||
|
String absender = content.substring(pos1 + 2); |
||||||
|
absender = absender.substring(0, absender.lastIndexOf("@@")); |
||||||
|
logger.log(Level.INFO," checking customer " + absender); |
||||||
|
int userinfo_id = DbUtils.getInt(con, "select tid from userinfo where email=?", absender); |
||||||
|
result = DbUtils.getString(stm, |
||||||
|
"select min(ch110_institut) from user_institution where userid=" + userinfo_id); |
||||||
|
|
||||||
|
if (result == null) |
||||||
|
result = "null"; |
||||||
|
else |
||||||
|
result = "'" + result + "'"; |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private int createTopic(Statement stm, int newHbtTid) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_topic')"); |
||||||
|
String insertSql = "INSERT INTO hbt_topic \n" + "( hbt_id,name, created_at)" + "VALUES (" + newHbtTid |
||||||
|
+ ",'Start',now() )"; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newTopicId = DbUtils.getInt(stm, "select max(tid) from hbt_topic"); |
||||||
|
return newTopicId; |
||||||
|
} |
||||||
|
|
||||||
|
private int createNote(Connection con, Statement stm, int hbtId, int topicId, Message m, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_note')"); |
||||||
|
PreparedStatement pst = con |
||||||
|
.prepareStatement(" INSERT INTO hbt_note (hbt_id,hbt_topic_id,note, created_at) VALUES (?,?,?,now());"); |
||||||
|
pst.setInt(1, hbtId); |
||||||
|
pst.setInt(2, topicId); |
||||||
|
|
||||||
|
pst.setString(3, content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId = DbUtils.getInt(stm, "select max(tid) from hbt_note"); |
||||||
|
saveAttachments(stm, hbtId, topicId, newNoteId, m); |
||||||
|
return newNoteId; |
||||||
|
} |
||||||
|
|
||||||
|
private void saveAttachments(Statement stm, int newHbtTid, int newTopicId, int newNoteId, Message m) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
// List<String> attachments = new ArrayList<String>();
|
||||||
|
Object content = m.getContent(); |
||||||
|
// if (content instanceof String) return null;
|
||||||
|
|
||||||
|
if (content instanceof Multipart) { |
||||||
|
Multipart multipart = (Multipart) content; |
||||||
|
for (int i = 0; i < multipart.getCount(); i++) { |
||||||
|
BodyPart part = multipart.getBodyPart(i); |
||||||
|
logger.log(Level.INFO,part.getFileName() + " " + part.getContentType() + " " + part.getDisposition()); |
||||||
|
if (part.getDisposition() != null && part.getDisposition().equalsIgnoreCase(Part.ATTACHMENT)) { |
||||||
|
// result.addAll(getAttachments(multipart.getBodyPart(i)));
|
||||||
|
String filename = SuperXManager.getWEB_INFPfad()+"/downloads/hbt_"+newHbtTid+"_" +newNoteId+"_"+FileUtils.removeProblemChars(part.getFileName()); |
||||||
|
sxDownloadsInsert(stm, newHbtTid, newTopicId, newNoteId, filename, part.getContentType()); |
||||||
|
// javaxmail >1.4 bodyPart.saveFile(filename);
|
||||||
|
// old version
|
||||||
|
InputStream is = part.getInputStream(); |
||||||
|
File f = new File(filename); |
||||||
|
FileOutputStream fos = new FileOutputStream(f); |
||||||
|
byte[] buf = new byte[4096]; |
||||||
|
int bytesRead; |
||||||
|
while ((bytesRead = is.read(buf)) != -1) { |
||||||
|
fos.write(buf, 0, bytesRead); |
||||||
|
} |
||||||
|
fos.close(); |
||||||
|
logger.log(Level.INFO," saving attachment " + (i++) + " as " + filename); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void sxDownloadsInsert(Statement stm, int newHbtTid, int newTopicId, int newNoteId, String filename, |
||||||
|
String contenttype) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('sx_downloads')"); |
||||||
|
String filenameShort = filename.substring(filename.indexOf(File.separator + "hbt") + 1); |
||||||
|
String insertSQLSxDownloads = "INSERT INTO sx_downloads \n" + "( \n" + " name, \n" + " importdatum, \n" |
||||||
|
+ " kommentar, \n" + " kommentar_url, \n" + " contenttype, \n" + " datei, \n" + " gueltig_seit, \n" |
||||||
|
+ " gueltig_bis \n" + ") \n" + "VALUES \n" + "( \n" + " '" + filenameShort + "', \n" + " today(), \n" |
||||||
|
+ " 'kommentar_value', \n" + " 'kommentar_url_value', \n" + " '" + contenttype + "', \n" + " '" |
||||||
|
+ filenameShort + "', \n" + " today(), \n" + " date_val('1.1.3000') \n" + ") \n" + ""; |
||||||
|
stm.execute(insertSQLSxDownloads); |
||||||
|
int newDownloadTid = DbUtils.getInt(stm, "select max(tid) from sx_downloads"); |
||||||
|
stm.executeUpdate("insert into hbt_attachment (hbt_id,topic_id,note_id,download_id) values (" + newHbtTid + "," |
||||||
|
+ newTopicId + "," + newNoteId + "," + newDownloadTid + ")"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* sendFeedBackEmail -- hier hätte ich gern automatisch newline in Zeile 60 |
||||||
|
* direkt unter createNewHeartBeat automatisch erzeugt, dann nach weiter unten |
||||||
|
* im Quelltext verlagert, damit von der Reihenfolge in |
||||||
|
* createNewHeartBeat(Message message) her passt |
||||||
|
* |
||||||
|
* @param newHbtTid : tid von neuem HeartBeat in der Datenbank |
||||||
|
* @param inMessage |
||||||
|
* @throws MessagingException |
||||||
|
* @throws AddressException |
||||||
|
*/ |
||||||
|
private void sendFeedbackEmail(String subject, String text, Message inMessage) |
||||||
|
throws AddressException, MessagingException { |
||||||
|
MimeMessage reply = sxmail.createMessage(); |
||||||
|
reply.setRecipients(Message.RecipientType.TO, inMessage.getFrom()); |
||||||
|
reply.setSubject(subject); |
||||||
|
reply.setText(text); |
||||||
|
sxmail.setMessage(reply); |
||||||
|
|
||||||
|
logger.log(Level.INFO,"Reply message happily sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
package de.memtext.lang; |
||||||
|
public class SingOrPluralWord { |
||||||
|
public final static SingOrPluralWord SEIN=new SingOrPluralWord("ist","sind"); |
||||||
|
private int count; |
||||||
|
private String singular,plural; |
||||||
|
public SingOrPluralWord(String singular,String plural) { |
||||||
|
this.singular=singular; |
||||||
|
this.plural=plural; |
||||||
|
} |
||||||
|
|
||||||
|
public static String format(int count,String sing,String plural) |
||||||
|
{ |
||||||
|
if (count==1) return count+" "+sing; |
||||||
|
else |
||||||
|
return count+" "+plural; |
||||||
|
} |
||||||
|
|
||||||
|
public String say(int count) |
||||||
|
{ |
||||||
|
if (count==1) return singular; |
||||||
|
else |
||||||
|
return plural; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
//Created on 12.12.2003 at 15:53:43
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue