XMLTranscoder* XMLTransService::makeNewTranscoderFor( XMLRecognizer::Encodings encodingEnum , XMLTransService::Codes& resValue , const unsigned int blockSize , MemoryManager* const manager) { // // We can only make transcoder if the passed encodingEnum is under this range // if (encodingEnum < XMLRecognizer::Encodings_Min || encodingEnum > XMLRecognizer::Encodings_Max) { resValue = XMLTransService::InternalFailure; return 0; } ENameMap* ourMapping = gMappingsRecognizer->elementAt(encodingEnum); // If we found it, then call the factory method for it if (ourMapping) { XMLTranscoder* temp = ourMapping->makeNew(blockSize, manager); resValue = temp ? XMLTransService::Ok : XMLTransService::InternalFailure; return temp; } else { XMLTranscoder* temp = makeNewXMLTranscoder(XMLRecognizer::nameForEncoding(encodingEnum, manager), resValue, blockSize, manager); // if successful, set resValue to OK // if failed, the makeNewXMLTranscoder has already set the proper failing resValue if (temp) resValue = XMLTransService::Ok; return temp; } }
// --------------------------------------------------------------------------- // MacOSTransService: The protected virtual transcoding service API // --------------------------------------------------------------------------- XMLTranscoder* MacOSUnicodeConverter::makeNewXMLTranscoder(const XMLCh* const encodingName , XMLTransService::Codes& resValue , const XMLSize_t blockSize , MemoryManager* const manager) { XMLTranscoder* result = NULL; resValue = XMLTransService::Ok; TextToUnicodeInfo textToUnicodeInfo = NULL; UnicodeToTextInfo unicodeToTextInfo = NULL; // Map the encoding to a Mac OS Encoding value Str255 pasEncodingName; char cEncodingName[256]; ConvertWideToNarrow(encodingName, cEncodingName, sizeof(cEncodingName)); CopyCStringToPascal(cEncodingName, pasEncodingName); TextEncoding textEncoding = 0; OSStatus status = TECGetTextEncodingFromInternetName ( &textEncoding, pasEncodingName); // Make a transcoder for that encoding if (status == noErr) result = makeNewXMLTranscoder(encodingName, resValue, blockSize, textEncoding, manager); else resValue = XMLTransService::UnsupportedEncoding; return result; }
XMLLCPTranscoder* MacOSUnicodeConverter::makeNewLCPTranscoder(MemoryManager* manager) { XMLLCPTranscoder* result = NULL; OSStatus status = noErr; // Discover the text encoding to use for the LCP TextEncoding lcpTextEncoding = discoverLCPEncoding(); // We implement the LCP transcoder in terms of the XMLTranscoder. // Create an XMLTranscoder for this encoding XMLTransService::Codes resValue; XMLTranscoder* xmlTrans = makeNewXMLTranscoder(fgMacLCPEncodingName, resValue, kTempBufCount, lcpTextEncoding, manager); if (xmlTrans) { // Pass the XMLTranscoder over to the LPC transcoder if (resValue == XMLTransService::Ok) result = new (manager) MacOSLCPTranscoder(xmlTrans, manager); else delete xmlTrans; } return result; }
XMLTranscoder* XMLTransService::makeNewTranscoderFor( const XMLCh* const encodingName , XMLTransService::Codes& resValue , const unsigned int blockSize , MemoryManager* const manager) { // // If strict IANA encoding flag is set, validate encoding name // if (gStrictIANAEncoding) { if (!EncodingValidator::instance()->isValidEncoding(encodingName)) { resValue = XMLTransService::UnsupportedEncoding; return 0; } } // // First try to find it in our list of mappings to intrinsically // supported encodings. We have to upper case the passed encoding // name because we use a hash table and we stored all our mappings // in all uppercase. // const unsigned int bufSize = 2048; XMLCh upBuf[bufSize + 1]; if (!XMLString::copyNString(upBuf, encodingName, bufSize)) { resValue = XMLTransService::InternalFailure; return 0; } XMLString::upperCase(upBuf); ENameMap* ourMapping = gMappings->get(upBuf); // If we found it, then call the factory method for it if (ourMapping) { XMLTranscoder* temp = ourMapping->makeNew(blockSize, manager); resValue = temp ? XMLTransService::Ok : XMLTransService::InternalFailure; return temp; } // // It wasn't an intrinsic and it wasn't disallowed, so pass it on // to the trans service to see if he can make anything of it. // XMLTranscoder* temp = makeNewXMLTranscoder(encodingName, resValue, blockSize, manager); // if successful, set resValue to OK // if failed, the makeNewXMLTranscoder has already set the proper failing resValue if (temp) resValue = XMLTransService::Ok; return temp; }