From: <fg...@us...> - 2009-05-08 20:56:07
|
Revision: 1191 http://openutils.svn.sourceforge.net/openutils/?rev=1191&view=rev Author: fgrilli Date: 2009-05-08 20:55:57 +0000 (Fri, 08 May 2009) Log Message: ----------- added header.txt with gplv3 license Added Paths: ----------- trunk/openutils-mgnlcriteria/src/etc/ trunk/openutils-mgnlcriteria/src/etc/header.txt Added: trunk/openutils-mgnlcriteria/src/etc/header.txt =================================================================== --- trunk/openutils-mgnlcriteria/src/etc/header.txt (rev 0) +++ trunk/openutils-mgnlcriteria/src/etc/header.txt 2009-05-08 20:55:57 UTC (rev 1191) @@ -0,0 +1,17 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ \ No newline at end of file Property changes on: trunk/openutils-mgnlcriteria/src/etc/header.txt ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-02-24 16:12:00
|
Revision: 2050 http://openutils.svn.sourceforge.net/openutils/?rev=2050&view=rev Author: fgiust Date: 2010-02-24 15:35:30 +0000 (Wed, 24 Feb 2010) Log Message: ----------- CRIT-5 support for boolean Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-02-24 15:20:12 UTC (rev 2049) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-02-24 15:35:30 UTC (rev 2050) @@ -62,22 +62,42 @@ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(); - fragment.append(" (").append(propertyName).append(getOp()); + fragment.append(" ("); if (value instanceof String) { + fragment.append(propertyName).append(getOp()); fragment.append("'" + value + "') "); } else if (value instanceof Number) { + fragment.append(propertyName).append(getOp()); fragment.append(value + ") "); } else if (value instanceof Character) { + fragment.append(propertyName).append(getOp()); fragment.append("'" + Character.toString((Character) value) + "') "); } + else if (value instanceof Boolean) + { + if ((Boolean) value) + { + fragment.append(propertyName).append(getOp()); + fragment.append(value + ") "); + } + else + { + // false should also match a missing boolean property + fragment.append("("); + fragment.append(propertyName).append(getOp()); + + fragment.append(value + ") or not(").append(propertyName + " ))"); + } + } else if (value instanceof Calendar) { + fragment.append(propertyName).append(getOp()); Calendar cal = (Calendar) value; if ("=".equals(op)) { @@ -97,11 +117,12 @@ fragment.append(XS_DATETIME_FUNCTION + "('" + date.toString() + "')) "); } } - else + else if (value != null) { - String msg = "value is not one of the accepted types String, Number, Calendar"; - log.error(msg); - throw new IllegalArgumentException(msg); + fragment.append(propertyName).append(getOp()); + + // just use the toString() of the given object + fragment.append("'" + value + "') "); } log.debug("xpathString is {} ", fragment); return fragment.toString(); Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaTest.java 2010-02-24 15:20:12 UTC (rev 2049) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaTest.java 2010-02-24 15:35:30 UTC (rev 2050) @@ -52,6 +52,23 @@ } + @Test + public void testBooleanProperty() + { + Criteria criteria = JCRCriteriaFactory.createMgnlCriteria("//site//*", null, "mgnl:content"); + + Junction conjunction = Restrictions.disjunction(); + criteria.add(conjunction); + conjunction.add(Restrictions.eq("@property", Boolean.FALSE)); + conjunction.add(Restrictions.eq("@anotherproperty", Boolean.TRUE)); + + String xpathExpression = criteria.toXpathExpression(); + Assert.assertEquals( + "//site//*[(( ((@property=false) or not(@property )) or (@anotherproperty=true) ) )] ", + xpathExpression); + + } + /** * Test for CRIT-3 */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-02-27 16:27:20
|
Revision: 2070 http://openutils.svn.sourceforge.net/openutils/?rev=2070&view=rev Author: fgiust Date: 2010-02-27 16:27:12 +0000 (Sat, 27 Feb 2010) Log Message: ----------- fix headers Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaFactory.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/ItalianSnowballAnalyzer.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/RepositoryTestNgTestcase.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; import java.util.Collection; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaFactory.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaFactory.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaFactory.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; import javax.jcr.query.Query; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; import info.magnolia.cms.core.Content; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; import info.magnolia.cms.core.HierarchyManager; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced.impl; import info.magnolia.cms.beans.config.ContentRepository; @@ -33,7 +52,7 @@ private String workspace = ContentRepository.WEBSITE; - private int pageNumberStartingFromOne; + private int pageNumberStartingFromOne = 1; private String spellCheckString; @@ -76,7 +95,7 @@ public AdvancedCriteria setPaging(int itemsPerPage, int pageNumberStartingFromOne) { this.maxResults = itemsPerPage; - this.pageNumberStartingFromOne = pageNumberStartingFromOne; + this.pageNumberStartingFromOne = Math.max(1, pageNumberStartingFromOne); this.offset = (Math.min(pageNumberStartingFromOne, 1) - 1) * maxResults; return this; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced.impl; import info.magnolia.cms.core.HierarchyManager; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced.impl; import info.magnolia.cms.core.Content; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced.impl; import info.magnolia.cms.core.HierarchyManager; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.jcr.query; import java.io.Serializable; Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.advanced; import info.magnolia.cms.beans.config.ContentRepository; Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/ItalianSnowballAnalyzer.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/ItalianSnowballAnalyzer.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/ItalianSnowballAnalyzer.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.tests; import java.io.Reader; Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/RepositoryTestNgTestcase.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/RepositoryTestNgTestcase.java 2010-02-27 15:33:02 UTC (rev 2069) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/tests/RepositoryTestNgTestcase.java 2010-02-27 16:27:12 UTC (rev 2070) @@ -1,3 +1,22 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package net.sourceforge.openutils.mgnlcriteria.tests; import info.magnolia.cms.beans.config.ContentRepository; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-03-03 23:00:07
|
Revision: 2088 http://openutils.svn.sourceforge.net/openutils/?rev=2088&view=rev Author: fgiust Date: 2010-03-03 22:59:50 +0000 (Wed, 03 Mar 2010) Log Message: ----------- CRIT-7 deep refactoring, trying to merge old and new APIs Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,55 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import java.util.Collection; - -import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; - - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedCriteria extends Criteria, ExecutableQuery -{ - - AdvancedCriteria setBasePath(String path); - - AdvancedCriteria setWorkspace(String path); - - AdvancedCriteria setSpellCheckString(String path); - - AdvancedCriteria add(Criterion criterion); - - AdvancedCriteria addOrder(Order order); - - /** - * @deprecated list() can't be used for advanced criterias, please use execute() - */ - @Deprecated - Collection< ? > list() throws JCRQueryException; - - AdvancedCriteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,76 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedResult -{ - - int getItemsPerPage(); - - int getPage(); - - int getTotalSize(); - - int getNumberOfPages(); - - String getSpellCheckerSuggestion(); - - ResultIterator<AdvancedResultItem> getItems(); - - public static AdvancedResult EMPTY_RESULT = new AdvancedResult() - { - - public int getTotalSize() - { - return 0; - } - - public String getSpellCheckerSuggestion() - { - return null; - } - - public int getPage() - { - return 0; - } - - public int getItemsPerPage() - { - return 0; - } - - public ResultIterator<AdvancedResultItem> getItems() - { - // @todo return an empty result - return null; - } - - public int getNumberOfPages() - { - return 0; - } - }; - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,39 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import info.magnolia.cms.core.Content; - - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedResultItem extends Content -{ - - String getExcerpt(); - - String getExcerpt(String selector); - - double getScore(); - - double getScore(String selector); -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,110 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import info.magnolia.cms.core.HierarchyManager; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DirectJcrQuery implements ExecutableQuery -{ - - private HierarchyManager hm; - - private String query; - - private String language; - - private String spellCheckString; - - private int maxResults; - - private int offset; - - /** - * @param hm - * @param query - * @param language - */ - public DirectJcrQuery(HierarchyManager hm, String query, String language) - { - this.hm = hm; - this.query = query; - this.language = language; - } - - /** - * Sets the spellCheckString. - * @param spellCheckString the spellCheckString to set - */ - public DirectJcrQuery setSpellCheckString(String spellCheckString) - { - this.spellCheckString = spellCheckString; - return this; - } - - /** - * Sets the maxResults. - * @param maxResults the maxResults to set - */ - public DirectJcrQuery setMaxResultsPerPage(int maxResults) - { - this.maxResults = maxResults; - return this; - } - - /** - * Sets the offset. - * @param offset the offset to set - */ - public DirectJcrQuery setOffset(int offset) - { - this.offset = offset; - return this; - } - - /** - * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults - * directly anymore. - * @param itemsPerPage - * @param pageNumberStartingFromOne - * @return - */ - public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) - { - this.maxResults = itemsPerPage; - this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedResult execute() - { - - return QueryExecutorHelper.execute(query, language, hm, maxResults, offset, spellCheckString); - } - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,30 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -/** - * @author fgiust - * @version $Id$ - */ -public interface ExecutableQuery -{ - - AdvancedResult execute(); -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,99 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import info.magnolia.cms.core.HierarchyManager; - -import javax.jcr.RangeIterator; -import javax.jcr.query.Row; -import javax.jcr.query.RowIterator; - - -/** - * @author fgiust - * @version $Id$ - */ -public abstract class ResultIterator<T> implements RangeIterator -{ - - protected RowIterator rowIterator; - - protected final HierarchyManager hm; - - /** - * @param rowIterator - */ - public ResultIterator(RowIterator rowIterator, HierarchyManager hm) - { - this.rowIterator = rowIterator; - this.hm = hm; - } - - /** - * {@inheritDoc} - */ - public boolean hasNext() - { - return rowIterator.hasNext(); - } - - /** - * {@inheritDoc} - */ - public void remove() - { - rowIterator.remove(); - } - - /** - * {@inheritDoc} - */ - public void skip(long skipNum) - { - rowIterator.skip(skipNum); - } - - /** - * {@inheritDoc} - */ - public long getSize() - { - return rowIterator.getSize(); - } - - /** - * {@inheritDoc} - */ - public long getPosition() - { - return rowIterator.getPosition(); - } - - /** - * {@inheritDoc} - */ - public T next() - { - return wrap(rowIterator.nextRow()); - } - - protected abstract T wrap(Row row); - -} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,33 +19,24 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; -import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.context.MgnlContext; import java.util.Collection; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedCriteria; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.AbstractCriteriaImpl; -import org.apache.commons.lang.StringUtils; - /** * @author fgiust * @version $Id$ */ -public class AdvancedCriteriaImpl extends AbstractCriteriaImpl implements AdvancedCriteria +public class AdvancedCriteriaImpl extends AbstractCriteriaImpl implements Criteria { - private String workspace = ContentRepository.WEBSITE; - - private String spellCheckString; - public AdvancedCriteriaImpl() { // empty @@ -54,79 +45,9 @@ /** * {@inheritDoc} */ - // @todo must be reviewd, cleaned up - public AdvancedCriteria setBasePath(String path) - { - - String finalPath = path; - if (!StringUtils.startsWith(path, Criterion.JCR_ROOT) && !StringUtils.startsWith(path, "//")) - { - finalPath = Criterion.JCR_ROOT + path; - } - if (!StringUtils.contains(finalPath, "*")) - { - finalPath = finalPath + "//*"; - } - - this.path = finalPath; - - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setWorkspace(String workspace) - { - this.workspace = workspace; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setSpellCheckString(String spellCheckString) - { - this.spellCheckString = spellCheckString; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setPaging(int itemsPerPage, int pageNumberStartingFromOne) - { - this.maxResults = itemsPerPage; - this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public AdvancedCriteria add(Criterion expression) - { - super.add(expression); - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public AdvancedCriteria addOrder(Order ordering) - { - super.addOrder(ordering); - return this; - } - - /** - * {@inheritDoc} - */ public Collection< ? > list() throws JCRQueryException { - throw new UnsupportedOperationException("list() is not supported in AdvancedCriteria, please call execute()"); + throw new UnsupportedOperationException("list() is not supported in advanced Criteria, please call execute()"); } /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -28,10 +28,10 @@ import javax.jcr.query.Row; import javax.jcr.query.RowIterator; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.advanced.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; import org.apache.jackrabbit.core.query.lucene.QueryResultImpl; import org.slf4j.Logger; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -28,7 +28,7 @@ import javax.jcr.Value; import javax.jcr.query.Row; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -26,8 +26,8 @@ import javax.jcr.query.Row; import javax.jcr.query.RowIterator; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.advanced.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; /** Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,77 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface AdvancedResult +{ + + int getItemsPerPage(); + + int getPage(); + + int getTotalSize(); + + int getNumberOfPages(); + + String getSpellCheckerSuggestion(); + + ResultIterator<AdvancedResultItem> getItems(); + + public static AdvancedResult EMPTY_RESULT = new AdvancedResult() + { + + public int getTotalSize() + { + return 0; + } + + public String getSpellCheckerSuggestion() + { + return null; + } + + public int getPage() + { + return 0; + } + + public int getItemsPerPage() + { + return 0; + } + + public ResultIterator<AdvancedResultItem> getItems() + { + // @todo return an empty result + return null; + } + + public int getNumberOfPages() + { + return 0; + } + }; + +} Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,39 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.Content; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface AdvancedResultItem extends Content +{ + + String getExcerpt(); + + String getExcerpt(String selector); + + double getScore(); + + double getScore(String selector); +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -21,7 +21,6 @@ import java.util.Collection; -import net.sourceforge.openutils.mgnlcriteria.advanced.ExecutableQuery; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; @@ -156,6 +155,14 @@ @Deprecated Collection< ? > list() throws JCRQueryException; + Criteria setBasePath(String path); + + Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); + + Criteria setSpellCheckString(String path); + + Criteria setWorkspace(String path); + /** * Returns the generated xpath expression * @return the generated xpath expression Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,110 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.HierarchyManager; +import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DirectJcrQuery implements ExecutableQuery +{ + + private HierarchyManager hm; + + private String query; + + private String language; + + private String spellCheckString; + + private int maxResults; + + private int offset; + + /** + * @param hm + * @param query + * @param language + */ + public DirectJcrQuery(HierarchyManager hm, String query, String language) + { + this.hm = hm; + this.query = query; + this.language = language; + } + + /** + * Sets the spellCheckString. + * @param spellCheckString the spellCheckString to set + */ + public DirectJcrQuery setSpellCheckString(String spellCheckString) + { + this.spellCheckString = spellCheckString; + return this; + } + + /** + * Sets the maxResults. + * @param maxResults the maxResults to set + */ + public DirectJcrQuery setMaxResultsPerPage(int maxResults) + { + this.maxResults = maxResults; + return this; + } + + /** + * Sets the offset. + * @param offset the offset to set + */ + public DirectJcrQuery setOffset(int offset) + { + this.offset = offset; + return this; + } + + /** + * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults + * directly anymore. + * @param itemsPerPage + * @param pageNumberStartingFromOne + * @return + */ + public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) + { + this.maxResults = itemsPerPage; + this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; + return this; + } + + /** + * {@inheritDoc} + */ + public AdvancedResult execute() + { + + return QueryExecutorHelper.execute(query, language, hm, maxResults, offset, spellCheckString); + } + +} Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,31 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface ExecutableQuery +{ + + AdvancedResult execute(); +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -21,8 +21,6 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.util.DeprecationUtil; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedCriteria; -import net.sourceforge.openutils.mgnlcriteria.advanced.DirectJcrQuery; import net.sourceforge.openutils.mgnlcriteria.advanced.impl.AdvancedCriteriaImpl; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.MagnoliaCriteriaImpl; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.MagnoliaCriteriaWithLimitImpl; @@ -39,7 +37,7 @@ { } - public static AdvancedCriteria createAdvancedCriteria() + public static Criteria createCriteria() { return new AdvancedCriteriaImpl(); } @@ -58,10 +56,13 @@ * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager * @param itemType String - if not specified defaults to "mgnl:content" * @return a factory for Magnolia CMS specific Criteria implementation + * @deprecated please use createCriteria() */ + @Deprecated public static Criteria createMgnlCriteria(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType) { + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaImpl(path, queryManager, itemType); } @@ -75,10 +76,13 @@ * @param itemType String - if not specified defaults to "mgnl:content" * @param clazz Class<?> - the list method of this implementation must return instances of this type * @return a factory for Magnolia CMS specific Criteria implementation + * @deprecated please use createCriteria() */ + @Deprecated public static Criteria createMgnlCriteria(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType, Class< ? > clazz) { + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaImpl(path, queryManager, itemType, clazz); } @@ -98,13 +102,13 @@ * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager * @param itemType String - if not specified defaults to "mgnl:content" * @return a factory for Magnolia CMS specific Criteria implementation - * @deprecated if you need paging/query limits please use createAdvancedCriteria() + * @deprecated please use createCriteria() */ @Deprecated public static Criteria createMgnlCriteriaWithLimit(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType) { - DeprecationUtil.isDeprecated("please use createAdvancedCriteria() instead"); + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType); } @@ -125,14 +129,14 @@ * @param itemType String - if not specified defaults to "mgnl:content" * @param clazz Class<?> - the list method of this implementation must return instances of this type * @return a factory for Magnolia CMS specific Criteria implementation - * @deprecated if you need paging/query limits please use createAdvancedCriteria() + * @deprecated please use createCriteria() */ @Deprecated public static Criteria createMgnlCriteriaWithLimit(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType, Class< ? > clazz) { - DeprecationUtil.isDeprecated("please use createAdvancedCriteria() instead"); + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType, clazz); } Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,99 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.HierarchyManager; + +import javax.jcr.RangeIterator; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; + + +/** + * @author fgiust + * @version $Id$ + */ +public abstract class ResultIterator<T> implements RangeIterator +{ + + protected RowIterator rowIterator; + + protected final HierarchyManager hm; + + /** + * @param rowIterator + */ + public ResultIterator(RowIterator rowIterator, HierarchyManager hm) + { + this.rowIterator = rowIterator; + this.hm = hm; + } + + /** + * {@inheritDoc} + */ + public boolean hasNext() + { + return rowIterator.hasNext(); + } + + /** + * {@inheritDoc} + */ + public void remove() + { + rowIterator.remove(); + } + + /** + * {@inheritDoc} + */ + public void skip(long skipNum) + { + rowIterator.skip(skipNum); + } + + /** + * {@inheritDoc} + */ + public long getSize() + { + return rowIterator.getSize(); + } + + /** + * {@inheritDoc} + */ + public long getPosition() + { + return rowIterator.getPosition(); + } + + /** + * {@inheritDoc} + */ + public T next() + { + return wrap(rowIterator.nextRow()); + } + + protected abstract T wrap(Row row); + +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -24,6 +24,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; + /** * @author fgrilli * @version $Id$ @@ -58,17 +59,20 @@ fragment.append(" (").append(propertyName).append(" >= "); if (lo instanceof String && hi instanceof String) + { fragment.append("'" + lo + "' and " + propertyName + " <= '" + hi + "'"); + } else if (lo instanceof Number && hi instanceof Number) + { fragment.append(lo + " and " + propertyName + " <= " + hi); + } else if (lo instanceof Calendar && hi instanceof Calendar) { Calendar cal = (Calendar) lo; Calendar cal2 = (Calendar) hi; StringBuilder date = new StringBuilder(); date.append(XS_DATETIME_FUNCTION + "('"); - date - .append(cal.get(Calendar.YEAR)) + date.append(cal.get(Calendar.YEAR)) .append(HYPHEN) .append( cal.get(Calendar.MONTH) < MONTH_MAX Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -25,6 +25,7 @@ */ public class Conjunction extends Junction { + private static final long serialVersionUID = 7590346442271897522L; public Conjunction() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,7 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; - import java.io.Serializable; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; @@ -41,33 +40,33 @@ public interface Criterion extends Serializable { - public static final Logger log = LoggerFactory.getLogger(Criterion.class); + Logger log = LoggerFactory.getLogger(Criterion.class); - public static final String ATTRIBUTE_SELECTOR = "@"; + String ATTRIBUTE_SELECTOR = "@"; - public static final String JCR_PREFIX = "jcr:"; + String JCR_PREFIX = "jcr:"; - public static final String JCR_ROOT = "/jcr:root"; + String JCR_ROOT = "/jcr:root"; - public static final String ALL_ELEMENTS = "//*"; + String ALL_ELEMENTS = "//*"; - public static final String ANY_PROPERTY = "."; + String ANY_PROPERTY = "."; - public static final String XS_DATETIME_FUNCTION = "xs:dateTime"; + String XS_DATETIME_FUNCTION = "xs:dateTime"; - public static final String MIDNIGHT = "T00:00:00.000+00:00"; + String MIDNIGHT = "T00:00:00.000+00:00"; - public static final String T235959 = "T23:59:59.000+00:00"; + String T235959 = "T23:59:59.000+00:00"; - public static final String NT_BASE = "nt:base"; + String NT_BASE = "nt:base"; - public static final String NOT = " not("; + String NOT = " not("; - public static final String HYPHEN = "-"; + String HYPHEN = "-"; - public static final int DAY_MAX = 10; + int DAY_MAX = 10; - public static final int MONTH_MAX = 9; + int MONTH_MAX = 9; /** * Render the XPath fragment Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -25,6 +25,7 @@ */ public class Disjunction extends Junction { + private static final long serialVersionUID = 1573336261639362776L; protected Disjunction() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -52,7 +52,9 @@ inClause.append(containsPredicate); // if this is not the last value, append an 'or' if ((i + 1) != values.length) + { inClause.append(" or "); + } } inClause.append(") "); return inClause.toString(); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -38,7 +38,9 @@ { super(propertyName, value, function); if (matchMode == null) + { throw new IllegalArgumentException("MatchMode can't be null"); + } this.matchMode = matchMode; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,11 +19,17 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl; +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.context.MgnlContext; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.TranslatableCriteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; @@ -32,6 +38,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.XPathSelect; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,8 +55,6 @@ protected String path = Criterion.JCR_ROOT; - protected String itemType; - protected Class< ? > classType; protected List<CriterionEntry> criterionEntries = new ArrayList<CriterionEntry>(); @@ -60,13 +65,21 @@ protected int offset = 0; - protected Integer timeout; + protected HierarchyManager hm; - protected String comment; + protected String spellCheckString; + protected String workspace = ContentRepository.WEBSITE; + protected AbstractCriteriaImpl() { + + } + + protected AbstractCriteriaImpl(HierarchyManager hm) + { super(); + this.hm = hm; } public Collection<CriterionEntry> getCriterionEntries() @@ -119,25 +132,37 @@ return this; } - public Integer getTimeout() + /** + * {@inheritDoc} + */ + public Criteria setBasePath(String path) { - return timeout; + this.path = StringUtils.defaultIfEmpty(path, "//*"); + return this; } - public Criteria setTimeout(int timeout) + /** + * {@inheritDoc} + */ + public Criteria setSpellCheckString(String spellCheckString) { - this.timeout = timeout; + this.spellCheckString = spellCheckString; return this; } - public String getComment() + /** + * {@inheritDoc} + */ + public Criteria setWorkspace(String workspace) { - return comment; + this.workspace = workspace; + return this; } - public Criteria setComment(String comment) + public Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne) { - this.comment = comment; + this.maxResults = itemsPerPage; + this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; return this; } @@ -155,4 +180,17 @@ return stmt; } + /** + * {@inheritDoc} + */ + public AdvancedResult execute() + { + + String language = javax.jcr.query.Query.XPATH; + String stmt = toXpathExpression(); + + return QueryExecutorHelper.execute(stmt, language, this.hm != null ? this.hm : MgnlContext + .getHierarchyManager(workspace), maxResults, offset, spellCheckString); + } + } \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -23,10 +23,7 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.search.QueryManager; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; import org.apache.commons.lang.StringUtils; @@ -38,11 +35,23 @@ public abstract class AbstractMagnoliaCriteriaImpl extends AbstractCriteriaImpl { + @Deprecated protected info.magnolia.cms.core.search.QueryManager queryManager; + @Deprecated + protected String itemType; + /** + * @param hm + */ + public AbstractMagnoliaCriteriaImpl(HierarchyManager hm) + { + super(hm); + } + + /** * Constructor to be used by subclasses - * @param path String - the path preceeding the predicate in the jcr query statement (you dont need to do escaping + * @param path String - the path preceding the predicate in the jcr query statement (you dont need to do escaping * yourself) * @param queryManager - an instance of {@link QueryManager} * @param itemType - String the itemType. Defaults to {@link ItemType#getSystemName#toString()} @@ -50,7 +59,8 @@ */ protected AbstractMagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { - super(); + + super(getPrivateHierarchyManagerFromQuery(queryManager)); if (StringUtils.isBlank(itemType)) { this.itemType = ItemType.CONTENT.getSystemName(); @@ -59,32 +69,14 @@ { this.itemType = itemType; } - this.path = XPathTextUtils.encodeDigitsInPath(path); + this.path = path; this.queryManager = queryManager; // defaults to info.magnolia.cms.core.Content this.classType = classType == null ? Content.class : classType; } - /** - * {@inheritDoc} - */ - public AdvancedResult execute() + protected static HierarchyManager getPrivateHierarchyManagerFromQuery(QueryManager queryManager) { - - String language = javax.jcr.query.Query.XPATH; - String stmt = toXpathExpression(); - - return QueryExecutorHelper.execute( - stmt, - language, - getPrivateHierarchyManagerFromQuery(stmt), - maxResults, - offset, - null); - } - - private HierarchyManager getPrivateHierarchyManagerFromQuery(String stmt) - { java.lang.reflect.Field field; try { @@ -95,9 +87,7 @@ } catch (Throwable e) { - - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); + throw new JCRQueryException("getting hierarchyManager", e); } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -20,6 +20,7 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl; import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.search.Query; import info.magnolia.cms.core.search.QueryManager; import info.magnolia.cms.core.search.QueryResult; @@ -48,17 +49,28 @@ protected static final String EXCEPTION_MSG = "An error occurred while executing a query. Xpath query was {}. Exception message is {}"; + @Deprecated public MagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType) { super(path, queryManager, itemType, null); } + @Deprecated public MagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { super(path, queryManager, itemType, classType); } + /** + * @param hm + */ + public MagnoliaCriteriaImpl(HierarchyManager hm) + { + super(hm); + } + @SuppressWarnings("unchecked") + @Deprecated public Collection< ? > list() throws JCRQueryException { DeprecationUtil.isDeprecated("please use execute() instead"); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -47,6 +47,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.JCRMagnoliaCriteriaQueryTranslator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.XPathSelect; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -64,7 +65,7 @@ * @version $Id$ */ @Deprecated -public class MagnoliaCriteriaWithLimitImpl extends AbstractMagnoliaCriteriaImpl +public class MagnoliaCriteriaWithLimitImpl extends MagnoliaCriteriaImpl { /** @@ -76,17 +77,28 @@ private static final String QUERY_MANAGER = "queryManager"; + @Deprecated public MagnoliaCriteriaWithLimitImpl(String path, QueryManager queryManager, String itemType) { super(path, queryManager, itemType, null); } + @Deprecated public MagnoliaCriteriaWithLimitImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { super(path, queryManager, itemType, classType); } + /** + * @param hm + */ + public MagnoliaCriteriaWithLimitImpl(HierarchyMan... [truncated message content] |
From: <die...@us...> - 2010-03-19 09:15:55
|
Revision: 2157 http://openutils.svn.sourceforge.net/openutils/?rev=2157&view=rev Author: diego_schivo Date: 2010-03-19 09:15:47 +0000 (Fri, 19 Mar 2010) Log Message: ----------- CRIT-9 escapeIllegalXpathSearchChars reimplemented to fix unit-tests Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-03-19 08:53:51 UTC (rev 2156) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-03-19 09:15:47 UTC (rev 2157) @@ -90,6 +90,22 @@ return str.replaceAll("'", "\""); } + private static String[] JCR_SEARCH_EXP_UNESCAPED = new String[] { + "'", + "\"", + "-", + "\\", + "?" + }; + + private static String[] JCR_SEARCH_EXP_ESCAPED = new String[] { + "\\'", + "\\\"", + "\\-", + "\\\\", + "\\?" + }; + /** * Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath queries). * The characters - and " have special meaning, and may be escaped with a backslash to obtain their literal value. @@ -107,9 +123,14 @@ // Escape ' and \ everywhere, preceding them with \ except when \ // appears // in one of the combinations \" or \- - return escapeIllegalXpathSearchChars(stringToXPathLiteral(str - .replaceAll("\\\\(?![-\"])", "\\\\\\\\") - .replaceAll("'", "\\\\'"))); + + // CRIT-9: if str=="\"milano\"" then only the trailing " is escaped, resulting in a JCRQueryException + // return escapeIllegalXpathSearchChars(stringToXPathLiteral(str + // .replaceAll("\\\\(?![-\"])", "\\\\\\\\") + // .replaceAll("'", "\\\\'"))); + + // if you change this implementation, please add unit tests + return StringUtils.replaceEach(str, JCR_SEARCH_EXP_UNESCAPED, JCR_SEARCH_EXP_ESCAPED); } /** Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java 2010-03-19 08:53:51 UTC (rev 2156) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java 2010-03-19 09:15:47 UTC (rev 2157) @@ -133,8 +133,8 @@ { String textEnteredByUser = "te?st"; Criteria criteria = criteria(textEnteredByUser, true); -// Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'te\\?st')))]", StringUtils -// .remove(criteria.toXpathExpression(), ' ')); + Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'te\\?st')))]", StringUtils + .remove(criteria.toXpathExpression(), ' ')); AdvancedResult advResult = null; try { @@ -155,9 +155,11 @@ public void testMilano() throws Exception { String textEnteredByUser = "\"Milano\""; - Criteria criteria = criteria(encode(textEnteredByUser), true); -// Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'\\\"Milano\\\"')))]", StringUtils -// .remove(criteria.toXpathExpression(), ' ')); + Criteria criteria = criteria(textEnteredByUser, true); + System.out.println("> " + criteria.toXpathExpression()); + Assert.assertEquals( + "//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'\\\"Milano\\\"')))]", + StringUtils.remove(criteria.toXpathExpression(), ' ')); AdvancedResult advResult = null; try { @@ -171,18 +173,9 @@ Assert.assertEquals(1, advResult.getTotalSize()); ResultIterator<AdvancedResultItem> items = advResult.getItems(); AdvancedResultItem item = items.next(); - Assert.assertEquals("hello \\\"Milano\\\" world", item.getTitle()); + Assert.assertEquals("hello \"Milano\" world", item.getTitle()); } - private String encode(String textEnteredByUser) - { - return StringUtils.replaceEach(textEnteredByUser, new String[]{ - "\"", "-" - }, new String[]{ - "\\\"", "\\-" - }); - } - private Criteria criteria(String titleSearch, boolean escape) { Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-03-29 20:44:24
|
Revision: 2229 http://openutils.svn.sourceforge.net/openutils/?rev=2229&view=rev Author: fgiust Date: 2010-03-29 20:44:18 +0000 (Mon, 29 Mar 2010) Log Message: ----------- CRIT-10 escape of ' and + Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-03-27 11:47:44 UTC (rev 2228) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-03-29 20:44:18 UTC (rev 2229) @@ -91,21 +91,9 @@ return str.replaceAll("'", "\""); } - private static String[] JCR_SEARCH_EXP_UNESCAPED = new String[] { - "'", - "\"", - "-", - "\\", - "?" - }; + private static String[] JCR_SEARCH_EXP_UNESCAPED = new String[]{"'", "\"", "-", "\\", "?", "+" }; - private static String[] JCR_SEARCH_EXP_ESCAPED = new String[] { - "\\'", - "\\\"", - "\\-", - "\\\\", - "\\?" - }; + private static String[] JCR_SEARCH_EXP_ESCAPED = new String[]{"''", "\\\"", "\\-", "\\\\", "\\?", "\\+" }; /** * Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath queries). Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-03-27 11:47:44 UTC (rev 2228) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-03-29 20:44:18 UTC (rev 2229) @@ -84,10 +84,12 @@ // "frappè" should not show up since "excludedproperty" is not indexed. But looks like it only works with // jackrabbit 2? - assertSortedResults( - new String[]{"Parigi (Francia)", "Parigi (Frància)", "Frància", "Tallart, Camille d'Hostun, cónte di-", "federale" }, - result, - "francia"); + assertSortedResults(new String[]{ + "Parigi (Francia)", + "Parigi (Frància)", + "Frància", + "Tallart, Camille d'Hostun, cónte di-", + "federale" }, result, "francia"); } @Test @@ -184,6 +186,42 @@ } @Test + public void testEscapeSingleQuotesForContainsRestriction() throws Exception + { + String searchText = "Milano'"; + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", searchText)); + try + { + criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Search string not properly escaped. " + e.getMessage()); + } + } + + @Test + public void testEscapePlusForContainsRestriction() throws Exception + { + String searchText = "Milano +"; + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", searchText)); + try + { + criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Search string not properly escaped. " + e.getMessage()); + } + } + + @Test public void testNotInPrivatePropertiesNoMagnoliaUser() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-04-02 11:56:15
|
Revision: 2238 http://openutils.svn.sourceforge.net/openutils/?rev=2238&view=rev Author: fgiust Date: 2010-04-02 11:56:09 +0000 (Fri, 02 Apr 2010) Log Message: ----------- escape of more invalid chars Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-03-31 20:23:49 UTC (rev 2237) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-04-02 11:56:09 UTC (rev 2238) @@ -91,10 +91,6 @@ return str.replaceAll("'", "\""); } - private static String[] JCR_SEARCH_EXP_UNESCAPED = new String[]{"'", "\"", "-", "\\", "?", "+" }; - - private static String[] JCR_SEARCH_EXP_ESCAPED = new String[]{"''", "\\\"", "\\-", "\\\\", "\\?", "\\+" }; - /** * Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath queries). * The characters - and " have special meaning, and may be escaped with a backslash to obtain their literal value. @@ -109,17 +105,36 @@ return str; } - // Escape ' and \ everywhere, preceding them with \ except when \ - // appears - // in one of the combinations \" or \- + StringBuffer sb = new StringBuffer(str.length() * 2); + for (int i = 0; i < str.length(); i++) + { + char c = str.charAt(i); + if (c == '!' + || c == '(' + || c == ')' + || c == '*' + || c == ':' + || c == '^' + || c == '[' + || c == ']' + || c == '\"' + || c == '{' + || c == '}' + || c == '?' + || c == '-' + || c == '\\' + || c == '+') + { + sb.append('\\'); + } + else if (c == '\'') + { + sb.append('\''); + } + sb.append(c); + } - // CRIT-9: if str=="\"milano\"" then only the trailing " is escaped, resulting in a JCRQueryException - // return escapeIllegalXpathSearchChars(stringToXPathLiteral(str - // .replaceAll("\\\\(?![-\"])", "\\\\\\\\") - // .replaceAll("'", "\\\\'"))); - - // if you change this implementation, please add unit tests - return StringUtils.replaceEach(str, JCR_SEARCH_EXP_UNESCAPED, JCR_SEARCH_EXP_ESCAPED); + return sb.toString(); } /** Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-03-31 20:23:49 UTC (rev 2237) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-04-02 11:56:09 UTC (rev 2238) @@ -186,6 +186,24 @@ } @Test + public void testEscapeInvalidChars() throws Exception + { + String searchText = "\"Milano(){}[]+*?^|\\/!"; + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", searchText)); + try + { + criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Search string not properly escaped. " + e.getMessage()); + } + } + + @Test public void testEscapeSingleQuotesForContainsRestriction() throws Exception { String searchText = "Milano'"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-12 16:51:35
|
Revision: 2430 http://openutils.svn.sourceforge.net/openutils/?rev=2430&view=rev Author: diego_schivo Date: 2010-05-12 16:51:27 +0000 (Wed, 12 May 2010) Log Message: ----------- CRIT-11 allow passing a simple handle to method setBasePath: query will be extended to all descendants (as base-path means) Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-12 16:10:17 UTC (rev 2429) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-12 16:51:27 UTC (rev 2430) @@ -121,7 +121,21 @@ */ public Criteria setBasePath(String path) { - this.path = StringUtils.defaultIfEmpty(path, "//*"); + if (!StringUtils.endsWith(path, "*")) + { + if (StringUtils.isEmpty(StringUtils.remove(path, '/'))) + { + this.path = "//*"; + } + else + { + this.path = "/" + StringUtils.defaultString(StringUtils.removeEnd(path, "/")) + "//*"; + } + } + else + { + this.path = path; + } return this; } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-12 16:10:17 UTC (rev 2429) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-12 16:51:27 UTC (rev 2430) @@ -78,8 +78,19 @@ } @Test - public void testSearchEntireTree() throws Exception + public void testSearchEntireTree1() throws Exception { + Collection<String> paths = searchPaths(null, "AdvancedCriteriaImpl"); + Assert.assertNotNull(paths); + Assert.assertEquals(3, paths.size()); + Assert.assertTrue(paths.contains("/Criteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); + Assert.assertTrue(paths.contains("/Criteria/AdvancedCriteriaImpl")); + Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); + } + + @Test + public void testSearchEntireTree2() throws Exception + { Collection<String> paths = searchPaths(StringUtils.EMPTY, "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); Assert.assertEquals(3, paths.size()); @@ -99,7 +110,7 @@ } @Test - public void testSearchSingleBranchDescendants() throws Exception + public void testSearchSingleBranchDescendants1() throws Exception { Collection<String> paths = searchPaths("//Criteria/TranslatableCriteria//*", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -107,6 +118,24 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + @Test + public void testSearchSingleBranchDescendants2() throws Exception + { + Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria", "AdvancedCriteriaImpl"); + Assert.assertNotNull(paths); + Assert.assertEquals(1, paths.size()); + Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); + } + + @Test + public void testSearchSingleBranchDescendants3() throws Exception + { + Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria/", "AdvancedCriteriaImpl"); + Assert.assertNotNull(paths); + Assert.assertEquals(1, paths.size()); + Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); + } + private Collection<String> searchPaths(String basePath, String title) { Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-13 06:18:06
|
Revision: 2435 http://openutils.svn.sourceforge.net/openutils/?rev=2435&view=rev Author: diego_schivo Date: 2010-05-13 06:18:00 +0000 (Thu, 13 May 2010) Log Message: ----------- CRIT-11 refactoring + javadocs Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-13 05:57:30 UTC (rev 2434) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-05-13 06:18:00 UTC (rev 2435) @@ -121,21 +121,25 @@ */ public Criteria setBasePath(String path) { - if (!StringUtils.endsWith(path, "*")) + // check if the specified path is already an xpath query + if (StringUtils.contains(path, "*")) { + this.path = path; + } + else + { + // convert the node handle to a xpath query if (StringUtils.isEmpty(StringUtils.remove(path, '/'))) { + // root node this.path = "//*"; } else { + // the handle already starts with a single '/', so prepend another one this.path = "/" + StringUtils.defaultString(StringUtils.removeEnd(path, "/")) + "//*"; } } - else - { - this.path = path; - } return this; } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-13 05:57:30 UTC (rev 2434) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-05-13 06:18:00 UTC (rev 2435) @@ -41,6 +41,7 @@ /** + * Tests criteria queries with different values of basePath parameter. * @author dschivo * @version $Id$ */ @@ -77,8 +78,12 @@ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); } + /** + * Passing a null basePath should search the entire repository. + * @throws Exception + */ @Test - public void testSearchEntireTree1() throws Exception + public void testNullBasePath() throws Exception { Collection<String> paths = searchPaths(null, "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -88,8 +93,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an empty basePath should search the entire repository. + * @throws Exception + */ @Test - public void testSearchEntireTree2() throws Exception + public void testEmptyBasePath() throws Exception { Collection<String> paths = searchPaths(StringUtils.EMPTY, "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -99,8 +108,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an xpath query ending with /* as the basePath should search the children. + * @throws Exception + */ @Test - public void testSearchSingleBranchChildren() throws Exception + public void testSearchXpathBasePathWithSingleSlash() throws Exception { Collection<String> paths = searchPaths("//Criteria/AbstractCriteriaImpl/*", StringUtils.EMPTY); Assert.assertNotNull(paths); @@ -109,8 +122,12 @@ Assert.assertTrue(paths.contains("/Criteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an xpath query ending with //* as the basePath should search the descendants. + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants1() throws Exception + public void testSearchXpathBasePathWithDoubleSlash() throws Exception { Collection<String> paths = searchPaths("//Criteria/TranslatableCriteria//*", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -118,8 +135,12 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an handle as the basePath should search the descendants. + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants2() throws Exception + public void testSearchHandleBasePath() throws Exception { Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); @@ -127,8 +148,13 @@ Assert.assertTrue(paths.contains("/Criteria/TranslatableCriteria/AbstractCriteriaImpl/AdvancedCriteriaImpl")); } + /** + * Passing an handle ending with / as the basePath should search the descendants. + * This test makes sure that the resulting xpath query does not end with ///* + * @throws Exception + */ @Test - public void testSearchSingleBranchDescendants3() throws Exception + public void testSearchHandleBasePathWithTrailingSlash() throws Exception { Collection<String> paths = searchPaths("/Criteria/TranslatableCriteria/", "AdvancedCriteriaImpl"); Assert.assertNotNull(paths); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-13 07:47:05
|
Revision: 2437 http://openutils.svn.sourceforge.net/openutils/?rev=2437&view=rev Author: diego_schivo Date: 2010-05-13 07:46:59 +0000 (Thu, 13 May 2010) Log Message: ----------- CRIT-11 CriteriaTest Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-05-13 07:17:14 UTC (rev 2436) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-05-13 07:46:59 UTC (rev 2437) @@ -31,6 +31,7 @@ /** + * Wraps the RowIterator returned by an AdvancedResult instance, adapting each Row to AdvancedResultItem. * @author fgiust * @version $Id$ */ Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-05-13 07:17:14 UTC (rev 2436) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-05-13 07:46:59 UTC (rev 2437) @@ -23,6 +23,7 @@ /** + * An extension of Content exposing additional informations obtained from a Row item of a QueryResult. * @author fgiust * @version $Id$ */ Added: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-05-13 07:46:59 UTC (rev 2437) @@ -0,0 +1,49 @@ +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + +import info.magnolia.cms.beans.config.ContentRepository; + +import java.util.Calendar; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + +import org.apache.commons.lang.StringUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + + +/** + * @author dschivo + * @version $Id$ + */ +public class CriteriaTest +{ + + @Test + public void testToXpathExpression() throws Exception + { + Calendar begin = Calendar.getInstance(); + begin.set(2004, Calendar.JANUARY, 1); + Calendar end = Calendar.getInstance(); + end.set(2008, Calendar.DECEMBER, 1); + + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/dogs") + .add(Restrictions.contains("@name", "Nana")) + .add(Restrictions.gt("@weight", Float.valueOf(10))) + .add(Restrictions.between("@birthDate", begin, end)) + .addOrder(Order.desc("@name")); + + String expectedStmt = "//dogs//*" + + "[((jcr:contains(@name, 'Nana')) and (@weight>10.0)" + + " and (@birthDate >=xs:dateTime('2004-01-01T00:00:00.000+00:00')" + + " and @birthDate <=xs:dateTime('2008-12-01T23:59:59.000+00:00')))]" + + " order by @name descending"; + String actualStmt = criteria.toXpathExpression(); + + Assert.assertEquals(StringUtils.remove(expectedStmt, ' '), StringUtils.remove(actualStmt, ' ')); + } + +} Property changes on: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-13 10:25:52
|
Revision: 2441 http://openutils.svn.sourceforge.net/openutils/?rev=2441&view=rev Author: diego_schivo Date: 2010-05-13 10:25:46 +0000 (Thu, 13 May 2010) Log Message: ----------- CRIT-11 javadocs Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-05-13 10:00:56 UTC (rev 2440) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-05-13 10:25:46 UTC (rev 2441) @@ -35,46 +35,53 @@ * * <pre> * Calendar begin = Calendar.getInstance(); - * begin.set(2004, Calendar.JANUARY, 1); + * begin.set(1999, Calendar.JANUARY, 1); * Calendar end = Calendar.getInstance(); - * end.set(2008, Calendar.DECEMBER, 1); + * end.set(2001, Calendar.DECEMBER, 31); * - * Criteria criteria = JCRCriteriaFactory - * .createCriteria() - * .setWorkspace(ContentRepository.WEBSITE) - * .setBasePath("/dogs") - * .add(Restrictions.contains("@name", "Nana")) - * .add(Restrictions.gt("@weight", Float.valueOf(10))) + * Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE) + * .setBasePath("/pets") + * .add(Restrictions.contains("@title", "Lucky")) + * .add(Restrictions.eq("@petType", "dog")) * .add(Restrictions.between("@birthDate", begin, end)) - * .addOrder(Order.desc("@name")); + * .addOrder(Order.desc("@title")); * </pre> * * will be translated into the following xpath statement * * <pre> - * //dogs//*[((jcr:contains(@name, 'Nana')) and (@weight>10.0) and (@birthDate >=xs:dateTime('2004-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2008-12-01T23:59:59.000+00:00')))] order by @name descending + * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2001-12-31T23:59:59.000+00:00')))] order by @title descending * </pre> * - * Furthermore, you may want to have only a subset of the whole result set returned, much like in - * a MySQL limit clause. In this case, you will use the <code>JCRCriteriaFactory.createMgnlCriteriaWithLimit</code> - * factory method. For this to work, the underlying JCR repository implementation must support this feature (Jackrabbit - * 1.4+ does). Here is an example. + * Furthermore, you may want to have only a subset of the whole result set returned, much like in a MySQL limit clause. + * In this case, you will use the <code>setFirstResult</code> and <code>setMaxResults</code> methods. Here is an + * example. * * <pre> - * Collection<Pet> pets = JCRCriteriaFactory.createMgnlCriteriaWithLimit("//dogs//*", MgnlContext.getQueryManager("website"), "mgnl:content", Pet.class).add( - * Restrictions.contains("@name", "Nana")).add( - * Restrictions.gt("@weight", Float.valueOf(10))).add( - * Restrictions.between("@birthDate", begin, end). - * setFirstResult(5). - * setMaxResults(10). - * addOrder(Order.desc("@name")).list(); + * Criteria criteria = JCRCriteriaFactory + * .createCriteria() + * .setWorkspace(ContentRepository.WEBSITE) + * .setBasePath("/pets") + * .add(Restrictions.between("@birthDate", begin, end)) + * .addOrder(Order.asc("@birthDate")) + * .setFirstResult(5) + * .setMaxResults(5); *</pre> * - * Notice the <code>setFirstResult(int)</code> and <code>setMaxResults(int)</code> methods. Now calling - * <code>list()</code> will return a subset of only five <code>Pet</code> objects, starting from the 6th item (counting - * starts from 0). If you dont specify these two calls, <code>list()</code> will behave as usual by returning the entire - * result set. If you only call <code>setMaxResults(int)</code>, the result set will be the subset of elements - * <code>[0, maxResults]</code> (firstResultValue is 0 by default). <br> + * Notice the <code>setFirstResult(int)</code> and <code>setMaxResults(int)</code> methods. Now executing the query will + * return a subset of no more than five results, starting from the 6th item (counting starts from 0). If you dont + * specify these two calls, the entire result set will be returned. If you only call <code>setMaxResults(int)</code>, + * the result set will be the subset of elements <code>[0, maxResults]</code> (firstResultValue is 0 by default).<br> + * Another way to paginate results is by using the <code>setPaging</code> method: + * + * <pre> + * Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE) + * .setBasePath("/pets") + * .add(Restrictions.between("@birthDate", begin, end)) + * .addOrder(Order.asc("@birthDate")) + * .setPaging(5, 2); + *</pre> + * * <br> * A word of warning about implementations returned by <code>JCRCriteriaFactory</code>. They are <strong>NOT</strong> * thread-safe, therefore client code wishing to use one of them as a shared global variable <strong>MUST</strong> @@ -142,7 +149,6 @@ Criteria setBasePath(String path); /** - * * @param itemsPerPage maximum number of results per page (i.e. page size) * @param pageNumberStartingFromOne page number to retrieve (1, 2, 3, ...) * @return this (for method chaining) @@ -150,7 +156,6 @@ Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); /** - * * @param spellCheckString * @return this (for method chaining) */ Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-05-13 10:00:56 UTC (rev 2440) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-05-13 10:25:46 UTC (rev 2441) @@ -79,7 +79,7 @@ @Test public void testToXpathExpression() throws Exception { - Criteria criteria = javadocXpathExampleCriteria(); + Criteria criteria = toXpathExpressionJavadocExampleCriteria(); String expectedStmt = "//pets//*" + "[((jcr:contains(@title, 'Lucky')) and (@petType='dog')" @@ -97,7 +97,7 @@ @Test public void testExecute() throws Exception { - Criteria criteria = javadocXpathExampleCriteria(); + Criteria criteria = toXpathExpressionJavadocExampleCriteria(); AdvancedResult result = criteria.execute(); Assert.assertEquals(1, result.getTotalSize()); @@ -108,14 +108,42 @@ } /** + * @return + */ + private Criteria toXpathExpressionJavadocExampleCriteria() + { + Calendar begin = Calendar.getInstance(); + begin.set(1999, Calendar.JANUARY, 1); + Calendar end = Calendar.getInstance(); + end.set(2001, Calendar.DECEMBER, 31); + + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( + "/pets").add(Restrictions.contains("@title", "Lucky")).add(Restrictions.eq("@petType", "dog")).add( + Restrictions.between("@birthDate", begin, end)).addOrder(Order.desc("@title")); + return criteria; + } + + /** * Tests pagination of results. * @throws Exception */ @Test - public void testSetPaging() throws Exception + public void testSetFirstResultAndMaxResults() throws Exception { - Criteria criteria = javadocPaginationExampleCriteria(); + Calendar begin = Calendar.getInstance(); + begin.set(1999, Calendar.JANUARY, 1); + Calendar end = Calendar.getInstance(); + end.set(2001, Calendar.DECEMBER, 31); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.between("@birthDate", begin, end)) + .addOrder(Order.asc("@birthDate")) + .setFirstResult(5) + .setMaxResults(5); + AdvancedResult result = criteria.execute(); // first page: // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06) @@ -137,9 +165,11 @@ } /** - * @return + * Tests pagination of results. + * @throws Exception */ - private Criteria javadocXpathExampleCriteria() + @Test + public void testSetPaging() throws Exception { Calendar begin = Calendar.getInstance(); begin.set(1999, Calendar.JANUARY, 1); @@ -147,26 +177,28 @@ end.set(2001, Calendar.DECEMBER, 31); Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.contains("@title", "Lucky")).add(Restrictions.eq("@petType", "dog")).add( - Restrictions.between("@birthDate", begin, end)).addOrder(Order.desc("@title")); - return criteria; - } - - /** - * @return - */ - private Criteria javadocPaginationExampleCriteria() - { - Calendar begin = Calendar.getInstance(); - begin.set(1999, Calendar.JANUARY, 1); - Calendar end = Calendar.getInstance(); - end.set(2001, Calendar.DECEMBER, 31); - - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( "/pets").add(Restrictions.between("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")).setPaging( 5, 2); - return criteria; + + AdvancedResult result = criteria.execute(); + // first page: + // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06) + // --- 6 (title=George, petType=snake, birthDate=2000-01-20) + // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07) + // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09) + // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24) + // second page: + // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07) + // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30) + // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17) + Assert.assertEquals(8, result.getTotalSize()); + + ResultIterator<AdvancedResultItem> iterator = result.getItems(); + Assert.assertEquals(3, iterator.getSize()); + Assert.assertEquals("1", iterator.next().getName()); + Assert.assertEquals("5", iterator.next().getName()); + Assert.assertEquals("3", iterator.next().getName()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-14 15:16:28
|
Revision: 2452 http://openutils.svn.sourceforge.net/openutils/?rev=2452&view=rev Author: diego_schivo Date: 2010-05-14 15:16:21 +0000 (Fri, 14 May 2010) Log Message: ----------- CRIT-12 fix test Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-05-14 14:52:00 UTC (rev 2451) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-05-14 15:16:21 UTC (rev 2452) @@ -21,6 +21,8 @@ import info.magnolia.cms.core.HierarchyManager; +import java.util.Iterator; + import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.query.InvalidQueryException; @@ -145,6 +147,14 @@ /** * {@inheritDoc} */ + public Iterator<AdvancedResultItem> getAccessibleItems() + { + return new AdvancedResultItemAccessibleResultIterator(getItems()); + } + + /** + * {@inheritDoc} + */ public String getSpellCheckerSuggestion() { if (spellCheckerSuggestion == null && spellCheckerQuery != null) Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java 2010-05-14 15:16:21 UTC (rev 2452) @@ -0,0 +1,84 @@ +package net.sourceforge.openutils.mgnlcriteria.advanced.impl; + +import info.magnolia.cms.security.AccessDeniedException; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; + + +/** + * @author dschivo + * @version $Id$ + */ +public class AdvancedResultItemAccessibleResultIterator implements Iterator<AdvancedResultItem> +{ + + private final ResultIterator<AdvancedResultItem> resultIterator; + + private AdvancedResultItem next; + + /** + * + */ + public AdvancedResultItemAccessibleResultIterator(ResultIterator<AdvancedResultItem> resultIterator) + { + this.resultIterator = resultIterator; + } + + /** + * {@inheritDoc} + */ + public boolean hasNext() + { + if (next != null) + { + return true; + } + if (!resultIterator.hasNext()) + { + return false; + } + do + { + try + { + next = resultIterator.next(); + } + catch (RuntimeException e) + { + if (!(e.getCause() instanceof AccessDeniedException)) + { + throw e; + } + } + } + while (next == null && resultIterator.hasNext()); + return next != null; + } + + /** + * {@inheritDoc} + */ + public AdvancedResultItem next() + { + if (next == null && !hasNext()) + { + throw new NoSuchElementException(); + } + AdvancedResultItem result = next; + next = null; + return result; + } + + /** + * {@inheritDoc} + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-05-14 14:52:00 UTC (rev 2451) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-05-14 15:16:21 UTC (rev 2452) @@ -19,7 +19,9 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; +import java.util.Iterator; + /** * The result of an advanced jcr query. * @author fgiust @@ -64,6 +66,8 @@ */ ResultIterator<AdvancedResultItem> getItems(); + Iterator<AdvancedResultItem> getAccessibleItems(); + public static AdvancedResult EMPTY_RESULT = new AdvancedResult() { @@ -93,6 +97,11 @@ return null; } + public Iterator<AdvancedResultItem> getAccessibleItems() + { + return null; + }; + public int getNumberOfPages() { return 0; Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java 2010-05-14 14:52:00 UTC (rev 2451) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java 2010-05-14 15:16:21 UTC (rev 2452) @@ -31,6 +31,7 @@ import java.lang.reflect.Field; import java.util.Calendar; import java.util.Collections; +import java.util.Iterator; import javax.jcr.RepositoryException; @@ -38,7 +39,6 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; @@ -149,13 +149,15 @@ // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07) // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24) // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17) - // Assert.assertEquals(result.getTotalSize(), 3); - ResultIterator<AdvancedResultItem> iterator = result.getItems(); - // Assert.assertEquals(iterator.getSize(), 3); + Iterator<AdvancedResultItem> iterator = result.getAccessibleItems(); + Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next().getName(), "4"); + Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next().getName(), "12"); + Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next().getName(), "3"); + Assert.assertFalse(iterator.hasNext()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-17 09:37:22
|
Revision: 2458 http://openutils.svn.sourceforge.net/openutils/?rev=2458&view=rev Author: diego_schivo Date: 2010-05-17 09:37:15 +0000 (Mon, 17 May 2010) Log Message: ----------- CRIT-12 Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java 2010-05-17 09:37:15 UTC (rev 2458) @@ -0,0 +1,76 @@ +package net.sourceforge.openutils.mgnlcriteria.advanced.impl; + +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.security.AccessDeniedException; + +import java.util.NoSuchElementException; + +import javax.jcr.query.RowIterator; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; + + +/** + * @author dschivo + * @version $Id$ + */ +public class AccessibleResultItemResultIterator extends AdvancedResultItemResultIterator +{ + + private AdvancedResultItem next; + + /** + * + */ + public AccessibleResultItemResultIterator(RowIterator rowIterator, HierarchyManager hm) + { + super(rowIterator, hm); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() + { + if (next != null) + { + return true; + } + if (!super.hasNext()) + { + return false; + } + do + { + try + { + next = super.next(); + } + catch (RuntimeException e) + { + if (!(e.getCause() instanceof AccessDeniedException)) + { + throw e; + } + } + } + while (next == null && super.hasNext()); + return next != null; + } + + /** + * {@inheritDoc} + */ + @Override + public AdvancedResultItem next() + { + if (next == null && !hasNext()) + { + throw new NoSuchElementException(); + } + AdvancedResultItem result = next; + next = null; + return result; + } +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-05-17 08:34:09 UTC (rev 2457) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-05-17 09:37:15 UTC (rev 2458) @@ -21,8 +21,6 @@ import info.magnolia.cms.core.HierarchyManager; -import java.util.Iterator; - import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.query.InvalidQueryException; @@ -141,20 +139,12 @@ throw jqe; } - return new AdvancedResultItemResultIterator(rows, this.hm); + return new AccessibleResultItemResultIterator(rows, this.hm); } /** * {@inheritDoc} */ - public Iterator<AdvancedResultItem> getAccessibleItems() - { - return new AdvancedResultItemAccessibleResultIterator(getItems()); - } - - /** - * {@inheritDoc} - */ public String getSpellCheckerSuggestion() { if (spellCheckerSuggestion == null && spellCheckerQuery != null) Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java 2010-05-17 08:34:09 UTC (rev 2457) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemAccessibleResultIterator.java 2010-05-17 09:37:15 UTC (rev 2458) @@ -1,84 +0,0 @@ -package net.sourceforge.openutils.mgnlcriteria.advanced.impl; - -import info.magnolia.cms.security.AccessDeniedException; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; - - -/** - * @author dschivo - * @version $Id$ - */ -public class AdvancedResultItemAccessibleResultIterator implements Iterator<AdvancedResultItem> -{ - - private final ResultIterator<AdvancedResultItem> resultIterator; - - private AdvancedResultItem next; - - /** - * - */ - public AdvancedResultItemAccessibleResultIterator(ResultIterator<AdvancedResultItem> resultIterator) - { - this.resultIterator = resultIterator; - } - - /** - * {@inheritDoc} - */ - public boolean hasNext() - { - if (next != null) - { - return true; - } - if (!resultIterator.hasNext()) - { - return false; - } - do - { - try - { - next = resultIterator.next(); - } - catch (RuntimeException e) - { - if (!(e.getCause() instanceof AccessDeniedException)) - { - throw e; - } - } - } - while (next == null && resultIterator.hasNext()); - return next != null; - } - - /** - * {@inheritDoc} - */ - public AdvancedResultItem next() - { - if (next == null && !hasNext()) - { - throw new NoSuchElementException(); - } - AdvancedResultItem result = next; - next = null; - return result; - } - - /** - * {@inheritDoc} - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - -} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-05-17 08:34:09 UTC (rev 2457) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-05-17 09:37:15 UTC (rev 2458) @@ -66,14 +66,6 @@ */ ResultIterator<AdvancedResultItem> getItems(); - /** - * Gets an iterator over accessible results only. A simple Iterator instance instead of ResultIterator is returned, - * because the number of results is unknown (we want to keep a lazy iteration on content and not filtering nodes - * like the standard magnolia API does). - * @return - */ - Iterator<AdvancedResultItem> getAccessibleItems(); - public static AdvancedResult EMPTY_RESULT = new AdvancedResult() { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java 2010-05-17 08:34:09 UTC (rev 2457) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AclTest.java 2010-05-17 09:37:15 UTC (rev 2458) @@ -31,7 +31,6 @@ import java.lang.reflect.Field; import java.util.Calendar; import java.util.Collections; -import java.util.Iterator; import javax.jcr.RepositoryException; @@ -39,6 +38,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; @@ -168,7 +168,7 @@ // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07) // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24) // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17) - Iterator<AdvancedResultItem> iterator = result.getAccessibleItems(); + ResultIterator<AdvancedResultItem> iterator = result.getItems(); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(iterator.next().getName(), "4"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-05-28 10:34:05
|
Revision: 2582 http://openutils.svn.sourceforge.net/openutils/?rev=2582&view=rev Author: diego_schivo Date: 2010-05-28 10:33:58 +0000 (Fri, 28 May 2010) Log Message: ----------- CRIT-12 enableAcl Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/org/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclQueryImpl.java trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/test/java/org/ Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-05-28 09:31:24 UTC (rev 2581) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-05-28 10:33:58 UTC (rev 2582) @@ -21,6 +21,8 @@ import info.magnolia.cms.core.HierarchyManager; +import java.lang.reflect.Field; + import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.query.InvalidQueryException; @@ -30,7 +32,9 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; import org.apache.commons.lang.StringUtils; +import org.apache.jackrabbit.core.query.ExecutableQuery; import org.apache.jackrabbit.core.query.QueryImpl; +import org.apache.jackrabbit.core.query.lucene.AclQueryImpl; import org.apache.jackrabbit.core.query.lucene.QueryResultImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,6 +75,7 @@ jcrQueryManager = jcrSession.getWorkspace().getQueryManager(); QueryImpl query = (QueryImpl) jcrQueryManager.createQuery(stmt, language); + enableAcl(query); if (maxResults > 0) { @@ -120,4 +125,34 @@ } } + + private static void enableAcl(QueryImpl query) + { + try + { + Field queryField = QueryImpl.class.getDeclaredField("query"); + queryField.setAccessible(true); + ExecutableQuery q = (ExecutableQuery) queryField.get(query); + if (q instanceof AclQueryImpl) + { + ((AclQueryImpl) q).setAclEnabled(true); + } + } + catch (SecurityException e) + { + // TODO Auto-generated catch block + } + catch (IllegalArgumentException e) + { + // TODO Auto-generated catch block + } + catch (NoSuchFieldException e) + { + // TODO Auto-generated catch block + } + catch (IllegalAccessException e) + { + // TODO Auto-generated catch block + } + } } Added: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclQueryImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclQueryImpl.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclQueryImpl.java 2010-05-28 10:33:58 UTC (rev 2582) @@ -0,0 +1,240 @@ +package org.apache.jackrabbit.core.query.lucene; + +import info.magnolia.cms.security.AccessManager; +import info.magnolia.cms.security.Permission; +import info.magnolia.cms.util.SimpleUrlPattern; +import info.magnolia.context.MgnlContext; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import javax.jcr.RepositoryException; +import javax.jcr.query.InvalidQueryException; +import javax.jcr.query.QueryResult; + +import org.apache.commons.lang.StringUtils; +import org.apache.jackrabbit.core.ItemManager; +import org.apache.jackrabbit.core.SessionImpl; +import org.apache.jackrabbit.core.query.PropertyTypeRegistry; +import org.apache.jackrabbit.spi.Path; +import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; +import org.apache.jackrabbit.spi.commons.query.OrderQueryNode; +import org.apache.jackrabbit.spi.commons.query.QueryNodeFactory; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.BooleanClause.Occur; + + +/** + * @author dschivo + * @version $Id$ + */ +public class AclQueryImpl extends QueryImpl +{ + + private boolean aclEnabled; + + /** + * + */ + public AclQueryImpl( + SessionImpl session, + ItemManager itemMgr, + SearchIndex index, + PropertyTypeRegistry propReg, + String statement, + String language, + QueryNodeFactory factory) throws InvalidQueryException + { + super(session, itemMgr, index, propReg, statement, language, factory); + } + + /** + * Returns the aclEnabled. + * @return the aclEnabled + */ + public boolean isAclEnabled() + { + return aclEnabled; + } + + /** + * Sets the aclEnabled. + * @param aclEnabled the aclEnabled to set + */ + public void setAclEnabled(boolean aclEnabled) + { + this.aclEnabled = aclEnabled; + } + + /** + * {@inheritDoc} + */ + @Override + public QueryResult execute(long offset, long limit) throws RepositoryException + { + // build lucene query + Query query = LuceneQueryBuilder.createQuery(root, session, index.getContext().getItemStateManager(), index + .getNamespaceMappings(), index.getTextAnalyzer(), propReg, index.getSynonymProvider(), index + .getIndexFormatVersion()); + + if (aclEnabled) + { + query = applyAcl(query); + } + + OrderQueryNode orderNode = root.getOrderNode(); + + OrderQueryNode.OrderSpec[] orderSpecs; + if (orderNode != null) + { + orderSpecs = orderNode.getOrderSpecs(); + } + else + { + orderSpecs = new OrderQueryNode.OrderSpec[0]; + } + Path[] orderProperties = new Path[orderSpecs.length]; + boolean[] ascSpecs = new boolean[orderSpecs.length]; + for (int i = 0; i < orderSpecs.length; i++) + { + orderProperties[i] = orderSpecs[i].getPropertyPath(); + ascSpecs[i] = orderSpecs[i].isAscending(); + } + + return new SingleColumnQueryResult( + index, + itemMgr, + session, + session.getAccessManager(), + this, + query, + new SpellSuggestion(index.getSpellChecker(), root), + getSelectProperties(), + orderProperties, + ascSpecs, + getRespectDocumentOrder(), + offset, + limit); + } + + @SuppressWarnings("unchecked") + private Query applyAcl(Query query) throws RepositoryException + { + List aclQueries = new ArrayList(); + AccessManager accessManager = MgnlContext.getAccessManager(session.getWorkspace().getName()); + List<Permission> permissions = accessManager.getPermissionList(); + if (!permissions.isEmpty()) + { + try + { + Field patternStringField = SimpleUrlPattern.class.getDeclaredField("patternString"); + patternStringField.setAccessible(true); + for (Permission permission : permissions) + { + if (permission.getPattern() instanceof SimpleUrlPattern) + { + String pattern = (String) patternStringField.get(permission.getPattern()); + String[] tokens = StringUtils.splitPreserveAllTokens(pattern, '/'); + if (tokens.length > 2 && "".equals(tokens[0]) && "*".equals(tokens[tokens.length - 1])) + { + Query q = null; + for (int i = 1; i < tokens.length - 1; i++) + { + if (q == null) + { + q = descendantSelfAxisQuery(jackrabbitTermQuery("_:PARENT"), nameQuery(tokens[i])); + } + else + { + q = childAxisQuery(q, tokens[i]); + } + } + q = descendantSelfAxisQuery(booleanQuery(q), new MatchAllDocsQuery()); + Occur o = (permission.getPermissions() & Permission.READ) != 0 + ? Occur.MUST + : Occur.MUST_NOT; + aclQueries.add(new Object[]{ + q, o + }); + } + } + } + } + catch (SecurityException e) + { + throw new RepositoryException(e); + } + catch (IllegalArgumentException e) + { + throw new RepositoryException(e); + } + catch (NoSuchFieldException e) + { + throw new RepositoryException(e); + } + catch (IllegalAccessException e) + { + throw new RepositoryException(e); + } + } + + if (!aclQueries.isEmpty()) + { + Query[] qs = new Query[1 + aclQueries.size()]; + Occur[] os = new Occur[qs.length]; + qs[0] = query; + os[0] = Occur.MUST; + for (int i = 1; i < qs.length; i++) + { + Object[] qo = (Object[]) aclQueries.get(i - 1); + qs[i] = (Query) qo[0]; + os[i] = (Occur) qo[1]; + } + query = booleanQuery(qs, os); + } + + return query; + } + + private NameQuery nameQuery(String n) + { + return new NameQuery(NameFactoryImpl.getInstance().create("", n), index.getIndexFormatVersion(), index + .getNamespaceMappings()); + } + + private JackrabbitTermQuery jackrabbitTermQuery(String f) + { + return new JackrabbitTermQuery(new Term(f)); + } + + private BooleanQuery booleanQuery(Query... qs) + { + return booleanQuery(qs, null); + } + + private BooleanQuery booleanQuery(Query[] qs, Occur[] os) + { + BooleanQuery bq = new BooleanQuery(); + for (int i = 0; i < qs.length; i++) + { + Occur o = (os != null && i < os.length) ? os[i] : Occur.MUST; + bq.add(qs[i], o); + } + return bq; + } + + private ChildAxisQuery childAxisQuery(Query q, String n) + { + return new ChildAxisQuery(index.getContext().getItemStateManager(), q, NameFactoryImpl.getInstance().create( + "", + n), index.getIndexFormatVersion(), index.getNamespaceMappings()); + } + + private DescendantSelfAxisQuery descendantSelfAxisQuery(Query cq, Query sq) + { + return new DescendantSelfAxisQuery(cq, sq, 1); + } +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclQueryImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java 2010-05-28 10:33:58 UTC (rev 2582) @@ -0,0 +1,35 @@ +package org.apache.jackrabbit.core.query.lucene; + +import javax.jcr.query.InvalidQueryException; + +import org.apache.jackrabbit.core.ItemManager; +import org.apache.jackrabbit.core.SessionImpl; +import org.apache.jackrabbit.core.query.ExecutableQuery; + + +/** + * @author dschivo + * @version $Id$ + */ +public class AclSearchIndex extends SearchIndex +{ + + /** + * {@inheritDoc} + */ + @Override + public ExecutableQuery createExecutableQuery(SessionImpl session, ItemManager itemMgr, String statement, + String language) throws InvalidQueryException + { + QueryImpl query = new AclQueryImpl( + session, + itemMgr, + this, + getContext().getPropertyTypeRegistry(), + statement, + language, + getQueryNodeFactory()); + query.setRespectDocumentOrder(getRespectDocumentOrder()); + return query; + } +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-07-01 07:32:23
|
Revision: 2776 http://openutils.svn.sourceforge.net/openutils/?rev=2776&view=rev Author: diego_schivo Date: 2010-07-01 07:32:15 +0000 (Thu, 01 Jul 2010) Log Message: ----------- MEDIA-145 class moved Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/jackrabbit-acl-search-index-test-configuration.xml Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-07-01 07:32:15 UTC (rev 2776) @@ -0,0 +1,109 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright (C)2009 - 2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene; + +import java.lang.reflect.Field; +import java.util.List; + +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.core.SessionImpl; +import org.apache.jackrabbit.core.query.lucene.AclQueryDecorator; +import org.apache.jackrabbit.core.query.lucene.LuceneQueryBuilder; +import org.apache.jackrabbit.core.query.lucene.SearchIndex; +import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory; +import org.apache.jackrabbit.spi.commons.query.QueryNodeVisitor; +import org.apache.jackrabbit.spi.commons.query.QueryRootNode; +import org.apache.lucene.search.Query; + + +/** + * Supports magnolia security at the lucene level by encoding acl rules as constraints in the lucene query. + * @author dschivo + * @version $Id$ + */ +public class AclSearchIndex extends SearchIndex +{ + + private final AclQueryNodeFactory aclQueryNodeFactory = new AclQueryNodeFactory(VALID_SYSTEM_INDEX_NODE_TYPE_NAMES); + + /** + * {@inheritDoc} + */ + @Override + protected DefaultQueryNodeFactory getQueryNodeFactory() + { + return aclQueryNodeFactory; + } + + /** + * Builds a specialized root node of the query tree, enabling decoration of the lucene query with acl constraints. + * @author dschivo + * @version $Id$ + */ + class AclQueryNodeFactory extends DefaultQueryNodeFactory + { + + /** + * + */ + public AclQueryNodeFactory(List validJcrSystemNodeTypeNames) + { + super(validJcrSystemNodeTypeNames); + } + + /** + * {@inheritDoc} + */ + @Override + public QueryRootNode createQueryRootNode() + { + return new QueryRootNode() + { + + /** + * {@inheritDoc} + */ + @Override + public Object accept(QueryNodeVisitor visitor, Object data) throws RepositoryException + { + // the lucene query without acl constraints + Query luceneQuery = (Query) super.accept(visitor, data); + try + { + // retrieves the session + Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); + sessionField.setAccessible(true); + SessionImpl session = (SessionImpl) sessionField.get(visitor); + + // adds acl constraints + AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); + return decorator.applyAcl(luceneQuery); + } + catch (Throwable e) + { + throw new RepositoryException(e); + } + } + }; + } + } + +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java 2010-07-01 07:27:35 UTC (rev 2775) +++ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/AclSearchIndex.java 2010-07-01 07:32:15 UTC (rev 2776) @@ -1,106 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright (C)2009 - 2010, Openmind S.r.l. http://www.openmindonline.it - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.apache.jackrabbit.core.query.lucene; - -import java.lang.reflect.Field; -import java.util.List; - -import javax.jcr.RepositoryException; - -import org.apache.jackrabbit.core.SessionImpl; -import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory; -import org.apache.jackrabbit.spi.commons.query.QueryNodeVisitor; -import org.apache.jackrabbit.spi.commons.query.QueryRootNode; -import org.apache.lucene.search.Query; - - -/** - * Supports magnolia security at the lucene level by encoding acl rules as constraints in the lucene query. - * @author dschivo - * @version $Id$ - */ -public class AclSearchIndex extends SearchIndex -{ - - private final AclQueryNodeFactory aclQueryNodeFactory = new AclQueryNodeFactory(VALID_SYSTEM_INDEX_NODE_TYPE_NAMES); - - /** - * {@inheritDoc} - */ - @Override - protected DefaultQueryNodeFactory getQueryNodeFactory() - { - return aclQueryNodeFactory; - } - - /** - * Builds a specialized root node of the query tree, enabling decoration of the lucene query with acl constraints. - * @author dschivo - * @version $Id$ - */ - class AclQueryNodeFactory extends DefaultQueryNodeFactory - { - - /** - * - */ - public AclQueryNodeFactory(List validJcrSystemNodeTypeNames) - { - super(validJcrSystemNodeTypeNames); - } - - /** - * {@inheritDoc} - */ - @Override - public QueryRootNode createQueryRootNode() - { - return new QueryRootNode() - { - - /** - * {@inheritDoc} - */ - @Override - public Object accept(QueryNodeVisitor visitor, Object data) throws RepositoryException - { - // the lucene query without acl constraints - Query luceneQuery = (Query) super.accept(visitor, data); - try - { - // retrieves the session - Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); - sessionField.setAccessible(true); - SessionImpl session = (SessionImpl) sessionField.get(visitor); - - // adds acl constraints - AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); - return decorator.applyAcl(luceneQuery); - } - catch (Throwable e) - { - throw new RepositoryException(e); - } - } - }; - } - } - -} Modified: trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/jackrabbit-acl-search-index-test-configuration.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/jackrabbit-acl-search-index-test-configuration.xml 2010-07-01 07:27:35 UTC (rev 2775) +++ trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/jackrabbit-acl-search-index-test-configuration.xml 2010-07-01 07:32:15 UTC (rev 2776) @@ -19,7 +19,7 @@ <param name="loadFactor" value="0.3" /> <param name="persistent" value="false" /> </PersistenceManager> - <SearchIndex class="org.apache.jackrabbit.core.query.lucene.AclSearchIndex"> + <SearchIndex class="net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene.AclSearchIndex"> <param name="indexingConfiguration" value="${rep.home}/../../test-classes/crit-repository/indexing_configuration.xml" /> <param name="path" value="${wsp.home}/index" /> <param name="useCompoundFile" value="false" /><!-- lasciare a false solo per i tests --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-07-16 07:33:46
|
Revision: 2820 http://openutils.svn.sourceforge.net/openutils/?rev=2820&view=rev Author: diego_schivo Date: 2010-07-16 07:33:39 +0000 (Fri, 16 Jul 2010) Log Message: ----------- CRIT-15 Restrictions.betweenDates(String, Calendar, Calendar) Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-07-16 06:32:42 UTC (rev 2819) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-07-16 07:33:39 UTC (rev 2820) @@ -69,33 +69,23 @@ else if (lo instanceof Calendar && hi instanceof Calendar) { Calendar cal = (Calendar) lo; + DATE_FORMAT.setCalendar(cal); + String fmt = DATE_FORMAT.format(cal.getTime()); Calendar cal2 = (Calendar) hi; - StringBuilder date = new StringBuilder(); - date.append(XS_DATETIME_FUNCTION + "('"); - date.append(cal.get(Calendar.YEAR)) - .append(HYPHEN) - .append( - cal.get(Calendar.MONTH) < MONTH_MAX - ? "0" + (cal.get(Calendar.MONTH) + 1) - : cal.get(Calendar.MONTH) + 1) - .append(HYPHEN) - .append( - cal.get(Calendar.DAY_OF_MONTH) < DAY_MAX ? "0" + cal.get(Calendar.DAY_OF_MONTH) : cal - .get(Calendar.DAY_OF_MONTH)); - date.append(MIDNIGHT); - date.append("') "); - - StringBuilder date2 = new StringBuilder(); - date2.append(XS_DATETIME_FUNCTION + "('"); - date2.append(cal2.get(Calendar.YEAR)).append(HYPHEN).append( - cal2.get(Calendar.MONTH) < MONTH_MAX - ? "0" + (cal2.get(Calendar.MONTH) + 1) - : cal2.get(Calendar.MONTH) + 1).append(HYPHEN).append( - cal2.get(Calendar.DAY_OF_MONTH) < DAY_MAX ? "0" + cal2.get(Calendar.DAY_OF_MONTH) : cal2 - .get(Calendar.DAY_OF_MONTH)); - date2.append(T235959); - date2.append("') "); - fragment.append(date.toString() + " and " + propertyName + " <= " + date2.toString()); + DATE_FORMAT.setCalendar(cal2); + String fmt2 = DATE_FORMAT.format(cal2.getTime()); + fragment.append(XS_DATETIME_FUNCTION + + "('" + + fmt + + "+00:00" + + "') and " + + propertyName + + " <= " + + XS_DATETIME_FUNCTION + + "('" + + fmt2 + + "+00:00" + + "') "); } else { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-07-16 06:32:42 UTC (rev 2819) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-07-16 07:33:39 UTC (rev 2820) @@ -70,7 +70,7 @@ int MONTH_MAX = 9; - DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); /** * Render the XPath fragment Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-07-16 06:32:42 UTC (rev 2819) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-07-16 07:33:39 UTC (rev 2820) @@ -21,6 +21,7 @@ import java.util.Calendar; import java.util.Collection; +import java.util.TimeZone; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; @@ -37,6 +38,16 @@ public class Restrictions { + private static final Calendar MIDNIGHT_GMT; + + static { + MIDNIGHT_GMT = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + MIDNIGHT_GMT.set(Calendar.HOUR_OF_DAY, 0); + MIDNIGHT_GMT.set(Calendar.MINUTE, 0); + MIDNIGHT_GMT.set(Calendar.SECOND, 0); + MIDNIGHT_GMT.set(Calendar.MILLISECOND, 0); + } + Restrictions() { // cannot be instantiated @@ -241,6 +252,17 @@ return new BetweenExpression(nodeName, lo, hi); } + public static Criterion betweenDates(String nodeName, Calendar lo, Calendar hi) + { + Calendar lo2 = (Calendar) MIDNIGHT_GMT.clone(); + lo2.set(lo.get(Calendar.YEAR), lo.get(Calendar.MONTH), lo.get(Calendar.DAY_OF_MONTH)); + Calendar hi2 = (Calendar) MIDNIGHT_GMT.clone(); + hi2.set(hi.get(Calendar.YEAR), hi.get(Calendar.MONTH), hi.get(Calendar.DAY_OF_MONTH)); + hi2.add(Calendar.DAY_OF_YEAR, 1); + hi2.add(Calendar.MILLISECOND, -1); + return between(nodeName, lo2, hi2); + } + /** * Apply an "in" constraint to the named node * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-07-16 06:32:42 UTC (rev 2819) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-07-16 07:33:39 UTC (rev 2820) @@ -104,8 +104,9 @@ { fragment.append(propertyName).append(getOp()); Calendar cal = (Calendar) value; + DATE_FORMAT.setCalendar(cal); String fmt = DATE_FORMAT.format(cal.getTime()); - fragment.append(XS_DATETIME_FUNCTION + "('" + fmt.substring(0, 26) + ':' + fmt.substring(26) + "')) "); + fragment.append(XS_DATETIME_FUNCTION + "('" + fmt + "+00:00" + "')) "); } else if (value != null) { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-07-16 06:32:42 UTC (rev 2819) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-07-16 07:33:39 UTC (rev 2820) @@ -92,7 +92,7 @@ String expectedStmt = "//pets//*" + "[((jcr:contains(@title, 'Lucky')) and (@petType='dog')" + " and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00')" - + " and @birthDate <=xs:dateTime('2001-12-31T23:59:59.000+00:00')))]" + + " and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))]" + " order by @title descending"; String actualStmt = criteria.toXpathExpression(); Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' ')); @@ -127,7 +127,7 @@ Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( "/pets").add(Restrictions.contains("@title", "Lucky")).add(Restrictions.eq("@petType", "dog")).add( - Restrictions.between("@birthDate", begin, end)).addOrder(Order.desc("@title")); + Restrictions.betweenDates("@birthDate", begin, end)).addOrder(Order.desc("@title")); return criteria; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-07-16 07:41:28
|
Revision: 2821 http://openutils.svn.sourceforge.net/openutils/?rev=2821&view=rev Author: diego_schivo Date: 2010-07-16 07:41:22 +0000 (Fri, 16 Jul 2010) Log Message: ----------- CRIT-15 Restrictions.betweenDates(String, Calendar, Calendar) Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-07-16 07:33:39 UTC (rev 2820) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-07-16 07:41:22 UTC (rev 2821) @@ -43,14 +43,14 @@ * .setBasePath("/pets") * .add(Restrictions.contains("@title", "Lucky")) * .add(Restrictions.eq("@petType", "dog")) - * .add(Restrictions.between("@birthDate", begin, end)) + * .add(Restrictions.betweenDates("@birthDate", begin, end)) * .addOrder(Order.desc("@title")); * </pre> * * will be translated into the following xpath statement * * <pre> - * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2001-12-31T23:59:59.000+00:00')))] order by @title descending + * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))] order by @title descending * </pre> * * Furthermore, you may want to have only a subset of the whole result set returned, much like in a MySQL limit clause. @@ -62,7 +62,7 @@ * .createCriteria() * .setWorkspace(ContentRepository.WEBSITE) * .setBasePath("/pets") - * .add(Restrictions.between("@birthDate", begin, end)) + * .add(Restrictions.betweenDates("@birthDate", begin, end)) * .addOrder(Order.asc("@birthDate")) * .setFirstResult(5) * .setMaxResults(5); @@ -77,7 +77,7 @@ * <pre> * Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE) * .setBasePath("/pets") - * .add(Restrictions.between("@birthDate", begin, end)) + * .add(Restrictions.betweenDates("@birthDate", begin, end)) * .addOrder(Order.asc("@birthDate")) * .setPaging(5, 2); *</pre> Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-07-16 07:33:39 UTC (rev 2820) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-07-16 07:41:22 UTC (rev 2821) @@ -147,7 +147,7 @@ .createCriteria() .setWorkspace(ContentRepository.WEBSITE) .setBasePath("/pets") - .add(Restrictions.between("@birthDate", begin, end)) + .add(Restrictions.betweenDates("@birthDate", begin, end)) .addOrder(Order.asc("@birthDate")) .setFirstResult(5) .setMaxResults(5); @@ -185,7 +185,7 @@ end.set(2001, Calendar.DECEMBER, 31); Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.between("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")).setPaging( + "/pets").add(Restrictions.betweenDates("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")).setPaging( 5, 2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <die...@us...> - 2010-07-21 16:41:44
|
Revision: 2828 http://openutils.svn.sourceforge.net/openutils/?rev=2828&view=rev Author: diego_schivo Date: 2010-07-21 16:41:37 +0000 (Wed, 21 Jul 2010) Log Message: ----------- CRIT-16 fix unit test Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/FirstDigitEscapeTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-07-21 16:38:48 UTC (rev 2827) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-07-21 16:41:37 UTC (rev 2828) @@ -130,7 +130,7 @@ /** * @param String path to encode eg //my//path/2009//* - * @return String encoded path eg //my//path/_x32_009//* + * @return String encoded path eg //my//path/_x0032_009//* */ public static String encodeDigitsInPath(String path) { @@ -150,7 +150,7 @@ if (i > 0 && path.charAt(i - 1) == '/' && Character.isDigit(ch)) { - encodedPath.append("_x" + Integer.toHexString(ch) + "_"); + encodedPath.append("_x" + StringUtils.leftPad(Integer.toHexString(ch), 4, '0') + "_"); } else { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/FirstDigitEscapeTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/FirstDigitEscapeTest.java 2010-07-21 16:38:48 UTC (rev 2827) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/FirstDigitEscapeTest.java 2010-07-21 16:41:37 UTC (rev 2828) @@ -51,6 +51,7 @@ ResultIterator<AdvancedResultItem> resultIterator = advResult.getItems(); Assert.assertTrue(resultIterator.hasNext()); + Assert.assertEquals(resultIterator.next().getName(), "ceb55065-e6cd-451a-8ce0-7e495e7e8fbc"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-19 09:25:48
|
Revision: 2854 http://openutils.svn.sourceforge.net/openutils/?rev=2854&view=rev Author: fgiust Date: 2010-08-19 09:25:38 +0000 (Thu, 19 Aug 2010) Log Message: ----------- formatting only Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIteratorTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndexTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIterator.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -37,8 +37,7 @@ { /** - * Local variable storing the next accessible result. - * Method hasNext() fetches it, method next() resets it. + * Local variable storing the next accessible result. Method hasNext() fetches it, method next() resets it. */ private AdvancedResultItem next; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -118,8 +118,8 @@ */ public int getNumberOfPages() { - return itemsPerPage > 0 ? (int) Math.round(Math - .ceil(((float) jcrQueryResult.getTotalSize() / (float) itemsPerPage))) : 1; + return itemsPerPage > 0 ? (int) Math + .round(Math.ceil(((float) jcrQueryResult.getTotalSize() / (float) itemsPerPage))) : 1; } /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -92,9 +92,11 @@ if (StringUtils.isNotBlank(spellCheckString)) { - spellCheckerQuery = jcrQueryManager.createQuery("/jcr:root[rep:spellcheck('" - + XPathTextUtils.stringToJCRSearchExp(spellCheckString) - + "')]/(rep:spellcheck())", Query.XPATH); + spellCheckerQuery = jcrQueryManager.createQuery( + "/jcr:root[rep:spellcheck('" + + XPathTextUtils.stringToJCRSearchExp(spellCheckString) + + "')]/(rep:spellcheck())", + Query.XPATH); } return new AdvancedResultImpl( Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -19,7 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; -import java.util.Iterator; /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -19,7 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; - /** * @author fgiust * @version $Id$ Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -97,7 +97,7 @@ /** * Transforms a Row instance, adapting it to a specific type. - * @param row + * @param row * @return a transformed version */ protected abstract T wrap(Row row); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/TranslatableCriteria.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -41,7 +41,7 @@ Collection<OrderEntry> getOrderEntries(); /** - * Gets the Order entries of this Criteria instance. + * Gets the Order entries of this Criteria instance. * @return a collection of Criterion entries */ Collection<CriterionEntry> getCriterionEntries(); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -39,8 +39,9 @@ { private static final Calendar MIDNIGHT_GMT; - - static { + + static + { MIDNIGHT_GMT = Calendar.getInstance(TimeZone.getTimeZone("GMT")); MIDNIGHT_GMT.set(Calendar.HOUR_OF_DAY, 0); MIDNIGHT_GMT.set(Calendar.MINUTE, 0); @@ -66,7 +67,6 @@ } /** - * * @param nodeName * @param value * @return @@ -264,7 +264,6 @@ } /** - * * @param nodeName * @param lo * @param hi Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -35,8 +35,8 @@ import org.apache.jackrabbit.core.query.lucene.MatchAllDocsQuery; import org.apache.jackrabbit.core.query.lucene.QueryDecoratorSupport; import org.apache.jackrabbit.core.query.lucene.SearchIndex; -import org.apache.lucene.search.Query; import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.Query; /** @@ -95,9 +95,7 @@ Occur o = (permission.getPermissions() & Permission.READ) != 0 ? Occur.MUST : Occur.MUST_NOT; - aclQueries.add(new Object[]{ - q, o - }); + aclQueries.add(new Object[]{q, o }); } } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -161,7 +161,6 @@ return this; } - /** * Returns the maxResults. * @return the maxResults @@ -230,8 +229,13 @@ String language = javax.jcr.query.Query.XPATH; String stmt = toXpathExpression(); - return QueryExecutorHelper.execute(stmt, language, this.hm != null ? this.hm : MgnlContext - .getHierarchyManager(workspace), maxResults, offset, spellCheckString); + return QueryExecutorHelper.execute( + stmt, + language, + this.hm != null ? this.hm : MgnlContext.getHierarchyManager(workspace), + maxResults, + offset, + spellCheckString); } } \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -271,13 +271,15 @@ } catch (RepositoryException re) { - log.error("{} caught while iterating on query results: {}", re.getClass().getName(), re - .getMessage()); + log.error( + "{} caught while iterating on query results: {}", + re.getClass().getName(), + re.getMessage()); if (log.isDebugEnabled()) { - log.debug(re.getClass().getName() - + " caught while iterating on query results: " - + re.getMessage(), re); + log.debug( + re.getClass().getName() + " caught while iterating on query results: " + re.getMessage(), + re); } } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -20,7 +20,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils; import org.apache.commons.lang.StringUtils; -import org.apache.lucene.queryParser.QueryParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Modified: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -21,9 +21,9 @@ import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.BooleanClause.Occur; /** @@ -45,8 +45,10 @@ protected Query nameQuery(String n) { - return new NameQuery(NameFactoryImpl.getInstance().create("", n), index.getIndexFormatVersion(), index - .getNamespaceMappings()); + return new NameQuery( + NameFactoryImpl.getInstance().create("", n), + index.getIndexFormatVersion(), + index.getNamespaceMappings()); } protected Query jackrabbitTermQuery(String f) Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -149,8 +149,8 @@ } /** - * Passing an handle ending with / as the basePath should search the descendants. - * This test makes sure that the resulting xpath query does not end with ///* + * Passing an handle ending with / as the basePath should search the descendants. This test makes sure that the + * resulting xpath query does not end with ///* * @throws Exception */ @Test Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -36,9 +36,8 @@ /** - * Unit test on escaping quotation mark in jcr:contains(). - * Unescaped quotation marks are not illegal: no Exception is thrown on query execution. - * All quotation marks (not only the trailing one) should be escaped to obatain results. + * Unit test on escaping quotation mark in jcr:contains(). Unescaped quotation marks are not illegal: no Exception is + * thrown on query execution. All quotation marks (not only the trailing one) should be escaped to obatain results. * @author dschivo * @version $Id$ */ Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIteratorTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIteratorTest.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AccessibleResultItemResultIteratorTest.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -150,8 +150,12 @@ Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.between("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.between("@birthDate", begin, end)) + .addOrder(Order.asc("@birthDate")); // Query results: // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06) Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/CriteriaTest.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -125,9 +125,14 @@ Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.contains("@title", "Lucky")).add(Restrictions.eq("@petType", "dog")).add( - Restrictions.betweenDates("@birthDate", begin, end)).addOrder(Order.desc("@title")); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.contains("@title", "Lucky")) + .add(Restrictions.eq("@petType", "dog")) + .add(Restrictions.betweenDates("@birthDate", begin, end)) + .addOrder(Order.desc("@title")); return criteria; } @@ -184,10 +189,13 @@ Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.betweenDates("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")).setPaging( - 5, - 2); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.betweenDates("@birthDate", begin, end)) + .addOrder(Order.asc("@birthDate")) + .setPaging(5, 2); AdvancedResult result = criteria.execute(); // first page: Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndexTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndexTest.java 2010-08-19 09:19:37 UTC (rev 2853) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndexTest.java 2010-08-19 09:25:38 UTC (rev 2854) @@ -152,8 +152,12 @@ Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.between("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.between("@birthDate", begin, end)) + .addOrder(Order.asc("@birthDate")); // Query results: // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06) @@ -199,8 +203,12 @@ Calendar end = Calendar.getInstance(); end.set(2001, Calendar.DECEMBER, 31); - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE).setBasePath( - "/pets").add(Restrictions.between("@birthDate", begin, end)).addOrder(Order.asc("@birthDate")); + Criteria criteria = JCRCriteriaFactory + .createCriteria() + .setWorkspace(ContentRepository.WEBSITE) + .setBasePath("/pets") + .add(Restrictions.between("@birthDate", begin, end)) + .addOrder(Order.asc("@birthDate")); AdvancedResult result = criteria.execute(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-20 17:07:07
|
Revision: 2858 http://openutils.svn.sourceforge.net/openutils/?rev=2858&view=rev Author: fgiust Date: 2010-08-20 17:07:00 +0000 (Fri, 20 Aug 2010) Log Message: ----------- CRIT-17 AdvancedResult.getPage() returns 1 for page 2 Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-19 09:30:47 UTC (rev 2857) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-20 17:07:00 UTC (rev 2858) @@ -83,7 +83,7 @@ } int pageNumberStartingFromOne = 1; - if (maxResults > 0 && offset > maxResults) + if (maxResults > 0 && offset > maxResults - 1) { pageNumberStartingFromOne = (offset / maxResults) + 1; } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-08-19 09:30:47 UTC (rev 2857) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java 2010-08-20 17:07:00 UTC (rev 2858) @@ -146,6 +146,28 @@ } @Test + public void testSearchPageNumber1() throws Exception + { + AdvancedResult advResult = search("francia", 1, 1); + Assert.assertEquals(advResult.getPage(), 1); + } + + // see CRIT-17 + @Test + public void testSearchPageNumber2() throws Exception + { + AdvancedResult advResult = search("francia", 2, 1); + Assert.assertEquals(advResult.getPage(), 2); + } + + @Test + public void testSearchPageNumber3() throws Exception + { + AdvancedResult advResult = search("francia", 3, 1); + Assert.assertEquals(advResult.getPage(), 3); + } + + @Test public void testEscapeQuotesForEqRestriction() throws Exception { String title = "Tallart, Camille d'Hostun, cónte di-"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-27 10:17:26
|
Revision: 2908 http://openutils.svn.sourceforge.net/openutils/?rev=2908&view=rev Author: fgiust Date: 2010-08-27 10:17:19 +0000 (Fri, 27 Aug 2010) Log Message: ----------- CRIT-19 refactored using proxies Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/indexing_configuration.xml Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-26 14:40:18 UTC (rev 2907) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-27 10:17:19 UTC (rev 2908) @@ -20,12 +20,17 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collections; import java.util.List; import javax.jcr.RepositoryException; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + import org.apache.jackrabbit.core.SessionImpl; import org.apache.jackrabbit.core.query.lucene.LuceneQueryBuilder; import org.apache.jackrabbit.core.query.lucene.SearchIndex; @@ -35,6 +40,8 @@ import org.apache.jackrabbit.spi.commons.query.QueryNodeVisitor; import org.apache.jackrabbit.spi.commons.query.QueryRootNode; import org.apache.lucene.search.Query; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -45,30 +52,45 @@ public class AclSearchIndex extends SearchIndex { - private final AclQueryNodeFactory aclQueryNodeFactory = new AclQueryNodeFactory(Collections.unmodifiableList(Arrays - .asList(new Name[]{ - NameConstants.NT_CHILDNODEDEFINITION, - NameConstants.NT_FROZENNODE, - NameConstants.NT_NODETYPE, - NameConstants.NT_PROPERTYDEFINITION, - NameConstants.NT_VERSION, - NameConstants.NT_VERSIONEDCHILD, - NameConstants.NT_VERSIONHISTORY, - NameConstants.NT_VERSIONLABELS, - NameConstants.REP_NODETYPES, - NameConstants.REP_SYSTEM, - NameConstants.REP_VERSIONSTORAGE, - // Supertypes - NameConstants.NT_BASE, - NameConstants.MIX_REFERENCEABLE }))); + private DefaultQueryNodeFactory proxiedQueryNodeFactory; /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AclSearchIndex.class); + + public AclSearchIndex() + { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(DefaultQueryNodeFactory.class); + enhancer.setCallback(new AclMethodInterceptor()); + proxiedQueryNodeFactory = (DefaultQueryNodeFactory) enhancer.create( + new Class[]{List.class }, + new Object[]{Collections.unmodifiableList(Arrays.asList(new Name[]{ + NameConstants.NT_CHILDNODEDEFINITION, + NameConstants.NT_FROZENNODE, + NameConstants.NT_NODETYPE, + NameConstants.NT_PROPERTYDEFINITION, + NameConstants.NT_VERSION, + NameConstants.NT_VERSIONEDCHILD, + NameConstants.NT_VERSIONHISTORY, + NameConstants.NT_VERSIONLABELS, + NameConstants.REP_NODETYPES, + NameConstants.REP_SYSTEM, + NameConstants.REP_VERSIONSTORAGE, + NameConstants.NT_BASE, + NameConstants.MIX_REFERENCEABLE })) }); + + } + + /** * {@inheritDoc} */ @Override protected DefaultQueryNodeFactory getQueryNodeFactory() { - return aclQueryNodeFactory; + + return proxiedQueryNodeFactory; } /** @@ -76,52 +98,45 @@ * @author dschivo * @version $Id$ */ - class AclQueryNodeFactory extends DefaultQueryNodeFactory + class AclMethodInterceptor implements MethodInterceptor { /** - * + * {@inheritDoc} */ - @SuppressWarnings("unchecked") - public AclQueryNodeFactory(List validJcrSystemNodeTypeNames) + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { - super(validJcrSystemNodeTypeNames); - } + String name = method.getName(); - /** - * {@inheritDoc} - */ - @Override - public QueryRootNode createQueryRootNode() - { - return new QueryRootNode() + if ("createQueryRootNode".equals(name)) { + return new QueryRootNode() + { - /** - * {@inheritDoc} - */ - @Override - public Object accept(QueryNodeVisitor visitor, Object data) throws RepositoryException - { - // the lucene query without acl constraints - Query luceneQuery = (Query) super.accept(visitor, data); - try + @Override + public Object accept(QueryNodeVisitor visitor, Object data) throws RepositoryException { - // retrieves the session - Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); - sessionField.setAccessible(true); - SessionImpl session = (SessionImpl) sessionField.get(visitor); + // the lucene query without acl constraints + Query luceneQuery = (Query) super.accept(visitor, data); + try + { + // retrieves the session + Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); + sessionField.setAccessible(true); + SessionImpl session = (SessionImpl) sessionField.get(visitor); - // adds acl constraints - AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); - return decorator.applyAcl(luceneQuery); + // adds acl constraints + AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); + return decorator.applyAcl(luceneQuery); + } + catch (Throwable e) + { + throw new RepositoryException(e); + } } - catch (Throwable e) - { - throw new RepositoryException(e); - } - } - }; + }; + } + return proxy.invokeSuper(obj, args); } } Modified: trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/indexing_configuration.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/indexing_configuration.xml 2010-08-26 14:40:18 UTC (rev 2907) +++ trunk/openutils-mgnlcriteria/src/test/resources/crit-repository/indexing_configuration.xml 2010-08-27 10:17:19 UTC (rev 2908) @@ -11,7 +11,8 @@ <property boost="10" useInExcerpt="false">title</property> <property boost="1.0" useInExcerpt="true">text</property> <!-- exclude jcr:* and mgnl:* properties --> - <property isRegexp="true" nodeScopeIndex="false" useInExcerpt="false">.*:.*</property> + <property isRegexp="true" nodeScopeIndex="false" useInExcerpt="false">mgnl:.*</property> + <property isRegexp="true" nodeScopeIndex="false" useInExcerpt="false">jcr:.*</property> </index-rule> <index-rule nodeType="mgnl:content"> <property boost="10" useInExcerpt="false">title</property> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-28 13:18:52
|
Revision: 2919 http://openutils.svn.sourceforge.net/openutils/?rev=2919&view=rev Author: fgiust Date: 2010-08-28 13:18:46 +0000 (Sat, 28 Aug 2010) Log Message: ----------- better escaping of the "OR" keyword (jackrabbit bug?) Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-28 12:54:34 UTC (rev 2918) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-28 13:18:46 UTC (rev 2919) @@ -111,9 +111,7 @@ * org.apache.jackrabbit.core.query.QueryImpl.execute() * http://stackoverflow.com/questions/1311304/keyword-or-and-search-in-lucene */ - String parseString = StringUtils.trimToEmpty(str).startsWith("OR ") - ? str.replaceFirst("\\bOR\\b", "or") - : StringUtils.trimToEmpty(str); + String parseString = StringUtils.trimToEmpty(str); /* * http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters @@ -123,6 +121,11 @@ parseString = parseString.replaceAll(escapeChars, "\\\\$0"); parseString = parseString.replaceAll("\'", "\'\'"); + if (StringUtils.startsWith(parseString, "OR ")) + { + parseString = parseString.replaceFirst("\\bOR\\b", "\"OR\""); + } + return parseString; } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java 2010-08-28 12:54:34 UTC (rev 2918) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java 2010-08-28 13:18:46 UTC (rev 2919) @@ -181,28 +181,6 @@ } @Test - public void testEscapeReservedKeyword() throws Exception - { - String searchText = "OR SONO"; - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); - criteria.setBasePath(StringUtils.EMPTY); - criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); - criteria.add(Restrictions.contains("@title", searchText)); - try - { - AdvancedResult advResult = criteria.execute(); - CriteriaTestUtils.assertNumOfResults( - 1, - CriteriaTestUtils.collectCollectionFromResult(advResult), - searchText); - } - catch (JCRQueryException e) - { - Assert.fail("Search string not properly escaped. " + e.getMessage()); - } - } - - @Test public void testEscapePipes() throws Exception { String searchText = "giovanni paolo ||"; @@ -366,6 +344,42 @@ CriteriaTestUtils.assertNumOfResults(0, result, searchText); } + @Test + public void testEscapeOrKeyword() throws Exception + { + String searchText = "OR SONO"; + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", searchText)); + + Assert.assertEquals( + criteria.toXpathExpression(), + "//*[( (@jcr:primaryType='mgnl:content') and ( jcr:contains(@title, '\"OR\" SONO') ) )] "); + + AdvancedResult advResult = criteria.execute(); + CriteriaTestUtils.assertNumOfResults(1, CriteriaTestUtils.collectCollectionFromResult(advResult), searchText); + + } + + @Test + public void testEscapeAndKeyword() throws Exception + { + String searchText = "AND ME"; + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", searchText)); + + Assert.assertEquals( + criteria.toXpathExpression(), + "//*[( (@jcr:primaryType='mgnl:content') and ( jcr:contains(@title, 'AND ME') ) )] "); + + AdvancedResult advResult = criteria.execute(); + CriteriaTestUtils.assertNumOfResults(0, CriteriaTestUtils.collectCollectionFromResult(advResult), searchText); + + } + // broken in jackrabbit 2.0/2.1 @Test(enabled = false) public void testSmile() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-29 07:10:00
|
Revision: 2920 http://openutils.svn.sourceforge.net/openutils/?rev=2920&view=rev Author: fgiust Date: 2010-08-29 07:09:52 +0000 (Sun, 29 Aug 2010) Log Message: ----------- CRIT-20 workaround for https://issues.apache.org/jira/browse/JCR-2732 Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-28 13:18:46 UTC (rev 2919) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 07:09:52 UTC (rev 2920) @@ -29,7 +29,7 @@ * @author fgrilli * @version $Id$ */ -public class XPathTextUtils +public final class XPathTextUtils { private static final Logger log = LoggerFactory.getLogger(XPathTextUtils.class); @@ -45,10 +45,11 @@ * A search string like 'test?' will run into a ParseException documented in * http://issues.apache.org/jira/browse/JCR-1248 This is copied from org.apache.jackrabbit.util.Text and was put * here just to keep this API JCR implementation agnostic - * @param string the string to encode + * @param s the string to encode * @return the escaped string * @deprecated may cause JCRQueryException on search-expressions like "\"milano\"" (CRIT-9) */ + @Deprecated public static String escapeIllegalXpathSearchChars(String s) { if (StringUtils.isEmpty(s)) @@ -113,6 +114,9 @@ */ String parseString = StringUtils.trimToEmpty(str); + // workaround for https://issues.apache.org/jira/browse/JCR-2732 + parseString = StringUtils.replaceEach(parseString, new String[]{":)", ":(" }, new String[]{": )", ": (" }); + /* * http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters * http://www.javalobby.org/java/forums/t86124.html @@ -131,7 +135,7 @@ } /** - * @param String path to encode eg //my//path/2009//* + * @param path to encode eg //my//path/2009//* * @return String encoded path eg //my//path/_x0032_009//* */ public static String encodeDigitsInPath(String path) Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java 2010-08-28 13:18:46 UTC (rev 2919) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/XpathEscapeTest.java 2010-08-29 07:09:52 UTC (rev 2920) @@ -81,6 +81,9 @@ Assert.fail("Invalid query"); } Assert.assertNotNull(advResult); + + Assert.assertEquals(advResult.getFirstResult().getTitle(), title); + Collection< ? extends Content> collection = CriteriaTestUtils.collectCollectionFromResult(advResult); Assert.assertEquals(collection.size(), 1); for (Content content : collection) @@ -380,8 +383,6 @@ } - // broken in jackrabbit 2.0/2.1 - @Test(enabled = false) public void testSmile() { @@ -391,8 +392,8 @@ criteria.setBasePath(StringUtils.EMPTY); criteria.add(Restrictions.contains("@title", searchText)); - // TODO: doesn't work with jackrabbit 2, to be fixed - Assert.assertEquals(criteria.toXpathExpression(), "//*[( ( jcr:contains(@title, '\\:\\)') ) )] "); + // the space is added as a workaround + Assert.assertEquals(criteria.toXpathExpression(), "//*[( ( jcr:contains(@title, '\\: \\)') ) )] "); AdvancedResult advResult = criteria.execute(); Collection< ? extends Content> result = CriteriaTestUtils.collectCollectionFromResult(advResult); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-29 07:20:13
|
Revision: 2922 http://openutils.svn.sourceforge.net/openutils/?rev=2922&view=rev Author: fgiust Date: 2010-08-29 07:20:05 +0000 (Sun, 29 Aug 2010) Log Message: ----------- CRIT-21 + CRIT-22 and some cleanup Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Junction.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java trunk/openutils-mgnlcriteria/src/test/resources/crit-bootstrap/website.contains.xml Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -19,7 +19,11 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; +import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.security.AccessDeniedException; +import info.magnolia.content2bean.Content2BeanException; +import info.magnolia.content2bean.Content2BeanUtil; import javax.jcr.RepositoryException; import javax.jcr.Value; @@ -32,6 +36,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIteratorImpl; import org.apache.jackrabbit.core.query.lucene.QueryResultImpl; import org.slf4j.Logger; @@ -184,4 +189,62 @@ return spellCheckerSuggestion; } + /** + * {@inheritDoc} + */ + public AdvancedResultItem getFirstResult() + { + ResultIterator<AdvancedResultItem> items = getItems(); + if (items.hasNext()) + { + return items.next(); + } + return null; + } + + /** + * {@inheritDoc} + */ + public <K> ResultIterator<K> getItems(final Class<K> theclass) + { + RowIterator rows; + try + { + rows = jcrQueryResult.getRows(); + } + catch (RepositoryException e) + { + JCRQueryException jqe = new JCRQueryException(statement, e); + throw jqe; + } + + return new ResultIteratorImpl<K>(rows, hm) + { + + @SuppressWarnings("unchecked") + @Override + protected K wrap(Row row) + { + try + { + Content content = new AdvancedResultItemImpl(row, this.hm); + + return (K) Content2BeanUtil.toBean(content, true, theclass); + } + catch (AccessDeniedException e) + { + throw new RuntimeException(e); + } + catch (RepositoryException e) + { + throw new RuntimeException(e); + } + catch (Content2BeanException e) + { + throw new RuntimeException(e); + } + } + }; + } + } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -27,7 +27,7 @@ import javax.jcr.query.RowIterator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIteratorImpl; /** @@ -35,7 +35,7 @@ * @author fgiust * @version $Id$ */ -public class AdvancedResultItemResultIterator extends ResultIterator<AdvancedResultItem> +public class AdvancedResultItemResultIterator extends ResultIteratorImpl<AdvancedResultItem> { /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -19,8 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; - - /** * The result of an advanced jcr query. * @author fgiust @@ -31,43 +29,60 @@ /** * Gets the maximum number of results per page - * @return + * @return the maximum number of results per page */ int getItemsPerPage(); /** * Gets the page number (1, 2, 3...) - * @return + * @return the page number (1, 2, 3...) */ int getPage(); /** - * Gets the total number of results that would be retrieved without pagination - * @return + * Gets the total number of results that would be retrieved without pagination. Note that jackrabbit may return -1 + * if the query doesn't have a sort condition, in order to optimize execution. Always add an order by clause (e.g. + * "order by @jcr:score") if you need to get the total size. + * @return the total number of results that would be retrieved without pagination. */ int getTotalSize(); /** * Gets the total number of pages - * @return + * @return total number of pages */ int getNumberOfPages(); /** * Gets the suggestion from the spell checker - * @return + * @return the suggestion from the spell checker */ String getSpellCheckerSuggestion(); /** * Gets an iterator over the results - * @return + * @return an iterator over the results */ ResultIterator<AdvancedResultItem> getItems(); + /** + * Gets an iterator over the results, transforming objects using content2bean while iterating + * @param <K> destination class. + * @return an iterator over the results + */ + <K> ResultIterator<K> getItems(Class<K> theclass); + + /** + * Returns the fist result if available, null otherwise. + * @return the fist result if available, null otherwise. + */ + AdvancedResultItem getFirstResult(); + public static AdvancedResult EMPTY_RESULT = new AdvancedResult() { + ResultIterator<AdvancedResultItem> iterator = new EmptyResultIterator(); + public int getTotalSize() { return 0; @@ -90,14 +105,61 @@ public ResultIterator<AdvancedResultItem> getItems() { - // @todo return an empty result - return null; + return iterator; } public int getNumberOfPages() { return 0; } + + public AdvancedResultItem getFirstResult() + { + return null; + } + + public <K> ResultIterator<K> getItems(Class<K> theclass) + { + return null; + } }; + /** + * @author fgiust + * @version $Id$ + */ + static final class EmptyResultIterator implements ResultIterator<AdvancedResultItem> + { + + public void skip(long skipNum) + { + // nothing to do + } + + public long getSize() + { + return 0; + } + + public long getPosition() + { + return 0; + } + + public boolean hasNext() + { + return false; + } + + public AdvancedResultItem next() + { + return null; + } + + public void remove() + { + // nothing to do + } + } + } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -19,11 +19,7 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; -import info.magnolia.cms.core.HierarchyManager; - import javax.jcr.RangeIterator; -import javax.jcr.query.Row; -import javax.jcr.query.RowIterator; /** @@ -31,75 +27,8 @@ * @author fgiust * @version $Id$ */ -public abstract class ResultIterator<T> implements RangeIterator +public interface ResultIterator<T> extends RangeIterator { - protected RowIterator rowIterator; - - protected final HierarchyManager hm; - - /** - * @param rowIterator - */ - public ResultIterator(RowIterator rowIterator, HierarchyManager hm) - { - this.rowIterator = rowIterator; - this.hm = hm; - } - - /** - * {@inheritDoc} - */ - public boolean hasNext() - { - return rowIterator.hasNext(); - } - - /** - * {@inheritDoc} - */ - public void remove() - { - rowIterator.remove(); - } - - /** - * {@inheritDoc} - */ - public void skip(long skipNum) - { - rowIterator.skip(skipNum); - } - - /** - * {@inheritDoc} - */ - public long getSize() - { - return rowIterator.getSize(); - } - - /** - * {@inheritDoc} - */ - public long getPosition() - { - return rowIterator.getPosition(); - } - - /** - * {@inheritDoc} - */ - public T next() - { - return wrap(rowIterator.nextRow()); - } - - /** - * Transforms a Row instance, adapting it to a specific type. - * @param row - * @return a transformed version - */ - protected abstract T wrap(Row row); - + T next(); } Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -0,0 +1,109 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.HierarchyManager; + +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; + + +/** + * Wraps a RowIterator, requiring subclasses to adapt each Row to a specific type. + * @author fgiust + * @version $Id$ + */ +public abstract class ResultIteratorImpl<T> implements ResultIterator<T> +{ + + protected RowIterator rowIterator; + + protected final HierarchyManager hm; + + /** + * Local variable storing the next accessible result. Method hasNext() fetches it, method next() resets it. + */ + private AdvancedResultItem next; + + /** + * @param rowIterator + */ + public ResultIteratorImpl(RowIterator rowIterator, HierarchyManager hm) + { + this.rowIterator = rowIterator; + this.hm = hm; + } + + /** + * {@inheritDoc} + */ + public boolean hasNext() + { + return rowIterator.hasNext(); + } + + /** + * {@inheritDoc} + */ + public void remove() + { + rowIterator.remove(); + } + + /** + * {@inheritDoc} + */ + public void skip(long skipNum) + { + rowIterator.skip(skipNum); + } + + /** + * {@inheritDoc} + */ + public long getSize() + { + return rowIterator.getSize(); + } + + /** + * {@inheritDoc} + */ + public long getPosition() + { + return rowIterator.getPosition(); + } + + /** + * {@inheritDoc} + */ + public T next() + { + return wrap(rowIterator.nextRow()); + } + + /** + * Transforms a Row instance, adapting it to a specific type. + * @param row + * @return a transformed version + */ + protected abstract T wrap(Row row); + +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Junction.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Junction.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Junction.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -39,8 +39,7 @@ private static final long serialVersionUID = 4745761472724863693L; - @SuppressWarnings("unchecked") - private final List criteria = new ArrayList(); + private final List<Criterion> criteria = new ArrayList<Criterion>(); private final String op; @@ -49,7 +48,6 @@ this.op = op; } - @SuppressWarnings("unchecked") public Junction add(Criterion criterion) { criteria.add(criterion); @@ -61,7 +59,6 @@ return op; } - @SuppressWarnings("unchecked") public String toXPathString(Criteria crit) throws JCRQueryException { @@ -71,12 +68,12 @@ } StringBuilder buffer = new StringBuilder().append('('); - Iterator iter = criteria.iterator(); + Iterator<Criterion> iter = criteria.iterator(); boolean isfirst = true; while (iter.hasNext()) { - String xPathString = ((Criterion) iter.next()).toXPathString(crit); + String xPathString = (iter.next()).toXPathString(crit); if (StringUtils.isNotBlank(xPathString)) { if (!isfirst && StringUtils.isNotBlank(xPathString)) Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -32,8 +32,8 @@ { /** - * - */ + * + */ private static final long serialVersionUID = 4524284746715983618L; private final Criterion lhs; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclQueryDecorator.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -50,7 +50,7 @@ private final SessionImpl session; /** - * + * */ public AclQueryDecorator(SessionImpl session, SearchIndex index) { @@ -58,11 +58,10 @@ this.session = session; } - @SuppressWarnings("unchecked") public Query applyAcl(Query query) throws RepositoryException { // creates a lucene query for each acl rule - List aclQueries = new ArrayList(); + List<Object[]> aclQueries = new ArrayList<Object[]>(); AccessManager accessManager = MgnlContext.getAccessManager(session.getWorkspace().getName()); List<Permission> permissions = accessManager.getPermissionList(); if (!permissions.isEmpty()) @@ -127,7 +126,7 @@ os[0] = Occur.MUST; for (int i = 1; i < qs.length; i++) { - Object[] qo = (Object[]) aclQueries.get(i - 1); + Object[] qo = aclQueries.get(i - 1); qs[i] = (Query) qo[0]; os[i] = (Occur) qo[1]; } Added: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java 2010-08-29 07:20:05 UTC (rev 2922) @@ -0,0 +1,150 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlcriteria.advanced; + +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.context.MgnlContext; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; +import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; + +import org.apache.commons.lang.StringUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +/** + * @author fgiust + * @version $Id$ + */ +public class Content2BeanTest extends RepositoryTestNgTestcase +{ + + /** + * {@inheritDoc} + */ + @Override + @BeforeClass + protected void setUp() throws Exception + { + setRepositoryConfigFileName("/crit-repository/test-repositories.xml"); + setJackrabbitRepositoryConfigFileName("/crit-repository/jackrabbit-test-configuration.xml"); + + super.setUp(); + + bootstrapSingleResource("/crit-bootstrap/website.contains.xml"); + MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); + } + + @Test + public void testLoremAndIpsum() throws Exception + { + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", "lorem ipsum")); + criteria.addOrder(Order.desc("@jcr:score")); + + AdvancedResult advResult = criteria.execute(); + Assert.assertNotNull(advResult); + Assert.assertEquals(advResult.getTotalSize(), 1); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals(item.getTitle(), "lorem ipsum"); + + ResultIterator<Page> itemsTransformed = advResult.getItems(Page.class); + Assert.assertNotNull(itemsTransformed); + Page page = itemsTransformed.next(); + Assert.assertEquals(page.getTitle(), "lorem ipsum"); + Assert.assertEquals(page.getText(), "ohoh"); + Assert.assertEquals(page.getNumber(), 5); + + } + + public static class Page + { + + private String title; + + private String text; + + private int number; + + /** + * Returns the title. + * @return the title + */ + public String getTitle() + { + return title; + } + + /** + * Sets the title. + * @param title the title to set + */ + public void setTitle(String title) + { + this.title = title; + } + + /** + * Returns the text. + * @return the text + */ + public String getText() + { + return text; + } + + /** + * Sets the text. + * @param text the text to set + */ + public void setText(String text) + { + this.text = text; + } + + /** + * Returns the number. + * @return the number + */ + public int getNumber() + { + return number; + } + + /** + * Sets the number. + * @param number the number to set + */ + public void setNumber(int number) + { + this.number = number; + } + } +} Property changes on: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/test/resources/crit-bootstrap/website.contains.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/test/resources/crit-bootstrap/website.contains.xml 2010-08-29 07:16:56 UTC (rev 2921) +++ trunk/openutils-mgnlcriteria/src/test/resources/crit-bootstrap/website.contains.xml 2010-08-29 07:20:05 UTC (rev 2922) @@ -202,6 +202,12 @@ <sv:property sv:name="jcr:createdBy" sv:type="String"> <sv:value>admin</sv:value> </sv:property> + <sv:property sv:name="number" sv:type="Long"> + <sv:value>5</sv:value> + </sv:property> + <sv:property sv:name="text" sv:type="String"> + <sv:value>ohoh</sv:value> + </sv:property> <sv:property sv:name="title" sv:type="String"> <sv:value>lorem ipsum</sv:value> </sv:property> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fg...@us...> - 2010-08-29 08:58:37
|
Revision: 2923 http://openutils.svn.sourceforge.net/openutils/?rev=2923&view=rev Author: fgiust Date: 2010-08-29 08:58:29 +0000 (Sun, 29 Aug 2010) Log Message: ----------- javadocs and code cleanup Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -19,9 +19,7 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; -import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.security.AccessDeniedException; import info.magnolia.content2bean.Content2BeanException; import info.magnolia.content2bean.Content2BeanUtil; @@ -214,8 +212,7 @@ } catch (RepositoryException e) { - JCRQueryException jqe = new JCRQueryException(statement, e); - throw jqe; + throw new JCRQueryException(statement, e); } return new ResultIteratorImpl<K>(rows, hm) @@ -227,14 +224,8 @@ { try { - Content content = new AdvancedResultItemImpl(row, this.hm); - - return (K) Content2BeanUtil.toBean(content, true, theclass); + return (K) Content2BeanUtil.toBean(new AdvancedResultItemImpl(row, this.hm), true, theclass); } - catch (AccessDeniedException e) - { - throw new RuntimeException(e); - } catch (RepositoryException e) { throw new RuntimeException(e); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/MappedDefaultContent.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,6 +27,7 @@ import info.magnolia.link.LinkException; import info.magnolia.link.LinkTransformerManager; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -48,7 +49,7 @@ * @author fgiust * @version $Id$ */ -public class MappedDefaultContent extends DefaultContent +public class MappedDefaultContent extends DefaultContent implements Map<String, Object> { /** @@ -70,7 +71,7 @@ } /** - * @see java.util.Map#size() + * {@inheritDoc} */ public int size() { @@ -78,7 +79,7 @@ } /** - * @see java.util.Map#isEmpty() + * {@inheritDoc} */ public boolean isEmpty() { @@ -86,15 +87,15 @@ } /** - * @see java.util.Map#containsKey(java.lang.Object) + * {@inheritDoc} */ public boolean containsKey(Object key) { - return getNodeData((String) key).isExist() || hasProperty((String) key); + return getNodeData((String) key).isExist() || hasProperty(key); } /** - * @see java.util.Map#containsValue(java.lang.Object) + * {@inheritDoc} */ public boolean containsValue(Object value) { @@ -105,6 +106,8 @@ /** * Shortcut for Content.getNodeData(name).getString() or Content.getNodeData(name).getName(). * @see java.util.Map#get(Object) + * @param key property name + * @return property value */ public Object get(Object key) { @@ -117,16 +120,24 @@ { key = "UUID"; } - if (hasProperty((String) key)) + if (hasProperty(key)) { try { return PropertyUtils.getProperty(this, (String) key); } - catch (Exception e) + catch (IllegalAccessException e) { log.error("can't read property " + key + " from the node " + this, e); } + catch (InvocationTargetException e) + { + log.error("can't read property " + key + " from the node " + this, e); + } + catch (NoSuchMethodException e) + { + log.error("can't read property " + key + " from the node " + this, e); + } } } } @@ -187,6 +198,11 @@ return value; } + /** + * Check if there is a bean property with the given key + * @param key property name + * @return true if this is a valid javabean property + */ protected boolean hasProperty(Object key) { try @@ -200,16 +216,16 @@ } /** - * @see java.util.Map#put(java.lang.Object, java.lang.Object) + * {@inheritDoc} */ - public Object put(Object arg0, Object arg1) + public Object put(String key, Object value) { // not implemented, only get() is needed return null; } /** - * @see java.util.Map#remove(java.lang.Object) + * {@inheritDoc} */ public Object remove(Object key) { @@ -218,15 +234,15 @@ } /** - * @see java.util.Map#putAll(java.util.Map) + * {@inheritDoc} */ - public void putAll(Map t) + public void putAll(Map< ? extends String, ? extends Object> t) { // not implemented, only get() is needed } /** - * @see java.util.Map#clear() + * {@inheritDoc} */ public void clear() { @@ -234,51 +250,51 @@ } /** - * @see java.util.Map#keySet() + * {@inheritDoc} */ - public Set keySet() + public Set<String> keySet() { - Collection nodeDataCollection = getNodeDataCollection(); - Set keys = new HashSet(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Set<String> keys = new HashSet<String>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - keys.add(((NodeData) iter.next()).getName()); + keys.add(iter.next().getName()); } return keys; } /** - * @see java.util.Map#values() + * {@inheritDoc} */ - public Collection values() + public Collection<Object> values() { - Collection nodeDataCollection = getNodeDataCollection(); - Collection values = new ArrayList(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Collection<Object> values = new ArrayList<Object>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - values.add(((NodeData) iter.next()).getString()); + values.add(iter.next().getString()); } return values; } /** - * @see java.util.Map#entrySet() + * {@inheritDoc} */ - public Set entrySet() + public Set<Map.Entry<String, Object>> entrySet() { - Collection nodeDataCollection = getNodeDataCollection(); - Set keys = new HashSet(); - for (Iterator iter = nodeDataCollection.iterator(); iter.hasNext();) + Collection<NodeData> nodeDataCollection = getNodeDataCollection(); + Set<Map.Entry<String, Object>> keys = new HashSet<Map.Entry<String, Object>>(); + for (Iterator<NodeData> iter = nodeDataCollection.iterator(); iter.hasNext();) { - NodeData nd = (NodeData) iter.next(); + NodeData nd = iter.next(); final String key = nd.getName(); final String value = nd.getString(); - keys.add(new Map.Entry() + keys.add(new Map.Entry<String, Object>() { - public Object getKey() + public String getKey() { return key; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/QueryExecutorHelper.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -41,7 +41,7 @@ * @author fgiust * @version $Id$ */ -public class QueryExecutorHelper +public final class QueryExecutorHelper { /** @@ -49,6 +49,11 @@ */ private static Logger log = LoggerFactory.getLogger(QueryExecutorHelper.class); + private QueryExecutorHelper() + { + // don't instantiate + } + /** * Executes a jcr query. * @param stmt the statement of the jcr query @@ -56,8 +61,8 @@ * @param hm the HirarchyManager for obtaining the QueryManager * @param maxResults maximun number of results to retrieve * @param offset the index of the first result to retrieve (0, 1, 2, ...) - * @param spellCheckString - * @return + * @param spellCheckString the input string used for spell checking + * @return the execution result */ public static AdvancedResultImpl execute(String stmt, String language, HierarchyManager hm, int maxResults, int offset, String spellCheckString) Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -20,7 +20,8 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; /** - * The result of an advanced jcr query. + * The result of a jcr query. You can access to the actual result items using getItems(). This bean will also give you + * information about the total number of available items, the current page number, the total number of pages. * @author fgiust * @version $Id$ */ @@ -28,6 +29,11 @@ { /** + * An empty result. + */ + AdvancedResult EMPTY_RESULT = new EmptyResult(); + + /** * Gets the maximum number of results per page * @return the maximum number of results per page */ @@ -54,7 +60,8 @@ int getNumberOfPages(); /** - * Gets the suggestion from the spell checker + * Gets the suggestion from the spell checker. Note that spell checker must be configured in jackrabbit for this to + * work. See http://wiki.apache.org/jackrabbit/Search for details. * @return the suggestion from the spell checker */ String getSpellCheckerSuggestion(); @@ -68,6 +75,7 @@ /** * Gets an iterator over the results, transforming objects using content2bean while iterating * @param <K> destination class. + * @param theclass destination class. * @return an iterator over the results */ <K> ResultIterator<K> getItems(Class<K> theclass); @@ -78,10 +86,14 @@ */ AdvancedResultItem getFirstResult(); - public static AdvancedResult EMPTY_RESULT = new AdvancedResult() + /** + * @author fgiust + * @version $Id$ + */ + class EmptyResult implements AdvancedResult { - ResultIterator<AdvancedResultItem> iterator = new EmptyResultIterator(); + private ResultIterator<AdvancedResultItem> iterator = new EmptyResultIterator(); public int getTotalSize() { @@ -122,7 +134,7 @@ { return null; } - }; + } /** * @author fgiust Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -37,7 +37,8 @@ String getExcerpt(); /** - * Returns the excerpt. + * Returns the excerpt for a specific property. + * @param selector property to use for the excerpt * @return the excerpt */ String getExcerpt(String selector); @@ -49,7 +50,8 @@ double getScore(); /** - * Returns the score. + * Returns the score for a specific property. + * @param selector property to use for the score * @return the score */ double getScore(String selector); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -23,7 +23,6 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; /** @@ -38,7 +37,7 @@ * begin.set(1999, Calendar.JANUARY, 1); * Calendar end = Calendar.getInstance(); * end.set(2001, Calendar.DECEMBER, 31); - * + * * Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE) * .setBasePath("/pets") * .add(Restrictions.contains("@title", "Lucky")) @@ -50,7 +49,10 @@ * will be translated into the following xpath statement * * <pre> - * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))] order by @title descending + * //pets//*[((jcr:contains(@title, 'Lucky')) and (@petType='dog') + * and (@birthDate >=xs:dateTime('1999-01-01T00:00:00.000+00:00') + * and @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+00:00')))] + * order by @title descending * </pre> * * Furthermore, you may want to have only a subset of the whole result set returned, much like in a MySQL limit clause. @@ -91,7 +93,6 @@ * This API was inspired by Hibernate's Criteria API. <br> * <br> * @see JCRCriteriaFactory#createCriteria() - * @see Restrictions * @see Order * @author Federico Grilli * @author fgiust @@ -130,9 +131,9 @@ Criteria setFirstResult(int firstResult); /** - * Get the results. <strong>The implementation should guarantee the caller that the returned Collection is never - * null</strong> + * Method kept in 2.x only for temporary backward compatibility. Always use execute(); * @return The Collection of matched query results. + * @throws JCRQueryException query exception * @deprecated use execute() */ @Deprecated @@ -153,7 +154,8 @@ Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); /** - * @param spellCheckString + * Sets the original input string for spell checking. + * @param spellCheckString the actual input string for spell checking * @return this (for method chaining) */ Criteria setSpellCheckString(String spellCheckString); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -58,6 +58,7 @@ /** * Sets the spellCheckString. * @param spellCheckString the spellCheckString to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setSpellCheckString(String spellCheckString) { @@ -68,6 +69,7 @@ /** * Sets the maxResults. * @param maxResults the maxResults to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setMaxResultsPerPage(int maxResults) { @@ -78,6 +80,7 @@ /** * Sets the offset. * @param offset the offset to set + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setOffset(int offset) { @@ -88,9 +91,9 @@ /** * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults * directly anymore. - * @param itemsPerPage - * @param pageNumberStartingFromOne - * @return + * @param itemsPerPage number of items per page + * @param pageNumberStartingFromOne page number (starting from 1) + * @return the DirectJcrQuery instance for chaining */ public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,10 +27,13 @@ /** + * Factory for criteria queries. Since mgnlcriteria 2.x always use the simple createCriteria() factory method. * @author fgrilli + * @author fgiust + * @author diego_schivo * @version $Id$ */ -public class JCRCriteriaFactory +public final class JCRCriteriaFactory { private JCRCriteriaFactory() @@ -38,7 +41,8 @@ } /** - * Creates a query criteria for dynamic query composition. + * Creates a query criteria for dynamic query composition. All the details can be set on the Criteria instance + * returned. * @return an AdvancedCriteriaImpl */ public static Criteria createCriteria() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -24,11 +24,15 @@ /** * Wraps a RowIterator, requiring subclasses to adapt each Row to a specific type. + * @param <T> the type of results you will get from this iterator. * @author fgiust * @version $Id$ */ public interface ResultIterator<T> extends RangeIterator { + /** + * {@inheritDoc} + */ T next(); } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIteratorImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,20 +27,22 @@ /** * Wraps a RowIterator, requiring subclasses to adapt each Row to a specific type. + * @param <T> type of results * @author fgiust * @version $Id$ */ public abstract class ResultIteratorImpl<T> implements ResultIterator<T> { + /** + * The jcr RowIterator + */ protected RowIterator rowIterator; - protected final HierarchyManager hm; - /** - * Local variable storing the next accessible result. Method hasNext() fetches it, method next() resets it. + * Magnolia Hierarchy Manager */ - private AdvancedResultItem next; + protected final HierarchyManager hm; /** * @param rowIterator @@ -101,7 +103,7 @@ /** * Transforms a Row instance, adapting it to a specific type. - * @param row + * @param row the jcr Row to wrap * @return a transformed version */ protected abstract T wrap(Row row); Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -0,0 +1,53 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright (C)2009 - 2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; + +import java.text.SimpleDateFormat; +import java.util.Locale; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Base abstract criterion, just to share some useful fields/constants that should not end up in the interface. + * @author fgiust + * @version $Id$ + */ +public abstract class BaseCriterion implements Criterion +{ + + /** + * Date format used for date formatting. + */ + protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSS", + Locale.ENGLISH); + + /** + * Stable serialVersionUID + */ + private static final long serialVersionUID = 42L; + + /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(getClass()); + +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BaseCriterion.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -29,7 +29,7 @@ * @author fgrilli * @version $Id$ */ -public class BetweenExpression implements Criterion +public class BetweenExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = 6686395240415024541L; @@ -53,6 +53,9 @@ return propertyName + " between " + lo + " and " + hi; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(); @@ -69,11 +72,18 @@ else if (lo instanceof Calendar && hi instanceof Calendar) { Calendar cal = (Calendar) lo; - DATE_FORMAT.setCalendar(cal); - String fmt = DATE_FORMAT.format(cal.getTime()); Calendar cal2 = (Calendar) hi; - DATE_FORMAT.setCalendar(cal2); - String fmt2 = DATE_FORMAT.format(cal2.getTime()); + String fmt; + String fmt2; + + synchronized (DATE_FORMAT) + { + DATE_FORMAT.setCalendar(cal); + fmt = DATE_FORMAT.format(cal.getTime()); + DATE_FORMAT.setCalendar(cal2); + fmt2 = DATE_FORMAT.format(cal2.getTime()); + } + fragment.append(XS_DATETIME_FUNCTION + "('" + fmt Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -20,16 +20,11 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; import java.io.Serializable; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * An object-oriented representation of a query criterion that may be used as a restriction in a <tt>Criteria</tt> * query. Built-in criterion types are provided by the <tt>Restrictions</tt> factory class. This interface might be @@ -42,8 +37,9 @@ public interface Criterion extends Serializable { - Logger log = LoggerFactory.getLogger(Criterion.class); + String JCR_PRIMARYTYPE = "@jcr:primaryType"; + String ATTRIBUTE_SELECTOR = "@"; String JCR_PREFIX = "jcr:"; @@ -52,32 +48,16 @@ String ALL_ELEMENTS = "//*"; - String ANY_PROPERTY = "."; - String XS_DATETIME_FUNCTION = "xs:dateTime"; - String MIDNIGHT = "T00:00:00.000+00:00"; - - String T235959 = "T23:59:59.000+00:00"; - String NT_BASE = "nt:base"; - String NOT = " not("; - - String HYPHEN = "-"; - - int DAY_MAX = 10; - - int MONTH_MAX = 9; - - DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); - /** * Render the XPath fragment - * @param criteria - * @return String - * @throws JCRQueryException + * @param criteria input criteria + * @return converted XPATH expression + * @throws JCRQueryException if there is a problem converting the input criteria to a valid xpath expression */ - public String toXPathString(Criteria criteria) throws JCRQueryException; + String toXPathString(Criteria criteria) throws JCRQueryException; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNotNullExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -30,10 +30,8 @@ public class IsNotNullExpression implements Criterion { - private static final long serialVersionUID = -1955669039985775985L; + private static final long serialVersionUID = 42L; - protected static final String WHITESPACE = " "; - private String nodeName; public IsNotNullExpression(String nodeName) @@ -47,8 +45,11 @@ return nodeName; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { - return WHITESPACE + nodeName + WHITESPACE; + return " " + nodeName + " "; } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/IsNullExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class IsNullExpression implements Criterion +public class IsNullExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -1600960388638847909L; @@ -48,7 +48,7 @@ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(); - fragment.append(Criterion.NOT).append(nodeName).append(") "); + fragment.append(" not(").append(nodeName).append(") "); log.debug("xpathString is {} ", fragment); return fragment.toString(); } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/JCRFunctionExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class JCRFunctionExpression implements Criterion +public class JCRFunctionExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -5570839091762158385L; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LogicalExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -28,7 +28,7 @@ * @author Federico Grilli * @version $Id$ */ -public class LogicalExpression implements Criterion +public class LogicalExpression extends BaseCriterion implements Criterion { /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/MatchMode.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,23 +32,6 @@ public abstract class MatchMode implements Serializable { - private static final long serialVersionUID = -7446324572335777782L; - - private final String name; - - private static final Map<String, MatchMode> INSTANCES = new HashMap<String, MatchMode>(); - - protected MatchMode(String name) - { - this.name = name; - } - - @Override - public String toString() - { - return name; - } - /** * Match the start of the string to the pattern */ @@ -88,6 +71,23 @@ } }; + private static final Map<String, MatchMode> INSTANCES = new HashMap<String, MatchMode>(); + + private static final long serialVersionUID = -7446324572335777782L; + + private final String name; + + protected MatchMode(String name) + { + this.name = name; + } + + @Override + public String toString() + { + return name; + } + static { INSTANCES.put(END.name, END); @@ -97,6 +97,8 @@ /** * convert the pattern, by appending/prepending "%" + * @param pattern input pattern + * @return formatted match string */ public abstract String toMatchString(String pattern); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/NotExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,7 +27,7 @@ * @author fgrilli * @version $Id$ */ -public class NotExpression implements Criterion +public class NotExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -5057676844499041929L; @@ -47,7 +47,7 @@ public String toXPathString(Criteria criteria) throws JCRQueryException { - StringBuilder fragment = new StringBuilder(Criterion.NOT); + StringBuilder fragment = new StringBuilder(" not("); fragment.append(expression.toXPathString(criteria)).append(") "); log.debug("xpathString is {} ", fragment); return fragment.toString(); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Order.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -27,24 +27,18 @@ * Represents an order imposed upon a <tt>Criteria</tt> result set * @author Federico Grilli */ -public class Order implements Criterion +public class Order extends BaseCriterion implements Criterion { /** - * - */ + * + */ private static final long serialVersionUID = -1228583450961430360L; private boolean ascending; private String nodeName; - @Override - public String toString() - { - return nodeName + ' ' + (ascending ? "ascending" : "descending"); - } - /** * Constructor for Order. */ @@ -54,6 +48,9 @@ this.ascending = ascending; } + /** + * {@inheritDoc} + */ public String toXPathString(Criteria criteria) throws JCRQueryException { StringBuilder fragment = new StringBuilder(" "); @@ -67,7 +64,7 @@ /** * Ascending order - * @param propertyName + * @param propertyName jcr property name, e.g. "@title" * @return Order */ public static Order asc(String propertyName) @@ -77,11 +74,17 @@ /** * Descending order - * @param propertyName + * @param propertyName jcr property name, e.g. "@title" * @return Order */ public static Order desc(String propertyName) { return new Order(propertyName, false); } + + @Override + public String toString() + { + return nodeName + ' ' + (ascending ? "ascending" : "descending"); + } } \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Restrictions.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.TimeZone; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; @@ -31,11 +30,11 @@ * The <tt>criterion</tt> package may be used by applications as a framework for building new kinds of * <tt>Criterion</tt>. However, it is intended that most applications will simply use the built-in criterion types via * the static factory methods of this class. - * @see Criteria + * @author fgiust * @author Federico Grilli * @version $Id$ */ -public class Restrictions +public final class Restrictions { private static final Calendar MIDNIGHT_GMT; @@ -49,7 +48,7 @@ MIDNIGHT_GMT.set(Calendar.MILLISECOND, 0); } - Restrictions() + private Restrictions() { // cannot be instantiated } @@ -67,16 +66,6 @@ } /** - * @param nodeName - * @param value - * @return - */ - public static Criterion eqDate(String nodeName, Calendar value) - { - return betweenDates(nodeName, value, value); - } - - /** * Apply a "not equal" constraint to the named node * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an * attribute it must be preceded by the '@'character (eg. @nt:somenode) @@ -97,7 +86,7 @@ * "http://www.nabble.com/Explanation-and-solutions-of-some-Jackrabbit-queries-regarding-performance-td15028655.html" * >us...@ja... mailing list</a> <br> * <em> - * <ul> + * <ul> * <li>Question: My xpath is '//*[jcr:like(@propertyName, * '%somevalue%')]' and it takes minutes to complete. * @@ -137,7 +126,7 @@ * "http://www.nabble.com/Explanation-and-solutions-of-some-Jackrabbit-queries-regarding-performance-td15028655.html" * >us...@ja... mailing list</a> <br> * <em> - * <ul> + * <ul> * <li>Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete. * * <li>Answer: a jcr:like with % will be translated to a WildcardQuery lucene @@ -264,11 +253,27 @@ } /** - * @param nodeName - * @param lo - * @param hi - * @return + * Adds a date contraint: the input date must be included in the given date, excluding time (between 00:00 and 23:59 + * of the given date) + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) + * @param value date (time will be ignored) + * @return Criterion */ + public static Criterion eqDate(String nodeName, Calendar value) + { + return betweenDates(nodeName, value, value); + } + + /** + * Adds a date contraint: the input date must be included in the given dates (between 00:00 of the first date to + * 23:59 of the last date) + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) + * @param lo lower date + * @param hi higher date + * @return Criterion + */ public static Criterion betweenDates(String nodeName, Calendar lo, Calendar hi) { return between(nodeName, getDayStart(lo), getDayEnd(hi)); @@ -301,6 +306,8 @@ /** * Apply an "is null" constraint to the named node + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) * @return Criterion */ public static Criterion isNull(String nodeName) @@ -310,6 +317,8 @@ /** * Apply an "is not null" constraint to the named node + * @param nodeName - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an + * attribute it must be preceded by the '@'character (eg. @nt:somenode) * @return Criterion */ public static Criterion isNotNull(String nodeName) @@ -319,8 +328,8 @@ /** * Return the conjuction of two expressions - * @param lhs - * @param rhs + * @param lhs left expression + * @param rhs right expression * @return Criterion */ public static LogicalExpression and(Criterion lhs, Criterion rhs) @@ -330,8 +339,8 @@ /** * Return the disjuction of two expressions - * @param lhs - * @param rhs + * @param lhs left expression + * @param rhs right expression * @return Criterion */ public static LogicalExpression or(Criterion lhs, Criterion rhs) @@ -341,7 +350,7 @@ /** * Return the negation of an expression - * @param expression + * @param expression to be negated * @return Criterion */ public static Criterion not(Criterion expression) @@ -350,40 +359,6 @@ } /** - * Apply a constraint expressed in xpath. - * @param xpath - * @param values - * @param types - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath, Object[] values) { throw new - * UnsupportedOperationException(); // return new XPathCriterion(sql, values, types); } - */ - - /** - * Apply a constraint expressed in xpath. - * @param xpath - * @param value - * @param type - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath, Object value) { throw new UnsupportedOperationException(); - * // return new XPathCriterion(sql, new Object[] { value }, new Type[] { // type } ); } - */ - - /** - * Apply a constraint expressed in xpath. - * @param xpath - * @return Criterion - */ - /* - * public static Criterion xpathRestriction(String xpath) { throw new UnsupportedOperationException(); // return new - * XPathCriterion(sql, ArrayHelper.EMPTY_OBJECT_ARRAY, // ArrayHelper.EMPTY_TYPE_ARRAY); } - */ - - /** * Group expressions together in a single conjunction (A and B and C...) * @return Conjunction */ Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/SimpleExpression.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,7 +32,7 @@ * @author Federico Grilli * @version $Id$ */ -public class SimpleExpression implements Criterion +public class SimpleExpression extends BaseCriterion implements Criterion { private static final long serialVersionUID = -1104419394978535803L; @@ -104,8 +104,13 @@ { fragment.append(propertyName).append(getOp()); Calendar cal = (Calendar) value; - DATE_FORMAT.setCalendar(cal); - String fmt = DATE_FORMAT.format(cal.getTime()); + String fmt; + + synchronized (DATE_FORMAT) + { + DATE_FORMAT.setCalendar(cal); + fmt = DATE_FORMAT.format(cal.getTime()); + } fragment.append(XS_DATETIME_FUNCTION + "('" + fmt + "+00:00" + "')) "); } else if (value != null) Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/lucene/AclSearchIndex.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -39,8 +39,6 @@ import org.apache.jackrabbit.spi.commons.query.QueryNodeVisitor; import org.apache.jackrabbit.spi.commons.query.QueryRootNode; import org.apache.lucene.search.Query; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** @@ -53,11 +51,6 @@ private DefaultQueryNodeFactory proxiedQueryNodeFactory; - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(AclSearchIndex.class); - public AclSearchIndex() { @@ -124,7 +117,6 @@ Field sessionField = LuceneQueryBuilder.class.getDeclaredField("session"); sessionField.setAccessible(true); SessionImpl session = (SessionImpl) sessionField.get(visitor); - // adds acl constraints AclQueryDecorator decorator = new AclQueryDecorator(session, AclSearchIndex.this); return decorator.applyAcl(luceneQuery); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -61,9 +61,9 @@ protected List<OrderEntry> orderEntries = new ArrayList<OrderEntry>(); - protected int maxResults = 0; + protected int maxResults; - protected int offset = 0; + protected int offset; protected HierarchyManager hm; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -32,6 +32,7 @@ * @author fgrilli * @version $Id$ */ +@Deprecated public abstract class AbstractMagnoliaCriteriaImpl extends AbstractCriteriaImpl { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -44,6 +44,7 @@ * @author Federico Grilli * @version $Id$ */ +@Deprecated public class MagnoliaCriteriaImpl extends AbstractMagnoliaCriteriaImpl { Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -55,8 +55,9 @@ /** - * Magnolia XPATH implementation of the <tt>Criteria</tt> interface which supports limiting the result set according to - * the underlying JCR implementation (e.g. Jackrabbit 1.4+) + * <strong>Deprecated in mgnlcriteria 2.x. Paging is now implemented at jcr level in AdvancedCriteria, this class should + * not be used anymore.</strong> Magnolia XPATH implementation of the <tt>Criteria</tt> interface which supports + * limiting the result set according to the underlying JCR implementation (e.g. Jackrabbit 1.4+) * @deprecated due to the way results are collected there is no guarantee that the offset specified is respected: for * example if your query matches both a page and a paragraph in it, and you ask for results of type mgnl:content those * two results will be merged into one. If you need paging use AdvancedCriteria and be sure to specify the desired @@ -97,6 +98,7 @@ super(hm); } + @Override @SuppressWarnings("unchecked") @Deprecated public Collection< ? > list() throws JCRQueryException @@ -148,7 +150,7 @@ stop = System.currentTimeMillis(); log.debug("Query executed in {} milliseconds", stop - start); - Collection retVal; + Collection<Content> retVal; field = managerClass.getDeclaredField(HIERARCHY_MANAGER); field.setAccessible(true); HierarchyManager hm = (HierarchyManager) field.get(queryManager); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -26,13 +26,14 @@ /** * A utility class to escape xpath strings + * @author fgiust * @author fgrilli * @version $Id$ */ public final class XPathTextUtils { - private static final Logger log = LoggerFactory.getLogger(XPathTextUtils.class); + private static Logger log = LoggerFactory.getLogger(XPathTextUtils.class); private XPathTextUtils() { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathTest.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -31,6 +31,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; @@ -166,7 +167,7 @@ { Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); criteria.setBasePath(basePath); - criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.eq(Criterion.JCR_PRIMARYTYPE, "mgnl:content")); if (!StringUtils.isEmpty(title)) { criteria.add(Restrictions.eq("@title", title)); Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java 2010-08-29 07:20:05 UTC (rev 2922) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/Content2BeanTest.java 2010-08-29 08:58:29 UTC (rev 2923) @@ -21,6 +21,9 @@ import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.context.MgnlContext; + +import java.util.Map; + import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; @@ -37,6 +40,7 @@ /** + * Tests for Content2Bean transformation * @author fgiust * @version $Id$ */ @@ -59,6 +63,7 @@ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); } + @SuppressWarnings("unchecked") @Test public void testLoremAndIpsum() throws Exception { @@ -75,6 +80,11 @@ AdvancedResultItem item = items.next(); Assert.assertEquals(item.getTitle(), "lorem ipsum"); + // this is also a Map! + Assert.assertEquals(((Map<String, Object>) item).get("title"), "lorem ipsum"); + Assert.assertEquals(((Map<String, Object>) item).get("text"), "ohoh"); + Assert.assertEquals(((Map<String, Object>) item).get("number"), "5"); + ResultIterator<Page> itemsTransformed = advResult.getItems(Page.class); Assert.assertNotNull(itemsTransformed); Page page = itemsTransformed.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |