Author: nbelaevski
Date: 2007-03-07 12:31:02 -0500 (Wed, 07 Mar 2007)
New Revision: 35
Modified:
trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Bean.java
trunk/richfaces-samples/tree-demo/src/main/resources/org/richfaces/test.xml
trunk/richfaces/tree/src/main/java/org/richfaces/component/ListRowKey.java
trunk/richfaces/tree/src/main/java/org/richfaces/component/TreeRowKey.java
trunk/richfaces/tree/src/main/java/org/richfaces/component/xml/XmlTreeDataBuilder.java
Log:
Colons escaping in Tree row keys implemented
Modified: trunk/richfaces/tree/src/main/java/org/richfaces/component/ListRowKey.java
===================================================================
--- trunk/richfaces/tree/src/main/java/org/richfaces/component/ListRowKey.java 2007-03-07
15:48:00 UTC (rev 34)
+++ trunk/richfaces/tree/src/main/java/org/richfaces/component/ListRowKey.java 2007-03-07
17:31:02 UTC (rev 35)
@@ -79,7 +79,7 @@
int oldIdx = 0;
do {
- idx = trimmedPath.indexOf(AbstractTreeDataModel.SEPARATOR, oldIdx);
+ idx = trimmedPath.indexOf(ESCAPED_SEPARATOR_CHAR_STRING, oldIdx);
String subData;
@@ -91,10 +91,11 @@
subData = subData.trim();
if (subData.length() != 0) {
- result.add(subData);
+ //unescape
+ result.add(subData.replace(ESCAPED_ESCAPE_CHAR_STRING, ESCAPE_CHAR_STRING));
}
- oldIdx = idx + 1;
+ oldIdx = idx + ESCAPED_SEPARATOR_CHAR_STRING.length();
} while (idx != -1);
return result;
@@ -189,7 +190,22 @@
boolean hasNext = iterator.hasNext();
while (hasNext) {
- result.append(iterator.next());
+ String pathSegment = iterator.next().toString();
+
+ StringBuffer escapedSubPath = new StringBuffer();
+ for (int i = 0; i < pathSegment.length(); i++) {
+ char ch = pathSegment.charAt(i);
+
+ //escape
+ if (AbstractTreeDataModel.SEPARATOR == ch || ListRowKey.SEPARATOR_ESCAPE_CHAR == ch)
{
+ escapedSubPath.append(ListRowKey.SEPARATOR_ESCAPE_CHAR);
+ }
+
+ escapedSubPath.append(ch);
+ }
+
+ result.append(escapedSubPath.toString());
+
hasNext = iterator.hasNext();
if (hasNext) {
Modified: trunk/richfaces/tree/src/main/java/org/richfaces/component/TreeRowKey.java
===================================================================
--- trunk/richfaces/tree/src/main/java/org/richfaces/component/TreeRowKey.java 2007-03-07
15:48:00 UTC (rev 34)
+++ trunk/richfaces/tree/src/main/java/org/richfaces/component/TreeRowKey.java 2007-03-07
17:31:02 UTC (rev 35)
@@ -30,6 +30,17 @@
* Base abstract clas for all tree row keys
*/
public abstract class TreeRowKey implements Serializable {
+
+ public static final char SEPARATOR_ESCAPE_CHAR = '-';
+
+ //that is to escape colons in path by preceding with "-"
+ //colon is SEPARATOR_CHAR
+ protected static final String ESCAPE_CHAR_STRING =
String.valueOf(SEPARATOR_ESCAPE_CHAR);
+ protected static final String ESCAPED_ESCAPE_CHAR_STRING = ESCAPE_CHAR_STRING +
ESCAPE_CHAR_STRING;
+
+ protected static final String SEPARATOR_CHAR_STRING =
String.valueOf(AbstractTreeDataModel.SEPARATOR);
+ protected static final String ESCAPED_SEPARATOR_CHAR_STRING = ESCAPE_CHAR_STRING +
SEPARATOR_CHAR_STRING;
+
/**
* getter for key depth
* @return key depth
@@ -63,7 +74,7 @@
return false;
}
- return (rowKey.getPath() + AbstractTreeDataModel.SEPARATOR).startsWith(getPath());
+ return (rowKey.getPath() + ESCAPED_SEPARATOR_CHAR_STRING).startsWith(getPath());
}
/**
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/component/xml/XmlTreeDataBuilder.java
===================================================================
---
trunk/richfaces/tree/src/main/java/org/richfaces/component/xml/XmlTreeDataBuilder.java 2007-03-07
15:48:00 UTC (rev 34)
+++
trunk/richfaces/tree/src/main/java/org/richfaces/component/xml/XmlTreeDataBuilder.java 2007-03-07
17:31:02 UTC (rev 35)
@@ -79,11 +79,19 @@
if (id == null || id.length() == 0) {
int currentId = 0;
- if (idsList.size() == level) {
+ if (idsList.size() <= level) {
+ for (int i = idsList.size(); i < level; i++) {
+ idsList.add(null);
+ }
+
idsList.add(new Integer(0));
} else {
Integer integer = (Integer) idsList.get(level);
- currentId = integer.intValue() + 1;
+ if (integer != null) {
+ currentId = integer.intValue() + 1;
+ } else {
+ //zero currentId is ok
+ }
}
Set exclusions = (Set) exclusionSets.get(level);
@@ -92,9 +100,7 @@
currentId++;
}
- if (currentId != 0) {
- idsList.set(level, new Integer(currentId));
- }
+ idsList.set(level, new Integer(currentId));
id = Integer.toString(currentId);
} else {
Modified: trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-03-07
15:48:00 UTC (rev 34)
+++ trunk/richfaces-samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-03-07
17:31:02 UTC (rev 35)
@@ -167,11 +167,13 @@
private void initData() {
selectedNodeChildren.clear();
- Iterator iter = selectedNode.getChildren();
- int i = 0;
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- selectedNodeChildren.put(((TreeNode)entry.getValue()).getData(),
Integer.toString(i++));
+ if (selectedNode != null) {
+ Iterator iter = selectedNode.getChildren();
+ int i = 0;
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ selectedNodeChildren.put(((TreeNode)entry.getValue()).getData(),
Integer.toString(i++));
+ }
}
}
Modified: trunk/richfaces-samples/tree-demo/src/main/resources/org/richfaces/test.xml
===================================================================
--- trunk/richfaces-samples/tree-demo/src/main/resources/org/richfaces/test.xml 2007-03-07
15:48:00 UTC (rev 34)
+++ trunk/richfaces-samples/tree-demo/src/main/resources/org/richfaces/test.xml 2007-03-07
17:31:02 UTC (rev 35)
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<web-app version="2.4">
+<web-app version="2.4" id="webApp:id">
<description>Tree demo</description>
<display-name>tree-demo</display-name>
<context-param>
Show replies by date