package at.gv.egovernment.moa.spss.tsl.utils; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import org.sqlite.SQLiteErrorCode; import iaik.util.logging.Log; import iaik.util.logging._l; import iaik.util.logging.Log.MultiThreadLoggingGroup; import iaik.xml.crypto.tsl.DbTables; import iaik.xml.crypto.tsl.TSLImportFromFileContext; import iaik.xml.crypto.tsl.TSLOpenURIException; import iaik.xml.crypto.tsl.constants.Countries; import iaik.xml.crypto.tsl.ex.TSLExceptionB; import iaik.xml.crypto.tsl.ex.ThrowableAndLocatorAndMitigation; import iaik.xml.crypto.tsl.ex.SeverityAspect.Severity; import iaik.xml.crypto.tsl.fetch.TopLevelTslFetchContext; public class TSLEUImportFromFileContext extends TopLevelTslFetchContext { public TSLEUImportFromFileContext( Countries euTerritory, URL euTslURL, String workingdirectory, boolean sqlMultithreaded, boolean throwExceptions, boolean logExceptions, boolean throwWarnings, boolean logWarnings, boolean nullRedundancies) { super( euTerritory, euTslURL, workingdirectory, sqlMultithreaded, throwExceptions, logExceptions, throwWarnings, logWarnings, nullRedundancies); } public List getErrorsAndWarnings() { List errorsAndWarnings = new ArrayList(); errorsAndWarnings.addAll(this.fatals_); errorsAndWarnings.addAll(this.faildTransactions_); errorsAndWarnings.addAll(this.warnings_); return errorsAndWarnings; } @Override public boolean normalizeXML() { return true; } @Override public Object throwException(Throwable e, Method enclosingMethod, Object thisObject, Object[] parameters) { if (enclosingMethod != null){ if ( e instanceof TSLOpenURIException && enclosingMethod.getName().equals("processUrl") && TSLImportFromFileContext.class.isAssignableFrom(enclosingMethod.getDeclaringClass()) && parameters[1] instanceof File && e.getCause() instanceof IOException && parameters[0] instanceof URL ){ _l.err("Ignoring download error using old: " + parameters[0],null); wrapException(e); return parameters[1]; } } //we allow each and every funny stuff from the EU as long as it's not insecure if (e instanceof TSLExceptionB){ TSLExceptionB ve = (TSLExceptionB) e; Severity s = ve.getSeverity(); if ( s != null && s.ordinal() < Severity.insecure.ordinal()){ _l.err("Ignored Exception: ",ve); // if(logExceptions_){ warnings_.add( new ThrowableAndLocatorAndMitigation( ve, null, ve.getLocator(), ve.getMitigation() ) ); // } return null; } } return super.throwException(e, enclosingMethod, thisObject, parameters); } @Override public Boolean doesViolateRawHash(SQLException e, byte[] rawHash) { String msg = e.getMessage(); return ( msg.startsWith("["+SQLiteErrorCode.SQLITE_CONSTRAINT.name()+"]") && msg.contains("column " + DbTables.TSLDownload.C.rawHash + " is not unique") ); } public MultiThreadLoggingGroup getLoggingGroup() { return this; } StringBuilder log = new StringBuilder(); public void flushLog() { if (log != null && log.length() > 0) { Thread currentThread = Thread.currentThread(); String ncName = getNcName(currentThread); synchronized (log) { print( "<" + ncName + " state=\"" + currentThread.getState() + "\" " + " id=\"" + currentThread.getId() + "\">\n" + log.toString() + "\n"); log.setLength(0); } } } public void print(Object msg) { Log.print(msg); } }