Author: nbelaevski
Date: 2011-01-18 14:20:56 -0500 (Tue, 18 Jan 2011)
New Revision: 21064
Added:
trunk/core/impl/src/main/java/org/richfaces/context/ClientIdWalker.java
trunk/core/impl/src/main/java/org/richfaces/context/IdSplitIterator.java
trunk/core/impl/src/main/java/org/richfaces/context/RowsFunctionContextCallback.java
trunk/core/impl/src/test/java/org/richfaces/context/IdSplitIteratorTest.java
Removed:
trunk/core/api/src/main/java/org/richfaces/renderkit/util/IdSplitBuilder.java
trunk/core/api/src/test/java/org/richfaces/renderkit/util/IdSplitBuilderTest.java
trunk/core/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java
trunk/core/impl/src/main/java/org/richfaces/context/IdTreeNode.java
trunk/core/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java
Modified:
trunk/core/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java
trunk/core/api/src/main/java/org/richfaces/renderkit/util/CoreAjaxRendererUtils.java
trunk/core/impl/src/main/java/org/richfaces/context/BaseExtendedVisitContext.java
trunk/core/impl/src/main/java/org/richfaces/context/ComponentIdResolver.java
trunk/core/impl/src/main/java/org/richfaces/context/IdParser.java
trunk/core/impl/src/main/java/org/richfaces/util/Util.java
trunk/core/impl/src/test/java/org/richfaces/context/ComponentIdResolverTest.java
trunk/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java
trunk/core/impl/src/test/java/org/richfaces/context/IdParserTest.java
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java
Log:
https://issues.jboss.org/browse/RF-10110
Modified: trunk/core/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/api/src/main/java/org/richfaces/context/ExtendedVisitContext.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -21,8 +21,6 @@
*/
package org.richfaces.context;
-import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
-
import java.util.Collection;
import java.util.Map;
@@ -32,6 +30,10 @@
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
+import org.richfaces.component.MetaComponentResolver;
+
+import com.google.common.base.Joiner;
+
/**
* @author Nick Belaevski
*
@@ -40,6 +42,8 @@
public static final String META_COMPONENT_ID =
"org.richfaces.MetaComponentId";
+ private static final Joiner META_COMPONENT_SEPARATOR_JOINER =
Joiner.on(MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR).skipNulls();
+
private final FacesContext facesContext;
private final ExtendedVisitContextMode visitMode;
@@ -76,37 +80,13 @@
}
public String buildExtendedClientId(UIComponent component) {
- String extendedClientId = component.getClientId(facesContext);
- String subComponentId = (String)
facesContext.getAttributes().get(META_COMPONENT_ID);
- if (subComponentId != null) {
- StringBuilder sb = new StringBuilder(extendedClientId.length() + 1 /*
separator length */ +
- subComponentId.length());
-
- sb.append(extendedClientId);
- sb.append(META_COMPONENT_SEPARATOR_CHAR);
- sb.append(subComponentId);
-
- extendedClientId = sb.toString();
- }
-
- return extendedClientId;
+ String metaComponentId = (String)
facesContext.getAttributes().get(META_COMPONENT_ID);
+ return META_COMPONENT_SEPARATOR_JOINER.join(component.getClientId(facesContext),
metaComponentId);
}
public String buildExtendedComponentId(UIComponent component) {
- String componentId = component.getId();
- String subComponentId = (String)
facesContext.getAttributes().get(META_COMPONENT_ID);
- if (subComponentId != null) {
- StringBuilder sb = new StringBuilder(componentId.length() + 1 /* separator
length */ +
- subComponentId.length());
-
- sb.append(componentId);
- sb.append(META_COMPONENT_SEPARATOR_CHAR);
- sb.append(subComponentId);
-
- componentId = sb.toString();
- }
-
- return componentId;
+ String metaComponentId = (String)
facesContext.getAttributes().get(META_COMPONENT_ID);
+ return META_COMPONENT_SEPARATOR_JOINER.join(component.getId(), metaComponentId);
}
@Override
Modified:
trunk/core/api/src/main/java/org/richfaces/renderkit/util/CoreAjaxRendererUtils.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/renderkit/util/CoreAjaxRendererUtils.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/api/src/main/java/org/richfaces/renderkit/util/CoreAjaxRendererUtils.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -165,15 +165,6 @@
}
/**
- * Split parameter string into array of strings.
- * @param valuesSet
- * @return
- */
- public static String[] asIdsArray(String valuesSet) {
- return IdSplitBuilder.split(valuesSet);
- }
-
- /**
* Get list of clientId's for given component
*
* @param uiComponent
@@ -198,15 +189,15 @@
}
public static Set<String> asSimpleSet(Object valueToSet) {
- return asSet(valueToSet, false);
+ return asSet(valueToSet);
}
public static Set<String> asIdsSet(Object valueToSet) {
- return asSet(valueToSet, true);
+ return asSet(valueToSet);
}
@SuppressWarnings("unchecked")
- private static Set<String> asSet(Object valueToSet, boolean idsSet) {
+ private static Set<String> asSet(Object valueToSet) {
if (null != valueToSet) {
// Simplest case - set.
@@ -220,12 +211,7 @@
String areasString = ((String) valueToSet).trim();
if (areasString.contains(",") || areasString.contains("
")) {
- String[] values;
- if (idsSet) {
- values = IdSplitBuilder.split(areasString);
- } else {
- values = ID_SPLIT_PATTERN.split(areasString);
- }
+ String[] values = ID_SPLIT_PATTERN.split(areasString);
Set<String> result = new
LinkedHashSet<String>(values.length);
for (String value : values) {
Deleted: trunk/core/api/src/main/java/org/richfaces/renderkit/util/IdSplitBuilder.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/renderkit/util/IdSplitBuilder.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/api/src/main/java/org/richfaces/renderkit/util/IdSplitBuilder.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,150 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.renderkit.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Nick Belaevski
- */
-final class IdSplitBuilder {
-
- private static final int INITIAL_SPLIT_LIST_SIZE = 3;
-
- private enum State {
- IN_ID (true) {
-
- @Override
- public State getNextState(char c) {
- if (c == '[') {
- return State.IN_ID_INSIDE_BRACKETS;
- } else if (isSeparator(c)) {
- return State.OUTSIDE_ID;
- } else {
- return this;
- }
- }
- },
- IN_ID_INSIDE_BRACKETS (true) {
-
- @Override
- public State getNextState(char c) {
- if (c == ']') {
- return State.IN_ID;
- } else {
- return this;
- }
- }
- },
- OUTSIDE_ID (false) {
-
- @Override
- public State getNextState(char c) {
- if (!isSeparator(c)) {
- if (c == '[') {
- return State.IN_ID_INSIDE_BRACKETS;
- } else {
- return State.IN_ID;
- }
- }
-
- return this;
- }
- };
-
- private final boolean idSegment;
-
- private State(boolean idSegment) {
- this.idSegment = idSegment;
- }
-
- private static boolean isSeparator(char c) {
- return c == ',' || Character.isWhitespace(c);
- }
-
- public abstract State getNextState(char c);
-
- public boolean isIdSegment() {
- return idSegment;
- }
-
- public void processChar(IdSplitBuilder builder, char c, int charIdx) {
- State nextState = getNextState(c);
-
- if (nextState.isIdSegment() ^ isIdSegment()) {
- if (nextState.isIdSegment()) {
- builder.setStartIndex(charIdx);
- } else {
- builder.flushBuilder(charIdx);
- builder.setStartIndex(-1);
- }
- }
-
- builder.state = nextState;
- }
- }
-
- private int startIdx = -1;
-
- private String sourceString;
-
- private List<String> result = new
ArrayList<String>(INITIAL_SPLIT_LIST_SIZE);
-
- private State state = State.OUTSIDE_ID;
-
- private IdSplitBuilder(String sourceString) {
- super();
- this.sourceString = sourceString;
- }
-
- private void setStartIndex(int idx) {
- startIdx = idx;
- }
-
- private void flushBuilder(int endIdx) {
- if (startIdx >= 0 && endIdx > startIdx) {
- String id = sourceString.substring(startIdx, endIdx);
- result.add(id);
- }
- }
-
- private void build() {
- int length = sourceString.length();
- for (int i = 0; i < length; i++) {
- char c = sourceString.charAt(i);
- state.processChar(this, c, i);
- }
- flushBuilder(length);
- }
-
- private String[] getSplit() {
- return result.toArray(new String[result.size()]);
- }
-
- public static String[] split(String s) {
- IdSplitBuilder splitBuilder = new IdSplitBuilder(s);
- splitBuilder.build();
- return splitBuilder.getSplit();
- }
-
-}
\ No newline at end of file
Deleted:
trunk/core/api/src/test/java/org/richfaces/renderkit/util/IdSplitBuilderTest.java
===================================================================
---
trunk/core/api/src/test/java/org/richfaces/renderkit/util/IdSplitBuilderTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/api/src/test/java/org/richfaces/renderkit/util/IdSplitBuilderTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.renderkit.util;
-
-import static org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-import org.richfaces.renderkit.util.IdSplitBuilder;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public class IdSplitBuilderTest {
-
- private static String[] asArray(String... strings) {
- return strings;
- }
-
- @Test
- public void testEmptyString() throws Exception {
- assertArrayEquals(asArray(), IdSplitBuilder.split(""));
- assertArrayEquals(asArray(), IdSplitBuilder.split(" \r\t\n "));
- }
-
- @Test
- public void testOneStrings() throws Exception {
- assertArrayEquals(asArray("test"),
IdSplitBuilder.split("test"));
- assertArrayEquals(asArray("some:id"),
IdSplitBuilder.split("some:id"));
- assertArrayEquals(asArray("table:[1]"),
IdSplitBuilder.split("table:[1]"));
- assertArrayEquals(asArray("table:[1, 2]"),
IdSplitBuilder.split("table:[1, 2]"));
- assertArrayEquals(asArray("table:[1, 2]:nestedTable:[*]"),
IdSplitBuilder.split("table:[1, 2]:nestedTable:[*]"));
- assertArrayEquals(asArray("table:[1, 2]:[*]:group"),
IdSplitBuilder.split("table:[1, 2]:[*]:group"));
- assertArrayEquals(asArray("table:[1 2]:nestedTable:[*]"),
IdSplitBuilder.split("table:[1 2]:nestedTable:[*]"));
- assertArrayEquals(asArray("table:[1 2]:[*]:group"),
IdSplitBuilder.split("table:[1 2]:[*]:group"));
- }
-
- @Test
- public void testTwoStrings() throws Exception {
- assertArrayEquals(asArray("test", "abc"),
IdSplitBuilder.split("test abc"));
- assertArrayEquals(asArray("some:id", "form:table"),
IdSplitBuilder.split("some:id form:table"));
- assertArrayEquals(asArray("test", "abc"),
IdSplitBuilder.split("test, abc"));
- assertArrayEquals(asArray("some:id", "form:table"),
IdSplitBuilder.split("some:id, form:table"));
-
- assertArrayEquals(asArray("test:[1 2 3]:abc", "form:[2]"),
IdSplitBuilder.split("test:[1 2 3]:abc form:[2]"));
- assertArrayEquals(asArray("[1 2]:some", "[3\t4]:id"),
IdSplitBuilder.split(" [1 2]:some [3\t4]:id "));
- }
-
- @Test
- public void testSeveralStrings() throws Exception {
- assertArrayEquals(asArray("test", "abc", "def",
"ghi"), IdSplitBuilder.split("test abc def ghi"));
- assertArrayEquals(asArray("test:[1 2]abc", "def",
"ghi"), IdSplitBuilder.split("test:[1 2]abc def ghi"));
- assertArrayEquals(asArray("[1 2]abc", "[3, 4]def",
"ghi[5 6 7]"),
- IdSplitBuilder.split("[1 2]abc [3, 4]def ghi[5 6 7]"));
-
- assertArrayEquals(
- asArray("test:[1 2]:abc", "table", "form:table:[ *
]:child", "extTable:[ 0, 3 ]:child:[1 8]:@header"),
- IdSplitBuilder.split(" test:[1 2]:abc, table," +
- " form:table:[ * ]:child, extTable:[ 0, 3 ]:child:[1
8]:@header" ));
- }
-}
Modified:
trunk/core/impl/src/main/java/org/richfaces/context/BaseExtendedVisitContext.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/BaseExtendedVisitContext.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/main/java/org/richfaces/context/BaseExtendedVisitContext.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -21,38 +21,76 @@
*/
package org.richfaces.context;
+import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR_JOINER;
+
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitHint;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import org.richfaces.component.MetaComponentResolver;
-
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
/**
* @author Nick Belaevski
*
*/
public class BaseExtendedVisitContext extends ExtendedVisitContext {
- static final String ANY_WILDCARD = "*";
+ protected static interface ClientIdVisitor {
- private static final int SHORT_ID_IN_CLIENTID_SEGMENTS_NUMBER = 2;
+ public abstract void visitSubtreeId(String baseId, String clientId);
+ public abstract void visitDirectSubtreeId(String baseId, String shortId);
+
+ public abstract void visitShortId(String shortId);
+
+ }
+
+ protected final ClientIdVisitor addNodeVisitor = new ClientIdVisitor() {
+
+ public void visitSubtreeId(String baseId, String clientId) {
+ subtreeIds.put(baseId, clientId);
+ }
+
+ public void visitDirectSubtreeId(String baseId, String shortId) {
+ directSubtreeIds.put(baseId, shortId);
+ }
+
+ public void visitShortId(String shortId) {
+ shortIds.add(shortId);
+ }
+ };
+
+ protected final ClientIdVisitor removeNodeVisitor = new ClientIdVisitor() {
+
+ public void visitSubtreeId(String baseId, String clientId) {
+ subtreeIds.remove(baseId, clientId);
+ }
+
+ public void visitShortId(String shortId) {
+ //do nothing
+ }
+
+ public void visitDirectSubtreeId(String baseId, String shortId) {
+ directSubtreeIds.remove(baseId, shortId);
+ }
+ };
+
private final class CollectionProxy extends AbstractCollection<String> {
private CollectionProxy() {
@@ -60,17 +98,17 @@
@Override
public boolean isEmpty() {
- return directNodesMap.isEmpty();
+ return clientIds.isEmpty();
}
@Override
public int size() {
- return directNodesMap.size();
+ return clientIds.size();
}
@Override
public Iterator<String> iterator() {
- return new IteratorProxy(directNodesMap.keySet().iterator());
+ return new IteratorProxy(clientIds.iterator());
}
@Override
@@ -106,8 +144,7 @@
public void remove() {
if (current != null) {
- ComponentMatcherNode node = directNodesMap.get(current);
- removeNode(node);
+ removeNode(current, false);
current = null;
}
@@ -116,86 +153,20 @@
}
}
- private interface NodeOperationCommand {
-
- public ComponentMatcherNode getNextNode(ComponentMatcherNode currentNode, String
nodeId, boolean isPattern);
-
- public boolean processLastNode(ComponentMatcherNode lastNode, String fullId);
- }
-
- private NodeOperationCommand addNodeOperation = new NodeOperationCommand() {
-
- public boolean processLastNode(ComponentMatcherNode lastNode, String fullId) {
- if (!directNodesMap.containsKey(fullId)) {
- directNodesMap.put(fullId, lastNode);
- lastNode.markAdded();
-
- ComponentMatcherNode n = lastNode;
- int addedSegmentsCount = 0;
- while (n != null && addedSegmentsCount <
SHORT_ID_IN_CLIENTID_SEGMENTS_NUMBER) {
- if (!n.isPatternNode() && !n.isMetaComponentNode()) {
- String shortId = n.getSource();
- if (shortId != null) {
- addedSegmentsCount++;
- //TODO filter meta component ids
- shortIds.add(shortId);
- }
- }
-
- n = n.getParentNode();
- }
-
- if (!lastNode.hasPatternNodeInChain()) {
- lastNode.addSubtreeId(fullId);
- }
-
- return true;
- }
-
- return false;
- }
-
- public ComponentMatcherNode getNextNode(ComponentMatcherNode currentNode, String
nodeId, boolean isPattern) {
- return currentNode.getOrCreateChild(nodeId, isPattern);
- }
- };
-
- private NodeOperationCommand removeNodeOperation = new NodeOperationCommand() {
-
- public boolean processLastNode(ComponentMatcherNode lastNode, String fullId) {
- ComponentMatcherNode node = directNodesMap.remove(fullId);
- if (node != null) {
- if (!node.hasPatternNodeInChain()) {
- node.removeSubtreeId(fullId);
- }
-
- removeNode(node);
-
- return true;
- }
-
- return false;
- }
-
- public ComponentMatcherNode getNextNode(ComponentMatcherNode currentNode, String
nodeId, boolean isPattern) {
- return currentNode.getChild(nodeId, isPattern);
- }
- };
-
- private IdParser idParser;
-
// The client ids to visit
private Collection<String> clientIds;
private Collection<String> shortIds;
+ private SetMultimap<String, String> subtreeIds;
+
+ private ListMultimap<String, String> directSubtreeIds;
+
// Our visit hints
private Set<VisitHint> hints;
- private ComponentMatcherNode rootNode;
+ private CollectionProxy proxiedClientIds;
- private Map<String, ComponentMatcherNode> directNodesMap;
-
/**
* Creates a PartialVisitorContext instance with the specified hints.
*
@@ -223,144 +194,53 @@
this.hints = Collections.unmodifiableSet(hintsEnumSet);
}
- private IdParser setupIdParser(String id) {
- if (idParser == null) {
- idParser = new
IdParser(UINamingContainer.getSeparatorChar(getFacesContext()),
- MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR);
- }
+ protected void visitClientId(String clientId, ClientIdVisitor visitor) {
+ IdSplitIterator splitIterator = new IdSplitIterator(clientId);
+
+ boolean isFirstIteration = true;
+
+ while (splitIterator.hasNext()) {
+ String shortId = splitIterator.next();
+ String subtreeId = splitIterator.getSubtreeId();
- idParser.setId(id);
-
- return idParser;
- }
-
- private ComponentMatcherNode findMatchingNode(String clientId) {
- ComponentMatcherNode node = rootNode;
-
- IdParser idParser = setupIdParser(clientId);
-
- while (node != null && idParser.findNext()) {
- String componentId = idParser.getComponentId();
- String metadataComponentId = idParser.getMetadataComponentId();
-
- if (metadataComponentId != null) {
- node = node.getChild(componentId, false);
- if (node != null) {
- node = node.getChild(metadataComponentId, false);
- }
- } else {
- node = node.getMatchedChild(componentId);
+ int metaSepIdx = shortId.indexOf(META_COMPONENT_SEPARATOR_CHAR);
+
+ if (subtreeId != null) {
+ visitor.visitSubtreeId(subtreeId, clientId);
+ visitor.visitDirectSubtreeId(subtreeId, shortId);
}
- }
- return node;
- }
-
- private ComponentMatcherNode findAddedNode(String clientId) {
- ComponentMatcherNode node = findMatchingNode(clientId);
-
- if (node != null && !node.isAdded()) {
- node = null;
- }
-
- return node;
- }
-
- private void removeNode(ComponentMatcherNode nodeToRemove) {
- nodeToRemove.markRemoved();
-
- ComponentMatcherNode node = nodeToRemove;
- while (node != null && !node.hasDirectChildren()) {
- ComponentMatcherNode parentNode = node.getParentNode();
- if (parentNode != null) {
- parentNode.removeChild(node);
- node = parentNode;
- } else {
- break;
+ if (metaSepIdx >= 0) {
+ String componentId = shortId.substring(0, metaSepIdx);
+
+ String extraBaseId = SEPARATOR_CHAR_JOINER.join(subtreeId, componentId);
+ visitor.visitDirectSubtreeId(extraBaseId, shortId);
+ visitor.visitSubtreeId(extraBaseId, clientId);
}
+
+ if (isFirstIteration) {
+ isFirstIteration = false;
+ visitor.visitShortId(shortId);
+ }
}
}
+
+ private boolean addNode(String clientId) {
+ if (clientIds.add(clientId)) {
+ visitClientId(clientId, addNodeVisitor);
- private boolean invokeNodeOperation(NodeOperationCommand command,
ComponentMatcherNode currentNode,
- IdTreeNode idTreeNode, StringBuilder sb) {
-
- String componentId = idTreeNode.getComponentId();
- String metadataComponentId = idTreeNode.getMetadataComponentId();
-
- ComponentMatcherNode nextNode;
-
- if (metadataComponentId != null) {
- nextNode = command.getNextNode(currentNode, componentId, false);
- if (nextNode != null) {
- nextNode = command.getNextNode(nextNode, metadataComponentId, false);
- nextNode.setMetaComponentNode(true);
- }
- } else {
- boolean isPattern = ANY_WILDCARD.equals(componentId);
- nextNode = command.getNextNode(currentNode, componentId, isPattern);
+ return true;
}
-
- boolean result = false;
-
- if (nextNode != null) {
- final int bufferLength = sb.length();
- if (bufferLength != 0) {
- //TODO replace with constant
- sb.append(':');
- }
- sb.append(componentId);
- if (metadataComponentId != null) {
- sb.append(metadataComponentId);
- }
-
- List<IdTreeNode> idTreeChildNodes = idTreeNode.getChildNodes();
- if (idTreeChildNodes != null) {
- final int newBufferLength = sb.length();
-
- for (IdTreeNode idTreeChildNode : idTreeChildNodes) {
- result |= invokeNodeOperation(command, nextNode, idTreeChildNode,
sb);
-
- sb.setLength(newBufferLength);
- }
- } else {
- result |= command.processLastNode(nextNode, sb.toString());
- }
-
- sb.setLength(bufferLength);
- }
-
- return result;
+
+ return false;
}
- private boolean invokeRootNodeOperation(NodeOperationCommand command, IdTreeNode
idTreeNode) {
- boolean result = false;
-
- List<IdTreeNode> idTreeChildNodes = idTreeNode.getChildNodes();
- if (idTreeChildNodes != null) {
- StringBuilder sb = new StringBuilder();
-
- for (IdTreeNode idTreeChildNode : idTreeChildNodes) {
- result |= invokeNodeOperation(command, rootNode, idTreeChildNode, sb);
- }
+ private void removeNode(String clientId, boolean removeFromClientIds) {
+ if (!removeFromClientIds || clientIds.remove(clientId)) {
+ visitClientId(clientId, removeNodeVisitor);
}
-
- return result;
}
- private boolean addNode(String patternId) {
- IdTreeNode idTreeNode = new IdTreeNode();
- idTreeNode.appendNodesFromParser(setupIdParser(patternId));
-
- return invokeRootNodeOperation(addNodeOperation, idTreeNode);
- }
-
- private boolean removeNode(String patternId) {
- IdTreeNode idTreeNode = new IdTreeNode();
- idTreeNode.appendNodesFromParser(setupIdParser(patternId));
-
- return invokeRootNodeOperation(removeNodeOperation, idTreeNode);
- }
-
/**
* @see VisitContext#getHints VisitContext.getHints
*/
@@ -378,13 +258,13 @@
// We just return our clientIds collection. This is
// the modifiable (but proxied) collection of all of
// the client ids to visit.
- return clientIds;
+ return proxiedClientIds;
}
protected boolean hasImplicitSubtreeIdsToVisit(UIComponent component) {
return false;
}
-
+
/**
* @see VisitContext#getSubtreeIdsToVisit VisitContext.getSubtreeIdsToVisit()
*/
@@ -402,28 +282,13 @@
String clientId = buildExtendedClientId(component);
- ComponentMatcherNode node = findMatchingNode(clientId);
+ Collection<String> result;
- Collection<String> result = null;
-
-
- if (node != null) {
- if (node.hasKidPatternNodes()) {
- result = VisitContext.ALL_IDS;
- } else {
- Collection<String> subtreeIds = node.getSubtreeIds();
- if (subtreeIds != null) {
- result = Collections.unmodifiableCollection(subtreeIds);
- } else {
- //TODO nick - this code addresses the case of parent pattern nodes,
and can be optimized
- if (node.hasDirectIdChildren()) {
- result = VisitContext.ALL_IDS;
- } else {
- result = Collections.emptySet();
- }
- }
- }
+ Set<String> ids = subtreeIds.get(clientId);
+ if (!ids.isEmpty()) {
+ result = Collections.unmodifiableCollection(ids);
} else {
+ //returned collection should be non-modifiable
result = Collections.emptySet();
}
@@ -440,17 +305,9 @@
}
String clientId = component.getClientId(getFacesContext());
- ComponentMatcherNode node = findMatchingNode(clientId);
- if (node != null && node.hasDirectPatternChildren()) {
- return VisitContext.ALL_IDS;
- }
+ Set<String> result = new
HashSet<String>(directSubtreeIds.get(clientId));
- Set<String> result = new HashSet<String>();
- if (node != null && node.hasDirectIdChildren()) {
- result.addAll(node.getIdChildren().keySet());
- }
-
addDirectSubtreeIdsToVisitForImplicitComponents(component, result);
if (result != null && !result.isEmpty()) {
@@ -467,19 +324,19 @@
protected boolean shouldCompleteOnEmptyIds() {
return true;
}
-
+
/**
* @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
*/
@Override
public VisitResult invokeVisitCallback(UIComponent component, VisitCallback callback)
{
- if (shortIds.contains(component.getId())) {
+ if (shortIds.contains(buildExtendedComponentId(component))) {
String clientId = buildExtendedClientId(component);
- ComponentMatcherNode node = findAddedNode(clientId);
- if (node != null) {
+
+ if (clientIds.contains(clientId)) {
VisitResult visitResult = callback.visit(this, component);
- removeNode(clientId);
+ removeNode(clientId, true);
if (clientIds.isEmpty() && shouldCompleteOnEmptyIds()) {
return VisitResult.COMPLETE;
@@ -494,11 +351,15 @@
// Called to initialize our various collections.
private void initializeCollections(Collection<String> clientIds) {
- this.rootNode = new ComponentMatcherNode();
- this.directNodesMap = new HashMap<String, ComponentMatcherNode>();
+ this.subtreeIds = HashMultimap.create();
+ this.directSubtreeIds = ArrayListMultimap.create();
+
this.shortIds = new HashSet<String>();
- this.clientIds = new CollectionProxy();
- this.clientIds.addAll(clientIds);
+
+ this.clientIds = Sets.newHashSet();
+
+ this.proxiedClientIds = new CollectionProxy();
+ this.proxiedClientIds.addAll(clientIds);
}
public VisitContext createNamingContainerVisitContext(UIComponent component,
Collection<String> directIds) {
Added: trunk/core/impl/src/main/java/org/richfaces/context/ClientIdWalker.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/ClientIdWalker.java
(rev 0)
+++ trunk/core/impl/src/main/java/org/richfaces/context/ClientIdWalker.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR_JOINER;
+
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.context.IdParser.Node;
+
+import com.google.common.collect.Lists;
+
+class ClientIdWalker {
+
+ private Node[] parsedId;
+
+ private UIComponent functionTarget;
+
+ private Collection<String> resolvedIds = Lists.newArrayList();
+
+ public ClientIdWalker(Node[] parsedId) {
+ super();
+ this.parsedId = parsedId;
+ }
+
+ private void walk(FacesContext facesContext, UIComponent component, String baseId,
int nodeIdx) {
+
+ boolean isLastNode = (nodeIdx == parsedId.length - 1);
+
+ Node node = parsedId[nodeIdx];
+
+ Collection<String> directSubtreeIds;
+ UIComponent childComponent;
+
+ if (node.getFunction() == null) {
+ directSubtreeIds = Collections.singleton(node.getImage());
+ childComponent = component;
+ } else {
+ directSubtreeIds = evaluateFunction(facesContext, component, baseId, node);
+ //functionTarget is set inside evaluateFunction(...) call!
+ childComponent = functionTarget;
+ }
+
+ for (String directSubtreeId : directSubtreeIds) {
+ String clientId = SEPARATOR_CHAR_JOINER.join(baseId, directSubtreeId);
+
+ if (isLastNode) {
+ resolvedIds.add(clientId);
+ } else {
+ walk(facesContext, childComponent, clientId, nodeIdx + 1);
+ }
+ }
+ }
+
+ private Collection<String> evaluateFunction(FacesContext facesContext,
UIComponent component, String baseId, Node node) {
+ Collection<String> directSubtreeIds;
+ String function = node.getFunction();
+ String image = node.getImage();
+
+ if (!"rows".equals(function)) {
+ throw new IllegalArgumentException(MessageFormat.format("Function {0} is
not supported", function));
+ }
+
+ RowsFunctionContextCallback rowsFunctionCallback = new
RowsFunctionContextCallback(image);
+
+ if (!component.invokeOnComponent(facesContext, baseId, rowsFunctionCallback)) {
+ throw new IllegalStateException(MessageFormat.format("Failed to visit
{0}", baseId));
+ }
+
+ functionTarget = rowsFunctionCallback.getComponent();
+ directSubtreeIds = rowsFunctionCallback.getConvertedKeys();
+ return directSubtreeIds;
+ }
+
+ public void walk(FacesContext facesContext) {
+ walk(facesContext, facesContext.getViewRoot(), null, 0);
+ }
+
+ public Collection<String> getResolvedIds() {
+ return resolvedIds;
+ }
+}
\ No newline at end of file
Modified: trunk/core/impl/src/main/java/org/richfaces/context/ComponentIdResolver.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/ComponentIdResolver.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/main/java/org/richfaces/context/ComponentIdResolver.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -22,6 +22,8 @@
package org.richfaces.context;
import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR;
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR_JOINER;
import java.util.Collection;
import java.util.HashMap;
@@ -33,14 +35,15 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import org.richfaces.component.AjaxContainer;
import org.richfaces.component.ComponentIterators;
import org.richfaces.component.MetaComponentResolver;
+import org.richfaces.context.IdParser.Node;
import org.richfaces.renderkit.util.CoreRendererUtils;
+import com.google.common.base.Strings;
import com.google.common.collect.Iterators;
/**
@@ -65,10 +68,6 @@
private LinkedList<UIComponent> componentsStack = null;
- private IdParser idParser;
-
- private char namingContainerSeparator;
-
private FacesContext facesContext;
private ComponentIdResolverNode rootNode;
@@ -81,8 +80,6 @@
this.resolvedIds = new HashSet<String>();
this.unresolvedIds = new HashSet<String>();
this.rootNode = new ComponentIdResolverNode(null, null);
- this.namingContainerSeparator =
UINamingContainer.getSeparatorChar(facesContext);
- this.idParser = new IdParser(namingContainerSeparator,
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR);
}
private static boolean isNotEmpty(Collection<?> c) {
@@ -166,43 +163,38 @@
}
if (containerClientId != null && containerClientId.length() != 0) {
- StringBuilder builder = new StringBuilder(containerClientId.length() + 1 /*
separator */ + id.length());
- builder.append(containerClientId);
- builder.append(namingContainerSeparator);
- builder.append(id);
- return builder.toString();
+ return SEPARATOR_CHAR_JOINER.join(containerClientId, id);
} else {
return id;
}
}
protected void addIdImmediately(String id) {
- idParser.setId(id);
+ Node[] nodes = IdParser.parse(id);
+
+ ComponentIdResolverNode resolverNode = rootNode;
- ComponentIdResolverNode node = rootNode;
-
- while (idParser.findNext()) {
- String componentId = idParser.getComponentId();
-
- if (componentId.length() == 0) {
+ for (Node node : nodes) {
+ if (node.getFunction() != null) {
continue;
}
-
- if (BaseExtendedVisitContext.ANY_WILDCARD.equals(componentId)) {
- continue;
+
+ String image = node.getImage();
+
+ int metaSepIdx = image.indexOf(META_COMPONENT_SEPARATOR_CHAR);
+ if (metaSepIdx >= 0) {
+ image = image.substring(0, metaSepIdx);
}
- if (componentId.length() > 2 && componentId.charAt(0) ==
'[' &&
- componentId.charAt(componentId.length() - 1) == ']') {
-
+ if (Strings.isNullOrEmpty(image)) {
continue;
}
-
- node = node.getOrCreateChild(componentId);
+
+ resolverNode = resolverNode.getOrCreateChild(image);
}
-
+
unresolvedIds.add(id);
- node.addFullId(id);
+ resolverNode.addFullId(id);
}
public void addId(String id) {
@@ -238,7 +230,7 @@
}
private boolean isAbsolute(String id) {
- return id.charAt(0) == namingContainerSeparator;
+ return id.charAt(0) == SEPARATOR_CHAR;
}
private void buildInversedFilteredTreeRecursively(ComponentIdResolverNode directNode)
{
Deleted: trunk/core/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,345 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.context;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-final class ComponentMatcherNode {
-
- private boolean added;
-
- private boolean patternNode;
-
- private boolean metaComponentNode = false;
-
- private String source;
-
- private boolean hasParentPatternNode;
-
- private int kidPatternNodesCounter = 0;
-
- private ComponentMatcherNode parentNode;
-
- private Map<String, ComponentMatcherNode> idChildren;
-
- private Map<String, ComponentMatcherNode> patternChildren;
-
- private Set<String> subtreeIds;
-
- private static boolean isEmpty(Collection<?> c) {
- return c == null || c.isEmpty();
- }
-
- private static boolean isEmpty(Map<?, ?> m) {
- return m == null || m.isEmpty();
- }
-
- void setParentNode(ComponentMatcherNode parentNode) {
- this.parentNode = parentNode;
- }
-
- void incrementKidPatternNodesCounter() {
- if (kidPatternNodesCounter == 0 && !isPatternNode()) {
- ComponentMatcherNode parentNode = getParentNode();
- if (parentNode != null) {
- parentNode.incrementKidPatternNodesCounter();
- }
- }
-
- kidPatternNodesCounter++;
- }
-
- void decrementKidPatternNodesCounter() {
- kidPatternNodesCounter--;
-
- if (kidPatternNodesCounter == 0 && !isPatternNode()) {
- ComponentMatcherNode parentNode = getParentNode();
- if (parentNode != null) {
- parentNode.decrementKidPatternNodesCounter();
- }
- }
- }
-
- void setHasParentPatternNode(boolean hasParentPatternNode) {
- this.hasParentPatternNode = hasParentPatternNode;
-
- if (!isPatternNode()) {
- if (idChildren != null) {
- for (ComponentMatcherNode child : idChildren.values()) {
- child.setHasParentPatternNode(hasParentPatternNode);
- }
- }
-
- if (patternChildren != null) {
- for (ComponentMatcherNode child : patternChildren.values()) {
- child.setHasParentPatternNode(hasParentPatternNode);
- }
- }
- }
- }
-
- boolean matches(String shortId) {
- if (isPatternNode()) {
- //TODO - modify when real patterns will be supported
- return true;
- } else {
- return source.equals(shortId);
- }
- }
-
- Map<String, ComponentMatcherNode> getChildrenMap(boolean isPattern) {
- return isPattern ? patternChildren : idChildren;
- }
-
- Map<String, ComponentMatcherNode> getOrCreateChildrenMap(boolean isPattern) {
- if (isPattern) {
- if (patternChildren == null) {
- patternChildren = new HashMap<String, ComponentMatcherNode>(1);
- }
-
- return patternChildren;
- } else {
- if (idChildren == null) {
- idChildren = new HashMap<String, ComponentMatcherNode>();
- }
-
- return idChildren;
- }
- }
-
- public String getSource() {
- return source;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
- public ComponentMatcherNode getParentNode() {
- return parentNode;
- }
-
- public ComponentMatcherNode getMatchedChild(String shortId) {
- ComponentMatcherNode node = null;
- if (idChildren != null) {
- node = idChildren.get(shortId);
- }
-
- if (node == null && patternChildren != null) {
- for (ComponentMatcherNode child : patternChildren.values()) {
- if (child.matches(shortId)) {
- node = child;
- break;
- }
- }
- }
-
- return node;
- }
-
- public ComponentMatcherNode getChild(String key, boolean isPatternNode) {
- Map<String, ComponentMatcherNode> childrenMap =
getChildrenMap(isPatternNode);
- if (childrenMap != null) {
- return childrenMap.get(key);
- }
-
- return null;
- }
-
- public ComponentMatcherNode getOrCreateChild(String key, boolean isPatternNode) {
- Map<String, ComponentMatcherNode> childrenMap =
getOrCreateChildrenMap(isPatternNode);
- ComponentMatcherNode childNode = childrenMap.get(key);
- if (childNode == null) {
- childNode = new ComponentMatcherNode();
-
- childNode.setPatternNode(isPatternNode);
- childNode.setSource(key);
-
- addChild(childNode);
- }
-
- return childNode;
- }
-
- public void addChild(ComponentMatcherNode child) {
- child.setParentNode(this);
-
- Map<String, ComponentMatcherNode> childrenMap =
getOrCreateChildrenMap(child.isPatternNode());
-
- ComponentMatcherNode previousNode = childrenMap.get(child.getSource());
- if (previousNode != null) {
- removeChild(previousNode);
- }
-
- childrenMap.put(child.getSource(), child);
-
- if (child.isPatternNode() || child.hasKidPatternNodes()) {
- incrementKidPatternNodesCounter();
- }
-
- if (hasPatternNodeInChain()) {
- child.setHasParentPatternNode(true);
- }
-
- addAllSubtreeIds(child.getSubtreeIds());
- }
-
- public void removeChild(ComponentMatcherNode child) {
- Map<String, ComponentMatcherNode> childrenMap =
getChildrenMap(child.isPatternNode());
- if (childrenMap != null) {
- if (child.getParentNode() == this) {
- child.setParentNode(null);
- child.setHasParentPatternNode(false);
- childrenMap.remove(child.getSource());
-
- if (child.isPatternNode() || child.hasKidPatternNodes()) {
- decrementKidPatternNodesCounter();
- }
-
- removeAllSubtreeIds(child.getSubtreeIds());
- } else {
- //TODO - ?
- }
- }
- }
-
- public boolean hasDirectChildren() {
- return hasDirectIdChildren() || hasDirectPatternChildren();
- }
-
- public boolean hasDirectIdChildren() {
- return !isEmpty(idChildren);
- }
-
- public boolean hasDirectPatternChildren() {
- return !isEmpty(patternChildren);
- }
-
- public boolean hasKidPatternNodes() {
- return kidPatternNodesCounter > 0;
- }
-
- public void markAdded() {
- added = true;
- }
-
- public void markRemoved() {
- added = false;
- }
-
- public boolean isAdded() {
- return added;
- }
-
- public boolean hasParentPatternNode() {
- return hasParentPatternNode;
- }
-
- public boolean hasPatternNodeInChain() {
- return isPatternNode() || hasParentPatternNode();
- }
-
- public Collection<String> getSubtreeIds() {
- return subtreeIds;
- }
-
- public boolean hasSubtreeIds() {
- return !isEmpty(subtreeIds);
- }
-
- public void addAllSubtreeIds(Collection<String> ids) {
- if (ids != null) {
- if (subtreeIds == null) {
- subtreeIds = new HashSet<String>();
- }
-
- subtreeIds.addAll(ids);
-
- if (parentNode != null) {
- parentNode.addAllSubtreeIds(ids);
- }
- }
- }
-
- public void addSubtreeId(String subtreeId) {
- if (subtreeIds == null) {
- subtreeIds = new HashSet<String>();
- }
-
- subtreeIds.add(subtreeId);
-
- if (parentNode != null) {
- parentNode.addSubtreeId(subtreeId);
- }
- }
-
- public void removeAllSubtreeIds(Collection<String> ids) {
- if (ids != null) {
- if (subtreeIds != null) {
- subtreeIds.removeAll(ids);
- }
-
- if (parentNode != null) {
- parentNode.removeAllSubtreeIds(ids);
- }
- }
- }
-
- public void removeSubtreeId(String subtreeId) {
- if (subtreeIds != null) {
- subtreeIds.remove(subtreeId);
- }
-
- if (parentNode != null) {
- parentNode.removeSubtreeId(subtreeId);
- }
- }
-
- public Map<String, ComponentMatcherNode> getIdChildren() {
- return idChildren;
- }
-
- public Map<String, ComponentMatcherNode> getPatternChildren() {
- return patternChildren;
- }
-
- public boolean isPatternNode() {
- return patternNode;
- }
-
- public void setPatternNode(boolean patternNode) {
- this.patternNode = patternNode;
- }
-
- public void setMetaComponentNode(boolean metaComponentNode) {
- this.metaComponentNode = metaComponentNode;
- }
-
- public boolean isMetaComponentNode() {
- return metaComponentNode;
- }
-}
Modified: trunk/core/impl/src/main/java/org/richfaces/context/IdParser.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/IdParser.java 2011-01-18 18:11:00
UTC (rev 21063)
+++ trunk/core/impl/src/main/java/org/richfaces/context/IdParser.java 2011-01-18 19:20:56
UTC (rev 21064)
@@ -21,107 +21,132 @@
*/
package org.richfaces.context;
+import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR_SPLITTER;
+import java.util.List;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Lists;
+
/**
* Helper class for parsing ids.
- *
+ *
* @author Nick Belaevski
*/
final class IdParser {
- private String id;
+ public static final class Node {
- private String componentId;
+ private String image;
- private String metadataComponentId;
+ private String function;
- private int idx;
+ Node(String image) {
+ this(image, null);
+ }
+
+ Node(String image, String function) {
+ super();
+ this.image = image;
+ this.function = function;
+ }
- private final char namingContainerSeparator;
+ public String getImage() {
+ return image;
+ }
- private final char subComponentSeparator;
+ public String getFunction() {
+ return function;
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).add("image",
image).add("function", function).toString();
+ }
- public IdParser(char namingContainerSeparator, char subComponentSeparator) {
- super();
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((function == null) ? 0 : function.hashCode());
+ result = prime * result + ((image == null) ? 0 : image.hashCode());
+ return result;
+ }
- this.namingContainerSeparator = namingContainerSeparator;
- this.subComponentSeparator = subComponentSeparator;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Node other = (Node) obj;
+ if (function == null) {
+ if (other.function != null) {
+ return false;
+ }
+ } else if (!function.equals(other.function)) {
+ return false;
+ }
+ if (image == null) {
+ if (other.image != null) {
+ return false;
+ }
+ } else if (!image.equals(other.image)) {
+ return false;
+ }
+ return true;
+ }
}
- private void reset() {
- this.id = null;
+ private static final char FUNCTION_IMAGE_START_TOKEN = '(';
+
+ private static final char FUNCTION_IMAGE_END_TOKEN = ')';
- this.componentId = null;
- this.metadataComponentId = null;
+ private static final Node[] EMPTY_NODES_ARRAY = new Node[0];
- this.idx = 0;
- }
-
- public void setId(String id) {
- reset();
- this.id = id;
- }
-
- public boolean findNext() {
- componentId = null;
- metadataComponentId = null;
-
- if (id == null) {
- return false;
+ private IdParser() {}
+
+ public static Node[] parse(String id) {
+ if (id.length() == 0) {
+ return EMPTY_NODES_ARRAY;
}
-
- int idLength = id.length();
-
- if (idx < idLength) {
- boolean foundSeparator = false;
-
- for (int i = idx; i < idLength && !foundSeparator; i++) {
- char c = id.charAt(i);
-
- if (c == subComponentSeparator) {
- if (componentId == null) {
- componentId = id.substring(idx, i);
- idx = i;
+
+ List<Node> result = Lists.newArrayList();
+
+ Iterable<String> split = SEPARATOR_CHAR_SPLITTER.split(id);
+ for (String s : split) {
+ if (s.charAt(0) == META_COMPONENT_SEPARATOR_CHAR) {
+ int startImageIdx = s.indexOf(FUNCTION_IMAGE_START_TOKEN);
+
+ if (startImageIdx < 0) {
+ result.add(new Node(s));
+ } else {
+ if (s.charAt(s.length() - 1) != FUNCTION_IMAGE_END_TOKEN) {
+ throw new IllegalArgumentException(id);
}
- } else if (c == namingContainerSeparator) {
- String idSegment = id.substring(idx, i);
-
- if (componentId == null) {
- componentId = idSegment;
- } else {
- metadataComponentId = idSegment;
+
+ if (startImageIdx + 1 > s.length() - 1) {
+ throw new IllegalArgumentException(id);
}
-
- idx = i + 1;
- foundSeparator = true;
+
+ String image = s.substring(startImageIdx + 1, s.length() - 1);
+ String functionName = s.substring(1, startImageIdx);
+
+ result.add(new Node(image, functionName));
}
+ } else {
+ result.add(new Node(s));
}
-
- if (!foundSeparator) {
- String idSegment = id.substring(idx, idLength);
-
- if (componentId == null) {
- componentId = idSegment;
- } else {
- metadataComponentId = idSegment;
- }
-
- idx = idLength;
- }
-
- return true;
- } else {
- reset();
- return false;
}
+
+ return result.toArray(new Node[result.size()]);
}
-
- public String getComponentId() {
- return componentId;
- }
-
- public String getMetadataComponentId() {
- return metadataComponentId;
- }
-
+
+
}
\ No newline at end of file
Added: trunk/core/impl/src/main/java/org/richfaces/context/IdSplitIterator.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/IdSplitIterator.java
(rev 0)
+++ trunk/core/impl/src/main/java/org/richfaces/context/IdSplitIterator.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import static org.richfaces.util.Util.NamingContainerDataHolder.SEPARATOR_CHAR;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.AbstractIterator;
+
+final class IdSplitIterator extends AbstractIterator<String> {
+
+ private String s;
+
+ private String subtreeId;
+
+ private int idx;
+
+ public IdSplitIterator(String s) {
+ super();
+ this.s = s;
+ this.idx = s.length();
+ }
+
+ @Override
+ protected String computeNext() {
+ int oldSepIdx = idx;
+ idx = s.lastIndexOf(SEPARATOR_CHAR, idx - 1);
+
+ String result;
+
+ if (idx >= 0) {
+ result = s.substring(idx + 1, oldSepIdx);
+
+ subtreeId = s.substring(0, idx);
+ } else {
+ if (oldSepIdx < 0) {
+ oldSepIdx = 0;
+ }
+ result = s.substring(0, oldSepIdx);
+
+ subtreeId = null;
+ }
+
+ if (Strings.isNullOrEmpty(result)) {
+ endOfData();
+ }
+
+ return result;
+ }
+
+ public String getSubtreeId() {
+ return subtreeId;
+ }
+
+}
\ No newline at end of file
Deleted: trunk/core/impl/src/main/java/org/richfaces/context/IdTreeNode.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/IdTreeNode.java 2011-01-18
18:11:00 UTC (rev 21063)
+++ trunk/core/impl/src/main/java/org/richfaces/context/IdTreeNode.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,155 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.context;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.richfaces.renderkit.util.CoreAjaxRendererUtils;
-
-final class IdTreeNode {
-
- private static final char LIST_OPENING_CHAR = '[';
-
- private static final char LIST_CLOSING_CHAR = ']';
-
- private String componentId;
-
- private String metadataComponentId;
-
- private List<IdTreeNode> childNodes;
-
- private IdTreeNode(String componentId, String metadataComponentId) {
- this.componentId = componentId;
- this.metadataComponentId = metadataComponentId;
- }
-
- public IdTreeNode() {
- this(null, null);
- }
-
- private void setChildNodes(String[] componentIds) {
- childNodes = new ArrayList<IdTreeNode>(componentIds.length);
- for (String componentId : componentIds) {
- childNodes.add(new IdTreeNode(componentId, null));
- }
- }
-
- private void setChildNode(String componentId, String metadataComponentId) {
- childNodes = Collections.singletonList(new IdTreeNode(componentId,
metadataComponentId));
- }
-
- private void appendToStringBuilder(StringBuilder sb, int indentLevel) {
- for (int i = 0; i < indentLevel; i++) {
- sb.append(' ');
- }
- sb.append('+');
-
- if (componentId != null) {
- sb.append(componentId);
-
- if (metadataComponentId != null) {
- sb.append('(');
- sb.append(metadataComponentId);
- sb.append(')');
- }
-
- } else {
- sb.append("<empty>");
- }
-
- sb.append('\n');
-
- if (childNodes != null) {
- for (IdTreeNode childNode : childNodes) {
- childNode.appendToStringBuilder(sb, indentLevel + 2);
- }
- }
- }
-
- public void appendNodesFromParser(IdParser idParser) {
- List<IdTreeNode> nodes = Collections.singletonList(this);
-
- while (idParser.findNext()) {
- String componentId = idParser.getComponentId();
- String metadataComponentId = idParser.getMetadataComponentId();
-
- int childNodesCount = 0;
-
- if (metadataComponentId != null) {
- for (IdTreeNode node : nodes) {
- node.setChildNode(componentId, metadataComponentId);
- childNodesCount++;
- }
- } else {
- if (componentId.length() > 2 && componentId.charAt(0) ==
LIST_OPENING_CHAR &&
- componentId.charAt(componentId.length() - 1) == LIST_CLOSING_CHAR) {
-
- String[] split =
CoreAjaxRendererUtils.asIdsArray(componentId.substring(1, componentId.length() - 1));
- for (IdTreeNode node : nodes) {
- node.setChildNodes(split);
- childNodesCount += split.length;
- }
- } else {
- for (IdTreeNode node : nodes) {
- node.setChildNode(componentId, null);
- childNodesCount++;
- }
- }
- }
-
- List<IdTreeNode> newNodesList;
- if (nodes.size() == 1) {
- newNodesList = nodes.get(0).getChildNodes();
- } else {
- newNodesList = new ArrayList<IdTreeNode>(childNodesCount);
- for (IdTreeNode node : nodes) {
- newNodesList.addAll(node.getChildNodes());
- }
- }
-
- nodes = newNodesList;
- }
- }
-
- public List<IdTreeNode> getChildNodes() {
- return childNodes;
- }
-
- public String getComponentId() {
- return componentId;
- }
-
- public String getMetadataComponentId() {
- return metadataComponentId;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- appendToStringBuilder(sb, 0);
-
- return sb.toString();
- }
-}
Added:
trunk/core/impl/src/main/java/org/richfaces/context/RowsFunctionContextCallback.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/context/RowsFunctionContextCallback.java
(rev 0)
+++
trunk/core/impl/src/main/java/org/richfaces/context/RowsFunctionContextCallback.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import java.util.Collection;
+
+import javax.faces.component.ContextCallback;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import com.google.common.collect.Lists;
+
+final class RowsFunctionContextCallback implements ContextCallback {
+
+ private final String image;
+
+ private UIComponent component;
+
+ private Collection<String> convertedKeys = Lists.newArrayList();
+
+ RowsFunctionContextCallback(String image) {
+ this.image = image;
+ }
+
+ public void invokeContextCallback(FacesContext context, UIComponent target) {
+ component = target;
+
+ Converter rowKeyConverter = (Converter)
target.getAttributes().get("rowKeyConverter");
+
+ Collection<?> keys = (Collection<?>)
context.getApplication().evaluateExpressionGet(context, "#{" + image +
"}", Object.class);
+
+ for (Object key : keys) {
+ String convertedKey;
+
+ if (rowKeyConverter != null) {
+ convertedKey = rowKeyConverter.getAsString(context, target, key);
+ } else {
+ convertedKey = key.toString();
+ }
+
+ convertedKeys.add(convertedKey);
+ }
+
+ }
+
+ public UIComponent getComponent() {
+ return component;
+ }
+
+ public Collection<String> getConvertedKeys() {
+ return convertedKeys;
+ }
+}
\ No newline at end of file
Modified: trunk/core/impl/src/main/java/org/richfaces/util/Util.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/util/Util.java 2011-01-18 18:11:00 UTC
(rev 21063)
+++ trunk/core/impl/src/main/java/org/richfaces/util/Util.java 2011-01-18 19:20:56 UTC
(rev 21064)
@@ -76,6 +76,7 @@
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.StateHolder;
+import javax.faces.component.UINamingContainer;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -85,6 +86,8 @@
import org.richfaces.log.RichfacesLogger;
import org.richfaces.resource.StateHolderResource;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
import com.google.common.base.Strings;
/**
@@ -96,14 +99,6 @@
private static final Pattern RESOURCE_PARAMS_SPLIT_PATTERN =
Pattern.compile("\\s*(\\s|,)\\s*");
private static final Pattern RESOURCE_PARAMS =
Pattern.compile("\\{([^\\}]*)\\}\\s*$");
- private static final String DATA_BYTES_SEPARATOR = "/DATB/";
- private static final String DATA_SEPARATOR = "/DATA/";
-
- // index of capturing group denoting version
- private static final int DATA_SEPARATOR_DATA_GROUP_INDEX = 2;
-
- // index of capturing group denoting data type encoded
- private static final int DATA_SEPARATOR_TYPE_GROUP_INDEX = 1;
private static final Logger RESOURCE_LOGGER = RichfacesLogger.RESOURCE.getLogger();
/* HTTP Date format required by the HTTP/1.1 RFC */
@@ -111,14 +106,24 @@
// TODO codec have settings
private static final Codec CODEC = new Codec();
- private static final String VERSION_SEPARATOR = "/VER";
- private static final Pattern DATA_SEPARATOR_PATTERN =
Pattern.compile("/DAT(A|B)/([^/]*)");
private static final SimpleDateFormat RFC1123_DATE_FORMATTER;
private static final String QUESTION_SIGN = "?";
private static final String EQUALS_SIGN = "=";
private static final Pattern CHARSET_IN_CONTENT_TYPE_PATTERN =
Pattern.compile(";\\s*charset\\s*=\\s*([^\\s;]+)", Pattern.CASE_INSENSITIVE);
+ public static final class NamingContainerDataHolder {
+
+ public static final char SEPARATOR_CHAR =
UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance());
+
+ public static final Joiner SEPARATOR_CHAR_JOINER =
Joiner.on(SEPARATOR_CHAR).skipNulls();
+
+ public static final Splitter SEPARATOR_CHAR_SPLITTER =
Splitter.on(SEPARATOR_CHAR);
+
+ private NamingContainerDataHolder() {}
+
+ }
+
static {
SimpleDateFormat format = new SimpleDateFormat(RFC1123_DATE_PATTERN, Locale.US);
@@ -286,105 +291,7 @@
return null;
}
-
- public static String legacyEncodeResourceData(String resourceName, Object storeData,
String resourceVersion) {
- StringBuilder uri = new StringBuilder(); //
ResourceServlet.DEFAULT_SERVLET_PATH).append("/");
- uri.append(resourceName);
-
- // append serialized data as Base-64 encoded request string.
- if (storeData != null) {
- String encodedData;
- if (storeData instanceof byte[]) {
- encodedData = encodeBytesData((byte[]) storeData);
-
- if (encodedData != null) {
- uri.append(DATA_BYTES_SEPARATOR);
- uri.append(encodedData);
- }
-
- } else {
- encodedData = encodeObjectData(storeData);
-
- if (encodedData != null) {
- uri.append(DATA_SEPARATOR);
- uri.append(encodedData);
- }
- }
- }
-
- if ((resourceVersion != null) && (resourceVersion.length() != 0)) {
- uri.append(VERSION_SEPARATOR);
- uri.append(resourceVersion);
- }
-
-// boolean isGlobal = !resource.isSessionAware();
-// String resourceURL = getFacesResourceURL(context,
-// uri.toString(), false /*isGlobal*/);//
context.getApplication().getViewHandler()
-// .getResourceURL(context,uri.toString());
- // if (!isGlobal) {
- // resourceURL = context.getExternalContext().encodeResourceURL(
- // resourceURL);
- // }
-// if (log.isDebugEnabled()) {
-// log.debug(Messages.getMessage(Messages.BUILD_RESOURCE_URI_INFO,
-// resource.getKey(), resourceURL));
-// }
- return uri.toString(); //
context.getExternalContext().encodeResourceURL(resourceURL);
- }
-
- public static String legacyDecodeResourceName(String resourceUri) {
- String resourceName = resourceUri;
- Matcher matcher = DATA_SEPARATOR_PATTERN.matcher(resourceName);
-
- if (matcher.find()) {
- int data = matcher.start();
-
- resourceName = resourceName.substring(0, data);
- } else {
- int idx = resourceName.indexOf(VERSION_SEPARATOR);
-
- if (idx > 0) {
- resourceName = resourceName.substring(0, idx);
- }
- }
-
- return resourceName;
- }
-
- public static String legacyDecodeResourceVersion(String resourceUri) {
- int idx = resourceUri.indexOf(VERSION_SEPARATOR);
-
- if (idx > 0) {
- return resourceUri.substring(idx + VERSION_SEPARATOR.length());
- }
-
- return null;
- }
-
- public static Object legacyDecodeResourceData(String resourceUri) {
- Object data = null;
- Matcher matcher = DATA_SEPARATOR_PATTERN.matcher(resourceUri);
-
- if (!matcher.find()) {
- return data;
- }
-
- if (RESOURCE_LOGGER.isDebugEnabled()) {
-
RESOURCE_LOGGER.debug(Messages.getMessage(Messages.RESTORE_DATA_FROM_RESOURCE_URI_INFO,
resourceUri, null));
- }
-
- String dataString = matcher.group(DATA_SEPARATOR_DATA_GROUP_INDEX);
-
- if ("B".equals(matcher.group(DATA_SEPARATOR_TYPE_GROUP_INDEX))) {
- data = decodeBytesData(dataString);
- } else {
- data = decodeObjectData(dataString);
- }
-
- return data;
- }
-
public static String encodeJSFURL(FacesContext context, String url) {
String mapping = Util.getMappingForRequest(context);
String resourcePath = url;
Modified:
trunk/core/impl/src/test/java/org/richfaces/context/ComponentIdResolverTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/context/ComponentIdResolverTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/test/java/org/richfaces/context/ComponentIdResolverTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -146,27 +146,25 @@
@Test
public void testFindByWildcardId() throws Exception {
ComponentIdResolver resolver = createComponentIdResolver();
- resolver.addId("table:*:input");
- resolver.addId("table:[*]:header");
- resolver.addId("table:[1 2]:column");
+ resolver.addId("table:@rows(inputKeys):input");
resolver.resolve(evaluateComponentExpression("#{testBean.table}"));
Set<String> resolvedIds = resolver.getResolvedIds();
- assertEquals(asSet("form:table:*:input",
"form:table:[*]:header", "form:table:[1 2]:column"), resolvedIds);
+ assertEquals(asSet("form:table:@rows(inputKeys):input"), resolvedIds);
}
@Test
public void testFindByMetaComponentId() throws Exception {
ComponentIdResolver resolver = createComponentIdResolver();
resolver.addId("input@text");
- resolver.addId("table:[*]:header@head");
- resolver.addId("table:[*]:header@footer");
+ resolver.addId("table:@rows(headerKeys):header@head");
+ resolver.addId("table:@rows(footerKeys):header@footer");
resolver.resolve(viewRoot);
Set<String> resolvedIds = resolver.getResolvedIds();
- assertEquals(asSet("form:table:[*]:header@footer",
"form:table:[*]:header@head", "form:table:input@text"), resolvedIds);
+ assertEquals(asSet("form:table:@rows(footerKeys):header@footer",
"form:table:@rows(headerKeys):header@head", "form:table:input@text"),
resolvedIds);
}
@Test
Deleted:
trunk/core/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,337 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.context;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ComponentMatcherNodeTest {
-
- private ComponentMatcherNode rootNode;
-
- @Before
- public void setUp() throws Exception {
- rootNode = new ComponentMatcherNode();
- }
-
- @After
- public void tearDown() throws Exception {
- rootNode = null;
- }
-
- private ComponentMatcherNode createNode(String source, boolean isPattern) {
- ComponentMatcherNode node = new ComponentMatcherNode();
- node.setSource(source);
- node.setPatternNode(isPattern);
-
- return node;
- }
-
- @Test
- public void testIdChild() throws Exception {
- ComponentMatcherNode idNode = createNode("table", false);
-
- assertNull(rootNode.getChild("table", false));
- assertNull(rootNode.getChild("table2", false));
-
- rootNode.addChild(idNode);
-
- assertSame(rootNode, idNode.getParentNode());
- assertNotNull(rootNode.getIdChildren());
- assertTrue(rootNode.hasDirectIdChildren());
- assertTrue(rootNode.hasDirectChildren());
- assertFalse(rootNode.hasDirectPatternChildren());
- assertFalse(rootNode.hasKidPatternNodes());
-
- assertSame(idNode, rootNode.getChild("table", false));
- assertSame(idNode, rootNode.getMatchedChild("table"));
-
- assertNull(rootNode.getChild("table2", false));
- assertNull(rootNode.getChild("xChild", false));
- assertNull(rootNode.getMatchedChild("xChild"));
-
- ComponentMatcherNode id2Node = createNode("table2", false);
- rootNode.addChild(id2Node);
- assertSame(idNode, rootNode.getChild("table", false));
- assertSame(id2Node, rootNode.getChild("table2", false));
- assertSame(id2Node, rootNode.getMatchedChild("table2"));
-
- rootNode.removeChild(idNode);
- rootNode.removeChild(id2Node);
-
- assertNull(idNode.getParentNode());
- assertFalse(rootNode.hasDirectIdChildren());
- assertFalse(rootNode.hasDirectChildren());
- assertFalse(rootNode.hasDirectPatternChildren());
- assertFalse(rootNode.hasKidPatternNodes());
-
- assertNull(rootNode.getChild("table", false));
- assertNull(rootNode.getMatchedChild("table"));
- }
-
- @Test
- public void testMarkAddedRemoved() throws Exception {
- ComponentMatcherNode idNode = createNode("table", false);
- ComponentMatcherNode patternNode = createNode("*", true);
-
- assertFalse(idNode.isAdded());
- assertFalse(patternNode.isAdded());
-
- rootNode.addChild(idNode);
- assertFalse(idNode.isAdded());
- assertFalse(rootNode.isAdded());
-
- idNode.markAdded();
- assertSame(idNode, rootNode.getChild("table", false));
- assertTrue(idNode.isAdded());
- assertFalse(rootNode.isAdded());
-
- idNode.markRemoved();
- assertSame(idNode, rootNode.getChild("table", false));
- assertFalse(idNode.isAdded());
- assertFalse(rootNode.isAdded());
-
- rootNode.addChild(patternNode);
- assertFalse(patternNode.isAdded());
- assertFalse(rootNode.isAdded());
-
- patternNode.markAdded();
- assertSame(patternNode, rootNode.getChild("*", true));
- assertTrue(patternNode.isAdded());
- assertFalse(rootNode.isAdded());
-
- patternNode.markRemoved();
- assertSame(patternNode, rootNode.getChild("*", true));
- assertFalse(patternNode.isAdded());
- assertFalse(rootNode.isAdded());
- }
-
- @Test
- public void testPatternChild() throws Exception {
- ComponentMatcherNode patternNode = createNode("*", true);
-
- assertNull(rootNode.getChild("*", true));
-
- rootNode.addChild(patternNode);
-
- assertSame(rootNode, patternNode.getParentNode());
- assertNotNull(rootNode.getPatternChildren());
- assertFalse(rootNode.hasDirectIdChildren());
- assertTrue(rootNode.hasDirectChildren());
- assertTrue(rootNode.hasDirectPatternChildren());
- assertTrue(rootNode.hasKidPatternNodes());
-
- assertSame(patternNode, rootNode.getChild("*", true));
- assertSame(patternNode, rootNode.getMatchedChild("anyId"));
- assertSame(patternNode, rootNode.getMatchedChild("justAnotherId"));
-
- rootNode.removeChild(patternNode);
- assertNull(patternNode.getParentNode());
- assertFalse(rootNode.hasDirectIdChildren());
- assertFalse(rootNode.hasDirectChildren());
- assertFalse(rootNode.hasDirectPatternChildren());
- assertFalse(rootNode.hasKidPatternNodes());
-
- assertNull(rootNode.getChild("*", true));
- assertNull(rootNode.getMatchedChild("anyId"));
- assertNull(rootNode.getMatchedChild("justAnotherId"));
- }
-
- private boolean hasPatternParent(ComponentMatcherNode node) {
- ComponentMatcherNode pNode = node;
- while ((pNode = pNode.getParentNode()) != null) {
- if (pNode.isPatternNode()) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean hasPatternKids(Map<String, ComponentMatcherNode> nodesMap) {
- if (nodesMap == null) {
- return false;
- }
-
- for (ComponentMatcherNode node : nodesMap.values()) {
- if (node.isPatternNode()) {
- return true;
- }
-
- if (hasPatternKids(node.getIdChildren())) {
- return true;
- }
-
- if (hasPatternKids(node.getPatternChildren())) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean hasPatternKids(ComponentMatcherNode node) {
- if (hasPatternKids(node.getIdChildren())) {
- return true;
- }
-
- if (hasPatternKids(node.getPatternChildren())) {
- return true;
- }
-
- return false;
- }
-
- private void verifyNodeChildren(Map<String, ComponentMatcherNode> nodesMap) {
- if (nodesMap != null) {
- for (ComponentMatcherNode childNode : nodesMap.values()) {
- verifyNode(childNode);
- }
- }
- }
-
- private void verifyNode(ComponentMatcherNode node) {
- assertTrue(hasPatternParent(node) == node.hasParentPatternNode());
- assertTrue(hasPatternKids(node) == node.hasKidPatternNodes());
-
- verifyNodeChildren(node.getIdChildren());
- verifyNodeChildren(node.getPatternChildren());
- }
-
- @Test
- public void testAddChild() throws Exception {
- verifyNode(rootNode);
-
- ComponentMatcherNode tableNode = createNode("table", false);
- rootNode.addChild(tableNode);
- verifyNode(rootNode);
- assertSame(tableNode, rootNode.getChild("table", false));
- assertSame(tableNode, rootNode.getMatchedChild("table"));
-
- ComponentMatcherNode tablePatternNode = createNode("table-*", true);
- rootNode.addChild(tablePatternNode);
- verifyNode(rootNode);
- assertSame(tablePatternNode, rootNode.getChild("table-*", true));
- assertSame(tablePatternNode, rootNode.getMatchedChild("anyChild"));
-
- ComponentMatcherNode rowNode = createNode("row", false);
- tableNode.addChild(rowNode);
- verifyNode(rootNode);
- assertSame(rowNode, tableNode.getChild("row", false));
- assertSame(rowNode, tableNode.getMatchedChild("row"));
-
- ComponentMatcherNode cellPatternNode = createNode("cell-*", true);
- rowNode.addChild(cellPatternNode);
- verifyNode(rootNode);
- assertSame(cellPatternNode, rowNode.getChild("cell-*", true));
- assertSame(cellPatternNode, rowNode.getMatchedChild("anyCell"));
-
- ComponentMatcherNode secondRowNode = createNode("row", false);
- tablePatternNode.addChild(secondRowNode);
- verifyNode(rootNode);
- assertSame(secondRowNode, tablePatternNode.getChild("row", false));
- assertSame(secondRowNode, tablePatternNode.getMatchedChild("row"));
-
- ComponentMatcherNode secondCellPatternNode = createNode("cell-*",
true);
- secondRowNode.addChild(secondCellPatternNode);
- verifyNode(rootNode);
- assertSame(secondCellPatternNode, secondRowNode.getChild("cell-*",
true));
- assertSame(secondCellPatternNode,
secondRowNode.getMatchedChild("anyCell"));
- }
-
- @Test
- public void testRemoveChild() throws Exception {
- ComponentMatcherNode tableNode = createNode("table", false);
- rootNode.addChild(tableNode);
-
- ComponentMatcherNode tablePatternNode = createNode("table-*", true);
- rootNode.addChild(tablePatternNode);
-
- ComponentMatcherNode rowNode = createNode("row", false);
- tableNode.addChild(rowNode);
-
- ComponentMatcherNode cellPatternNode = createNode("cell-*", true);
- rowNode.addChild(cellPatternNode);
-
- ComponentMatcherNode secondRowNode = createNode("row", false);
- tablePatternNode.addChild(secondRowNode);
-
- ComponentMatcherNode secondCellPatternNode = createNode("cell-*",
true);
- secondRowNode.addChild(secondCellPatternNode);
-
- verifyNode(rootNode);
-
- assertSame(secondCellPatternNode, secondRowNode.getChild("cell-*",
true));
- assertSame(secondCellPatternNode,
secondRowNode.getMatchedChild("anyCell"));
- secondRowNode.removeChild(secondCellPatternNode);
- assertNull(secondRowNode.getChild("cell-*", true));
- assertNull(secondRowNode.getMatchedChild("anyCell"));
-
- verifyNode(rootNode);
-
- assertSame(rowNode, tableNode.getChild("row", false));
- assertSame(rowNode, tableNode.getMatchedChild("row"));
- tableNode.removeChild(rowNode);
- assertNull(tableNode.getChild("row", false));
- assertNull(tableNode.getMatchedChild("row"));
-
- verifyNode(rootNode);
-
- assertSame(secondRowNode, tablePatternNode.getChild("row", false));
- assertSame(secondRowNode, tablePatternNode.getMatchedChild("row"));
- tablePatternNode.removeChild(secondRowNode);
- assertNull(tablePatternNode.getChild("row", false));
- assertNull(tablePatternNode.getMatchedChild("row"));
-
- verifyNode(rootNode);
-
- assertSame(tablePatternNode, rootNode.getChild("table-*", true));
- assertSame(tablePatternNode, rootNode.getMatchedChild("anyChild"));
- rootNode.removeChild(tablePatternNode);
- assertNull(rootNode.getChild("table-*", true));
- assertNull(rootNode.getMatchedChild("anyChild"));
-
- verifyNode(rootNode);
-
- assertSame(tableNode, rootNode.getChild("table", false));
- assertSame(tableNode, rootNode.getMatchedChild("table"));
- rootNode.removeChild(tableNode);
- assertNull(rootNode.getChild("table", false));
- assertNull(rootNode.getMatchedChild("table"));
-
- verifyNode(rootNode);
- }
-}
Modified:
trunk/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -379,7 +379,7 @@
assertNotNull(iterator);
assertFalse(iterator.hasNext());
- Set<String> idsToAdd = asSet("someIds",
"thisIs:evenBetter", "id:*:x");
+ Set<String> idsToAdd = asSet("someIds",
"thisIs:evenBetter", "myForm:table:0:nestedText");
idsToVisit.addAll(idsToAdd);
assertFalse(idsToVisit.isEmpty());
@@ -472,11 +472,11 @@
renderingContext.getIdsToVisit().add("myForm:table:theHeader");
renderingContext.getIdsToVisit().add("myForm:table:1:nestedOutput");
renderingContext.getIdsToVisit().add("myForm:table:0:nestedText");
- renderingContext.getIdsToVisit().add("myForm:table:0:nestedTable:1");
+
renderingContext.getIdsToVisit().add("myForm:table:0:nestedTable:1:nestedTableText");
renderingContext.getIdsToVisit().add("myForm:table:0:nestedTable:nestedFooter");
Set<String> formClientIds = asSet("myForm:outerOutput",
"myForm:table:0:nestedText",
- "myForm:table:1:nestedOutput", "myForm:table:theHeader",
"myForm:table:0:nestedTable:1",
+ "myForm:table:1:nestedOutput", "myForm:table:theHeader",
"myForm:table:0:nestedTable:1:nestedTableText",
"myForm:table:0:nestedTable:nestedFooter");
Set<String> formIds = asSet("table", "outerOutput");
@@ -485,7 +485,7 @@
assertEqualSets(formIds, renderingContext.getDirectSubtreeIdsToVisit(form));
Set<String> tableClientIds = asSet("myForm:table:0:nestedText",
"myForm:table:1:nestedOutput",
- "myForm:table:theHeader", "myForm:table:0:nestedTable:1",
"myForm:table:0:nestedTable:nestedFooter");
+ "myForm:table:theHeader",
"myForm:table:0:nestedTable:1:nestedTableText",
"myForm:table:0:nestedTable:nestedFooter");
Set<String> tableIds = asSet("0", "1",
"theHeader");
assertEqualSets(tableClientIds, renderingContext.getSubtreeIdsToVisit(table));
@@ -493,7 +493,7 @@
table.setRowIndex(0);
- Set<String> nestedTableClientIds =
asSet("myForm:table:0:nestedTable:1",
+ Set<String> nestedTableClientIds =
asSet("myForm:table:0:nestedTable:1:nestedTableText",
"myForm:table:0:nestedTable:nestedFooter");
Set<String> nestedTableIds = asSet("nestedFooter",
"1");
@@ -504,46 +504,6 @@
}
@Test
- public void testSubtreeIdsForWildcardIds() throws Exception {
- createVisitContext(false);
- renderingContext.getIdsToVisit().add("myForm:table:*:nestedText");
- renderingContext.getIdsToVisit().add("myForm:table:*:nestedTable:0");
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(form));
- assertEqualSets(asSet("table", "outerOutput"),
renderingContext.getDirectSubtreeIdsToVisit(form));
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(table));
- assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
- }
-
- @Test
- public void testSubtreeIdsForWildcardIdsWithLimitRender() throws Exception {
- createVisitContext(true);
- renderingContext.getIdsToVisit().add("myForm:table:*:nestedText");
- renderingContext.getIdsToVisit().add("myForm:table:*:nestedTable:0");
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(form));
- assertEqualSets(asSet("table"),
renderingContext.getDirectSubtreeIdsToVisit(form));
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(table));
- assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
- }
-
- @Test
- public void testSubtreeIdsForWildcardIds2WithLimitRender() throws Exception {
- createVisitContext(true);
- renderingContext.getIdsToVisit().add("myForm:table:*:nestedTable");
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(form));
- assertEqualSets(asSet("table"),
renderingContext.getDirectSubtreeIdsToVisit(form));
-
- assertSame(VisitContext.ALL_IDS, renderingContext.getSubtreeIdsToVisit(table));
- assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
-
- table.setRowIndex(-1);
- }
-
- @Test
public void testVisitCallbackForEmptyIds() throws Exception {
createVisitContext(false);
@@ -593,20 +553,10 @@
renderingContext.getIdsToVisit().add("myForm:table:1:nestedTable@footer");
boolean visitResult = viewRoot.visitTree(renderingContext,
trackingVisitCallback);
- assertTrue(visitResult);
-
+
assertEquals(Arrays.asList("myForm:table:1:nestedTable@footer"),
trackingVisitCallback.getVisitedIds());
- }
- @Test
- public void testVisitMetaComponentsWithWildcardsWithLimitRender() throws Exception {
- createVisitContext(true);
-
renderingContext.getIdsToVisit().add("myForm:table:*:nestedTable@footer");
-
- viewRoot.visitTree(renderingContext, trackingVisitCallback);
-
- assertEquals(Arrays.asList("myForm:table:0:nestedTable@footer",
"myForm:table:1:nestedTable@footer"),
- trackingVisitCallback.getVisitedIds());
+ assertTrue(visitResult);
}
@Test
@@ -636,7 +586,7 @@
public void testFormVisitContextWithLimitRender() throws Exception {
createVisitContext(true);
- renderingContext.getIdsToVisit().add("myForm:table:0");
+ renderingContext.getIdsToVisit().add("myForm:table:0:nestedText");
Collection<String> formDirectIds =
renderingContext.getDirectSubtreeIdsToVisit(form);
assertNotSame(VisitContext.ALL_IDS, formDirectIds);
@@ -685,7 +635,10 @@
public void testVisitMultiple() throws Exception {
createVisitContext(true);
- renderingContext.getIdsToVisit().add("myForm:table:[ 0, 1 ]:nestedTable:[ 1
]:nestedTableText");
+ String idFormat = "myForm:table:{0}:nestedTable:1:nestedTableText";
+
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 0));
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 1));
boolean visitResult = viewRoot.visitTree(renderingContext,
trackingVisitCallback);
assertTrue(visitResult);
@@ -697,20 +650,24 @@
public void testVisitMultipleWithPatternAndMetacomponent() throws Exception {
createVisitContext(true);
- renderingContext.getIdsToVisit().add("myForm:table:[ 0, 1
]:nestedTable:*:nestedTableText");
-
renderingContext.getIdsToVisit().add("myForm:table:[0]:nestedTable@footer");
+ String idFormat = "myForm:table:{0}:nestedTable:{1}:nestedTableText";
+
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 0, 0));
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 0, 1));
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 1, 0));
+ renderingContext.getIdsToVisit().add(MessageFormat.format(idFormat, 1, 1));
+
renderingContext.getIdsToVisit().add("myForm:table:0:nestedTable@footer");
+
viewRoot.visitTree(renderingContext, trackingVisitCallback);
assertEquals(Arrays.asList(
"myForm:table:0:nestedTable@footer",
"myForm:table:0:nestedTable:0:nestedTableText",
"myForm:table:0:nestedTable:1:nestedTableText",
- "myForm:table:0:nestedTable:2:nestedTableText",
"myForm:table:1:nestedTable:0:nestedTableText",
- "myForm:table:1:nestedTable:1:nestedTableText",
- "myForm:table:1:nestedTable:2:nestedTableText"
+ "myForm:table:1:nestedTable:1:nestedTableText"
), trackingVisitCallback.getVisitedIds());
}
@@ -729,5 +686,17 @@
assertFalse(renderingContext.getIdsToVisit().contains("table"));
assertFalse(renderingContext.getIdsToVisit().contains("myForm:table"));
}
+
+ @Test
+ public void testVisitForm() throws Exception {
+ createVisitContext(true);
+
+ renderingContext.getIdsToVisit().add("myForm");
+
+ boolean result = facesContext.getViewRoot().visitTree(renderingContext,
trackingVisitCallback);
+
+ assertTrue(result);
+ assertEquals(Arrays.asList("myForm"),
trackingVisitCallback.getVisitedIds());
+ }
}
Modified: trunk/core/impl/src/test/java/org/richfaces/context/IdParserTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/context/IdParserTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++ trunk/core/impl/src/test/java/org/richfaces/context/IdParserTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
+ * Copyright 2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -21,163 +21,76 @@
*/
package org.richfaces.context;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.fail;
+import static org.richfaces.context.IdParser.parse;
-import org.junit.After;
+import java.util.HashMap;
+
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.context.IdParser.Node;
-
/**
* @author Nick Belaevski
- *
+ *
*/
+(a)RunWith(MockTestRunner.class)
public class IdParserTest {
- private IdParser idParser;
-
+ @Mock
+ @Environment({Environment.Feature.EXTERNAL_CONTEXT})
+ private MockFacesEnvironment environment;
+
@Before
public void setUp() throws Exception {
- idParser = new IdParser(':', '@');
+ environment.resetToNice();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ expect(facesContext.getAttributes()).andStubReturn(new HashMap<Object,
Object>());
+ environment.replay();
}
-
- @After
- public void tearDown() throws Exception {
- idParser = null;
- }
-
+
@Test
- public void testIncorrectIds() throws Exception {
- idParser.setId("");
-
- idParser.findNext();
- assertFalse(idParser.findNext());
-
- idParser.setId(":test");
-
- idParser.findNext();
- idParser.findNext();
- assertFalse(idParser.findNext());
-
- idParser.setId("test:");
-
- idParser.findNext();
- idParser.findNext();
- assertFalse(idParser.findNext());
-
- idParser.setId("@head");
-
- idParser.findNext();
- assertFalse(idParser.findNext());
-
- idParser.setId("head@");
-
- idParser.findNext();
- assertFalse(idParser.findNext());
- }
-
- @Test
public void testSimpleId() throws Exception {
- idParser.setId("simpleId");
-
- assertTrue(idParser.findNext());
- assertEquals("simpleId", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertFalse(idParser.findNext());
+ assertArrayEquals(new Node[0], parse(""));
+ assertArrayEquals(new Node[] { new Node("test") },
parse("test"));
+ assertArrayEquals(new Node[] { new Node("form"), new
Node("table") }, parse("form:table"));
}
@Test
- public void testSubComponentId() throws Exception {
- idParser.setId("table@head");
-
- assertTrue(idParser.findNext());
- assertEquals("@head", idParser.getMetadataComponentId());
- assertEquals("table", idParser.getComponentId());
-
- assertFalse(idParser.findNext());
+ public void testRowsFunction() throws Exception {
+ try {
+ parse("form:table:@rows(");
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ignore
+ }
+
+ try {
+ parse("form:table:@rows(12");
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ignore
+ }
+
+ assertArrayEquals(new Node[] { new Node("form"), new
Node("table"), new Node("", "rows"), new
Node("@row") }, parse("form:table:@rows():@row"));
+ assertArrayEquals(new Node[] { new Node("form"), new
Node("table"), new Node("12", "rows") },
parse("form:table:@rows(12)"));
+ assertArrayEquals(new Node[] { new Node("form"), new
Node("table"), new Node("", "rows"), new
Node("subtable") },
+ parse("form:table:@rows():subtable"));
+
+ assertArrayEquals(new Node[] {
+ new Node("form"), new Node("table"), new
Node("12", "rows"), new Node("subtable"),
+ new Node("a", "rows"), new Node("cell") },
+ parse("form:table:@rows(12):subtable:@rows(a):cell"));
+
}
-
- @Test
- public void testSeries() throws Exception {
- idParser.setId("form:table:0:nestedTable@body");
-
- assertTrue(idParser.findNext());
- assertEquals("form", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("table", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("0", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("@body", idParser.getMetadataComponentId());
- assertEquals("nestedTable", idParser.getComponentId());
-
- assertFalse(idParser.findNext());
-
- idParser.setId("myBigTable@header");
-
- assertTrue(idParser.findNext());
- assertEquals("@header", idParser.getMetadataComponentId());
- assertEquals("myBigTable", idParser.getComponentId());
-
- assertFalse(idParser.findNext());
-
- idParser.setId("tree:0-12-28:node@status:table:10:tab@label");
-
- assertTrue(idParser.findNext());
- assertEquals("tree", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("0-12-28", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("@status", idParser.getMetadataComponentId());
- assertEquals("node", idParser.getComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("table", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("10", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("@label", idParser.getMetadataComponentId());
- assertEquals("tab", idParser.getComponentId());
-
- assertFalse(idParser.findNext());
- }
-
- @Test
- public void testNestedSubcomponents() throws Exception {
- //TODO - review this test - behavior is not clear for now
-
- idParser.setId("form:table@head@x-head:child");
-
- assertTrue(idParser.findNext());
- assertEquals("form", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("@head@x-head", idParser.getMetadataComponentId());
- assertEquals("table", idParser.getComponentId());
-
- assertTrue(idParser.findNext());
- assertEquals("child", idParser.getComponentId());
- assertNull(idParser.getMetadataComponentId());
-
- assertFalse(idParser.findNext());
- }
+
}
Added: trunk/core/impl/src/test/java/org/richfaces/context/IdSplitIteratorTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/context/IdSplitIteratorTest.java
(rev 0)
+++
trunk/core/impl/src/test/java/org/richfaces/context/IdSplitIteratorTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class IdSplitIteratorTest {
+
+ @Mock
+ @Environment({Environment.Feature.EXTERNAL_CONTEXT})
+ private MockFacesEnvironment environment;
+
+ @Before
+ public void setUp() throws Exception {
+ environment.resetToNice();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ expect(facesContext.getAttributes()).andStubReturn(new HashMap<Object,
Object>());
+ environment.replay();
+ }
+
+ @Test
+ public void testEmptyString() throws Exception {
+ IdSplitIterator iterator = new IdSplitIterator("");
+
+ assertFalse(iterator.hasNext());
+
+ try {
+ iterator.next();
+ fail();
+ } catch (NoSuchElementException e) {
+ //ignore
+ }
+
+ assertNull(iterator.getSubtreeId());
+ }
+
+ @Test
+ public void testSimpleString() throws Exception {
+ IdSplitIterator iterator = new IdSplitIterator("id");
+
+ assertTrue(iterator.hasNext());
+
+ assertEquals("id", iterator.next());
+ assertNull(iterator.getSubtreeId());
+
+ assertFalse(iterator.hasNext());
+
+ try {
+ iterator.next();
+ fail();
+ } catch (NoSuchElementException e) {
+ //ignore
+ }
+
+ assertNull(iterator.getSubtreeId());
+ }
+
+ @Test
+ public void testTwoSegmentsString() throws Exception {
+ IdSplitIterator iterator = new IdSplitIterator("form:table");
+
+ assertTrue(iterator.hasNext());
+
+ assertEquals("table", iterator.next());
+ assertEquals("form", iterator.getSubtreeId());
+
+ assertTrue(iterator.hasNext());
+ assertEquals("form", iterator.next());
+ assertNull(iterator.getSubtreeId());
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ public void testThreeSegmentsString() throws Exception {
+ IdSplitIterator iterator = new IdSplitIterator("form:table:cell");
+
+ assertTrue(iterator.hasNext());
+
+ assertEquals("cell", iterator.next());
+ assertEquals("form:table", iterator.getSubtreeId());
+
+ assertTrue(iterator.hasNext());
+
+ assertEquals("table", iterator.next());
+ assertEquals("form", iterator.getSubtreeId());
+
+ assertTrue(iterator.hasNext());
+ assertEquals("form", iterator.next());
+ assertNull(iterator.getSubtreeId());
+
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ public void testBadStrings() throws Exception {
+ IdSplitIterator iterator;
+
+ iterator = new IdSplitIterator(":");
+ assertFalse(iterator.hasNext());
+
+ iterator = new IdSplitIterator("test:");
+ assertFalse(iterator.hasNext());
+
+ iterator = new IdSplitIterator(":test");
+ assertTrue(iterator.hasNext());
+ assertEquals("test", iterator.next());
+ assertEquals("", iterator.getSubtreeId());
+ assertFalse(iterator.hasNext());
+
+ iterator = new IdSplitIterator("::");
+ assertFalse(iterator.hasNext());
+ }
+}
Modified:
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java
===================================================================
---
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java 2011-01-18
18:11:00 UTC (rev 21063)
+++
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java 2011-01-18
19:20:56 UTC (rev 21064)
@@ -47,9 +47,6 @@
public class TreeConverterUtilTest {
@Mock
- private FacesContext context;
-
- @Mock
@Environment({Environment.Feature.EXTERNAL_CONTEXT})
private MockFacesEnvironment environment;