本文整理汇总了Scala中org.xml.sax.InputSource类的典型用法代码示例。如果您正苦于以下问题:Scala InputSource类的具体用法?Scala InputSource怎么用?Scala InputSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InputSource类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PageDownloader
//设置package包名称以及导入依赖的类
package com.nekopiano.scala.rest.client
import dispatch.classic.url
import dispatch.classic.Http
import java.io.StringReader
import nu.validator.htmlparser.common.XmlViolationPolicy
import nu.validator.htmlparser.sax.HtmlParser
import org.xml.sax.InputSource
import scalax.io.JavaConverters._
import scalax.io.Resource
import scala.xml.Node
import scala.xml.parsing.NoBindingFactoryAdapter
object PageDownloader {
def main(args: Array[String]): Unit = {
val h = new Http
val req = url("http://www.sample.jp/products/") >\ "UTF-8"
val html = h(req as_str)
val rootNode = toNode(html)
val links = rootNode \\ "@href" filter (_.text matches "/products/[a-z]+/[a-z0-9]+/")
val pages = links.map(a => {
"http://www.sample.jp" + a.text + "shiyo.htm"
}).sorted.distinct
println("pages.size=" + pages.size)
pages.foreach(url => {
println(url)
val data = Resource.fromURL(url).byteArray
println("downloading: %s ..." format url)
val r = "[a-z]+/[a-z0-9]+/shiyo.htm".r
val productName = r.findAllIn(url).matchData.mkString.dropRight(10).replace("/", "-")
Resource.fromFile(new java.io.File("samplepages\\" + productName + ".html")).write(data)
})
}
def toNode(str: String): Node = {
val hp = new HtmlParser
hp.setNamePolicy(XmlViolationPolicy.ALLOW)
val saxer = new NoBindingFactoryAdapter
hp.setContentHandler(saxer)
hp.parse(new InputSource(new StringReader(str)))
saxer.rootElem
}
}
示例2: PageDownloader
//设置package包名称以及导入依赖的类
package com.nekopiano.scala.scalasandbox.download
import dispatch.classic.url
import dispatch.classic.Http
import java.io.StringReader
import nu.validator.htmlparser.common.XmlViolationPolicy
import nu.validator.htmlparser.sax.HtmlParser
import org.xml.sax.InputSource
import scalax.io.JavaConverters._
import scalax.io.Resource
import scala.xml.Node
import scala.xml.parsing.NoBindingFactoryAdapter
object PageDownloader {
def main(args: Array[String]): Unit = {
val h = new Http
val req = url("http://www.sample.jp/products/") >\ "UTF-8"
val html = h(req as_str)
val rootNode = toNode(html)
val links = rootNode \\ "@href" filter (_.text matches "/products/[a-z]+/[a-z0-9]+/")
val pages = links.map(a => {
"http://www.sample.jp" + a.text + "shiyo.htm"
}).sorted.distinct
println("pages.size=" + pages.size)
pages.foreach(url => {
println(url)
val data = Resource.fromURL(url).byteArray
println("downloading: %s ..." format url)
val r = "[a-z]+/[a-z0-9]+/shiyo.htm".r
val productName = r.findAllIn(url).matchData.mkString.dropRight(10).replace("/", "-")
Resource.fromFile(new java.io.File("samplepages\\" + productName + ".html")).write(data)
})
}
def toNode(str: String): Node = {
val hp = new HtmlParser
hp.setNamePolicy(XmlViolationPolicy.ALLOW)
val saxer = new NoBindingFactoryAdapter
hp.setContentHandler(saxer)
hp.parse(new InputSource(new StringReader(str)))
saxer.rootElem
}
}
示例3: Starscream
//设置package包名称以及导入依赖的类
package com.iofficecorp.svg
import java.io.Reader
import java.io.Writer
import org.xml.sax.{XMLReader, Attributes, InputSource}
import org.xml.sax.helpers.XMLReaderFactory
import org.dom4j.io.XMLWriter
object Starscream {
private implicit class FilterChain(val reader: XMLReader) {
def chain(newReader: XMLReader => XMLReader): FilterChain =
new FilterChain(newReader(reader))
}
def transformSVGFromReaderToWriter(
reader: Reader,
writer: Writer,
scale:Float = 1.0f,
minimum:Float = Float.MinValue)
: Unit = {
val filter =
XMLReaderFactory.createXMLReader()
.chain(new ScaleFilter(_, scale))
.chain(new MinimumFilter(_, minimum))
.chain(new StripWhitespaceFilter(_, "id"))
.chain(new StripWhitespaceFilter(_, "href"))
.reader
val xmlWriter = new XMLWriter(writer)
filter.setContentHandler(xmlWriter)
filter.parse(new InputSource(reader))
}
}