Annotation of parser3/src/classes/xalan-patched/XalanTransformer2.cpp, revision 1.1
1.1 ! parser 1: /*
! 2: * The Apache Software License, Version 1.1
! 3: *
! 4: *
! 5: * Copyright (c) 2001 The Apache Software Foundation. All rights
! 6: * reserved.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: *
! 12: * 1. Redistributions of source code must retain the above copyright
! 13: * notice, this list of conditions and the following disclaimer.
! 14: *
! 15: * 2. Redistributions in binary form must reproduce the above copyright
! 16: * notice, this list of conditions and the following disclaimer in
! 17: * the documentation and/or other materials provided with the
! 18: * distribution.
! 19: *
! 20: * 3. The end-user documentation included with the redistribution,
! 21: * if any, must include the following acknowledgment:
! 22: * "This product includes software developed by the
! 23: * Apache Software Foundation (http://www.apache.org/)."
! 24: * Alternately, this acknowledgment may appear in the software itself,
! 25: * if and wherever such third-party acknowledgments normally appear.
! 26: *
! 27: * 4. The names "Xalan" and "Apache Software Foundation" must
! 28: * not be used to endorse or promote products derived from this
! 29: * software without prior written permission. For written
! 30: * permission, please contact apache@apache.org.
! 31: *
! 32: * 5. Products derived from this software may not be called "Apache",
! 33: * nor may "Apache" appear in their name, without prior written
! 34: * permission of the Apache Software Foundation.
! 35: *
! 36: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
! 37: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 38: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 39: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
! 40: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
! 41: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
! 42: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
! 43: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
! 44: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
! 45: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
! 46: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 47: * SUCH DAMAGE.
! 48: * ====================================================================
! 49: *
! 50: * This software consists of voluntary contributions made by many
! 51: * individuals on behalf of the Apache Software Foundation and was
! 52: * originally based on software copyright (c) 1999, International
! 53: * Business Machines, Inc., http://www.ibm.com. For more
! 54: * information on the Apache Software Foundation, please see
! 55: * <http://www.apache.org/>.
! 56: */
! 57: #include "XalanTransformer.hpp"
! 58:
! 59:
! 60:
! 61: #include <algorithm>
! 62:
! 63:
! 64:
! 65: #include <sax/SAXException.hpp>
! 66:
! 67:
! 68:
! 69: #include <XalanDOM/XalanDOMException.hpp>
! 70:
! 71:
! 72:
! 73: #include <PlatformSupport/DOMStringHelper.hpp>
! 74: #include <PlatformSupport/DOMStringPrintWriter.hpp>
! 75: #include <PlatformSupport/XalanOutputStreamPrintWriter.hpp>
! 76:
! 77:
! 78:
! 79: #include <XPath/XObjectFactoryDefault.hpp>
! 80: #include <XPath/XPathFactoryBlock.hpp>
! 81: #include <XPath/XPathFactoryDefault.hpp>
! 82:
! 83:
! 84:
! 85: #include <XSLT/StylesheetConstructionContextDefault.hpp>
! 86: #include <XSLT/StylesheetExecutionContextDefault.hpp>
! 87: #include <XSLT/StylesheetRoot.hpp>
! 88: #include <XSLT/XSLTEngineImpl.hpp>
! 89: #include <XSLT/XSLTInit.hpp>
! 90: #include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
! 91:
! 92:
! 93:
! 94: #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
! 95: #include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
! 96:
! 97:
! 98:
! 99: #include "XalanCompiledStylesheetDefault.hpp"
! 100: #include "XalanDefaultDocumentBuilder.hpp"
! 101: #include "XalanDefaultParsedSource.hpp"
! 102: #include "XalanTransformerOutputStream.hpp"
! 103: #include "XercesDOMParsedSource.hpp"
! 104:
! 105:
! 106:
! 107: XSLTInit* XalanTransformer::s_xsltInit = 0;
! 108:
! 109:
! 110:
! 111: XalanTransformer::XalanTransformer():
! 112: m_compiledStylesheets(),
! 113: m_parsedSources(),
! 114: m_paramPairs(),
! 115: m_functionPairs(),
! 116: m_errorMessage(1, '\0'),
! 117: m_stylesheetExecutionContext(new StylesheetExecutionContextDefault)
! 118: {
! 119: }
! 120:
! 121:
! 122:
! 123: XalanTransformer::~XalanTransformer()
! 124: {
! 125: #if !defined(XALAN_NO_NAMESPACES)
! 126: using std::for_each;
! 127: #endif
! 128:
! 129: // Clean up all entries in the compliledStylesheets vector.
! 130: for_each(m_compiledStylesheets.begin(),
! 131: m_compiledStylesheets.end(),
! 132: DeleteFunctor<XalanCompiledStylesheet>());
! 133:
! 134: // Clean up all entries in the compliledStylesheets vector.
! 135: for_each(m_parsedSources.begin(),
! 136: m_parsedSources.end(),
! 137: DeleteFunctor<XalanParsedSource>());
! 138:
! 139: for (FunctionParamPairVectorType::size_type i = 0; i < m_functionPairs.size(); ++i)
! 140: {
! 141: delete m_functionPairs[i].second;
! 142: }
! 143:
! 144: m_functionPairs.clear();
! 145:
! 146: delete m_stylesheetExecutionContext;
! 147: }
! 148:
! 149:
! 150:
! 151: void
! 152: XalanTransformer::initialize()
! 153: {
! 154: // Initialize Xalan.
! 155: s_xsltInit = new XSLTInit;
! 156: }
! 157:
! 158:
! 159:
! 160: void
! 161: XalanTransformer::terminate()
! 162: {
! 163: // Terminate Xalan and release memory.
! 164: delete s_xsltInit;
! 165:
! 166: s_xsltInit = 0;
! 167: }
! 168:
! 169:
! 170:
! 171: int
! 172: XalanTransformer::transform(
! 173: const XalanParsedSource& theParsedXML,
! 174: const XSLTInputSource& theStylesheetSource,
! 175: const XSLTResultTarget& theResultTarget)
! 176: {
! 177: #if !defined(XALAN_NO_NAMESPACES)
! 178: using std::for_each;
! 179: #endif
! 180:
! 181: int theResult = 0;
! 182:
! 183: // Clear the error message.
! 184: m_errorMessage.resize(1, '\0');
! 185:
! 186: // Store error messages from problem listener.
! 187: XalanDOMString theErrorMessage;
! 188:
! 189: try
! 190: {
! 191: // Create the helper object that is necessary for running the processor...
! 192: XalanAutoPtr<XalanParsedSourceHelper> theHelper(theParsedXML.createHelper());
! 193: assert(theHelper.get() != 0);
! 194:
! 195: DOMSupport& theDOMSupport = theHelper->getDOMSupport();
! 196:
! 197: XMLParserLiaison& theParserLiaison = theHelper->getParserLiaison();
! 198:
! 199: // Create some more support objects...
! 200: XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport;
! 201:
! 202: XObjectFactoryDefault theXObjectFactory;
! 203:
! 204: XPathFactoryDefault theXPathFactory;
! 205:
! 206: // Create a processor...
! 207: XSLTEngineImpl theProcessor(
! 208: theParserLiaison,
! 209: theXSLTProcessorEnvSupport,
! 210: theDOMSupport,
! 211: theXObjectFactory,
! 212: theXPathFactory);
! 213:
! 214: theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
! 215:
! 216: // Create a problem listener and send output to a XalanDOMString.
! 217: DOMStringPrintWriter thePrintWriter(theErrorMessage);
! 218:
! 219: ProblemListenerDefault theProblemListener(&thePrintWriter);
! 220:
! 221: theProcessor.setProblemListener(&theProblemListener);
! 222:
! 223: theParserLiaison.setExecutionContext(*m_stylesheetExecutionContext);
! 224:
! 225: // Create a stylesheet construction context,
! 226: // using the stylesheet's factory support objects.
! 227: StylesheetConstructionContextDefault theStylesheetConstructionContext(
! 228: theProcessor,
! 229: theXSLTProcessorEnvSupport,
! 230: theXPathFactory);
! 231:
! 232: // Hack used to cast away const.
! 233: XSLTResultTarget tempResultTarget(theResultTarget);
! 234:
! 235: const EnsureReset theReset(*this);
! 236:
! 237: // Set up the stylesheet execution context.
! 238: m_stylesheetExecutionContext->setXPathEnvSupport(&theXSLTProcessorEnvSupport);
! 239:
! 240: m_stylesheetExecutionContext->setDOMSupport(&theDOMSupport);
! 241:
! 242: m_stylesheetExecutionContext->setXObjectFactory(&theXObjectFactory);
! 243:
! 244: m_stylesheetExecutionContext->setXSLTProcessor(&theProcessor);
! 245:
! 246: // Set the parameters if any.
! 247: for (ParamPairVectorType::size_type i = 0; i < m_paramPairs.size(); ++i)
! 248: {
! 249: theProcessor.setStylesheetParam(
! 250: m_paramPairs[i].first,
! 251: m_paramPairs[i].second);
! 252: }
! 253:
! 254: // Set the functions if any.
! 255: for (FunctionParamPairVectorType::size_type f = 0; f < m_functionPairs.size(); ++f)
! 256: {
! 257: theXSLTProcessorEnvSupport.installExternalFunctionLocal(
! 258: m_functionPairs[f].first.getNamespace(),
! 259: m_functionPairs[f].first.getLocalPart(),
! 260: *(m_functionPairs[f].second));
! 261: }
! 262:
! 263: // Do the transformation...
! 264: theProcessor.process(
! 265: theParsedXML.getDocument(),
! 266: theStylesheetSource,
! 267: tempResultTarget,
! 268: theStylesheetConstructionContext,
! 269: *m_stylesheetExecutionContext);
! 270: }
! 271: catch (XSLException& e)
! 272: {
! 273: if (length(theErrorMessage) != 0)
! 274: {
! 275: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 276: }
! 277: else
! 278: {
! 279: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 280: }
! 281:
! 282: theResult = -1;
! 283: }
! 284: catch (SAXException& e)
! 285: {
! 286: if (length(theErrorMessage) != 0)
! 287: {
! 288: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 289: }
! 290: else
! 291: {
! 292: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 293: }
! 294:
! 295: theResult = -2;
! 296: }
! 297: catch (XMLException& e)
! 298: {
! 299: if (length(theErrorMessage) != 0)
! 300: {
! 301: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 302: }
! 303: else
! 304: {
! 305: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 306: }
! 307:
! 308: theResult = -3;
! 309: }
! 310: catch(const XalanDOMException& e)
! 311: {
! 312: if (length(theErrorMessage) != 0)
! 313: {
! 314: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 315: }
! 316: else
! 317: {
! 318: XalanDOMString theMessage("XalanDOMException caught. The code is ");
! 319:
! 320: append(theMessage, LongToDOMString(long(e.getExceptionCode())));
! 321: append(theMessage, XalanDOMString("."));
! 322:
! 323: TranscodeToLocalCodePage(theMessage, m_errorMessage, true);
! 324: }
! 325:
! 326: theResult = -4;
! 327: }
! 328:
! 329: return theResult;
! 330: }
! 331:
! 332:
! 333:
! 334: int
! 335: XalanTransformer::transform(
! 336: const XalanParsedSource& theParsedXML,
! 337: const XalanCompiledStylesheet* theCompiledStylesheet,
! 338: const XSLTResultTarget& theResultTarget)
! 339: {
! 340: #if !defined(XALAN_NO_NAMESPACES)
! 341: using std::for_each;
! 342: #endif
! 343:
! 344: int theResult = 0;
! 345:
! 346: // Clear the error message.
! 347: m_errorMessage.resize(1, '\0');
! 348:
! 349: // Store error messages from problem listener.
! 350: XalanDOMString theErrorMessage;
! 351:
! 352: try
! 353: {
! 354: // Create the helper object that is necessary for running the processor...
! 355: XalanAutoPtr<XalanParsedSourceHelper> theHelper(theParsedXML.createHelper());
! 356: assert(theHelper.get() != 0);
! 357:
! 358: DOMSupport& theDOMSupport = theHelper->getDOMSupport();
! 359:
! 360: XMLParserLiaison& theParserLiaison = theHelper->getParserLiaison();
! 361:
! 362: // Create some more support objects...
! 363: XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport;
! 364:
! 365: XObjectFactoryDefault theXObjectFactory;
! 366:
! 367: XPathFactoryDefault theXPathFactory;
! 368:
! 369: // Create a processor...
! 370: XSLTEngineImpl theProcessor(
! 371: theParserLiaison,
! 372: theXSLTProcessorEnvSupport,
! 373: theDOMSupport,
! 374: theXObjectFactory,
! 375: theXPathFactory);
! 376:
! 377: theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
! 378:
! 379: // Create a problem listener and send output to a XalanDOMString.
! 380: DOMStringPrintWriter thePrintWriter(theErrorMessage);
! 381:
! 382: ProblemListenerDefault theProblemListener(&thePrintWriter);
! 383:
! 384: theProcessor.setProblemListener(&theProblemListener);
! 385:
! 386: // Since the result target is not const in our
! 387: // internal intefaces, we'll pass in a local copy
! 388: // of the one provided...
! 389: XSLTResultTarget tempResultTarget(theResultTarget);
! 390:
! 391: const EnsureReset theReset(*this);
! 392:
! 393: // Set up the stylesheet execution context.
! 394: m_stylesheetExecutionContext->setXPathEnvSupport(&theXSLTProcessorEnvSupport);
! 395:
! 396: m_stylesheetExecutionContext->setDOMSupport(&theDOMSupport);
! 397:
! 398: m_stylesheetExecutionContext->setXObjectFactory(&theXObjectFactory);
! 399:
! 400: m_stylesheetExecutionContext->setXSLTProcessor(&theProcessor);
! 401:
! 402: // Set the compiled stylesheet.
! 403: m_stylesheetExecutionContext->setStylesheetRoot(theCompiledStylesheet->getStylesheetRoot());
! 404:
! 405: // Set the parameters if any.
! 406: for (ParamPairVectorType::size_type i = 0; i < m_paramPairs.size(); ++i)
! 407: {
! 408: theProcessor.setStylesheetParam(
! 409: m_paramPairs[i].first,
! 410: m_paramPairs[i].second);
! 411: }
! 412:
! 413: // Set the functions if any.
! 414: for (FunctionParamPairVectorType::size_type f = 0; f < m_functionPairs.size(); ++f)
! 415: {
! 416: theXSLTProcessorEnvSupport.installExternalFunctionLocal(
! 417: m_functionPairs[f].first.getNamespace(),
! 418: m_functionPairs[f].first.getLocalPart(),
! 419: *(m_functionPairs[f].second));
! 420: }
! 421:
! 422: // Do the transformation...
! 423: theProcessor.process(
! 424: theParsedXML.getDocument(),
! 425: tempResultTarget,
! 426: *m_stylesheetExecutionContext);
! 427: }
! 428: catch (XSLException& e)
! 429: {
! 430: if (length(theErrorMessage) != 0)
! 431: {
! 432: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 433: }
! 434: else
! 435: {
! 436: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 437: }
! 438:
! 439: theResult = -1;
! 440: }
! 441: catch (SAXException& e)
! 442: {
! 443: if (length(theErrorMessage) != 0)
! 444: {
! 445: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 446: }
! 447: else
! 448: {
! 449: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 450: }
! 451:
! 452: theResult = -2;
! 453: }
! 454: catch (XMLException& e)
! 455: {
! 456: if (length(theErrorMessage) != 0)
! 457: {
! 458: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 459: }
! 460: else
! 461: {
! 462: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 463: }
! 464:
! 465: theResult = -3;
! 466: }
! 467: catch(const XalanDOMException& e)
! 468: {
! 469: if (length(theErrorMessage) != 0)
! 470: {
! 471: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 472: }
! 473: else
! 474: {
! 475: XalanDOMString theMessage("XalanDOMException caught. The code is ");
! 476:
! 477: append(theMessage, LongToDOMString(long(e.getExceptionCode())));
! 478: append(theMessage, XalanDOMString("."));
! 479:
! 480: TranscodeToLocalCodePage(theMessage, m_errorMessage, true);
! 481: }
! 482:
! 483: theResult = -4;
! 484: }
! 485:
! 486: return theResult;
! 487: }
! 488:
! 489:
! 490:
! 491: int
! 492: XalanTransformer::transform(
! 493: const XSLTInputSource& theInputSource,
! 494: const XalanCompiledStylesheet* theCompiledStylesheet,
! 495: const XSLTResultTarget& theResultTarget)
! 496: {
! 497: const XalanParsedSource* theParsedSource = 0;
! 498:
! 499: const int theResult = parseSource(theInputSource, theParsedSource);
! 500:
! 501: if (theResult != 0)
! 502: {
! 503: return theResult;
! 504: }
! 505: else
! 506: {
! 507: assert(theParsedSource != 0);
! 508:
! 509: // Make sure the parsed source is destroyed when
! 510: // the transformation is finished...
! 511: EnsureDestroyParsedSource theGuard(*this, theParsedSource);
! 512:
! 513: // Do the transformation...
! 514: return transform(
! 515: *theParsedSource,
! 516: theCompiledStylesheet,
! 517: theResultTarget);
! 518: }
! 519: }
! 520:
! 521: int
! 522: XalanTransformer::transform(
! 523: const XSLTInputSource& theInputSource,
! 524: const XSLTInputSource& theStylesheetSource,
! 525: const XSLTResultTarget& theResultTarget)
! 526: {
! 527: // Parse the source document.
! 528: const XalanParsedSource* theParsedSource = 0;
! 529:
! 530: const int theResult = parseSource(theInputSource, theParsedSource);
! 531:
! 532: if (theResult != 0)
! 533: {
! 534: return theResult;
! 535: }
! 536: else
! 537: {
! 538: assert(theParsedSource != 0);
! 539:
! 540: // Make sure the parsed source is destroyed when
! 541: // the transformation is finished...
! 542: EnsureDestroyParsedSource theGuard(*this, theParsedSource);
! 543:
! 544: // Do the transformation...
! 545: return transform(
! 546: *theParsedSource,
! 547: theStylesheetSource,
! 548: theResultTarget);
! 549: }
! 550: }
! 551:
! 552:
! 553:
! 554: int
! 555: XalanTransformer::transform(
! 556: const XSLTInputSource& theInputSource,
! 557: const XSLTResultTarget& theResultTarget)
! 558: {
! 559: // Do the transformation...
! 560: return transform(
! 561: theInputSource,
! 562: XSLTInputSource(),
! 563: theResultTarget);
! 564: }
! 565:
! 566:
! 567:
! 568: int
! 569: XalanTransformer::transform(
! 570: const XSLTInputSource& theInputSource,
! 571: const XSLTInputSource& theStylesheetSource,
! 572: void* theOutputHandle,
! 573: XalanOutputHandlerType theOutputHandler,
! 574: XalanFlushHandlerType theFlushHandler)
! 575: {
! 576: // Set to output target to the callback
! 577: XalanTransformerOutputStream theOutputStream(theOutputHandle, theOutputHandler, theFlushHandler);
! 578:
! 579: XalanOutputStreamPrintWriter thePrintWriter(theOutputStream);
! 580:
! 581: XSLTResultTarget theResultTarget(&thePrintWriter);
! 582:
! 583: // Do the transformation...
! 584: return transform(
! 585: theInputSource,
! 586: theStylesheetSource,
! 587: theResultTarget);
! 588: }
! 589:
! 590:
! 591:
! 592: int
! 593: XalanTransformer::transform(
! 594: const XalanParsedSource& theParsedSource,
! 595: const XalanCompiledStylesheet* theCompiledStylesheet,
! 596: void* theOutputHandle,
! 597: XalanOutputHandlerType theOutputHandler,
! 598: XalanFlushHandlerType theFlushHandler)
! 599: {
! 600: // Set to output target to the callback
! 601: XalanTransformerOutputStream theOutputStream(theOutputHandle, theOutputHandler, theFlushHandler);
! 602:
! 603: XalanOutputStreamPrintWriter thePrintWriter(theOutputStream);
! 604:
! 605: XSLTResultTarget theResultTarget(&thePrintWriter);
! 606:
! 607: // Do the transformation...
! 608: return transform(
! 609: theParsedSource,
! 610: theCompiledStylesheet,
! 611: theResultTarget);
! 612: }
! 613:
! 614:
! 615:
! 616: int
! 617: XalanTransformer::transform(
! 618: const XSLTInputSource& theInputSource,
! 619: void* theOutputHandle,
! 620: XalanOutputHandlerType theOutputHandler,
! 621: XalanFlushHandlerType theFlushHandler)
! 622: {
! 623: // Set to output target to the callback
! 624: XalanTransformerOutputStream theOutputStream(theOutputHandle, theOutputHandler, theFlushHandler);
! 625:
! 626: XalanOutputStreamPrintWriter thePrintWriter(theOutputStream);
! 627:
! 628: XSLTResultTarget theResultTarget(&thePrintWriter);
! 629:
! 630: // Do the transformation...
! 631: return transform(
! 632: theInputSource,
! 633: XSLTInputSource(),
! 634: theResultTarget);
! 635: }
! 636:
! 637:
! 638:
! 639: int
! 640: XalanTransformer::compileStylesheet(
! 641: const XSLTInputSource& theStylesheetSource,
! 642: const XalanCompiledStylesheet*& theCompiledStylesheet)
! 643: {
! 644: // Clear the error message.
! 645: m_errorMessage.resize(1, '\0');
! 646:
! 647: // Store error messages from problem listener.
! 648: XalanDOMString theErrorMessage;
! 649:
! 650: int theResult = 0;
! 651:
! 652: try
! 653: {
! 654: // Create some support objects that are necessary for running the processor...
! 655: XalanSourceTreeDOMSupport theDOMSupport;
! 656:
! 657: XalanSourceTreeParserLiaison theParserLiaison(theDOMSupport);
! 658:
! 659: // Hook the two together...
! 660: theDOMSupport.setParserLiaison(&theParserLiaison);
! 661:
! 662: // Create some more support objects...
! 663: XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport;
! 664:
! 665: XObjectFactoryDefault theXObjectFactory;
! 666:
! 667: XPathFactoryDefault theXPathFactory;
! 668:
! 669: // Create a processor...
! 670: XSLTEngineImpl theProcessor(
! 671: theParserLiaison,
! 672: theXSLTProcessorEnvSupport,
! 673: theDOMSupport,
! 674: theXObjectFactory,
! 675: theXPathFactory);
! 676:
! 677: // Create a problem listener and send output to a XalanDOMString.
! 678: DOMStringPrintWriter thePrintWriter(theErrorMessage);
! 679:
! 680: ProblemListenerDefault theProblemListener(&thePrintWriter);
! 681:
! 682: theProcessor.setProblemListener(&theProblemListener);
! 683:
! 684: // Create a new XalanCompiledStylesheet.
! 685: theCompiledStylesheet =
! 686: new XalanCompiledStylesheetDefault(
! 687: theStylesheetSource,
! 688: theXSLTProcessorEnvSupport,
! 689: theProcessor);
! 690:
! 691: // Store it in a vector.
! 692: m_compiledStylesheets.push_back(theCompiledStylesheet);
! 693: }
! 694: catch (XSLException& e)
! 695: {
! 696: if (length(theErrorMessage) != 0)
! 697: {
! 698: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 699: }
! 700: else
! 701: {
! 702: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 703: }
! 704:
! 705: theResult = -1;
! 706: }
! 707: catch (SAXException& e)
! 708: {
! 709: if (length(theErrorMessage) != 0)
! 710: {
! 711: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 712: }
! 713: else
! 714: {
! 715: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 716: }
! 717:
! 718: theResult = -2;
! 719: }
! 720: catch (XMLException& e)
! 721: {
! 722: if (length(theErrorMessage) != 0)
! 723: {
! 724: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 725: }
! 726: else
! 727: {
! 728: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 729: }
! 730:
! 731: theResult = -3;
! 732: }
! 733: catch(const XalanDOMException& e)
! 734: {
! 735: if (length(theErrorMessage) != 0)
! 736: {
! 737: TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
! 738: }
! 739: else
! 740: {
! 741: XalanDOMString theMessage("XalanDOMException caught. The code is ");
! 742:
! 743: append(theMessage, LongToDOMString(long(e.getExceptionCode())));
! 744:
! 745: append(theMessage, XalanDOMString("."));
! 746:
! 747: TranscodeToLocalCodePage(theMessage, m_errorMessage, true);
! 748: }
! 749:
! 750: theResult = -4;
! 751: }
! 752:
! 753: return theResult;
! 754: }
! 755:
! 756:
! 757:
! 758: int
! 759: XalanTransformer::destroyStylesheet(const XalanCompiledStylesheet* theStylesheet)
! 760: {
! 761: #if !defined(XALAN_NO_NAMESPACES)
! 762: using std::find;
! 763: #endif
! 764:
! 765: const CompiledStylesheetPtrVectorType::iterator i =
! 766: find(
! 767: m_compiledStylesheets.begin(),
! 768: m_compiledStylesheets.end(),
! 769: theStylesheet);
! 770:
! 771: if (i == m_compiledStylesheets.end())
! 772: {
! 773: const char* const theStylesheetErrorMessage =
! 774: "An invalid compiled stylesheet was provided.";
! 775:
! 776: const unsigned int theLength =
! 777: length(theStylesheetErrorMessage);
! 778:
! 779: m_errorMessage.resize(theLength + 1, '\0');
! 780:
! 781: strncpy(&*m_errorMessage.begin(), theStylesheetErrorMessage, theLength);
! 782:
! 783: return -1;
! 784: }
! 785: else
! 786: {
! 787: m_compiledStylesheets.erase(i);
! 788:
! 789: #if defined(XALAN_CANNOT_DELETE_CONST)
! 790: delete (XalanCompiledStylesheet*) theStylesheet;
! 791: #else
! 792: delete theStylesheet;
! 793: #endif
! 794:
! 795: return 0;
! 796: }
! 797: }
! 798:
! 799:
! 800:
! 801: int
! 802: XalanTransformer::parseSource(
! 803: const XSLTInputSource& theInputSource,
! 804: const XalanParsedSource*& theParsedSource,
! 805: bool useXercesDOM)
! 806: {
! 807: // Clear the error message.
! 808: m_errorMessage.clear();
! 809: m_errorMessage.push_back(0);
! 810:
! 811: int theResult = 0;
! 812:
! 813: try
! 814: {
! 815: if(useXercesDOM == true)
! 816: {
! 817: theParsedSource = new XercesDOMParsedSource(theInputSource);
! 818: }
! 819: else
! 820: {
! 821: theParsedSource = new XalanDefaultParsedSource(theInputSource);
! 822: }
! 823:
! 824: // Store it in a vector.
! 825: m_parsedSources.push_back(theParsedSource);
! 826: }
! 827: catch (XSLException& e)
! 828: {
! 829: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 830:
! 831: theResult = -1;
! 832: }
! 833: catch (SAXException& e)
! 834: {
! 835: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 836:
! 837: theResult = -2;
! 838: }
! 839: catch (XMLException& e)
! 840: {
! 841: TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
! 842:
! 843: theResult = -3;
! 844: }
! 845: catch(const XalanDOMException& e)
! 846: {
! 847: XalanDOMString theMessage("XalanDOMException caught. The code is ");
! 848:
! 849: append(theMessage, LongToDOMString(long(e.getExceptionCode())));
! 850:
! 851: append(theMessage, XalanDOMString("."));
! 852:
! 853: TranscodeToLocalCodePage(theMessage, m_errorMessage, true);
! 854:
! 855: theResult = -3;
! 856: }
! 857:
! 858: return theResult;
! 859: }
! 860:
! 861:
! 862:
! 863: int
! 864: XalanTransformer::destroyParsedSource(const XalanParsedSource* theParsedSource)
! 865: {
! 866: #if !defined(XALAN_NO_NAMESPACES)
! 867: using std::find;
! 868: #endif
! 869:
! 870: const ParsedSourcePtrVectorType::iterator i =
! 871: find(
! 872: m_parsedSources.begin(),
! 873: m_parsedSources.end(),
! 874: theParsedSource);
! 875:
! 876: if (i == m_parsedSources.end())
! 877: {
! 878: const char* const theParsedSourceErrorMessage =
! 879: "An invalid parsed source was provided.";
! 880:
! 881: const unsigned int theLength =
! 882: length(theParsedSourceErrorMessage);
! 883:
! 884: m_errorMessage.resize(theLength + 1, '\0');
! 885:
! 886: strncpy(&*m_errorMessage.begin(), theParsedSourceErrorMessage, theLength);
! 887:
! 888: return -1;
! 889: }
! 890: else
! 891: {
! 892: m_parsedSources.erase(i);
! 893:
! 894: #if defined(XALAN_CANNOT_DELETE_CONST)
! 895: delete (XalanCompiledStylesheet*) theParsedSource;
! 896: #else
! 897: delete theParsedSource;
! 898: #endif
! 899:
! 900: return 0;
! 901: }
! 902: }
! 903:
! 904:
! 905:
! 906: void
! 907: XalanTransformer::setStylesheetParam(
! 908: const XalanDOMString& key,
! 909: const XalanDOMString& expression)
! 910: {
! 911: // Store the stylesheet parameter in a vector.
! 912: m_paramPairs.push_back(ParamPairType(key, expression));
! 913: }
! 914:
! 915:
! 916:
! 917: XalanDocumentBuilder*
! 918: XalanTransformer::createDocumentBuilder()
! 919: {
! 920: m_parsedSources.reserve(m_parsedSources.size() + 1);
! 921:
! 922: XalanDocumentBuilder* const theNewBuilder = new XalanDefaultDocumentBuilder;
! 923:
! 924: m_parsedSources.push_back(theNewBuilder);
! 925:
! 926: return theNewBuilder;
! 927: }
! 928:
! 929:
! 930:
! 931: void
! 932: XalanTransformer::destroyDocumentBuilder(XalanDocumentBuilder* theDocumentBuilder)
! 933: {
! 934: destroyParsedSource(theDocumentBuilder);
! 935: }
! 936:
! 937:
! 938:
! 939: void
! 940: XalanTransformer::installExternalFunction(
! 941: const XalanDOMString& theNamespace,
! 942: const XalanDOMString& functionName,
! 943: const Function& function)
! 944: {
! 945: m_functionPairs.push_back(FunctionPairType(XalanQNameByValue(theNamespace, functionName), function.clone()));
! 946: }
! 947:
! 948:
! 949:
! 950: void
! 951: XalanTransformer::installExternalFunctionGlobal(
! 952: const XalanDOMString& theNamespace,
! 953: const XalanDOMString& functionName,
! 954: const Function& function)
! 955: {
! 956: XSLTProcessorEnvSupportDefault::installExternalFunctionGlobal(
! 957: theNamespace,
! 958: functionName,
! 959: function);
! 960: }
! 961:
! 962:
! 963:
! 964: void
! 965: XalanTransformer::uninstallExternalFunction(
! 966: const XalanDOMString& theNamespace,
! 967: const XalanDOMString& functionName)
! 968: {
! 969: for (FunctionParamPairVectorType::size_type i = 0; i < m_functionPairs.size(); ++i)
! 970: {
! 971: if(XalanQNameByReference(theNamespace, functionName).equals(m_functionPairs[i].first))
! 972: {
! 973: delete m_functionPairs[i].second;
! 974:
! 975: m_functionPairs.erase(m_functionPairs.begin() + i);
! 976: }
! 977: }
! 978: }
! 979:
! 980:
! 981:
! 982: void
! 983: XalanTransformer::uninstallExternalFunctionGlobal(
! 984: const XalanDOMString& theNamespace,
! 985: const XalanDOMString& functionName)
! 986: {
! 987: XSLTProcessorEnvSupportDefault::uninstallExternalFunctionGlobal(
! 988: theNamespace,
! 989: functionName);
! 990: }
! 991:
! 992:
! 993:
! 994:
! 995: const char*
! 996: XalanTransformer::getLastError() const
! 997: {
! 998: return &m_errorMessage[0];
! 999: }
! 1000:
! 1001:
! 1002:
! 1003: void
! 1004: XalanTransformer::reset()
! 1005: {
! 1006: try
! 1007: {
! 1008: // Reset objects.
! 1009: m_stylesheetExecutionContext->setXPathEnvSupport(0);
! 1010:
! 1011: m_stylesheetExecutionContext->setDOMSupport(0);
! 1012:
! 1013: m_stylesheetExecutionContext->setXObjectFactory(0);
! 1014:
! 1015: m_stylesheetExecutionContext->setXSLTProcessor(0);
! 1016:
! 1017: m_stylesheetExecutionContext->reset();
! 1018:
! 1019: // Clear the ParamPairVectorType.
! 1020: m_paramPairs.clear();
! 1021: }
! 1022: catch(...)
! 1023: {
! 1024: }
! 1025: }
! 1026:
! 1027:
! 1028:
! 1029:
! 1030: XalanTransformer::EnsureReset::~EnsureReset()
! 1031: {
! 1032: m_transformer.m_stylesheetExecutionContext->reset();
! 1033:
! 1034: m_transformer.reset();
! 1035: }
E-mail: