| 20 | { |
| 21 | |
| 22 | CompressedInputSource::CompressedInputSource(const String & file_path, const String & header, MemoryManager * const manager) : |
| 23 | xercesc::InputSource(manager), |
| 24 | head_(header) |
| 25 | { |
| 26 | if (head_.size() < 2) |
| 27 | { |
| 28 | head_ = "\0\0"; |
| 29 | } |
| 30 | // |
| 31 | // If the path is relative, then complete it according to the current |
| 32 | // working directory rules of the current platform. Else, just take |
| 33 | // it as is. |
| 34 | // |
| 35 | Internal::StringManager strman; |
| 36 | auto file = strman.convert(file_path.c_str()); |
| 37 | if (xercesc::XMLPlatformUtils::isRelative(file.c_str(), manager)) |
| 38 | { |
| 39 | XMLCh * curDir = xercesc::XMLPlatformUtils::getCurrentDirectory(manager); |
| 40 | |
| 41 | XMLSize_t curDirLen = XMLString::stringLen(curDir); |
| 42 | XMLSize_t filePathLen = XMLString::stringLen(file.c_str()); |
| 43 | XMLCh * fullDir = (XMLCh *) manager->allocate |
| 44 | ( |
| 45 | (curDirLen + filePathLen + 2) * sizeof(XMLCh) |
| 46 | ); //new XMLCh [ curDirLen + filePathLen + 2]; |
| 47 | |
| 48 | XMLString::copyString(fullDir, curDir); |
| 49 | fullDir[curDirLen] = chForwardSlash; |
| 50 | XMLString::copyString(&fullDir[curDirLen + 1], file.c_str()); |
| 51 | |
| 52 | XMLPlatformUtils::removeDotSlash(fullDir, manager); |
| 53 | XMLPlatformUtils::removeDotDotSlash(fullDir, manager); |
| 54 | |
| 55 | setSystemId(fullDir); |
| 56 | |
| 57 | manager->deallocate(curDir); //delete [] curDir; |
| 58 | manager->deallocate(fullDir); //delete [] fullDir; |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | XMLCh * tmpBuf = XMLString::replicate(file.c_str(), manager); |
| 63 | XMLPlatformUtils::removeDotSlash(tmpBuf, manager); |
| 64 | setSystemId(tmpBuf); |
| 65 | manager->deallocate(tmpBuf); //delete [] tmpBuf; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | CompressedInputSource::CompressedInputSource(const XMLCh * const file, const String & header, MemoryManager * const manager) : |
| 70 | xercesc::InputSource(manager), |