void
XalanXMLSerializerFactory::setEncoding(
                             MemoryManager&          theManager,
                             Writer&            theWriter,
                             XalanDOMString&    theEncoding)
{
    XalanOutputStream* stream = theWriter.getStream();

    if(stream != 0)
    {
        if(theEncoding.empty())
        {
            // Default to UTF-8 if the requested encoding is not supported...
            stream->setOutputEncoding(XalanDOMString(XalanTranscodingServices::s_utf8String, theManager));

            theEncoding = XalanTranscodingServices::s_utf8String;
        }
        else
        {
            try
            {
                stream->setOutputEncoding(theEncoding);
            }
            catch(const XalanOutputStream::UnsupportedEncodingException&)
            {
                // Default to UTF-8 if the requested encoding is not supported...
                stream->setOutputEncoding(XalanDOMString(XalanTranscodingServices::s_utf8String, theManager));

                theEncoding = XalanTranscodingServices::s_utf8String;
            }
        }

    }
}
Example #2
0
ParseOptionType  
XalanCProcessor::getParseOption(const XalanNode* option)
{
    if (option != 0 
        && option->getNodeType() == XalanNode::TEXT_NODE)
    {
        if (option->getNodeValue() == XalanDOMString("") 
            || option->getNodeValue() == XalanDOMString("xst"))
        {
            return eXalanSourceTree;
        }
        else if (option->getNodeValue() == XalanDOMString("xerces-dom"))
        {
            return eXercesDOM;
        }
        else 
        {
            return eInvalid;
        }
    }
    else
    {
        return eInvalid;
    }
}
Example #3
0
    /**
     * Get the namespace from a prefix by searching the stack of namespace
     * lists.
     *
     * @param prefix prefix to search
     * @return namespace corresponding to prefix, or null if not found.
     */
    const XalanDOMString*
    getNamespaceForPrefixFromStack(const XalanDOMChar*	prefix) const
    {
        assert(prefix != 0);

        return XalanQName::getNamespaceForPrefix(m_namespaces, XalanDOMString(prefix));
    }
Example #4
0
void
XercesParserLiaison::formatErrorMessage(
			const SAXParseExceptionType&	e,
			XalanDOMString& 				theMessage)
{

	const XalanDOMChar* const	theSystemID = e.getSystemId();

	if (theSystemID == 0 || length(theSystemID) == 0)
	{

		append(theMessage,XalanMessageLoader::getMessage(XalanMessages::AtUnknownFileLineColumn_2Param
			,LongToDOMString(long(e.getLineNumber()))
			,LongToDOMString(long(e.getColumnNumber()))
			));
	}
	else
	{
		append(theMessage,XalanMessageLoader::getMessage(XalanMessages::AtFileLineColumn_3Param
			,XalanDOMString(theSystemID)
			,LongToDOMString(long(e.getLineNumber()))
			,LongToDOMString(long(e.getColumnNumber()))
			));
	}

	append(theMessage, e.getMessage());
}
inline bool
checkForExclusion(const XALAN_CPP_NAMESPACE_QUALIFIER XalanDOMString&	currentFile)
{
	for (int i=0; excludeStylesheets[i] != 0; i++)
	{	
		if (currentFile == XALAN_CPP_NAMESPACE_QUALIFIER XalanDOMString(excludeStylesheets[i]))
		{
			return true;
		}
	}
	return false;
}
Example #6
0
const XMLCh*
NamedNodeMapAttributeList::getValue(const XMLCh* const name) const
{
	const XalanNode*	theNode = m_nodeMap.getNamedItem(XalanDOMString(name));

	if (theNode == 0)
	{
		return 0;
	}
	else
	{
		return c_wstr(theNode->getNodeValue());
	}
}
Example #7
0
int CXslTransform::setResultTarget(const char *pszFileName)
{
    closeResultTarget();

    try
    {
        m_resultTargetFile.clear().append(pszFileName);
        m_resultTarget = new XSLTResultTarget(XalanDOMString(pszFileName));
    }
    catch(...)
    {
        throw MakeStringException(1, "Exception opening file %s", pszFileName);
    }
    return 0;
}
Example #8
0
ResultTarget*
XalanCProcessor::getResultOption(
    const XalanDOMString& fileName,
    const XalanNode* option)
{
    if (option != 0 
        && option->getNodeType() == XalanNode::TEXT_NODE
        && m_resultOptionsMap.find(option->getNodeValue()) != m_resultOptionsMap.end())
    {
        return m_resultOptionsMap[option->getNodeValue()]->clone(fileName);
    }
    else
    {
        return m_resultOptionsMap[XalanDOMString("")]->clone(fileName);
    }
}
const XalanDOMString
XercesBridgeHelper::substringData(
			const DOM_CharacterDataType&	theXercesNode,
			unsigned int					offset,
			unsigned int					count)
{
	try
	{
		const DOMStringType		theString(theXercesNode.substringData(offset, count));

		return XalanDOMString(theString.rawBuffer(), theString.length());
	}
	catch(const DOM_DOMExceptionType&	theException)
	{
		throw XercesDOMException(theException);
	}
}
Example #10
0
void
XalanCProcessor::init()
{
    m_transformer = new XalanTransformer();

    m_resultOptionsMap[XalanDOMString("")] = &m_fileResult;
    m_resultOptionsMap[XalanDOMString("file")] = &m_fileResult;
    m_resultOptionsMap[XalanDOMString("xst")] = &m_xalanSourceTreeResult;
    m_resultOptionsMap[XalanDOMString("xerces-dom")] = &m_xercesDOMResult;
    m_resultOptionsMap[XalanDOMString("null")] = &m_nullResult;
    m_resultOptionsMap[XalanDOMString("stream")] = &m_streamResult;
}
Example #11
0
XALAN_CPP_NAMESPACE_BEGIN



