-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
426 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "colorer/xml/libxml2/LibXmlInputSource.h" | ||
#include "colorer/Exception.h" | ||
#include "colorer/utils/Environment.h" | ||
|
||
LibXmlInputSource::LibXmlInputSource(const UnicodeString& path, const UnicodeString* base) | ||
{ | ||
if (path.isEmpty()) { | ||
throw InputSourceException("XmlInputSource::newInstance: path is empty"); | ||
} | ||
UnicodeString full_path; | ||
if (path.startsWith(jar) || (base != nullptr && base->startsWith(jar))) { | ||
#ifdef COLORER_FEATURE_ZIPINPUTSOURCE | ||
initZipSource(path, base); | ||
#else | ||
throw InputSourceException("zip input source not supported"); | ||
#endif | ||
} | ||
else if (colorer::Environment::isRegularFile(base, &path, full_path)) { | ||
sourcePath = full_path; | ||
} | ||
else { | ||
throw InputSourceException(full_path + " isn't regular file."); | ||
} | ||
} | ||
|
||
LibXmlInputSource::~LibXmlInputSource() | ||
{ | ||
#ifdef COLORER_FEATURE_ZIPINPUTSOURCE | ||
if (zip_source) { | ||
zip_source->delref(); | ||
} | ||
#endif | ||
} | ||
|
||
LibXmlInputSource LibXmlInputSource::createRelative(const UnicodeString& relPath) const | ||
{ | ||
return LibXmlInputSource(relPath, &sourcePath); | ||
} | ||
|
||
UnicodeString& LibXmlInputSource::getPath() | ||
{ | ||
return sourcePath; | ||
} | ||
|
||
#ifdef COLORER_FEATURE_ZIPINPUTSOURCE | ||
void LibXmlInputSource::initZipSource(const UnicodeString& path, const UnicodeString* base) | ||
{ | ||
if (path.startsWith(jar)) { | ||
const auto path_idx = path.lastIndexOf('!'); | ||
if (path_idx == -1) { | ||
throw InputSourceException("Bad jar uri format: " + path); | ||
} | ||
|
||
const UnicodeString path_to_jar = colorer::Environment::getAbsolutePath( | ||
base ? *base : u"", UnicodeString(path, jar.length(), path_idx - jar.length())); | ||
const UnicodeString path_in_jar(path, path_idx + 1); | ||
|
||
sourcePath = jar + path_to_jar + u"!" + path_in_jar; | ||
zip_source = SharedXmlInputSource::getSharedInputSource(path_to_jar); | ||
} | ||
else { | ||
const auto base_idx = base->lastIndexOf('!'); | ||
if (base_idx == -1) { | ||
throw InputSourceException("Bad jar uri format: " + path); | ||
} | ||
const UnicodeString path_to_jar(*base, jar.length(), base_idx - jar.length()); | ||
const UnicodeString path_in_jar = colorer::Environment::getAbsolutePath(UnicodeString(*base, base_idx + 1), path); | ||
|
||
sourcePath = jar + path_to_jar + u"!" + path_in_jar; | ||
zip_source = SharedXmlInputSource::getSharedInputSource(path_to_jar); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.