当前位置: 首页>>代码示例>>Scala>>正文


Scala StreamSource类代码示例

本文整理汇总了Scala中javax.xml.transform.stream.StreamSource的典型用法代码示例。如果您正苦于以下问题:Scala StreamSource类的具体用法?Scala StreamSource怎么用?Scala StreamSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StreamSource类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: LRPmmlEvaluator

//设置package包名称以及导入依赖的类
package com.inneractive.cerberus

import java.io.{File, FileInputStream}
import java.util
import javax.xml.transform.stream.StreamSource

import org.dmg.pmml.{FieldName, Model, PMML}
import org.jpmml.evaluator.{EvaluatorUtil, FieldValue, ModelEvaluator, ModelEvaluatorFactory}
import org.jpmml.model.JAXBUtil

import scala.collection.Map
import scala.util.Try



class LRPmmlEvaluator(modelLocation: String, threshold: Option[Double]) {

  val inputStream = new FileInputStream(new File(modelLocation, "/model/PMML/PMML.xml"))
  val pmmModel: PMML = JAXBUtil.unmarshalPMML(new StreamSource(inputStream))

  val evaluatorFactory: ModelEvaluatorFactory = ModelEvaluatorFactory.newInstance()
  val evaluator: ModelEvaluator[_ <: Model] = evaluatorFactory.newModelManager(pmmModel)
  val activeFields: util.List[FieldName] = evaluator.getActiveFields
  val targetFields: util.List[FieldName] = EvaluatorUtil.getTargetFields(evaluator)
  val outputFields: util.List[FieldName] = EvaluatorUtil.getOutputFields(evaluator)

  def arguments(eval: FieldName => (FieldName, FieldValue)) = (activeFields map eval).toMap

  def getResults(result: java.util.Map[FieldName, _]) = {
    val targets = targetFields map (f => EvaluatorUtil.decode(result.get(f)))
    val outputs = outputFields map (f => result.get(f))
    Tuple3(targets.head.asInstanceOf[Double], outputs.head.asInstanceOf[Double], outputs(1).asInstanceOf[Double])
  }

  def callEvaluator(params : Map[FieldName, _]) = getResults(evaluator.evaluate(params))

  def predict(features: Features) = Try {
    val r = callEvaluator(arguments((f: FieldName) => {
      val value = features.vector(f.getValue)
      val activeValue = evaluator.prepare(f, value)
      (f, activeValue)
    }))
    new Prediction("", if (r._1 == 0.0) true else false, if (r._1 == 0) r._2 else r._3)
  }
} 
开发者ID:inneractive-opensrc,项目名称:cerberus,代码行数:46,代码来源:Evaluators.scala

示例2: XmlValidator

//设置package包名称以及导入依赖的类
package com.nekopiano.scala.rest

import scala.io.Source
import javax.xml.validation.SchemaFactory
import org.xml.sax.SAXException
import javax.xml.transform.stream.StreamSource
import java.io.File


object XmlValidator {

  val DIR = "C:\\Repos\\AcmeDocsRepo\\git\\?????\\REST\\1.ExpectedResponsesFromExcelSpec\\"
  val DIR_URI = "file://C:/Repos/AcmeDocsRepo/git/?????/REST/1.ExpectedResponsesFromExcelSpec/"

  def main(args: Array[String]): Unit = {

    // val s = Source.fromFile("requests/REST-requests.txt")
    //    val xsd = Source.fromFile("C:\\Repos\\AcmeDocsRepo\\git\\?????\\REST\\1.ExpectedResponsesFromExcelSpec\\1-ApprovedList.xsd")

    //require(args.size >= 2, "Params: xmlFile, xsdFile")

    val result =
      //      if (validate(args(0), args(1)))
//      if (validate(new File(DIR + "1-ApprovedList.xml"), new File(DIR + "1-ApprovedList.xsd")))
      if (validate(new File("responses/payloads/1.ApprovedList.xml"), new File(DIR + "1-ApprovedList.xsd")))
        "Validates!"
      else
        "Not valid."
    println(result)

  }

  def validate(xmlFile: File, xsdFile: File): Boolean = {
    try {
      val schemaLang = "http://www.w3.org/2001/XMLSchema"
      val factory = SchemaFactory.newInstance(schemaLang)
      val schema = factory.newSchema(new StreamSource(xsdFile))
      val validator = schema.newValidator()
      validator.validate(new StreamSource(xmlFile))
    } catch {
      case ex: SAXException =>
        throw ex; println(ex); return false
      case ex: Exception => ex.printStackTrace()
    }
    true
  }

  def validate(xmlFile: String, xsdFile: String): Boolean = {
    validate(new File(xmlFile), new File(xsdFile))
  }

} 
开发者ID:lamusique,项目名称:ScalaSandbox,代码行数:53,代码来源:XmlValidator.scala

