예제 #1
0
bool 
ASTCnBase::read(XMLInputStream& stream, const std::string& )
{
  bool read = false;

  const XMLToken element = stream.next ();
  
  ExpectedAttributes expectedAttributes;
  addExpectedAttributes(expectedAttributes, stream);
  read = readAttributes(element.getAttributes(), expectedAttributes,
                        stream, element);

  string prefix;
  if (isSetUnits() == true)
  {
    prefix = element.getAttrPrefix(
      element.getAttrIndex("units", stream.getSBMLNamespaces()->getURI()));
	  
    setUnitsPrefix(prefix);
  }

  //return ASTBase::read(stream, reqd_prefix);

  return read;
}
bool
ASTCiNumberNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  const XMLToken element = stream.next ();
  const string&  nameE = element.getName();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  if (nameE != "ci")
  {
#if 0
    cout << "HELP\n";
#endif
    return read;
  }

  ExpectedAttributes expectedAttributes;
  addExpectedAttributes(expectedAttributes, stream);
  read = readAttributes(element.getAttributes(), expectedAttributes,
                        stream, element);

  const string name = trim( stream.next().getCharacters() );
    
  setName((name));
  ASTBase::setType(AST_NAME);

  if (read == true)
    stream.skipPastEnd(element);

  return read;
}
예제 #3
0
/**
 * Sets the type of an ASTNode based on the given MathML <ci> element.
 * Errors will be logged in the stream's SBMLErrorLog object.
 */
static void
setTypeCI (ASTNode& node, const XMLToken& element, XMLInputStream& stream)
{
  if (element.getName() == "csymbol")
  {
    string url;
    element.getAttributes().readInto("definitionURL", url);

    if ( url == URL_DELAY ) node.setType(AST_FUNCTION_DELAY);
    else if ( url == URL_TIME  ) node.setType(AST_NAME_TIME);
    else if ( url == URL_AVOGADRO  ) node.setType(AST_NAME_AVOGADRO);
    else 
    {
      static_cast <SBMLErrorLog*>
	        (stream.getErrorLog())->logError(BadCsymbolDefinitionURLValue,
          stream.getSBMLNamespaces()->getLevel(), 
          stream.getSBMLNamespaces()->getVersion());
    }
  }
  else if (element.getName() == "ci")
  {
    node.setDefinitionURL(element.getAttributes());
  }

  const string name = trim( stream.next().getCharacters() );
  node.setName( name.c_str() );
}
예제 #4
0
bool 
ArraysASTPlugin::readMatrixRow(XMLInputStream& stream, const std::string& reqd_prefix,
                        const XMLToken& currentElement)
{
  bool read = false;
  
  stream.skipText();
  const XMLToken nextElement = stream.peek();
  const string&  nextName = nextElement.getName();
  
  unsigned int numChildren = determineNumChildren(stream, "matrixrow");
    
  mVector = new ASTArraysVectorFunctionNode(AST_LINEAR_ALGEBRA_MATRIXROW_CONSTRUCTOR);
  
  mVector->setExpectedNumChildren(numChildren);
  
  // read attributes on this element here since we have already consumed
  // the element
  ExpectedAttributes expectedAttributes;
  mVector->addExpectedAttributes(expectedAttributes, stream);
  read = mVector->ASTBase::readAttributes(currentElement.getAttributes(), 
                                expectedAttributes, stream, currentElement);
  if (read == false)
  {
    mVector = NULL;
  }
  else
  {  
    read = mVector->read(stream, reqd_prefix);
  }

  return read;
}
예제 #5
0
void
ASTBase::logError (XMLInputStream& stream, const XMLToken& element, SBMLErrorCode_t code,
          const std::string& msg)
{
  SBMLNamespaces* ns = stream.getSBMLNamespaces();
  if (ns != NULL)
  {
    static_cast <SBMLErrorLog*>
      (stream.getErrorLog())->logError(
      code,
      ns->getLevel(), 
      ns->getVersion(),
      msg, 
      element.getLine(), 
      element.getColumn());
  }
  else
  {
    static_cast <SBMLErrorLog*>
      (stream.getErrorLog())->logError(
      code, 
      SBML_DEFAULT_LEVEL, 
      SBML_DEFAULT_VERSION, 
      msg, 
      element.getLine(), 
      element.getColumn());
  }
}
예제 #6
0
/**
 * Sets the type of an ASTNode based on the given MathML &lt;cn> element.
 * Errors will be logged in the stream's SBMLErrorLog object.
 */
