/** Returns the nearest IdSpace (scope), never null. */ private static Scope getIdSpace(Scope scope) { if (scope instanceof IdSpace) return scope; if (scope instanceof Component) { scope = ((Component) scope).getSpaceOwner(); if (scope != null) return scope; } return null; }
/** @param x either a page or component. It cannot be null.*/ private Object getFellowByPath(Object x, String name) { return Path.getComponent(x instanceof Page ? (Page) x : ((Component) x).getSpaceOwner(), name.replace(_separator, '/')); }
/** Returns the parent IdSpace (scope), or null if no parent. */ private static Scope getParentIdSpace(Scope scope) { if (scope == null || !(scope instanceof Component)) return null; final Component p = ((Component) scope).getParent(); return p != null ? p.getSpaceOwner() : null; }
/** Converts a path, generated by {@link #componentToPath}, to * a component. * * @param ref the component used to generated the path from. * It cannot be null. It is the same as the one when calling * {@link #componentToPath}. * @since 3.0.0 */ public static final Component pathToComponent(String path, Component ref) { if (path == null) { return null; } else if (".".equals(path)) { return ref; } else if ("".equals(path)) { final IdSpace owner = ref.getSpaceOwner(); if (!(owner instanceof Component)) throw new IllegalStateException("The component is moved after serialized: " + ref); return (Component) owner; } return Path.getComponent(ref.getSpaceOwner(), path); }
/** Returns the path of the specified component. */ public static final String getPath(Component comp) { final StringBuffer sb = new StringBuffer(64); for (;;) { if (sb.length() > 0) sb.insert(0, '/'); final String compId = comp.getId(); if (compId.length() == 0) throw new UiException("ID required: " + comp); sb.insert(0, compId); IdSpace is = comp.getSpaceOwner(); if (is instanceof Page) break; //done if (is == comp) { final Component p = ((Component) is).getParent(); if (p == null) break; //topmost is = p.getSpaceOwner(); if (is instanceof Page) break; //done } comp = (Component) is; } sb.insert(0, '/'); return sb.toString(); }
/** Returns the parent of the ID space, or null if not found. * @since 5.0.0 */ public static IdSpace getParentIdSpace(IdSpace idspace) { if (idspace instanceof Component) { final Component c = (Component) idspace; final Component p = c.getParent(); return p != null ? p.getSpaceOwner() : c.getPage(); } return null; }
/** Applies the variable element against the parent component. * * @param comp the parent component (it cannot be null) */ public void apply(Component comp) { if (_vars != null && isEffective(comp)) { final Evaluator eval = getEvaluator(); for (Map.Entry<String, Object> me : _vars.entrySet()) { final String name = me.getKey(); final Object value = me.getValue(); comp.getSpaceOwner().setAttribute(name, Utils.evaluateComposite(eval, comp, value), !_local); } } }
for (IdSpace space = ref.getSpaceOwner();;) { if (comp == space) { return sb.toString(); //could be "" if (parent == null) throw new UnsupportedOperationException("Unable to locate " + comp + " from " + ref); space = parent.getSpaceOwner();
path = "."; target = deferred ? path : ".".equals(path) ? comp : Path.getComponent(comp.getSpaceOwner(), path); if (target == null && comp instanceof IdSpace && comp.getParent() != null) { target = Path.getComponent(comp.getParent().getSpaceOwner(), path);
is = p != null ? p.getSpaceOwner() : c.getPage(); if (k < 0) { return (is instanceof Component) ? (Component) is : null;
return comp != null ? comp : page; if ("spaceOwner".equals(name)) return comp != null ? comp.getSpaceOwner() : page; if ("page".equals(name)) return page; return comp != null ? comp.getAttributes() : Collections.EMPTY_MAP; if ("spaceScope".equals(name)) { final Scope scope = comp != null ? comp.getSpaceOwner() : page; return scope != null ? scope.getAttributes() : Collections.EMPTY_MAP;
for (int j = 0; j < comps.length; ++j) { final Component vroot = comps[j]; final Component comp = Path.getComponent(vroot.getSpaceOwner(), _compPath); if (comp != null) { //found _binder = new AnnotateDataBinder(comp, b);
/** Injects the fellows in the context of the given IdSpace. */ public void wireFellows(final IdSpace idspace) { //inject fellows final Collection<Component> fellows = idspace.getFellows(); for (Component xcomp : fellows) injectFellow(xcomp); //inject space owner ancestors if (idspace instanceof Component) { for (IdSpace is = idspace;;) { final Component parent = is instanceof Component ? ((Component) is).getParent() : null; if (parent == null) { //hit page final Page page = ((Component) idspace).getPage(); if (page != null) injectFellow(page); break; } is = parent.getSpaceOwner(); injectFellow(is); } } else { injectFellow((Page) idspace); } }
bean = Path.getComponent(beanid); } else if (beanid.startsWith(".")) { //a relative component Path: ./ or ../ bean = Path.getComponent(comp.getSpaceOwner(), beanid); } else {
setBean(beanid, val); } else if (!setZScriptVariable(comp, beanid, val)) { comp.getSpaceOwner().setAttribute(beanid, val, true);
return _component; case SPACE_OWNER: return _component == null ? null : _component.getSpaceOwner(); case VIEW: return _binder == null ? null : _binder.getView();
if ("spaceOwner".equals(name)) { if (self instanceof Component) return ((Component) self).getSpaceOwner(); if (self instanceof Page) return self;