ElemEmpty::ElemEmpty(
			StylesheetConstructionContext&	constructionContext,
			Stylesheet&						stylesheetTree,
			int								lineNumber,
			int								columnNumber,
			const XalanDOMString*			elementName) :
	ElemTemplateElement(constructionContext,
						stylesheetTree,
						StylesheetConstructionContext::ELEMNAME_UNDEFINED,
						XalanDOMString(),
						lineNumber,
						columnNumber),
	m_elementName(elementName)
{
}
Example #12
0
XalanDOMString
ExtensionNSHandler::getScriptString(const XalanElement&		/* elem */)
{
	return XalanDOMString();
}
Example #13
0
     */
    int
    destroyParsedSource(const XalanParsedSource*    theParsedSource);

    /**
     * Create a document builder.  Using the document builder, you
     * can construct a document using SAX2 interfaces.  The XalanTransformer
     * instance owns the document builder and will delete it when the
     * XalanTransformer instance goes out of scope, or you explicitly call
     * destroyDocumentBuilder().  You must not delete the instance yourself.
     *
     * @param theURI The base URI for the document instance.
     * @return  a pointer to a XalanDocumentBuilder instance or 0 for failure.
     */
    XalanDocumentBuilder*
    createDocumentBuilder(const XalanDOMString&     theURI = XalanDOMString(XalanMemMgrs::getDummyMemMgr()));

    /**
     * Destroy a document builder created by a previous call to createDocumentBuilder().
     * Passing a pointer that is not created by a call to createDocumentBuilder() can
     * result in undefined behavior.
     *
     * @param theDocumentBuilder The document builder to destroy.
     */
    void
    destroyDocumentBuilder(XalanDocumentBuilder*    theDocumentBuilder);

    /**
     * Install an external function in the local space.
     *
     * @param theNamespace The namespace for the functionl
{
public:

	typedef AttributeVectorTypeDecl				        AttributeVectorType;
	typedef XalanMap<const XalanDOMString*,
					AttributeVectorType>				NamespacesMapType;

	/**
	 * Constructor.
	 *
	 * @param theDocument The XalanDocument instance to use for namespace bindings.
	 * @param theURI The base URI for the instance.  This is rarely needed, but can be provided if the URI for the XalanDocument instance is known.
	 */
	XalanDocumentPrefixResolver(
			const XalanDocument*	theDocument,
			const XalanDOMString&	theURI = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
            MemoryManagerType&      theManager XALAN_DEFAULT_MEMMGR);

	virtual
	~XalanDocumentPrefixResolver();


	virtual const XalanDOMString*
	getNamespaceForPrefix(const XalanDOMString&		prefix) const;

	virtual const XalanDOMString&
	getURI() const;

	/**
	 * A utility class to walk the XalanDocument instance and look for attribute nodes that declare namespaces.
	 */