static void
setTypeCN (ASTNode& node, const XMLToken& element, XMLInputStream& stream)
{
  string type = "real";
  element.getAttributes().readInto("type", type);

  // here is the only place we might encounter the sbml:units attribute
  string units = "";
  element.getAttributes().readInto("units", units);

  if (type == "real")
  {
    double value = 0;
    istringstream isreal;
    isreal.str( stream.next().getCharacters() );
    isreal >> value;

    node.setValue(value);

    if (isreal.fail() 
      || node.isInfinity()
      || node.isNegInfinity()
      )
    {
      static_cast <SBMLErrorLog*>
        (stream.getErrorLog())->logError(FailedMathMLReadOfDouble,
          stream.getSBMLNamespaces()->getLevel(), 
          stream.getSBMLNamespaces()->getVersion());
    }

  }
예제 #7
0
bool
ASTUnaryFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  ASTBase * child = NULL;
  const XMLToken element = stream.peek ();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  const char*      name = element.getName().c_str();

  setType(getTypeFromName(name));
  ASTBase::read(stream, reqd_prefix);

  unsigned int numChildrenAdded = 0;

  if (getExpectedNumChildren() > 0)
  {
    while (stream.isGood() && numChildrenAdded < getExpectedNumChildren())
    {
      stream.skipText();

      name = stream.peek().getName().c_str();

      if (representsNumber(ASTBase::getTypeFromName(name)) == true)
      {
        child = new ASTNumber();
      }
      else 
      {
        child = new ASTFunction();
      }

      read = child->read(stream, reqd_prefix);

      stream.skipText();

      if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS)
      {
        numChildrenAdded++;
      }
      else
      {
        delete child;
        child = NULL;
        read = false;
        break;
      }
    }
  }
  else
  {
    stream.skipPastEnd(element);
    read = true;
  }

  return read;
}
예제 #8
0
/*
 * @return @c true if this XMLToken is an XML end element for the given XML
 * start element, false otherwise.
 */
bool
XMLToken::isEndFor (const XMLToken& element) const
{
  return
    isEnd()                        &&
    !isStart()                     &&
    element.isStart()              &&
    element.getName() == getName() &&
    element.getURI () == getURI ();
}
예제 #9
0
bool 
ASTBase::read(XMLInputStream& stream, const std::string& )
{
  ExpectedAttributes expectedAttributes;
  addExpectedAttributes(expectedAttributes, stream);
  
  const XMLToken element = stream.next ();
  
  return readAttributes(element.getAttributes(), expectedAttributes,
                        stream, element);
}
예제 #10
0
bool
XMLTokenizer::containsChild(bool & valid, 
                            const std::string& qualifier, 
                            const std::string& container)
{
  valid = false;
  //unsigned int numQualifiers = 0;
  

  size_t size = mTokens.size();
  if (size < 2)
  {
    return false;
  }

  unsigned int index = 0;
  //unsigned int depth = 0;
  std::string name;
  
  XMLToken next = mTokens.at(index);
  name = next.getName();

  while (index < size-2)
  {
    // skip any text elements
    while(next.isText() == true && index < size-1)
    {
      index++;
      next = mTokens.at(index);
    }

    if (next.getName() == qualifier)
    {
      valid = true;
      return true;
    }

    index++;
    if (index < size)
    {
      next = mTokens.at(index);
    }
  }  

  // we might have hit the end of the loop and the end of the correct tag
  if (valid == false && index >= size-2)
  {
    valid = true;
  }

  return false;
}
예제 #11
0
bool
ArraysASTPlugin::read(XMLInputStream& stream, const std::string& reqd_prefix, 
                                             const XMLToken& currentElement)
{
  bool read = false;
  
  stream.skipText();
  
  const string&  currentName = currentElement.getName();

  //ASTBase::checkPrefix(stream, reqd_prefix, currentElement);
  
  // create appropriate sub class
  if (currentName == "vector")
  {
    read = readVector(stream, reqd_prefix, currentElement);
  }
#if (0)
  else if (currentName == "matrix")
  {
    read = readMatrix(stream, reqd_prefix, currentElement);
  }
  else if (currentName == "matrixrow")
  {
    read = readMatrixRow(stream, reqd_prefix, currentElement);
  }
#endif
 
  return read;
}
예제 #12
0
void
ASTBase::checkPrefix(XMLInputStream &stream, const std::string& reqd_prefix, 
                     const XMLToken& element)
{
  if (!reqd_prefix.empty())
  {
    std::string prefix = element.getPrefix();
    if (prefix != reqd_prefix)
    {
      const string message = "Element <" + element.getName() 
        + "> should have prefix \"" + reqd_prefix + "\".";

      logError(stream, element, InvalidMathElement, message);
      
    }
  }
}
예제 #13
0
/*
 * Consume zero or more XMLTokens up to and including the corresponding
 * end XML element or EOF.
 */
void
XMLInputStream::skipPastEnd (const XMLToken& element)
{
  if ( element.isEnd() ) return;

  while ( isGood() && !peek().isEndFor(element) ) next();
  next();
}
예제 #14
0
bool
ASTCnRealNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  const XMLToken element = stream.peek ();
  const string&  name = element.getName();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  if (name != "cn")
  {
#if 0
    cout << "HELP\n";
#endif
    return read;
  }

  ASTCnBase::read(stream, reqd_prefix);

  std::string type = "real";
  element.getAttributes().readInto("type", type);

  if (type == "real")
  {
    double value = 0;
    istringstream isreal;
    isreal.str( stream.next().getCharacters() );
    isreal >> value;

    setReal(value);
    ASTBase::setType(AST_REAL);

    if (isreal.fail() 
      || (util_isInf(getValue()) > 0)
      || (util_isInf(getValue()) < 0)
      )
    {
      logError(stream, element, FailedMathMLReadOfDouble);      
    }

    read = true;
  }
