Revision: 14811
http://zk1.svn.sourceforge.net/zk1/?rev=14811&view=rev
Author: asuka1978
Date: 2011-09-10 00:46:50 +0000 (Sat, 10 Sep 2011)
Log Message:
-----------
2011/09/10 ?\233?\128?\177?\229?\133?\173
Modified Paths:
--------------
branches/5.5/zk/src/org/zkoss/zk/ui/metainfo/Parser.java
Modified: branches/5.5/zk/src/org/zkoss/zk/ui/metainfo/Parser.java
===================================================================
--- branches/5.5/zk/src/org/zkoss/zk/ui/metainfo/Parser.java 2011-09-09 11:27:21 UTC (rev 14810)
+++ branches/5.5/zk/src/org/zkoss/zk/ui/metainfo/Parser.java 2011-09-10 00:46:50 UTC (rev 14811)
@@ -598,9 +598,26 @@
* @param bNativeContent whether to consider the child element all native
* It is true if a component definition with text-as is found
*/
- private void parseItems(PageDefinition pgdef, NodeInfo parent,
+ private void parseItems(final PageDefinition pgdef, final NodeInfo parent,
Collection items, AnnotationHelper annHelper, boolean bNativeContent)
throws Exception {
+ LanguageDefinition parentlang = getLanguageDefinition(parent);
+ if (parentlang == null)
+ parentlang = pgdef.getLanguageDefinition();
+ final boolean bZkSwitch = isZkSwitch(parent);
+
+ ComponentInfo pi = null;
+ String textAs = null;
+ StringBuffer textAsBuffer = null;
+ for (NodeInfo p = parent; p != null; p = p.getParent())
+ if (p instanceof ComponentInfo) {
+ pi = (ComponentInfo)p;
+ textAs = pi.getTextAs();
+ if (textAs != null && pi == parent) //only direct child
+ textAsBuffer = new StringBuffer();
+ break; //found
+ }
+
for (Iterator it = items.iterator(); it.hasNext();) {
final Object o = it.next();
if (o instanceof Element) {
@@ -613,18 +630,7 @@
if (label.length() == 0)
continue;
- LanguageDefinition parentlang = getLanguageDefinition(parent);
- if (parentlang == null)
- parentlang = pgdef.getLanguageDefinition();
-
- ComponentInfo pi = null;
- for (NodeInfo p = parent; p != null; p = p.getParent())
- if (p instanceof ComponentInfo) {
- pi = (ComponentInfo)p;
- break; //found
- }
-
- if (isZkSwitch(parent)) {
+ if (bZkSwitch) {
if (trimLabel.length() == 0)
continue;
throw new UiException("Only <zk> can be used in <zk switch>, "+((Item)o).getLocator());
@@ -641,15 +647,13 @@
new TextInfo(parent, label);
//Don't trim if native (3.5.0)
} else {
- final String textAs = pi != null ? pi.getTextAs(): null;
if (textAs != null) { //implies pi != null (parent is ComponentInfo)
if (trimLabel.length() != 0)
- if (pi == parent) {
- pi.addProperty(textAs, trimLabel, null);
- } else if (!(parent instanceof TemplateInfo)) {
+ if (textAsBuffer != null) //implies pi == parent
+ textAsBuffer.append(label); //concatenate all together
+ else if (!(parent instanceof TemplateInfo))
throw new UnsupportedOperationException(
- (parent instanceof ZkInfo ? "<zk>": parent.toString()) + " not allowed in text-as");
- }
+ "Not allowed in text-as, "+((Item)o).getParent().getLocator());
} else {
if (isTrimLabel() && !parentlang.isRawLabel()) {
if (trimLabel.length() == 0)
@@ -664,6 +668,12 @@
}
}
}
+
+ if (textAsBuffer != null) { //parent might be TempalteInfo
+ final String trimLabel = textAsBuffer.toString().trim();
+ if (trimLabel.length() != 0)
+ pi.addProperty(textAs, trimLabel, null);
+ }
}
/** Returns whether to trim the leading and trailing whitespaces
* of labels.
@@ -864,15 +874,36 @@
final Collection items = el.getChildren();
String textAs = null;
if (!bNativeContent && !items.isEmpty() //if empty, no need to check
- && (textAs = compInfo.getTextAs()) != null
- && items.size() == 1) { //if items.size >= 2, no need to check further
+ && (textAs = compInfo.getTextAs()) != null) {
//if textAs is specified, we detect if any child element
//if so, we parse them as property
//if not, we handle it normally and text, if any, will be
//trimmed and assigned as a property (in parseItems)
- final Object o = items.iterator().next();
- if (o instanceof Text || o instanceof CData)
- textAs = null; //parse it normally
+ String xmlFound = null; //whether a XML fragment
+ String zkElem = null; //a ZK element
+ for (Iterator it = items.iterator();;) {
+ if (zkElem != null && xmlFound != null)
+ throw new UnsupportedOperationException(
+ "Unable to handle XML fragment, <"+xmlFound+">, with <"+zkElem+">. Please use CDATA instead.");
+ //might be possible to handle but not worth
+ if (!it.hasNext())
+ break;
+
+ final Object o = it.next();
+ if (o instanceof Element) {
+ final String n = ((Element)o).getName();
+ if ("attribute".equals(n) || "custom-attributes".equals(n)
+ || "variables".equals(n) || "template".equals(n)) {
+ zkElem = n;
+ textAs = null;
+ //unable to handle them because EL/zscript might affect
+ //the result
+ } else if (!"zscript".equals(n)) {
+ xmlFound = n;
+ //including "zk" (risk if allowed to mix zk with attribute...)
+ }
+ }
+ }
}
if (textAs != null)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|