[jboss-svn-commits] JBL Code SVN: r25553 - in labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src: test/java/org/jboss/labs/clearspace/plugin/hfurl and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 9 09:29:16 EDT 2009
Author: lkrzyzanek
Date: 2009-03-09 09:29:16 -0400 (Mon, 09 Mar 2009)
New Revision: 25553
Added:
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
Modified:
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java
Log:
implementation of method createHFURLTitle + tests
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java 2009-03-09 13:22:49 UTC (rev 25552)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java 2009-03-09 13:29:16 UTC (rev 25553)
@@ -21,6 +21,9 @@
*/
package org.jboss.labs.clearspace.plugin.hfurl;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -44,11 +47,33 @@
* Key is DocumentID<br>
* Value is HF URL Title
*/
- private Cache<String, String> hfURLCache;
+ private Map<String, String> hfURLCache;
public String createHFURLTitle(String documentTitle) {
- // TODO Auto-generated method stub
- return null;
+ // remove white spaces
+ String hfURLTitle = documentTitle.replaceAll("[\\s]+", "-");
+ // to lower case
+ hfURLTitle = hfURLTitle.toLowerCase();
+
+ // Remove accents
+ // Java 6
+ // hfURLTitle = java.text.Normalizer.normalize(hfURLTitle,
+ // java.text.Normalizer.Form.NFD);
+
+ // Java 5
+ hfURLTitle = sun.text.Normalizer.normalize(hfURLTitle,
+ sun.text.Normalizer.DECOMP, 0);
+
+ // remove special characters
+ hfURLTitle = hfURLTitle.replaceAll("[^a-zA-Z-]+", "");
+
+ // remove more hyphen with one hyphen
+ hfURLTitle = hfURLTitle.replaceAll("[-]+", "-");
+
+ // URL Encode - not needed because all special characters are removed
+ // hfURLTitle = URLEncoder.encode(hfURLTitle, "UTF-8");
+
+ return hfURLTitle;
}
public String getDocumentID(String hfURLTitle) {
@@ -81,7 +106,7 @@
return documentID;
}
- public void setHfURLCache(Cache<String, String> hfURLCache) {
+ public void setHfURLCache(Map<String, String> hfURLCache) {
this.hfURLCache = hfURLCache;
}
Added: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java 2009-03-09 13:29:16 UTC (rev 25553)
@@ -0,0 +1,84 @@
+/*
+ * JBoss.org http://jboss.org/
+ *
+ * Copyright (c) 2009 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.clearspace.plugin.hfurl;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.jivesoftware.community.cache.Cache;
+
+/**
+ * Test of DbHFURLManager
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ *
+ */
+public class DbHFURLManagerTest {
+
+ private DbHFURLManager hfURLManager;
+
+ private Map<String, String> hfURLCache;
+
+
+
+ @Before
+ public void setupHFURLManager() {
+ hfURLManager = new DbHFURLManager();
+
+ hfURLCache = new HashMap<String, String>();
+
+ hfURLCache.put("DOC-1234", "document-with-friendly-url");
+ hfURLCache.put("DOC-2345", "document-with-friendly-url-2");
+
+ hfURLManager.setHfURLCache(hfURLCache);
+ }
+
+ /**
+ * Test method for {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#createHFURLTitle(java.lang.String)}.
+ */
+ @Test
+ public void testCreateHFURLTitle() {
+ assertEquals("document-with-friendly-url", hfURLManager.createHFURLTitle("document with friendly url"));
+ assertEquals("more-than-one-space", hfURLManager.createHFURLTitle("more than one space"));
+ assertEquals("upper-case-document-title", hfURLManager.createHFURLTitle("UPPER CASE DOCUMENT TITLE"));
+
+ assertEquals("special-characters-", hfURLManager.createHFURLTitle("special characters :!@#$%^&*()\"\"\u00a7()[]?><~\u00b1_+`"));
+ assertEquals("title-with-hyphen", hfURLManager.createHFURLTitle("title with - hyphen"));
+ assertEquals("national-characters-escrzyaiedtnescrzyaiedtn", hfURLManager.createHFURLTitle("National characters: \u011b\u0161\u010d\u0159\u017e\u00fd\u00e1\u00ed\u00e9\u010f\u0165\u0148\u011a\u0160\u010c\u0158\u017d\u00dd\u00c1\u00cd\u00c9\u010e\u0164\u0147"));
+ }
+
+ /**
+ * Test method for {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#getDocumentID(java.lang.String)}.
+ */
+ @Test
+ public void testGetDocumentID() {
+ assertEquals("DOC-1234", hfURLManager.getDocumentID("document-with-friendly-url"));
+ assertEquals("DOC-2345", hfURLManager.getDocumentID("document-with-friendly-url-2"));
+
+ assertEquals(null, hfURLManager.getDocumentID("not-existing"));
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jboss-svn-commits
mailing list