You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/06/07 20:35:08 UTC

cvs commit: xml-xalan/c/src/XSLT Stylesheet.cpp Stylesheet.hpp StylesheetConstructionContext.hpp StylesheetConstructionContextDefault.cpp StylesheetConstructionContextDefault.hpp StylesheetHandler.cpp XSLTEngineImpl.cpp

dbertoni    00/06/07 11:35:07

  Modified:    c/src/XSLT Stylesheet.cpp Stylesheet.hpp
                        StylesheetConstructionContext.hpp
                        StylesheetConstructionContextDefault.cpp
                        StylesheetConstructionContextDefault.hpp
                        StylesheetHandler.cpp XSLTEngineImpl.cpp
  Log:
  Raise an error when more than one named template of the same name exists in a stylesheet.  Also added code to better manage object lifetime to plug memory leaks during exceptions.
  
  Revision  Changes    Path
  1.20      +29 -7     xml-xalan/c/src/XSLT/Stylesheet.cpp
  
  Index: Stylesheet.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.cpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Stylesheet.cpp	2000/05/29 22:47:30	1.19
  +++ Stylesheet.cpp	2000/06/07 18:35:01	1.20
  @@ -415,7 +415,9 @@
    * Add a template to the template list.
    */
   void
  -Stylesheet::addTemplate(ElemTemplate *tmpl)
  +Stylesheet::addTemplate(
  +			ElemTemplate*					tmpl,
  +			StylesheetConstructionContext&	constructionContext)
   {
   	unsigned int	pos = 0;
   
  @@ -443,9 +445,30 @@
   		}
   	}
   
  -	if(tmpl->getName().isEmpty() == false)
  +	const QName&	theName = tmpl->getName();
  +
  +	if(theName.isEmpty() == false)
   	{
  -		m_namedTemplates.insert(ElemTemplateElementMapType::value_type(tmpl->getName(), tmpl));
  +		if (m_namedTemplates.find(theName) != m_namedTemplates.end())
  +		{
  +			XalanDOMString	theMessage("The stylesheet already has a template with the name ");
  +
  +			const XalanDOMString&	theNamespace = theName.getNamespace();
  +
  +			if (length(theNamespace) != 0)
  +			{
  +				theMessage += theNamespace;
  +				theMessage += ":";
  +			}
  +
  +			theMessage += theName.getLocalPart();
  +
  +			constructionContext.error(theMessage, 0, tmpl);
  +		}
  +		else
  +		{
  +			m_namedTemplates[theName] = tmpl;
  +		}
   	}
   
   	const XPath* const	xp = tmpl->getMatchPattern();
  @@ -556,11 +579,11 @@
   
   	if(0 == theResult)
   	{
  -		const int	nImports = m_imports.size();
  +		const unsigned int	nImports = m_imports.size();
   
  -		for(int i = 0; i < nImports; i++)
  +		for(unsigned int i = 0; i < nImports; i++)
   		{
  -			Stylesheet* const	stylesheet = m_imports[i];
  +			const Stylesheet* const		stylesheet = m_imports[i];
   			assert(stylesheet != 0);
   
   			theResult = stylesheet->getTopLevelVariable(name, executionContext);
  @@ -635,7 +658,6 @@
   			{
   			case XalanNode::ELEMENT_NODE:
   				{
  -					//java: XalanDOMString targetName = m_processor->getParserLiaison().getLocalNameOfNode(targetNode);
   					const XalanDOMString	targetName = DOMServices::getLocalNameOfNode(*targetNode);
   					matchPatternList = locateMatchPatternList2(targetName, true);
   				}
  
  
  
  1.13      +15 -9     xml-xalan/c/src/XSLT/Stylesheet.hpp
  
  Index: Stylesheet.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/Stylesheet.hpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Stylesheet.hpp	2000/05/29 22:47:30	1.12
  +++ Stylesheet.hpp	2000/06/07 18:35:01	1.13
  @@ -138,7 +138,7 @@
   typedef XALAN_STD vector<NameSpace> 				  NamespaceVectorType;
   typedef XALAN_STD vector<NamespaceVectorType>		  NamespacesStackType;
   typedef XALAN_STD vector<QName> 					  QNameVectorType;
  -typedef XALAN_STD vector<Stylesheet*>				  StylesheetVectorType;
  +typedef XALAN_STD vector<const Stylesheet*>				StylesheetVectorType;
   typedef XALAN_STD vector<const XMLURL*> 			  URLStackType;
   typedef XALAN_STD vector<const XPath*>				  XPathVectorType;
   typedef XALAN_STD vector<ElemDecimalFormat*>			ElemDecimalFormatVectorType;
  @@ -313,16 +313,19 @@
   	 * Add a template to the list of names templates
   	 * 
   	 * @param tmpl template to add
  +	 * @param constructionContext context for construction
   	 */
   	void
  -	addTemplate(ElemTemplate *tmpl);
  +	addTemplate(
  +			ElemTemplate*					tmpl,
  +			StylesheetConstructionContext&	constructionContext);
   
   	/**
   	 * Process an attribute that has the value of 'yes' or 'no'.
   	 * 
   	 * @param aname name of attribute
   	 * @param val value
  -	 * @param constructionContext context for evaluation
  +	 * @param constructionContext context for construction
   	 * @return true if value equals string constant for "yes," false otherwise
   	 */
   	virtual bool
  @@ -463,14 +466,17 @@
   	}
   
   	/**
  -	 * Retrieve the list of imported stylesheets
  -	 * 
  -	 * @return vector of imported stylesheets
  +	 * Add an imported stylesheet.
  +	 *
  +	 * @param theStylesheet The stylesheet to add.
  +	 * @param fFront If true, the stylesheet is added to the front of the imports, instead of the end.
   	 */
  -	StylesheetVectorType&
  -	getImports()
  +	void
  +	addImport(
  +			const Stylesheet*	theStylesheet,
  +			bool				fFront)
   	{
  -		return m_imports;
  +		m_imports.insert(fFront ? m_imports.begin() : m_imports.end(), theStylesheet);
   	}
   
   	/**
  
  
  
  1.8       +16 -2     xml-xalan/c/src/XSLT/StylesheetConstructionContext.hpp
  
  Index: StylesheetConstructionContext.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetConstructionContext.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StylesheetConstructionContext.hpp	2000/05/29 22:47:55	1.7
  +++ StylesheetConstructionContext.hpp	2000/06/07 18:35:01	1.8
  @@ -82,6 +82,7 @@
   class DocumentHandler;
   class Locator;
   class PrefixResolver;
  +class Stylesheet;
   class StylesheetRoot;
   class XalanDocument;
   class XPath;
  @@ -137,9 +138,22 @@
   	create(XSLTInputSource&		theInputSource) = 0;
   
   	/**
  +	 * Create a new Stylesheet instance.  The StylesheetConstructionContext
  +	 * instance owns the Stylesheet instance, and will delete it when asked
  +	 * or when the StylesheetConstructionContext instance is destroyed.
  +	 *
  +	 * @param A reference to the StylesheetRoot instance.
  +	 * @param theBaseIdentifier A URI to the stylesheet file.
  +	 * @return A pointer to a new StylesheetRoot instance.
  +	 */
  +	virtual Stylesheet*
  +	create(
  +			StylesheetRoot&			theStylesheetRoot,
  +			const XalanDOMString&	theBaseIdentifier) = 0;
  +
  +	/**
   	 * Destroy a StylesheetRoot instance.  If this StylesheetConstructionContext
  -	 * instance does not own the StylesheetRoot, it will not delete the
  -	 * StylesheetRoot.
  +	 * instance does not own the StylesheetRoot, it will not delete it
   	 *
   	 * @param theStylesheet A pointer to the StylesheetRoot instance to delete.
   	 */
  
  
  
  1.7       +16 -0     xml-xalan/c/src/XSLT/StylesheetConstructionContextDefault.cpp
  
  Index: StylesheetConstructionContextDefault.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetConstructionContextDefault.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StylesheetConstructionContextDefault.cpp	2000/05/29 22:47:55	1.6
  +++ StylesheetConstructionContextDefault.cpp	2000/06/07 18:35:01	1.7
  @@ -184,6 +184,22 @@
   
   
   
  +Stylesheet*
  +StylesheetConstructionContextDefault::create(
  +			StylesheetRoot&			theStylesheetRoot,
  +			const XalanDOMString&	theBaseIdentifier)
  +{
  +	Stylesheet* const	theStylesheet =
  +		new Stylesheet(
  +			theStylesheetRoot,
  +			theBaseIdentifier,
  +			*this);
  +
  +	return theStylesheet;
  +}
  +
  +
  +
   void
   StylesheetConstructionContextDefault::destroy(StylesheetRoot*	theStylesheetRoot)
   {
  
  
  
  1.8       +5 -0      xml-xalan/c/src/XSLT/StylesheetConstructionContextDefault.hpp
  
  Index: StylesheetConstructionContextDefault.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetConstructionContextDefault.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StylesheetConstructionContextDefault.hpp	2000/05/29 22:47:55	1.7
  +++ StylesheetConstructionContextDefault.hpp	2000/06/07 18:35:01	1.8
  @@ -135,6 +135,11 @@
   	virtual StylesheetRoot*
   	create(XSLTInputSource&		theInputSource);
   
  +	virtual Stylesheet*
  +	create(
  +			StylesheetRoot&			theStylesheetRoot,
  +			const XalanDOMString&	theBaseIdentifier);
  +
   	virtual void
   	destroy(StylesheetRoot*		theStylesheetRoot);
   
  
  
  
  1.31      +34 -15    xml-xalan/c/src/XSLT/StylesheetHandler.cpp
  
  Index: StylesheetHandler.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetHandler.cpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- StylesheetHandler.cpp	2000/05/31 15:02:46	1.30
  +++ StylesheetHandler.cpp	2000/06/07 18:35:01	1.31
  @@ -56,16 +56,19 @@
    */
   #include "StylesheetHandler.hpp"
   
  +
  +
   #include <algorithm>
  -#include <PlatformSupport/STLHelper.hpp>
  +#include <memory>
  +
   
   
   #include <sax/Locator.hpp>
   #include <sax/SAXException.hpp>
  -
   #include <util/XMLURL.hpp>
   
   
  +
   #include <XMLSupport/Formatter.hpp>
   
   
  @@ -73,6 +76,7 @@
   #include <PlatformSupport/AttributeListImpl.hpp>
   #include <PlatformSupport/DOMStringHelper.hpp>
   #include <PlatformSupport/StringTokenizer.hpp>
  +#include <PlatformSupport/STLHelper.hpp>
   
   
   
  @@ -305,7 +309,7 @@
   												name, atts, lineNumber, columnNumber);
   					m_elemStack.push_back(m_pTemplate);
   					m_inTemplate = true;
  -					m_stylesheet.addTemplate(m_pTemplate);
  +					m_stylesheet.addTemplate(m_pTemplate, m_constructionContext);
   					break;
   
   				case Constants::ELEMNAME_EXTENSION:
  @@ -1015,16 +1019,24 @@
   	{
   		m_exceptionPending = true;
   
  -		m_pendingException = e.getMessage();
  +		// Pop anything that's not an empty element...
  +		while(m_elemStack.back()->getXSLToken() != Constants::ELEMNAME_UNDEFINED)
  +		{
  +			m_elemStack.pop_back();
  +		}
   
  -		m_elemStack.clear();
  +		m_pendingException = e.getMessage();
   	}
   	catch(...)
   	{
   		// $$$ ToDo: This probably should't happen, but it does...
   		m_exceptionPending = true;
   
  -		m_elemStack.clear();
  +		// Pop anything that's not an empty element...
  +		while(m_elemStack.back()->getXSLToken() != Constants::ELEMNAME_UNDEFINED)
  +		{
  +			m_elemStack.pop_back();
  +		}
   
   		throw;
   	}
  @@ -1112,6 +1124,9 @@
   
   		if(equals(aname, Constants::ATTRNAME_HREF))
   		{
  +#if !defined(XALAN_NO_NAMESPACES)
  +			using std::auto_ptr;
  +#endif
   			foundIt = true;
   			
   			if(m_foundNotImport)
  @@ -1145,19 +1160,23 @@
   
   			const XalanDOMString	theImportURI(hrefUrl->getURLText());
   
  -			Stylesheet* pImportedStylesheet = new Stylesheet(
  +			// This will take care of cleaning up the stylesheet if an exception
  +			// is thrown.
  +			auto_ptr<Stylesheet>	importedStylesheet( 
  +				m_constructionContext.create(
   				m_stylesheet.getStylesheetRoot(), 
  -				theImportURI,
  -				m_constructionContext);
  +				theImportURI));
  +
  +			StylesheetHandler tp(*importedStylesheet.get(), m_constructionContext);
   
  -			StylesheetHandler tp(*pImportedStylesheet, m_constructionContext);
  +			m_constructionContext.parseXML(*hrefUrl, &tp, importedStylesheet.get());
   
  -			m_constructionContext.parseXML(*hrefUrl, &tp, pImportedStylesheet);
  +			// Add it to the front of the imports
  +			m_stylesheet.addImport(importedStylesheet.get(), true);
   
  -			// I'm going to insert the elements in backwards order, 
  -			// so I can walk them 0 to n.
  -			m_stylesheet.getImports().insert(m_stylesheet.getImports().begin(),
  -				pImportedStylesheet);
  +			// The imported stylesheet is now owned by the stylesheet, so
  +			// release the auto_ptr.
  +			importedStylesheet.release();
   
   			importStack.pop_back();
   			
  
  
  
  1.44      +2 -2      xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp
  
  Index: XSLTEngineImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- XSLTEngineImpl.cpp	2000/06/01 16:28:37	1.43
  +++ XSLTEngineImpl.cpp	2000/06/07 18:35:02	1.44
  @@ -463,7 +463,7 @@
   
   				if(false == isRoot)
   				{
  -					prevStylesheet->getImports().push_back(stylesheet);
  +					prevStylesheet->addImport(stylesheet, false);
   				}
   
   				prevStylesheet = stylesheet;
  @@ -856,7 +856,7 @@
   			}
   			else
   			{
  -				stylesheet = new Stylesheet(*const_cast<StylesheetRoot*>(m_stylesheetRoot), stringHolder, constructionContext);
  +				stylesheet = constructionContext.create(*const_cast<StylesheetRoot*>(m_stylesheetRoot), stringHolder);
   			}
   
   			StylesheetHandler stylesheetProcessor(*stylesheet, constructionContext);