Пример #1
0
LIBSBML_CPP_NAMESPACE_BEGIN


/**
 * Creates a new list of XML namespaces declarations from a "raw" Xerces-C++
 * Attributes set.
 */
XercesNamespaces::XercesNamespaces (const xercesc::Attributes& attrs)
{
  unsigned int size = attrs.getLength();
  mNamespaces.reserve(size);


  for (unsigned int n = 0; n < size; ++n)
  {
    const string            name  = XercesTranscode( attrs.getLocalName(n) );
    const string            qname = XercesTranscode( attrs.getQName    (n) );
    const string            value = XercesTranscode( attrs.getValue    (n) );
    const string::size_type pos   = qname.find(":", 0);

    const string prefix = (pos != string::npos) ? qname.substr(0, pos) : "";

         if (prefix == "xmlns") add( value, name );
    else if (name   == "xmlns") add( value );
  }
}
Пример #2
0
void ConfigurationManager::startElement(const XMLCh* const uri, const XMLCh* const localname,
                                        const XMLCh* const qname,
                                        const xercesc::Attributes& attributes)
{
   std::map<std::string, std::string> *currentMapPtr = NULL;

   dtUtil::XMLStringConverter qnameConv(qname);
   std::string sectionStr = qnameConv.ToString();

   if(sectionStr == "General")
   {
      currentMapPtr = &mGeneralVariables;
   }
   else if(sectionStr == "Layout")
   {
      currentMapPtr = &mLayoutVariables;
   }
   else if(sectionStr == "Plugins")
   {
      currentMapPtr = &mPluginVariables;
   }
   else
   {
      //Unrecognized element; can't do much with it
      return;
   }

   for(XMLSize_t i = 0; i < attributes.getLength(); ++i)
   {
      dtUtil::XMLStringConverter varNameConv(attributes.getQName(i));
      dtUtil::XMLStringConverter varValueConv(attributes.getValue(i));

      (*currentMapPtr)[varNameConv.ToString()] = varValueConv.ToString();
   }
}
Пример #3
0
XMLNodeAttributeMap::XMLNodeAttributeMap( const xercesc::Attributes &attributes )
{
    for ( size_t i = 0; i < attributes.getLength(); i++ )
    {
        std::string key   = transcodeString( attributes.getLocalName( i ) );
        std::string value = transcodeString( attributes.getValue( i ) );

        m_attributes.insert( std::make_pair( key, value ) );
    }
}
//-----------------------------------------------------------------------------
smart::data::message_content_handler_base::tag_attributes_collection_type smart::data::message_content_handler_base::get_attribs(const xercesc::Attributes& attrs) const
{
  tag_attributes_collection_type attrs_res;

  for (unsigned int/*size_t*/ i = 0; i < attrs.getLength(); ++i)
  {
    const string attr_name           = xml_to_std_string(xml_string_type(attrs.getQName(i)));
    const xml_string_type attr_value = xml_string_type(attrs.getValue(i));
    attrs_res.insert(make_pair(attr_name, attr_value));
  }

  return attrs_res;
}
Пример #5
0
void XParser::startElement(const XMLCh* const uri, const XMLCh* const local,
		  	   const XMLCh* const raw,
			   const xercesc::Attributes& attrs)
{
	// if text is mixed with elements.
	if (_elementBuffer.length() > 0)
	{
		std::string	text = _trim(_elementBuffer);
		if (text.length() > 0)
		{
			unsigned long long	value = XHash::hash(text);
			int	tid = _xtree->addText(_idStack[_stackTop],
						      _lsidStack[_stackTop],
						      text, value);
			_lsidStack[_stackTop] = tid;
			_currentNodeID = tid;
			_valueStack[_stackTop] += value;
		}
	}

	std::string local_s(xercesc::XMLString::transcode(local));

//cout << "Add element " << _idStack[_stackTop] << "\t" << _lsidStack[_stackTop] << "\t" << local_s << endl;
	int	eid = _xtree->addElement(_idStack[_stackTop],
					 _lsidStack[_stackTop], local_s);
	// Update last sibling info.
	_lsidStack[_stackTop] = eid;

	// Push
	_stackTop++;
	_idStack[_stackTop] = eid;
	_currentNodeID = eid;
	_lsidStack[_stackTop] = XTree::NULL_NODE;
	_valueStack[_stackTop] = XHash::hash(local_s);

	// Take care of attributes
	if (attrs.getLength() > 0)
	{
		for (unsigned int i = 0; i < attrs.getLength(); i++)
		{
			std::string	name(xercesc::XMLString::transcode(attrs.getQName(i)));
			unsigned long long	namehash = XHash::hash(name);
			
			unsigned long long	attrhash = namehash * namehash;
			std::string	value = "";
			char	*valueP = xercesc::XMLString::transcode(attrs.getValue(i));
			if (valueP != NULL)
			{
				value = std::string(valueP);
				unsigned long long valuehash = XHash::hash(value);
				attrhash += valuehash * valuehash;
			}
			int	aid = _xtree->addAttribute(eid, _lsidStack[_stackTop], name, value, namehash, attrhash);

			_lsidStack[_stackTop] = aid;
			_currentNodeID = aid + 1;
			_valueStack[_stackTop] += attrhash * attrhash;
		}
	}
	
	_readElement = true;
	_elementBuffer = std::string("");

}
Пример #6
0
		void startElement(
			const XMLCh* namespaceURI, 
			const XMLCh* lName, 
			const XMLCh* qName, 
			const xercesc::Attributes& attrs)
		{

			// Update the information about the state of the current element (tracks ancestor attributes)
			outer.lock()->setElementState( ElementState(outer.lock()->getElementState(), attrs ));

			// Stash new URIs in xsi:schemaLocation attributes if desired
			if (loader->useSchemaLocationAttributes()) 
			{
				std::string schemaLocations = to_string(attrs.getValue(XS(XMLConstants::XMLSchemaInstanceNamespace),XS("schemaLocation")));
				if (!schemaLocations.empty()) 
				{
					//logger.debug("Processing schema locations: " + schemaLocations);
					//std::string[] fields = schemaLocations.trim().split("\\s+");
					//for (int i=1; i<fields.length; i=i+2) 
					{
						//try 
						//{
						//	Poco::URI uri = getBaseURISAXResolver().getBaseURI().resolve(Poco::URI(fields[i]));
						//	logger.debug("Working on: " + uri);
						//	loader.stashURI(uri);
						//}
						//catch (URISyntaxException e) 
						//{
						//	logger.warn("Ignoring malformed XSI schemaLocation URI in: " + schemaLocations);
						//}
						//catch (XBRLException e) 
						//{
						//	logger.warn("A problem occurred when stashing the schemaLocation URI: " + fields[i]);
						//}
						//catch (XMLBaseException e) 
						//{
						//	logger.warn("A problem occurred when getting the base URI so schemaLocation URIs were not stashed from: " + schemaLocations);
						//}
					}
				}
			}

			// Identify the fragments
			for (const std::shared_ptr<Identifier>& identifier : identifiers) 
			{
				try 
				{
					identifier->startElement(namespaceURI, lName, qName, attrs);
					if (loader->isBuildingAFragment()) 
					{
						if (loader->getFragment().isNewFragment()) 
						{
							break;
						}
					}
				}
				catch (XBRLException e) 
				{
					//	logger.error(this->getURI() + " : " + e.getMessage());
					throw xercesc::SAXException(strcat("Fragment identification failed. ", + e.getMessage().c_str()));
				}
			}

			if (! loader->isBuildingAFragment()) 
			{
				throw xercesc::SAXException("Some element has not been placed in a fragment.");
			}

			// Insert the current element into the fragment being built
			try 
			{
				Fragment fragment = loader->getFragment();
				//if (fragment == NULL) throw xercesc::SAXException("A fragment should be being built.");
				Builder builder = fragment.getBuilder();
				//if (builder == null) throw xercesc::SAXException("A fragment that is being built needs a builder.");
				builder.appendElement(namespaceURI, lName, qName, attrs);

				// Hardwire XLink resource language code inheritance to
				// improve query performance based on language selections.
				if (attrs.getIndex(XS(XMLConstants::XLinkNamespace),XS("type")) > -1) 
				{
					//try 
					//{
					std::shared_ptr<DOMElement> element = fragment.getDataRootElement();
					if (!element->hasAttributeNS(XS(XMLConstants::XMLNamespace),XS("lang"))) 
					{
						std::string code = outer.lock()->getElementState().getLanguageCode();
						//if (code != null) 
						//{
						element->setAttribute(XS("xml:lang"),XS(code));
						//}
					}
					//}
					//catch (Throwable t) 
					//{
					//	logger.info("bugger");
					//}
				}

			}
			catch (XBRLException e) 
			{
				//	logger.error(this->getURI() + " : " + e.getMessage());
				throw xercesc::SAXException(strcat("The element could not be appended to the fragment.",e.getMessage().c_str()));
			}

		}
