void ValidateArgumentCheckFilter::startElementEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname) { if(seenOne_ && level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } if(inDocumentNode_ && level_ == 1) { if(seenDocElem_) { XQThrow3(DynamicErrorException,X("XQValidate::generateEvents"), X("A document being validated must have exactly one child element [err:XQDY0061]"), info_); } seenDocElem_ = true; } if((!inDocumentNode_ && level_ == 0) || (inDocumentNode_ && level_ == 1)) { // if validation is strict, there must be a schema for the root node if(mode_ == DocumentCache::VALIDATION_STRICT) { if(!context_->getDocumentCache()->getElementDecl(uri, localname)) { XMLBuffer msg(1023); msg.set(X("Element {")); msg.append(uri); msg.append(X("}")); msg.append(localname); msg.append(X(" is not defined as a global element [err:XQDY0084]")); XQThrow3(DynamicErrorException,X("XQValidate::generateEvents"), msg.getRawBuffer(), info_); } } } seenOne_ = true; ++level_; next_->startElementEvent(prefix, uri, localname); }
void XQillaNSResolverImpl::forbiddenBindingCheck(const XMLCh* prefix, const XMLCh* uri, const LocationInfo *info) { if(XPath2Utils::equals(prefix,XMLUni::fgXMLNSString) || XPath2Utils::equals(prefix,XMLUni::fgXMLString)) XQThrow3(StaticErrorException,X("XQillaNSResolverImpl::forbiddenBindingCheck"), X("The prefixes 'xmlns' and 'xml' cannot be used in a namespace declaration [err:XQST0070]"), info); if(XPath2Utils::equals(uri,XMLUni::fgXMLURIName)) XQThrow3(StaticErrorException,X("XQillaNSResolverImpl::forbiddenBindingCheck"), X("The 'http://www.w3.org/XML/1998/namespace' namespace cannot be bound to any prefix [err:XQST0070]"), info); }
PendingUpdateList URename::createUpdateList(DynamicContext *context) const { Node::Ptr node = (Node*)target_->createResult(context)->next(context).get(); if(node->dmNodeKind() != Node::element_string && node->dmNodeKind() != Node::attribute_string && node->dmNodeKind() != Node::processing_instruction_string) XQThrow(XPath2TypeMatchException,X("URename::createUpdateList"), X("It is a type error for the target expression of a rename expression not to be a single element, " "attribute or processing instruction [err:XUTY0012]")); ATQNameOrDerived::Ptr qname = (ATQNameOrDerived*)name_->createResult(context)->next(context).get(); // 3. The following checks are performed for error conditions: // a. If $target is an element node, the "namespaces" property of $target must not include any namespace binding that conflicts // with the implied namespace binding of $QName [err:XUDY0023]. if(node->dmNodeKind() == Node::element_string) { ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), node, context, this); if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) { XMLBuffer buf; buf.append(X("Implied namespace binding for the rename expression (\"")); buf.append(qname->getPrefix()); buf.append(X("\" -> \"")); buf.append(qname->getURI()); buf.append(X("\") conflicts with those already existing on the target element [err:XUDY0023]")); XQThrow3(DynamicErrorException, X("URename::createUpdateList"), buf.getRawBuffer(), this); } } // b. If $target is an attribute node that has a parent, the "namespaces" property of parent($target) must not include any // namespace binding that conflicts with the implied namespace binding of $QName [err:XUDY0023]. else if(node->dmNodeKind() == Node::attribute_string) { Node::Ptr parentNode = node->dmParent(context); if(parentNode.notNull() && qname->getURI() != 0 && *(qname->getURI()) != 0) { ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), parentNode, context, this); if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) { XMLBuffer buf; buf.append(X("Implied namespace binding for the rename expression (\"")); buf.append(qname->getPrefix()); buf.append(X("\" -> \"")); buf.append(qname->getURI()); buf.append(X("\") conflicts with those already existing on the parent element of the target attribute [err:XUDY0023]")); XQThrow3(DynamicErrorException, X("URename::createUpdateList"), buf.getRawBuffer(), this); } } } // c. If $target is processing instruction node, $QName must not include a non-empty namespace prefix. [err:XUDY0025]. else if(node->dmNodeKind() == Node::processing_instruction_string && !XPath2Utils::equals(qname->getPrefix(), XMLUni::fgZeroLenString)) XQThrow(XPath2TypeMatchException,X("URename::createUpdateList"), X("The target of a rename expression is a processing instruction node, and the new name " "expression returned a QName with a non-empty namespace prefix [err:XUDY0025]")); return PendingUpdate(PendingUpdate::RENAME, node, qname, this); }
void ValidateArgumentCheckFilter::textEvent(const XMLCh *chars, unsigned int length) { if(level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } if(inDocumentNode_ && level_ == 1) { XQThrow3(DynamicErrorException,X("XQValidate::generateEvents"), X("A document being validated can only have element, comments and processing instructions as children [err:XQDY0061]"), info_); } next_->textEvent(chars, length); }
void XercesUpdateFactory::completeUpdate(DynamicContext *context) { completeDeletions(context); completeRevalidation(context); // Call the URIResolvers to handle the PutSet for(PutSet::iterator i = putSet_.begin(); i != putSet_.end(); ++i) { try { if(!context->putDocument(i->node, i->uri)) { XMLBuffer buf; buf.append(X("Writing of updated document failed for URI \"")); buf.append(i->uri); buf.append(X("\"")); XQThrow3(ASTException, X("XercesUpdateFactory::completeUpdate"), buf.getRawBuffer(), i->location); } } catch(XQException& e) { if(e.getXQueryLine() == 0) { e.setXQueryPosition(i->location); } throw e; } } }
Item::Ptr UTransform::TransformResult::next(DynamicContext *context) { context->testInterrupt(); AutoVariableStoreReset reset(context, &scope_); if(toDo_) { toDo_ = false; NodeSet copiedNodes = NodeSet(nodecompare(context)); VectorOfCopyBinding::const_iterator end = transform_->getBindings()->end(); for(VectorOfCopyBinding::const_iterator it = transform_->getBindings()->begin(); it != end; ++it) { if((*it)->qname_ == 0) continue; Sequence values = (*it)->expr_->createResult(context)->toSequence(context); // Keep a record of the nodes that have been copied Result valIt = values; Item::Ptr val; while((val = valIt->next(context)).notNull()) { copiedNodes.insert((Node*)val.get()); } scope_.setVar((*it)->uri_, (*it)->name_, values); } // Get the pending update list PendingUpdateList pul = transform_->getModifyExpr()->createUpdateList(context); // Check that the targets of the pending updates are copied nodes for(PendingUpdateList::const_iterator i = pul.begin(); i != pul.end(); ++i) { Node::Ptr target = i->getTarget(); while(copiedNodes.find(target) == copiedNodes.end()) { target = target->dmParent(context); if(target.isNull()) { XQThrow3(StaticErrorException,X("UTransform::staticTyping"), X("The target node of an update expression in the transform expression is not a node from the copy clauses [err:XUDY0014]"), &(*i)); } } } // Apply the updates AutoDelete<UpdateFactory> ufactory(context->createUpdateFactory()); ufactory->applyUpdates(pul, context, transform_->getRevalidationMode()); // Execute the return expression result_ = transform_->getReturnExpr()->createResult(context); } Item::Ptr result = result_->next(context); if(result.isNull()) { result_ = 0; return 0; } return result; }
void XercesUpdateFactory::addToPutSet(const Node::Ptr &node, const LocationInfo *location, DynamicContext *context) { Node::Ptr root = node->root(context); Sequence docURISeq = root->dmDocumentURI(context); const XMLCh *docuri = 0; if(!docURISeq.isEmpty()) { docuri = docURISeq.first()->asString(context); } PutItem item(docuri, root, location, context); std::pair<PutSet::iterator, bool> res = putSet_.insert(item); if(!res.second && !res.first->node->equals(item.node)) { if(context->getMessageListener() != 0) { context->getMessageListener()->warning(X("In the context of this expression"), res.first->location); } XMLBuffer buf; buf.append(X("Document writing conflict for URI \"")); buf.append(item.uri); buf.append(X("\"")); XQThrow3(ASTException, X("XercesUpdateFactory::addToPutSet"), buf.getRawBuffer(), location); } }
PendingUpdateList UInsertAsLast::createUpdateList(DynamicContext *context) const { Node::Ptr node = (Node*)target_->createResult(context)->next(context).get(); if(node->dmNodeKind() != Node::element_string && node->dmNodeKind() != Node::document_string) XQThrow(XPath2TypeMatchException,X("UInsertAsLast::createUpdateList"), X("It is a type error for the target expression of an insert as last expression not to be a single element " "or document [err:XUTY0005]")); Sequence alist(context->getMemoryManager()); Sequence clist(context->getMemoryManager()); Result value = source_->createResult(context); Item::Ptr item; while((item = value->next(context)).notNull()) { if(((Node*)item.get())->dmNodeKind() == Node::attribute_string) { if(!clist.isEmpty()) XQThrow(ASTException,X("UInsertAsLast::createUpdateList"), X("Attribute nodes must occur before other nodes in the source expression for an insert as last expression [err:XUTY0004]")); // b. No attribute node in $alist may have a QName whose implied namespace binding conflicts with a namespace // binding in the "namespaces" property of $target [err:XUDY0023]. ATQNameOrDerived::Ptr qname = ((Node*)item.get())->dmNodeName(context); if(qname->getURI() != 0 && *(qname->getURI()) != 0) { ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), node, context, this); if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) { XMLBuffer buf; buf.append(X("Implied namespace binding for the insert as last expression (\"")); buf.append(qname->getPrefix()); buf.append(X("\" -> \"")); buf.append(qname->getURI()); buf.append(X("\") conflicts with those already existing on the parent element of the target attribute [err:XUDY0023]")); XQThrow3(DynamicErrorException, X("UInsertInto::createUpdateList"), buf.getRawBuffer(), this); } } alist.addItem(item); } else clist.addItem(item); } PendingUpdateList result; if(!alist.isEmpty()) { // 3. If $alist is not empty and into is specified, the following checks are performed: // a. $target must be an element node [err:XUTY0022]. if(node->dmNodeKind() == Node::document_string) XQThrow(XPath2TypeMatchException,X("UInsertInto::createUpdateList"), X("It is a type error if an insert expression specifies the insertion of an attribute node into a document node [err:XUTY0022]")); result.addUpdate(PendingUpdate(PendingUpdate::INSERT_ATTRIBUTES, node, alist, this)); } if(!clist.isEmpty()) { result.addUpdate(PendingUpdate(PendingUpdate::INSERT_INTO_AS_LAST, node, clist, this)); } return result; }
void ValidateArgumentCheckFilter::namespaceEvent(const XMLCh *prefix, const XMLCh *uri) { if(level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } next_->namespaceEvent(prefix, uri); }
void ValidateArgumentCheckFilter::piEvent(const XMLCh *target, const XMLCh *value) { if(level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } next_->piEvent(target, value); }
Result XQContextItem::result(DynamicContext *context, const LocationInfo *info) { const Item::Ptr item = context->getContextItem(); if(item.isNull()) { XQThrow3(DynamicErrorException,X("XQContextItem::result"), X("It is an error for the context item to be undefined when using it [err:XPDY0002]"), info); } return item; }
void ValidateArgumentCheckFilter::attributeEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname, const XMLCh *value, const XMLCh *typeURI, const XMLCh *typeName) { if(level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } next_->attributeEvent(prefix, uri, localname, value, typeURI, typeName); }
void ValidateArgumentCheckFilter::atomicItemEvent(AnyAtomicType::AtomicObjectType type, const XMLCh *value, const XMLCh *typeURI, const XMLCh *typeName) { if(level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } next_->atomicItemEvent(type, value, typeURI, typeName); }
void ValidateArgumentCheckFilter::endDocumentEvent() { if(!seenDocElem_) { XQThrow3(DynamicErrorException,X("XQValidate::generateEvents"), X("A document being validated must have exactly one child element [err:XQDY0061]"), info_); } next_->endDocumentEvent(); inDocumentNode_ = false; --level_; }
void ValidateArgumentCheckFilter::startDocumentEvent(const XMLCh *documentURI, const XMLCh *encoding) { if(seenOne_ && level_ == 0) { XQThrow3(DynamicErrorException, X("XQValidate::generateEvents"), X("The expression to be validated must evaluate to exactly one document or element node [err:XQTY0030]."), info_); } seenOne_ = true; inDocumentNode_ = true; seenDocElem_ = false; ++level_; next_->startDocumentEvent(documentURI, encoding); }
void XercesUpdateFactory::applyPut(const PendingUpdate &update, DynamicContext *context) { PutItem item(update.getValue().first()->asString(context), update.getTarget(), &update, context); std::pair<PutSet::iterator, bool> res = putSet_.insert(item); if(!res.second) { if(context->getMessageListener() != 0) { context->getMessageListener()->warning(X("In the context of this expression"), res.first->location); } XMLBuffer buf; buf.append(X("fn:put() called with the URI \"")); buf.append(item.uri); buf.append(X("\" twice. [err:XUDY0031]")); XQThrow3(ASTException, X("XercesUpdateFactory::applyPut"), buf.getRawBuffer(), &update); } }
/*static*/ bool Equals::equals(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, Collation* collation, DynamicContext* context, const LocationInfo *info) { try { // take care of the special case first if(atom1->getPrimitiveTypeIndex() == AnyAtomicType::STRING) { if(atom2->getPrimitiveTypeIndex() != AnyAtomicType::STRING && atom2->getPrimitiveTypeIndex() != AnyAtomicType::ANY_URI) { XQThrow3(XPath2ErrorException,X("Equals::equals"), X("An attempt to compare a string type to a non string type has occurred [err:XPTY0004]"), info); } // if the function returns 0, then they are equal return (collation->compare(atom1->asString(context),atom2->asString(context))==0); } return atom1->equals(atom2, context); } catch(XQException &e) { if(e.getXQueryLine() == 0) e.setXQueryPosition(info); throw; } }
void SequenceType::ItemType::staticResolution(StaticContext *context, const LocationInfo *location) { // Prefix resolution should only happen once // (since SequenceType objects can be multiple times in the AST) if(!staticallyResolved_) { staticallyResolved_ = true; if(m_pType && m_TypeURI == 0) { const XMLCh *prefix = m_pType->getPrefix(); // an empty prefix means the default element and type namespace if(prefix == 0 || *prefix == 0) { m_TypeURI = context->getDefaultElementAndTypeNS(); } else { m_TypeURI = context->getUriBoundToPrefix(prefix, location); } } if(m_pName && m_NameURI == 0) { const XMLCh *prefix = m_pName->getPrefix(); // if we are testing for an attribute, an empty prefix means empty namespace; if we are testing an element, it means // the default element and type namespace if(prefix == 0 || *prefix == 0) { if(m_nTestType == TEST_ELEMENT || m_nTestType == TEST_SCHEMA_ELEMENT || m_nTestType == TEST_DOCUMENT || m_nTestType == TEST_SCHEMA_DOCUMENT) m_NameURI = context->getDefaultElementAndTypeNS(); } else { m_NameURI = context->getUriBoundToPrefix(prefix, location); } } } if(m_pType) { if(m_nTestType == ItemType::TEST_ATOMIC_TYPE) { // check if the type to be tested is defined and is really an atomic one if(!context->getDocumentCache()->isTypeDefined(m_TypeURI, m_pType->getName())) { XMLBuffer buf; buf.set(X("Type {")); buf.append(m_TypeURI); buf.append(X("}:")); buf.append(m_pType->getName()); buf.append(X(" is not defined [err:XPST0051]")); XQThrow3(StaticErrorException, X("SequenceType::ItemType::staticResolution"), buf.getRawBuffer(), location); } if(!context->getDocumentCache()->isTypeOrDerivedFromType(m_TypeURI, m_pType->getName(), FunctionConstructor::XMLChXPath2DatatypesURI, AnyAtomicType::fgDT_ANYATOMICTYPE)) { XMLBuffer buf; buf.set(X("Type {")); buf.append(m_TypeURI); buf.append(X("}:")); buf.append(m_pType->getName()); buf.append(X(" is not an atomic type [err:XPST0051]")); XQThrow3(StaticErrorException, X("SequenceType::ItemType::staticResolution"), buf.getRawBuffer(), location); } } else if(!context->getDocumentCache()->isTypeDefined(m_TypeURI, m_pType->getName())) { XMLBuffer msg; msg.set(X("Type {")); msg.append(m_TypeURI); msg.append(X("}")); msg.append(m_pType->getName()); msg.append(X(" is not defined [err:XPTY0004]")); XQThrow3(XPath2ErrorException,X("SequenceType::ItemType::matchesNameType"), msg.getRawBuffer(), location); } } switch(m_nTestType) { case TEST_SCHEMA_DOCUMENT: case TEST_SCHEMA_ELEMENT: { // retrieve the type of the element name SchemaElementDecl *elemDecl = context->getDocumentCache()->getElementDecl(m_NameURI, m_pName->getName()); if(elemDecl == NULL) { XMLBuffer msg(1023, context->getMemoryManager()); msg.set(X("Element {")); msg.append(m_NameURI); msg.append(X("}")); msg.append(m_pName->getName()); msg.append(X(" is not defined as a global element [err:XPST0081]")); XQThrow3(StaticErrorException,X("SequenceType::ItemType::staticResolution"), msg.getRawBuffer(), location); } break; } case TEST_SCHEMA_ATTRIBUTE: { // retrieve the type of the attribute name SchemaAttDef *attrDecl = context->getDocumentCache()->getAttributeDecl(m_NameURI, m_pName->getName()); if(attrDecl == NULL) { XMLBuffer msg(1023, context->getMemoryManager()); msg.set(X("Attribute {")); msg.append(m_NameURI); msg.append(X("}")); msg.append(m_pName->getName()); msg.append(X(" is not defined as a global attribute [err:XPST0081]")); XQThrow3(StaticErrorException,X("SequenceType::ItemType::staticResolution"), msg.getRawBuffer(), location); } break; } default: break; } if(returnType_) returnType_->staticResolution(context); }