List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:ch.kostceco.tools.siardexcerpt.SIARDexcerpt.java
/** Die Eingabe besteht aus mind 3 Parameter: [0] Pfad zur SIARD-Datei oder Verzeichnis [1] * configfile [2] Modul/*from w w w. j a va 2s .com*/ * * bersicht der Module: --init --search --extract sowie --finish * * bei --search kommen danach noch die Suchtexte und bei --extract die Schlssel * * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:config/applicationContext.xml"); /** SIARDexcerpt: Aufbau des Tools * * 1) init: Config Kopieren und ggf SIARD-Datei ins Workverzeichnis entpacken * * 2) search: gemss config die Tabelle mit Suchtext befragen und Ausgabe des Resultates * * 3) extract: mit den Keys anhand der config einen Records herausziehen und anzeigen * * 4) finish: Config-Kopie sowie Workverzeichnis lschen */ /* TODO: siehe Bemerkung im applicationContext-services.xml bezglich Injection in der * Superklasse aller Impl-Klassen ValidationModuleImpl validationModuleImpl = * (ValidationModuleImpl) context.getBean("validationmoduleimpl"); */ SIARDexcerpt siardexcerpt = (SIARDexcerpt) context.getBean("siardexcerpt"); // Ist die Anzahl Parameter (mind 3) korrekt? if (args.length < 3) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); System.exit(1); } String module = new String(args[2]); File siardDatei = new File(args[0]); File configFile = new File(args[1]); /* arg 1 gibt den Pfad zur configdatei an. Da dieser in ConfigurationServiceImpl hartcodiert * ist, wird diese nach "configuration/SIARDexcerpt.conf.xml" kopiert. */ File configFileHard = new File("configuration" + File.separator + "SIARDexcerpt.conf.xml"); // excerpt ist der Standardwert wird aber anhand der config dann gesetzt File directoryOfOutput = new File("excerpt"); // temp_SIARDexcerpt ist der Standardwert wird aber anhand der config dann gesetzt File tmpDir = new File("temp_SIARDexcerpt"); boolean okA = false; boolean okB = false; boolean okC = false; // die Anwendung muss mindestens unter Java 6 laufen String javaRuntimeVersion = System.getProperty("java.vm.version"); if (javaRuntimeVersion.compareTo("1.6.0") < 0) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_WRONG_JRE)); System.exit(1); } if (module.equalsIgnoreCase("--init")) { /** 1) init: Config Kopieren und ggf SIARD-Datei ins Workverzeichnis entpacken * * a) config muss existieren und SIARDexcerpt.conf.xml noch nicht * * b) Excerptverzeichnis mit schreibrechte und ggf anlegen * * c) Workverzeichnis muss leer sein und mit schreibrechte * * d) SIARD-Datei entpacken * * e) Struktur-Check SIARD-Verzeichnis * * TODO: Erledigt */ System.out.println("SIARDexcerpt: init"); /** a) config muss existieren und SIARDexcerpt.conf.xml noch nicht */ if (!configFile.exists()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_CONFIGFILE_FILENOTEXISTING, configFile.getAbsolutePath())); System.exit(1); } if (configFileHard.exists()) { System.out .println(siardexcerpt.getTextResourceService().getText(ERROR_CONFIGFILEHARD_FILEEXISTING)); System.exit(1); } Util.copyFile(configFile, configFileHard); /** b) Excerptverzeichnis mit schreibrechte und ggf anlegen */ String pathToOutput = siardexcerpt.getConfigurationService().getPathToOutput(); directoryOfOutput = new File(pathToOutput); if (!directoryOfOutput.exists()) { directoryOfOutput.mkdir(); } // Im Logverzeichnis besteht kein Schreibrecht if (!directoryOfOutput.canWrite()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_LOGDIRECTORY_NOTWRITABLE, directoryOfOutput)); // Lschen des configFileHard, falls eines angelegt wurde if (configFileHard.exists()) { Util.deleteDir(configFileHard); } System.exit(1); } if (!directoryOfOutput.isDirectory()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_LOGDIRECTORY_NODIRECTORY)); // Lschen des configFileHard, falls eines angelegt wurde if (configFileHard.exists()) { Util.deleteDir(configFileHard); } System.exit(1); } /** c) Workverzeichnis muss leer sein und mit schreibrechte */ String pathToWorkDir = siardexcerpt.getConfigurationService().getPathToWorkDir(); tmpDir = new File(pathToWorkDir); /* bestehendes Workverzeichnis Abbruch wenn nicht leer, da am Schluss das Workverzeichnis * gelscht wird und entsprechend bestehende Dateien gelscht werden knnen */ if (tmpDir.exists()) { if (tmpDir.isDirectory()) { // Get list of file in the directory. When its length is not zero the folder is not empty. String[] files = tmpDir.list(); if (files.length > 0) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_WORKDIRECTORY_EXISTS, pathToWorkDir)); // Lschen des configFileHard, falls eines angelegt wurde if (configFileHard.exists()) { Util.deleteDir(configFileHard); } System.exit(1); } } } if (!tmpDir.exists()) { tmpDir.mkdir(); } // Im Workverzeichnis besteht kein Schreibrecht if (!tmpDir.canWrite()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_WORKDIRECTORY_NOTWRITABLE, pathToWorkDir)); // Lschen des configFileHard, falls eines angelegt wurde if (configFileHard.exists()) { Util.deleteDir(configFileHard); } System.exit(1); } /** d) SIARD-Datei entpacken */ if (!siardDatei.exists()) { // SIARD-Datei existiert nicht System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_SIARDFILE_FILENOTEXISTING, siardDatei.getAbsolutePath())); // Lschen des configFileHard, falls eines angelegt wurde if (configFileHard.exists()) { Util.deleteDir(configFileHard); } System.exit(1); } if (!siardDatei.isDirectory()) { /* SIARD-Datei ist eine Datei * * Die Datei muss ins Workverzeichnis extrahiert werden. Dies erfolgt im Modul A. * * danach der Pfad zu SIARD-Datei dorthin zeigen lassen */ Controllerexcerpt controllerexcerpt = (Controllerexcerpt) context.getBean("controllerexcerpt"); File siardDateiNew = new File(pathToWorkDir + File.separator + siardDatei.getName()); okA = controllerexcerpt.executeA(siardDatei, siardDateiNew, ""); if (!okA) { // SIARD Datei konte nicht entpackt werden System.out.println(MESSAGE_XML_MODUL_A); System.out.println(ERROR_XML_A_CANNOTEXTRACTZIP); // Lschen des Arbeitsverzeichnisses und configFileHard, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (configFileHard.exists()) { Util.deleteDir(configFileHard); } // Fehler Extraktion --> invalide System.exit(2); } else { @SuppressWarnings("unused") File siardDateiOld = siardDatei; siardDatei = siardDateiNew; } } else { /* SIARD-Datei entpackt oder Datei war bereits ein Verzeichnis. * * Gerade bei grsseren SIARD-Dateien ist es sinnvoll an einer Stelle das ausgepackte SIARD * zu haben, damit diese nicht immer noch extrahiert werden muss */ } /** e) Struktur-Check SIARD-Verzeichnis */ File content = new File(siardDatei.getAbsolutePath() + File.separator + "content"); File header = new File(siardDatei.getAbsolutePath() + File.separator + "header"); File xsd = new File( siardDatei.getAbsolutePath() + File.separator + "header" + File.separator + "metadata.xsd"); File metadata = new File( siardDatei.getAbsolutePath() + File.separator + "header" + File.separator + "metadata.xml"); if (!content.exists() || !header.exists() || !xsd.exists() || !metadata.exists()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_XML_B_STRUCTURE)); // Lschen des Arbeitsverzeichnisses und configFileHard, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (configFileHard.exists()) { Util.deleteDir(configFileHard); } // Fehler Extraktion --> invalide System.exit(2); } else { // Struktur sieht plausibel aus, extraktion kann starten } } // End init if (module.equalsIgnoreCase("--search")) { /** 2) search: gemss config die Tabelle mit Suchtext befragen und Ausgabe des Resultates * * a) Ist die Anzahl Parameter (mind 4) korrekt? arg4 = Suchtext * * b) Suchtext einlesen * * c) search.xml vorbereiten (Header) und xsl in Output kopieren * * d) grep ausfhren * * e) Suchergebnis speichern und anzeigen (via GUI) * * TODO: Noch offen */ System.out.println("SIARDexcerpt: search"); String pathToOutput = siardexcerpt.getConfigurationService().getPathToOutput(); directoryOfOutput = new File(pathToOutput); if (!directoryOfOutput.exists()) { directoryOfOutput.mkdir(); } /** a) Ist die Anzahl Parameter (mind 4) korrekt? arg4 = Suchtext */ if (args.length < 4) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); System.exit(1); } if (!siardDatei.isDirectory()) { File siardDateiNew = new File(tmpDir.getAbsolutePath() + File.separator + siardDatei.getName()); if (!siardDateiNew.exists()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_NOINIT)); System.exit(1); } else { siardDatei = siardDateiNew; } } /** b) Suchtext einlesen */ String searchString = new String(args[3]); /** c) search.xml vorbereiten (Header) und xsl in Output kopieren */ // Zeitstempel der Datenextraktion java.util.Date nowStartS = new java.util.Date(); java.text.SimpleDateFormat sdfStartS = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeStartS = sdfStartS.format(nowStartS); /* Der SearchString kann zeichen enthalten, welche nicht im Dateinamen vorkommen drfen. * Entsprechend werden diese normalisiert */ String searchStringFilename = searchString.replaceAll("/", "_"); searchStringFilename = searchStringFilename.replaceAll(">", "_"); searchStringFilename = searchStringFilename.replaceAll("<", "_"); searchStringFilename = searchStringFilename.replace(".*", "_"); searchStringFilename = searchStringFilename.replaceAll("___", "_"); searchStringFilename = searchStringFilename.replaceAll("__", "_"); String outDateiNameS = siardDatei.getName() + "_" + searchStringFilename + "_SIARDsearch.xml"; outDateiNameS = outDateiNameS.replaceAll("__", "_"); // Informationen zum Archiv holen String archiveS = siardexcerpt.getConfigurationService().getArchive(); // Konfiguration des Outputs, ein File Logger wird zustzlich erstellt LogConfigurator logConfiguratorS = (LogConfigurator) context.getBean("logconfigurator"); String outFileNameS = logConfiguratorS.configure(directoryOfOutput.getAbsolutePath(), outDateiNameS); File outFileSearch = new File(outFileNameS); // Ab hier kann ins Output geschrieben werden... // Informationen zum XSL holen String pathToXSLS = siardexcerpt.getConfigurationService().getPathToXSLsearch(); File xslOrigS = new File(pathToXSLS); File xslCopyS = new File(directoryOfOutput.getAbsolutePath() + File.separator + xslOrigS.getName()); if (!xslCopyS.exists()) { Util.copyFile(xslOrigS, xslCopyS); } LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_HEADER, xslCopyS.getName())); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_START, ausgabeStartS)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_ARCHIVE, archiveS)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_INFO)); /** d) search: dies ist in einem eigenen Modul realisiert */ Controllerexcerpt controllerexcerptS = (Controllerexcerpt) context.getBean("controllerexcerpt"); okB = controllerexcerptS.executeB(siardDatei, outFileSearch, searchString); /** e) Ausgabe und exitcode */ if (!okB) { // Suche konnte nicht erfolgen LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_MODUL_B)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(ERROR_XML_B_CANNOTSEARCHRECORD)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_LOGEND)); System.out.println(MESSAGE_XML_MODUL_B); System.out.println(ERROR_XML_B_CANNOTSEARCHRECORD); System.out.println(""); // Lschen des Arbeitsverzeichnisses und configFileHard erfolgt erst bei schritt 4 finish // Fehler Extraktion --> invalide System.exit(2); } else { // Suche konnte durchgefhrt werden LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Lschen des Arbeitsverzeichnisses und configFileHard erfolgt erst bei schritt 4 finish // Record konnte extrahiert werden System.exit(0); } } // End search if (module.equalsIgnoreCase("--excerpt")) { /** 3) extract: mit den Keys anhand der config einen Records herausziehen und anzeigen * * a) Ist die Anzahl Parameter (mind 4) korrekt? arg4 = Suchtext * * b) extract.xml vorbereiten (Header) und xsl in Output kopieren * * c) extraktion: dies ist in einem eigenen Modul realisiert * * d) Ausgabe und exitcode * * TODO: Erledigt */ System.out.println("SIARDexcerpt: extract"); String pathToOutput = siardexcerpt.getConfigurationService().getPathToOutput(); directoryOfOutput = new File(pathToOutput); if (!directoryOfOutput.exists()) { directoryOfOutput.mkdir(); } /** a) Ist die Anzahl Parameter (mind 4) korrekt? arg4 = Suchtext */ if (args.length < 4) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); System.exit(1); } if (!siardDatei.isDirectory()) { File siardDateiNew = new File(tmpDir.getAbsolutePath() + File.separator + siardDatei.getName()); if (!siardDateiNew.exists()) { System.out.println(siardexcerpt.getTextResourceService().getText(ERROR_NOINIT)); System.exit(1); } else { siardDatei = siardDateiNew; } } /** b) extract.xml vorbereiten (Header) und xsl in Output kopieren */ // Zeitstempel der Datenextraktion java.util.Date nowStart = new java.util.Date(); java.text.SimpleDateFormat sdfStart = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeStart = sdfStart.format(nowStart); String excerptString = new String(args[3]); String outDateiName = siardDatei.getName() + "_" + excerptString + "_SIARDexcerpt.xml"; // Informationen zum Archiv holen String archive = siardexcerpt.getConfigurationService().getArchive(); // Konfiguration des Outputs, ein File Logger wird zustzlich erstellt LogConfigurator logConfigurator = (LogConfigurator) context.getBean("logconfigurator"); String outFileName = logConfigurator.configure(directoryOfOutput.getAbsolutePath(), outDateiName); File outFile = new File(outFileName); // Ab hier kann ins Output geschrieben werden... // Informationen zum XSL holen String pathToXSL = siardexcerpt.getConfigurationService().getPathToXSL(); File xslOrig = new File(pathToXSL); File xslCopy = new File(directoryOfOutput.getAbsolutePath() + File.separator + xslOrig.getName()); if (!xslCopy.exists()) { Util.copyFile(xslOrig, xslCopy); } LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_HEADER, xslCopy.getName())); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_START, ausgabeStart)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_ARCHIVE, archive)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_INFO)); /** c) extraktion: dies ist in einem eigenen Modul realisiert */ Controllerexcerpt controllerexcerpt = (Controllerexcerpt) context.getBean("controllerexcerpt"); okC = controllerexcerpt.executeC(siardDatei, outFile, excerptString); /** d) Ausgabe und exitcode */ if (!okC) { // Record konnte nicht extrahiert werden LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_MODUL_C)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(ERROR_XML_C_CANNOTEXTRACTRECORD)); LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_LOGEND)); System.out.println(MESSAGE_XML_MODUL_C); System.out.println(ERROR_XML_C_CANNOTEXTRACTRECORD); System.out.println(""); // Lschen des Arbeitsverzeichnisses und configFileHard erfolgt erst bei schritt 4 finish // Fehler Extraktion --> invalide System.exit(2); } else { // Record konnte extrahiert werden LOGGER.logError(siardexcerpt.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Lschen des Arbeitsverzeichnisses und configFileHard erfolgt erst bei schritt 4 finish // Record konnte extrahiert werden System.exit(0); } } // End extract if (module.equalsIgnoreCase("--finish")) { /** 4) finish: Config-Kopie sowie Workverzeichnis lschen * * TODO: Erledigt */ System.out.println("SIARDexcerpt: finish"); // Lschen des Arbeitsverzeichnisses und confiFileHard, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (configFileHard.exists()) { Util.deleteDir(configFileHard); } } // End finish }
From source file:ch.kostceco.tools.kostsimy.KOSTSimy.java
/** Die Eingabe besteht aus 2 Parameter: [0] Original-Ordner [1] Replica-Ordner * // w w w . ja va2s . c om * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:config/applicationContext.xml"); // Zeitstempel Start java.util.Date nowStart = new java.util.Date(); java.text.SimpleDateFormat sdfStart = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeStart = sdfStart.format(nowStart); KOSTSimy kostsimy = (KOSTSimy) context.getBean("kostsimy"); File configFile = new File("configuration" + File.separator + "kostsimy.conf.xml"); // Ueberprfung des Parameters (Log-Verzeichnis) String pathToLogfile = kostsimy.getConfigurationService().getPathToLogfile(); File directoryOfLogfile = new File(pathToLogfile); if (!directoryOfLogfile.exists()) { directoryOfLogfile.mkdir(); } // Im Logverzeichnis besteht kein Schreibrecht if (!directoryOfLogfile.canWrite()) { System.out.println( kostsimy.getTextResourceService().getText(ERROR_LOGDIRECTORY_NOTWRITABLE, directoryOfLogfile)); System.exit(1); } if (!directoryOfLogfile.isDirectory()) { System.out.println(kostsimy.getTextResourceService().getText(ERROR_LOGDIRECTORY_NODIRECTORY)); System.exit(1); } // Ist die Anzahl Parameter (2) korrekt? if (args.length > 3) { System.out.println(kostsimy.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); System.exit(1); } File origDir = new File(args[0]); File repDir = new File(args[1]); File logDatei = null; logDatei = origDir; // Informationen zum Arbeitsverzeichnis holen String pathToWorkDir = kostsimy.getConfigurationService().getPathToWorkDir(); /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim * entsprechenden Modul die property anzugeben: <property name="configurationService" * ref="configurationService" /> */ // Konfiguration des Loggings, ein File Logger wird zustzlich erstellt LogConfigurator logConfigurator = (LogConfigurator) context.getBean("logconfigurator"); String logFileName = logConfigurator.configure(directoryOfLogfile.getAbsolutePath(), logDatei.getName()); File logFile = new File(logFileName); // Ab hier kann ins log geschrieben werden... LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_HEADER)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_START, ausgabeStart)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_END)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_INFO)); System.out.println("KOST-Simy"); System.out.println(""); if (!origDir.exists()) { // Das Original-Verzeichnis existiert nicht LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_NOORIGDIR, origDir.getAbsolutePath()))); System.out .println(kostsimy.getTextResourceService().getText(ERROR_NOORIGDIR, origDir.getAbsolutePath())); System.exit(1); } if (!repDir.exists()) { // Das Replica-Verzeichnis existiert nicht LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_NOREPDIR1, repDir.getAbsolutePath()))); System.out .println(kostsimy.getTextResourceService().getText(ERROR_NOREPDIR1, repDir.getAbsolutePath())); System.exit(1); } File xslOrig = new File("resources" + File.separator + "kost-simy.xsl"); File xslCopy = new File(directoryOfLogfile.getAbsolutePath() + File.separator + "kost-simy.xsl"); if (!xslCopy.exists()) { Util.copyFile(xslOrig, xslCopy); } // Informationen zur prozentualen Stichprobe holen String randomTest = kostsimy.getConfigurationService().getRandomTest(); /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim * entsprechenden Modul die property anzugeben: <property name="configurationService" * ref="configurationService" /> */ int iRandomTest = 100; try { iRandomTest = Integer.parseInt(randomTest); } catch (Exception ex) { // unzulaessige Eingabe --> 50 wird gesetzt iRandomTest = 50; } if (iRandomTest > 100 || iRandomTest < 1) { // unzulaessige Eingabe --> 50 wird gesetzt iRandomTest = 50; } File tmpDir = new File(pathToWorkDir); /* bestehendes Workverzeichnis Abbruch wenn nicht leer, da am Schluss das Workverzeichnis * gelscht wird und entsprechend bestehende Dateien gelscht werden knnen */ if (tmpDir.exists()) { if (tmpDir.isDirectory()) { // Get list of file in the directory. When its length is not zero the folder is not empty. String[] files = tmpDir.list(); if (files.length > 0) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_WORKDIRECTORY_EXISTS, pathToWorkDir))); System.out.println( kostsimy.getTextResourceService().getText(ERROR_WORKDIRECTORY_EXISTS, pathToWorkDir)); System.exit(1); } } } // Im Pfad keine Sonderzeichen Programme knnen evtl abstrzen String patternStr = "[^!#\\$%\\(\\)\\+,\\-_\\.=@\\[\\]\\{\\}\\~:\\\\a-zA-Z0-9 ]"; Pattern pattern = Pattern.compile(patternStr); String name = tmpDir.getAbsolutePath(); String[] pathElements = name.split("/"); for (int i = 0; i < pathElements.length; i++) { String element = pathElements[i]; Matcher matcher = pattern.matcher(element); boolean matchFound = matcher.find(); if (matchFound) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name))); System.out.println(kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name)); System.exit(1); } } // die Anwendung muss mindestens unter Java 6 laufen String javaRuntimeVersion = System.getProperty("java.vm.version"); if (javaRuntimeVersion.compareTo("1.6.0") < 0) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_WRONG_JRE))); System.out.println(kostsimy.getTextResourceService().getText(ERROR_WRONG_JRE)); System.exit(1); } // bestehendes Workverzeichnis wieder anlegen if (!tmpDir.exists()) { tmpDir.mkdir(); File origDirTmp = new File(tmpDir.getAbsolutePath() + File.separator + "orig"); File repDirTmp = new File(tmpDir.getAbsolutePath() + File.separator + "rep"); origDirTmp.mkdir(); repDirTmp.mkdir(); } // Im workverzeichnis besteht kein Schreibrecht if (!tmpDir.canWrite()) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_WORKDIRECTORY_NOTWRITABLE, tmpDir))); System.out.println(kostsimy.getTextResourceService().getText(ERROR_WORKDIRECTORY_NOTWRITABLE, tmpDir)); System.exit(1); } // Im Pfad keine Sonderzeichen --> Absturzgefahr name = origDir.getAbsolutePath(); pathElements = name.split("/"); for (int i = 0; i < pathElements.length; i++) { String element = pathElements[i]; Matcher matcher = pattern.matcher(element); boolean matchFound = matcher.find(); if (matchFound) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name))); System.out.println(kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name)); System.exit(1); } } name = repDir.getAbsolutePath(); pathElements = name.split("/"); for (int i = 0; i < pathElements.length; i++) { String element = pathElements[i]; Matcher matcher = pattern.matcher(element); boolean matchFound = matcher.find(); if (matchFound) { LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name))); System.out.println(kostsimy.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name)); System.exit(1); } } LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_IMAGE1)); float count = 0; int countNio = 0; int countIo = 0; float countVal = 0; int countNotVal = 0; float percentage = (float) 0.0; if (!origDir.isDirectory()) { // TODO: Bildervergleich zweier Dateien --> erledigt --> nur Marker if (repDir.isDirectory()) { // Das Replica-ist ein Verzeichnis, aber Original eine Datei LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_NOREPDIR2, repDir.getAbsolutePath()))); System.out.println( kostsimy.getTextResourceService().getText(ERROR_NOREPDIR2, repDir.getAbsolutePath())); System.exit(1); } boolean compFile = compFile(origDir, logFileName, directoryOfLogfile, repDir, tmpDir); float statIo = 0; int statNio = 0; float statUn = 0; if (compFile) { statIo = 100; } else { statNio = 100; } LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_IMAGE2)); LOGGER.logError( kostsimy.getTextResourceService().getText(MESSAGE_XML_STATISTICS, statIo, statNio, statUn)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostsimy.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTSimyLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError( "<Error>" + kostsimy.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } if (compFile) { // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Validierte Datei valide System.exit(0); } else { // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Fehler in Validierte Datei --> invalide System.exit(2); } } else { // TODO: Bildervergleich zweier Verzeichnisse --> in Arbeit --> nur Marker if (!repDir.isDirectory()) { // Das Replica-ist eine Datei, aber Original ein Ordner LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_IOE, kostsimy.getTextResourceService().getText(ERROR_NOREPDIR3, repDir.getAbsolutePath()))); System.out.println( kostsimy.getTextResourceService().getText(ERROR_NOREPDIR3, repDir.getAbsolutePath())); System.exit(1); } Map<String, File> fileMap = Util.getFileMap(origDir, false); Set<String> fileMapKeys = fileMap.keySet(); boolean other = false; for (Iterator<String> iterator = fileMapKeys.iterator(); iterator.hasNext();) { String entryName = iterator.next(); File newFile = fileMap.get(entryName); if (!newFile.isDirectory()) { origDir = newFile; count = count + 1; if ((origDir.getAbsolutePath().toLowerCase().endsWith(".pdf") || origDir.getAbsolutePath().toLowerCase().endsWith(".pdfa") || origDir.getAbsolutePath().toLowerCase().endsWith(".tif") || origDir.getAbsolutePath().toLowerCase().endsWith(".tiff") || origDir.getAbsolutePath().toLowerCase().endsWith(".jpeg") || origDir.getAbsolutePath().toLowerCase().endsWith(".jpg") || origDir.getAbsolutePath().toLowerCase().endsWith(".jpe") || origDir.getAbsolutePath().toLowerCase().endsWith(".jp2") || origDir.getAbsolutePath().toLowerCase().endsWith(".gif") || origDir.getAbsolutePath().toLowerCase().endsWith(".png") || origDir.getAbsolutePath().toLowerCase().endsWith(".bmp"))) { percentage = 100 / count * countVal; if (percentage < iRandomTest) { // if ( 100 / count * (countVal + 1) <= iRandomTest ) { countVal = countVal + 1; String origWithOutExt = FilenameUtils.removeExtension(origDir.getName()); File repFile = new File( repDir.getAbsolutePath() + File.separator + origWithOutExt + ".pdf"); if (!repFile.exists()) { repFile = new File( repDir.getAbsolutePath() + File.separator + origWithOutExt + ".pdfa"); if (!repFile.exists()) { repFile = new File( repDir.getAbsolutePath() + File.separator + origWithOutExt + ".tif"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".tiff"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".jpeg"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".jpg"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".jpe"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".jp2"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".gif"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".png"); if (!repFile.exists()) { repFile = new File(repDir.getAbsolutePath() + File.separator + origWithOutExt + ".bmp"); if (!repFile.exists()) { other = true; LOGGER.logError(kostsimy .getTextResourceService() .getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError(kostsimy .getTextResourceService() .getText(MESSAGE_XML_COMPFILE, origDir)); LOGGER.logError(kostsimy .getTextResourceService().getText( MESSAGE_XML_VALERGEBNIS_NOTVALIDATED)); LOGGER.logError( kostsimy.getTextResourceService() .getText(ERROR_NOREP, origDir.getName())); LOGGER.logError(kostsimy .getTextResourceService().getText( MESSAGE_XML_VALERGEBNIS_CLOSE)); } } } } } } } } } } } if (!other) { boolean compFile = compFile(origDir, logFileName, directoryOfLogfile, repFile, tmpDir); if (compFile) { // Vergleich bestanden countIo = countIo + 1; } else { // Vergleich nicht bestanden countNio = countNio + 1; } } } else { countNotVal = countNotVal + 1; LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError( kostsimy.getTextResourceService().getText(MESSAGE_XML_COMPFILE, origDir)); LOGGER.logError(kostsimy.getTextResourceService() .getText(MESSAGE_XML_VALERGEBNIS_NOTVALIDATED)); LOGGER.logError( kostsimy.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); } } else { countNotVal = countNotVal + 1; LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_COMPFILE, origDir)); LOGGER.logError( kostsimy.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_NOTVALIDATED)); LOGGER.logError( kostsimy.getTextResourceService().getText(ERROR_INCORRECTFILEENDING, origDir)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); } } } if (countNio == 0 && countIo == 0) { // keine Dateien verglichen LOGGER.logError(kostsimy.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS)); System.out.println(kostsimy.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS)); } float statIo = 100 / (float) count * (float) countIo; float statNio = 100 / (float) count * (float) countNio; float statUn = 100 - statIo - statNio; LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_IMAGE2)); LOGGER.logError( kostsimy.getTextResourceService().getText(MESSAGE_XML_STATISTICS, statIo, statNio, statUn)); LOGGER.logError(kostsimy.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostsimy.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTSimyLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError( "<Error>" + kostsimy.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } if (countNio == 0 && countIo == 0) { // keine Dateien verglichen bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } System.exit(1); } else if (countNio == 0) { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // alle Validierten Dateien valide System.exit(0); } else { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Fehler in Validierten Dateien --> invalide System.exit(2); } if (tmpDir.exists()) { Util.deleteDir(tmpDir); tmpDir.deleteOnExit(); } } }
From source file:edu.nyu.tandon.tool.RawHits.java
@SuppressWarnings("unchecked") public static void main(final String[] arg) throws Exception { SimpleJSAP jsap = new SimpleJSAP(RawHits.class.getName(), "Loads indices relative to a collection, possibly loads the collection, and answers to queries.", new Parameter[] { new FlaggedOption("collection", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'c', "collection", "The collection of documents indexed by the given indices."), new FlaggedOption("objectCollection", new ObjectParser(DocumentCollection.class, MG4JClassParser.PACKAGE), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "object-collection", "An object specification describing a document collection."), new FlaggedOption("titleList", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 't', "title-list", "A serialized big list of titles (will override collection titles if specified)."), new FlaggedOption("titleFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'T', "title-file", "A file of newline-separated, UTF-8 titles (will override collection titles if specified)."), new FlaggedOption("input", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'I', "input", "A file containing the input."), new Switch("noSizes", 'n', "no-sizes", "Disable loading document sizes (they are necessary for BM25 scoring)."), new Switch("http", 'h', "http", "Starts an HTTP query server."), new Switch("verbose", 'v', "verbose", "Print full exception stack traces."), new FlaggedOption("itemClass", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'i', "item-class", "The class that will handle item display in the HTTP server."), new FlaggedOption("itemMimeType", JSAP.STRING_PARSER, "text/html", JSAP.NOT_REQUIRED, 'm', "item-mime-type", "A MIME type suggested to the class handling item display in the HTTP server."), new FlaggedOption("port", JSAP.INTEGER_PARSER, "4242", JSAP.NOT_REQUIRED, 'p', "port", "The port on localhost where the server will appear."), new UnflaggedOption("basenameWeight", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.GREEDY, "The indices that the servlet will use. Indices are specified using their basename, optionally followed by a colon and a double representing the weight used to score results from that index. Indices without a specified weight are weighted 1."), new Switch("noMplex", 'P', "noMplex", "Starts with multiplex disabled."), new FlaggedOption("results", JSAP.INTEGER_PARSER, "1000", JSAP.NOT_REQUIRED, 'r', "results", "The # of results to display"), new FlaggedOption("mode", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'M', "time", "The results display mode"), new FlaggedOption("divert", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'd', "divert", "output file"), new FlaggedOption("dumpsize", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'D', "dumpsize", "number of queries before dumping") });//from ww w . ja v a 2 s. com final JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return; final DocumentCollection documentCollection = (DocumentCollection) (jsapResult.userSpecified("collection") ? AbstractDocumentSequence.load(jsapResult.getString("collection")) : jsapResult.userSpecified("objectCollection") ? jsapResult.getObject("objectCollection") : null); final BigList<? extends CharSequence> titleList = (BigList<? extends CharSequence>) (jsapResult .userSpecified("titleList") ? BinIO.loadObject(jsapResult.getString("titleList")) : jsapResult.userSpecified("titleFile") ? new FileLinesBigList(jsapResult.getString("titleFile"), "UTF-8") : null); final String[] basenameWeight = jsapResult.getStringArray("basenameWeight"); final Object2ReferenceLinkedOpenHashMap<String, Index> indexMap = new Object2ReferenceLinkedOpenHashMap<String, Index>( Hash.DEFAULT_INITIAL_SIZE, .5f); final Reference2DoubleOpenHashMap<Index> index2Weight = new Reference2DoubleOpenHashMap<Index>(); final boolean verbose = jsapResult.getBoolean("verbose"); final boolean loadSizes = !jsapResult.getBoolean("noSizes"); RawHits.loadIndicesFromSpec(basenameWeight, loadSizes, documentCollection, indexMap, index2Weight); final long numberOfDocuments = indexMap.values().iterator().next().numberOfDocuments; if (titleList != null && titleList.size64() != numberOfDocuments) throw new IllegalArgumentException("The number of titles (" + titleList.size64() + " and the number of documents (" + numberOfDocuments + ") do not match"); final Object2ObjectOpenHashMap<String, TermProcessor> termProcessors = new Object2ObjectOpenHashMap<String, TermProcessor>( indexMap.size()); for (String alias : indexMap.keySet()) termProcessors.put(alias, indexMap.get(alias).termProcessor); final SimpleParser simpleParser = new SimpleParser(indexMap.keySet(), indexMap.firstKey(), termProcessors); final Reference2ReferenceMap<Index, Object> index2Parser = new Reference2ReferenceOpenHashMap<Index, Object>(); /* // Fetch parsers for payload-based fields. for( Index index: indexMap.values() ) if ( index.hasPayloads ) { if ( index.payload.getClass() == DatePayload.class ) index2Parser.put( index, DateFormat.getDateInstance( DateFormat.SHORT, Locale.UK ) ); } */ final HitsQueryEngine queryEngine = new HitsQueryEngine(simpleParser, new DocumentIteratorBuilderVisitor( indexMap, index2Parser, indexMap.get(indexMap.firstKey()), MAX_STEMMING), indexMap); queryEngine.setWeights(index2Weight); queryEngine.score(new Scorer[] { new BM25Scorer(), new VignaScorer() }, new double[] { 1, 1 }); queryEngine.multiplex = !jsapResult.userSpecified("moPlex") || jsapResult.getBoolean("noMplex"); queryEngine.intervalSelector = null; queryEngine.equalize(1000); RawHits query = new RawHits(queryEngine); // start docHits with at least 10K results query.interpretCommand("$score BM25Scorer"); // query.interpretCommand("$mode time"); if (jsapResult.userSpecified("divert")) query.interpretCommand("$divert " + jsapResult.getObject("divert")); query.displayMode = OutputType.DOCHHITS; query.maxOutput = jsapResult.getInt("results", 1000); String q; int n = 0; String lastQ = ""; try { final BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(jsapResult.getString("input")))); final ObjectArrayList<DocumentScoreInfo<ObjectArrayList<Byte>>> results = new ObjectArrayList<DocumentScoreInfo<ObjectArrayList<Byte>>>(); for (;;) { q = br.readLine(); if (q == null) { System.err.println(); break; // CTRL-D } if (q.length() == 0) continue; if (q.charAt(0) == '$') { if (!query.interpretCommand(q)) break; continue; } queryCount++; long time = -System.nanoTime(); if (q.compareTo(lastQ) != 0) { try { n = queryEngine.process(q, 0, query.maxOutput, results); } catch (QueryParserException e) { if (verbose) e.getCause().printStackTrace(System.err); else System.err.println(e.getCause()); continue; } catch (Exception e) { if (verbose) e.printStackTrace(System.err); else System.err.println(e); continue; } lastQ = q; } time += System.nanoTime(); query.output(results, documentCollection, titleList, TextMarker.TEXT_BOLDFACE); } } finally { } }
From source file:edu.nyu.tandon.tool.BinnedRawHits.java
@SuppressWarnings("unchecked") public static void main(final String[] arg) throws Exception { SimpleJSAP jsap = new SimpleJSAP(BinnedRawHits.class.getName(), "Loads indices relative to a collection, possibly loads the collection, and answers to queries.", new Parameter[] { new FlaggedOption("collection", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'c', "collection", "The collection of documents indexed by the given indices."), new FlaggedOption("objectCollection", new ObjectParser(DocumentCollection.class, MG4JClassParser.PACKAGE), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "object-collection", "An object specification describing a document collection."), new FlaggedOption("titleList", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 't', "title-list", "A serialized big list of titles (will override collection titles if specified)."), new FlaggedOption("titleFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'T', "title-file", "A file of newline-separated, UTF-8 titles (will override collection titles if specified)."), new FlaggedOption("input", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'I', "input", "A file containing the input."), new Switch("noSizes", 'n', "no-sizes", "Disable loading document sizes (they are necessary for BM25 scoring)."), new Switch("http", 'h', "http", "Starts an HTTP query server."), new Switch("verbose", 'v', "verbose", "Print full exception stack traces."), new FlaggedOption("itemClass", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'i', "item-class", "The class that will handle item display in the HTTP server."), new FlaggedOption("itemMimeType", JSAP.STRING_PARSER, "text/html", JSAP.NOT_REQUIRED, 'm', "item-mime-type", "A MIME type suggested to the class handling item display in the HTTP server."), new FlaggedOption("port", JSAP.INTEGER_PARSER, "4242", JSAP.NOT_REQUIRED, 'p', "port", "The port on localhost where the server will appear."), new UnflaggedOption("basenameWeight", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.GREEDY, "The indices that the servlet will use. Indices are specified using their basename, optionally followed by a colon and a double representing the weight used to score results from that index. Indices without a specified weight are weighted 1."), new Switch("noMplex", 'P', "noMplex", "Starts with multiplex disabled."), new FlaggedOption("results", JSAP.INTEGER_PARSER, "1000", JSAP.NOT_REQUIRED, 'r', "results", "The # of results to display"), new FlaggedOption("mode", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'M', "time", "The results display mode"), new FlaggedOption("divert", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'd', "divert", "output file"), new FlaggedOption("dumpsize", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'D', "dumpsize", "number of queries before dumping") });//from ww w . j a va 2s .c om final JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return; final DocumentCollection documentCollection = (DocumentCollection) (jsapResult.userSpecified("collection") ? AbstractDocumentSequence.load(jsapResult.getString("collection")) : jsapResult.userSpecified("objectCollection") ? jsapResult.getObject("objectCollection") : null); final BigList<? extends CharSequence> titleList = (BigList<? extends CharSequence>) (jsapResult .userSpecified("titleList") ? BinIO.loadObject(jsapResult.getString("titleList")) : jsapResult.userSpecified("titleFile") ? new FileLinesBigList(jsapResult.getString("titleFile"), "UTF-8") : null); final String[] basenameWeight = jsapResult.getStringArray("basenameWeight"); final Object2ReferenceLinkedOpenHashMap<String, Index> indexMap = new Object2ReferenceLinkedOpenHashMap<String, Index>( Hash.DEFAULT_INITIAL_SIZE, .5f); final Reference2DoubleOpenHashMap<Index> index2Weight = new Reference2DoubleOpenHashMap<Index>(); final boolean verbose = jsapResult.getBoolean("verbose"); final boolean loadSizes = !jsapResult.getBoolean("noSizes"); BinnedRawHits.loadIndicesFromSpec(basenameWeight, loadSizes, documentCollection, indexMap, index2Weight); final long numberOfDocuments = indexMap.values().iterator().next().numberOfDocuments; if (titleList != null && titleList.size64() != numberOfDocuments) throw new IllegalArgumentException("The number of titles (" + titleList.size64() + " and the number of documents (" + numberOfDocuments + ") do not match"); final Object2ObjectOpenHashMap<String, TermProcessor> termProcessors = new Object2ObjectOpenHashMap<String, TermProcessor>( indexMap.size()); for (String alias : indexMap.keySet()) termProcessors.put(alias, indexMap.get(alias).termProcessor); final SimpleParser simpleParser = new SimpleParser(indexMap.keySet(), indexMap.firstKey(), termProcessors); final Reference2ReferenceMap<Index, Object> index2Parser = new Reference2ReferenceOpenHashMap<Index, Object>(); /* // Fetch parsers for payload-based fields. for( Index index: indexMap.values() ) if ( index.hasPayloads ) { if ( index.payload.getClass() == DatePayload.class ) index2Parser.put( index, DateFormat.getDateInstance( DateFormat.SHORT, Locale.UK ) ); } */ final HitsQueryEngine queryEngine = new HitsQueryEngine(simpleParser, new DocumentIteratorBuilderVisitor( indexMap, index2Parser, indexMap.get(indexMap.firstKey()), MAX_STEMMING), indexMap); queryEngine.setWeights(index2Weight); queryEngine.score(new Scorer[] { new BM25Scorer(), new VignaScorer() }, new double[] { 1, 1 }); queryEngine.multiplex = !jsapResult.userSpecified("moPlex") || jsapResult.getBoolean("noMplex"); queryEngine.intervalSelector = null; queryEngine.equalize(1000); BinnedRawHits query = new BinnedRawHits(queryEngine); // start docHits with at least 10K results query.interpretCommand("$score BM25Scorer"); query.interpretCommand("$mode time"); if (jsapResult.userSpecified("divert")) query.interpretCommand("$divert " + jsapResult.getObject("divert")); query.displayMode = OutputType.DOCHHITS; query.maxOutput = jsapResult.getInt("results", 10000); String q; int n = 0; int dumpsize = jsapResult.userSpecified("dumpsize") ? jsapResult.getInt("dumpsize", 10000) : 10000; buildBins(query.maxOutput, (int) numberOfDocuments); String lastQ = ""; try { final BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(jsapResult.getString("input")))); final ObjectArrayList<DocumentScoreInfo<ObjectArrayList<Byte>>> results = new ObjectArrayList<DocumentScoreInfo<ObjectArrayList<Byte>>>(); for (;;) { q = br.readLine(); if (q == null) { System.err.println(); break; // CTRL-D } if (q.length() == 0) continue; if (q.charAt(0) == '$') { if (!query.interpretCommand(q)) break; continue; } queryCount++; long time = -System.nanoTime(); if (q.compareTo(lastQ) != 0) { try { n = queryEngine.process(q, 0, query.maxOutput, results); } catch (QueryParserException e) { if (verbose) e.getCause().printStackTrace(System.err); else System.err.println(e.getCause()); continue; } catch (Exception e) { if (verbose) e.printStackTrace(System.err); else System.err.println(e); continue; } lastQ = q; } time += System.nanoTime(); query.output(results, documentCollection, titleList, TextMarker.TEXT_BOLDFACE); // dump batch if (queryCount % dumpsize == 0) { dumpBatch(query, numberOfDocuments, false); } // check postHits if (query.postHits.size() > 100000000) dumpPosthits(query, numberOfDocuments, false); } } finally { dumpBatch(query, numberOfDocuments, true); dumpPosthits(query, numberOfDocuments, true); if (query.outputDH != System.out) query.outputDH.close(); } }
From source file:edu.nyu.tandon.tool.RawDocHits_deprecated.java
@SuppressWarnings("unchecked") public static void main(final String[] arg) throws Exception { SimpleJSAP jsap = new SimpleJSAP(RawDocHits_deprecated.class.getName(), "Loads indices relative to a collection, possibly loads the collection, and answers to queries.", new Parameter[] { new FlaggedOption("collection", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'c', "collection", "The collection of documents indexed by the given indices."), new FlaggedOption("objectCollection", new ObjectParser(DocumentCollection.class, MG4JClassParser.PACKAGE), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "object-collection", "An object specification describing a document collection."), new FlaggedOption("titleList", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 't', "title-list", "A serialized big list of titles (will override collection titles if specified)."), new FlaggedOption("titleFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'T', "title-file", "A file of newline-separated, UTF-8 titles (will override collection titles if specified)."), new FlaggedOption("input", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'I', "input", "A file containing the input."), new Switch("noSizes", 'n', "no-sizes", "Disable loading document sizes (they are necessary for BM25 scoring)."), new Switch("http", 'h', "http", "Starts an HTTP query server."), new Switch("verbose", 'v', "verbose", "Print full exception stack traces."), new FlaggedOption("itemClass", MG4JClassParser.getParser(), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'i', "item-class", "The class that will handle item display in the HTTP server."), new FlaggedOption("itemMimeType", JSAP.STRING_PARSER, "text/html", JSAP.NOT_REQUIRED, 'm', "item-mime-type", "A MIME type suggested to the class handling item display in the HTTP server."), new FlaggedOption("port", JSAP.INTEGER_PARSER, "4242", JSAP.NOT_REQUIRED, 'p', "port", "The port on localhost where the server will appear."), new UnflaggedOption("basenameWeight", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.GREEDY, "The indices that the servlet will use. Indices are specified using their basename, optionally followed by a colon and a double representing the weight used to score results from that index. Indices without a specified weight are weighted 1."), new Switch("noMplex", 'P', "noMplex", "Starts with multiplex disabled."), new FlaggedOption("results", JSAP.INTEGER_PARSER, "1000", JSAP.NOT_REQUIRED, 'r', "results", "The # of results to display"), new FlaggedOption("mode", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'M', "time", "The results display mode"), new FlaggedOption("divert", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'd', "divert", "output file"), new FlaggedOption("dumpsize", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'D', "dumpsize", "number of queries before dumping") });//from w ww.j av a2s . co m final JSAPResult jsapResult = jsap.parse(arg); if (jsap.messagePrinted()) return; final DocumentCollection documentCollection = (DocumentCollection) (jsapResult.userSpecified("collection") ? AbstractDocumentSequence.load(jsapResult.getString("collection")) : jsapResult.userSpecified("objectCollection") ? jsapResult.getObject("objectCollection") : null); final BigList<? extends CharSequence> titleList = (BigList<? extends CharSequence>) (jsapResult .userSpecified("titleList") ? BinIO.loadObject(jsapResult.getString("titleList")) : jsapResult.userSpecified("titleFile") ? new FileLinesBigList(jsapResult.getString("titleFile"), "UTF-8") : null); final String[] basenameWeight = jsapResult.getStringArray("basenameWeight"); final Object2ReferenceLinkedOpenHashMap<String, Index> indexMap = new Object2ReferenceLinkedOpenHashMap<String, Index>( Hash.DEFAULT_INITIAL_SIZE, .5f); final Reference2DoubleOpenHashMap<Index> index2Weight = new Reference2DoubleOpenHashMap<Index>(); final boolean verbose = jsapResult.getBoolean("verbose"); final boolean loadSizes = !jsapResult.getBoolean("noSizes"); RawDocHits_deprecated.loadIndicesFromSpec(basenameWeight, loadSizes, documentCollection, indexMap, index2Weight); final long numberOfDocuments = indexMap.values().iterator().next().numberOfDocuments; if (titleList != null && titleList.size64() != numberOfDocuments) throw new IllegalArgumentException("The number of titles (" + titleList.size64() + " and the number of documents (" + numberOfDocuments + ") do not match"); final Object2ObjectOpenHashMap<String, TermProcessor> termProcessors = new Object2ObjectOpenHashMap<String, TermProcessor>( indexMap.size()); for (String alias : indexMap.keySet()) termProcessors.put(alias, indexMap.get(alias).termProcessor); final SimpleParser simpleParser = new SimpleParser(indexMap.keySet(), indexMap.firstKey(), termProcessors); final Reference2ReferenceMap<Index, Object> index2Parser = new Reference2ReferenceOpenHashMap<Index, Object>(); /* // Fetch parsers for payload-based fields. for( Index index: indexMap.values() ) if ( index.hasPayloads ) { if ( index.payload.getClass() == DatePayload.class ) index2Parser.put( index, DateFormat.getDateInstance( DateFormat.SHORT, Locale.UK ) ); } */ final QueryEngine queryEngine = new QueryEngine(simpleParser, new DocumentIteratorBuilderVisitor(indexMap, index2Parser, indexMap.get(indexMap.firstKey()), MAX_STEMMING), indexMap); queryEngine.setWeights(index2Weight); queryEngine.score(new Scorer[] { new BM25Scorer(), new VignaScorer() }, new double[] { 1, 1 }); // We set up an interval selector only if there is a collection for snippeting queryEngine.intervalSelector = documentCollection != null ? new IntervalSelector(4, 40) : new IntervalSelector(); queryEngine.multiplex = !jsapResult.userSpecified("moPlex") || jsapResult.getBoolean("noMplex"); queryEngine.equalize(1000); RawDocHits_deprecated query = new RawDocHits_deprecated(queryEngine); // start docHits with at least 10K results query.interpretCommand("$score BM25Scorer"); query.interpretCommand("$mode time"); query.interpretCommand("$select"); if (jsapResult.userSpecified("divert")) query.interpretCommand("$divert " + jsapResult.getObject("divert")); query.displayMode = OutputType.DOCHHITS; query.maxOutput = jsapResult.getInt("results", 10000); String q; int n = 0; int dumpsize = jsapResult.userSpecified("dumpsize") ? jsapResult.getInt("dumpsize", 10000) : 1000; buildBins(query.maxOutput, (int) numberOfDocuments); String lastQ = ""; try { final BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(jsapResult.getString("input")))); final ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index, SelectedInterval[]>>> results = new ObjectArrayList<DocumentScoreInfo<Reference2ObjectMap<Index, SelectedInterval[]>>>(); for (;;) { q = br.readLine(); if (q == null) { System.err.println(); break; // CTRL-D } if (q.length() == 0) continue; if (q.charAt(0) == '$') { if (!query.interpretCommand(q)) break; continue; } queryCount++; long time = -System.nanoTime(); if (q.compareTo(lastQ) != 0) { try { n = queryEngine.process(q, 0, query.maxOutput, results); } catch (QueryParserException e) { if (verbose) e.getCause().printStackTrace(System.err); else System.err.println(e.getCause()); continue; } catch (Exception e) { if (verbose) e.printStackTrace(System.err); else System.err.println(e); continue; } lastQ = q; time += System.nanoTime(); query.output(results, documentCollection, titleList, TextMarker.TEXT_BOLDFACE); } else { // repeat last query results time += System.nanoTime(); for (int j = 0; j < results.size(); j++) docHits[lastResults[j]]++; } // dump batch if (queryCount % dumpsize == 0) { dumpBatch(query, numberOfDocuments); } } } finally { dumpBatch(query, numberOfDocuments); if (query.output != System.out) query.output.close(); } }
From source file:ch.kostceco.tools.kostval.KOSTVal.java
/** Die Eingabe besteht aus 2 oder 3 Parameter: [0] Validierungstyp [1] Pfad zur Val-File [2] * option: Verbose// ww w .j av a 2 s. c o m * * @param args * @throws IOException */ @SuppressWarnings("unused") public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:config/applicationContext.xml"); // Zeitstempel Start java.util.Date nowStart = new java.util.Date(); java.text.SimpleDateFormat sdfStart = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeStart = sdfStart.format(nowStart); /* TODO: siehe Bemerkung im applicationContext-services.xml bezglich Injection in der * Superklasse aller Impl-Klassen ValidationModuleImpl validationModuleImpl = * (ValidationModuleImpl) context.getBean("validationmoduleimpl"); */ KOSTVal kostval = (KOSTVal) context.getBean("kostval"); File configFile = new File("configuration" + File.separator + "kostval.conf.xml"); // Ueberprfung des Parameters (Log-Verzeichnis) String pathToLogfile = kostval.getConfigurationService().getPathToLogfile(); File directoryOfLogfile = new File(pathToLogfile); if (!directoryOfLogfile.exists()) { directoryOfLogfile.mkdir(); } // Im Logverzeichnis besteht kein Schreibrecht if (!directoryOfLogfile.canWrite()) { System.out.println( kostval.getTextResourceService().getText(ERROR_LOGDIRECTORY_NOTWRITABLE, directoryOfLogfile)); System.exit(1); } if (!directoryOfLogfile.isDirectory()) { System.out.println(kostval.getTextResourceService().getText(ERROR_LOGDIRECTORY_NODIRECTORY)); System.exit(1); } // Ist die Anzahl Parameter (mind. 2) korrekt? if (args.length < 2) { System.out.println(kostval.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); System.exit(1); } File valDatei = new File(args[1]); File logDatei = null; logDatei = valDatei; // Informationen zum Arbeitsverzeichnis holen String pathToWorkDir = kostval.getConfigurationService().getPathToWorkDir(); /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim * entsprechenden Modul die property anzugeben: <property name="configurationService" * ref="configurationService" /> */ // Informationen holen, welche Formate validiert werden sollen String pdfaValidation = kostval.getConfigurationService().pdfaValidation(); String siardValidation = kostval.getConfigurationService().siardValidation(); String tiffValidation = kostval.getConfigurationService().tiffValidation(); String jp2Validation = kostval.getConfigurationService().jp2Validation(); // Konfiguration des Loggings, ein File Logger wird zustzlich erstellt LogConfigurator logConfigurator = (LogConfigurator) context.getBean("logconfigurator"); String logFileName = logConfigurator.configure(directoryOfLogfile.getAbsolutePath(), logDatei.getName()); File logFile = new File(logFileName); // Ab hier kann ins log geschrieben werden... String formatValOn = ""; // ermitteln welche Formate validiert werden knnen respektive eingeschaltet sind if (pdfaValidation.equals("yes")) { formatValOn = "PDF/A"; if (tiffValidation.equals("yes")) { formatValOn = formatValOn + ", TIFF"; } if (jp2Validation.equals("yes")) { formatValOn = formatValOn + ", JP2"; } if (siardValidation.equals("yes")) { formatValOn = formatValOn + ", SIARD"; } } else if (tiffValidation.equals("yes")) { formatValOn = "TIFF"; if (jp2Validation.equals("yes")) { formatValOn = formatValOn + ", JP2"; } if (siardValidation.equals("yes")) { formatValOn = formatValOn + ", SIARD"; } } else if (jp2Validation.equals("yes")) { formatValOn = "JP2"; if (siardValidation.equals("yes")) { formatValOn = formatValOn + ", SIARD"; } } else if (siardValidation.equals("yes")) { formatValOn = "SIARD"; } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_HEADER)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_START, ausgabeStart)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_END)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMATON, formatValOn)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_INFO)); System.out.println("KOST-Val"); System.out.println(""); if (args[0].equals("--format") && formatValOn.equals("")) { // Formatvalidierung aber alle Formate ausgeschlossen LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_NOFILEENDINGS))); System.out.println(kostval.getTextResourceService().getText(ERROR_NOFILEENDINGS)); System.exit(1); } File xslOrig = new File("resources" + File.separator + "kost-val.xsl"); File xslCopy = new File(directoryOfLogfile.getAbsolutePath() + File.separator + "kost-val.xsl"); if (!xslCopy.exists()) { Util.copyFile(xslOrig, xslCopy); } File tmpDir = new File(pathToWorkDir); /* bestehendes Workverzeichnis Abbruch wenn nicht leer, da am Schluss das Workverzeichnis * gelscht wird und entsprechend bestehende Dateien gelscht werden knnen */ if (tmpDir.exists()) { if (tmpDir.isDirectory()) { // Get list of file in the directory. When its length is not zero the folder is not empty. String[] files = tmpDir.list(); if (files.length > 0) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_WORKDIRECTORY_EXISTS, pathToWorkDir))); System.out.println( kostval.getTextResourceService().getText(ERROR_WORKDIRECTORY_EXISTS, pathToWorkDir)); System.exit(1); } } } // Im Pfad keine Sonderzeichen xml-Validierung SIP 1d und SIARD C strzen ab String patternStr = "[^!#\\$%\\(\\)\\+,\\-_\\.=@\\[\\]\\{\\}\\~:\\\\a-zA-Z0-9 ]"; Pattern pattern = Pattern.compile(patternStr); String name = tmpDir.getAbsolutePath(); String[] pathElements = name.split("/"); for (int i = 0; i < pathElements.length; i++) { String element = pathElements[i]; Matcher matcher = pattern.matcher(element); boolean matchFound = matcher.find(); if (matchFound) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name))); System.out.println(kostval.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name)); System.exit(1); } } // die Anwendung muss mindestens unter Java 6 laufen String javaRuntimeVersion = System.getProperty("java.vm.version"); if (javaRuntimeVersion.compareTo("1.6.0") < 0) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_WRONG_JRE))); System.out.println(kostval.getTextResourceService().getText(ERROR_WRONG_JRE)); System.exit(1); } // bestehendes Workverzeichnis wieder anlegen if (!tmpDir.exists()) { tmpDir.mkdir(); } // Im workverzeichnis besteht kein Schreibrecht if (!tmpDir.canWrite()) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_WORKDIRECTORY_NOTWRITABLE, tmpDir))); System.out.println(kostval.getTextResourceService().getText(ERROR_WORKDIRECTORY_NOTWRITABLE, tmpDir)); System.exit(1); } /* Vorberitung fr eine allfllige Festhaltung bei unterschiedlichen PDFA-Validierungsresultaten * in einer PDF_Diagnosedatei sowie Zhler der SIP-Dateiformate */ String diaPath = kostval.getConfigurationService().getPathToDiagnose(); // Im diaverzeichnis besteht kein Schreibrecht File diaDir = new File(diaPath); if (!diaDir.exists()) { diaDir.mkdir(); } if (!diaDir.canWrite()) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_DIADIRECTORY_NOTWRITABLE, diaDir))); System.out.println(kostval.getTextResourceService().getText(ERROR_DIADIRECTORY_NOTWRITABLE, diaDir)); System.exit(1); } File xmlDiaOrig = new File("resources" + File.separator + "KaD-Diagnosedaten.kost-val.xml"); File xmlDiaCopy = new File(diaPath + File.separator + "KaD-Diagnosedaten.kost-val.xml"); if (!xmlDiaCopy.exists()) { Util.copyFile(xmlDiaOrig, xmlDiaCopy); } File xslDiaOrig = new File("resources" + File.separator + "kost-val_KaDdia.xsl"); File xslDiaCopy = new File(diaPath + File.separator + "kost-val_KaDdia.xsl"); if (!xslDiaCopy.exists()) { Util.copyFile(xslDiaOrig, xslDiaCopy); } /* Ueberprfung des optionalen Parameters (2 -v --> im Verbose-mode werden die originalen Logs * nicht gelscht (PDFTron, Jhove & Co.) */ boolean verbose = false; if (args.length > 2) { if (!(args[2].equals("-v"))) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_PARAMETER_OPTIONAL_1))); System.out.println(kostval.getTextResourceService().getText(ERROR_PARAMETER_OPTIONAL_1)); System.exit(1); } else { verbose = true; } } /* Initialisierung TIFF-Modul B (JHove-Validierung) berprfen der Konfiguration: existiert die * jhove.conf am angebenen Ort? */ String jhoveConf = kostval.getConfigurationService().getPathToJhoveConfiguration(); File fJhoveConf = new File(jhoveConf); if (!fJhoveConf.exists() || !fJhoveConf.getName().equals("jhove.conf")) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_JHOVECONF_MISSING))); System.out.println(kostval.getTextResourceService().getText(ERROR_JHOVECONF_MISSING)); System.exit(1); } // Im Pfad keine Sonderzeichen xml-Validierung SIP 1d und SIARD C strzen ab name = valDatei.getAbsolutePath(); pathElements = name.split("/"); for (int i = 0; i < pathElements.length; i++) { String element = pathElements[i]; Matcher matcher = pattern.matcher(element); boolean matchFound = matcher.find(); if (matchFound) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name))); System.out.println(kostval.getTextResourceService().getText(ERROR_SPECIAL_CHARACTER, name)); System.exit(1); } } // Ueberprfung des Parameters (Val-Datei): existiert die Datei? if (!valDatei.exists()) { LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_VALFILE_FILENOTEXISTING))); System.out.println(kostval.getTextResourceService().getText(ERROR_VALFILE_FILENOTEXISTING)); System.exit(1); } if (args[0].equals("--format")) { LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT1)); Integer countNio = 0; Integer countSummaryNio = 0; Integer count = 0; Integer pdfaCountIo = 0; Integer pdfaCountNio = 0; Integer siardCountIo = 0; Integer siardCountNio = 0; Integer tiffCountIo = 0; Integer tiffCountNio = 0; Integer jp2CountIo = 0; Integer jp2CountNio = 0; // TODO: Formatvalidierung an einer Datei --> erledigt --> nur Marker if (!valDatei.isDirectory()) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostval.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTValLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError("<Error>" + kostval.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } if (valFile) { // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Validierte Datei valide System.exit(0); } else { // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Fehler in Validierte Datei --> invalide System.exit(2); } } else { // TODO: Formatvalidierung ber ein Ordner --> erledigt --> nur Marker Map<String, File> fileMap = Util.getFileMap(valDatei, false); Set<String> fileMapKeys = fileMap.keySet(); for (Iterator<String> iterator = fileMapKeys.iterator(); iterator.hasNext();) { String entryName = iterator.next(); File newFile = fileMap.get(entryName); if (!newFile.isDirectory()) { valDatei = newFile; count = count + 1; // Ausgabe Dateizhler Ersichtlich das KOST-Val Dateien durchsucht System.out.print(count + " "); System.out.print("\r"); if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".jp2"))) && jp2Validation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (valFile) { jp2CountIo = jp2CountIo + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } else { jp2CountNio = jp2CountNio + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } } else if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".tiff") || valDatei.getAbsolutePath().toLowerCase().endsWith(".tif"))) && tiffValidation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (valFile) { tiffCountIo = tiffCountIo + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } else { tiffCountNio = tiffCountNio + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } } else if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".siard")) && siardValidation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (valFile) { siardCountIo = siardCountIo + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } else { siardCountNio = siardCountNio + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } } else if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".pdf") || valDatei.getAbsolutePath().toLowerCase().endsWith(".pdfa"))) && pdfaValidation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (valFile) { pdfaCountIo = pdfaCountIo + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } else { pdfaCountNio = pdfaCountNio + 1; // Lschen des Arbeitsverzeichnisses, falls eines angelegt wurde if (tmpDir.exists()) { Util.deleteDir(tmpDir); } } } else { countNio = countNio + 1; } } } System.out.print(" "); System.out.print("\r"); if (countNio.equals(count)) { // keine Dateien Validiert LOGGER.logError( kostval.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS, formatValOn)); System.out.println( kostval.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS, formatValOn)); } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostval.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTValLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError("<Error>" + kostval.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } countSummaryNio = pdfaCountNio + siardCountNio + tiffCountNio + jp2CountNio; if (countNio.equals(count)) { // keine Dateien Validiert bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } System.exit(1); } else if (countSummaryNio == 0) { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // alle Validierten Dateien valide System.exit(0); } else { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } // Fehler in Validierten Dateien --> invalide System.exit(2); } if (tmpDir.exists()) { Util.deleteDir(tmpDir); tmpDir.deleteOnExit(); } } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); } else if (args[0].equals("--sip")) { LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT1)); // TODO: Sipvalidierung --> erledigt --> nur Marker boolean validFormat = false; File originalSipFile = valDatei; File unSipFile = valDatei; File outputFile3c = null; String fileName3c = null; File tmpDirZip = null; // zuerst eine Formatvalidierung ber den Content dies ist analog aufgebaut wie --format Integer countNio = 0; Integer countSummaryNio = 0; Integer countSummaryIo = 0; Integer count = 0; Integer pdfaCountIo = 0; Integer pdfaCountNio = 0; Integer siardCountIo = 0; Integer siardCountNio = 0; Integer tiffCountIo = 0; Integer tiffCountNio = 0; Integer jp2CountIo = 0; Integer jp2CountNio = 0; if (!valDatei.isDirectory()) { Boolean zip = false; // Eine ZIP Datei muss mit PK.. beginnen if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".zip") || valDatei.getAbsolutePath().toLowerCase().endsWith(".zip64"))) { FileReader fr = null; try { fr = new FileReader(valDatei); BufferedReader read = new BufferedReader(fr); // Hex 03 in Char umwandeln String str3 = "03"; int i3 = Integer.parseInt(str3, 16); char c3 = (char) i3; // Hex 04 in Char umwandeln String str4 = "04"; int i4 = Integer.parseInt(str4, 16); char c4 = (char) i4; // auslesen der ersten 4 Zeichen der Datei int length; int i; char[] buffer = new char[4]; length = read.read(buffer); for (i = 0; i != length; i++) ; // die beiden charArrays (soll und ist) mit einander vergleichen char[] charArray1 = buffer; char[] charArray2 = new char[] { 'P', 'K', c3, c4 }; if (Arrays.equals(charArray1, charArray2)) { // hchstwahrscheinlich ein ZIP da es mit 504B0304 respektive PK.. beginnt zip = true; } } catch (Exception e) { LOGGER.logError("<Error>" + kostval.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } } // wenn die Datei kein Directory ist, muss sie mit zip oder zip64 enden if ((!(valDatei.getAbsolutePath().toLowerCase().endsWith(".zip") || valDatei.getAbsolutePath().toLowerCase().endsWith(".zip64"))) || zip == false) { // Abbruch! D.h. Sip message beginnen, Meldung und Beenden ab hier bis System.exit( 1 ); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP1)); valDatei = originalSipFile; LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALTYPE, kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION))); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALFILE, valDatei.getAbsolutePath())); System.out.println(kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION)); System.out.println(valDatei.getAbsolutePath()); // die eigentliche Fehlermeldung LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_MODUL_Aa_SIP) + kostval.getTextResourceService().getText(ERROR_XML_AA_INCORRECTFILEENDING)); System.out.println(kostval.getTextResourceService().getText(ERROR_XML_AA_INCORRECTFILEENDING)); // Fehler im Validierten SIP --> invalide & Abbruch LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_INVALID)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); System.out.println("Invalid"); System.out.println(""); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostval.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTValLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError("<Error>" + kostval.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } System.exit(1); } else { // geziptes SIP --> in temp dir entzipen String toplevelDir = valDatei.getName(); int lastDotIdx = toplevelDir.lastIndexOf("."); toplevelDir = toplevelDir.substring(0, lastDotIdx); tmpDirZip = new File( tmpDir.getAbsolutePath() + File.separator + "ZIP" + File.separator + toplevelDir); try { Zip64Archiver.unzip(valDatei.getAbsolutePath(), tmpDirZip.getAbsolutePath()); } catch (Exception e) { try { Zip64Archiver.unzip64(valDatei, tmpDirZip); } catch (Exception e1) { // Abbruch! D.h. Sip message beginnen, Meldung und Beenden ab hier bis System.exit LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP1)); valDatei = originalSipFile; LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALTYPE, kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION))); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALFILE, valDatei.getAbsolutePath())); System.out.println(kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION)); System.out.println(valDatei.getAbsolutePath()); // die eigentliche Fehlermeldung LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_MODUL_Aa_SIP) + kostval.getTextResourceService().getText(ERROR_XML_AA_CANNOTEXTRACTZIP)); System.out.println( kostval.getTextResourceService().getText(ERROR_XML_AA_CANNOTEXTRACTZIP)); // Fehler im Validierten SIP --> invalide & Abbruch LOGGER.logError( kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_INVALID)); LOGGER.logError( kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); System.out.println("Invalid"); System.out.println(""); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat( "dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostval.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTValLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e2) { LOGGER.logError("<Error>" + kostval.getTextResourceService() .getText(ERROR_XML_UNKNOWN, e2.getMessage())); System.out.println("Exception: " + e2.getMessage()); } // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } System.exit(1); } } valDatei = tmpDirZip; File toplevelfolder = new File( valDatei.getAbsolutePath() + File.separator + valDatei.getName()); if (toplevelfolder.exists()) { valDatei = toplevelfolder; } unSipFile = valDatei; } } else { // SIP ist ein Ordner valDatei bleibt unverndert } // Vorgngige Formatvalidierung (Schritt 3c) Map<String, File> fileMap = Util.getFileMap(valDatei, false); Set<String> fileMapKeys = fileMap.keySet(); int pdf = 0; int tiff = 0; int siard = 0; int txt = 0; int csv = 0; int xml = 0; int xsd = 0; int wave = 0; int mp3 = 0; int jp2 = 0; int jpx = 0; int jpeg = 0; int png = 0; int dng = 0; int svg = 0; int mpeg2 = 0; int mp4 = 0; int xls = 0; int odt = 0; int ods = 0; int odp = 0; int other = 0; for (Iterator<String> iterator = fileMapKeys.iterator(); iterator.hasNext();) { String entryName = iterator.next(); File newFile = fileMap.get(entryName); if (!newFile.isDirectory() && newFile.getAbsolutePath().contains(File.separator + "content" + File.separator)) { valDatei = newFile; count = count + 1; // Ausgabe Dateizhler Ersichtlich das KOST-Val Dateien durchsucht System.out.print(count + " "); System.out.print("\r"); String extension = valDatei.getName(); int lastIndexOf = extension.lastIndexOf("."); if (lastIndexOf == -1) { // empty extension extension = "other"; } else { extension = extension.substring(lastIndexOf); } if (extension.equalsIgnoreCase(".pdf") || extension.equalsIgnoreCase(".pdfa")) { pdf = pdf + 1; } else if (extension.equalsIgnoreCase(".tiff") || extension.equalsIgnoreCase(".tif")) { tiff = tiff + 1; } else if (extension.equalsIgnoreCase(".siard")) { siard = siard + 1; } else if (extension.equalsIgnoreCase(".txt")) { txt = txt + 1; } else if (extension.equalsIgnoreCase(".csv")) { csv = csv + 1; } else if (extension.equalsIgnoreCase(".xml")) { xml = xml + 1; } else if (extension.equalsIgnoreCase(".xsd")) { xsd = xsd + 1; } else if (extension.equalsIgnoreCase(".wav")) { wave = wave + 1; } else if (extension.equalsIgnoreCase(".mp3")) { mp3 = mp3 + 1; } else if (extension.equalsIgnoreCase(".jp2")) { jp2 = jp2 + 1; } else if (extension.equalsIgnoreCase(".jpx") || extension.equalsIgnoreCase(".jpf")) { jpx = jpx + 1; } else if (extension.equalsIgnoreCase(".jpe") || extension.equalsIgnoreCase(".jpeg") || extension.equalsIgnoreCase(".jpg")) { jpeg = jpeg + 1; } else if (extension.equalsIgnoreCase(".png")) { png = png + 1; } else if (extension.equalsIgnoreCase(".dng")) { dng = dng + 1; } else if (extension.equalsIgnoreCase(".svg")) { svg = svg + 1; } else if (extension.equalsIgnoreCase(".mpeg") || extension.equalsIgnoreCase(".mpg")) { mpeg2 = mpeg2 + 1; } else if (extension.equalsIgnoreCase(".f4a") || extension.equalsIgnoreCase(".f4v") || extension.equalsIgnoreCase(".m4a") || extension.equalsIgnoreCase(".m4v") || extension.equalsIgnoreCase(".mp4")) { mp4 = mp4 + 1; } else if (extension.equalsIgnoreCase(".xls") || extension.equalsIgnoreCase(".xlw") || extension.equalsIgnoreCase(".xlsx")) { xls = xls + 1; } else if (extension.equalsIgnoreCase(".odt") || extension.equalsIgnoreCase(".ott")) { odt = odt + 1; } else if (extension.equalsIgnoreCase(".ods") || extension.equalsIgnoreCase(".ots")) { ods = ods + 1; } else if (extension.equalsIgnoreCase(".odp") || extension.equalsIgnoreCase(".otp")) { odp = odp + 1; } else { other = other + 1; } if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".jp2"))) && jp2Validation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); if (valFile) { jp2CountIo = jp2CountIo + 1; } else { jp2CountNio = jp2CountNio + 1; } } else if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".tiff") || valDatei.getAbsolutePath().toLowerCase().endsWith(".tif"))) && tiffValidation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); if (valFile) { tiffCountIo = tiffCountIo + 1; } else { tiffCountNio = tiffCountNio + 1; } } else if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".siard")) && siardValidation.equals("yes")) { // Arbeitsverzeichnis zum Entpacken des Archivs erstellen String pathToWorkDirSiard = kostval.getConfigurationService().getPathToWorkDir(); File tmpDirSiard = new File(pathToWorkDirSiard + File.separator + "SIARD"); if (tmpDirSiard.exists()) { Util.deleteDir(tmpDirSiard); } if (!tmpDirSiard.exists()) { tmpDirSiard.mkdir(); } boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); if (valFile) { siardCountIo = siardCountIo + 1; } else { siardCountNio = siardCountNio + 1; } } else if (((valDatei.getAbsolutePath().toLowerCase().endsWith(".pdf") || valDatei.getAbsolutePath().toLowerCase().endsWith(".pdfa"))) && pdfaValidation.equals("yes")) { boolean valFile = valFile(valDatei, logFileName, directoryOfLogfile, verbose); if (valFile) { pdfaCountIo = pdfaCountIo + 1; } else { pdfaCountNio = pdfaCountNio + 1; } } else { countNio = countNio + 1; } } } countSummaryNio = pdfaCountNio + siardCountNio + tiffCountNio + jp2CountNio; countSummaryIo = pdfaCountIo + siardCountIo + tiffCountIo + jp2CountIo; int countSummaryIoP = 100 / count * countSummaryIo; int countSummaryNioP = 100 / count * countSummaryNio; int countNioP = 100 / count * countNio; String summary3c = kostval.getTextResourceService().getText(MESSAGE_XML_SUMMARY_3C, count, countSummaryIo, countSummaryNio, countNio, countSummaryIoP, countSummaryNioP, countNioP); if (countSummaryNio == 0) { // alle Validierten Dateien valide validFormat = true; fileName3c = "3c_Valide.txt"; } else { // Fehler in Validierten Dateien --> invalide validFormat = false; fileName3c = "3c_Invalide.txt"; } // outputFile3c = new File( directoryOfLogfile + fileName3c ); outputFile3c = new File(pathToWorkDir + File.separator + fileName3c); try { outputFile3c.createNewFile(); } catch (IOException e) { e.printStackTrace(); } if (countNio == count) { // keine Dateien Validiert LOGGER.logError(kostval.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS, formatValOn)); System.out .println(kostval.getTextResourceService().getText(ERROR_INCORRECTFILEENDINGS, formatValOn)); } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_FORMAT2)); // Start Normale SIP-Validierung mit auswertung Format-Val. im 3c LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP1)); valDatei = unSipFile; LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALTYPE, kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION))); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALFILE, originalSipFile.getAbsolutePath())); System.out.println(kostval.getTextResourceService().getText(MESSAGE_SIPVALIDATION)); System.out.println(originalSipFile.getAbsolutePath()); Controllersip controller = (Controllersip) context.getBean("controllersip"); boolean okMandatory = false; okMandatory = controller.executeMandatory(valDatei, directoryOfLogfile); boolean ok = false; /* die Validierungen 1a - 1d sind obligatorisch, wenn sie bestanden wurden, knnen die * restlichen Validierungen, welche nicht zum Abbruch der Applikation fhren, ausgefhrt * werden. * * 1a wurde bereits getestet (vor der Formatvalidierung entsprechend fngt der Controller mit * 1b an */ if (okMandatory) { ok = controller.executeOptional(valDatei, directoryOfLogfile); } // Formatvalidierung validFormat ok = (ok && okMandatory && validFormat); if (ok) { // Validiertes SIP valide LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_VALID)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); System.out.println("Valid"); System.out.println(""); } else { // Fehler im Validierten SIP --> invalide LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_INVALID)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_VALERGEBNIS_CLOSE)); System.out.println("Invalid"); System.out.println(""); } // ggf. Fehlermeldung 3c ergnzen Util.val3c(summary3c, logFile ); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP2)); LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_LOGEND)); // Zeitstempel End java.util.Date nowEnd = new java.util.Date(); java.text.SimpleDateFormat sdfEnd = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String ausgabeEnd = sdfEnd.format(nowEnd); ausgabeEnd = "<End>" + ausgabeEnd + "</End>"; Util.valEnd(ausgabeEnd, logFile); Util.val3c(summary3c, logFile); Util.amp(logFile); // Die Konfiguration hereinkopieren try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setExpandEntityReferences(false); Document docConfig = factory.newDocumentBuilder().parse(configFile); NodeList list = docConfig.getElementsByTagName("configuration"); Element element = (Element) list.item(0); Document docLog = factory.newDocumentBuilder().parse(logFile); Node dup = docLog.importNode(element, true); docLog.getDocumentElement().appendChild(dup); FileWriter writer = new FileWriter(logFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ElementToStream(docLog.getDocumentElement(), baos); String stringDoc2 = new String(baos.toByteArray()); writer.write(stringDoc2); writer.close(); // Der Header wird dabei leider verschossen, wieder zurck ndern String newstring = kostval.getTextResourceService().getText(MESSAGE_XML_HEADER); String oldstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><KOSTValLog>"; Util.oldnewstring(oldstring, newstring, logFile); } catch (Exception e) { LOGGER.logError( "<Error>" + kostval.getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); System.out.println("Exception: " + e.getMessage()); } // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } StringBuffer command = new StringBuffer("rd " + tmpDir.getAbsolutePath() + " /s /q"); try { // KaD-Diagnose-Datei mit den neusten Anzahl Dateien pro KaD-Format Updaten DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlDiaCopy); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName("KOSTVal_FFCounter"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (pdf > 0) { String pdfNodeString = eElement.getElementsByTagName("pdf").item(0).getTextContent(); int pdfNodeValue = Integer.parseInt(pdfNodeString); pdf = pdf + pdfNodeValue; Util.kadDia("<pdf>" + pdfNodeValue + "</pdf>", "<pdf>" + pdf + "</pdf>", xmlDiaCopy); } if (tiff > 0) { String tiffNodeString = eElement.getElementsByTagName("tiff").item(0).getTextContent(); int tiffNodeValue = Integer.parseInt(tiffNodeString); tiff = tiff + tiffNodeValue; Util.kadDia("<tiff>" + tiffNodeValue + "</tiff>", "<tiff>" + tiff + "</tiff>", xmlDiaCopy); } if (siard > 0) { String siardNodeString = eElement.getElementsByTagName("siard").item(0) .getTextContent(); int siardNodeValue = Integer.parseInt(siardNodeString); siard = siard + siardNodeValue; Util.kadDia("<siard>" + siardNodeValue + "</siard>", "<siard>" + siard + "</siard>", xmlDiaCopy); } if (txt > 0) { String txtNodeString = eElement.getElementsByTagName("txt").item(0).getTextContent(); int txtNodeValue = Integer.parseInt(txtNodeString); txt = txt + txtNodeValue; Util.kadDia("<txt>" + txtNodeValue + "</txt>", "<txt>" + txt + "</txt>", xmlDiaCopy); } if (csv > 0) { String csvNodeString = eElement.getElementsByTagName("csv").item(0).getTextContent(); int csvNodeValue = Integer.parseInt(csvNodeString); csv = csv + csvNodeValue; Util.kadDia("<csv>" + csvNodeValue + "</csv>", "<csv>" + csv + "</csv>", xmlDiaCopy); } if (xml > 0) { String xmlNodeString = eElement.getElementsByTagName("xml").item(0).getTextContent(); int xmlNodeValue = Integer.parseInt(xmlNodeString); xml = xml + xmlNodeValue; Util.kadDia("<xml>" + xmlNodeValue + "</xml>", "<xml>" + xml + "</xml>", xmlDiaCopy); } if (xsd > 0) { String xsdNodeString = eElement.getElementsByTagName("xsd").item(0).getTextContent(); int xsdNodeValue = Integer.parseInt(xsdNodeString); xsd = xsd + xsdNodeValue; Util.kadDia("<xsd>" + xsdNodeValue + "</xsd>", "<xsd>" + xsd + "</xsd>", xmlDiaCopy); } if (wave > 0) { String waveNodeString = eElement.getElementsByTagName("wave").item(0).getTextContent(); int waveNodeValue = Integer.parseInt(waveNodeString); wave = wave + waveNodeValue; Util.kadDia("<wave>" + waveNodeValue + "</wave>", "<wave>" + wave + "</wave>", xmlDiaCopy); } if (mp3 > 0) { String mp3NodeString = eElement.getElementsByTagName("mp3").item(0).getTextContent(); int mp3NodeValue = Integer.parseInt(mp3NodeString); mp3 = mp3 + mp3NodeValue; Util.kadDia("<mp3>" + mp3NodeValue + "</mp3>", "<mp3>" + mp3 + "</mp3>", xmlDiaCopy); } if (jp2 > 0) { String jp2NodeString = eElement.getElementsByTagName("jp2").item(0).getTextContent(); int jp2NodeValue = Integer.parseInt(jp2NodeString); jp2 = jp2 + jp2NodeValue; Util.kadDia("<jp2>" + jp2NodeValue + "</jp2>", "<jp2>" + jp2 + "</jp2>", xmlDiaCopy); } if (jpx > 0) { String jpxNodeString = eElement.getElementsByTagName("jpx").item(0).getTextContent(); int jpxNodeValue = Integer.parseInt(jpxNodeString); jpx = jpx + jpxNodeValue; Util.kadDia("<jpx>" + jpxNodeValue + "</jpx>", "<jpx>" + jpx + "</jpx>", xmlDiaCopy); } if (jpeg > 0) { String jpegNodeString = eElement.getElementsByTagName("jpeg").item(0).getTextContent(); int jpegNodeValue = Integer.parseInt(jpegNodeString); jpeg = jpeg + jpegNodeValue; Util.kadDia("<jpeg>" + jpegNodeValue + "</jpeg>", "<jpeg>" + jpeg + "</jpeg>", xmlDiaCopy); } if (png > 0) { String pngNodeString = eElement.getElementsByTagName("png").item(0).getTextContent(); int pngNodeValue = Integer.parseInt(pngNodeString); png = png + pngNodeValue; Util.kadDia("<png>" + pngNodeValue + "</png>", "<png>" + png + "</png>", xmlDiaCopy); } if (dng > 0) { String dngNodeString = eElement.getElementsByTagName("dng").item(0).getTextContent(); int dngNodeValue = Integer.parseInt(dngNodeString); dng = dng + dngNodeValue; Util.kadDia("<dng>" + dngNodeValue + "</dng>", "<dng>" + dng + "</dng>", xmlDiaCopy); } if (svg > 0) { String svgNodeString = eElement.getElementsByTagName("svg").item(0).getTextContent(); int svgNodeValue = Integer.parseInt(svgNodeString); svg = svg + svgNodeValue; Util.kadDia("<svg>" + svgNodeValue + "</svg>", "<svg>" + svg + "</svg>", xmlDiaCopy); } if (mpeg2 > 0) { String mpeg2NodeString = eElement.getElementsByTagName("mpeg2").item(0) .getTextContent(); int mpeg2NodeValue = Integer.parseInt(mpeg2NodeString); mpeg2 = mpeg2 + mpeg2NodeValue; Util.kadDia("<mpeg2>" + mpeg2NodeValue + "</mpeg2>", "<mpeg2>" + mpeg2 + "</mpeg2>", xmlDiaCopy); } if (mp4 > 0) { String mp4NodeString = eElement.getElementsByTagName("mp4").item(0).getTextContent(); int mp4NodeValue = Integer.parseInt(mp4NodeString); mp4 = mp4 + mp4NodeValue; Util.kadDia("<mp4>" + mp4NodeValue + "</mp4>", "<mp4>" + mp4 + "</mp4>", xmlDiaCopy); } if (xls > 0) { String xlsNodeString = eElement.getElementsByTagName("xls").item(0).getTextContent(); int xlsNodeValue = Integer.parseInt(xlsNodeString); xls = xls + xlsNodeValue; Util.kadDia("<xls>" + xlsNodeValue + "</xls>", "<xls>" + xls + "</xls>", xmlDiaCopy); } if (odt > 0) { String odtNodeString = eElement.getElementsByTagName("odt").item(0).getTextContent(); int odtNodeValue = Integer.parseInt(odtNodeString); odt = odt + odtNodeValue; Util.kadDia("<odt>" + odtNodeValue + "</odt>", "<odt>" + odt + "</odt>", xmlDiaCopy); } if (ods > 0) { String odsNodeString = eElement.getElementsByTagName("ods").item(0).getTextContent(); int odsNodeValue = Integer.parseInt(odsNodeString); ods = ods + odsNodeValue; Util.kadDia("<ods>" + odsNodeValue + "</ods>", "<ods>" + ods + "</ods>", xmlDiaCopy); } if (odp > 0) { String odpNodeString = eElement.getElementsByTagName("odp").item(0).getTextContent(); int odpNodeValue = Integer.parseInt(odpNodeString); odp = odp + odpNodeValue; Util.kadDia("<odp>" + odpNodeValue + "</odp>", "<odp>" + odp + "</odp>", xmlDiaCopy); } if (other > 0) { String otherNodeString = eElement.getElementsByTagName("other").item(0) .getTextContent(); int otherNodeValue = Integer.parseInt(otherNodeString); other = other + otherNodeValue; Util.kadDia("<other>" + otherNodeValue + "</other>", "<other>" + other + "</other>", xmlDiaCopy); } } } } catch (Exception e) { e.printStackTrace(); } if (ok) { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (tmpDir.exists()) { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command.toString()); } System.exit(0); } else { // bestehendes Workverzeichnis ggf. lschen if (tmpDir.exists()) { Util.deleteDir(tmpDir); } if (tmpDir.exists()) { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(command.toString()); } System.exit(2); } LOGGER.logError(kostval.getTextResourceService().getText(MESSAGE_XML_SIP2)); } else { /* Ueberprfung des Parameters (Val-Typ): format / sip args[0] ist nicht "--format" oder * "--sip" --> INVALIDE */ LOGGER.logError(kostval.getTextResourceService().getText(ERROR_IOE, kostval.getTextResourceService().getText(ERROR_PARAMETER_USAGE))); System.out.println(kostval.getTextResourceService().getText(ERROR_PARAMETER_USAGE)); if (tmpDir.exists()) { Util.deleteDir(tmpDir); tmpDir.deleteOnExit(); } System.exit(1); } }
From source file:com.foo.manager.commonManager.thread.HttpHandleThread.java
public static void main(String arg[]) { // String logistics_interface = "<LoadHead><loadContents><loadContent><loadContentId>1</loadContentId><outorderId>6666666666</outorderId></loadContent><loadContent><loadContentId>2</loadContentId><outorderId>7777777777</outorderId></loadContent></loadContents><loadHeadId>12</loadHeadId><loadId>1736474588</loadId><total>2</total><tracyNum>3</tracyNum><TotalWeight>2.5</TotalWeight><CarEcNo>?A234234</CarEcNo></LoadHead>"; ////from ww w .j a v a 2 s . c o m // String data_digest = CommonUtil.makeSign(logistics_interface); // // System.out.println(data_digest); // try { // System.out // .println("logistics_interface=" // + URLEncoder.encode(logistics_interface, "utf-8") // + "&data_digest=" // + URLEncoder.encode(data_digest, "utf-8")); // } catch (UnsupportedEncodingException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // try { // System.out.println(URLEncoder.encode("helloworld", "utf-8")); // System.out.println(URLEncoder.encode("voQc3u6+f6pSflMPdw4ySQ==", // "utf-8")); // } catch (UnsupportedEncodingException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("RECORD_NO", "335"); map1.put("CREAT_TIME", "2018-09-14 21:46:17"); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("RECORD_NO", "145"); map2.put("CREAT_TIME", "2018-09-14 23:46:17"); Map<String, Object> map3 = new HashMap<String, Object>(); map3.put("RECORD_NO", "285"); map3.put("CREAT_TIME", "2018-09-14 22:46:17"); Map<String, Object> map4 = new HashMap<String, Object>(); map4.put("RECORD_NO", "265"); map4.put("CREAT_TIME", "2018-09-14 22:46:17"); list.add(map1); list.add(map2); list.add(map3); list.add(map4); // ?? for (Map<String, Object> map : list) { System.out.println(map); } Collections.sort(list, new Comparator<Map>() { public int compare(Map o1, Map o2) { // double qty1 = Double.valueOf(o1.get("QTY") // .toString()); // double qty2 = Double.valueOf(o2.get("QTY") // .toString()); String recordNo1 = o1.get("RECORD_NO") != null ? o1.get("RECORD_NO").toString() : ""; String recordNo2 = o2.get("RECORD_NO") != null ? o2.get("RECORD_NO").toString() : ""; // if (qty1 > qty2) { if (recordNo1.compareTo(recordNo2) < 0) { return 0; } else { return 1; } // } else { // return 0; // } } }); System.out.println("-------------------"); for (Map<String, Object> map : list) { System.out.println(map); } // // String s = "<![CDATA[?]]>"; // Pattern p = Pattern.compile(".*<!\\[CDATA\\[(.*)\\]\\]>.*"); // Matcher m = p.matcher(s); // // if (m.matches()) { // System.out.println(m.group(1)); // }else{ // System.out.println(s); // } // // System.out.println(CommonUtil.getDateFormatter(CommonDefine.COMMON_FORMAT_2) // .format(new Date())); // String response = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><ns:sendOrderResponse xmlns:ns=\"http://ws.com\"><ns:return><?xml version=\"1.0\" encoding=\"UTF-8\"?><DATA><ORDER><ORDER_CODE>W100133410</ORDER_CODE><CD>OK</CD><INFO>11811000073</INFO></ORDER></DATA></ns:return></ns:sendOrderResponse></soapenv:Body></soapenv:Envelope>"; // // String xxxx = StringEscapeUtils.escapeXml(response); // String returnXmlData = XmlUtil // .getResponseFromXmlString_CJ(xxxx); // String returnXmlData = XmlUtil.getTotalMidValue(response,"<ns:return>","</ns:return>"); // // Map orderResult = XmlUtil.parseXmlFPAPI_SingleNodes(returnXmlData, "//DATA/ORDER/child::*"); // System.out.println(xxxx); // System.out.println(orderResult); try { String xxx = "<returnInfo>?????????????</returnInfo>"; xxx = "<returnInfo>?????????????/returnInfo>"; // String xxx = "??[??3201966A69??AAAA124613101110701] ?[3201966A69]??[AAAA124613101110701]??? ??[1210680001]???[245119218897]???? ?[3201966A69]??[AAAA124613101110701]??"; // String uft_gbk = new String(xxx.getBytes("UTF-8"),"GBK"); String gbk_utf = new String(xxx.getBytes("GBK"), "UTF-8"); // System.out.println(uft_gbk); System.out.println(gbk_utf); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static boolean isHourInInterval(String target, String start, String end) { return ((target.compareTo(start) >= 0) && (target.compareTo(end) <= 0)); }
From source file:Main.java
public static boolean isSorted(List<String> list) { String previous = ""; for (String current : list) { if (current.compareTo(previous) < 0) return false; previous = current;// w ww.j a va 2 s. c o m } return true; }
From source file:Main.java
public static int compare(String srcDate, String tagDate) { return srcDate.compareTo(tagDate); }