예제 #15
0
LIBSBML_CPP_NAMESPACE_BEGIN
#ifdef __cplusplus

/**
 * logs the given erroron the error log of the stream.
 * 
 * @param stream the stream to log the error on
 * @param element the element to log the error for
 * @param code the error code to log
 * @param msg optional message
 */
static void
logError (XMLInputStream* stream, const XMLToken& element, SBMLErrorCode_t code,
          const std::string& msg = "")
{
  if (&element == NULL || stream == NULL) return;

  SBMLNamespaces* ns = stream->getSBMLNamespaces();
  if (ns != NULL)
  {
    static_cast <SBMLErrorLog*>
      (stream->getErrorLog())->logError(
      code,
      ns->getLevel(), 
      ns->getVersion(),
      msg, 
      element.getLine(), 
      element.getColumn());
  }
  else
  {
    static_cast <SBMLErrorLog*>
      (stream->getErrorLog())->logError(
      code, 
      SBML_DEFAULT_LEVEL, 
      SBML_DEFAULT_VERSION, 
      msg, 
      element.getLine(), 
      element.getColumn());
  }
}
예제 #16
0
/*
 * Copy constructor; creates a copy of this XMLToken.
 */
XMLToken::XMLToken(const XMLToken& orig)
 : mTriple()
 , mAttributes()
 , mNamespaces()
 , mChars (orig.mChars)
 , mIsStart (orig.mIsStart)
 , mIsEnd (orig.mIsEnd)
 , mIsText (orig.mIsText)
 , mLine (orig.mLine)
 , mColumn (orig.mColumn)
{
  if (!orig.mTriple.isEmpty())
    mTriple = XMLTriple(orig.getName(), orig.getURI(), orig.getPrefix());
  
  if (!orig.mAttributes.isEmpty())
    mAttributes = XMLAttributes(orig.getAttributes());
  
  if (!orig.mNamespaces.isEmpty())
    mNamespaces = XMLNamespaces(orig.getNamespaces());

}
예제 #17
0
bool
ASTCnIntegerNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  const XMLToken element = stream.peek ();
  const string&  name = element.getName();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  if (name != "cn")
  {
    cout << "HELP\n";
    return read;
  }

  ASTCnBase::read(stream, reqd_prefix);

  std::string type;
  element.getAttributes().readInto("type", type);

  if (type == "integer")
  {
    int value = 0;
    istringstream isint;
    isint.str( stream.next().getCharacters() );
    isint >> value;

    if (isint.fail())
    {
      logError(stream, element, FailedMathMLReadOfInteger);      
    }
    else if ( sizeof(int) > 4 && ( (value > SBML_INT_MAX) || (value < SBML_INT_MIN) ) )
    {
      logError(stream, element, FailedMathMLReadOfInteger);      
    }

    setInteger(value);
    ASTBase::setType(AST_INTEGER);
    read = true;
  }
