You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2017/01/19 13:18:16 UTC
svn commit: r1779461 - in /myfaces/core/branches/2.3.x/impl/src:
main/java/org/apache/myfaces/component/search/
test/java/org/apache/myfaces/component/search/
Author: tandraschko
Date: Thu Jan 19 13:18:15 2017
New Revision: 1779461
URL: http://svn.apache.org/viewvc?rev=1779461&view=rev
Log:
MYFACES-4075 SearchExpression API (cleanup)
Modified:
myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/ChildSearchKeywordResolver.java
myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/ChildSearchKeywordResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/ChildSearchKeywordResolver.java?rev=1779461&r1=1779460&r2=1779461&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/ChildSearchKeywordResolver.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/ChildSearchKeywordResolver.java Thu Jan 19 13:18:15 2017
@@ -41,79 +41,61 @@ public class ChildSearchKeywordResolver
@Override
public void resolve(SearchKeywordContext expressionContext, UIComponent current, String keyword)
{
- try
+ Matcher matcher = PATTERN.matcher(keyword);
+
+ if (matcher.matches())
{
- Matcher matcher = PATTERN.matcher(keyword);
+ int childNumber = Integer.parseInt(matcher.group(1));
- if (matcher.matches())
+ if (childNumber + 1 > current.getChildCount())
{
+ throw new FacesException("Component with clientId \""
+ + current.getClientId(expressionContext.getSearchExpressionContext().getFacesContext())
+ + "\" has fewer children as \"" +
+ childNumber + "\". Expression: \"" + keyword + "\"");
+ }
- int childNumber = Integer.parseInt(matcher.group(1));
-
- if (childNumber + 1 > current.getChildCount())
- {
- throw new FacesException("Component with clientId \""
- + current.getClientId(expressionContext.getSearchExpressionContext().getFacesContext())
- + "\" has fewer children as \"" +
- childNumber + "\". Expression: \"" + keyword + "\"");
- }
-
- List<UIComponent> list = current.getChildren();
- int count = 0;
- for (int i = 0; i < current.getChildCount(); i++)
+ List<UIComponent> list = current.getChildren();
+ int count = 0;
+ for (int i = 0; i < current.getChildCount(); i++)
+ {
+ if (! (list.get(i) instanceof UntargetableComponent))
{
- if (! (list.get(i) instanceof UntargetableComponent))
- {
- count++;
- }
- if (count == childNumber + 1)
- {
- expressionContext.invokeContextCallback(current.getChildren().get(childNumber));
- break;
- }
+ count++;
}
- if (count < childNumber)
+ if (count == childNumber + 1)
{
- throw new FacesException("Component with clientId \""
- + current.getClientId(expressionContext.getSearchExpressionContext().getFacesContext())
- + "\" has fewer children as \"" +
- childNumber + "\". Expression: \"" + keyword + "\"");
+ expressionContext.invokeContextCallback(current.getChildren().get(childNumber));
+ break;
}
}
- else
+ if (count < childNumber)
{
- throw new FacesException(
- "Expression does not match following pattern @child(n). Expression: \"" + keyword + "\"");
+ throw new FacesException("Component with clientId \""
+ + current.getClientId(expressionContext.getSearchExpressionContext().getFacesContext())
+ + "\" has fewer children as \"" +
+ childNumber + "\". Expression: \"" + keyword + "\"");
}
-
}
- catch (Exception e)
+ else
{
throw new FacesException(
- "Expression does not match following pattern @child(n). Expression: \"" + keyword + "\"", e);
+ "Expression does not match following pattern @child(n). Expression: \"" + keyword + "\"");
}
}
@Override
public boolean isResolverForKeyword(SearchExpressionContext searchExpressionContext, String command)
{
- if (command != null && command.length() > 6 &&
- command.substring(0, CHILD_KEYWORD.length()).equalsIgnoreCase(CHILD_KEYWORD))
+ if (command.length() > 6 && command.substring(0, CHILD_KEYWORD.length()).equalsIgnoreCase(CHILD_KEYWORD))
{
- try
- {
- Matcher matcher = PATTERN.matcher(command);
+ Matcher matcher = PATTERN.matcher(command);
- if (matcher.matches())
- {
- return true;
- }
- else
- {
- return false;
- }
+ if (matcher.matches())
+ {
+ return true;
}
- catch (Exception e)
+ else
{
return false;
}
Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java?rev=1779461&r1=1779460&r2=1779461&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java Thu Jan 19 13:18:15 2017
@@ -91,30 +91,20 @@ public class IdSearchKeywordResolver ext
protected String extractId(String expression)
{
- try
+ Matcher matcher = PATTERN.matcher(expression);
+ if (matcher.matches())
{
- Matcher matcher = PATTERN.matcher(expression);
- if (matcher.matches())
- {
- return matcher.group(1);
- }
- else
- {
- throw new FacesException("Expression does not match following pattern @id(id). Expression: \""
- + expression + "\"");
- }
-
+ return matcher.group(1);
}
- catch (Exception e)
+ else
{
throw new FacesException("Expression does not match following pattern @id(id). Expression: \""
- + expression + "\"", e);
+ + expression + "\"");
}
}
private static void withId(FacesContext context, String id, UIComponent base, ContextCallback callback)
{
-
if (id.equals(base.getId()))
{
callback.invokeContextCallback(context, base);
@@ -141,23 +131,15 @@ public class IdSearchKeywordResolver ext
@Override
public boolean isResolverForKeyword(SearchExpressionContext searchExpressionContext, String command)
{
- if (command != null && command.length() > 6 &&
- command.substring(0, ID_KEYWORD.length()).equalsIgnoreCase(ID_KEYWORD))
+ if (command.length() > 6 && command.substring(0, ID_KEYWORD.length()).equalsIgnoreCase(ID_KEYWORD))
{
- try
- {
- Matcher matcher = PATTERN.matcher(command);
+ Matcher matcher = PATTERN.matcher(command);
- if (matcher.matches())
- {
- return true;
- }
- else
- {
- return false;
- }
+ if (matcher.matches())
+ {
+ return true;
}
- catch (Exception e)
+ else
{
return false;
}
Modified: myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java?rev=1779461&r1=1779460&r2=1779461&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java Thu Jan 19 13:18:15 2017
@@ -88,6 +88,10 @@ public class SearchExpressionImplTest ex
Assert.assertEquals(componentId, "mainForm:showName");
componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(
+ searchContext, "mainForm:table:0:baseText").get(0);
+ Assert.assertEquals(componentId, "mainForm:table:0:baseText");
+
+ componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(
searchContext, "@parent:showName:@parent:showName").get(0);
Assert.assertEquals(componentId, "mainForm:showName");