Example #15
0
int
runTests(
			int		argc,
			char*	argv[])
{
	// Just hoist everything...
	XALAN_CPP_NAMESPACE_USE

	MemoryManagerType& theManager = XalanMemMgrs::getDefaultXercesMemMgr();

	XalanFileUtility	h(theManager);

	// Set the program help string,  then get the command line parameters.
	//
	setHelp(h);

	bool setGold = false;

	const XalanDOMString	processorType(XALAN_STATIC_UCODE_STRING("XalanC"));

	if (h.getParams(argc, argv, "PERFT-RESULTS", setGold) == true)
	{
		XalanTransformer xalan;

		// Generate Unique Run id and processor info
		XalanDOMString UniqRunid;
		h.generateUniqRunid(UniqRunid);


		// Defined basic constants for file manipulation and open results file
		const XalanDOMString  resultFilePrefix("cpp");
		XalanDOMString  resultsFile= h.args.output;
		resultsFile += resultFilePrefix;
		resultsFile += UniqRunid;
		resultsFile += XalanFileUtility::s_xmlSuffix;


		XalanXMLFileReporter	logFile(theManager, resultsFile);
		logFile.logTestFileInit("Performance Testing - Reports various performance metrics using the Transformer");

		// Get the list of sub-directories below "base" and iterate through them
		bool foundDir = false;		// Flag indicates directory found. Used in conjunction with -sub cmd-line arg.

		typedef XalanFileUtility::FileNameVectorType		FileNameVectorType;

		FileNameVectorType dirs;
		h.getDirectoryNames(h.args.base, dirs);

		for(FileNameVectorType::size_type	j = 0; j < dirs.size(); j++)
		{
			// Run specific category of files from given directory
			if (length(h.args.sub) > 0 && !equals(dirs[j], h.args.sub))
			{
				continue;
			}

			cout << "Processing files in Directory: " << dirs[j] << endl;

			// Check that output directory is there.
			XalanDOMString  theOutputDir = h.args.output;
			theOutputDir += dirs[j];
			h.checkAndCreateDir(theOutputDir);

					
			// Indicate that directory was processed and get test files from the directory
			foundDir = true;
			FileNameVectorType files;
			h.getTestFileNames(h.args.base, dirs[j], false, files);
			XalanDOMString logEntry;
			logEntry = "Performance Directory: ";
			logEntry += dirs[j];
			logFile.logTestCaseInit(logEntry);

			const long	iterCount = h.args.iters;

			for(FileNameVectorType::size_type i = 0; i < files.size(); i++)
			{
				// Define  variables used for timing and reporting ...
				clock_t startTime, endTime, accmTime, avgEtoe;
				double timeinMilliseconds = 0, theAverage =0;
				int transformResult = 0;

				typedef XalanXMLFileReporter::Hashtable	Hashtable;

				Hashtable attrs(theManager);

				attrs.insert(Hashtable::value_type(XalanDOMString("idref"), files[i]));
				attrs.insert(Hashtable::value_type(XalanDOMString("UniqRunid"),UniqRunid));
				attrs.insert(Hashtable::value_type(XalanDOMString("processor"),processorType));
				logFile.addMetricToAttrs("Iterations",iterCount, attrs);
								
				if (h.args.skip)
				{
					if (checkForExclusion(files[i]))
						continue;
				}

				XalanDOMString  theXSLFile = h.args.base;
				theXSLFile += dirs[j];
				theXSLFile += XalanFileUtility::s_pathSep;
				theXSLFile += files[i];

				XalanDOMString  theXMLFile; 
				h.generateFileName(theXSLFile,"xml", theXMLFile);

				XalanDOMString  outbase = h.args.output;
				outbase += dirs[j];
				outbase += XalanFileUtility::s_pathSep;
				outbase += files[i]; 
				XalanDOMString  theOutputFile;
				h.generateFileName(outbase, "out", theOutputFile);

				const XSLTInputSource	xslInputSource(theXSLFile);
				const XSLTInputSource	xmlInputSource(theXMLFile);
				const XSLTResultTarget	theResultTarget(theOutputFile);

				attrs.insert(Hashtable::value_type(XalanDOMString("href"), theXSLFile));
				cout << endl << files[i] << endl;

				// Time the parsing(compile) of the XSL stylesheet and report the results..
				//
				startTime = clock();
				const XalanCompiledStylesheet*	compiledSS = 0;
				xalan.compileStylesheet(xslInputSource, compiledSS);
				endTime = clock();

				if (compiledSS == 0)
				{
					continue;
				}

				timeinMilliseconds = calculateElapsedTime(startTime, endTime);
				cout << "   XSL: " << timeinMilliseconds << " milliseconds, Parse" << endl;
				logFile.addMetricToAttrs("parsexsl",timeinMilliseconds, attrs);	

				// Time the parsing of the input XML and report the results..
				//
				startTime = clock();
				const XalanParsedSource*	parsedSource = 0;
				xalan.parseSource(xmlInputSource, parsedSource);
				endTime = clock();

				if (parsedSource == 0)
				{
					continue;
				}

				timeinMilliseconds = calculateElapsedTime(startTime, endTime);
				cout << "   XML: " << timeinMilliseconds << " milliseconds, Parse" <<endl;
				logFile.addMetricToAttrs("parsexml",timeinMilliseconds, attrs);

				// Perform One transform using parsed stylesheet and unparsed xml source, report results...
				// 
				startTime = clock();
					transformResult = xalan.transform(xmlInputSource, compiledSS, theResultTarget);
				endTime = clock();
				if(!transformResult)
				{
					timeinMilliseconds = calculateElapsedTime(startTime, endTime);
					cout << endl << "   One: " << timeinMilliseconds << " w/Parsed XSL." << endl;
					logFile.addMetricToAttrs("single", timeinMilliseconds, attrs);	
				}
				else
				{
					cout << xalan.getLastError();
					return -1;
				}

				// Do One eTOe transform with no pre parsing of either xsl or xml files.
				// And output metrics to console and result log
				startTime = clock();
					transformResult = xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
				endTime = clock();
				if(!transformResult)
				{
					timeinMilliseconds = calculateElapsedTime(startTime, endTime);
					cout << "   One: " << timeinMilliseconds << " eTOe." << endl;
					logFile.addMetricToAttrs("etoe", timeinMilliseconds, attrs);	
				}
				else
				{
					cout << xalan.getLastError();
					return -1;
				}


				// Perform multiple transforms and calculate the average time ..
				// These are done 3 different ways.
				//
				// FIRST: Parsed XSL Stylesheet and Parsed XML Source.
				//
				accmTime = 0;
				for(int j = 0; j < iterCount; ++j)
				{	
					startTime = clock();
						transformResult = xalan.transform(*parsedSource, compiledSS, theResultTarget);
					endTime = clock();
					
					accmTime += endTime - startTime;
				}

				theAverage = calculateAvgTime(accmTime, iterCount); 
				cout << endl << "   Avg: " << theAverage << " for " << iterCount << " iter's w/Parsed files" << endl;
				logFile.addMetricToAttrs("avgparsedxml",theAverage, attrs);
				

				// SECOND: Parsed Stylesheet and UnParsed XML Source.
				// This is currently how the XalanJ 2.0 is performing transforms
				//
				accmTime = 0;
				for(int k = 0; k < iterCount; ++k)
				{
					startTime = clock();
						transformResult = xalan.transform(xmlInputSource, compiledSS, theResultTarget);
					endTime = clock();
					
					accmTime += endTime - startTime;						
				}
				theAverage = calculateAvgTime(accmTime, iterCount);
				cout << "   Avg: " << theAverage << " for " << iterCount << " iter's w/UnParsed XML" << endl;
				logFile.addMetricToAttrs("avgunparsedxml",theAverage, attrs);


				// THIRD: Neither Stylesheet nor XML Source are parsed.
				// Perform multiple etoe transforms and calculate the average ...
				//
				avgEtoe = 0;
				for(int jj = 0; jj < iterCount; ++jj)
				{	
					startTime = clock();
						transformResult = xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
					endTime = clock();
					
					avgEtoe += endTime - startTime;						
				}
				theAverage = calculateAvgTime(avgEtoe,iterCount);

				// Output average transform time to console and result log
				cout << "   Avg: " << theAverage << " for " << iterCount << " iter's of eToe" << endl;
				logFile.addMetricToAttrs("avgetoe",theAverage, attrs);

				logFile.logElementWAttrs(10, "perf", attrs, "xxx");

				xalan.destroyParsedSource(parsedSource);
				xalan.destroyStylesheet(compiledSS);

			}

			logEntry = "Performance Directory: ";
			logEntry += dirs[j];
 			logFile.logTestCaseClose(logEntry, XalanDOMString("Done"));
		}

		// Check to see if -sub cmd-line directory was processed correctly.
		if (!foundDir)
		{
			cout << "Specified test directory: \"" << c_str(TranscodeToLocalCodePage(h.args.sub)) << "\" not found" << endl;
		}

		h.reportPassFail(logFile, UniqRunid);
		logFile.logTestFileClose("Performance", "Done");
		logFile.close();
	}

	return 0;
}
Example #16
0
XSECXPathNodeList * TXFMXPathFilter::evaluateSingleExpr(DSIGXPathFilterExpr *expr) {

	// Have a single expression that we wish to find the resultant nodeset
	// for

	XSECXPathNodeList addedNodes;
	setXPathNS(document, expr->mp_NSMap, addedNodes, mp_formatter, mp_nse);

	XPathProcessorImpl	xppi;					// The processor
	XercesParserLiaison xpl;
#if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10
	XercesDOMSupport	xds(xpl);
#else
	XercesDOMSupport	xds;
#endif
	XPathEvaluator		xpe;
	XPathFactoryDefault xpf;
	XPathConstructionContextDefault xpcc;

	XalanDocument		* xd;
	XalanNode			* contextNode;

	// Xalan can throw exceptions in all functions, so do one broad catch point.

	try {
	
		// Map to Xalan
		xd = xpl.createDocument(document);

		// For performing mapping
		XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd);
		XercesWrapperNavigator xwn(xdw);

		// Map the "here" node

		XalanNode * hereNode = NULL;

		hereNode = xwn.mapNode(expr->mp_xpathFilterNode);

		if (hereNode == NULL) {

			hereNode = findHereNodeFromXalan(&xwn, xd, expr->mp_exprTextNode);

			if (hereNode == NULL) {

				throw XSECException(XSECException::XPathFilterError,
				   "Unable to find here node in Xalan Wrapper map");
			}

		}

		// Now work out what we have to set up in the new processing

		XalanDOMString cd;		// For XPath Filter, the root is always the context node

		cd = XalanDOMString("/");		// Root node

		// The context node is the "root" node
		contextNode =
			xpe.selectSingleNode(
			xds,
			xd,
			cd.c_str(),
			xd->getDocumentElement());

		XPathEnvSupportDefault xpesd;
		XObjectFactoryDefault			xof;
		XPathExecutionContextDefault	xpec(xpesd, xds, xof);

		ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds);

		// Work around the fact that the XPath implementation is designed for XSLT, so does
		// not allow here() as a NCName.

		// THIS IS A KLUDGE AND SHOULD BE DONE BETTER

		int offset = 0;
		safeBuffer k(KLUDGE_PREFIX);
		k.sbStrcatIn(":");

		// Map the expression into a local code page string (silly - should be XMLCh)
		safeBuffer exprSB;
		exprSB << (*mp_formatter << expr->m_expr.rawXMLChBuffer());

		offset = exprSB.sbStrstr("here()");

		while (offset >= 0) {

			if (offset == 0 || offset == 1 || 
				(!(exprSB[offset - 1] == ':' && exprSB[offset - 2] != ':') &&
				separator(exprSB[offset - 1]))) {

				exprSB.sbStrinsIn(k.rawCharBuffer(), offset);

			}

			offset = exprSB.sbOffsetStrstr("here()", offset + 11);

		}

		// Install the External function in the Environment handler

		if (hereNode != NULL) {

			xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode));

		}

		XPath * xp = xpf.create();

		XalanDOMString Xexpr((char *) exprSB.rawBuffer());
		xppi.initXPath(*xp, xpcc, Xexpr, pr);
		
		// Now resolve

		XObjectPtr xObj = xp->execute(contextNode, pr, xpec);

		// Now map to a list that others can use (naieve list at this time)

		const NodeRefListBase&	lst = xObj->nodeset();
		
		int size = (int) lst.getLength();
		const DOMNode *item;
		
		XSECXPathNodeList * ret;
		XSECnew(ret, XSECXPathNodeList);
		Janitor<XSECXPathNodeList> j_ret(ret);

		for (int i = 0; i < size; ++ i) {

			if (lst.item(i) == xd)
				ret->addNode(document);
			else {
				item = xwn.mapNode(lst.item(i));
				ret->addNode(item);
			}
		}

		xpesd.uninstallExternalFunctionGlobal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"));

		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);

		j_ret.release();
		return ret;

	}

	catch (XSLException &e) {

		safeBuffer msg;

		// Whatever happens - fix any changes to the original document
		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);
	
		// Collate the exception message into an XSEC message.		
		msg.sbTranscodeIn("Xalan Exception : ");
