Exemplo n.º 1
0
void testObj::test<3>(void)
{
  try
  {
    openElement("/i/do/not/exist", Mode::READWRITE, isSaneTrue);
    fail("call didn't throw on error");
  }
  catch(const ExceptionFilesystemIO &)
  {
    // this is expected
  }
}
Exemplo n.º 2
0
void testObj::test<2>(void)
{
  try
  {
    openElement("testdata/file", Mode::READ, isSaneFalse);
    fail("call didn't throw on error");
  }
  catch(const ExceptionFilesystemIO &)
  {
    // this is expected
  }
}
    //---------------------------------------------------------------
    void StreamWriter::startDocument()
    {
        appendNCNameString ( CSWC::XML_START_ELEMENT );
        openElement ( CSWC::CSW_ELEMENT_COLLADA );
		if ( getCOLLADAVersion() == COLLADA_1_4_1 )
		{
			appendAttribute ( CSWC::CSW_ATTRIBUTE_XMLNS, CSWC::CSW_NAMESPACE_1_4_1 );
			appendAttribute ( CSWC::CSW_ATTRIBUTE_VERSION, CSWC::CSW_VERSION_1_4_1 );
		}
		else if ( getCOLLADAVersion() == COLLADA_1_5_0 )
		{
			appendAttribute ( CSWC::CSW_ATTRIBUTE_XMLNS, CSWC::CSW_NAMESPACE_1_5_0 );
			appendAttribute ( CSWC::CSW_ATTRIBUTE_VERSION, CSWC::CSW_VERSION_1_5_0 );
			appendAttribute ( CSWC::CSW_ATTRIBUTE_XSI_SCHEMALOCATION, CSWC::CSW_SCHEMALOCATION_1_5_0 );
			appendAttribute ( CSWC::CSW_ATTRIBUTE_XMLNS_XSI, CSWC::CSW_XMLNS_XSI_1_5_0 );
		}
		else
		{
			COLLADABU_ASSERT(false);
		}
    }
 //---------------------------------------------------------------
 void StreamWriter::appendTextElement ( const String& elementName, const String& text )
 {
     openElement ( elementName );
     appendText ( COLLADABU::StringUtils::translateToXML(text) );
     closeElement();
 }
    //---------------------------------------------------------------
    void StreamWriter::appendURIElement ( const String& elementName, const COLLADABU::URI& uri )
    {
        openElement ( elementName );
		appendText ( COLLADABU::StringUtils::translateToXML(uri.getURIString()) );
        closeElement();
    }
