[Schmitzm-commits] r2244 - in trunk: . schmitzm-adresses schmitzm-adresses/src/main/java/de/schmitzm/adresses schmitzm-core schmitzm-core/src/main/java/de/schmitzm schmitzm-core/src/main/java/de/schmitzm/lang schmitzm-core/src/test/java/de/schmitzm schmitzm-core/src/test/java/de/schmitzm/lang schmitzm-excelcsv/src/main/resources/de/schmitzm/csv/resource/locales schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales schmitzm-regexcache schmitzm-regexcache/src schmitzm-regexcache/src/main schmitzm-regexcache/src/main/java schmitzm-regexcache/src/main/java/de schmitzm-regexcache/src/main/java/de/schmitzm schmitzm-regexcache/src/main/java/de/schmitzm/regex schmitzm-regexcache/src/test schmitzm-regexcache/src/test/java schmitzm-regexcache/src/test/java/de schmitzm-regexcache/src/test/java/de/schmitzm schmitzm-regexcache/src/test/java/de/schmitzm/regex
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sun Feb 24 20:44:24 CET 2013
Author: alfonx
Date: 2013-02-24 20:44:23 +0100 (Sun, 24 Feb 2013)
New Revision: 2244
Added:
trunk/schmitzm-regexcache/
trunk/schmitzm-regexcache/pom.xml
trunk/schmitzm-regexcache/src/
trunk/schmitzm-regexcache/src/main/
trunk/schmitzm-regexcache/src/main/java/
trunk/schmitzm-regexcache/src/main/java/de/
trunk/schmitzm-regexcache/src/main/java/de/schmitzm/
trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/
trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexCache.java
trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexUtil.java
trunk/schmitzm-regexcache/src/test/
trunk/schmitzm-regexcache/src/test/java/
trunk/schmitzm-regexcache/src/test/java/de/
trunk/schmitzm-regexcache/src/test/java/de/schmitzm/
trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/
trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexCacheTest.java
trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexUtilTest.java
Removed:
trunk/schmitzm-core/src/main/java/de/schmitzm/regex/
trunk/schmitzm-core/src/test/java/de/schmitzm/regex/
Modified:
trunk/pom.xml
trunk/schmitzm-adresses/pom.xml
trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java
trunk/schmitzm-core/pom.xml
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LimitedConcurrentHashMap.java
trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
trunk/schmitzm-excelcsv/src/main/resources/de/schmitzm/csv/resource/locales/CsvResourceBundle_de.properties
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphic.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphicPreviewFixStyleVisitor.java
trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties
Log:
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/pom.xml 2013-02-24 19:44:23 UTC (rev 2244)
@@ -17,6 +17,7 @@
<module>schmitzm-gt</module>
<module>schmitzm-jfree</module>
<module>schmitzm-jfree-gt</module>
+ <module>schmitzm-regexcache</module>
<module>schmitzm-adresses</module>
<module>schmitzm-excelcsv</module>
<module>schmitzm-mail</module>
Modified: trunk/schmitzm-adresses/pom.xml
===================================================================
--- trunk/schmitzm-adresses/pom.xml 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-adresses/pom.xml 2013-02-24 19:44:23 UTC (rev 2244)
@@ -34,6 +34,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>de.schmitzm</groupId>
+ <artifactId>schmitzm-regex</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</project>
Modified: trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java
===================================================================
--- trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-adresses/src/main/java/de/schmitzm/adresses/AddrStringUtil.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -14,6 +14,7 @@
import de.schmitzm.lang.LangUtil;
import de.schmitzm.regex.RegexCache;
+import de.schmitzm.regex.RegexUtil;
/**
* Diese Klasse bietete nützliche Methoden zur Bearbeitung von Addressschreibweisen. Zur Zeit werden nur Strings mit
@@ -705,7 +706,7 @@
}
static public String saeubereStrassenname(final String orginal) {
- String strasse = LangUtil.removeTags(orginal).toLowerCase();
+ String strasse = RegexUtil.removeTags(orginal).toLowerCase();
// HN. am Ende
strasse = RegexCache.getInstance().replaceAll(strasse, "(\\d)\\s*\\.$", "$1");
Modified: trunk/schmitzm-core/pom.xml
===================================================================
--- trunk/schmitzm-core/pom.xml 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-core/pom.xml 2013-02-24 19:44:23 UTC (rev 2244)
@@ -111,27 +111,6 @@
<scope>compile</scope>
</dependency>
- <dependency>
- <artifactId>solr-core</artifactId>
- <groupId>org.apache.solr</groupId>
- <version>4.1.0</version>
- <type>jar</type>
- <exclusions>
- <exclusion>
- <artifactId>jcl-over-slf4j</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-jdk14</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- <exclusion>
- <artifactId>slf4j-api</artifactId>
- <groupId>org.slf4j</groupId>
- </exclusion>
- </exclusions>
- </dependency>
-
</dependencies>
<build>
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -77,7 +77,6 @@
import org.apache.log4j.PatternLayout;
import de.schmitzm.io.IOUtil;
-import de.schmitzm.regex.RegexCache;
import de.schmitzm.temp.BaseTypeUtil;
/**
@@ -176,15 +175,15 @@
* {@link #REMOVE_WHITESPACES_ON_PARSE_STRING} flag. This method can be called at the beginning of an application.
*/
public static boolean checkRegexCacheAvailable() {
- try {
- RegexCache.getInstance();
- REMOVE_WHITESPACES_ON_PARSE_STRING = true;
- return true;
- } catch (Throwable e) {
- // RegexCache can not be used
+// try {
+// RegexCache.getInstance();
+// REMOVE_WHITESPACES_ON_PARSE_STRING = true;
+// return true;
+// } catch (Throwable e) {
+// // RegexCache can not be used
REMOVE_WHITESPACES_ON_PARSE_STRING = false;
return false;
- }
+// }
}
@@ -2473,83 +2472,7 @@
return result;
}
- final static String REMOVETAGSREGEX = "\\s*<[^>]*>\\s*";
-
/**
- * Kann verwendet werden, um einen String von XML/HTML Tags zu säubern. Rückgabe ist ein ein String ohne Tags. Mehr
- * als 2 Leerzeichen werden zu einem Leerzeichen. Am Ende und Anfang nie Leerzeichen. Ein <li>wird zu einem * um die
- * Lesbarkeit als Rein-Text zu verbessern.<br/>
- * Die Methode basiert auf RegEx. Es wird also kein valides oder wellformed-XML erwartet.
- */
- public static String removeTags(String withTags) {
- if (withTags == null)
- return null;
-
- String withoutTags = withTags;
-
- Matcher matcher = RegexCache.getInstance().getMatcher("<li>", withoutTags);
- if (matcher.find())
- withoutTags = matcher.replaceAll("*");
-
- matcher = RegexCache.getInstance().getMatcher(REMOVETAGSREGEX, withoutTags);
- if (matcher.find())
- withoutTags = matcher.replaceAll(" ");
-
- matcher = RegexCache.getInstance().getMatcher("\\b\\+\\b", withoutTags);
- if (matcher.find())
- withoutTags = matcher.replaceAll(" ");
-
- matcher = RegexCache.getInstance().getMatcher("\\s{1,}", withoutTags);
- if (matcher.find())
- withoutTags = matcher.replaceAll(" ");
-
- // withoutTags = withoutTags.replaceAll("<li>", "*");
- // withoutTags = withoutTags.replaceAll(REMOVETAGSREGEX, " ");
- // withoutTags = withoutTags.replaceAll("\\s{1,}", " ");
-
- return withoutTags.trim();
- }
-
- /**
- * Liefert einen String zurück, der zeigt, wo die RegEx im String getroffen hat. Der getroffene Bereich wird
- * +-$border Zeichen ausgeschnitten und GROSS geschrieben. <br/>
- * Beispiele:
- * <ul>
- * <li>assertEquals("abcBAUMdef", LangUtil.regExBereich("abcBaumdef", "Baum", 115)); <br/>
- * <li>assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1));
- */
- static public String regExBereich(String value, String regex, int border) {
- return regExBereich(value, regex, border, ".*", ".*");
- }
-
- static public String regExBereich(String value, String regex, int border, String pre, String post) {
-
- if (border < 0)
- throw new IllegalStateException("border may not be smaller 0!");
-
- if (regex.startsWith("^"))
- regex = regex.substring(1);
-
- String r2 = pre + "(" + regex + ")" + post;
- // Pattern compile = Pattern.compile(r2);
- // Matcher matcher = compile.matcher(value);
-
- Matcher matcher = RegexCache.getInstance().getMatcher(r2, value);
- if (!matcher.find())
- return "";
-
- int start = matcher.start(1);
- final String treffer = matcher.group(1);
-
- int s2 = Math.min(start, border);
- String vorher = value.substring(start - s2, start);
-
- String nachher = value.substring(matcher.end(1), Math.min(matcher.end(1) + border, value.length()));
-
- return vorher.toLowerCase() + treffer.toUpperCase() + nachher.toLowerCase();
- }
-
- /**
* Fasst Zeilenumbrüche und sonstige Leerräume zu einem einizgen Leerzeichen zusammen.
*
* @Deprecated use removeWhitespacesToNull
@@ -2590,12 +2513,13 @@
if (string == null)
return "";
- final Matcher matcher = RegexCache.getInstance().getMatcher(REMOVE_WHITESPACES_PATTERN_R, string);
+// final Matcher matcher = RegexCache.getInstance().getMatcher(REMOVE_WHITESPACES_PATTERN_R, string);
+ final Matcher matcher = Pattern.compile(REMOVE_WHITESPACES_PATTERN_R).matcher(string);
string = matcher.replaceAll(" ");
// Leerraum konsolidieren
- final String result = RegexCache.getInstance().getMatcher(REMOVE_WHITESPACES_PATTERN2_R, string)
+ final String result = Pattern.compile(REMOVE_WHITESPACES_PATTERN2_R).matcher(string)
.replaceAll(" ");
return result;
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LimitedConcurrentHashMap.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LimitedConcurrentHashMap.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LimitedConcurrentHashMap.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -33,8 +33,6 @@
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.solr.util.ConcurrentLFUCache;
-
import de.schmitzm.data.event.AbstractObjectTraceable;
import de.schmitzm.data.event.GeneralObjectChangeEvent;
import de.schmitzm.data.event.Invoker;
Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -21,6 +21,7 @@
assertTrue(LangUtil.onlyZero("0"));
assertTrue(LangUtil.onlyZero(""));
assertTrue(LangUtil.onlyZero("000,000,0.0"));
+
assertFalse(LangUtil.onlyZero(" 0,02"));
assertFalse(LangUtil.onlyZero(" 20,0"));
assertFalse(LangUtil.onlyZero(" 00200,0"));
@@ -116,50 +117,6 @@
assertEquals("s5", withOutNulls[1]);
}
- @Test
- public void testRemoveTags() {
- assertEquals("hallo welt", LangUtil.removeTags("<h1>hallo<br/>welt</h1>"));
- assertEquals("hallo welt", LangUtil.removeTags("<h1>hallo<br/>\nwelt</h1>"));
- assertEquals("hallo welt", LangUtil.removeTags("<h1>hallo<td/>\n<td>welt</h1>"));
- assertEquals("hallo welt", LangUtil.removeTags("<h1>hallo<td/> <td>welt</h1>"));
- assertEquals("hallo welt", LangUtil.removeTags("<h1>hallo<td/> \n <td image='asdasdasa'>welt</h1>"));
- assertEquals("hallo *asd welt",
- LangUtil.removeTags("<h1>hallo<td/><li>asd</li><td image='asdasdasa'>welt</h1>"));
- assertEquals("hallo welt", LangUtil.removeTags("<h1 time='as'>hallo<td/> \n <td image='asdasdasa'>welt</h1>"));
-
- assertEquals("Pflanzkamp 10a 40229 Düsseldorf", LangUtil.removeTags("Pflanzkamp+10a+40229+Düsseldorf"));
- }
-
- @Test
- public void testRegExBereich() {
- assertEquals("BAUM", LangUtil.regExBereich("Baum", "Baum", 5));
- assertEquals("BAUM", LangUtil.regExBereich("Baum", "^Baum", 5));
- assertEquals("23BAUM", LangUtil.regExBereich("123Baum", "Baum$", 2));
- assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 5));
- assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 115));
- assertEquals("abcBAUMdef", LangUtil.regExBereich("abcBaumdef", "Baum", 115));
- assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1));
-
- assertEquals("er BAUM zu",
- LangUtil.regExBereich("Am Ender der Absperrung war ein groÃer Baum zu sehen", "Baum", 3));
-
- }
-
- @Test
- public void testRegExBereich2() {
- assertEquals("BAUM", LangUtil.regExBereich("Baum", "Baum", 5, "^.*?", ""));
- assertEquals("BAUM", LangUtil.regExBereich("Baum", "^Baum", 5, "^.*?", ""));
- assertEquals("23BAUM", LangUtil.regExBereich("123Baum", "Baum$", 2, "^.*?", ""));
- assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 5, "^.*?", ""));
- assertEquals("12345BAUM67890", LangUtil.regExBereich("12345Baum67890", "Baum", 115, "^.*?", ""));
- assertEquals("abcBAUMdef", LangUtil.regExBereich("abcBaumdef", "Baum", 115, "^.*?", ""));
- assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1, "^.*?", ""));
-
- assertEquals("er BAUM zu",
- LangUtil.regExBereich("Am Ender der Absperrung war ein groÃer Baum zu sehen", "Baum", 3));
-
- }
-
public static int testMethod(int i, double j) {
return i;
}
Modified: trunk/schmitzm-excelcsv/src/main/resources/de/schmitzm/csv/resource/locales/CsvResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-excelcsv/src/main/resources/de/schmitzm/csv/resource/locales/CsvResourceBundle_de.properties 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-excelcsv/src/main/resources/de/schmitzm/csv/resource/locales/CsvResourceBundle_de.properties 2013-02-24 19:44:23 UTC (rev 2244)
@@ -1,63 +1,63 @@
-##########
-#Copyright (c) 2009 Martin O. J. Schmitz.
-#
-#This file is part of the SCHMITZM library - a collection of utility
-#classes based on Java 1.6, focusing (not only) on Java Swing
-#and the Geotools library.
-#
-#The SCHMITZM project is hosted at:
-#http://wald.intevation.org/projects/schmitzm/
-#
-#This program is free software; you can redistribute it and/or
-#modify it under the terms of the GNU Lesser General Public License
-#as published by the Free Software Foundation; either version 3
-#of the License, or (at your option) any later version.
-#
-#This program is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#GNU General Public License for more details.
-#
-#You should have received a copy of the GNU Lesser General Public License (license.txt)
-#along with this program; if not, write to the Free Software
-#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#or try this link: http://www.gnu.org/licenses/lgpl.html
-#
-#Contributors:
-# Martin O. J. Schmitz - initial API and implementation
-# Stefan A. Tzeggai - additional utility classes
-##########
-
-# ------------------------------------------------
-# ------ German Translations for components ------
-# ------ in Package de.schmitzm.csv ------
-# ------------------------------------------------
-
-CSVDialogOptions.file.label=CSV Datei
-CSVDialogOptions.delim.label=CSV Spalten-Trennzeichen
-CSVDialogOptions.delim.tab.desc=Tab (\\t)
-CSVDialogOptions.delim.semicolon.desc=Semikolon (;)
-CSVDialogOptions.delim.pipe.desc=Pipe (|)
-CSVDialogOptions.delim.comma.desc=Komma (,)
-CSVDialogOptions.delim.space.desc=Leerzeichen (' ')
-CSVDialogOptions.quote.label=CSV Text-Maskierungs-Zeichen
-CSVDialogOptions.decimal.label=CSV Dezimal-Trennzeichen
-CSVDialogOptions.charset.label=Zeichensatz der Datei
-CSVDialogOptions.charset.cp850.desc=Codepage 850 (Windows)
-CSVDialogOptions.charset.cp1252.desc=Codepage 1252 (Windows)
-CSVDialogOptions.charset.utf8.desc=UTF-8 (moderne Betriebssysteme, z.B. Linux)
-CSVDialogOptions.charset.iso-8859-15.desc=ISO-8859-15 Westeuropa (Windows)
-CSVDialogOptions.nodata.label=Wert der \"no data\" darstellt
-
-CSVPreviewTableModel.error.title=CSV Vorschau
-CSVPreviewTableModel.error.mess=Fehler bei der Generierung der CSV-Vorschau (siehe CSV-Quelle für Details)
-
-CSVPreviewPanel.tab.preview=Konfiguration & Vorschau
-CSVPreviewPanel.tab.source=Quell-Datei
-CSVPreviewPanel.preview.label=Vorschau
-CSVPreviewPanel.preview.limit.label=Limit für Vorschau-Zeilen
-CSVPreviewPanel.preview.firstLine.label=Erste Zeile für Vorschau
-
-CSVColumnAllocationPanel.columns.label=CSV-Spalten Zuweisung
-CSVColumnAllocationPanel.units.label=CSV Einheit
-
+##########
+#Copyright (c) 2009 Martin O. J. Schmitz.
+#
+#This file is part of the SCHMITZM library - a collection of utility
+#classes based on Java 1.6, focusing (not only) on Java Swing
+#and the Geotools library.
+#
+#The SCHMITZM project is hosted at:
+#http://wald.intevation.org/projects/schmitzm/
+#
+#This program is free software; you can redistribute it and/or
+#modify it under the terms of the GNU Lesser General Public License
+#as published by the Free Software Foundation; either version 3
+#of the License, or (at your option) any later version.
+#
+#This program is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU Lesser General Public License (license.txt)
+#along with this program; if not, write to the Free Software
+#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#or try this link: http://www.gnu.org/licenses/lgpl.html
+#
+#Contributors:
+# Martin O. J. Schmitz - initial API and implementation
+# Stefan A. Tzeggai - additional utility classes
+##########
+
+# ------------------------------------------------
+# ------ German Translations for components ------
+# ------ in Package de.schmitzm.csv ------
+# ------------------------------------------------
+
+CSVDialogOptions.file.label=CSV Datei
+CSVDialogOptions.delim.label=CSV Spalten-Trennzeichen
+CSVDialogOptions.delim.tab.desc=Tab (\\t)
+CSVDialogOptions.delim.semicolon.desc=Semikolon (;)
+CSVDialogOptions.delim.pipe.desc=Pipe (|)
+CSVDialogOptions.delim.comma.desc=Komma (,)
+CSVDialogOptions.delim.space.desc=Leerzeichen (' ')
+CSVDialogOptions.quote.label=CSV Text-Maskierungs-Zeichen
+CSVDialogOptions.decimal.label=CSV Dezimal-Trennzeichen
+CSVDialogOptions.charset.label=Zeichensatz der Datei
+CSVDialogOptions.charset.cp850.desc=Codepage 850 (Windows)
+CSVDialogOptions.charset.cp1252.desc=Codepage 1252 (Windows)
+CSVDialogOptions.charset.utf8.desc=UTF-8 (moderne Betriebssysteme, z.B. Linux)
+CSVDialogOptions.charset.iso-8859-15.desc=ISO-8859-15 Westeuropa (Windows)
+CSVDialogOptions.nodata.label=Wert der \"no data\" darstellt
+
+CSVPreviewTableModel.error.title=CSV Vorschau
+CSVPreviewTableModel.error.mess=Fehler bei der Generierung der CSV-Vorschau (siehe CSV-Quelle f\ufffdr Details)
+
+CSVPreviewPanel.tab.preview=Konfiguration & Vorschau
+CSVPreviewPanel.tab.source=Quell-Datei
+CSVPreviewPanel.preview.label=Vorschau
+CSVPreviewPanel.preview.limit.label=Limit f\ufffdr Vorschau-Zeilen
+CSVPreviewPanel.preview.firstLine.label=Erste Zeile f\ufffdr Vorschau
+
+CSVColumnAllocationPanel.columns.label=CSV-Spalten Zuweisung
+CSVColumnAllocationPanel.units.label=CSV Einheit
+
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphic.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphic.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphic.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -30,7 +30,6 @@
import de.schmitzm.geotools.feature.FeatureUtil;
import de.schmitzm.geotools.gui.GeotoolsGUIUtil;
import de.schmitzm.geotools.styling.StylingUtil;
-import de.schmitzm.regex.RegexCache;
import de.schmitzm.swing.SwingUtil;
/**
@@ -266,7 +265,7 @@
*/
// Read the Chart-Type!
- Pattern typePattern = RegexCache.getInstance().getPattern(
+ Pattern typePattern = Pattern.compile(
"cht=(.*?)(&.*|^)");
Matcher m = typePattern.matcher(url);
if (m.find() && m.groupCount() > 0) {
@@ -274,7 +273,7 @@
}
// Read the ATTRIBUTE NAMES from the Style
- Pattern nextAtt = RegexCache.getInstance().getPattern(
+ Pattern nextAtt = Pattern.compile(
"\\$\\{([^ ]*?)( .*?|)\\}");
m = nextAtt.matcher(url);
while (m.find() && m.groupCount() > 0) {
@@ -282,12 +281,12 @@
}
// Read the COLORS from the Style
- Pattern colorPart = RegexCache.getInstance().getPattern(
+ Pattern colorPart = Pattern.compile(
"chco=([^&]*?)(&.*|$)");
m = colorPart.matcher(url);
if (m.find() && m.groupCount() == 2) {
String colorstr = m.group(1);
- Pattern nextColor = RegexCache.getInstance().getPattern(
+ Pattern nextColor = Pattern.compile(
"([a-f,A-F,0-9]{6,6})(?:[&,]|$)?");
m = nextColor.matcher(colorstr);
int count = 0;
@@ -300,7 +299,7 @@
}
// Read any size from the Style
- Pattern sizePart = RegexCache.getInstance().getPattern(
+ Pattern sizePart = Pattern.compile(
"chs=(\\d+)x(\\d+)");
m = sizePart.matcher(url);
if (m.find() && m.groupCount() == 2) {
@@ -309,7 +308,7 @@
}
// Try to find a maxValue
- Pattern maxValuePattern = RegexCache.getInstance().getPattern(
+ Pattern maxValuePattern = Pattern.compile(
"\\$\\{([^ \\*]*?) \\* 100\\. / ([^ \\*]*)\\}");
m = maxValuePattern.matcher(url);
if (m.find() && m.groupCount() == 2) {
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphicPreviewFixStyleVisitor.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphicPreviewFixStyleVisitor.java 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/chartsymbols/ChartGraphicPreviewFixStyleVisitor.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -1,13 +1,13 @@
package de.schmitzm.geotools.styling.chartsymbols;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.geotools.styling.ExternalGraphic;
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
import de.schmitzm.geotools.styling.StylingUtil;
-import de.schmitzm.regex.RegexCache;
/**
* When a dynamic Chart Symvol is previewed, the freemarker(?) expressions (like
@@ -31,14 +31,14 @@
// Howmany placeholders to we have?
int count = 0;
- Matcher m = RegexCache.getInstance().getPattern(regex).matcher(url2);
+ Matcher m = Pattern.compile(regex).matcher(url2);
while (m
.find()) {
count++;
}
int count2 = 0;
- m = RegexCache.getInstance().getPattern(regex).matcher(url2);
+ m = Pattern.compile(regex).matcher(url2);
while (m
.find()) {
count2++;
Modified: trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties 2013-02-23 21:54:40 UTC (rev 2243)
+++ trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties 2013-02-24 19:44:23 UTC (rev 2244)
@@ -1,44 +1,44 @@
-##########
-#Copyright (c) 2009 Martin O. J. Schmitz.
-#
-#This file is part of the SCHMITZM library - a collection of utility
-#classes based on Java 1.6, focusing (not only) on Java Swing
-#and the Geotools library.
-#
-#The SCHMITZM project is hosted at:
-#http://wald.intevation.org/projects/schmitzm/
-#
-#This program is free software; you can redistribute it and/or
-#modify it under the terms of the GNU Lesser General Public License
-#as published by the Free Software Foundation; either version 3
-#of the License, or (at your option) any later version.
-#
-#This program is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#GNU General Public License for more details.
-#
-#You should have received a copy of the GNU Lesser General Public License (license.txt)
-#along with this program; if not, write to the Free Software
-#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#or try this link: http://www.gnu.org/licenses/lgpl.html
-#
-#Contributors:
-# Martin O. J. Schmitz - initial API and implementation
-# Stefan A. Tzeggai - additional utility classes
-##########
-
-# ------------------------------------------------
-# ------ German Translations for components ------
-# ------ in Package de.schmitzm.net.mail ------
-# ------------------------------------------------
-MailAddressesPanel.from=Von
-MailAddressesPanel.to=An
-MailAddressesPanel.cc=Kopie (CC)
-MailAddressesPanel.bcc=Blindkopie (BCC)
-AttachmentsPanel.caption=Anhänge
-AttachmentsPanel.size=Größe
-AttachmentsPanel.add=Anhang
-AttachmentsPanel.add.desc=Datei-Anhang der Mail hinzufügen
-
-
+##########
+#Copyright (c) 2009 Martin O. J. Schmitz.
+#
+#This file is part of the SCHMITZM library - a collection of utility
+#classes based on Java 1.6, focusing (not only) on Java Swing
+#and the Geotools library.
+#
+#The SCHMITZM project is hosted at:
+#http://wald.intevation.org/projects/schmitzm/
+#
+#This program is free software; you can redistribute it and/or
+#modify it under the terms of the GNU Lesser General Public License
+#as published by the Free Software Foundation; either version 3
+#of the License, or (at your option) any later version.
+#
+#This program is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU Lesser General Public License (license.txt)
+#along with this program; if not, write to the Free Software
+#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#or try this link: http://www.gnu.org/licenses/lgpl.html
+#
+#Contributors:
+# Martin O. J. Schmitz - initial API and implementation
+# Stefan A. Tzeggai - additional utility classes
+##########
+
+# ------------------------------------------------
+# ------ German Translations for components ------
+# ------ in Package de.schmitzm.net.mail ------
+# ------------------------------------------------
+MailAddressesPanel.from=Von
+MailAddressesPanel.to=An
+MailAddressesPanel.cc=Kopie (CC)
+MailAddressesPanel.bcc=Blindkopie (BCC)
+AttachmentsPanel.caption=Anh\ufffdnge
+AttachmentsPanel.size=Gr\ufffd\ufffde
+AttachmentsPanel.add=Anhang
+AttachmentsPanel.add.desc=Datei-Anhang der Mail hinzuf\ufffdgen
+
+
Added: trunk/schmitzm-regexcache/pom.xml
===================================================================
--- trunk/schmitzm-regexcache/pom.xml (rev 0)
+++ trunk/schmitzm-regexcache/pom.xml 2013-02-24 19:44:23 UTC (rev 2244)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>schmitzm-regex</artifactId>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>de.schmitzm</groupId>
+ <artifactId>schmitzm-parent</artifactId>
+ <version>2.8-SNAPSHOT</version>
+ <relativePath>../schmitzm-parent/pom.xml</relativePath>
+ </parent>
+
+ <name>schmitzm-regex</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>com.eaio.stringsearch</groupId>
+ <artifactId>stringsearch</artifactId>
+ <version>2</version>
+ </dependency>
+
+ <dependency>
+ <artifactId>solr-core</artifactId>
+ <groupId>org.apache.solr</groupId>
+ <version>4.1.0</version>
+ <type>jar</type>
+ <exclusions>
+ <exclusion>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-jdk14</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>slf4j-api</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+
+ <repositories>
+ <repository>
+ <id>eaio.com</id>
+ <url>http://eaio.com/maven2</url>
+ </repository>
+ </repositories>
+
+
+
+</project>
Added: trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexCache.java
===================================================================
--- trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexCache.java (rev 0)
+++ trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexCache.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -0,0 +1,293 @@
+package de.schmitzm.regex;
+
+import java.io.PrintStream;
+import java.util.regex.MatchResult;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+import org.apache.solr.util.ConcurrentLRUCache;
+import org.apache.solr.util.ConcurrentLRUCache.Stats;
+
+/**
+ * Cached compilierte Pattern und auch Ergebnisse von RegExes. Use the matchers methods to obtain cached result and add
+ * regex to cache automatically.
+ *
+ * @author stranger
+ * @author stefan.tzeggai
+ */
+
+public class RegexCache {
+
+ private static final String KEY_STRING_TRENNER = ":*:";
+
+ final static Logger log = Logger.getLogger(RegexCache.class);
+ //
+ // final static ThreadLocal<BNDM> bndms = new ThreadLocal<BNDM>() {
+ // @Override
+ // protected BNDM initialValue() {
+ // return new BNDM();
+ // }
+ // };
+ //
+ // final static ThreadLocal<BNDMCI> bndmcis = new ThreadLocal<BNDMCI>() {
+ // @Override
+ // protected BNDMCI initialValue() {
+ // return new BNDMCI();
+ // }
+ // };
+
+ /**
+ * Regex-Auswertungen komplett cachen
+ */
+ public static boolean resultsCacheEnabled = true;
+
+ /**
+ * Ein String der länger ist als die hier angegebene Anzahl Zeichen wir nicht gecached. Die Wahrscheinlichkeit, dass
+ * der selbe Sting nochmal auftaucht wird als zu gering eingeschätzt.
+ **/
+ private static final int CACHE_VALUES_TO_RESULT_MAX_VALUE_LENGTH = 100;
+
+ /**
+ * Ein String der kürzer als die hier angegebene Anzahl Zeichen wir nicht gecached.
+ **/
+ private static final int CACHE_VALUES_TO_RESULT_MIN_VALUE_LENGTH = 0;
+
+ /**
+ * Der Results-Cache greift nur für Regex länger als soviel Zeichen:
+ */
+ private static final int CACHE_VALUES_TO_RESULT_MIN_REGEX_LENGTH = 0;
+ /**
+ * Der Results-Cache greift nur für Regex länger als soviel Zeichen:
+ */
+ private static final int CACHE_VALUES_TO_RESULT_MAX_REGEX_LENGTH = 10000;
+
+ private static RegexCache singletonInstance;
+
+ private final ConcurrentLRUCache<String, Pattern> patternCache = new ConcurrentLRUCache<String, Pattern>(110000,
+ 90000);
+
+ public static RegexCache getInstance() {
+ return singletonInstance != null ? singletonInstance : new RegexCache();
+ }
+
+ private final ConcurrentLRUCache<String, MyMatchResult> resultsCache = new ConcurrentLRUCache<String, MyMatchResult>(
+ 400000, 300000);
+
+ private RegexCache() {
+ singletonInstance = this;
+ }
+
+ /**
+ * Diese Methode ist gedacht um die Erstellung von Matcher-Objekten in der JVM zu reduzieren. Es für bis zu 10000
+ * RegEx ein Cache verwaltet. Jeder dieser Caches ist ein ThreadLocal-Cache von Matchern. Somit liefert diese Methde
+ * für die selbe RegEx auf N Threads N unterschiedliche Matcher.<br/>
+ * Die Matcher werden für die Regex gecached. Wird ein Matcher für eine gecachte Regex mit einem anderen TEXT
+ * angeforderd, wird zuerst {@link Matcher#reset(CharSequence)} ausgeführt.
+ */
+ public final Matcher getMatcher(final String regex, final String text) {
+ return getPattern(regex).matcher(text);
+ }
+
+ /**
+ * Liefert eine compiliertes RegEx Pattern aus dem Cache. Wenn es vorher nicht existierte wird es erstellt.
+ */
+ public final Pattern getPattern(final String regex) {
+ if (regex == null)
+ return null;
+ // synchronized (regex) {
+ Pattern p = patternCache.get(regex);
+ if (p == null) {
+ p = Pattern.compile(regex);
+ patternCache.put(regex, p);
+ }
+ return p;
+ // }
+ }
+
+ /**
+ * Will throw java exceptions when pattern won't compile.
+ *
+ * @param regex
+ * may not be null
+ * @param value
+ * returns false is <code>null</code>
+ */
+ public final boolean matches(final String regex, final Object object) {
+ if (object == null)
+ return false;
+
+ final String value = object instanceof String ? (String) object : object.toString();
+
+ // Hier beginnt eine interessante Optimierung. Wenn der String keine Regex ist, und nicht länger 32, dann wird
+ // ein schnellere Stringsuche verwendet.
+ // boolean canSpeedup = true;
+ // boolean speedUpIgnorecase = true;
+ //
+ // if (regex.length() > 20)
+ // canSpeedup = false;
+ // else {
+ // String copy = regex;
+ // if (copy.startsWith("(?is)") || copy.startsWith("(?im)") || copy.startsWith("(?ims)")) {
+ // copy = copy.substring(5);
+ // speedUpIgnorecase = true;
+ // }
+ // if (copy.startsWith("^.*?")) {
+ // copy = copy.substring(4);
+ // }
+ // canSpeedup = !(looksLikeRegex(copy));
+ // }
+ //
+ // if (canSpeedup) {
+ //
+ // StringSearch bndm = speedUpIgnorecase ? bndmcis.get() : bndms.get();
+ // int searchString = bndm.searchString(value, regex);
+ //
+ // int idx = searchString;
+ // return idx >= 0;
+ // } else {
+ return result(regex, value) != null;
+ // }
+ }
+
+ String ERKENNE_REGEX_RX = "[\\[\\]()?\\\\+{}^$.]";
+
+ public boolean looksLikeRegex(final String suchString) {
+ // Kein "Matches()" hier verwenden sonst StackOverflow
+ // return matches(ERKENNE_REGEX_RX, regex);
+ return result(ERKENNE_REGEX_RX, suchString) != null;
+ }
+
+ /**
+ * Will throw java exceptions when pattern won't compile.
+ *
+ * @param regex
+ * may not be null
+ * @param value
+ * may not be null
+ * @return <code>null</code> if the pattern didn't match. A {@link MatchResult} otherwise which contains the groups
+ * etc.
+ * TODO Der cache sollte eine Hit-Quote halten, die irgendwann den Cache für eine Regex blockt
+ */
+ public final MatchResult result(final String regex, final String value) {
+
+ // Wenn der value-String zu lang oder zu kurz ist, dann einfach so machten
+ if (!resultsCacheEnabled || value.length() < CACHE_VALUES_TO_RESULT_MIN_VALUE_LENGTH
+ || value.length() > CACHE_VALUES_TO_RESULT_MAX_VALUE_LENGTH
+ || regex.length() < CACHE_VALUES_TO_RESULT_MIN_REGEX_LENGTH
+ || regex.length() > CACHE_VALUES_TO_RESULT_MAX_REGEX_LENGTH) {
+
+ final Matcher m = getMatcher(regex, value);
+ final boolean found = m.find();
+ MatchResult matchResult = found ? m.toMatchResult() : null;
+ return matchResult;
+ }
+
+ final String key = regex + KEY_STRING_TRENNER + value;
+ MyMatchResult mResult = resultsCache.get(key);
+ if (mResult == null) {
+ // final Matcher xm = pattern.matcher(value);
+ final Matcher xm = getMatcher(regex, value);
+
+ if (xm.find())
+ mResult = new MyMatchResult(xm.toMatchResult());
+ else
+ mResult = new MyMatchResult(null);
+
+ resultsCache.put(key, mResult);
+ }
+
+ return mResult.matcherResult;
+ }
+
+ /**
+ * Liefert die aktuellen Statistiken des ResultsCache
+ */
+ public Stats getResultsCacheStats() {
+ return resultsCache.getStats();
+ }
+
+ /**
+ * Liefert die aktuellen Statistiken des PatternCache
+ */
+ public Stats getPatternCacheStats() {
+ return patternCache.getStats();
+ }
+
+ /**
+ * Diese Klasse dienst dazu, einen Eintrag im cache liegen zu haben, auch wenn keine match gefunden wurde. In dem
+ * Falle ist das Feld {@link #matcherResult} dann <code>null</code>
+ *
+ */
+ final static class MyMatchResult {
+
+ final MatchResult matcherResult;
+
+ MyMatchResult(final MatchResult matcher) {
+ this.matcherResult = matcher;
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ destroy();
+ } finally {
+ super.finalize();
+ }
+ }
+
+ /**
+ * The RegexCache is no more usable after calling destroy!
+ */
+ public void destroy() {
+ if (resultsCache != null) {
+ resultsCache.clear();
+ resultsCache.destroy();
+ }
+
+ if (patternCache != null) {
+ patternCache.clear();
+ patternCache.destroy();
+ }
+ }
+
+ public void report(PrintStream out) {
+ org.apache.solr.util.ConcurrentLRUCache.Stats cStats = getPatternCacheStats();
+ out.println("PatternCache : Hits=" + cStats.getCumulativeHits() + " Lookups="
+ + cStats.getCumulativeLookups() + " Misses=" + cStats.getCumulativeMisses() + " currentSize="
+ + cStats.getCurrentSize());
+
+ cStats = getResultsCacheStats();
+ out.println("ResultsCacheStats: Hits=" + cStats.getCumulativeHits() + " Lookups="
+ + cStats.getCumulativeLookups() + " Misses=" + cStats.getCumulativeMisses() + " currentSize="
+ + cStats.getCurrentSize());
+ }
+
+ /**
+ * Ist einem {@link String#replaceAll(String, String)} vorzuziehen, da hier das Pattern nicht immer neu erstellt
+ * werden muss.
+ *
+ * @param text
+ * @param regex
+ * @param replacement
+ */
+ public String replaceAll(String text, String regex, String replacement) {
+ Matcher matcher = getMatcher(regex, text);
+ return matcher.replaceAll(replacement);
+ }
+
+ /**
+ * Ist einem {@link String#replaceFirst(String, String)} vorzuziehen, da hier das Pattern nicht immer neu erstellt
+ * werden muss.
+ *
+ * @param text
+ * @param regex
+ * @param replacement
+ */
+ public String replaceFirst(String text, String regex, String replacement) {
+ Matcher matcher = getMatcher(regex, text);
+ return matcher.replaceFirst(replacement);
+ }
+
+}
Added: trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexUtil.java
===================================================================
--- trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexUtil.java (rev 0)
+++ trunk/schmitzm-regexcache/src/main/java/de/schmitzm/regex/RegexUtil.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -0,0 +1,83 @@
+package de.schmitzm.regex;
+
+import java.util.regex.Matcher;
+
+public class RegexUtil {
+
+ final static String REMOVETAGSREGEX = "\\s*<[^>]*>\\s*";
+
+ /**
+ * Kann verwendet werden, um einen String von XML/HTML Tags zu säubern. Rückgabe ist ein ein String ohne Tags. Mehr
+ * als 2 Leerzeichen werden zu einem Leerzeichen. Am Ende und Anfang nie Leerzeichen. Ein <li>wird zu einem * um die
+ * Lesbarkeit als Rein-Text zu verbessern.<br/>
+ * Die Methode basiert auf RegEx. Es wird also kein valides oder wellformed-XML erwartet.
+ */
+ public static String removeTags(String withTags) {
+ if (withTags == null)
+ return null;
+
+ String withoutTags = withTags;
+
+ Matcher matcher = RegexCache.getInstance().getMatcher("<li>", withoutTags);
+ if (matcher.find())
+ withoutTags = matcher.replaceAll("*");
+
+ matcher = RegexCache.getInstance().getMatcher(REMOVETAGSREGEX, withoutTags);
+ if (matcher.find())
+ withoutTags = matcher.replaceAll(" ");
+
+ matcher = RegexCache.getInstance().getMatcher("\\b\\+\\b", withoutTags);
+ if (matcher.find())
+ withoutTags = matcher.replaceAll(" ");
+
+ matcher = RegexCache.getInstance().getMatcher("\\s{1,}", withoutTags);
+ if (matcher.find())
+ withoutTags = matcher.replaceAll(" ");
+
+ // withoutTags = withoutTags.replaceAll("<li>", "*");
+ // withoutTags = withoutTags.replaceAll(REMOVETAGSREGEX, " ");
+ // withoutTags = withoutTags.replaceAll("\\s{1,}", " ");
+
+ return withoutTags.trim();
+ }
+
+ /**
+ * Liefert einen String zurück, der zeigt, wo die RegEx im String getroffen hat. Der getroffene Bereich wird
+ * +-$border Zeichen ausgeschnitten und GROSS geschrieben. <br/>
+ * Beispiele:
+ * <ul>
+ * <li>assertEquals("abcBAUMdef", LangUtil.regExBereich("abcBaumdef", "Baum", 115)); <br/>
+ * <li>assertEquals("5BAUM6", LangUtil.regExBereich("12345Baum67890", "Baum", 1));
+ */
+ static public String regExBereich(String value, String regex, int border) {
+ return regExBereich(value, regex, border, ".*", ".*");
+ }
+
+ static public String regExBereich(String value, String regex, int border, String pre, String post) {
+
+ if (border < 0)
+ throw new IllegalStateException("border may not be smaller 0!");
+
+ if (regex.startsWith("^"))
+ regex = regex.substring(1);
+
+ String r2 = pre + "(" + regex + ")" + post;
+ // Pattern compile = Pattern.compile(r2);
+ // Matcher matcher = compile.matcher(value);
+
+ Matcher matcher = RegexCache.getInstance().getMatcher(r2, value);
+ if (!matcher.find())
+ return "";
+
+ int start = matcher.start(1);
+ final String treffer = matcher.group(1);
+
+ int s2 = Math.min(start, border);
+ String vorher = value.substring(start - s2, start);
+
+ String nachher = value.substring(matcher.end(1), Math.min(matcher.end(1) + border, value.length()));
+
+ return vorher.toLowerCase() + treffer.toUpperCase() + nachher.toLowerCase();
+ }
+
+}
Added: trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexCacheTest.java
===================================================================
--- trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexCacheTest.java (rev 0)
+++ trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexCacheTest.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -0,0 +1,27 @@
+package de.schmitzm.regex;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class RegexCacheTest {
+ @Test
+ public void testLooksLikeRegex() {
+ RegexCache rC = RegexCache.getInstance();
+
+ assertTrue(rC.looksLikeRegex("^Brezeln"));
+ assertTrue(rC.looksLikeRegex("Um mit (?:dir|das) Brezeln"));
+ assertTrue(rC.looksLikeRegex("Um mit [asd] Brezeln"));
+ assertTrue(rC.looksLikeRegex("Gastst.tte"));
+ assertFalse(rC.looksLikeRegex("asd"));
+ }
+
+ @Test
+ public void testMatches() {
+ RegexCache rC = RegexCache.getInstance();
+
+ assertTrue(rC.matches("[sd]h", "asdasdh asdsa"));
+ assertFalse(rC.matches("[sd]h", "asdasd asdsa"));
+ assertTrue(rC.matches("\\basdsa", "asdasd asdsa"));
+ }
+}
Added: trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexUtilTest.java
===================================================================
--- trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexUtilTest.java (rev 0)
+++ trunk/schmitzm-regexcache/src/test/java/de/schmitzm/regex/RegexUtilTest.java 2013-02-24 19:44:23 UTC (rev 2244)
@@ -0,0 +1,53 @@
+package de.schmitzm.regex;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class RegexUtilTest {
+
+ @Test
+ public void testRemoveTags() {
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1>hallo<br/>welt</h1>"));
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1>hallo<br/>\nwelt</h1>"));
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1>hallo<td/>\n<td>welt</h1>"));
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1>hallo<td/> <td>welt</h1>"));
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1>hallo<td/> \n <td image='asdasdasa'>welt</h1>"));
+ assertEquals("hallo *asd welt",
+ RegexUtil.removeTags("<h1>hallo<td/><li>asd</li><td image='asdasdasa'>welt</h1>"));
+ assertEquals("hallo welt", RegexUtil.removeTags("<h1 time='as'>hallo<td/> \n <td image='asdasdasa'>welt</h1>"));
+
+ assertEquals("Pflanzkamp 10a 40229 Düsseldorf", RegexUtil.removeTags("Pflanzkamp+10a+40229+Düsseldorf"));
+ }
+
+ @Test
+ public void testRegExBereich() {
+ assertEquals("BAUM", RegexUtil.regExBereich("Baum", "Baum", 5));
+ assertEquals("BAUM", RegexUtil.regExBereich("Baum", "^Baum", 5));
+ assertEquals("23BAUM", RegexUtil.regExBereich("123Baum", "Baum$", 2));
+ assertEquals("12345BAUM67890", RegexUtil.regExBereich("12345Baum67890", "Baum", 5));
+ assertEquals("12345BAUM67890", RegexUtil.regExBereich("12345Baum67890", "Baum", 115));
+ assertEquals("abcBAUMdef", RegexUtil.regExBereich("abcBaumdef", "Baum", 115));
+ assertEquals("5BAUM6", RegexUtil.regExBereich("12345Baum67890", "Baum", 1));
+
+ assertEquals("er BAUM zu",
+ RegexUtil.regExBereich("Am Ender der Absperrung war ein groÃer Baum zu sehen", "Baum", 3));
+
+ }
+
+ @Test
+ public void testRegExBereich2() {
+ assertEquals("BAUM", RegexUtil.regExBereich("Baum", "Baum", 5, "^.*?", ""));
+ assertEquals("BAUM", RegexUtil.regExBereich("Baum", "^Baum", 5, "^.*?", ""));
+ assertEquals("23BAUM", RegexUtil.regExBereich("123Baum", "Baum$", 2, "^.*?", ""));
+ assertEquals("12345BAUM67890", RegexUtil.regExBereich("12345Baum67890", "Baum", 5, "^.*?", ""));
+ assertEquals("12345BAUM67890", RegexUtil.regExBereich("12345Baum67890", "Baum", 115, "^.*?", ""));
+ assertEquals("abcBAUMdef", RegexUtil.regExBereich("abcBaumdef", "Baum", 115, "^.*?", ""));
+ assertEquals("5BAUM6", RegexUtil.regExBereich("12345Baum67890", "Baum", 1, "^.*?", ""));
+
+ assertEquals("er BAUM zu",
+ RegexUtil.regExBereich("Am Ender der Absperrung war ein groÃer Baum zu sehen", "Baum", 3));
+
+ }
+
+}
More information about the Schmitzm-commits
mailing list