bool
ASTCnExponentialNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  const XMLToken element = stream.peek ();
  const string&  name = element.getName();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  if (name != "cn")
  {
#if 0
    cout << "HELP\n";
#endif
    return read;
  }

  ASTCnBase::read(stream, reqd_prefix);

  std::string type;
  element.getAttributes().readInto("type", type);

  if (type == "e-notation")
  {
    double mantissa = 0;
    long   exponent = 0;
    istringstream ismantissa;
    istringstream isexponent;
    ismantissa.str( stream.next().getCharacters() );
    ismantissa >> mantissa;

    if (stream.peek().getName() == "sep")
    {
      stream.next();
      isexponent.str( stream.next().getCharacters() );
      isexponent >> exponent;
    }
예제 #19
0
XMLTokenHandler::Result PrefsLoader::HandleToken(XMLToken &token)
{
	switch (token.GetType())
	{
	case XMLToken::TYPE_STag:
	case XMLToken::TYPE_ETag:
	case XMLToken::TYPE_EmptyElemTag:
		if (token.GetType() != XMLToken::TYPE_ETag)
		{
			HandleStartElement(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength(), token.GetAttributes(), token.GetAttributesCount());
		}
		if (token.GetType() != XMLToken::TYPE_STag)
			HandleEndElement(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength());
	}

    return RESULT_OK;
}
예제 #20
0
/*
 * Receive notification of character data inside an element.
 */
void
XMLTokenizer::characters (const XMLToken& data)
{
  if (mInStart)
  {
    mInStart = false;
    mTokens.push_back( mCurrent );
  }

  if (mInChars)
  {
    mCurrent.append( data.getCharacters() );
  }
  else
  {
    mInChars = true;
    mCurrent = data;
  }
}
예제 #21
0
/* virtual */ XMLTokenHandler::Result
WebFeedStorage::HandleToken(XMLToken &token)
{
	OP_STATUS status = OpStatus::OK;

	switch (token.GetType())
	{
		case XMLToken::TYPE_CDATA:
		case XMLToken::TYPE_Text:
			status = HandleTextToken(token);
			break;

		case XMLToken::TYPE_STag:
			status = HandleStartTagToken(token);
			break;

		case XMLToken::TYPE_ETag:
			status = HandleEndTagToken(token);
			break;

		case XMLToken::TYPE_EmptyElemTag:
			status = HandleStartTagToken(token);
			if (OpStatus::IsSuccess(status))
				status = HandleEndTagToken(token);
			break;

		default:
			break;
	}

	if (OpStatus::IsMemoryError(status))
		return XMLTokenHandler::RESULT_OOM;
	else if (OpStatus::IsError(status))
		return XMLTokenHandler::RESULT_ERROR;

	return XMLTokenHandler::RESULT_OK;
}
예제 #22
0
/* virtual */ XMLTokenHandler::Result
XMLToLanguageParserTokenHandler::HandleToken(XMLToken &token)
{
	OP_STATUS status = OpStatus::OK;
	OpStatus::Ignore(status);

	if (finished)
		return RESULT_OK;

	if (ignore_element_depth != 0)
	{
		if (token.GetType() == XMLToken::TYPE_STag)
			++ignore_element_depth;
		else if (token.GetType() == XMLToken::TYPE_ETag)
			--ignore_element_depth;
	}

	XMLParserImpl *xmlparser = (XMLParserImpl *) token.GetParser();
	BOOL block = FALSE;

	if (ignore_element_depth == 0)
	{
#ifdef XML_ERRORS
		XMLRange location;
#endif // XML_ERRORS

		switch (token.GetType())
		{
		case XMLToken::TYPE_PI:
#ifdef XML_ERRORS
			token.GetTokenRange(location);
			parser->SetLocation(location);
#endif // XML_ERRORS

			status = parser->AddProcessingInstruction(token.GetName().GetLocalPart(), token.GetName().GetLocalPartLength(), token.GetData(), token.GetDataLength());
			break;

		case XMLToken::TYPE_CDATA:
		case XMLToken::TYPE_Text:
		case XMLToken::TYPE_Comment:
		{
			XMLLanguageParser::CharacterDataType cdatatype = XMLLanguageParser::CHARACTERDATA_TEXT;
			if (token.GetType() != XMLToken::TYPE_Comment)
				if (token.GetType() == XMLToken::TYPE_CDATA)
					cdatatype = XMLLanguageParser::CHARACTERDATA_CDATA_SECTION;
				else if (token.GetLiteralIsWhitespace())
				{
					if (!entity_signalled)
						/* Don't generate calls to the language parser before the
						   first call to StartEntity. */
						break;
					cdatatype = XMLLanguageParser::CHARACTERDATA_TEXT_WHITESPACE;
				}

			const uni_char *simplevalue;
			uni_char *allocatedvalue;

			if ((simplevalue = token.GetLiteralSimpleValue()) == 0)
			{
				simplevalue = allocatedvalue = token.GetLiteralAllocatedValue();
				if (!allocatedvalue)
					status = OpStatus::ERR_NO_MEMORY;
			}
			else
				allocatedvalue = 0;

			if (simplevalue)
			{
#ifdef XML_ERRORS
				token.GetTokenRange(location);
				parser->SetLocation(location);
#endif // XML_ERRORS

				if (token.GetType() == XMLToken::TYPE_Comment)
					status = parser->AddComment(simplevalue, token.GetLiteralLength());
				else
					status = parser->AddCharacterData(cdatatype, simplevalue, token.GetLiteralLength());

				OP_DELETEA(allocatedvalue);
			}
			break;
		}
		case XMLToken::TYPE_STag:
		case XMLToken::TYPE_ETag:
		case XMLToken::TYPE_EmptyElemTag:
			if (!(xmlparser->GetCurrentEntityUrl() == current_entity_url) && xmlparser->GetCurrentEntityDepth() <= current_entity_depth)
				status = parser->EndEntity();

			if (OpStatus::IsSuccess(status) && (!(xmlparser->GetCurrentEntityUrl() == current_entity_url) || current_entity_url.IsEmpty() && !entity_signalled) && xmlparser->GetCurrentEntityDepth() > current_entity_depth)
			{
				status = parser->StartEntity(xmlparser->GetCurrentEntityUrl(), xmlparser->GetDocumentInformation(), xmlparser->GetCurrentEntityDepth() > 1);
				entity_signalled = TRUE;
			}

			current_entity_url = xmlparser->GetCurrentEntityUrl();
			current_entity_depth = xmlparser->GetCurrentEntityDepth();

			if (token.GetType() != XMLToken::TYPE_ETag)
			{
				if (OpStatus::IsSuccess(status))
				{
					BOOL fragment_start = FALSE;

					if (!fragment_found)
					{
						if (!fragment_id)
							fragment_start = TRUE;
						else
						{
							XMLToken::Attribute *attributes = token.GetAttributes();
							unsigned attributes_count = token.GetAttributesCount();
							unsigned fragment_id_length = uni_strlen(fragment_id);

							for (unsigned index = 0; index < attributes_count; ++index)
								if (attributes[index].GetId())
									if (attributes[index].GetValueLength() == fragment_id_length && uni_strncmp(attributes[index].GetValue(), fragment_id, fragment_id_length) == 0)
									{
										fragment_start = TRUE;
										break;
									}
						}

						if (fragment_start)
							fragment_found = TRUE;
					}

#ifdef XML_ERRORS
					token.GetTokenRange(location);
					parser->SetLocation(location);
#endif // XML_ERRORS

					BOOL ignore_element = FALSE;
					status = parser->StartElement(token.GetName(), fragment_start, ignore_element);

					if (ignore_element)
					{
						if (token.GetType() == XMLToken::TYPE_STag)
							ignore_element_depth = 1;
					}
					else
					{
						XMLToken::Attribute *attributes = token.GetAttributes();
						unsigned attributes_count = token.GetAttributesCount();

						for (unsigned index = 0; OpStatus::IsSuccess(status) && index < attributes_count; ++index)
						{
#ifdef XML_ERRORS
							token.GetAttributeRange(location, index);
							parser->SetLocation(location);
#endif // XML_ERRORS

							XMLToken::Attribute &attribute = attributes[index];
							status = parser->AddAttribute(attribute.GetName(), attribute.GetValue(), attribute.GetValueLength(), attribute.GetSpecified(), attribute.GetId());
						}

						if (OpStatus::IsSuccess(status))
							status = parser->StartContent();
					}
				}
			}

			if (OpStatus::IsSuccess(status) && token.GetType() != XMLToken::TYPE_STag)
			{
#ifdef XML_ERRORS
				token.GetTokenRange(location);
				parser->SetLocation(location);
#endif // XML_ERRORS

				status = parser->EndElement(block, finished);

				if (OpStatus::IsSuccess(status) && block)
					parser->SetSourceCallback(&sourcecallbackimpl);
			}
			break;

		case XMLToken::TYPE_Finished:
			status = parser->EndEntity();
		}
	}

	if (OpStatus::IsSuccess(status))
		if (block)
			return RESULT_BLOCK;
		else
			return RESULT_OK;
	else if (OpStatus::IsMemoryError(status))
		return RESULT_OOM;
	else
		return RESULT_ERROR;
}
예제 #23
0
OP_STATUS
WebFeedStorage::HandleStartTagToken(const XMLToken& token)
{
	// Fetch information about the element.
	const XMLCompleteNameN &elemname = token.GetName();

	const uni_char *elm_name = elemname.GetLocalPart();
	UINT elm_name_len = elemname.GetLocalPartLength();

	if (STRN_MATCH(elm_name, "entry", elm_name_len))
	{
		OP_ASSERT(m_current_feed);
		OP_ASSERT(!m_current_entry);

		m_current_entry = OP_NEW(WebFeedEntry, (m_current_feed));

		if (!m_current_entry)
			return OpStatus::ERR_NO_MEMORY;

		if (OpStatus::IsError(m_current_entry->Init()))
		{
			m_current_entry->DecRef();
			return OpStatus::ERR_NO_MEMORY;
		}

		const XMLToken::Attribute *attrs = token.GetAttributes();
		for (UINT i = 0; i < token.GetAttributesCount(); i++)
		{
			const uni_char *attr_name = attrs[i].GetName().GetLocalPart();
			UINT attr_name_len = attrs[i].GetName().GetLocalPartLength();
			const uni_char *attr_value = attrs[i].GetValue();
			UINT attr_value_len = attrs[i].GetValueLength();

			if (STRN_MATCH(attr_name, "id", attr_name_len))
			{
				OpString attr_val_str;
				RETURN_IF_ERROR(attr_val_str.Set(attr_value, attr_value_len));

				m_current_entry->SetId((OpFeedEntry::EntryId)uni_atoi(attr_val_str.CStr()));
			}
			else if (STRN_MATCH(attr_name, "keep", attr_name_len))
			{
				if (STRN_MATCH(attr_value, "yes", attr_value_len))
					m_current_entry->SetKeep(TRUE);
			}
			else if (STRN_MATCH(attr_name, "read", attr_name_len))
			{
				if (STRN_MATCH(attr_value, "yes", attr_value_len))
					m_current_entry->SetReadStatus(OpFeedEntry::STATUS_READ);
			}
			else if (STRN_MATCH(attr_name, "guid", attr_name_len))
			{
				OpString attr_val_str;
				RETURN_IF_ERROR(attr_val_str.Set(attr_value, attr_value_len));

				m_current_entry->SetGuid(attr_val_str.CStr());
			}
		}
	}
	else if (STRN_MATCH(elm_name, "feed", elm_name_len))
	{
		OP_ASSERT(!m_current_feed);

		if (m_is_feed_file)
		{
			OP_STATUS status;
			if (m_current_feed)
				m_current_feed->DecRef();

			m_current_feed = OP_NEW(WebFeed, ());
			if (!m_current_feed)
				return OpStatus::ERR_NO_MEMORY;

			OP_ASSERT(m_current_stub);
			if (m_current_stub)
				status = m_current_feed->Init(m_current_stub);
			else
				return OpStatus::ERR;

			if (OpStatus::IsError(status))
			{
				m_current_feed->DecRef();
				m_current_feed = NULL;
				return OpStatus::ERR_NO_MEMORY;
			}
			else
				m_current_feed->IncRef();
		}
		else
		{
bool
ASTNaryFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  ASTBase * child = NULL;
  const XMLToken element = stream.peek ();

  ASTBase::checkPrefix(stream, reqd_prefix, element);

  const char*      name = element.getName().c_str();

  int type = getTypeFromName(name);
  setType(type);
  ASTBase::read(stream, reqd_prefix);

  unsigned int numChildrenAdded = 0;

  if (getExpectedNumChildren() > 0)
  {
    while (stream.isGood() && numChildrenAdded < getExpectedNumChildren())
    {
      stream.skipText();

      name = stream.peek().getName().c_str();

      if (representsNumber(ASTBase::getTypeFromName(name)) == true)
      {
        child = new ASTNumber();
      }
      else 
      {
        child = new ASTFunction();
      }

      read = child->read(stream, reqd_prefix);

      stream.skipText();

      if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS)
      {
        numChildrenAdded++;
      }
      else
      {
        delete child;
        child = NULL;
        read = false;
        break;
      }
    }
  }
  else
  {
    stream.skipPastEnd(element);
    read = true;
  }

  if (read == true && type == AST_FUNCTION_ROOT 
    && getExpectedNumChildren() == 1 
    && ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_DEGREE)
  {
    /* HACK TO REPLICATE OLD BEHAVIOUR */
    /* we need to add the qualifier child for the degree 2 */
    ASTFunction * degree = new ASTFunction(AST_QUALIFIER_DEGREE);
    ASTNumber * int2 = new ASTNumber(AST_INTEGER);
    int2->setInteger(2);
    degree->addChild(int2->deepCopy());
    this->prependChild(degree->deepCopy());
    delete int2;
    delete degree;

  }

  //if (read == false)
  //{
  //  stream.skipPastEnd(element);
  //}

  return read;
}
예제 #25
0
unsigned int
XMLTokenizer::determineNumberChildren(bool & valid, const std::string element)
{
  valid = false;
  unsigned int numChildren = 0;
  std::string closingTag = element;
  bool forcedElement = true;
  if (closingTag.empty() == true) 
  {
    closingTag = "apply";
    forcedElement = false;
  }

  // if there is only one token there cannot be any children 
  size_t size = mTokens.size();
  if (size < 2)
  {
    return numChildren;
  }

  // we assume that the first unread token is a 
  // function and that at some point in the
  // list of tokens we will hit the end of the 
  // element for that function
  // need to count the number of starts

  unsigned int index = 0;
  XMLToken firstUnread = mTokens.at(index);
  while (firstUnread.isText() && index < size - 1)
  {
    // skip any text
    index++;
    firstUnread = mTokens.at(index);
  }


  // if we have an apply the firstToken should be a function
  // that is both a start and an end
  // unless we are reading a user function
  // or a csymbol
  // if the tag is not a start and an end this is an error
  // we want to exit
  // but be happy that the read is ok
  // and the error gets logged elsewhere
  if (closingTag == "apply")
  {
    std::string firstName = firstUnread.getName();

    if (firstName != "ci" && firstName != "csymbol")
    {
      if (firstUnread.isStart() != true 
        || (firstUnread.isStart() == true &&  firstUnread.isEnd() != true))
      {
        valid = true;
        return numChildren;
      }
    }
  }

  index = 1;
  if (forcedElement == true)
  {
    index = 0;
  }

  unsigned int depth = 0;
  std::string name;
  bool cleanBreak = false;
  XMLToken next = mTokens.at(index);
  while (index < size-2)
  {
    // skip any text elements
    while(next.isText() == true && index < size-1)
    {
      index++;
      next = mTokens.at(index);
    }
    if (next.isEnd() == true && next.getName() == closingTag)
    {
      valid = true;
      break;
    }
    // iterate to first start element
    while (next.isStart() == false && index < size-1)
    {
      index++;
      next = mTokens.at(index);
    }

    // check we have not reached the end
    // this would be a bad place if we have so set num children to zero
    if (index == size)
    {
      numChildren = 0;
      break;
    }

    // record the name of the start element
    name = next.getName();
    numChildren++;

 //   index++;
    // check we have not reached the end
    if (index + 1 == size)
    {
      numChildren = 0;
      break;
    }
    else if (next.isEnd() == false)
    {
      index++;
      if (index < size)
      {
        next = mTokens.at(index);
      }
      else
      {
        break;
      }
    }

    // iterate to the end of </name>
    // checking that we have not got a nested element <name></name>
    cleanBreak = false;
    while (index < size-1)
    {
      if (next.isStart() == true && next.isEnd() == false && next.getName() == name)
      {
        depth++;
      }

      if (next.isEnd() == true && next.getName() == name)
      {
        if (depth == 0)
        {
          cleanBreak = true;
          break;
        }
        else
        {
          depth--;
        }
      }

      index++;
      next = mTokens.at(index);
    }

    index++;
    if (index < size)
    {
      next = mTokens.at(index);
    }
  } 

  // we might have hit the end of the loop and the end of the correct tag
  // but the loop hits before it can record that it was valid
  if (valid == false && cleanBreak == true)
  {
  if (index >= size-2 && next.isEnd() == true && next.getName() == closingTag)
  {
      valid = true;
  }
  }

  return numChildren;
}
예제 #26
0
unsigned int
XMLTokenizer::determineNumSpecificChildren(bool & valid, 
                                           const std::string& qualifier, 
                                        const std::string& container)
{
  valid = false;
  unsigned int numQualifiers = 0;

  size_t size = mTokens.size();
  if (size < 2)
  {
    return numQualifiers;
  }

  unsigned int depth = 0;
  unsigned int index = 0;
  std::string name;
  std::string prevName = "";
  std::string rogueTag = "";
  
  XMLToken next = mTokens.at(index);
  name = next.getName();
  if (next.isStart() == true && next.isEnd() == true && 
    name == qualifier && index < size)
  {
    numQualifiers++;
    index++;
    next = mTokens.at(index);
  }
  bool cleanBreak = false;

  while (index < size-2)
  {
    // skip any text elements
    while(next.isText() == true && index < size-1)
    {
      index++;
      next = mTokens.at(index);
    }

    if (next.isEnd() == true)
    {
      if (next.getName() == container)
      {
        valid = true;
        break;
      }
      //else if (!rogueTag.empty() && next.getName() == rogueTag)
      //{
      //  index++;
      //  next = mTokens.at(index);
      //  break;
      //}
    }
    // iterate to first start element
    while (next.isStart() == false && index < size-1)
    {
      index++;
      next = mTokens.at(index);
    }

    if (next.isStart() == true && next.isEnd() == true)
    {
      if (qualifier.empty() == true)
      {
        // if we are not looking for a specifc element then
        // we may have a child that is a start and end
        // such as <true/>
        numQualifiers++;
      }
      index++;
      if (index < size)
      {
        next = mTokens.at(index);
        continue;
      }
    }
    // check we have not reached the end
    // this would be a bad place if we have so set num children to zero
    if (index == size)
    {
      numQualifiers = 0;
      break;
    }

    // record the name of the start element
    name = next.getName();

    // need to deal with the weird situation where someone has used a tag
    // after the piece but before the next correct element
    //if (container == "piecewise")
    //{
    //  if (prevName == "piece")
    //  {
    //    if (name != "piece" && name != "otherwise")
    //    {
    //      rogueTag = name;
    //      index++;
    //      next = mTokens.at(index);
    //      continue;
    //    }
    //  }
    //}
    if (qualifier.empty() == true || name == qualifier)
    {
      numQualifiers++;
    }

//    index++;
    // check we have not reached the end
    if (index+1 == size)
    {
      numQualifiers = 0;
      break;
    }
    else
    {
      index++;
      next = mTokens.at(index);
    }

    // iterate to the end of </name>
    // checking that we have not got a nested element <name></name>
    cleanBreak = false;
    while (index < size-1)
    {
      if (next.isStart() == true && next.getName() == name)
      {
        depth++;
      }

      if (next.isEnd() == true && next.getName() == name)
      {
        if (depth == 0)
        {
          cleanBreak = true;
          break;
        }
        else
        {
          depth--;
        }
      }

      index++;
      if (index < size)
      {
        next = mTokens.at(index);
      }
    }

    prevName = name;
    index++;
    if (index < size)
    {
      next = mTokens.at(index);
    }
  }  

  // we might have hit the end of the loop and the end of the correct tag
  if (valid == false && cleanBreak == true)
  {
    if (index >= size-2 && next.isEnd() == true && next.getName() == container)
    {
        valid = true;
    }
  }

  return numQualifiers;
}
예제 #27
0
/*
 * Subclasses should override this method to read (and store) XHTML,
 * MathML, etc. directly from the XMLInputStream.
 *
 * @return true if the subclass read from the stream, false otherwise.
 */
bool
InitialAssignment::readOtherXML (XMLInputStream& stream)
{
  bool          read = false;
  const string& name = stream.peek().getName();

  if (name == "math")
  {
    // if this is level 1 there shouldnt be any math!!!
    if (getLevel() == 1) 
    {
      logError(NotSchemaConformant, getLevel(), getVersion(),
	       "SBML Level 1 does not support MathML.");
      delete mMath;
      return false;
    }

    if (mMath)
    {
      if (getLevel() < 3) 
      {
        logError(NotSchemaConformant, getLevel(), getVersion(),
	        "Only one <math> element is permitted inside a "
	        "particular containing element.");
      }
      else
      {
        logError(OneMathElementPerInitialAssign, getLevel(), getVersion());
      }
    }
   /* check for MathML namespace 
     * this may be explicitly declared here
     * or implicitly declared on the whole document
     */
    const XMLToken elem = stream.peek();
    unsigned int match = 0;
    int n;
    if (elem.getNamespaces().getLength() != 0)
    {
      for (n = 0; n < elem.getNamespaces().getLength(); n++)
      {
        if (!strcmp(elem.getNamespaces().getURI(n).c_str(), "http://www.w3.org/1998/Math/MathML"))
        {
          match = 1;
          break;
        }
      }
    }
    if (match == 0)
    {
      if( mSBML->getNamespaces() != NULL)
      /* check for implicit declaration */
      {
        for (n = 0; n < mSBML->getNamespaces()->getLength(); n++)
        {
          if (!strcmp(mSBML->getNamespaces()->getURI(n).c_str(), 
                                                     "http://www.w3.org/1998/Math/MathML"))
          {
            match = 1;
            break;
          }
        }
      }
    }
    if (match == 0)
    {
      logError(InvalidMathElement);
    }

    delete mMath;
    mMath = readMathML(stream);
    if (mMath) mMath->setParentSBMLObject(this);
    read  = true;
  }

  return read;
}
예제 #28
0
bool 
ASTBase::readAttributes(const XMLAttributes& attributes,
                       const ExpectedAttributes& expectedAttributes,
                               XMLInputStream& stream, const XMLToken& element)
{
  bool read = true;

  //
  // check that all attributes are expected
  //
  for (int i = 0; i < attributes.getLength(); i++)
  {
    std::string name   = attributes.getName(i);
    std::string uri    = attributes.getURI(i);
    std::string prefix = attributes.getPrefix(i);

    //
    // To allow prefixed attribute whose namespace doesn't belong to
    // core or extension package.
    //
    // (e.g. xsi:type attribute in Curve element in layout extension)
    //
    if (!prefix.empty())
    {
      if ( expectedAttributes.hasAttribute(prefix + ":" + name) ) continue;
    }

    if (!expectedAttributes.hasAttribute(name))
    {
      std::string message = "The attribute '" + name + "' is not permitted" +
        " on a <" + element.getName() + "> element.";
      if (name == "type")
      {
        logError(stream, element, DisallowedMathTypeAttributeUse, message);    
      }
      else if (name == "encoding")
      {
        logError(stream, element, DisallowedMathMLEncodingUse, message);    
      }
      else if (name == "definitionURL")
      {
        logError(stream, element, DisallowedDefinitionURLUse, message);    
      }
      else if (name == "units")
      {
        if (stream.getSBMLNamespaces() != NULL
          && stream.getSBMLNamespaces()->getLevel() > 2)
        {
          logError(stream, element, DisallowedMathUnitsUse, message);   
        }
        else
        {
          message = "The 'units' attribute was introduced in SBML Level 3.";
          logError(stream, element, InvalidMathMLAttribute, message);  
        }

      }
      else
      {
        logError(stream, element, InvalidMathElement, message);
      }

      // not sufficient to make the read bad
      //return false;
    }
  }


  
  string id; 
  string className;
  string style;

  attributes.readInto( "id"           , id        );
  attributes.readInto( "class"        , className );
  attributes.readInto( "style"        , style     );

  if (!id.empty())
  {
	  if (setId(id) != LIBSBML_OPERATION_SUCCESS)
    {
      read = false;
    }
  }

  if (!className.empty())
  {
	  if (setClass(className) != LIBSBML_OPERATION_SUCCESS)
    {
      read = false;
    }
  }

  if (!style.empty())
  {
	  if (setStyle(style) != LIBSBML_OPERATION_SUCCESS)
    {
      read = false;
    }
  }

  unsigned int i = 0;
  while (read == true && i < getNumPlugins())
  {
    read = getPlugin(i)->readAttributes(attributes, expectedAttributes, 
                                        stream, element, getExtendedType());
    i++;
  }


  return read;
}
bool
ASTCSymbolDelayNode::read(XMLInputStream& stream, const std::string& reqd_prefix)
{
  bool read = false;
  XMLToken element = stream.peek ();
  const string&  nameE = element.getName();

  if (nameE != "csymbol")
  {
#if 0
    cout << "HELP\n";
#endif
    return read;
  }

  ASTBase::read(stream, reqd_prefix);

  const string nameDelay = trim( stream.next().getCharacters() );
    
  setName((nameDelay));
  ASTBase::setType(AST_FUNCTION_DELAY);

  stream.skipPastEnd(element);
  
  const char * name;
  ASTBase * child = NULL;

  unsigned int numChildrenAdded = 0;
  // catch if we do not have two children
  if (getExpectedNumChildren() > 0)
  {
    while (stream.isGood() && numChildrenAdded < getExpectedNumChildren())
    {
      stream.skipText();

      name = stream.peek().getName().c_str();

      if (representsNumber(ASTBase::getTypeFromName(name)) == true)
      {
        child = new ASTNumber();
      }
      else 
      {
        child = new ASTFunction();
      }

      read = child->read(stream, reqd_prefix);

      stream.skipText();

      if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS)
      {
        numChildrenAdded++;
      }
      else
      {
        read = false;
        break;
      }
    }
  }
  else
  {
    stream.skipPastEnd(element);
    read = true;
  }

  return read;
}