Author: julien_viet
Date: 2010-03-11 10:12:41 -0500 (Thu, 11 Mar 2010)
New Revision: 2172
Added:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestEscape.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestSearch.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/Utils.java
Log:
GTNPORTAL-811 : search input not triggered after pressing enter
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java 2010-03-11
15:02:35 UTC (rev 2171)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMSession.java 2010-03-11
15:12:41 UTC (rev 2172)
@@ -307,11 +307,15 @@
{
if (title != null)
{
+ title = Utils.queryEscape(title);
if (type == ObjectType.PAGE)
{
statement =
"jcr:path LIKE '" + workspaceChunk + "/" +
ownerTypeChunk + "/" + ownerIdChunk
- + "/mop:rootpage/mop:children/mop:pages/mop:children/%' AND
gtn:name='" + title + "'";
+ + "/mop:rootpage/mop:children/mop:pages/mop:children/%' AND
" +
+ "(" +
+ "LOWER(gtn:name) LIKE '%" + title + "%' OR
CONTAINS(gtn:name,'" + title + "')" +
+ ")";
}
else
{
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/Utils.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/Utils.java 2010-03-11
15:02:35 UTC (rev 2171)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/Utils.java 2010-03-11
15:12:41 UTC (rev 2172)
@@ -175,4 +175,15 @@
chunks[index] = s.substring(fromIndex, toIndex);
return chunks;
}
+
+ /**
+ * Escape the provided string for being usable as a query litteral.
+ *
+ * @param s the string to escpae
+ * @return the escaped result
+ */
+ public static String queryEscape(String s)
+ {
+ return s.replaceAll("[\\\\%_'\"]", "\\\\$0");
+ }
}
Added:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestEscape.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestEscape.java
(rev 0)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestEscape.java 2010-03-11
15:12:41 UTC (rev 2172)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.config;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+import org.exoplatform.portal.pom.config.Utils;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestEscape extends AbstractGateInTest
+{
+
+ public void testQueryEscape()
+ {
+ assertEquals("\\%", Utils.queryEscape("%"));
+ assertEquals("\\'", Utils.queryEscape("'"));
+ assertEquals("\\\"", Utils.queryEscape("\""));
+ assertEquals("\\_", Utils.queryEscape("_"));
+ assertEquals("\\\\", Utils.queryEscape("\\"));
+ }
+
+}
Added:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestSearch.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestSearch.java
(rev 0)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestSearch.java 2010-03-11
15:12:41 UTC (rev 2172)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.config;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestSearch extends AbstractPortalTest
+{
+
+ /** . */
+ private DataStorage storage;
+
+ /** . */
+ private POMSessionManager mgr;
+
+ /** . */
+ private POMSession session;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ begin();
+ PortalContainer container = PortalContainer.getInstance();
+ storage = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ mgr =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
+ session = mgr.openSession();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ session.close();
+ end();
+ super.tearDown();
+ }
+
+ private void assertFound(String searchTitle, String expectedPage) throws Exception
+ {
+ Query<Page> q = new Query<Page>(null, null, null, searchTitle,
Page.class);
+ List<Page> res = storage.find(q).getAll();
+ assertEquals(1, res.size());
+ assertEquals(expectedPage, res.get(0).getPageId());
+ }
+
+ private void assertNotFound(String searchTitle) throws Exception
+ {
+ Query<Page> q = new Query<Page>(null, null, null, searchTitle,
Page.class);
+ List<Page> res = storage.find(q).getAll();
+ assertEquals(0, res.size());
+ }
+
+ public void testFoo() throws Exception
+ {
+ Page page = new Page();
+ page.setPageId("portal::test::searchedpage");
+ page.setTitle("Juuu Ziii");
+ storage.create(page);
+ session.save();
+
+ //
+ assertFound("Juuu Ziii", "portal::test::searchedpage");
+ assertFound("Juuu", "portal::test::searchedpage");
+ assertFound("Ziii", "portal::test::searchedpage");
+ assertFound("juuu ziii", "portal::test::searchedpage");
+ assertFound("juuu", "portal::test::searchedpage");
+ assertFound("ziii", "portal::test::searchedpage");
+ assertFound("juu", "portal::test::searchedpage");
+ assertFound("zii", "portal::test::searchedpage");
+ assertFound("ju", "portal::test::searchedpage");
+ assertFound("zi", "portal::test::searchedpage");
+
+ assertNotFound("foo");
+ assertNotFound("foo bar");
+ }
+}