Skip to content

Commit

Permalink
Version 0.0.9 erstellt
Browse files Browse the repository at this point in the history
======================
- Bereinigung der temporären Daten mit jeweils einer row pro Zeile
- Sonderzeichen werden bemängelt (beim Start der Initialisierung)
- Leerschläge werden neu unterstützt
- kleinere Korrekturen
  • Loading branch information
Chlara committed Nov 21, 2016
1 parent 684f7e9 commit 75f9708
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* == SIARDexcerpt ==============================================================================
* The SIARDexcerpt v0.0.8 application is used for excerpt a record from a SIARD-File. Copyright (C)
* The SIARDexcerpt v0.0.9 application is used for excerpt a record from a SIARD-File. Copyright (C)
* 2016 Claire Röthlisberger (KOST-CECO)
* -----------------------------------------------------------------------------------------------
* SIARDexcerpt is a development of the KOST-CECO. All rights rest with the KOST-CECO. This
Expand All @@ -25,6 +25,9 @@
import java.io.OutputStream;
// import java.io.OutputStreamWriter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -161,7 +164,7 @@ public static void main( String[] args ) throws IOException
*
* e) Struktur-Check SIARD-Verzeichnis
*
* f) TODO: Config bei Bedarf (..) gemäss metadata.xml ausfüllen
* f) Config bei Bedarf (..) gemäss metadata.xml ausfüllen
*
* TODO: Erledigt */

Expand Down Expand Up @@ -269,6 +272,79 @@ public static void main( String[] args ) throws IOException
System.exit( 1 );
}

try {
// Im Pfad keine Sonderzeichen kann abstürzen

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 ) {
if ( matcher.group( i ).equals( " " ) ) {
// Leerschlag ab v0.0.9 OK
} else {
System.console().printf(
siardexcerpt.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name,
matcher.group( i ) ) );
Thread.sleep( 5000 );
System.exit( 1 );
}
}
}

name = directoryOfOutput.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 ) {
if ( matcher.group( i ).equals( " " ) ) {
// Leerschlag ab v0.0.9 OK
} else {
System.console().printf(
siardexcerpt.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name,
matcher.group( i ) ) );
Thread.sleep( 5000 );
System.exit( 1 );
}
}
}

name = siardDatei.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 ) {
if ( matcher.group( i ).equals( " " ) ) {
// Leerschlag ab v0.0.9 OK
} else {
System.console().printf(
siardexcerpt.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name,
matcher.group( i ) ) );
Thread.sleep( 5000 );
System.exit( 1 );
}
}
}

} catch ( Exception e ) {
System.out.println( "Exception: " + e.getMessage() );
}

