/** Checks whether the value is an empty string. * Note: Like {@link #noEL}, it is OK to be null!! */ private static void noEmpty(String nm, String val, Item item) throws UiException { if (val != null && val.length() == 0) throw new UiException(message(nm + " cannot be empty", item)); }
private static void noEL(String nm, String val, Item item) throws UiException { if (val != null && val.contains("${")) throw new UiException(message(nm + " does not support EL expressions", item)); }
private static void warnWrongZkAttr(Attribute attr) { log.warn(message("Attribute " + attr.getName() + " ignored in <zk>", attr)); }
for (Iterator<Item> it = items.iterator();;) { if (zkElem != null && xmlFound != null) throw new UnsupportedOperationException(message( "Unable to handle XML fragment, <" + xmlFound + ">, with <" + zkElem + ">. Please use CDATA instead",
private static void noELnorEmpty(String nm, String val, Item item) throws UiException { if (isEmpty(val)) throw new UiException(message(nm + " cannot be empty", item)); noEL(nm, val, item); }
private void checkZScriptEnabled(org.zkoss.xml.Locator loc) { if (!_wapp.getConfiguration().isZScriptEnabled()) throw new UiException(message("zscript is not allowed since <disable-zscript> is configured", loc)); }
private static TemplateInfo parseTemplate(NodeInfo parent, Element el, AnnotationHelper annHelper) throws Exception { if (annHelper.clear()) log.warn(message("Annotations are ignored since <template> doesn't support them", el)); if (el.getAttributeItem("forEach") != null) log.warn(message("forEach is ignored since <template> doesn't support it", el));
/** Parse the XEL method. */ private static void parseXelMethod(PageDefinition pgdef, ProcessingInstruction pi, Map<String, String> params) throws Exception { final String prefix = params.remove("prefix"); noELnorEmpty("prefix", prefix, pi); final String nm = params.remove("name"); noELnorEmpty("name", nm, pi); final String clsnm = params.remove("class"); noELnorEmpty("class", clsnm, pi); final String sig = params.remove("signature"); noELnorEmpty("signature", sig, pi); final Method mtd; try { final ClassResolver clsresolver = pgdef.getImportedClassResolver(); final Class cls = clsresolver.resolveClass(clsnm); mtd = Classes.getMethodBySignature(cls, sig, null, clsresolver); } catch (ClassNotFoundException ex) { throw new UiException(message("Class not found: " + ex.getMessage(), pi)); } catch (Exception ex) { throw new UiException(message("Method not found: " + sig + " in " + clsnm, pi)); } if ((mtd.getModifiers() & Modifier.STATIC) == 0) throw new UiException(message("Not a static method: " + mtd, pi)); pgdef.addXelMethod(prefix, nm, new MethodFunction(mtd)); }
private static void parseAnnotation(Element el, AnnotationHelper annHelper) throws Exception { if (!el.getElements().isEmpty()) throw new UiException(message("Child elements are not allowed for the annotations", el)); final Map<String, String[]> attrs = new LinkedHashMap<String, String[]>(); for (final Attribute attr : el.getAttributeItems()) { attrs.put(attr.getLocalName(), AnnotationHelper.parseAttributeValue(attr.getValue().trim(), location(attr))); } annHelper.add(el.getLocalName(), attrs, location(el)); }
private static ZkInfo parseZk(NodeInfo parent, Element el, AnnotationHelper annHelper) throws Exception { if (annHelper.clear()) log.warn(message("Annotations are ignored since <zk> doesn't support them", el)); } else if ("switch".equals(attnm) || "choose".equals(attnm)) { if (isZkSwitch(parent)) throw new UiException(message("<zk " + attnm + "> cannot be used in <zk switch/choose>", el)); zi.setSwitch(attval); } else if ("case".equals(attnm)) { if (!isZkSwitch(parent)) throw new UiException(message("<zk case> can be used only in <zk switch>", attr)); zi.setCase(attval); } else {
private static void parseVariables(LanguageDefinition langdef, NodeInfo parent, Element el, AnnotationHelper annHelper) throws Exception { //if (!el.getElements().isEmpty()) // throw new UiException(message("Child elements are not allowed for <variables> element", el)); if (annHelper.clear()) log.warn(message("Annotations are ignored since <variables> doesn't support them", el)); //old style annotation not supported here String ifc = null, unless = null, composite = null; boolean local = false; final Map<String, String> vars = new LinkedHashMap<String, String>(); for (final Attribute attr : el.getAttributeItems()) { final Namespace attrns = attr.getNamespace(); final String attnm = attr.getLocalName(); final String attval = attr.getValue(); if ("if".equals(attnm) && isZkElementAttr(langdef, attrns)) { ifc = attval; } else if ("unless".equals(attnm) && isZkElementAttr(langdef, attrns)) { unless = attval; } else if ("local".equals(attnm) && isZkElementAttr(langdef, attrns)) { local = "true".equals(attval); } else if ("composite".equals(attnm) && isZkElementAttr(langdef, attrns)) { composite = attval; } else if ("forEach".equals(attnm) && isZkElementAttr(langdef, attrns)) { throw new UiException(message("forEach not applicable to <variables>", el)); } else { vars.put(attnm, attval); } } if (!vars.isEmpty()) new VariablesInfo(parent, vars, local, composite, ConditionImpl.getInstance(ifc, unless)); }
if (!(pi.getParent() instanceof Document)) log.warn( message("Ignored language attribute since the page directive is not at the top level", pi)); } else if ("title".equals(nm)) { pgdef.setTitle(val); pgdef.setComplete("true".equals(val)); } else { log.warn(message("Ignored unknown attribute: " + nm, pi));
final String clsnm = params.remove("class"); if (isEmpty(clsnm)) throw new UiException(message("The class attribute is required", pi)); final String prefix = params.remove("prefix"); if (!params.isEmpty()) log.warn(message("Ignored unknown attributes: " + params.keySet(), pi)); if (uri == null || prefix == null) throw new UiException(message("Both uri and prefix attribute are required", pi)); final String unless = params.remove("unless"); if (!params.isEmpty()) log.warn(message("Ignored unknown attributes: " + params.keySet(), pi)); noEmpty("uri", uri, pi); pgdef.addForwardInfo(new ForwardInfo(uri, ConditionImpl.getInstance(ifc, unless))); } else if ("import".equals(target)) { //import throw new UiException(message("The import directive can be used only at the top level", pi)); } else if ("template".equals(target)) { //ZK-2623: page scope template final String name = params.remove("name"); pgdef.addTemplateInfo(new TemplateInfo(null, name, src, params, null)); } else { log.warn(message("Unknown processing instruction: " + target, pi));
throw new UiException(message("<custom-attributes> must be used under a component", el)); if (annHelper.clear()) log.warn(message("Annotations are ignored since <custom-attributes> doesn't support them", el)); //old style annotation not supported composite = attval; } else if ("forEach".equals(attnm) && isZkElementAttr(langdef, attrns)) { throw new UiException(message("forEach not applicable to <custom-attributes>", el)); } else if (parent instanceof ComponentInfo && AnnotationHelper.isAnnotation(attvaltrim = attval.trim())) { if (attrAnnHelper == null)
/** Process the init directive. */ private void parseInitDirective(PageDefinition pgdef, ProcessingInstruction pi, Map<String, String> params) throws Exception { final String clsnm = params.remove("class"); final String zsrc = params.remove("zscript"); final Map<String, String> args = new LinkedHashMap<String, String>(params); if (clsnm == null) { if (zsrc == null) throw new UiException(message("Either the class or zscript attribute must be specified", pi)); checkZScriptEnabled(pi.getLocator()); ZScript zs = null; final String zslang = pgdef.getZScriptLanguage(); if (!zsrc.contains("${")) { final URL url = getLocator().getResource(zsrc); if (url != null) zs = new ZScript(zslang, url); //Bug 2929887: defer the error message since it might not be required } if (zs == null) zs = new ZScript(pgdef.getEvaluatorRef(), zslang, zsrc, getLocator()); pgdef.addInitiatorInfo(new InitiatorInfo(new ZScriptInitiator(zs), args)); } else { if (zsrc != null) throw new UiException(message("You cannot specify both class and zscript", pi)); pgdef.addInitiatorInfo(new InitiatorInfo(clsnm, args)); } }
if (LanguageDefinition.CLIENT_NAMESPACE.equals(uri) || "client".equals(uri)) { if (name.length() == 0) throw new UiException(message("Client attribute name required", xl)); if ("use".equals(name)) { if (cond != null) throw new UnsupportedOperationException(message("if and unless not allowed for w:use", xl)); compInfo.setWidgetClass(value); } else {
impclses.add(nm); } else { log.warn(message("Ignored unknown attribute for import: " + nm, pi));
private void parseZScript(NodeInfo parent, Element el, AnnotationHelper annHelper) { if (el.getAttributeItem("forEach") != null) throw new UiException(message("forEach not applicable to <zscript>", el)); if (annHelper.clear()) log.warn(message("Annotations are ignored since <zscript> doesn't support them", el));
while (item != null) { if ("template".equals(item.getLocalName())) throw new UiException(message(rn + " does not support between templates", (Item) root)); item = item.getNextSibling();
private void parseAttribute(PageDefinition pgdef, ComponentInfo parent, Element el, AnnotationHelper annHelper) throws Exception { if (el.getAttributeItem("forEach") != null) throw new UiException(message("forEach not applicable to attribute", el)); throw new UiException(message("The name attribute required", el)); if (elFound != null) { if (Events.isValid(attnm)) throw new UiException(message("<" + elFound + "> not allowed in an event listener", el));