Author: thomas.heute(a)jboss.com
Date: 2007-08-09 09:07:56 -0400 (Thu, 09 Aug 2007)
New Revision: 7883
Added:
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQuery.java
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQueryConverter.java
Log:
- Adding missing files
Added:
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQuery.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQuery.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQuery.java 2007-08-09
13:07:56 UTC (rev 7883)
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.search.impl.jcr;
+
+import org.jboss.portal.search.Query;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRQuery implements Query
+{
+ private String jcrQuery;
+
+ public JCRQuery(String jcrQuery)
+ {
+ this.jcrQuery = jcrQuery;
+ }
+
+ public String getJcrQuery()
+ {
+ return jcrQuery;
+ }
+
+ public String toString()
+ {
+ return jcrQuery;
+ }
+}
+
Added:
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQueryConverter.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQueryConverter.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/search/src/main/org/jboss/portal/search/impl/jcr/JCRQueryConverter.java 2007-08-09
13:07:56 UTC (rev 7883)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.search.impl.jcr;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.portal.search.Query;
+import org.jboss.portal.search.QueryConversionException;
+import org.jboss.portal.search.impl.AbstractQueryConverter;
+import org.jboss.portal.search.query.BooleanClause;
+import org.jboss.portal.search.query.BooleanQuery;
+import org.jboss.portal.search.query.Term;
+import org.jboss.portal.search.query.TermQuery;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class JCRQueryConverter extends AbstractQueryConverter
+{
+
+ public Query convert(Query query)
+ {
+ if (query == null)
+ {
+ return null;
+ }
+ StringBuffer result = new StringBuffer();
+ result.append("//*[");
+ try
+ {
+ result.append(((JCRQuery)super.convert(query)).getJcrQuery());
+ }
+ catch (QueryConversionException e)
+ {
+ e.printStackTrace();
+ }
+ result.append("]");
+ return new JCRQuery(result.toString());
+ }
+
+ public Query convertTermQuery(TermQuery query)
+ {
+
+ StringBuffer result = new StringBuffer();
+
+ Term term = query.getTerm();
+ result.append("jcr:contains(., '" + term.getText() +
"')");
+
+ return new JCRQuery(result.toString());
+ }
+
+ public Query convertBooleanQuery(BooleanQuery query) throws QueryConversionException
+ {
+ List clauses = query.getClauses();
+
+ StringBuffer result = new StringBuffer();
+
+ Iterator it = clauses.iterator();
+ boolean first = true;
+ while (it.hasNext())
+ {
+ BooleanClause clause = (BooleanClause)it.next();
+ if (!first)
+ {
+ result.append(", ");
+ }
+ if (!clause.isProhibited())
+ {
+ result.append(((JCRQuery)super.convert(clause.getQuery())).getJcrQuery());
+ first = false;
+ }
+ }
+ return new JCRQuery(result.toString());
+ }
+
+
+}