[Schmitzm-commits] r1573 - in trunk/schmitzm-core/src: main/java/de/schmitzm/io main/java/de/schmitzm/lang main/java/de/schmitzm/net/mail main/java/de/schmitzm/swing main/java/de/schmitzm/versionnumber test/java/de/schmitzm/lang test/java/de/schmitzm/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu May 5 18:19:58 CEST 2011
Author: alfonx
Date: 2011-05-05 18:19:57 +0200 (Thu, 05 May 2011)
New Revision: 1573
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java
trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedLimitedHashmapTest.java
trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java
Log:
Neue Methode in LangUtil um String von XML/HTML Tags zu s?\195?\164ubern. (HTML -> Text)
Und alle Imports Organized.
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -66,12 +66,9 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.lang.SystemUtils;
import org.apache.log4j.Logger;
-import de.schmitzm.io.FilterUtil.FilterMode;
import de.schmitzm.lang.LangUtil;
/**
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -132,74 +132,71 @@
return string.trim();
}
- /**
- * Completes an incomplete date definition (in european
- * dotted-format {@code dd.MM.yyyy}). Missing dots are also added.
- * In this case the method expects that day is given
- * with 2 digits. If month and/or year is not given, these information
- * is completed with the current month/year.<br>
- * Examples: Expect that current date is 29.03.2011, then
- * <ul>
- * <li>"12102009" is completed to "12.10.2009"</li>
- * <li>"111" is completed to "11.1.2011"</li
- * <li>"11" is completed to "11.3.2011"</li
- * <li>"12.10" is completed to "12.10.2011"</li
- * <li>"12.10." is completed to "12.10.2011"</li
- * <li>"1204" is completed to "12.04.2011"</li>
- * </ul>
- * @param dateStr a european date definition as string
- * @return the source string if the given string contains other
- * signs than digits and dots
- */
- public static String completeEuropeanDateString(String dateStr) {
- if ( dateStr == null || !dateStr.matches("[\\d\\.]+") )
- return dateStr;
-
- final Calendar CURR_DATE = new GregorianCalendar();
- final int CURR_MONTH = CURR_DATE.get(Calendar.MONTH)+1;
- final int CURR_DAY = CURR_DATE.get(Calendar.DAY_OF_MONTH);
- final int CURR_YEAR = CURR_DATE.get(Calendar.YEAR);
+ /**
+ * Completes an incomplete date definition (in european dotted-format
+ * {@code dd.MM.yyyy}). Missing dots are also added. In this case the method
+ * expects that day is given with 2 digits. If month and/or year is not
+ * given, these information is completed with the current month/year.<br>
+ * Examples: Expect that current date is 29.03.2011, then
+ * <ul>
+ * <li>"12102009" is completed to "12.10.2009"</li>
+ * <li>"111" is completed to "11.1.2011"</li
+ * <li>"11" is completed to "11.3.2011"</li
+ * <li>"12.10" is completed to "12.10.2011"</li
+ * <li>"12.10." is completed to "12.10.2011"</li
+ * <li>"1204" is completed to "12.04.2011"</li>
+ * </ul>
+ *
+ * @param dateStr
+ * a european date definition as string
+ * @return the source string if the given string contains other signs than
+ * digits and dots
+ */
+ public static String completeEuropeanDateString(String dateStr) {
+ if (dateStr == null || !dateStr.matches("[\\d\\.]+"))
+ return dateStr;
- if ( dateStr.endsWith(".") )
- dateStr = dateStr.substring(0,dateStr.length()-1);
-
- // Punkte automatisch ergaenzen (Ziffern muessen
- // 2-stellig eingegeben werden
- if ( dateStr.indexOf(".") < 0 ) {
- if ( dateStr.length() > 2 )
- dateStr = dateStr.substring(0,2) +
- "." +
- dateStr.substring(2);
- if ( dateStr.length() > 5 )
- dateStr = dateStr.substring(0,5) +
- "." +
- dateStr.substring(5);
- }
- // keine 2 Punkte vorhanden
- // -> aktuelles Jahr/Monat ergaenzen
- if ( dateStr.indexOf(".") == dateStr.lastIndexOf(".") ) {
- // kein Punkt vorhanden
- // Monat und Jahr ergaenzen
- if ( dateStr.indexOf(".") < 0 ) {
- int month = CURR_DATE.get(Calendar.MONTH)+1;
- dateStr += "." + CURR_MONTH + "." + CURR_YEAR;
- } else {
- // nur Jahr ergaenzen
- dateStr += "." + CURR_YEAR;
- }
- } else {
- // 2 Punkte vorhanden
- // --> wenn Jahr < 100 eingegeben wird, Jahr um
- // "19" erweitern
- String yearStr = dateStr.substring(dateStr.lastIndexOf(".")+1);
- if ( Integer.parseInt(yearStr) < 100 )
- dateStr = dateStr.substring(0,dateStr.lastIndexOf("."))
- + ".19" + yearStr;
-
- }
- return dateStr;
- }
+ final Calendar CURR_DATE = new GregorianCalendar();
+ final int CURR_MONTH = CURR_DATE.get(Calendar.MONTH) + 1;
+ final int CURR_DAY = CURR_DATE.get(Calendar.DAY_OF_MONTH);
+ final int CURR_YEAR = CURR_DATE.get(Calendar.YEAR);
+ if (dateStr.endsWith("."))
+ dateStr = dateStr.substring(0, dateStr.length() - 1);
+
+ // Punkte automatisch ergaenzen (Ziffern muessen
+ // 2-stellig eingegeben werden
+ if (dateStr.indexOf(".") < 0) {
+ if (dateStr.length() > 2)
+ dateStr = dateStr.substring(0, 2) + "." + dateStr.substring(2);
+ if (dateStr.length() > 5)
+ dateStr = dateStr.substring(0, 5) + "." + dateStr.substring(5);
+ }
+ // keine 2 Punkte vorhanden
+ // -> aktuelles Jahr/Monat ergaenzen
+ if (dateStr.indexOf(".") == dateStr.lastIndexOf(".")) {
+ // kein Punkt vorhanden
+ // Monat und Jahr ergaenzen
+ if (dateStr.indexOf(".") < 0) {
+ int month = CURR_DATE.get(Calendar.MONTH) + 1;
+ dateStr += "." + CURR_MONTH + "." + CURR_YEAR;
+ } else {
+ // nur Jahr ergaenzen
+ dateStr += "." + CURR_YEAR;
+ }
+ } else {
+ // 2 Punkte vorhanden
+ // --> wenn Jahr < 100 eingegeben wird, Jahr um
+ // "19" erweitern
+ String yearStr = dateStr.substring(dateStr.lastIndexOf(".") + 1);
+ if (Integer.parseInt(yearStr) < 100)
+ dateStr = dateStr.substring(0, dateStr.lastIndexOf("."))
+ + ".19" + yearStr;
+
+ }
+ return dateStr;
+ }
+
/**
* Returns the current time as formatted string.
*
@@ -1034,43 +1031,49 @@
.getName();
return className;
}
-
+
/**
- * Instantiates an object by {@link Class#forName(String)}.
- * The class must be present in runtime classpath.
- * @param className full name of class (incl. package)
- * @param fallback if <code>true</code> this method returns
- * <code>null</code> if {@link Class#forName(String)}
- * fails
- * @param constrArg arguments for the constructor
- * @exception UnsupportedOperationException if class could be
- * loaded, but no matching constructor can be found
- * @exception RuntimeException if class can not be loaded and
- * fallback is disabled or another error occurs
- * during {@link Constructor#newInstance(Object...)}
+ * Instantiates an object by {@link Class#forName(String)}. The class must
+ * be present in runtime classpath.
+ *
+ * @param className
+ * full name of class (incl. package)
+ * @param fallback
+ * if <code>true</code> this method returns <code>null</code> if
+ * {@link Class#forName(String)} fails
+ * @param constrArg
+ * arguments for the constructor
+ * @exception UnsupportedOperationException
+ * if class could be loaded, but no matching constructor can
+ * be found
+ * @exception RuntimeException
+ * if class can not be loaded and fallback is disabled or
+ * another error occurs during
+ * {@link Constructor#newInstance(Object...)}
*/
- public static Object instantiateObject(String className, boolean fallback, Object... constrArg) {
- try {
- Class<?> clazz = Class.forName(className);
- for (Constructor constructor : clazz.getConstructors())
- try {
- return constructor.newInstance(constrArg);
- } catch (IllegalArgumentException err) {
- }
- throw new UnsupportedOperationException(
- "No matching constructor found...");
- } catch (ClassNotFoundException err) {
- // if we want to fall back, we do nothing but
- // return NULL
- if ( fallback )
- return null;
- throw new RuntimeException(err);
- } catch (Exception err) {
-// LOGGER.error("Unexpected error when trying to instantiate "+className,err);
- // do not fall back, because in general the
- // the class is supported (class present)!
- throw new RuntimeException(err);
- }
+ public static Object instantiateObject(String className, boolean fallback,
+ Object... constrArg) {
+ try {
+ Class<?> clazz = Class.forName(className);
+ for (Constructor constructor : clazz.getConstructors())
+ try {
+ return constructor.newInstance(constrArg);
+ } catch (IllegalArgumentException err) {
+ }
+ throw new UnsupportedOperationException(
+ "No matching constructor found...");
+ } catch (ClassNotFoundException err) {
+ // if we want to fall back, we do nothing but
+ // return NULL
+ if (fallback)
+ return null;
+ throw new RuntimeException(err);
+ } catch (Exception err) {
+ // LOGGER.error("Unexpected error when trying to instantiate "+className,err);
+ // do not fall back, because in general the
+ // the class is supported (class present)!
+ throw new RuntimeException(err);
+ }
}
/**
@@ -1693,9 +1696,10 @@
*/
public static Number parseNumberAs(final String valueString,
final Class<?> numClass) {
-
- if (StringUtils.trimToNull(valueString) == null) return null;
+ if (StringUtils.trimToNull(valueString) == null)
+ return null;
+
// everything can be parsed as a Double
final Double doubleValue = Double.parseDouble(valueString);
@@ -1818,4 +1822,24 @@
}
return result;
}
+
+ /**
+ * 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) {
+ String withoutTags = withTags;
+
+ String re1 = "\\s*<[^>]*>\\s*";
+
+ withoutTags = withoutTags.replaceAll("<li>", "*");
+ withoutTags = withoutTags.replaceAll(re1, " ");
+ withoutTags = withoutTags.replaceAll("\\s{1,}", " ");
+
+ return withoutTags.trim();
+ }
}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -2,7 +2,6 @@
import java.awt.Desktop;
import java.awt.GraphicsEnvironment;
-import java.awt.Toolkit;
import java.net.URI;
import java.util.Date;
import java.util.Locale;
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/DateTextField.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -1,6 +1,5 @@
package de.schmitzm.swing;
-import java.awt.Font;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -9,8 +8,6 @@
import javax.swing.JFormattedTextField;
import javax.swing.text.DateFormatter;
import javax.swing.text.DefaultFormatterFactory;
-import javax.swing.text.Document;
-import javax.swing.text.PlainDocument;
import de.schmitzm.lang.LangUtil;
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -68,7 +68,6 @@
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
-import javax.swing.BorderFactory;
import javax.swing.CellEditor;
import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -3,7 +3,6 @@
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -111,4 +111,15 @@
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<td/><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>"));
+ }
+
}
\ No newline at end of file
Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedLimitedHashmapTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedLimitedHashmapTest.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/TimedLimitedHashmapTest.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -1,6 +1,8 @@
package de.schmitzm.lang;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java 2011-05-05 14:13:36 UTC (rev 1572)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/swing/FormattedTextFieldTest.java 2011-05-05 16:19:57 UTC (rev 1573)
@@ -1,19 +1,15 @@
package de.schmitzm.swing;
-import java.awt.Font;
import java.text.Format;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.swing.BoxLayout;
import javax.swing.JButton;
-import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextField;
import org.junit.Test;
-import de.schmitzm.lang.LangUtil;
import de.schmitzm.testing.TestingClass;
import de.schmitzm.testing.TestingUtil;
More information about the Schmitzm-commits
mailing list