Skip to content

Commit f1b590f

Browse files
author
Johan Walters
committed
Lenient location of catalog.xml
Proposed solution for issue dvreeze#4
1 parent 63b3b2b commit f1b590f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

jvm/src/main/scala/eu/cdevreeze/tqa/base/taxonomy/customfactory/jvm/TaxonomyBaseFactoryFromRemoteZip.scala

+8-5
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,22 @@ final class TaxonomyBaseFactoryFromRemoteZip(
140140
* names, using Unix-style (file component) separators.
141141
*/
142142
def locateAndParseCatalog(fileDataCollection: ListMap[String, ArraySeq[Byte]]): SimpleCatalog = {
143-
val fileData: ArraySeq[Byte] =
144-
fileDataCollection.getOrElse(catalogZipEntryName, sys.error(s"Missing META-INF/catalog.xml file"))
145-
parseCatalog(fileData)
143+
val (catalogLocation, fileData) = {
144+
fileDataCollection
145+
.find { case (path, bytes) => path.endsWith(catalogZipEntryName) }
146+
.getOrElse(catalogZipEntryName, sys.error(s"Missing META-INF/catalog.xml file"))
147+
}
148+
parseCatalog(catalogLocation, fileData)
146149
}
147150

148151
/**
149152
* Parses the catalog file data (as immutable byte array) into a SimpleCatalog. The returned catalog has as document URI
150153
* the relative URI "META-INF/catalog.xml".
151154
*/
152-
def parseCatalog(fileData: ArraySeq[Byte]): SimpleCatalog = {
155+
def parseCatalog(location: String, fileData: ArraySeq[Byte]): SimpleCatalog = {
153156
val docParser = DocumentParserUsingStax.newInstance()
154157
// A relative document URI, which is allowed for indexed/simple documents!
155-
val docUri: URI = URI.create(catalogZipEntryName).ensuring(!_.isAbsolute)
158+
val docUri: URI = URI.create(location).ensuring(!_.isAbsolute)
156159
val catalogRootElem: indexed.Elem =
157160
indexed.Elem(docUri, docParser.parse(new ByteArrayInputStream(fileData.toArray)).documentElement)
158161

jvm/src/main/scala/eu/cdevreeze/tqa/docbuilder/jvm/TaxonomyPackagePartialUriResolvers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object TaxonomyPackagePartialUriResolvers {
5151
val catalogEntry: ZipEntry = zipFile
5252
.entries()
5353
.asScala
54-
.find(entry => toRelativeUri(entry).toString.endsWith("META-INF/catalog.xml"))
54+
.find(entry => entry.getName.endsWith("catalog.xml"))
5555
.getOrElse(sys.error(s"No META-INF/catalog.xml found in taxonomy package ZIP file ${zipFile.getName}"))
5656

5757
val catalogEntryRelativeUri: URI = toRelativeUri(catalogEntry).ensuring(!_.isAbsolute)

0 commit comments

Comments
 (0)