/*this method is only used for setting special character */ XmlNode addTextForAcctOwner(char *value) { XMLTransService::Codes failReason; XMLCh* xmlChars = new XMLCh[512]; unsigned int eaten = 0; unsigned char* charSizes = new unsigned char[512]; if (value != NULL) { try { XMLTranscoder* t = XMLPlatformUtils::fgTransService->makeNewTranscoderFor( "UTF-8", failReason, 16 * 1024); t->transcodeFrom((XMLByte*) value, 512, xmlChars, 512, eaten, charSizes); node->setTextContent(xmlChars); } catch (...) { XMLCh *tempStr = XMLString::transcode(value); node->setTextContent(tempStr); XMLString::release(&tempStr); } } delete xmlChars; delete charSizes; return XmlNode(node,doc); }
int DocumentParser::FetchContent(const VXIchar * uri, const VXIMapHolder & properties, VXIMapHolder & fetchInfo, VXIinetInterface * inet, SimpleLogger & log, const vxistring & encoding, vxistring & content) { const VXIbyte * buffer; VXIulong bufSize; vxistring docURL; // (1) Retrieve the URI. switch (DocumentParser::FetchBuffer(uri, properties, fetchInfo, inet, log, buffer, bufSize, docURL, 0, NULL)) { case -1: // Out of memory? return -1; case 0: // Success break; case 2: // Unable to open URI return 2; case 3: // Unable to read from URI return 3; case 1: // Invalid parameter default: return 1; } // (2) Create a transcoder for the requested type. VXIcharToXMLCh encName(encoding.c_str()); XMLTransService::Codes failReason; XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(encName.c_str(), failReason, 8*1064 ,XMLPlatformUtils::fgMemoryManager); if (transcoder == NULL) return 4; // (3) Allocate memory for the conversion. XMLCh * convertedString = new XMLCh[bufSize+1]; unsigned char* charSizes = new unsigned char[bufSize]; if (convertedString == NULL || charSizes == NULL) { delete[] convertedString; delete[] charSizes; return -1; } // (4) Transcode the values into our string. unsigned int bytesEaten; unsigned int charsDone = transcoder->transcodeFrom(buffer, bufSize, convertedString, bufSize, bytesEaten, charSizes); // (5) Finally convert from XMLCh to VXIchar. convertedString[charsDone] = '\0'; // Add terminator. XMLChToVXIchar result(convertedString); // (6) Done. Release memory. content = result.c_str(); delete[] convertedString; delete[] charSizes; DocumentParser::ReleaseBuffer(buffer); delete transcoder; return 0; }
DOMText * XIncludeUtils::doXIncludeTEXTFileDOM(const XMLCh *href, const XMLCh *relativeHref, const XMLCh *encoding, DOMNode *includeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){ if (encoding == NULL) /* "UTF-8" is stipulated default by spec */ encoding = XMLUni::fgUTF8EncodingString; XMLTransService::Codes failReason; XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(encoding, failReason, 16*1024); Janitor<XMLTranscoder> janTranscoder(transcoder); if (failReason){ XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href); return NULL; } //addDocumentURIToCurrentInclusionHistoryStack(href); InputSource* is=NULL; Janitor<InputSource> janIS(is); if(entityResolver) { XMLResourceIdentifier resIdentifier(XMLResourceIdentifier::ExternalEntity, relativeHref, NULL, NULL, includeNode->getBaseURI()); is=entityResolver->resolveEntity(&resIdentifier); janIS.reset(is); } if(janIS.get()==NULL) janIS.reset(new URLInputSource(href)); if(janIS.get()==NULL) { XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href); return NULL; } BinInputStream* stream=janIS.get()->makeStream(); if(stream==NULL) { XIncludeUtils::reportError(parsedDocument, XMLErrs::XIncludeCannotOpenFile, href, href); return NULL; } Janitor<BinInputStream> janStream(stream); const XMLSize_t maxToRead=16*1024; XMLByte* buffer=(XMLByte*)XMLPlatformUtils::fgMemoryManager->allocate(maxToRead * sizeof(XMLByte)); if(buffer==NULL) throw OutOfMemoryException(); ArrayJanitor<XMLByte> janBuffer(buffer, XMLPlatformUtils::fgMemoryManager); XMLCh* xmlChars=(XMLCh*)XMLPlatformUtils::fgMemoryManager->allocate(maxToRead*2*sizeof(XMLCh)); if(xmlChars==NULL) throw OutOfMemoryException(); ArrayJanitor<XMLCh> janUniBuffer(xmlChars, XMLPlatformUtils::fgMemoryManager); unsigned char *charSizes = (unsigned char *)XMLPlatformUtils::fgMemoryManager->allocate(maxToRead * sizeof(unsigned char)); if(charSizes==NULL) throw OutOfMemoryException(); ArrayJanitor<unsigned char> janCharSizes(charSizes, XMLPlatformUtils::fgMemoryManager); XMLSize_t nRead, nOffset=0; XMLBuffer repository; while((nRead=stream->readBytes(buffer+nOffset, maxToRead-nOffset))>0){ XMLSize_t bytesEaten=0; XMLSize_t nCount = transcoder->transcodeFrom(buffer, nRead, xmlChars, maxToRead*2, bytesEaten, charSizes); repository.append(xmlChars, nCount); if(bytesEaten<nRead) { nOffset=nRead-bytesEaten; memmove(buffer, buffer+bytesEaten, nRead-bytesEaten); } } return parsedDocument->createTextNode(repository.getRawBuffer()); }