Exemplo n.º 1
0
/*******************************************************************************
  14.9.2 fn:parse-xml-fragment
********************************************************************************/
bool FnParseXmlFragmentIterator::nextImpl(
    store::Item_t& result,
    PlanState& planState) const
{
  zstring docString;

  FnParseXmlFragmentIteratorState* state;
  DEFAULT_STACK_INIT(FnParseXmlFragmentIteratorState, state, planState);

  if (consumeNext(result, theChildren[0].getp(), planState))
  {
    if (result->isStreamable())
    {
      state->theFragmentStream.theStream = &result->getStream();
    }
    else
    {
      result->getStringValue2(docString);
      state->theFragmentStream.theIss = new std::istringstream(docString.c_str());
      state->theFragmentStream.theStream = state->theFragmentStream.theIss;
    }

    state->theProperties.setBaseUri(theSctx->get_base_uri());
    state->theProperties.setParseExternalParsedEntity(true);
    state->theProperties.setStoreDocument(false);

    state->baseUri = state->theProperties.getBaseUri();    

    // create only one document node holding all fragment nodes
    state->theFragmentStream.only_one_doc_node = 1;
       
    try
    {
      result = GENV.getStore().loadDocument(state->baseUri,
                                            state->docUri,
                                            state->theFragmentStream,
                                            state->theProperties);
    }
    catch ( ZorbaException const &e )
    {
      if ( !state->theProperties.getNoError() )
      {
        XQueryException xe(
          XQUERY_EXCEPTION(err::FODC0006,
          ERROR_PARAMS( "fn:parse-xml-fragment()", e.what() ),
          ERROR_LOC( loc )));

        set_data( xe, e );
        throw xe;
      }
      result = nullptr;
    }

    if (result != NULL)
      STACK_PUSH(true, state);
  } // if 

  STACK_END(state);
}
Exemplo n.º 2
0
void IndexDelta::addGeneralPair(store::Item_t& node, store::Item_t& key)
{
  assert(node->isNode() && key->isAtomic());

  theGeneralDelta.resize(theGeneralDelta.size() + 1);
  theGeneralDelta.back().first.transfer(node);
  theGeneralDelta.back().second.transfer(key);
}
Exemplo n.º 3
0
static void get_options( store::Item_t const &options_object,
                         options_type *options ) {
  ZORBA_ASSERT( options_object->getKind() == store::Item::OBJECT );
  store::Iterator_t i( options_object->getObjectKeys() );
  i->open();
  store::Item_t opt_key;
  while ( i->next( opt_key ) ) {
    zstring const opt_name( opt_key->getStringValue() );
    store::Item_t const opt_value( options_object->getObjectValue( opt_key ) );
    (*options)[ opt_name ] = opt_value->getStringValue();
  }
  i->close();
}
Exemplo n.º 4
0
void dynamic_context::get_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Item_t& itemValue,
    store::TempSeq_t& seqValue) const
{
  itemValue = NULL;
  seqValue = NULL;

  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    zstring varName = static_context::var_name(varname.getp());

    if (varid >= theVarValues.size() ||
        theVarValues[varid].theIsExternalOrLocal ||
        (varid > 0 && varid < MAX_IDVARS_RESERVED))
    {
      RAISE_ERROR(err::XPDY0002, loc,
      ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varName));
    }
    else
    {
      RAISE_ERROR(err::XQDY0054, loc, ERROR_PARAMS(varName));
    }
  }

  const VarValue& var = theVarValues[varid];

  if (var.theState == VarValue::declared)
  {
    zstring varName = static_context::var_name(varname.getp());

    if (var.theIsExternalOrLocal)
    {
      RAISE_ERROR(err::XPDY0002, loc,
      ERROR_PARAMS(ZED(XPDY0002_VariableHasNoValue_2), varName));
    }
    else
    {
      RAISE_ERROR(err::XQDY0054, loc, ERROR_PARAMS(varName));
    }
  }

  if (var.theState == VarValue::item)
    itemValue = var.theValue.item;
  else
    seqValue = var.theValue.temp_seq;
}
Exemplo n.º 5
0
bool
ZorbaValidateInPlaceIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
  store::Item_t node;

  PlanIteratorState* state;
  store::PUL_t pul;

  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);

  if (consumeNext(node, theChild.getp(), planState))
  {
    // verify that if the element being revalidated is an element it is the root
    if (node->getNodeKind()==store::StoreConsts::elementNode &&
        node->getParent() &&
        node->getParent()->getNodeKind()!=store::StoreConsts::documentNode)
      throw XQUERY_EXCEPTION( zerr::ZAPI0090_CANNOT_VALIDATE_NON_ROOT, ERROR_LOC( loc ) );

    pul = GENV_ITEMFACTORY->createPendingUpdateList();

    pul->addRevalidate(&loc,node);

    result.transfer(pul);
    STACK_PUSH(true, state);
  }

  STACK_END(state);
}
Exemplo n.º 6
0
static void x2j_children( store::Item_t const &parent,
                          vector<store::Item_t> *children ) {
  ZORBA_ASSERT( children );
  store::Iterator_t i( parent->getChildren() );
  i->open();
  store::Item_t child_item, temp_item;
  while ( i->next( child_item ) ) {
    if ( !x2j_map_atomic( child_item, &temp_item ) ) {
      if ( !child_item->isNode() )
        throw XQUERY_EXCEPTION(
          zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
          ERROR_PARAMS( ZED( ZJ2X0001_BadElement ), child_item->getKind() )
        );
      switch ( child_item->getNodeKind() ) {
        case store::StoreConsts::elementNode:
          x2j_element( child_item, &temp_item );
          break;
        case store::StoreConsts::textNode: {
          zstring s( child_item->getStringValue() );
          GENV_ITEMFACTORY->createString( temp_item, s );
          break;
        }
        default:
          continue;
      } // switch
    } // if
    children->push_back( temp_item );
  } // while
  i->close();
}
Exemplo n.º 7
0
bool PlanIterator::consumeNext(
    store::Item_t& result,
    const PlanIterator* iter,
    PlanState& planState)
{
  if (planState.theHasToQuit) 
  {
    // std::cout << "Plan interupted" << std::endl;

    throw FlowCtlException(FlowCtlException::INTERRUPT);
  }
  bool status = iter->produceNext(result, planState);

  if (planState.theCompilerCB->theConfig.print_item_flow)
  {
    if (Properties::instance().getStableIteratorIDs())
      std::cout << "next (" << iter->getId();
    else
      std::cout << "next (" << iter;

    std::cout << " = " << iter->getNameAsString() // typeid (*iter).name()
              << ") -> "
              << "status: " << status << " -> "
              << ((status && result != NULL) ? result->show().c_str() : "null")
              << std::endl;
  }
  return status;
}
Exemplo n.º 8
0
bool NumArithIterator<Operation>::compute(
    store::Item_t& result,
    dynamic_context* dctx,
    const TypeManager* tm,
    const QueryLoc& aLoc, 
    store::Item_t& n0,
    store::Item_t& n1)
{
  assert(n0->isAtomic());
  assert(n1->isAtomic());

  store::SchemaTypeCode type0 = n0->getTypeCode();
  store::SchemaTypeCode type1 = n1->getTypeCode();

  return computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
}
Exemplo n.º 9
0
store::Item_t get_json_value( store::Item_t const &object,
                              char const *key ) {
  zstring key_str( key );
  store::Item_t key_item;
  GENV_ITEMFACTORY->createString( key_item, key_str );
  return object->getObjectValue( key_item );
}
Exemplo n.º 10
0
store::Item_t getFirstAttribute(store::Item_t node)
{
  store::Item_t attr;
  store::Iterator_t attributes = node->getAttributes();
  attributes->open();
  attributes->next(attr);
  attributes->close();
  return attr;
}
Exemplo n.º 11
0
void xml_to_json( store::Item_t const &xml_item, store::Item_t *json_item ) {
  ZORBA_ASSERT( json_item );
  switch ( xml_item->getNodeKind() ) {
    case store::StoreConsts::elementNode:
      x2j_element( xml_item, json_item );
      break;
    default:
      throw XQUERY_EXCEPTION( zerr::ZJSE0001_NOT_ELEMENT_NODE );
  }
}
Exemplo n.º 12
0
bool x2j_map_atomic( store::Item_t const &xml_item, store::Item_t *json_item ) {
  if ( xml_item->isAtomic() ) {
    switch ( xml_item->getTypeCode() ) {
      case store::JS_NULL:
      case store::XS_BOOLEAN:
      case store::XS_BYTE:
      case store::XS_DECIMAL:
      case store::XS_DOUBLE:
      case store::XS_ENTITY:
      case store::XS_FLOAT:
      case store::XS_ID:
      case store::XS_IDREF:
      case store::XS_INT:
      case store::XS_INTEGER:
      case store::XS_LONG:
      case store::XS_NAME:
      case store::XS_NCNAME:
      case store::XS_NEGATIVE_INTEGER:
      case store::XS_NMTOKEN:
      case store::XS_NON_NEGATIVE_INTEGER:
      case store::XS_NON_POSITIVE_INTEGER:
      case store::XS_NORMALIZED_STRING:
      case store::XS_POSITIVE_INTEGER:
      case store::XS_SHORT:
      case store::XS_STRING:
      case store::XS_TOKEN:
      case store::XS_UNSIGNED_BYTE:
      case store::XS_UNSIGNED_INT:
      case store::XS_UNSIGNED_LONG:
      case store::XS_UNSIGNED_SHORT:
        *json_item = xml_item;
        break;
      default:
        zstring s( xml_item->getStringValue() );
        GENV_ITEMFACTORY->createString( *json_item, s );
        break;
    } // switch
    return true;
  } // if
  return false;
}
Exemplo n.º 13
0
void dynamic_context::set_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Item_t& valueItem)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  VarValue& var = theVarValues[varid];

  // variables can be set multiple times, so we need to make sure to remove
  // previously set temp sequences
  if (var.theState == VarValue::item)
  {
    assert(var.theValue.item != NULL);
    var.theValue.item->removeReference();
  }
  else if (var.theState == VarValue::temp_seq)
  {
    assert(var.theValue.temp_seq != NULL);
    RCHelper::removeReference(var.theValue.temp_seq);
  }
  else if (var.theState == VarValue::declared)
  {
    assert(var.theValue.item == NULL);
  }
  else
  {
    ZORBA_ASSERT(false);
  }

  var.theState = VarValue::item;
  var.theValue.item = valueItem.release();
}
Exemplo n.º 14
0
static void j2x_object( store::Item_t const &object_item,
                        store::Item_t *parent_xml_item ) {
  ZORBA_ASSERT( parent_xml_item );
  store::Item_t junk_item, key_item, type_name;

  store::Iterator_t k( object_item->getObjectKeys() );
  k->open();
  while ( k->next( key_item ) ) {
    store::Item_t att_name;
    GENV_ITEMFACTORY->createQName(
      att_name, "", "", key_item->getStringValue()
    );
    store::Item_t value_item( object_item->getObjectValue( key_item ) );
    zstring value_str( value_item->getStringValue() );
    GENV_ITEMFACTORY->createString( value_item, value_str );
    type_name = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
    GENV_ITEMFACTORY->createAttributeNode(
      junk_item, *parent_xml_item, att_name, type_name, value_item
    );
  }
  k->close();
}
Exemplo n.º 15
0
void GeneralIndexCondition::pushRange(
    store::Item_t& lower,
    store::Item_t& upper,
    bool haveLower,
    bool haveUpper,
    bool lowerIncl,
    bool upperIncl)
{
  assert(theKind == BOX_VALUE);
  assert(!theIsSet);
  assert(!haveLower || (lower && lower->isAtomic()));
  assert(!haveUpper || (upper && upper->isAtomic()));

  theRangeFlags.theHaveLowerBound = haveLower;
  theRangeFlags.theHaveUpperBound = haveUpper;
  theRangeFlags.theLowerBoundIncl = lowerIncl;
  theRangeFlags.theUpperBoundIncl = upperIncl;

  if (haveLower)
  {
    theLowerBound.transfer(lower);

    store::Item* baseItem = theLowerBound->getBaseItem();
    if (baseItem != NULL)
      theLowerBound = baseItem;
  }

  if (haveUpper)
  {
    theUpperBound.transfer(upper);

    store::Item* baseItem = theUpperBound->getBaseItem();
    if (baseItem != NULL)
      theUpperBound = baseItem;
  }

  theIsSet = true;
}
Exemplo n.º 16
0
void GeneralIndexCondition::pushItem(store::Item_t& item)
{
  assert(theKind == POINT_VALUE || theKind == POINT_GENERAL);
  assert(!theIsSet);
  assert(item && item->isAtomic());

  theKey.transfer(item);

  store::Item* baseItem = theKey->getBaseItem();
  if (baseItem != NULL)
    theKey = baseItem;

  theIsSet = true;
}
Exemplo n.º 17
0
void dynamic_context::set_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Iterator_t& valueIter)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  valueIter->open();

  // For now, use eager eval because the assignment expression may reference
  // the variable itself, and the current value of the variable is overwriten
  // here by this temp sequence. TODO: use lazy eval if we know the the
  // assignment expression does not reference the variable itself.
  store::TempSeq_t seq = GENV_STORE.createTempSeq(valueIter, false); // no lazy eval

  valueIter->close();

  VarValue& var = theVarValues[varid];

  // variables can be set multiple times, so we need to make sure to remove
  // previously set temp sequences
  if (var.theState == VarValue::item)
  {
    assert(var.theValue.item != NULL);
    var.theValue.item->removeReference();
  }
  else if (var.theState == VarValue::temp_seq)
  {
    assert(var.theValue.temp_seq != NULL);
    RCHelper::removeReference(var.theValue.temp_seq);
  }
  else if (var.theState == VarValue::declared)
  {
    assert(var.theValue.item == NULL);
  }
  else
  {
    ZORBA_ASSERT(false);
  }

  var.theState = VarValue::temp_seq;
  var.theValue.temp_seq = seq.release();
}
Exemplo n.º 18
0
bool EitherNodesOrAtomicsIterator::nextImpl(
    store::Item_t& result,
    PlanState& planState) const
{
  EitherNodesOrAtomicsIteratorState* state;
  DEFAULT_STACK_INIT(EitherNodesOrAtomicsIteratorState, state, planState);

  if (CONSUME(result, 0))
  {
    state->atomics = !result->isNode();

    STACK_PUSH(true, state);

    while (CONSUME(result, 0))
    {
      if (state->atomics == result->isNode())
        throw XQUERY_EXCEPTION(err::XPTY0018, ERROR_LOC(loc));

      STACK_PUSH(true, state);
    }
  }

  STACK_END(state);
}
Exemplo n.º 19
0
void json_to_xml( store::Item_t const &json_item, store::Item_t *xml_item ) {
  ZORBA_ASSERT( xml_item );
  switch ( json_item->getKind() ) {
    case store::Item::ARRAY:
      *xml_item = j2x_array( json_item, nullptr );
      break;
    case store::Item::OBJECT:
      throw XQUERY_EXCEPTION(
        zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
        ERROR_PARAMS( ZED( ZJ2X0001_ArrayRequired ) )
      );
    default:
      ZORBA_ASSERT( false );
  }
}
Exemplo n.º 20
0
bool get_attribute_value( store::Item_t const &element, char const *att_name,
                          zstring *att_value ) {
  store::Iterator_t i( element->getAttributes() );
  bool found = false;
  i->open();
  store::Item_t att_item;
  while ( i->next( att_item ) ) {
    if ( name_of( att_item ) == att_name ) {
      att_item->getStringValue2( *att_value );
      found = true;
      break;
    }
  }
  i->close();
  return found;
}
Exemplo n.º 21
0
/*******************************************************************************
  declare updating function
  remove($uri as xs:string) as empty-sequence()
********************************************************************************/
bool RemoveDocumentIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  zstring       lRetrievedUriString;
  zstring       lResolvedUriString;
  store::Item_t lUri;
  store::Item_t lResolvedUriItem;
  store::PUL_t lPul;

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);

  consumeNext(lUri, theChildren[0].getp(), aPlanState);

  // absolutize retrieved uri
  try
  {
    lUri->getStringValue2(lRetrievedUriString);
    lResolvedUriString = theSctx->resolve_relative_uri(lRetrievedUriString, true);
  }
  catch (ZorbaException const&)
  {
    RAISE_ERROR(err::FODC0004, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoResolveRelativeURI)));
  }

  // check if document exists in the store
  if (GENV_STORE.getDocument(lResolvedUriString) == NULL)
  {
    RAISE_ERROR(zerr::ZXQD0002_DOCUMENT_NOT_VALID, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoURIInStore)));
  }

  // create the pul and add the primitive
  GENV_ITEMFACTORY->createAnyURI(lResolvedUriItem, lResolvedUriString);

  lPul = GENV_ITEMFACTORY->createPendingUpdateList();

  lPul->addDeleteDocument(&loc, lResolvedUriItem);

  result.transfer(lPul);
  STACK_PUSH(result != NULL, state);

  STACK_END(state);
}
Exemplo n.º 22
0
static void x2j_attributes( store::Item_t const &element,
                            store::Item_t *json_item ) {
  ZORBA_ASSERT( json_item );

  store::Item_t att_item;
  vector<store::Item_t> keys, values;

  store::Iterator_t i( element->getAttributes() );
  i->open();
  while ( i->next( att_item ) ) {
    zstring const att_name( name_of( att_item ) );
    if ( att_name != "xmlns" ) {
      push_back( &keys, att_name );
      push_back( &values, att_item->getStringValue() );
    }
  } // while
  i->close();
  if ( !keys.empty() )
    GENV_ITEMFACTORY->createJSONObject( *json_item, keys, values );
}
Exemplo n.º 23
0
store::Item_t SchemaValidatorImpl::findAttributeItem(const store::Item *parent, 
                                                     store::Item_t &attQName)
{
  store::Iterator_t attributes = parent->getAttributes();

  store::Item_t attribute;

  while ( attributes->next(attribute) )
  {
    ZORBA_ASSERT(attribute->isNode());
    ZORBA_ASSERT(attribute->getNodeKind() == store::StoreConsts::attributeNode);

    store::Item_t currentAttName = attribute->getNodeName();

    if (attQName->equals(currentAttName))
    {
      return attribute.getp();
    }
  }
  //ZORBA_ASSERT(false);
  return NULL;
}
Exemplo n.º 24
0
bool TreatIterator::count( store::Item_t &result, PlanState &planState) const {
  bool const ret_val = theChild->count( result, planState );
  xs_integer const count( result->getIntegerValue() );

  switch ( theQuantifier ) {
    case SequenceType::QUANT_QUESTION:
      if ( count <= numeric_consts<xs_integer>::one() )
        break;
      // no break;
    case SequenceType::QUANT_ONE:
      if ( count > numeric_consts<xs_integer>::one() )
        raiseError("sequence of more than one item");
      // no break;
    case SequenceType::QUANT_PLUS:
      if ( count == numeric_consts<xs_integer>::zero() )
        raiseError("empty-sequence()");
      break;
    default:
      // do nothing
      break;
  }
  return ret_val;
}
Exemplo n.º 25
0
void dynamic_context::unset_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  VarValue& var = theVarValues[varid];

  if (var.theState == VarValue::item)
  {
    assert(var.theValue.item != NULL);
    var.theValue.item->removeReference();
  }
  else if (var.theState == VarValue::temp_seq)
  {
    assert(var.theValue.temp_seq != NULL);
    RCHelper::removeReference(var.theValue.temp_seq);
  }
  else if (var.theState == VarValue::declared)
  {
    assert(var.theValue.item == NULL);
  }
  else
  {
    ZORBA_ASSERT(false);
  }

  var.theState = VarValue::declared;
  var.theValue.item = NULL;
}
Exemplo n.º 26
0
void processOptions(store::Item_t item, store::LoadProperties& props, static_context* theSctx, const QueryLoc& loc)
{
  URI lValidatedBaseUri;
  store::Item_t child, tempItem;

  if (item.getp() == NULL)
    return;

#ifndef ZORBA_NO_XMLSCHEMA
  if (item->isValidated())
  {
    if (item->getNodeName() == NULL
        ||
        item->getNodeName()->getNamespace() != static_context::ZORBA_XML_FN_OPTIONS_NS)
    {
      throw XQUERY_EXCEPTION(zerr::ZXQD0003_INCONSISTENT_PARSE_FRAGMENT_OPTIONS,
                             ERROR_PARAMS(ZED(ParseFragmentInvalidOptions)), ERROR_LOC( loc ));
    }
  }
  else
  {
    tempItem = NULL; // used as the effectiveValidationValue()'s typeName
    Validator::effectiveValidationValue(
        item,
        item,
        tempItem,
        theSctx->get_typemanager(),
        ParseConstants::val_strict,
        theSctx,
        loc);
  }
#endif

  store::Iterator_t children = item->getChildren();
  children->open();

  while (children->next(child))
  {
    if (child->getNodeKind() != store::StoreConsts::elementNode)
      continue;

    if (child->getNodeName()->getLocalName() == "base-uri")
    {
      store::Item_t attr = getFirstAttribute(child);

      try {
        lValidatedBaseUri = URI(attr->getStringValue());
      } catch (ZorbaException const& /* e */) {
        throw XQUERY_EXCEPTION(
          err::FODC0007,
          ERROR_PARAMS( attr->getStringValue() ),
          ERROR_LOC( loc )
        );
      }

      if (!lValidatedBaseUri.is_absolute()) {
        throw XQUERY_EXCEPTION(
          err::FODC0007,
          ERROR_PARAMS( lValidatedBaseUri.toString() ),
          ERROR_LOC( loc )
        );
      }

      props.setBaseUri(attr->getStringValue());
    }
    else if (child->getNodeName()->getLocalName() == "no-error")
      props.setNoError(true);
    else if (child->getNodeName()->getLocalName() == "strip-boundary-space")
      props.setStripWhitespace(true);
    else if (child->getNodeName()->getLocalName() == "schema-validate")
    {
      store::Item_t attr = getFirstAttribute(child);
      if (attr->getStringValue() == "strict")
        props.setSchemaStrictValidate(true);
      else
        props.setSchemaLaxValidate(true);
    }
    else if (child->getNodeName()->getLocalName() == "DTD-validate")
      props.setDTDValidate(true);
    else if (child->getNodeName()->getLocalName() == "DTD-load")
      props.setDTDLoad(true);
    else if (child->getNodeName()->getLocalName() == "default-DTD-attributes")
      props.setDefaultDTDAttributes(true);
    else if (child->getNodeName()->getLocalName() == "parse-external-parsed-entity")
    {
      props.setParseExternalParsedEntity(true);
      store::Item_t attr;
      store::Iterator_t attribs = child->getAttributes();
      attribs->open();
      while (attribs->next(attr))
      {
        if (attr->getNodeName()->getLocalName() == "skip-root-nodes")
          props.setSkipRootNodes(ztd::aton<xs_int>(attr->getStringValue().c_str()));
        else if (attr->getNodeName()->getLocalName() == "skip-top-level-text-nodes")
          props.setSkipTopLevelTextNodes(true);
        else if (attr->getNodeName()->getLocalName() == "error-on-doctype")
          props.setErrorOnDoctype(true);
      }
      attribs->close();
    }
    else if (child->getNodeName()->getLocalName() == "substitute-entities")
      props.setSubstituteEntities(true);
    else if (child->getNodeName()->getLocalName() == "xinclude-substitutions")
      props.setXincludeSubstitutions(true);
    else if (child->getNodeName()->getLocalName() == "remove-redundant-ns")
      props.setRemoveRedundantNS(true);
    else if (child->getNodeName()->getLocalName() == "no-CDATA")
      props.setNoCDATA(true);
    else if (child->getNodeName()->getLocalName() == "no-xinclude-nodes")
      props.setNoXIncludeNodes(true);
    else if (child->getNodeName()->getLocalName() == "no-network-access")
      props.setNoNetworkAccess(true);
  }

  children->close();

  if (props.getSchemaLaxValidate() + props.getSchemaStrictValidate() +
      props.getDTDValidate() + props.getParseExternalParsedEntity() > 1)
  {
    throw XQUERY_EXCEPTION(zerr::ZXQD0003_INCONSISTENT_PARSE_FRAGMENT_OPTIONS,
                           ERROR_PARAMS(ZED(ParseFragmentOptionCombinationNotAllowed)), ERROR_LOC( loc ));
  }
}
Exemplo n.º 27
0
bool TreatIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
  store::Item_t temp;
  bool res;
  const TypeManager* tm = theSctx->get_typemanager();

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);

  if (!consumeNext(result, theChild.getp(), planState))
  {
    if (theQuantifier == SequenceType::QUANT_PLUS ||
        theQuantifier == SequenceType::QUANT_ONE)
    {
      raiseError("empty-sequence()");
    }
  }
  else if (theQuantifier == SequenceType::QUANT_QUESTION ||
           theQuantifier == SequenceType::QUANT_ONE)
  {
    if (consumeNext(temp, theChild.getp(), planState))
    {
      raiseError("sequence of more than one item");
    }

    if (theCheckPrime)
    {
      if (theTreatType->type_kind() == XQType::ATOMIC_TYPE_KIND &&
          result->isAtomic())
      {
        store::SchemaTypeCode targetType = 
        static_cast<const AtomicXQType*>(theTreatType.getp())->get_type_code();

        store::SchemaTypeCode itemType = result->getTypeCode();

        res = TypeOps::is_subtype(itemType, targetType);
      }
      else
      {
        res = TypeOps::is_subtype(tm, result, *theTreatType, loc);
      }
      
      if (!res)
      {
        zstring valueType = tm->create_value_type(result)->toSchemaString();
        raiseError(valueType);
      }
    }

    STACK_PUSH(true, state);
  }
  else
  {
    do
    {
      if (theCheckPrime) 
      {
        if (theTreatType->type_kind() == XQType::ATOMIC_TYPE_KIND &&
            result->isAtomic())
        {
          store::SchemaTypeCode targetType = 
          static_cast<const AtomicXQType*>(theTreatType.getp())->get_type_code();

          store::SchemaTypeCode itemType = result->getTypeCode();

          res = TypeOps::is_subtype(itemType, targetType);
        }
        else
        {
          res = TypeOps::is_subtype(tm, result, *theTreatType, loc);
        } 
        
        if (!res)
        {
          zstring valueType = tm->create_value_type(result)->toSchemaString();
          raiseError(valueType);
        }
      }

      STACK_PUSH(true, state);
    } 
    while (consumeNext(result, theChild.getp(), planState));
  }

  STACK_END(state);
}
Exemplo n.º 28
0
bool GenericArithIterator<Operation>::compute(
    store::Item_t& result,
    dynamic_context* dctx,
    const TypeManager* tm,
    const QueryLoc& aLoc, 
    store::Item_t& n0,
    store::Item_t& n1)
{
  RootTypeManager& rtm = GENV_TYPESYSTEM;

  assert(n0->isAtomic());
  assert(n1->isAtomic());

  store::SchemaTypeCode type0 = n0->getTypeCode();
  store::SchemaTypeCode type1 = n1->getTypeCode();
  
  if (TypeOps::is_numeric(type0) &&
      (TypeOps::is_subtype(type1, store::XS_YM_DURATION) ||
       TypeOps::is_subtype(type1, store::XS_DT_DURATION)))
  {
    GenericCast::castToAtomic(n0, n0, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);

    if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
    {
      return Operation::template
             compute<store::XS_DOUBLE, store::XS_YM_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else
    {
      return Operation::template
             compute<store::XS_DOUBLE,store::XS_DT_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION) &&
           TypeOps::is_subtype(type1, store::XS_TIME))
  {
    return Operation::template
           compute<store::XS_DURATION,store::XS_TIME>
           (result, dctx, tm, &aLoc, n0, n1);
  }
  else if (TypeOps::is_subtype(type0, store::XS_YM_DURATION))
  {
    if (TypeOps::is_numeric(type1))
    {
      GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);
      return Operation::template
             compute<store::XS_YM_DURATION,store::XS_DOUBLE>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
    {
      return Operation::template
             compute<store::XS_DURATION,store::XS_DATETIME>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DATE))
    {
      return Operation::template
             compute<store::XS_DURATION,store::XS_DATE>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (type0 == type1)
    {
      return Operation::template
      computeSingleType<store::XS_YM_DURATION>
      (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if (TypeOps::is_subtype(type0, store::XS_DT_DURATION))
  {
    if (TypeOps::is_numeric(type1))
    {
      GenericCast::castToAtomic(n1, n1, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, aLoc);

      return Operation::template
             compute<store::XS_DT_DURATION,store::XS_DOUBLE>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DATETIME))
    {
      return Operation::template 
             compute<store::XS_DURATION,store::XS_DATETIME>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DATE))
    {
      return Operation::template
             compute<store::XS_DURATION,store::XS_DATE>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (type0 == type1)
    {
      return Operation::template
             computeSingleType<store::XS_DT_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if (TypeOps::is_subtype(type0, store::XS_DATETIME))
  {
    if (TypeOps::is_subtype(type1, store::XS_DATETIME))
    {
      return Operation::template
             compute<store::XS_DATETIME,store::XS_DATETIME>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
    {
      return Operation::template
             compute<store::XS_DATETIME,store::XS_DURATION>
            (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
    {
      return Operation::template
             compute<store::XS_DATETIME,store::XS_DURATION>
            (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if (TypeOps::is_subtype(type0, store::XS_DATE))
  {
    if (TypeOps::is_subtype(type1, store::XS_DATE))
    {
      return Operation::template
             compute<store::XS_DATE,store::XS_DATE>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_YM_DURATION))
    {
      return Operation::template
             compute<store::XS_DATE,store::XS_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
    {
      return Operation::template
             compute<store::XS_DATE,store::XS_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if (TypeOps::is_subtype(type0, store::XS_TIME))
  {
    if (TypeOps::is_subtype(type1, store::XS_TIME))
    {
      return Operation::template
             compute<store::XS_TIME,store::XS_TIME>
             (result, dctx, tm, &aLoc, n0, n1);
    }
    else if (TypeOps::is_subtype(type1, store::XS_DT_DURATION))
    {
      return Operation::template 
             compute<store::XS_TIME,store::XS_DURATION>
             (result, dctx, tm, &aLoc, n0, n1);
    }
  }
  else if ((TypeOps::is_numeric(type0) || type0 == store::XS_UNTYPED_ATOMIC) &&
           (TypeOps::is_numeric(type1) || type1 == store::XS_UNTYPED_ATOMIC))
  {
    return NumArithIterator<Operation>::
           computeAtomic(result, dctx, tm, aLoc, n0, type0, n1, type1);
  }

  {  
    xqtref_t type0 = tm->create_value_type(n0);
    xqtref_t type1 = tm->create_value_type(n1);

    RAISE_ERROR(err::XPTY0004, aLoc,
    ERROR_PARAMS(ZED(ArithOpNotDefinedBetween_23), *type0, *type1));
  }

  return false; // suppresses wanring
}
Exemplo n.º 29
0
void SchemaValidatorImpl::processElement(
    store::PUL* pul,
    TypeManager* typeManager,
    EventSchemaValidator& schemaValidator,
    store::Item_t element,
    const QueryLoc& loc)
{
  ZORBA_ASSERT(element->isNode());
  ZORBA_ASSERT(element->getNodeKind() == store::StoreConsts::elementNode);

  store::Item_t nodeName = element->getNodeName();
  zstring baseUri;
  element->getBaseURI(baseUri);

  //cout << " vup    - processElement: " << nodeName->getLocalName()->c_str()
  //    << " @ " << nodeName->getNamespace()->c_str() << "\n"; cout.flush();

  schemaValidator.startElem(nodeName);

  // namespace declarations must go first
  processNamespaces( schemaValidator, element);

  // since the type of an element is determined only after the validator
  // receives all of it's attributes, and an attribute node needs it's
  // parent when created we need to go through the attributes twice: once
  // for validation and once for creation
  validateAttributes(schemaValidator, element->getAttributes());

  store::Item_t typeQName = schemaValidator.getTypeQName();
  store::Item_t substitutedElemQName = schemaValidator.getSubstitutedElemQName();

  //cout << " vup      - elemType old: "
  //    << element->getType()->getLocalName()->c_str() << " @ "
  //    << element->getType()->getNamespace()->c_str() << "\n"; cout.flush();
  //cout << " vup      - elemType new: " << typeQName->getLocalName()->c_str()
  //    << " @ " << typeQName->getNamespace()->c_str() << "\n"; cout.flush();

  bool isInSubstitutionElement = false;
  if (substitutedElemQName)
  {
    isInSubstitutionElement = true;
    //    cout << " vup        - substitutes: " << substitutedElemQName->g
    //  etLocalName()->c_str() << " @ " << substitutedElemQName->getNamespace()->
    // c_str() << "\n"; cout.flush();
  }

  bool isNewType = false;
  xqtref_t newType;
  store::Item_t elm;

  if ( !typeQName->equals(element->getType()) )
  {
    isNewType = true;
    newType = typeManager->create_named_type(typeQName, SequenceType::QUANT_ONE, loc);

    elm = element;
  }

  store::NsBindings bindings;
  element->getNamespaceBindings(bindings);
  namespace_context nsCtx = namespace_context(theSctx, bindings);

  processAttributes(pul, nsCtx, typeManager, schemaValidator, element, 
                    element->getAttributes(), loc);

  std::vector<store::Item_t> typedValues;
  int noOfChildren = processChildren(pul,
                                     nsCtx,
                                     typeManager, 
                                     schemaValidator,
                                     element->getChildren(),
                                     typedValues,
                                     loc);

  if ( isNewType )
  {
    bool tHasValue      = Validator::typeHasValue(newType);
    bool tHasTypedValue = Validator::typeHasTypedValue(typeManager, newType, loc);
    bool tHasEmptyValue = Validator::typeHasEmptyValue(newType);

    if ( noOfChildren==0 )
    {
      // workaround for elem of type xsd:string with no text child
      if ( newType->is_builtin() && 
          newType->getQName()->equals(GENV_TYPESYSTEM.STRING_TYPE_ONE->getQName()) )
      {
        /*store::Item_t result;
         zstring emptyStr = "";
         GENV_ITEMFACTORY->createString( result, emptyStr);
         typedValues.push_back(result);*/
        tHasEmptyValue = true;
        tHasTypedValue = false;
        tHasValue = false;
      }
      else if ( newType->type_kind()==XQType::USER_DEFINED_KIND )
      {
        const UserDefinedXQType udXQType = static_cast<const UserDefinedXQType&>(*newType);
        if ( udXQType.isSubTypeOf(typeManager, *GENV_TYPESYSTEM.STRING_TYPE_ONE) )
        {
          tHasEmptyValue = true;
          tHasTypedValue = false;
          tHasValue = false;
        }
      }
    }

    //cout << " vup        - addSetElementType: " << elm->getNodeName()->
    //  getLocalName()->str() << "   " << newType->get_qname()->getLocalName() 
    //  << " @ " << newType->get_qname()->getNamespace() << "\n"; cout.flush();
    //cout << " vup             - " << ( tHasTypedValue ? "hasTypedValue" : "" )
    //  << " values.size: " << typedValues.size() << (typedValues.size()>0 ? 
    // " [0]=" + typedValues[0]->getStringValue()->str() : "" ) << ( tHasValue ?
    // " hasValue" : "" ) << ( tHasEmptyValue ? " hasEmptyValue" : "" ) << "\n";
    //  cout.flush();

    if ( typedValues.size()==1 )
      pul->addSetElementType(&loc,
                             elm,
                             typeQName,
                             typedValues[0],
                             tHasValue,
                             tHasEmptyValue,
                             tHasTypedValue,
                             isInSubstitutionElement);
    else
      pul->addSetElementType(&loc,
                             elm,
                             typeQName,
                             (std::vector<store::Item_t>&)typedValues,
                             tHasValue,
                             tHasEmptyValue,
                             tHasTypedValue,
                             isInSubstitutionElement);
  }

  schemaValidator.endElem(nodeName);
}
Exemplo n.º 30
0
static store::Item_t j2x_array( store::Item_t const &array_item,
                                store::Item *parent_xml_item ) {
  zstring base_uri;
  store::NsBindings ns_bindings;
  store::Item_t array_elt_item, element_name, junk_item, type_name, xml_item;

  store::Iterator_t i( array_item->getArrayValues() );
  i->open();

  if ( !i->next( array_elt_item ) )
    throw XQUERY_EXCEPTION(
      zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
      ERROR_PARAMS( ZED( ZJ2X0001_EmptyArray ) )
    );
  if ( !array_elt_item->isAtomic() ||
       !TypeOps::is_subtype( array_elt_item->getTypeCode(), store::XS_STRING ) )
    throw XQUERY_EXCEPTION(
      zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
      ERROR_PARAMS( ZED( ZJ2X0001_Bad1stElement ) )
    );

  GENV_ITEMFACTORY->createQName(
    element_name, "", "", array_elt_item->getStringValue()
  );
  type_name = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
  GENV_ITEMFACTORY->createElementNode(
    xml_item, parent_xml_item,
    element_name, type_name, false, false, ns_bindings, base_uri
  );

  bool did_attributes = false;
  while ( i->next( array_elt_item ) ) {
    switch ( array_elt_item->getKind() ) {
      case store::Item::ARRAY:
        j2x_array( array_elt_item, xml_item.getp() );
        break;
      case store::Item::ATOMIC: {
        zstring value_str( array_elt_item->getStringValue() );
        GENV_ITEMFACTORY->createTextNode( junk_item, xml_item, value_str );
        break;
      }
      case store::Item::OBJECT:
        if ( did_attributes )
          throw XQUERY_EXCEPTION(
            zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
            ERROR_PARAMS( ZED( ZJ2X0001_UnexpectedObject ) )
          );
        j2x_object( array_elt_item, &xml_item );
        did_attributes = true;
        break;
      default:
        throw XQUERY_EXCEPTION(
          zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
          ERROR_PARAMS( ZED( ZJ2X0001_BadElement ), array_elt_item->getKind() )
        );
    } // switch
  } // while

  i->close();
  return xml_item;
}