public String toString() { final StringBuffer sb = new StringBuffer(64).append('[') .append(this instanceof NativeInfo ? "NativeInfo" : "ComponentInfo"); if (_compdef != null) sb.append(": ").append(_compdef.getName()); if (_tag != null) sb.append(" <").append(_tag).append('>'); return sb.append(']').toString(); }
/** Applies the event handlers and properties to the specified component. * * <p>It also invokes {@link ComponentDefinition#applyProperties}. * * <p>Note: annotations are applied to the component when a component * is created. So, this method doesn't and need not to copy them. * See also {@link org.zkoss.zk.ui.AbstractComponent#AbstractComponent}. * */ public void applyProperties(Component comp) { _compdef.applyProperties(comp); }
/** Adds a component definition to this map. * * <p>Thread safe. */ public void add(ComponentDefinition compdef) { if (compdef == null) throw new IllegalArgumentException("null"); String name = compdef.getName(); if (isCaseInsensitive()) name = name.toLowerCase(java.util.Locale.ENGLISH); Object implcls = compdef.getImplementationClass(); if (implcls instanceof Class) implcls = ((Class) implcls).getName(); synchronized (this) { if (_compdefs == null) { _compdefsByClass = Collections.synchronizedMap(new HashMap<String, ComponentDefinition>(4)); _compdefs = Collections.synchronizedMap(new HashMap<String, ComponentDefinition>(4)); } _compdefs.put(name, compdef); _compdefsByClass.put((String) implcls, compdef); } }
private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); final LanguageDefinition langdef = _compdef.getLanguageDefinition(); if (langdef != null) { s.writeObject(langdef.getName()); s.writeObject(_compdef.getName()); } else { s.writeObject(_compdef); } }
/** Generates all widgets in the specified language. * @param lang the language to look at */ public static String outWidgetListJavaScript(String lang) { final StringBuffer sb = new StringBuffer(4096).append("zk.wgt.WidgetInfo.register(["); boolean first = true; for (Iterator it = LanguageDefinition.lookup(lang).getComponentDefinitions().iterator(); it.hasNext();) { final ComponentDefinition compdef = (ComponentDefinition) it.next(); for (Iterator e = compdef.getMoldNames().iterator(); e.hasNext();) { final String mold = (String) e.next(); final String wgtcls = compdef.getWidgetClass(null, mold); if (wgtcls != null) { if (first) first = false; else sb.append(','); sb.append('\'').append(wgtcls).append('\''); } } } return sb.append("]);").toString(); }
Object useClass = _compDef.getImplementationClass(); if (_compDef.isInlineMacro()) {// the tag holds multiple components. final Map props = new HashMap(); Component parent = this._parenttag.getComponent(); props.put("includer", parent); _compDef.evalProperties(props, page, parent); props.putAll(_attrMap); if (this.getUse() != null) props.put("use", this.getUse()); _comps = parent.getDesktop().getExecution().createComponents( _compDef.getMacroURI(), props); } else {// the tag hold only one component. String clazzName = null; clazzName = ((Class) useClass).getName(); _comps = new Component[] { _comp = _compDef.newInstance(page, clazzName) }; _comp.getDefinition().applyProperties(_comp); else _roottag.addChildTag(this); if(!_compDef.isInlineMacro())// apply attributes to component... evaluateDynaAttributes(_comp, _attrMap);
if (!isEmpty(clsnm)) { noEL("class", clsnm, pi); compdef.setImplementationClass(clsnm); throw new UiException(message("class not allowed with inline macros", pi)); noEL("class", clsnm, pi); compdef.setImplementationClass(clsnm); if (ref.isMacro()) throw new UiException(message("Unable to extend from a macro component", pi)); compdef = ref.clone(null, name); if (!isEmpty(clsnm)) { noEL("class", clsnm, pi); compdef.setImplementationClass(clsnm); compdef.setImplementationClass(clsnm); wgtnm = params.remove("widget-class"); if (wgtnm != null) compdef.setDefaultWidgetClass(wgtnm); message("cssURI not supported in 5.0. Use <?link?> or lang-addon.xml instead", pi)); compdef.setApply(params.remove("apply")); compdef.addProperty(me.getKey(), me.getValue());
if (_inline) throw new UiException("class not allowed with _inline macros, "); compdef.setImplementationClass(_useClass); if (ref.isMacro()) throw new UiException("Unable to extend from a macro component, "+_extends); compdef = ref.clone(null, _name); if (!isEmpty(_useClass)) { compdef.setImplementationClass(_useClass); compdef.setImplementationClass(_useClass); compdef.addProperty((String)me.getKey(), (String)me.getValue());
private static Component[] execCreateChild(CreateInfo ci, Component parent, ComponentInfo childInfo, ReplaceableText replaceableText, Component insertBefore) { final ComponentDefinition childdef = childInfo.getComponentDefinition(); if (childdef.isInlineMacro()) { if (insertBefore != null) throw new UnsupportedOperationException("The inline macro doesn't support template"); final Map<String, Object> props = new HashMap<String, Object>(); props.put("includer", parent); childInfo.evalProperties(props, ci.page, parent, true); return new Component[] { ci.exec.createComponents(childdef.getMacroURI(), parent, props) }; } else { String rt = null; if (replaceableText != null) { // ZK-3549 should ignore blank but was not able to do so in Parser, e.g. applying template if (parent == null || parent.getDefinition().isBlankPreserved()) { rt = replaceableText.text; } replaceableText.text = childInfo.getReplaceableText(); if (replaceableText.text != null) return new Component[0]; //Note: replaceableText is one-shot only //So, replaceable text might not be generated //and it is ok since it is only blank string } Component child = execCreateChild0(ci, parent, childInfo, rt, insertBefore); return child != null ? new Component[] { child } : new Component[0]; } }
compdef = (ComponentDefinitionImpl) ref; } else { compdef = (ComponentDefinitionImpl) ref.clone(ref.getLanguageDefinition(), name); compdef.setDeclarationURL(url); if (ref.isMacro()) throw new UiException(message("Unable to extend from a macro component", el)); compdef = (ComponentDefinitionImpl) ref; } else { compdef = (ComponentDefinitionImpl) ref.clone(ref.getLanguageDefinition(), name); compdef.setDeclarationURL(url);
/** * Creates and registers the component. * Called by {@link #doTag}. */ /*package*/ void initComponent() throws Exception { if(_roottag==null) throw new IllegalStateException("Must be nested inside the page tag: "+this); String tagName = getComponentName(); Page page = this._roottag.getPage(); ComponentDefinition compdef = page.getComponentDefinition(tagName, true); if(compdef==null) throw new JspException("can't find this Component's definition:"+tagName); _comp = (Component) compdef.resolveImplementationClass(page, getUse()).newInstance(); _composeHandle.doBeforeComposeChildren(_comp); if (_parenttag != null)_parenttag.addChildTag(this); else _roottag.addChildTag(this); _comp.getDefinition().applyProperties(_comp); // apply attributes to component... evaluateDynaAttributes(_comp, _attrMap); } /**
public boolean isInline() { return _compDef.isInlineMacro(); }
public void setMold(String mold) { if (mold != null && (DEFAULT.equals(mold) || mold.length() == 0)) mold = null; if (!Objects.equals(_auxinf != null ? _auxinf.mold : DEFAULT, mold)) { if (!_def.hasMold(mold != null ? mold : DEFAULT)) throw new UiException("Unknown mold: " + mold + "; allowed: " + _def.getMoldNames()); final String oldtype = getWidgetClass(); initAuxInfo().mold = mold; if (Objects.equals(oldtype, getWidgetClass())) smartUpdate("mold", getMold()); else invalidate(); } }
/** Returns the component definition of the specified class, or null * if not found. */ /*package*/ static ComponentDefinition getDefinition(Execution exec, Class<? extends Component> cls) { if (exec != null) { final ExecutionCtrl execCtrl = (ExecutionCtrl) exec; final PageDefinition pgdef = execCtrl.getCurrentPageDefinition(); final Page page = execCtrl.getCurrentPage(); final ComponentDefinition compdef = pgdef != null ? pgdef.getComponentDefinition(cls, true) : page != null ? page.getComponentDefinition(cls, true) : null; if (compdef != null && compdef.getLanguageDefinition() != null) return compdef; //already from langdef (not from pgdef) final ComponentDefinition compdef2 = Components.getDefinitionByDeviceType(exec.getDesktop().getDeviceType(), cls); return compdef != null && (compdef2 == null || !Objects.equals(compdef.getImplementationClass(), compdef2.getImplementationClass())) ? compdef : compdef2; //Feature 2816083: use compdef2 if same class } for (String deviceType : LanguageDefinition.getDeviceTypes()) { final ComponentDefinition compdef = Components.getDefinitionByDeviceType(deviceType, cls); if (compdef != null) return compdef; } return null; }
public String getMacroURI() { return _uri != null ? _uri : getDefinition().getMacroURI(); }
/** Called when the upload attribute is modified. */ private void onUploadChanged(String upload) { if (upload != null && !"trendy".equals(getMold()) && getDefinition().getMoldNames().contains("trendy")) //Toolbarbutton doesn't support trendy setMold("trendy"); }
/** Evaluates and retrieves properties to the specified map from * {@link ComponentDefinition} (and {@link ComponentInfo}). * * @param propmap the map to store the retrieved properties * (String name, Object value). * If null, a HashMap instance is created. * @param owner the owner page; used if parent is null * @param parent the parent component (may be null) * @param defIncluded whether to call {@link ComponentDefinition#evalProperties}. */ public Map<String, Object> evalProperties(Map<String, Object> propmap, Page owner, Component parent, boolean defIncluded) { if (defIncluded) propmap = _compdef.evalProperties(propmap, owner, parent); else if (propmap == null) propmap = new HashMap<String, Object>(); if (_props != null) { for (Property prop : _props) { if (parent != null) { if (prop.isEffective(parent)) propmap.put(prop.getName(), prop.getValue(parent)); } else { if (prop.isEffective(owner)) propmap.put(prop.getName(), prop.getValue(owner)); } } } return propmap; }
"self".equals(attnm) ? null: attnm, true); else if(target.getDefinition().isMacro()) ((DynamicPropertied)target).setDynamicProperty(attnm, value); else Fields.setByCompound(target, attnm, value, true); else if(target.getDefinition().isMacro()) ((DynamicPropertied)target).setDynamicProperty(attnm, value); else Fields.setByCompound(target, attnm, value, true);
s.writeObject(null); } else { LanguageDefinition langdef = _def.getLanguageDefinition(); if (langdef != null) { s.writeObject(langdef.getName()); s.writeObject(_def.getName()); } else { s.writeObject(_def);
/*package*/ void doCatch (Throwable throwable) throws JspException{ if(!_compDef.isInlineMacro()){ if(!_composeHandle.doCatch(throwable)){ throw new JspException(throwable); } }else{// is inlineMacro, throw exception anyway... throw new JspException(throwable); } }