/** d) SIARD-Datei entpacken */
if ( !siardDatei.exists() ) {
// SIARD-Datei existiert nicht
Expand Down Expand Up @@ -401,6 +477,14 @@ public static void main( String[] args ) throws IOException

System.out.println( "SIARDexcerpt: search" );

String pathToWorkDir = siardexcerpt.getConfigurationService().getPathToWorkDir();
if ( pathToWorkDir.startsWith( "Configuration-Error:" ) ) {
System.out.println( pathToWorkDir );
System.exit( 1 );
}

tmpDir = new File( pathToWorkDir );

String pathToOutput = siardexcerpt.getConfigurationService().getPathToOutput();

directoryOfOutput = new File( pathToOutput );
Expand Down Expand Up @@ -589,6 +673,14 @@ public static void main( String[] args ) throws IOException

System.out.println( "SIARDexcerpt: extract" );

String pathToWorkDir = siardexcerpt.getConfigurationService().getPathToWorkDir();
if ( pathToWorkDir.startsWith( "Configuration-Error:" ) ) {
System.out.println( pathToWorkDir );
System.exit( 1 );
}

tmpDir = new File( pathToWorkDir );

String pathToOutput = siardexcerpt.getConfigurationService().getPathToOutput();

directoryOfOutput = new File( pathToOutput );
Expand Down Expand Up @@ -621,7 +713,6 @@ public static void main( String[] args ) throws IOException
String ausgabeStart = sdfStart.format( nowStart );

String excerptString = new String( args[3] );

/* Der excerptString kann zeichen enthalten, welche nicht im Dateinamen vorkommen dürfen.
* Entsprechend werden diese normalisiert */
String excerptStringFilename = excerptString.replaceAll( "/", "_" );
Expand All @@ -632,6 +723,8 @@ public static void main( String[] args ) throws IOException
excerptStringFilename = excerptStringFilename.replaceAll( "___", "_" );
excerptStringFilename = excerptStringFilename.replaceAll( "__", "_" );

excerptString = excerptString.replaceAll( "\\*", "\\." );

String outDateiName = siardDatei.getName() + "_" + excerptStringFilename
+ "_SIARDexcerpt.xml";
outDateiName = outDateiName.replaceAll( "__", "_" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public boolean validate( File siardDatei, File outFileSearch, String searchStrin
}
Util.oldnewstring( System.getProperty( "line.separator" ) + "<c", "<c", fSearchtable );
Util.oldnewstring( System.getProperty( "line.separator" ) + "</row", "</row", fSearchtable );

// Trennt ><row>. Nur eine row auf eine neue Zeile
Util.oldnewstring( "><row", ">"+System.getProperty( "line.separator" ) + "<row", fSearchtable );
Util.oldnewstring( "><row", ">" + System.getProperty( "line.separator" ) + "<row",
fSearchtable );

/* Der SearchString soll nur über <row>...</row> durchgeführt werden
*
Expand All @@ -158,9 +159,9 @@ public boolean validate( File siardDatei, File outFileSearch, String searchStrin

try {
// grep -E "REGEX-Suchbegriff" table13.xml >> output.txt
String command = "cmd /c \"" + pathToGrepExe + " -E" + insensitiveOption + " \""
+ searchString + "\" " + fSearchtable.getAbsolutePath() + " >> "
+ tempOutFile.getAbsolutePath() + "\"";
String command = "cmd /c \"\"" + pathToGrepExe + "\" -E" + insensitiveOption + " \""
+ searchString + "\" \"" + fSearchtable.getAbsolutePath() + "\" >> \""
+ tempOutFile.getAbsolutePath() + "\"\"";
/* Das redirect Zeichen verunmöglicht eine direkte eingabe. mit dem geschachtellten Befehl
* gehts: cmd /c\"urspruenlicher Befehl\" */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
// TODO: Record aus Maintable herausholen
try {
if ( tempOutFile.exists() ) {
Util.deleteDir( tempOutFile );
tempOutFile.delete();
if ( tempOutFile.exists() ) {
Util.replaceAllChar( tempOutFile, "" );
}
/* Util.deleteDir( tempOutFile );
*
* wird nicht verwendet, da es jetzt gelöscht werden muss und nicht spätestens bei exit.
* wenn es nicht gelöchscht werden kann wird es geleert. */
}

/* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim
Expand Down Expand Up @@ -146,9 +153,9 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
}
Util.oldnewstring( System.getProperty( "line.separator" ) + "<c", "<c", fMaintable );
Util.oldnewstring( System.getProperty( "line.separator" ) + "</row", "</row", fMaintable );

// Trennt ><row>. Nur eine row auf eine neue Zeile
Util.oldnewstring( "><row", ">"+System.getProperty( "line.separator" ) + "<row", fMaintable );
Util.oldnewstring( "><row", ">" + System.getProperty( "line.separator" ) + "<row", fMaintable );

try {
/* Der excerptString kann Leerschläge enthalten, welche bei grep Problem verursachen.
Expand All @@ -158,8 +165,8 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
excerptStringM = excerptStringM.replaceAll( "\\.", "\\.*" );
excerptStringM = "<" + cell + ">" + excerptStringM + "</" + cell + ">";
// grep "<c11>7561234567890</c11>" table13.xml >> output.txt
String command = "cmd /c \"" + pathToGrepExe + " -E \"" + excerptStringM + "\" "
+ fMaintable.getAbsolutePath() + " >> " + tempOutFile.getAbsolutePath() + "\"";
String command = "cmd /c \"\"" + pathToGrepExe + "\" -E \"" + excerptStringM + "\" \""
+ fMaintable.getAbsolutePath() + "\" >> \"" + tempOutFile.getAbsolutePath() + "\"\"";
/* Das redirect Zeichen verunmöglicht eine direkte eingabe. mit dem geschachtellten Befehl
* gehts: cmd /c\"urspruenlicher Befehl\" */

Expand Down Expand Up @@ -304,7 +311,14 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
getTextResourceService().getText( MESSAGE_XML_ELEMENT_CLOSE, folder ) );

if ( tempOutFile.exists() ) {
Util.deleteDir( tempOutFile );
tempOutFile.delete();
if ( tempOutFile.exists() ) {
Util.replaceAllChar( tempOutFile, "" );
}
/* Util.deleteDir( tempOutFile );
*
* wird nicht verwendet, da es jetzt gelöscht werden muss und nicht spätestens bei exit.
* wenn es nicht gelöchscht werden kann wird es geleert. */
}
content = "";

Expand Down Expand Up @@ -367,7 +381,8 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
Util.oldnewstring( System.getProperty( "line.separator" ) + "</row", "</row", fSubtable );

// Trennt ><row>. Nur eine row auf eine neue Zeile
Util.oldnewstring( "><row", ">"+System.getProperty( "line.separator" ) + "<row", fSubtable );
Util.oldnewstring( "><row", ">" + System.getProperty( "line.separator" ) + "<row",
fSubtable );

try {
/* Der excerptString kann Leerschläge enthalten, welche bei grep Problem verursachen.
Expand All @@ -376,8 +391,8 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
excerptStringM = excerptStringM.replaceAll( "\\.", "\\.*" );
excerptStringM = "<" + cell + ">" + excerptStringM + "</" + cell + ">";
// grep "<c11>7561234567890</c11>" table13.xml >> output.txt
String command = "cmd /c \"" + pathToGrepExe + " -E \"" + excerptStringM + "\" "
+ fSubtable.getAbsolutePath() + " >> " + tempOutFile.getAbsolutePath() + "\"";
String command = "cmd /c \"\"" + pathToGrepExe + "\" -E \"" + excerptStringM + "\" \""
+ fSubtable.getAbsolutePath() + "\" >> \"" + tempOutFile.getAbsolutePath() + "\"\"";
/* Das redirect Zeichen verunmöglicht eine direkte eingabe. mit dem geschachtellten Befehl
* gehts: cmd /c\"urspruenlicher Befehl\" */

Expand Down Expand Up @@ -527,7 +542,14 @@ public boolean validate( File siardDatei, File outFile, String excerptString )
getTextResourceService().getText( MESSAGE_XML_ELEMENT_CLOSE, folder ) );

if ( tempOutFile.exists() ) {
Util.deleteDir( tempOutFile );
tempOutFile.delete();
if ( tempOutFile.exists() ) {
Util.replaceAllChar( tempOutFile, "" );
}
/* Util.deleteDir( tempOutFile );
*
* wird nicht verwendet, da es jetzt gelöscht werden muss und nicht spätestens bei exit.
* wenn es nicht gelöchscht werden kann wird es geleert. */
}
content = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface MessageConstants
String ERROR_LOGGING_NOFILEAPPENDER = "error.logging.nofileappender";
String ERROR_WRONG_JRE = "error.wrong.jdk";
String ERROR_NOINIT = "error.noinit";
String ERROR_SPECIAL_CHARACTER = "error.special.character";

// Globale Meldungen
String MESSAGE_XML_HEADER = "message.xml.header";
Expand Down
3 changes: 2 additions & 1 deletion SIARDexcerpt/src/main/resources/de_messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ error.configfilehard.fileexisting = Die Config-Datei "configuration/SIARDexcerpt
error.logging.nofileappender =Kein File Appender gefunden. Die Konfiguration von log4j ist eventuell inkorrekt.
error.wrong.jdk = Die Version der Java Runtime Engine muss mindestens 1.6 sein. Bitte installieren Sie auf Ihrem Computer ein(e) ausreichende(s) JRE oder JDK. Die JRE kann von hier heruntergeladen werden\: http\://www.java.com/de/download/
error.noinit = Bitte zuerst die Initialisierung durchfuehren: {0}
error.special.character = Der Pfad "{0}" enthaelt ein Sonderzeichen "{1}", welches noch nicht unterstuetzt wird. Bitte normalisieren und nochmals starten.

# Globale Meldungen
message.xml.header = <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="{0}"?><table>
message.xml.start = <Infos><Start>{0}</Start>
message.xml.text = <{1}>{0}</{1}>
message.xml.info = <Info>SIARDexcerpt v0.0.8, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.info = <Info>SIARDexcerpt v0.0.9, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.logend = </table>
message.xml.title = Suchergebnis aus der Tabelle {0}:

Expand Down
3 changes: 2 additions & 1 deletion SIARDexcerpt/src/main/resources/en_messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ error.configfilehard.fileexisting = The config-file "{0}" already exists! Pleas
error.logging.nofileappender = No file appender found. The configuration of log4j is possibly incorrect.
error.wrong.jdk = The version of the Java Runtime Engine must be at least 1.6 Please install on your computer a sufficient JRE or JDK The JRE can be downloaded from here\: http\://www.java.com/de/download/
error.noinit = Please perform first the initialization: {0}
error.special.character = The path "{0}" contains a special character "{1}", which is not yet supported. Please normalize and restart it.

# Global Announcements
message.xml.header = <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="{0}"?><table>
message.xml.start = <Infos><Start>{0}</Start>
message.xml.text = <{1}>{0}</{1}>
message.xml.info = <Info>SIARDexcerpt v0.0.8, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.info = <Info>SIARDexcerpt v0.0.9, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.logend = </table>
message.xml.title = Search result from the table {0}:

Expand Down
3 changes: 2 additions & 1 deletion SIARDexcerpt/src/main/resources/fr_messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ error.configfilehard.fileexisting = Le fichier "configuration/SIARDexcerpt.conf
error.logging.nofileappender = Aucun fichier appender trouve. La configuration de log4j est peut-etre incorrecte.
error.wrong.jdk = La version de Java Runtime Engine doit etre au moins 1.6. S`il vous plait installer sur votre ordinateur un JRE ou JDK suffisant. Le JRE peut etre telecharge a partir d`ici \: http\://www.java.com/de/download/
error.noinit = S`il vous plait effectuer d`abord l`initialisation: {0}
error.special.character = Le lien "{0}" contient un caractere special "{1}", qui n`est pas encore pris en charge. S`il vous plait normaliser et recommencer.

# Globale Meldungen
message.xml.header = <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="{0}"?><table>
message.xml.start = <Infos><Start>{0}</Start>
message.xml.text = <{1}>{0}</{1}>
message.xml.info = <Info>SIARDexcerpt v0.0.8, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.info = <Info>SIARDexcerpt v0.0.9, Copyright (C) 2016 Claire Roethlisberger (KOST-CECO). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.logend = </table>
message.xml.title = Resultat de la recherche de la table {0}:

Expand Down
14 changes: 6 additions & 8 deletions SIARDexcerpt/src/main/resources_notJar/GUI/SIARDexcerpt.ini
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ Bottom=65
#Bottom=123

#[Field 12]
#Type=Button
#Text=&_Konfigurationsdatei zurücksetzen
#Flags=NOTIFY
#State=1
#Left=146
#Right=266
#Top=110
#Bottom=123
#Type=Label
#Text=_Maintable
#Left=-50
#Right=-3
#Top=69
#Bottom=79

[Field 13]
Type=Label
Expand Down
Loading

0 comments on commit 75f9708

Please sign in to comment.