const XalanDOMString* NamespacesHandler::getNamespace(const XalanDOMString& thePrefix) const { const NamespacesVectorType::value_type* theNamespace = findByPrefix(m_excludedResultPrefixes, thePrefix); if (theNamespace != 0) { return &theNamespace->getURI(); } else { return findNamespace(m_namespaceDeclarations, thePrefix); } }
/* * DeclareNamespace - by far the most complex routine in Genx */ genxNamespace genxDeclareNamespace(genxWriter w, constUtf8 uri, constUtf8 defaultPref, genxStatus * statusP) { genxNamespace ns; genxAttribute defaultDecl; UTFTYPE newPrefix[100]; if (uri == NULL || uri[0] == 0) { w->status = GENX_BAD_NAMESPACE_NAME; goto busted; } if ((w->status = genxCheckText(w, uri)) != GENX_SUCCESS) goto busted; /* if a prefix is provided, it has to be an NCname */ if (defaultPref != NULL && defaultPref[0] != 0 && (w->status = checkNCName(w, defaultPref)) != GENX_SUCCESS) goto busted; /* previously declared? */ if ((ns = findNamespace(&w->namespaces, uri))) { /* just a lookup, really */ if ((defaultPref == NULL) || (defaultPref[0] == 0 && ns->defaultDecl == w->xmlnsEquals) || (strcmp((const char *) ns->defaultDecl->name + STRLEN_XMLNS_COLON, (const char *) defaultPref) == 0)) { w->status = *statusP = GENX_SUCCESS; return ns; } } /* wasn't already declared */ else { /* make a default prefix if none provided */ if (defaultPref == NULL) { sprintf((char *) newPrefix, "g%d", w->nextPrefix++); defaultPref = newPrefix; } ns = (genxNamespace) allocate(w, sizeof(struct genxNamespace_rec)); if (ns == NULL) { w->status = GENX_ALLOC_FAILED; goto busted; } ns->writer = w; ns->baroque = False; if ((ns->name = copy(w, uri)) == NULL) { w->status = GENX_ALLOC_FAILED; goto busted; } if ((w->status = listAppend(&w->namespaces, ns)) != GENX_SUCCESS) goto busted; ns->defaultDecl = ns->declaration = NULL; ns->declCount = 0; } if (defaultPref[0] == 0) { if (w->defaultNsDeclared) { w->status = GENX_DUPLICATE_PREFIX; goto busted; } defaultDecl = w->xmlnsEquals; w->defaultNsDeclared = True; } else { /* this catches dupes too */ if ((defaultPref = storePrefix(w, defaultPref, False)) == NULL) goto busted; defaultDecl = declareAttribute(w, NULL, defaultPref, ns->name, statusP); if (defaultDecl == NULL || *statusP != GENX_SUCCESS) { w->status = *statusP; return NULL; } } if (ns->defaultDecl != NULL && defaultDecl != ns->defaultDecl) ns->baroque = True; ns->defaultDecl = defaultDecl; *statusP = GENX_SUCCESS; return ns; busted: *statusP = w->status; return NULL; }