#if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING)
		msg.sbXMLChCat(e.getType().c_str());
#else
		msg.sbXMLChCat(e.getType());
#endif
		msg.sbXMLChCat(" caught.  Message : ");
		msg.sbXMLChCat(e.getMessage().c_str());

		throw XSECException(XSECException::XPathFilterError,
			msg.rawXMLChBuffer());

	}

	catch (...) {
		clearXPathNS(document, addedNodes, mp_formatter, mp_nse);
		throw;
	}

	return NULL;
}
Example #17
0
     */
    int
    destroyParsedSource(const XalanParsedSource*	theParsedSource);

    /**
     * Create a document builder.  Using the document builder, you
     * can construct a document using SAX2 interfaces.	The XalanTransformer
     * instance owns the document builder and will delete it when the
     * XalanTransformer instance goes out of scope, or you explicitly call
     * destroyDocumentBuilder().  You must not delete the instance yourself.
     *
     * @param theURI The base URI for the document instance.
     * @return	a pointer to a XalanDocumentBuilder instance or 0 for failure.
     */
    XalanDocumentBuilder*
    createDocumentBuilder(const XalanDOMString&		theURI = XalanDOMString());

    /**
     * Destroy a document builder created by a previous call to createDocumentBuilder().
     * Passing a pointer that is not created by a call to createDocumentBuilder() can
     * result in undefined behavior.
     *
     * @param theDocumentBuilder The document builder to destroy.
     */
    void
    destroyDocumentBuilder(XalanDocumentBuilder*	theDocumentBuilder);

    /**
     * Install an external function in the local space.
     *
     * @param theNamespace The namespace for the functionl
Example #18
0
void TXFMXPath::evaluateExpr(DOMNode *h, safeBuffer inexpr) {

	// Temporarily add any necessary name spaces into the document

	XSECXPathNodeList addedNodes;
	setXPathNS(document, XPathAtts, addedNodes, formatter, mp_nse);

	XPathProcessorImpl	xppi;					// The processor
	XercesParserLiaison xpl;
#if XALAN_VERSION_MAJOR == 1 && XALAN_VERSION_MINOR > 10
	XercesDOMSupport	xds(xpl);
#else
	XercesDOMSupport	xds;
#endif
	XPathEvaluator		xpe;
	XPathFactoryDefault xpf;
	XPathConstructionContextDefault xpcc;

	XalanDocument		* xd;
	XalanNode			* contextNode;

	// Xalan can throw exceptions in all functions, so do one broad catch point.

	try {
	
		// Map to Xalan
		xd = xpl.createDocument(document);

		// For performing mapping
		XercesDocumentWrapper *xdw = xpl.mapDocumentToWrapper(xd);
		XercesWrapperNavigator xwn(xdw);

		// Map the "here" node - but only if part of current document

		XalanNode * hereNode = NULL;

		if (h->getOwnerDocument() == document) {
			
			hereNode = xwn.mapNode(h);

			if (hereNode == NULL) {

				hereNode = findHereNodeFromXalan(&xwn, xd, h);

				if (hereNode == NULL) {

					throw XSECException(XSECException::XPathError,
					   "Unable to find here node in Xalan Wrapper map");
				}

			}
		}

		// Now work out what we have to set up in the new processing

		TXFMBase::nodeType inputType = input->getNodeType();

		XalanDOMString cd;		// For the moment assume the root is the context

		const XalanDOMChar * cexpr;

		safeBuffer contextExpr;

		switch (inputType) {

		case DOM_NODE_DOCUMENT :
		case DOM_NODE_XPATH_NODESET :
			// do XPath over the whole document and, if the input was an 
			// XPath Nodeset, then later intersect the result with the input nodelist			
			cd = XalanDOMString("/");		// Root node
			cexpr = cd.c_str();

			// The context node is the "root" node
			contextNode =
				xpe.selectSingleNode(
				xds,
				xd,
				cexpr,
				xd->getDocumentElement());

			break;

		case DOM_NODE_DOCUMENT_FRAGMENT :
			{

				// Need to map the DOM_Node that we are given from the input to the appropriate XalanNode

				// Create the XPath expression to find the node

				if (input->getFragmentId() != NULL) {

					contextExpr.sbTranscodeIn("//descendant-or-self::node()[attribute::Id='");
					contextExpr.sbXMLChCat(input->getFragmentId());
					contextExpr.sbXMLChCat("']");

					// Map the node

					contextNode = 
						xpe.selectSingleNode(
						xds,
						xd,
						contextExpr.rawXMLChBuffer(), //XalanDOMString((char *) contextExpr.rawBuffer()).c_str(), 
						xd->getDocumentElement());


					if (contextNode == NULL) {
						// Last Ditch
						contextNode = xwn.mapNode(input->getFragmentNode());

					}

				}
				else
					contextNode = xwn.mapNode(input->getFragmentNode());

				if (contextNode == NULL) {

					// Something wrong
					throw XSECException(XSECException::XPathError, "Error mapping context node");

				}

				break;
			}

		default :

			throw XSECException(XSECException::XPathError);	// Should never get here

		}

		safeBuffer str;
		XPathEnvSupportDefault xpesd;
		XObjectFactoryDefault			xof;
		XPathExecutionContextDefault	xpec(xpesd, xds, xof);

		ElementPrefixResolverProxy pr(xd->getDocumentElement(), xpesd, xds);

		// Work around the fact that the XPath implementation is designed for XSLT, so does
		// not allow here() as a NCName.

		// THIS IS A KLUDGE AND SHOULD BE DONE BETTER

		int offset = 0;
		safeBuffer k(KLUDGE_PREFIX);
		k.sbStrcatIn(":");

		offset = inexpr.sbStrstr("here()");

		while (offset >= 0) {

			if (offset == 0 || offset == 1 || 
				(!(inexpr[offset - 1] == ':' && inexpr[offset - 2] != ':') &&
				separator(inexpr[offset - 1]))) {

				inexpr.sbStrinsIn(k.rawCharBuffer(), offset);

			}

			offset = inexpr.sbOffsetStrstr("here()", offset + 11);

		}

		// Install the External function in the Environment handler

		if (hereNode != NULL) {

			xpesd.installExternalFunctionLocal(XalanDOMString(URI_ID_DSIG), XalanDOMString("here"), DSIGXPathHere(hereNode));

		}

		str.sbStrcpyIn("(descendant-or-self::node() | descendant-or-self::node()/attribute::* | descendant-or-self::node()/namespace::*)[");
		str.sbStrcatIn(inexpr);
		str.sbStrcatIn("]");

		XPath * xp = xpf.create();

		XalanDOMString Xexpr((char *) str.rawBuffer());
		xppi.initXPath(*xp, xpcc, Xexpr, pr);
		
		// Now resolve

		XObjectPtr xObj = xp->execute(contextNode, pr, xpec);

		// Now map to a list that others can use (naieve list at this time)

		const NodeRefListBase&	lst = xObj->nodeset();
		
		int size = (int) lst.getLength();
		const DOMNode *item;
		
		for (int i = 0; i < size; ++ i) {

			if (lst.item(i) == xd)
				m_XPathMap.addNode(document);
			else {
				item = xwn.mapNode(lst.item(i));
				m_XPathMap.addNode(item);
			}
		}

		if (inputType == DOM_NODE_XPATH_NODESET) {
			//the input list was a XPATH nodeset, so we must intersect the 
			// results of the XPath processing done above with the input nodeset
			m_XPathMap.intersect(input->getXPathNodeList());
		}
	}

	catch (XSLException &e) {

		safeBuffer msg;

		// Whatever happens - fix any changes to the original document
		clearXPathNS(document, addedNodes, formatter, mp_nse);
	
		// Collate the exception message into an XSEC message.		
		msg.sbTranscodeIn("Xalan Exception : ");
#if defined (XSEC_XSLEXCEPTION_RETURNS_DOMSTRING)
		msg.sbXMLChCat(e.getType().c_str());
#else
		msg.sbXMLChCat(e.getType());
#endif
		msg.sbXMLChCat(" caught.  Message : ");
		msg.sbXMLChCat(e.getMessage().c_str());

		throw XSECException(XSECException::XPathError,
			msg.rawXMLChBuffer());
	}
	
	clearXPathNS(document, addedNodes, formatter, mp_nse);

}
Example #19
0
  * @param mediaType         media type (MIME content type) of the data
  * @param doctypeSystem     system identifier to be used in the document
  *                          type declaration
  * @param doctypePublic     public identifier to be used in the document
  *                          type declaration
  * @param xmlDecl           true if the XSLT processor should output an XML
  *                          declaration
  * @param standalone        true if the XSLT processor should output a
  *                          standalone document declaration
  *
  * @param format            should be used only by derived classes.
  * @param fBufferData       If true, data will be buffered in the formatter
  */
 FormatterToXML(
         Writer&                 writer,
         const XalanDOMString&   version = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         bool                    doIndent = false,
         int                     indent = eDefaultIndentAmount,
         const XalanDOMString&   encoding = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         const XalanDOMString&   mediaType = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         const XalanDOMString&   doctypeSystem = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         const XalanDOMString&   doctypePublic = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         bool                    xmlDecl = true,
         const XalanDOMString&   standalone = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
         eFormat                 format = OUTPUT_METHOD_XML,
         bool                    fBufferData = true,
         MemoryManagerType&      theManager XALAN_DEFAULT_MEMMGR);
 
 static FormatterToXML*
 create(
         MemoryManagerType&      theManager,
Example #20
0
 FileResult(const XalanDOMString & fileName = XalanDOMString(""))
 {
     resultTarget.setFileName(fileName);
 }
Example #21
0
int CXslTransform::setStringParameter(const char *pszName, const char *pszString)
{
    m_XalanTransformer.setStylesheetParam(XalanDOMString(pszName), XalanDOMString(StringBuffer("'").append(pszString).append("'").str()));
    return 0;
}
	// These interfaces are inherited from XMLParserLiaison...

	virtual void
	reset();

	virtual ExecutionContext*
	getExecutionContext() const;

	virtual void
	setExecutionContext(ExecutionContext&	theContext);

	virtual XalanDocument*
	parseXMLStream(
			const InputSourceType&	reader,
			const XalanDOMString&	identifier = XalanDOMString(XalanMemMgrs::getDummyMemMgr()));

	virtual void
	parseXMLStream(
			const InputSourceType&	inputSource,
			DocumentHandlerType&	handler,
			const XalanDOMString&	identifier = XalanDOMString(XalanMemMgrs::getDummyMemMgr()));

	virtual void
	destroyDocument(XalanDocument*	theDocument);

	virtual int
	getIndent() const;

	virtual void
	setIndent(int	i);
Example #23
0
int CXslTransform::setParameter(const char *pszName, const char *pszExpression)
{
    m_XalanTransformer.setStylesheetParam(XalanDOMString(pszName), XalanDOMString(pszExpression));
    return 0;
}
Example #24
0
	/**
	 * Constructor
	 * 
	 * @param theMessage message to write when exception thrown
	 * @param theURI the URI of the related document, if known
	 * @param theLineNumber the line number of the related document, or -1 if not known
	 * @param theColumnNumber the column number of the related document, or -1 if not known
	 * @param theType type of exception, default is "XPathParserException"
	 */
	XPathParserException(
			const XalanDOMString&	theMessage,
			const XalanDOMString&	theURI,
			int						theLineNumber,
			int						theColumnNumber,
			const XalanDOMString&	theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathParserException")));

	/**
	 * Constructor
	 * 
	 * @param theLocator The locator instance for error reporting.
	 * @param theMessage message to write when exception thrown
	 * @param theType type of exception, default is "XPathParserException"
	 */
	XPathParserException(
			const LocatorType&		theLocator,
			const XalanDOMString&	theMessage,
			const XalanDOMString&	theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathParserException")));

	/**
	 * Constructor
Example #25
0
/* Parse a URI into component parts.
   Essentially implements the regex ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
 */
void XalanParsedURI::parse(
    const XalanDOMChar*         uriString,
    XalanDOMString::size_type   uriStringLen
)
{
    XalanDOMString::size_type index = 0;
    
    // Clear the components present mask
    m_defined = 0;

    // Scheme portion
    while (index < uriStringLen && 
                uriString[index] != XalanUnicode::charColon && 
                uriString[index] != XalanUnicode::charSolidus && 
                uriString[index] != XalanUnicode::charQuestionMark && 
                uriString[index] != XalanUnicode::charNumberSign)
    {
        ++index;
    }
    
    if (index > 0 && uriString[index] == XalanUnicode::charColon)
    {
        m_scheme = XalanDOMString(uriString, getMemoryManager(), index);
        ++index;
        m_defined |= d_scheme;
    }
    else
    {
        index = 0;
        m_scheme.clear();
    }

    // Authority portion
    if (index < uriStringLen - 1 &&
        uriString[index] == XalanUnicode::charSolidus && 
        uriString[index+1] == XalanUnicode::charSolidus) 
    {
        index += 2;
        XalanDOMString::size_type authority = index;

        while (index < uriStringLen &&
                uriString[index] != XalanUnicode::charSolidus && 
                uriString[index] != XalanUnicode::charQuestionMark && 
                uriString[index] != XalanUnicode::charNumberSign)
        {
            ++index;
        }
        if (index != authority)
        {
            m_authority = XalanDOMString(uriString + authority, getMemoryManager(), index - authority);
            m_defined |= d_authority;
        }
        else
            m_authority.clear();
    }
    else
    {
        m_authority.clear();
    }

    // Path portion
    XalanDOMString::size_type path = index;
    while (index < uriStringLen &&
            uriString[index] != XalanUnicode::charQuestionMark && 
            uriString[index] != XalanUnicode::charNumberSign)
    {
        ++index;
    }
    m_path = XalanDOMString(uriString + path,getMemoryManager(), index - path);

    // Query portion
    if (index < uriStringLen && uriString[index] == XalanUnicode::charQuestionMark)
    {
        ++index;
        XalanDOMString::size_type query = index;

        while (index < uriStringLen &&
                uriString[index] != XalanUnicode::charNumberSign)
        {
            ++index;
        }
        m_query = XalanDOMString(uriString + query,getMemoryManager(), index - query);
        m_defined |= d_query;
    }
    else
    {
        m_query.clear();
    }

    // Fragment portion
    if (index < uriStringLen && uriString[index] == XalanUnicode::charNumberSign)
    {
        ++index;
        m_fragment = XalanDOMString(uriString + index, getMemoryManager(), uriStringLen - index);
        m_defined |= d_fragment;
    }
    else
    {
        m_fragment.clear();
    }
}
Example #26
0
#if defined(XALAN_BUILD_DEPRECATED_DOM_BRIDGE)
	/**
	 * Constructor
	 *
	 * @param theDocument The Xerces document to wrap
	 * @param theParserLiaison The XercesParserLiaison instance that will own the document.
	 * @param theDOMSupport The XercesDOMSupport instance
	 * @param theURI The URI of the document, if any.
	 *
	 * @deprecated This constructor is deprecated.
	 */
	XercesDOMWrapperParsedSource(
			const DOM_Document_Type&	theDocument,
			XercesParserLiaison&		theParserLiaison,
			XercesDOMSupport&			theDOMSupport,
			const XalanDOMString&		theURI = XalanDOMString());
#endif

	/**
	 * Constructor
	 *
	 * @param theDocument The Xerces document to wrap
	 * @param theParserLiaison The XercesParserLiaison instance that will own the document.
	 * @param theDOMSupport The XercesDOMSupport instance
	 * @param theURI The URI of the document, if any.
	 */
	XercesDOMWrapperParsedSource(
			const DOMDocument_Type*		theDocument,
			XercesParserLiaison&		theParserLiaison,
			XercesDOMSupport&			theDOMSupport,
			const XalanDOMString&		theURI = XalanDOMString());