Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.io.{BufferedReader, InputStreamReader}

enablePlugins(JavaAppPackaging)

lazy val xmlCalabashVersion = "2.99.10"
lazy val xmlCalabashVersion = "2.99.11"
lazy val jafplVersion = "0.3.83"
lazy val saxonVersion = "10.6"
lazy val useSaxonEE = Option(System.getProperty("saxonEdition")).getOrElse("HE") == "EE"
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/xmlcalabash/XMLCalabash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class XMLCalabash private(userProcessor: Option[Processor], val configurer: XPro
// Build the options before compiling in case some of them are statics...
_options.clear()
val nsmap = mutable.HashMap.empty[String,String]
for (param <- args.parameters) {
for (param <- parameters) {
param match {
case ns: PipelineNamespace =>
nsmap.put(ns.prefix, ns.namespace)
Expand Down Expand Up @@ -355,7 +355,7 @@ class XMLCalabash private(userProcessor: Option[Processor], val configurer: XPro

val nsmap = mutable.HashMap.empty[String,String]

for (param <- args.parameters) {
for (param <- parameters) {
param match {
case ns: PipelineNamespace =>
nsmap.put(ns.prefix, ns.namespace)
Expand Down Expand Up @@ -387,7 +387,7 @@ class XMLCalabash private(userProcessor: Option[Processor], val configurer: XPro
// To deal with outputs, we have to collate multiple outputs to the same port together.
// But we also have to check that there's at most one explicit DataConsumer.
val outputMap = mutable.HashMap.empty[String, ListBuffer[PipelineOutputDocument]]
for (opt <- args.parameters collect { case p: PipelineOutputDocument => p }) {
for (opt <- parameters collect { case p: PipelineOutputDocument => p }) {
if (!(outputMap.contains(opt.port))) {
outputMap.put(opt.port, ListBuffer.empty[PipelineOutputDocument])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package com.xmlcalabash.runtime
package com.xmlcalabash.testing

import com.jafpl.messages.Message
import com.jafpl.steps.DataConsumer
import com.xmlcalabash.exceptions.XProcException
import com.xmlcalabash.messages.XProcItemMessage
import com.xmlcalabash.model.xxml.XOutput
import com.xmlcalabash.util.MediaType

import scala.collection.mutable.ListBuffer

class BufferingConsumer(output: XOutput) extends DataConsumer {
class BufferingConsumer() extends DataConsumer {
private val _items = ListBuffer.empty[XProcItemMessage]
private val _mediaTypes = ListBuffer.empty[MediaType]

def messages: List[XProcItemMessage] = _items.toList

def mediaTypes: List[MediaType] = _mediaTypes.toList
def mediaTypes_=(types: List[MediaType]): Unit = {
_mediaTypes.clear()
_mediaTypes ++= types
}

override def consume(port: String, message: Message): Unit = {
message match {
case msg: XProcItemMessage =>
// Check that the message content type is allowed on the output port
val mtypes = output.contentTypes;
val metadata = msg.metadata;
if (mtypes.nonEmpty) {
if (!metadata.contentType.allowed(mtypes)) {
throw XProcException.xdBadOutputMediaType(metadata.contentType, mtypes, output.location)
if (_mediaTypes.nonEmpty) {
if (!metadata.contentType.allowed(_mediaTypes.toList)) {
throw XProcException.xdBadOutputMediaType(metadata.contentType, _mediaTypes.toList, None)
}
}
_items += msg
Expand Down
14 changes: 8 additions & 6 deletions src/main/scala/com/xmlcalabash/testing/Tester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.xmlcalabash.testing

import com.xmlcalabash.XMLCalabash
import com.xmlcalabash.exceptions.TestException
import com.xmlcalabash.runtime.BufferingConsumer
import com.xmlcalabash.util.S9Api
import com.xmlcalabash.util.{PipelineOutputConsumer, S9Api}
import net.sf.saxon.s9api.{QName, Serializer, XdmNode}
import org.slf4j.{Logger, LoggerFactory}

Expand Down Expand Up @@ -37,13 +36,16 @@ class Tester(xmlcalabash: XMLCalabash) {

def run(): TestResult = {
try {
var result: Option[BufferingConsumer] = Some(new BufferingConsumer())
xmlcalabash.parameter(new PipelineOutputConsumer("result", result.get))

xmlcalabash.configure()
val decl = xmlcalabash.step
var result = Option.empty[BufferingConsumer]

val decl = xmlcalabash.step
if (decl.outputPorts.contains("result")) {
result = Some(new BufferingConsumer(decl.output("result")))
xmlcalabash.args.output("result", result.get)
result.get.mediaTypes = decl.output("result").contentTypes
} else {
result = None
}

xmlcalabash.run()
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/xmlcalabash/util/MediaType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object MediaType {
val HTML = new MediaType("text", "html")
val XHTML = new MediaType("application", "xhtml+xml")
val ZIP = new MediaType("application", "zip")
val PDF = new MediaType("application", "pdf")
val MULTIPART = new MediaType("multipart", "*")
val MULTIPART_MIXED = new MediaType("multipart", "mixed")

Expand Down