void cElementManager::gotTag (const string &tag)
{
  string tagname;
  list<sParam> params;
  sParam param;
  param.flag = false;
  char quote;
  tagParserState pstate = tagBegin;
  string::const_iterator it;
  for (it = tag.begin(); it != tag.end(); ++it)
  {
    char ch = *it;

    //process character
    switch (pstate) {
      case tagBegin: {
        if (ch != ' ')
        {
          pstate = tagName;
          tagname += ch;
        }
        break;
      }
      case tagName: {
        if (ch == ' ')
          pstate = tagBetweenParams;
        else
          tagname += ch;
        break;
      }
      case tagParam: {
        if (ch == '=')
          pstate = tagParamValue;
        else if (ch == ' ')
        {
          //one parameter, value only (it could also be a flag, we'll check that later)
          param.value = param.name;
          param.name = "";
          //add a new parameter :-)
          params.push_back (param);
          param.value = "";
          pstate = tagBetweenParams;
        }
        else
          param.name += ch;
        break;
      }
      case tagParamValue: {
        if (ch == ' ')
        {
          //add a new parameter :-)
          params.push_back (param);
          param.name = "";
          param.value = "";
          pstate = tagBetweenParams;
        }
        else if (param.value.empty() && ((ch == '\'') || (ch == '"')))
        {
          pstate = tagQuotedParam;
          quote = ch;
        }
        else
          param.value += ch;
        break;
      }
      case tagQuotedParam: {
        if (ch == quote)
        {
          //add a new parameter :-)
          params.push_back (param);
          param.name = "";
          param.value = "";
          pstate = tagAfterQuotedParam;
        }
        else
          param.value += ch;
        break;
      }
      case tagAfterQuotedParam: {
        if (ch == ' ')    //ignore everything up to some space...
          pstate = tagBetweenParams;
        break;
      }
      case tagBetweenParams: {
        if (ch != ' ')
        {
          if ((ch == '\'') || (ch == '"'))
          {
            pstate = tagQuotedParam;
            param.name = "";
            quote = ch;
          }
          else
          {
            pstate = tagParam;
            param.name += ch;
          }
        }
        break;
      }
    };
  }

  //last parameter...
  switch (pstate) {
    case tagBegin:
      results->addToList (results->createError ("Received a tag with no body!"));
      break;
    case tagParam: {
      param.value = param.name;
      param.name = "";
      params.push_back (param);
      }
      break;
    case tagParamValue:
      params.push_back (param);
      break;
    case tagQuotedParam:
      results->addToList (results->createError ("Received tag " + tagname +
          " with unfinished quoted parameter!"));
      break;
  };

  //nothing more to do if the tag has no contents...
  if (pstate == tagBegin) return;
  
  //convert tag name to lowercase
  tagname = lcase (tagname);
  
  //handle closing tag...
  if (tagname[0] == '/')
  {
    if (!params.empty())
      results->addToList (results->createError ("Received closing tag " + tagname +
          " with parametrs!"));
    //remove that '/'
    tagname.erase (tagname.begin());
    //and call closing tag processing
    handleClosingTag (tagname);
    return;
  }
  
  //convert all parameter names to lower-case
  list<sParam>::iterator parit;
  for (parit = params.begin(); parit != params.end(); ++parit)
    (*parit).name = lcase ((*parit).name);
  
  //now we check the type of the tag and act accordingly
  if (!elementDefined (tagname))
  {
    params.clear();
    results->addToList (results->createError ("Received undefined tag " + tagname + "!"));
    return;
  }

  mxpMode m = state->getMXPMode ();
  //mode can be open or secure; locked mode is not possible here (or we're in a bug)
  if (m == openMode)
    //open mode - only open tags allowed
    if (!openElement (tagname))
    {
    params.clear();
      results->addToList (results->createError ("Received secure tag " + tagname +
          " in open mode!"));
      return;
    }

  if (internalElement (tagname))
  {
    //if the name is an alias for another tag, change the name
    if (aliases.count (tagname))
      tagname = aliases[tagname];
    //the <support> tag has to be handled separately :(
    if (tagname == "support")
    {
      processSupport (params);
      return;
    }
    //identify all flags in the tag
    identifyFlags (ielements[tagname]->attdefault, params);
    //correctly identify all parameters (assign names where necessary)
    handleParams (tagname, params, ielements[tagname]->attlist, ielements[tagname]->attdefault);
    //separate out all the flags (flags are only valid for internal tags)
    list<string> flags;
    parit = params.begin();
    while (parit != params.end())
    {
      if ((*parit).flag)
      {
        flags.push_back ((*parit).name);
        parit = params.erase (parit);
      }
      else
        ++parit;
    }
    //okay, parsing done - send the tag for further processing
    processInternalTag (tagname, params, flags);
  }
  else
  {
    handleParams (tagname, params, elements[tagname]->attlist, elements[tagname]->attdefault);
    processCustomTag (tagname, params);
  }
  
  params.clear ();
}
void cElementManager::addElement (const string &name, list<sElementPart *> contents,
    list<string> attlist, map<string, string> attdefault, bool open, bool empty,
    int tag, string flag)
{
  //sanity checks
  if (elementDefined (name))
  {
    results->addToList (results->createError ("Multiple definition of element " + name + "!"));
    return;
  }

  sElement *e = new sElement;
  e->open = open;
  e->empty = empty;
  if ((tag >= 20) && (tag <= 99))
  {
    e->tag = tag;
    if (lineTags.count (tag))
      results->addToList (results->createError ("Element " + name +
          " uses an already assigned line tag!"));
    lineTags[tag] = name;
  }
  else
    e->tag = 0;
  e->flag = flag;

  //assign element contents, generating the list of closing tags
  e->element.clear();
  list<sElementPart *>::iterator it;
  for (it = contents.begin(); it != contents.end(); ++it)
  {
    sElementPart *ep = *it;
    if (ep->istag)
    {
      string tag = lcase (firstword (ep->text));
      if (elementDefined (tag))
      {
        if (open && !(openElement (tag)))
        {
          delete ep;
          results->addToList (results->createError ("Definition of open " + name +
              " tag contains secure tag " + tag + "!"));
        }
        else if (empty && !(emptyElement (tag)))
        {
          delete ep;
          results->addToList (results->createError ("Definition of empty " + name +
              " tag contains non-empty tag " + tag + "!"));
        }
        else
        {
          e->element.push_back (ep);
          if (!emptyElement(tag)) e->closingseq.push_front (tag);
        }
      }
      else
      {
        //element doesn't exist yet - we must believe that it's correct
        e->element.push_back (ep);
        if (!empty) e->closingseq.push_front (tag);
        results->addToList (results->createWarning ("Definition of element " + name +
            " contains undefined element " + tag + "!"));
      }
    }
    else
      e->element.push_back (ep);
  }

  //assign the element definition
  elements[name] = e;

  //set attribute list
  setAttList (name, attlist, attdefault);
}
Exemplo n.º 8
0
void testObj::test<1>(void)
{
  ensure("file not opened", openElement("testdata/file", Mode::READ, isSaneTrue).get()!=NULL );
}