コード例 #1
0
ファイル: update.cpp プロジェクト: buchenberg/zorba
void areNodeModifiersViolated(
    const static_context* aSctx,
    const store::Item* aTarget,
    const QueryLoc& aLoc)
{
  const store::Collection* lColl = aTarget->getCollection();
  if (lColl != 0 && !lColl->isDynamic()) 
  {
    const StaticallyKnownCollection* lDeclColl = 
    aSctx->lookup_collection(lColl->getName());

    if (lDeclColl == NULL)
    {
      throw XQUERY_EXCEPTION(zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
                             ERROR_PARAMS(lColl->getName()->getStringValue()),
                             ERROR_LOC(aLoc));
    }

    switch(lDeclColl->getNodeModifier()) 
    {
    case StaticContextConsts::read_only:
      throw XQUERY_EXCEPTION(zerr::ZDDY0010_COLLECTION_CONST_NODE_UPDATE,
                             ERROR_PARAMS( lColl->getName()->getStringValue() ),
                             ERROR_LOC(aLoc));

    case StaticContextConsts::mutable_node:
      // good to go
      break;
    }
  }
}
コード例 #2
0
ファイル: arithmetic_impl.cpp プロジェクト: cezarfx/zorba
bool DivideOperation::compute<store::XS_DT_DURATION,store::XS_DOUBLE>
( store::Item_t& result,
  dynamic_context* dctx,
  const TypeManager* tm,
  const QueryLoc* loc,
  const store::Item* i0,
  const store::Item* i1 )
{
  std::unique_ptr<Duration> d;

  if( i1->getDoubleValue().isPosInf() || i1->getDoubleValue().isNegInf() )
  {
    d.reset(new Duration());
  }
  else if ( i1->getDoubleValue().isZero() )
    throw XQUERY_EXCEPTION( err::FODT0002, ERROR_LOC( loc ) );
  else if ( i1->getDoubleValue().isNaN() )
    throw XQUERY_EXCEPTION( err::FOCA0005, ERROR_LOC( loc ) );
  else try {
    d.reset(i0->getDayTimeDurationValue() / i1->getDoubleValue());
  } catch (XQueryException& e) {
    set_source(e, *loc);
    throw;
  }

  return GENV_ITEMFACTORY->createDayTimeDuration(result, d.get());
}
コード例 #3
0
ファイル: index_func_impl.cpp プロジェクト: alyst/zorba
bool
IndexKeysIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  store::Item_t    lQName;
  IndexDecl_t      indexDecl;
  store::IndexKey  lKey;

  store::Item_t lKeyNodeName;
  GENV_ITEMFACTORY->createQName(lKeyNodeName,
      static_context::ZORBA_STORE_UNORDERED_MAPS_FN_NS,
      "", "key");

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

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

  if ((indexDecl = theSctx->lookup_index(lQName)) == NULL)
  {
    throw XQUERY_EXCEPTION(
      zerr::ZDDY0021_INDEX_NOT_DECLARED,
      ERROR_PARAMS( lQName->getStringValue() ),
      ERROR_LOC( loc )
    );
  }

  state->theIndex = GENV_STORE.getIndex(lQName);

  if (!state->theIndex)
  {
    throw XQUERY_EXCEPTION(
      zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
      ERROR_PARAMS( lQName->getStringValue() ),
      ERROR_LOC( loc )
    );
  }

  state->theIter = state->theIndex->keys();

  state->theIter->open();

  // generate result elements of the form
  // <key>
  //   <attribute value="key1_value"/>
  //   <attribute value="key2_value"/>
  //   <attribute value="key3_value"/>
  // </key>
  while (state->theIter->next(lKey))
  {
    IndexUtil::createIndexKeyElement(
        state->theIndex->getSpecification().theIsGeneral,
        result, lKey, static_context::ZORBA_STORE_STATIC_INDEXES_DML_FN_NS
      );
    STACK_PUSH(true, state);
  }

  STACK_END(state);
}
コード例 #4
0
ファイル: PPFtScan.cpp プロジェクト: bitkeeper/sedna
void PPFtScan::do_next(xqp_tuple &t)
{
        if (first_time)
    {
        tuple_cell tc;

        index_type.op->next(t);
        if (t.is_eos())
            throw XQUERY_EXCEPTION(SE1071);
        tc = t.cells[0];
        if (!tc.is_atomic() || !is_string_type(tc.get_atomic_type()))
            throw XQUERY_EXCEPTION(SE1071);
        tc = tuple_cell::make_sure_light_atomic(tc);
        ft_index_type itype = str2ft_index_type(tc.get_str_mem());

        if (cust_rules.op)
        {
            ptr = ft_custom_tree_t::init();

            ft_index_template_t * templ = make_cust_rules_vector(&cust_rules, cxt);
            ft_index_template_t::iterator tmp=templ->begin();
            while (tmp!=templ->end())
            {
                ptr->put(new ft_custom_cell(tmp->first, tmp->second));
                tmp++;
            }
            delete_cust_rules_vector(templ);
        }
        sj=se_new SednaSearchJob(&seq, itype, ptr);

        query.op->next(t);
        if (t.is_eos())
            throw XQUERY_EXCEPTION(SE1071);
        tc = t.cells[0];
        if (!tc.is_atomic() || !is_string_type(tc.get_atomic_type()))
            throw XQUERY_EXCEPTION(SE1071);

        sj->set_request(tc);
        query.op->next(t);
        if (!t.is_eos())
            throw XQUERY_EXCEPTION(SE1071);

        first_time = false;
    }

    sj->get_next_result(t);
    if (t.is_eos())
    {
        delete sj;
        sj = NULL;
        first_time = true;
    }
}
コード例 #5
0
ファイル: schema_impl.cpp プロジェクト: zorba-processor/zorba
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);
}
コード例 #6
0
Resource*
FileURLResolver::resolveURL
(zstring const& aUrl, EntityData const* aEntityData)
{
  switch ( aEntityData->getKind() ) {
    case EntityData::COLLECTION:
#ifndef ZORBA_NO_FULL_TEXT
    case EntityData::THESAURUS:
#endif /* ZORBA_NO_FULL_TEXT */
      return nullptr;
    default:
      break;
  }

  uri::scheme lScheme = uri::get_scheme(aUrl);
  if (lScheme != uri::file) {
    return NULL;
  }
  try {
    std::string lPath( fs::normalize_path(aUrl) );
    if (fs::get_type(lPath) == fs::file) {
      std::ifstream* lStream = new std::ifstream(lPath.c_str());
      return new StreamResource(
          lStream, &fileStreamReleaser, "", true /* seekable */);
    }
    return NULL;
  }
  catch ( std::invalid_argument const &e ) {
    throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
  }
}
コード例 #7
0
void dynamic_context::set_implicit_timezone(long tzone_seconds)
{
  if (tzone_seconds > 14*3600 || tzone_seconds < -14*3600)
    throw XQUERY_EXCEPTION(err::FODT0003, ERROR_PARAMS(tzone_seconds));

  theTimezone = tzone_seconds;
}
コード例 #8
0
ファイル: jsonml_array.cpp プロジェクト: alyst/zorba
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();
}
コード例 #9
0
ファイル: path_expr.cpp プロジェクト: zorba-processor/zorba
void relpath_expr::compute_scripting_kind()
{
  theScriptingKind = UNKNOWN_SCRIPTING_KIND;

  for (unsigned i = 0; i < size(); ++i)
  {
    expr* step = theSteps[i];

    if (step->is_updating())
    {
      throw XQUERY_EXCEPTION(err::XUST0001,
                             ERROR_PARAMS(ZED(XUST0001_Generic)),
                             ERROR_LOC(get_loc()));
    }

    theScriptingKind |= step->get_scripting_detail();
  }

  theScriptingKind &= ~VACUOUS_EXPR;

  if (is_sequential(theScriptingKind))
    theScriptingKind &= ~SIMPLE_EXPR;

  checkScriptingKind();
}
コード例 #10
0
ファイル: update.cpp プロジェクト: buchenberg/zorba
bool
DeleteIterator::nextImpl(store::Item_t& result, PlanState& aPlanState) const
{ 
  store::Item_t target;
  std::unique_ptr<store::PUL> pul;

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

  pul.reset(GENV_ITEMFACTORY->createPendingUpdateList());

  while (consumeNext(target, theChild, aPlanState))
  {
    if (!target->isNode())
      throw XQUERY_EXCEPTION( err::XUTY0007, ERROR_LOC( loc ) );

    areNodeModifiersViolated(theSctx, target, loc);

    pul->addDelete(&loc, target);

  }
  result = pul.release();
  STACK_PUSH(true, state);
  STACK_END(state);
}
コード例 #11
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);
}
コード例 #12
0
ファイル: jsonml_array.cpp プロジェクト: alyst/zorba
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 );
  }
}
コード例 #13
0
ファイル: arithmetic_impl.cpp プロジェクト: cezarfx/zorba
bool DivideOperation::compute<store::XS_DT_DURATION, store::XS_DT_DURATION>(
    store::Item_t& result,
    dynamic_context* dctx,
    const TypeManager* tm,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1 )
{
  xs_dayTimeDuration otherDTDuration = i1->getDayTimeDurationValue();
  if (otherDTDuration.isZero())  
      throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC(loc));
  xs_decimal d = i0->getDayTimeDurationValue() / otherDTDuration;
  return GENV_ITEMFACTORY->createDecimal(result, d);
}
コード例 #14
0
ファイル: NumericsImpl.cpp プロジェクト: alyst/zorba
bool IntegerDivideOperation::compute<store::XS_DOUBLE,store::XS_DOUBLE>(
    store::Item_t& result,
    dynamic_context* /* dctx */,
    const TypeManager* /* tm */,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1 )
{
  xs_double d0 = i0->getDoubleValue();
  xs_double d1 = i1->getDoubleValue();

  if ( d1 == numeric_consts<xs_double>::zero() )
  {
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
  }

  if (i0->isNaN() || i1->isNaN()) 
  {
    throw XQUERY_EXCEPTION(
      err::FOAR0002, ERROR_PARAMS( ZED( DivisionNoNaN ) ), ERROR_LOC( loc )
    );
  }
  if (i0->isPosOrNegInf()) 
  {
    throw XQUERY_EXCEPTION(
      err::FOAR0002, ERROR_PARAMS( ZED( DivisionNoINF ) ), ERROR_LOC( loc )
    );
  }

  if (i0->isPosOrNegInf()) {
    // idiv with +-INF divisor has 0 as result
    return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
  }

  xs_integer const lInteger( d0 / d1 );
  return GENV_ITEMFACTORY->createInteger (result,  lInteger );
}
コード例 #15
0
ファイル: schema_impl.cpp プロジェクト: zorba-processor/zorba
bool
ValidateIterator::nextImpl(store::Item_t& result, PlanState& planState) const 
{
  store::Item_t item;
  store::Item_t tmp;

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

  if (consumeNext(item, theChild, planState))
  {
    if (consumeNext(tmp, theChild, planState))
    {
      throw XQUERY_EXCEPTION( err::XQTY0030, ERROR_LOC( loc ) );
      // STACK_PUSH(false, aState); -- THIS IS NEVER REACHED
    }
    else
    {
      STACK_PUSH(Validator::effectiveValidationValue(result,
                                                     item,
                                                     typeName,
                                                     typemgr.getp(),
                                                     validationMode,
                                                     theSctx,
                                                     this->loc),
                 aState);
    }
  }
  else
  {
    throw XQUERY_EXCEPTION( err::XQTY0030, ERROR_LOC( loc ) );
    // STACK_PUSH(false, aState); -- THIS IS NEVER REACHED
  }

  STACK_END (aState);
}
コード例 #16
0
ファイル: jsonml_array.cpp プロジェクト: alyst/zorba
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 );
  }
}
コード例 #17
0
ファイル: NumericsImpl.cpp プロジェクト: alyst/zorba
bool DivideOperation::compute<store::XS_DECIMAL,store::XS_DECIMAL>(
    store::Item_t& result,
    dynamic_context* /*dctx*/,
    const TypeManager* /* tm */,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1)
{
  xs_decimal ld0 = i0->getDecimalValue();
  xs_decimal ld1 = i1->getDecimalValue();
  if ( ld1.sign() == 0 )
  {
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
  }
  return GENV_ITEMFACTORY->createDecimal (result,  ld0 / ld1 );
}
コード例 #18
0
ファイル: NumericsImpl.cpp プロジェクト: alyst/zorba
bool DivideOperation::compute<store::XS_INTEGER,store::XS_INTEGER>(
    store::Item_t& result,
    dynamic_context* /* dctx */,
    const TypeManager* /* tm */,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1 )
{
  xs_decimal const ll0(i0->getIntegerValue());
  xs_decimal const ll1(i1->getIntegerValue());
  if ( ll1.sign() == 0 )
  {
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
  }
  return GENV_ITEMFACTORY->createDecimal (result,  ll0 / ll1 );
}
コード例 #19
0
ファイル: jsound_impl.cpp プロジェクト: zorba-processor/zorba
static bool get_bool_opt( store::Item_t const &object,
                          char const *opt_name, bool *result ) {
  store::Item_t opt_item;
  if ( get_json_option( object, opt_name, &opt_item ) ) {
    if ( !IS_ATOMIC_TYPE( opt_item, XS_BOOLEAN ) )
      throw XQUERY_EXCEPTION(
        jse::INVALID_OPTION,
        ERROR_PARAMS(
          opt_item->getStringValue(),
          opt_name,
          ZED( INVALID_OPTION_jse_MustBeBoolean )
        )
      );
    *result = opt_item->getBooleanValue();
    return true;
  }
  return false;
}
コード例 #20
0
ファイル: PPFtHighlight.cpp プロジェクト: sunnlo/sedna
void PPFtHighlight::do_next(xqp_tuple &t)
{
    if (first_time)
    {
        tuple_cell tc;

        U_ASSERT(fthl == NULL);

        if (options.op)
        {
            options.op->next(t);
            if (t.is_eos())
                throw XQUERY_EXCEPTION(SE1071);
            tc = t.cells[0];
            if (!tc.is_atomic() || !is_string_type(tc.get_atomic_type()))
                throw XQUERY_EXCEPTION(SE1071);

            op_str_buf buf(tc);
            fthl = new FtHighlighter(hl_fragment, &seq);
            fthl->set_options(buf.c_str());

            options.op->next(t);
            if (!t.is_eos())
                throw XQUERY_EXCEPTION(SE1071);
        }
        else
            fthl = new FtHighlighter(hl_fragment, &seq);

        query.op->next(t);
        if (t.is_eos())
            throw XQUERY_EXCEPTION(SE1071);
        tc = t.cells[0];
        if (!tc.is_atomic() || !is_string_type(tc.get_atomic_type()))
            throw XQUERY_EXCEPTION(SE1071);

        fthl->set_request(tc);
        query.op->next(t);
        if (!t.is_eos())
            throw XQUERY_EXCEPTION(SE1071);

        first_time = false;
    }

    fthl->get_next_result(t);

    if (t.is_eos())
    {
        delete fthl;
        fthl = NULL;
        first_time = true;
    }
}
コード例 #21
0
ファイル: json_impl.cpp プロジェクト: cezarfx/zorba
bool XMLtoJSONInternal::nextImpl( store::Item_t& result,
                                  PlanState &planState ) const {
  store::Item_t xml_item;
  options_type options;

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

  ZORBA_ASSERT( theChildren.size() == 2 );
  consumeNext( xml_item, theChildren[1], planState );
  get_options( xml_item, &options );

  consumeNext( xml_item, theChildren[0], planState );
  try {
    options_type::mapped_type const &format_opt = options[ "json-format" ];
    ZORBA_ASSERT( !format_opt.empty() );

    switch ( xml_item->getNodeKind() ) {
      case store::StoreConsts::elementNode:
        if ( format_opt == "Snelson" )
          snelson::xml_to_json( xml_item, &result );
        else if ( format_opt == "JsonML" || format_opt == "JsonML-array" )
          jsonml_array::xml_to_json( xml_item, &result );
        else if ( format_opt == "JsonML-object" )
          jsonml_object::xml_to_json( xml_item, &result );
        else
          ZORBA_ASSERT( false );
        break;
      default:
        throw XQUERY_EXCEPTION(
          zerr::ZJSE0001_NOT_ELEMENT_NODE,
          ERROR_LOC( loc )
        );
    } // switch
  }
  catch ( ZorbaException &e ) {
    set_source( e, loc );
    throw;
  }

  STACK_PUSH( !!result, state );
  STACK_END( state );
}
コード例 #22
0
ファイル: arithmetic_impl.cpp プロジェクト: cezarfx/zorba
bool SubtractOperation::compute<store::XS_TIME,store::XS_TIME>(
    store::Item_t& result,
    dynamic_context* dctx,
    const TypeManager* tm,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1)
{
  std::unique_ptr<Duration> d;
  try 
  {
    d.reset(i0->getTimeValue().subtractDateTime(&i1->getTimeValue(),
                                                dctx->get_implicit_timezone()));
  }
  catch (InvalidTimezoneException const &e)
  {
    throw XQUERY_EXCEPTION(err::FODT0003, ERROR_PARAMS(e.get_tz_seconds()));
  }
  return GENV_ITEMFACTORY->createDayTimeDuration(result, d.get());
}
コード例 #23
0
ファイル: path_expr.cpp プロジェクト: zorba-processor/zorba
void relpath_expr::add_back(expr* step)
{
  if (step->is_updating())
  {
    throw XQUERY_EXCEPTION(err::XUST0001,
                           ERROR_PARAMS(ZED(XUST0001_Generic)),
                           ERROR_LOC(get_loc()));
  }

  theScriptingKind |= step->get_scripting_detail();

  if (theScriptingKind & VACUOUS_EXPR)
    theScriptingKind &= ~VACUOUS_EXPR;

  if (is_sequential(theScriptingKind))
    theScriptingKind &= ~SIMPLE_EXPR;

  checkScriptingKind();

  theSteps.push_back(step);
}
コード例 #24
0
// ---------------------------------------------------------------------------
//  LoadSchemaErrorHandler: Overrides of the SAX ErrorHandler interface
// ---------------------------------------------------------------------------
void LoadSchemaErrorHandler::error(const XERCES_CPP_NAMESPACE::SAXParseException& e)
{
  zstring system_id, public_id;
  if ( e.getSystemId() )
    system_id = StrX( e.getSystemId() ).localFormOrDefault( "" );
  if ( e.getPublicId() )
    public_id = StrX( e.getPublicId() ).localFormOrDefault( "" );

  theSawErrors = true;
  throw XQUERY_EXCEPTION(
    err::XQST0059,
    ERROR_PARAMS(
      ZED( XQST0059_XercesMessage ),
      e.getLineNumber(),
      e.getColumnNumber(),
      system_id,
      public_id,
      StrX( e.getMessage() ).localFormOrDefault( "" )
    ),
    ERROR_LOC( theQueryLoc )
  );
}
コード例 #25
0
ファイル: compiler_api.cpp プロジェクト: alyst/zorba
/******************************************************************************
  Create a dummy main module to wrap a library module.
******************************************************************************/
parsenode_t XQueryCompiler::createMainModule(
    parsenode_t aLibraryModule,
    std::istream& aXQuery,
    const zstring& aFileName)
{
  //get the namespace from the LibraryModule
  LibraryModule* mod_ast = dynamic_cast<LibraryModule *>(&*aLibraryModule);
  if (!mod_ast)
    throw ZORBA_EXCEPTION(zerr::ZAPI0002_XQUERY_COMPILATION_FAILED,
    ERROR_PARAMS(ZED(BadLibraryModule)));

  const zstring& lib_namespace = mod_ast->get_decl()->get_target_namespace();

  URI lURI(lib_namespace);
  if(!lURI.is_absolute())
  {
    throw XQUERY_EXCEPTION(err::XQST0046,
    ERROR_PARAMS(lURI.toString(), ZED(MustBeAbsoluteURI)),
      ERROR_LOC(mod_ast->get_decl()->get_location()));
  }

  // Set up the original query stream as the result of resolving the
  // library module's URI
  aXQuery.clear();
  aXQuery.seekg(0);

  FakeLibraryModuleURLResolver* aFakeResolver =
    new FakeLibraryModuleURLResolver(aFileName, aXQuery);

  theCompilerCB->theRootSctx->add_url_resolver(aFakeResolver);

  // create a dummy main module and parse it
  std::stringstream lDocStream;
  zstring tmp;
  zorba::xml::escape(lib_namespace, &tmp);
  lDocStream << "import module namespace m = '" << tmp << "'; 1";
  return parse(lDocStream, aFileName);
}
コード例 #26
0
ファイル: sequencetypes.cpp プロジェクト: alyst/zorba
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);
}
コード例 #27
0
ファイル: doc_uri_heuristics.cpp プロジェクト: alyst/zorba
void normalizeInputUri(
    zstring const& aUri,
    static_context* aSctx,
    QueryLoc const& aLoc,
    zstring* aResult)
{
  zstring const lBaseUri = aSctx->get_base_uri();

  try
  {
    // To support the very common (if technically incorrect) use
    // case of users passing local filesystem paths to fn:doc(),
    // we use the following heuristic: IF the base URI has a file:
    // scheme AND the incoming URI has no scheme, we will assume
    // the incoming URI is actually a filesystem path.  QQQ For
    // the moment, we assume any "unknown" schemes are probably
    // Windows drive letters.
    if ((uri::get_scheme(aUri) == uri::none ||
         uri::get_scheme(aUri) == uri::unknown) &&
        uri::get_scheme(lBaseUri) == uri::file)
    {
      try
      {
        // Ok, we assume it's a filesystem path. First normalize it.
        zstring lNormalizedPath = fs::normalize_path( aUri );
        // QQQ For now, normalize_path() doesn't do what we
        // want when base URI represents a file. So, when the
        // normalized path is relative, we pretend it's a relative
        // URI and resolve it as such.
        if (fs::is_absolute(lNormalizedPath))
        {
          URI::encode_file_URI(lNormalizedPath, *aResult);
        }
        else
        {
  #ifdef WIN32
          ascii::replace_all(lNormalizedPath, '\\', '/');
  #endif
          *aResult = aSctx->resolve_relative_uri(lNormalizedPath, true);
        }
      }
      catch ( std::invalid_argument const &e )
      {
        throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
      }
    }
    else
    {
      // We do NOT assume it's a filesystem path; just resolve it.
      *aResult = aSctx->resolve_relative_uri(aUri, true);
    }
  }
  catch (ZorbaException& e)
  {
    if (e.diagnostic() == err::XQST0046)
      // the value of a URILiteral is of nonzero length and is not in the
      // lexical space of xs:anyURI.
      e.set_diagnostic(err::FODC0005);
    else
      e.set_diagnostic(err::FODC0002);

    set_source(e, aLoc);
    throw;
  }
}
コード例 #28
0
ファイル: uris_impl.cpp プロジェクト: alyst/zorba
bool
DecodeURIIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
  store::Item_t lString, lDecodePlus, lEncoding;
  zstring       lDecodedString, lCharset;

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

  consumeNext(lString, theChildren[0].getp(), planState);
  consumeNext(lDecodePlus, theChildren[1].getp(), planState);
  consumeNext(lEncoding, theChildren[2].getp(), planState);

  lString->getStringValue2(lDecodedString);
  lEncoding->getStringValue2(lCharset);

  if (lDecodePlus->getBooleanValue())
  {
    std::replace( lDecodedString.begin(), lDecodedString.end(), '+', ' ' );
  }

  uri::decode(lDecodedString);

  if (transcode::is_necessary(lCharset.c_str()))
  {
    if (!transcode::is_supported(lCharset.c_str()))
    {
      throw XQUERY_EXCEPTION(
        zuri::CHARSET_UNKNOWN,
        ERROR_PARAMS( lCharset ),
        ERROR_LOC( loc )
      );
    }

    try
    {
      transcode::stream<istringstream> lTranscoder(
          lCharset.c_str(),
          lDecodedString.c_str()
        );

      lDecodedString.clear();
      char buf[1024];
      while (lTranscoder.good())
      {
        lTranscoder.read(buf, 1024);
        lDecodedString.append(buf, static_cast<zstring::size_type>(lTranscoder.gcount()));
      }
    }
    catch (ZorbaException& e)
    {
      throw XQUERY_EXCEPTION(
        zerr::ZOSE0006_TRANSCODING_ERROR,
        ERROR_PARAMS( e.what() ),
        ERROR_LOC( loc )
      );
    }
  }

  STACK_PUSH(GENV_ITEMFACTORY->createString(result, lDecodedString), state );

  STACK_END (state);
}
コード例 #29
0
ファイル: uris_impl.cpp プロジェクト: alyst/zorba
bool
SerializeURIIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
  store::Item_t     lItemURI, lItemKey;
  zorba::zstring    lStrValue, lStrKey, lStrRes;
  store::Iterator_t lKeys;
  URI               uri = URI();
  int               lIntPort = 0;
  bool              lHasSchemeField, lHasOpaqueField, lHasNotOpaqueField;

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

  consumeNext(lItemURI, theChildren[0].getp(), planState);

  lHasSchemeField = lHasOpaqueField = lHasNotOpaqueField = false;
  if(lItemURI->isObject()) {
    lKeys = lItemURI->getObjectKeys();
    if(!lKeys.isNull()){
      lKeys->open();
      while(lKeys->next(lItemKey)){
        lStrKey = lItemKey->getStringValue();
        lStrValue = lItemURI->getObjectValue(lItemKey)->getStringValue();
        if(lStrKey == SCHEME_NAME && !lStrValue.empty()){
          uri.set_scheme(lStrValue);
          lHasSchemeField = true;
        } else if(lStrKey == OPAQUE_PART_NAME && !lStrValue.empty()){
          uri.set_opaque_part(lStrValue);
          lHasOpaqueField = true;
        } else if(lStrKey == AUTHORITY_NAME && !lStrValue.empty()){
          uri.set_reg_based_authority(lStrValue);
          lHasNotOpaqueField = true;
        } else if(lStrKey == USER_INFO_NAME && !lStrValue.empty()){
          uri.set_user_info(lStrValue);
          lHasNotOpaqueField = true;
        } else if(lStrKey == HOST_NAME && !lStrValue.empty()){
          uri.set_host(lStrValue);
          lHasNotOpaqueField = true;
        } else if(lStrKey == PORT_NAME){
          sscanf(lStrValue.str().c_str(), "%d", &lIntPort);
          if(lIntPort != 0){
            uri.set_port(lIntPort);
            lHasNotOpaqueField = true;
          }
        } else if(lStrKey == PATH_NAME && !lStrValue.empty()){
          uri.set_path(lStrValue);
          lHasNotOpaqueField = true;
        } else if(lStrKey == QUERY_NAME){
          uri.set_query(lStrValue);
          lHasNotOpaqueField = true;
        } else if(lStrKey == FRAGMENT_NAME){
          uri.set_fragment(lStrValue);
        }
      }
      lKeys->close();
    }
  }

  // check for errors
  if(lHasOpaqueField && lHasNotOpaqueField)
  {
    throw XQUERY_EXCEPTION(
      zuri::OPAQUE_COMB_NOT_VALID,
      ERROR_LOC( loc )
    );
  }
  if(lHasOpaqueField && !lHasSchemeField)
  {
    throw XQUERY_EXCEPTION(
      zuri::OPAQUE_WITHOUT_SCHEME,
      ERROR_LOC( loc )
    );
  }
  if(lHasSchemeField && !uri.get_encoded_path().empty() && (uri.get_encoded_path().substr(0,1) != "/"))
  {
    throw XQUERY_EXCEPTION(
      zuri::INVALID_ABSOLUTE_PATH,
      ERROR_LOC( loc )
    );
  }
  
  lStrRes = zorba::zstring(uri.toString());
  STACK_PUSH(GENV_ITEMFACTORY->createString(result, lStrRes), state );

  STACK_END (state);
}
コード例 #30
0
ファイル: jsonml_array.cpp プロジェクト: alyst/zorba
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;
}