Пример #7
0
		void startElement(
			const XMLCh* namespaceURI, 
			const XMLCh* lName, 
			const XMLCh* qName,
			const xercesc::Attributes& attrs)
		{
			std::shared_ptr<Fragment> fragment;

			if (namespaceURI == XS(XMLConstants::XMLSchemaNamespace)) 
			{
				if (lName == L"group")
				{
					fragment = std::make_shared<SchemaGroupCompositor>();
				} 
				else if (lName == L"all")
				{
					fragment = std::make_shared<SchemaAllCompositor>();
				} 
				else if (lName == L"choice")
				{
					fragment = std::make_shared<SchemaChoiceCompositor>();
				} 
				else if (lName == L"sequence")
				{
					fragment = std::make_shared<SchemaSequenceCompositor>();
				} 
				else if (lName == L"complexType")
				{
					fragment = std::make_shared<TypeDeclaration>();
				} 
				else if (lName == L"simpleType")
				{
					fragment = std::make_shared<SimpleTypeDeclaration>();
				} 
				else if (lName == L"attribute")
				{
					fragment = std::make_shared<AttributeDeclaration>();
				} 
				else if (lName == L"attributeGroup")
				{
					fragment = std::make_shared<AttributeGroupDeclaration>();
				} 
				else if (lName == L"schema")
				{
					fragment = std::make_shared<Schema>();
					setXSModel(constructXSModel());
					setTargetNamespace(std::shared_ptr<const XMLCh>(attrs.getValue(L"targetNamespace")));
				} 
				else if (lName == L"element")
				{
					auto elementName = std::shared_ptr<const XMLCh>(attrs.getValue(L"name"));

					if (!getXSModel().get()) 
					{
						throw new XBRLException("An XML Schema element declaration was found outside of an XML Schema.");
					}

					auto targetNamespace = getTargetNamespace(); 
					if (!targetNamespace.get()) 
					{
						throw new XBRLException("An XML Schema element was found without a target namespace.");
					}

					// Find the XS model element declaration for the element that has been started - if one can be found
					std::shared_ptr<XSElementDeclaration> declaration;

					// Handle anonymous schemas first - these are the tough case
					if (targetNamespace.get())
					{
						// Get the list of namespaces declared in the model
						auto nsItemList = std::shared_ptr<XSNamespaceItemList>(getXSModel()->getNamespaceItems());

						// For each namespace ...
						for (XMLSize_t i=0; i < nsItemList->size(); ++i) 
						{
							auto nsItem = std::shared_ptr<XSNamespaceItem>(nsItemList->elementAt(i));

							// Get a candidate element declaration if one exists
							auto candidateDeclaration = std::shared_ptr<XSElementDeclaration>(nsItem->getElementDeclaration(elementName.get()));


							if (candidateDeclaration.get()) 
							{
								// Get the URIs of the documents that were used to create elements in this namespace
								auto locations = std::shared_ptr<const StringList>(nsItem->getDocumentLocations());

								// Check to see if the current document URI is one of those documents and if so, the candidate could be good
								for (XMLSize_t j=0; j < locations->size(); ++j) 
								{
									auto location = locations->elementAt(j);
									if (to_string(location) == contentHandler->getURI().toString()) 
									{
										// Throw an exception if we find two feasible candidate element declarations in the Schema model
										if (declaration.get()) throw new XBRLException("Potentially ambiguous anonymous Schema problem.");
										declaration = candidateDeclaration;
									}
								}
							}
						}

						if (!declaration.get()) throw new XBRLException("An element declaration was found that could not be handled.");

						// Handle the easy case where the schema specifies its target namespace
					} 
					else if (elementName.get()) 
					{

						declaration = 
							std::shared_ptr<XSElementDeclaration>(
								getXSModel()->getElementDeclaration(elementName.get(), 
								getTargetNamespace().get()));
					}

					// Determine what substitution groups the element is in - if any.
					if (declaration.get()) 
					{
						auto sgDeclaration = std::shared_ptr<XSElementDeclaration>(declaration->getSubstitutionGroupAffiliation());
						while (sgDeclaration.get()) 
						{
							if (to_string(sgDeclaration->getNamespace()) == XMLConstants::XBRL21Namespace)
							{
								if (sgDeclaration->getName() == L"item")
								{
									fragment = std::shared_ptr<Concept>();
									break;
								} 
								else if (sgDeclaration->getName() == L"tuple")
								{
									fragment = std::shared_ptr<Concept>();
									break;
								}
							}

							if (to_string(sgDeclaration->getNamespace()) == XMLConstants::XBRL21LinkNamespace)
							{
								//if (sgDeclaration->getName() == L"part")
								//	fragment = std::shared_ptr<ReferencePartDeclaration>();
								break;
							}
							sgDeclaration = 
								std::shared_ptr<XSElementDeclaration>(sgDeclaration->getSubstitutionGroupAffiliation());
						}
					}

					if (!fragment.get()) 
					{
						fragment = std::shared_ptr<ElementDeclaration>();
					}
				}

				if (fragment.get()) 
				{
					outer.lock()->processFragment(fragment, attrs);
				}
			}
		}