FAXPP_Error FaxppParserWrapper::parseInputSource(const InputSource &srcToUse, XPath2MemoryManager *m) { reset(); mm = m; // Create a BinInputStream BinInputStream *stream = srcToUse.makeStream(); if(stream == NULL) XQThrow2(XMLParseException, X("FaxppParserWrapper::parseInputSource"), X("Document not found")); inputStreams.push_back(stream); // Initialize the parse FAXPP_Error err = FAXPP_init_parse_callback(parser, binInputStreamReadCallback, stream); // Set the correct base URI if(err == NO_ERROR && srcToUse.getSystemId()) { FAXPP_Text base = { (void*)srcToUse.getSystemId(), (XMLString::stringLen(srcToUse.getSystemId()) + 1) * sizeof(XMLCh) }; err = FAXPP_set_base_uri(parser, &base); } // Force use of encoding set on InputSource (this is done by FunctionParseXML) if(err == NO_ERROR && srcToUse.getEncoding()) { FAXPP_DecodeFunction decode = FAXPP_string_to_decode(UTF8(srcToUse.getEncoding())); if(decode == 0) err = UNSUPPORTED_ENCODING; else FAXPP_set_decode(parser, decode); } #if 0 else if(stream->getContentType()) { } #endif return err; }
Sequence FunctionUnparsedText::createSequence(DynamicContext* context, int flags) const { Item::Ptr uriArg = getParamNumber(1, context)->next(context); if(uriArg.isNull()) { return Sequence(context->getMemoryManager()); } const XMLCh *uri = uriArg->asString(context); if(!XPath2Utils::isValidURI(uri, context->getMemoryManager())) XQThrow(FunctionException, X("FunctionUnparsedText::createSequence"), X("The argument to fn:unparsed-text() is not a valid URI [err:XTDE1170]")); // TBD Implement a URIResolver method for resolving unparsed text - jpcs const XMLCh *baseUri = context->getBaseURI(); InputSource *srcToUse = 0; if(context->getXMLEntityResolver()){ XMLResourceIdentifier resourceIdentifier(XMLResourceIdentifier::UnKnown, uri, 0, XMLUni::fgZeroLenString, baseUri); srcToUse = context->getXMLEntityResolver()->resolveEntity(&resourceIdentifier); } if(srcToUse == 0) { try { // Resolve the uri against the base uri XMLURL urlTmp; if(baseUri && *baseUri) { urlTmp.setURL(baseUri, uri); } else { urlTmp.setURL(uri); } srcToUse = new URLInputSource(urlTmp); } catch(const MalformedURLException &e) { } } if(srcToUse == 0) { // It's not a URL, so let's assume it's a local file name. if(baseUri && *baseUri) { AutoDeallocate<XMLCh> tmpBuf(XMLPlatformUtils::weavePaths(baseUri, uri), XMLPlatformUtils::fgMemoryManager); srcToUse = new LocalFileInputSource(tmpBuf); } else { srcToUse = new LocalFileInputSource(uri); } } Janitor<InputSource> janIS(srcToUse); if(getNumArgs() == 2) { const XMLCh *encoding = getParamNumber(2, context)->next(context)->asString(context); srcToUse->setEncoding(encoding); } XMLBuffer result; try { BinInputStream *stream = srcToUse->makeStream(); if(stream == NULL) { XMLBuffer buf; buf.set(X("Cannot read unparsed content from ")); buf.append(uri); buf.append(X(" [err:XTDE1170]")); XQThrow2(FunctionException,X("FunctionUnparsedText::createSequence"), buf.getRawBuffer()); } Janitor<BinInputStream> janStream(stream); #ifdef HAVE_GETCONTENTTYPE if(FunctionMatches::matches(stream->getContentType(), X("(text|application)/(xml|[^ +;]+\\+xml)"), X("i"))) { srcToUse->setEncoding(0); srcToUse->setEncoding(FindXMLEncoding().start(*srcToUse, context)); } #endif XPath2Utils::readSource(stream, context->getMemoryManager(), result, srcToUse->getEncoding()); } catch(XMLException &e) { XMLBuffer buf; buf.set(X("Exception reading unparsed content: ")); buf.append(e.getMessage()); buf.append(X(" [err:XTDE1190]")); XQThrow2(FunctionException,X("FunctionUnparsedText::createSequence"), buf.getRawBuffer()); } return Sequence(context->getItemFactory()->createString(result.getRawBuffer(), context), context->getMemoryManager()); }