You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by au...@apache.org on 2001/04/19 20:46:27 UTC

cvs commit: xml-xalan/c/samples/UseStylesheetParam UseStylesheetParam.cpp

auriemma    01/04/19 11:46:27

  Modified:    c/samples/UseStylesheetParam UseStylesheetParam.cpp
  Log:
  Updated to use the XalanTransformer class.
  
  Revision  Changes    Path
  1.11      +40 -116   xml-xalan/c/samples/UseStylesheetParam/UseStylesheetParam.cpp
  
  Index: UseStylesheetParam.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/samples/UseStylesheetParam/UseStylesheetParam.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- UseStylesheetParam.cpp	2001/01/08 20:26:43	1.10
  +++ UseStylesheetParam.cpp	2001/04/19 18:46:26	1.11
  @@ -3,48 +3,14 @@
   
   
   
  -#if defined(XALAN_OLD_STREAM_HEADERS)
  -#include <fstream.h>
  -#include <iostream.h>
  -#else
  -#include <fstream>
  -#include <iostream>
  -#endif
  -
  -
  -
   #include <util/PlatformUtils.hpp>
   
   
  -
  -#include <PlatformSupport/DOMStringHelper.hpp>
  -
  -
  -
  -#include <DOMSupport/DOMSupportDefault.hpp>
  -
  -
  -
  -#include <XPath/XObjectFactoryDefault.hpp>
  -#include <XPath/XPathFactoryDefault.hpp>
  -
   
  +#include <XalanTransformer/XalanTransformer.hpp>
   
  -#include <XSLT/StylesheetConstructionContextDefault.hpp>
  -#include <XSLT/StylesheetExecutionContextDefault.hpp>
  -#include <XSLT/XSLTEngineImpl.hpp>
  -#include <XSLT/XSLTInit.hpp>
  -#include <XSLT/XSLTInputSource.hpp>
  -#include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
  -#include <XSLT/XSLTResultTarget.hpp>
   
   
  -
  -#include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
  -#include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
  -
  -
  -
   int
   main(
   		  int				     argc,
  @@ -53,101 +19,59 @@
   #if !defined(XALAN_NO_NAMESPACES)
     using std::cerr;
     using std::endl;
  -  using std::ofstream;
   #endif
   
  +	int	theResult = 0;
  +
   	if (argc != 3)
   	{
   		cerr << "Usage: UseStylesheetParam key expression" << endl;
   
  -		return -1;
  +		theResult = -1;
   	}
  -
  -	try
  +	else
   	{
  -		// Call the static initializer for Xerces...
  +		// Call the static initializer for Xerces.
   		XMLPlatformUtils::Initialize();
   
  -		{
  -			// Initialize the Xalan XSLT subsystem...
  -			XSLTInit			theInit;
  +		// Initialize Xalan.
  +		XalanTransformer::initialize();
  +
  +		// Create a XalanTransformer.
  +		XalanTransformer theXalanTransformer;
   
  -			// Get the stylesheet parameter key (name) and
  -			// expression (a string expression).
  -			const XalanDOMString	paramKey(argv[1]);
  -			const XalanDOMString	paramExpression(argv[2]);
  -
  -			// Set up input and output objects for the transformation.
  -			// Assumption: the executable is run from the directory
  -			// containing the input files. 
  -			const XalanDOMString	theXMLFileName("foo.xml");
  -			const XalanDOMString	theXSLFileName("foo.xsl");
  -
  -			const XSLTInputSource	theInputSource(c_wstr(theXMLFileName));
  -			const XSLTInputSource	theStylesheetSource(c_wstr(theXSLFileName));
  - 
  -			// The output target...
  -			const XalanDOMString	theOutputFile("foo.out");
  -			XSLTResultTarget		theResultTarget(theOutputFile);
  -
  -			// Create some support objects that are necessary for running the processor...
  -			XalanSourceTreeDOMSupport		theDOMSupport;
  -			XalanSourceTreeParserLiaison	theParserLiaison(theDOMSupport);
  -
  -			// Hook the two together...
  -			theDOMSupport.setParserLiaison(&theParserLiaison);
  -
  -			// Create some more support objects.
  -			XSLTProcessorEnvSupportDefault	theXSLTProcessorEnvSupport;
  -			XObjectFactoryDefault			theXObjectFactory;
  -			XPathFactoryDefault				theXPathFactory;
  -
  -			// Create a processor...
  -			XSLTEngineImpl	theProcessor(
  -						theParserLiaison,
  -						theXSLTProcessorEnvSupport,
  -						theDOMSupport,
  -						theXObjectFactory,
  -						theXPathFactory);
  -
  - 
  -			// Connect the processor to the support object...
  -			theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
  -
  -			// Create a stylesheet construction context, and a stylesheet
  -			// execution context...
  -			StylesheetConstructionContextDefault	theConstructionContext(
  -							theProcessor,
  -							theXSLTProcessorEnvSupport,
  -							theXPathFactory);
  -
  -			StylesheetExecutionContextDefault		theExecutionContext(
  -							theProcessor,
  -							theXSLTProcessorEnvSupport,
  -							theDOMSupport,
  -							theXObjectFactory);
  -
  -			// Set the stylesheet parameter.
  -			theProcessor.setStylesheetParam(paramKey,  paramExpression);
  - 
  -			// Perform the transformation...
  -			theProcessor.process(
  -							theInputSource,
  -							theStylesheetSource,
  -							theResultTarget,
  -							theConstructionContext,
  -							theExecutionContext);
  +		// Our input files...The assumption is that the executable will be run
  +		// from same directory as the input files.
  +		const char*		theXMLFileName = "foo.xml";
  +		const char*		theXSLFileName = "foo.xsl";
  +
  +		// Our output target...
  +		const char*	theOutputFileName = "foo.out";
  +
  +		// Get the stylesheet parameter key (name) and
  +		// expression (a string expression).
  +		const char*	paramKey = argv[1];
  +		const char*	paramExpression = argv[2];
  +
  +		// Set the stylesheet parameter.
  +		theXalanTransformer.setStylesheetParam(paramKey, paramExpression);
  +
  +		// Do the transform.
  +		theResult = theXalanTransformer.transform(theXMLFileName, theXSLFileName, theOutputFileName);
  +    
  +		if(theResult != 0)
  +		{
  +			cerr << "UseStylesheetParam Error: \n" << theXalanTransformer.getLastError()
  +				 << endl
  +				 << endl;
   		}
   
  -		// Call the static terminator for Xerces...
  +		// Terminate Xalan.
  +		XalanTransformer::terminate();
  +
  +		// Call the static terminator for Xerces.
   		XMLPlatformUtils::Terminate();
   	}
  -	catch(...)
  -	{
  -		cerr << "UseStylesheetParam Exception caught!!!"
  -			 << endl
  -			 << endl;
  -	}
   
  -	return 0;
  +	return theResult;
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org