示例3: DoiMetaSerializerTest

//设置package包名称以及导入依赖的类
package se.lu.nateko.cp.doi.core.test

import org.scalatest.FunSuite
import views.xml.doi.DoiMeta
import scala.xml.XML
import se.lu.nateko.cp.doi.core.DoiMetaParser
import javax.xml.validation.SchemaFactory
import javax.xml.XMLConstants
import java.net.URL
import javax.xml.transform.stream.StreamSource
import java.io.StringReader

class DoiMetaSerializerTest extends FunSuite{

	test("Serializing/parsing round trip"){
		val meta = DoiMetaExamples.full

		assertResult(meta){
			val serialized = views.xml.doi.DoiMeta(meta).body
			val xml = XML.loadString(serialized)
			DoiMetaParser.parse(xml).get
		}
	}

	ignore("For manual run: validating the XML-serialized metadata against DataCite's XSD Schema"){
		val sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
		val schema = sfactory.newSchema(new URL("http://schema.datacite.org/meta/kernel-4.0/metadata.xsd"))
		val validator = schema.newValidator()
		val serialized = views.xml.doi.DoiMeta(DoiMetaExamples.full).body
		val source = new StreamSource(new StringReader(serialized))
		validator.validate(source)
	}
} 
开发者ID:ICOS-Carbon-Portal,项目名称:doi,代码行数:34,代码来源:DoiMetaSerializerTest.scala

示例4: validate

//设置package包名称以及导入依赖的类
package com.github.tkqubo.saml_metadata.validator

import java.io.{File, FileInputStream}
import javax.xml.XMLConstants
import javax.xml.transform.Source
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.{Schema, SchemaFactory, Validator}

trait MetadataValidator {
  private lazy val validator: Validator = buildValidator()
  private val xsdFileNames = Seq(
    "MetadataExchange.xsd",
    "oasis-200401-wss-wssecurity-secext-1.0.xsd",
    "oasis-200401-wss-wssecurity-utility-1.0.xsd",
    "saml-schema-assertion-2.0.xsd",
    "saml-schema-metadata-2.0.xsd",
    "ws-addr.xsd",
    "ws-authorization.xsd",
    "ws-federation.xsd",
    "ws-securitypolicy-1.2.xsd",
    "xenc-schema.xsd",
    "xmldsig-core-schema.xsd"
  )

  def validate(file: File): Boolean = {
    val xmlSource = new StreamSource(new FileInputStream(file))
    try {
      validator.validate(xmlSource)
      true
    } catch {
      case e: Throwable =>
        false
    }
  }

  private def buildValidator(): Validator = {
    val xsdSources: Array[Source] = xsdFileNames
      .map { fileName =>
        new StreamSource(new FileInputStream(new File(getClass.getResource(s"/schemas/$fileName").toURI)))
      }(collection.breakOut)
    val factory: SchemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
    val schema: Schema = factory.newSchema(xsdSources)
    schema.newValidator()
  }
}

object MetadataValidator extends MetadataValidator 
开发者ID:tkqubo,项目名称:saml-metadata,代码行数:48,代码来源:MetadataValidator.scala

示例5: WWSClient

//设置package包名称以及导入依赖的类
package com.springml.spark.workday.ws

import java.io.{StringReader, StringWriter}
import javax.xml.transform.stream.{StreamResult, StreamSource}

import com.springml.spark.workday.model.WWSInput
import org.apache.log4j.Logger
import org.springframework.ws.client.core.WebServiceTemplate
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory


class WWSClient(
               val wwsInput : WWSInput
               ) {

  @transient val logger = Logger.getLogger(classOf[WWSClient])

  private val webServiceTemplate = createWebServiceTemplate;

  def execute() : String = {
    logger.debug("Request : " + wwsInput.request)
    val source = new StreamSource(new StringReader(wwsInput.request))
    val writer = new StringWriter
    val streamResult = new StreamResult(writer)
    webServiceTemplate.sendSourceAndReceiveToResult(source, usernameTokenHandler, streamResult)

    val response = writer.toString
    logger.debug("Response : " + response)

    return response
  }

  private def createWebServiceTemplate : WebServiceTemplate = {
    val wsTemplate = new WebServiceTemplate(new AxiomSoapMessageFactory)
    wsTemplate.setDefaultUri(wwsInput.wssEndpoint)

    wsTemplate
  }

  private def usernameTokenHandler : UsernameTokenHandler = {
    new UsernameTokenHandler(wwsInput.username, wwsInput.password)
  }
} 
开发者ID:springml,项目名称:spark-workday,代码行数:44,代码来源:WWSClient.scala


注:本文中的javax.xml.transform.stream.StreamSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。