Package org.zkoss.idom

Examples of org.zkoss.idom.Namespace


   */
  private void parse(PageDefinition pgdef, NodeInfo parent,
  Element el, AnnotationHelper annHelper, boolean bNativeContent)
  throws Exception {
    final String nm = el.getLocalName();
    final Namespace ns = el.getNamespace();
    final String pref = ns != null ? ns.getPrefix(): "";
    final String uri = ns != null ? ns.getURI(): "";
    LanguageDefinition langdef = pgdef.getLanguageDefinition();
    if ("zscript".equals(nm) && isZkElement(langdef, nm, pref, uri)) {
      parseZScript(parent, el, annHelper);
    } else if ("attribute".equals(nm) && isZkElement(langdef, nm, pref, uri)) {
      if (!(parent instanceof ComponentInfo))
        throw new UiException("<attribute> cannot be the root element, "+el.getLocator());

      parseAttribute(pgdef, (ComponentInfo)parent, el, annHelper);
    } else if ("custom-attributes".equals(nm) && isZkElement(langdef, nm, pref, uri)) {
      parseCustomAttributes(langdef, parent, el, annHelper);
    } else if ("variables".equals(nm) && isZkElement(langdef, nm, pref, uri)) {
      parseVariables(langdef, parent, el, annHelper);
    } else if (LanguageDefinition.ANNO_NAMESPACE.equals(uri)
    || "annotation".equals(uri)) {
      parseAnnotation(el, annHelper);
    } else {
      //if (D.ON && log.debugable()) log.debug("component: "+nm+", ns:"+ns);
      final ComponentInfo compInfo;
      final boolean bzk =
        "zk".equals(nm) && isZkElement(langdef, nm, pref, uri);
      if (bzk) {
        if (annHelper.clear())
          log.warning("Annotations are ignored since <zk> doesn't support them, "+el.getLocator());
        compInfo = new ZkInfo(parent);
      } else {
        if (isZkSwitch(parent))
          throw new UiException("Only <zk> can be used in <zk switch>, "+el.getLocator());

        boolean prefRequired =
          uri.startsWith(LanguageDefinition.NATIVE_NAMESPACE_PREFIX);
        boolean bNative = bNativeContent || prefRequired
          || LanguageDefinition.NATIVE_NAMESPACE.equals(uri)
          || "native".equals(uri);

        if (!bNative && langdef.isNative()
        && !langdef.getNamespace().equals(uri))
          bNative = prefRequired =
            ("".equals(pref) && "".equals(uri))
            || !LanguageDefinition.exists(uri);
          //Spec: if pref/URI not specified => native
          //    if uri unknown => native

        if (bNative) {
          if (annHelper.clear())
            log.warning("Annotations are ignored since native doesn't support them, "+el.getLocator());

          final NativeInfo ni;
          compInfo = ni = new NativeInfo(
            parent, langdef.getNativeDefinition(),
            prefRequired && pref.length() > 0 ? pref + ":" + nm: nm);

          //add declared namespace if starting with native:
          final Collection dns = el.getDeclaredNamespaces();
          if (!dns.isEmpty())
            addDeclaredNamespace(ni, dns, langdef);
        } else {
          final boolean defaultNS = isDefaultNS(langdef, pref, uri);
          final LanguageDefinition complangdef =
            defaultNS ? langdef: LanguageDefinition.lookup(uri);
          ComponentDefinition compdef =
            defaultNS ? pgdef.getComponentDefinitionMap().get(nm): null;
          if (compdef != null) {
            compInfo = new ComponentInfo(parent, compdef);
          } else if (complangdef.hasComponentDefinition(nm)) {
            compdef = complangdef.getComponentDefinition(nm);
            compInfo = new ComponentInfo(parent, compdef);
            langdef = complangdef;
          } else {
            compdef = complangdef.getDynamicTagDefinition();
            if (compdef == null)
              throw new DefinitionNotFoundException("Component definition not found: "+nm+" in "+complangdef+", "+el.getLocator());
            compInfo = new ComponentInfo(parent, compdef, nm);
            langdef = complangdef;
          }

          //process use first because addProperty needs it
          String use = el.getAttributeValue("use");
          if (use != null) {
            use = use.trim();
            if (use.length() != 0)
              compInfo.setImplementation(use);
              //Resolve later since might defined in zscript
          }
        }
      }

      String ifc = null, unless = null,
        forEach = null, forEachBegin = null, forEachEnd = null;
      AnnotationHelper attrAnnHelper = null;
      for (Iterator it = el.getAttributeItems().iterator();
      it.hasNext();) {
        final Attribute attr = (Attribute)it.next();
        final Namespace attrns = attr.getNamespace();
        final String attURI = attrns != null ? attrns.getURI(): "";
        final String attnm = attr.getLocalName();
        final String attval = attr.getValue();
        if (LanguageDefinition.ANNO_NAMESPACE.equals(attURI)
        || "annotation".equals(attURI)) {
          if (bzk) warnWrongZkAttr(attr);
          else {
            if (attrAnnHelper == null)
              attrAnnHelper = new AnnotationHelper();
            attrAnnHelper.addByRawValue(attnm, attval);
          }
        } else if ("apply".equals(attnm) && isZkAttr(langdef, attrns)) {
          if (bzk) warnWrongZkAttr(attr);
          else compInfo.setApply(attval);
        } else if ("forward".equals(attnm) && isZkAttr(langdef, attrns)) {
          if (bzk) warnWrongZkAttr(attr);
          else compInfo.setForward(attval);
        } else if ("if".equals(attnm) && isZkAttr(langdef, attrns)) {
          ifc = attval;
        } else if ("unless".equals(attnm) && isZkAttr(langdef, attrns)) {
          unless = attval;
        } else if ("forEach".equals(attnm) && isZkAttr(langdef, attrns)) {
          forEach = attval;
        } else if ("forEachBegin".equals(attnm) && isZkAttr(langdef, attrns)) {
          forEachBegin = attval;
        } else if ("forEachEnd".equals(attnm) && isZkAttr(langdef, attrns)) {
          forEachEnd = attval;
        } else if ("fulfill".equals(attnm) && isZkAttr(langdef, attrns)) {
          if (bzk) warnWrongZkAttr(attr);
          else compInfo.setFulfill(attval);
        } else if (bzk) {
          if ("switch".equals(attnm) || "choose".equals(attnm)) {
            if (isZkSwitch(parent))
              throw new UiException("<zk "+attnm+"> cannot be used in <zk switch/choose>, "+el.getLocator());
            ((ZkInfo)compInfo).setSwitch(attval);
          } else if ("case".equals(attnm)) {
            if (!isZkSwitch(parent))
              throw new UiException("<zk case> can be used only in <zk switch>, "+attr.getLocator());
            ((ZkInfo)compInfo).setCase(attval);
          } else if ("when".equals(attnm)) {
            ifc = attval;
          } else {
            final String attPref = attrns != null ? attrns.getPrefix(): null;
            if (!"xmlns".equals(attnm) && !"xml".equals(attnm)
            && attURI.indexOf("w3.org") < 0
            && (attPref == null
             || (!"xmlns".equals(attPref) && !"xml".equals(attPref))))
              warnWrongZkAttr(attr);
          }
        } else if (!("use".equals(attnm) && isZkAttr(langdef, attrns))) {
          final String attPref = attrns != null ? attrns.getPrefix(): "";
          if (!"xmlns".equals(attPref)
          && !("xmlns".equals(attnm) && "".equals(attPref))
          && !"http://www.w3.org/2001/XMLSchema-instance".equals(attURI)) {
            if (isAttrAnnot(attval)) { //annotation
              if (attrAnnHelper == null)
View Full Code Here


    final Map attrs = new HashMap();
    AnnotationHelper attrAnnHelper = null;
    for (Iterator it = el.getAttributeItems().iterator();
    it.hasNext();) {
      final Attribute attr = (Attribute)it.next();
      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)) {
View Full Code Here

    boolean local = false;
    final Map vars = new HashMap();
    for (Iterator it = el.getAttributeItems().iterator();
    it.hasNext();) {
      final Attribute attr = (Attribute)it.next();
      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)) {
View Full Code Here

  /** Adds the declared namespaces to the native info, if necessary.
   */
  private static void addDeclaredNamespace(
  NativeInfo nativeInfo, Collection namespaces, LanguageDefinition langdef) {
    for (Iterator it = namespaces.iterator(); it.hasNext();) {
      final Namespace ns = (Namespace)it.next();
      final String uri = ns.getURI();
      boolean bNatPrefix =
        uri.startsWith(LanguageDefinition.NATIVE_NAMESPACE_PREFIX);
      if (bNatPrefix
      || (langdef.isNative()
        && !LanguageDefinition.ZK_NAMESPACE.equals(uri)
        && !"zk".equals(uri)
        && !LanguageDefinition.ANNO_NAMESPACE.equals(uri)
        && !"annotation".equals(uri)
        && !LanguageDefinition.NATIVE_NAMESPACE.equals(uri)
        && !"native".equals(uri)
        && !langdef.getNamespace().equals(uri)))
        nativeInfo.addDeclaredNamespace(
          new Namespace(ns.getPrefix(),
            bNatPrefix ? uri.substring(LanguageDefinition.NATIVE_NAMESPACE_PREFIX.length()):
              uri));
    }
  }
View Full Code Here

   */
  public static final
  void getAttributes(StringBuffer sb, Map props, Collection namespaces) {
    if (namespaces != null && !namespaces.isEmpty()) {
      for (Iterator it = namespaces.iterator(); it.hasNext();) {
        final Namespace ns = (Namespace)it.next();
        sb.append(" xmlns");
        if (ns.getPrefix().length() > 0)
          sb.append(':').append(ns.getPrefix());
        sb.append("=\"").append(ns.getURI()).append('"');
      }
    }

    if (props != null && !props.isEmpty()) {
      for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
View Full Code Here

TOP

Related Classes of org.zkoss.idom.Namespace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.