• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Node类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Helpers

//设置package包名称以及导入依赖的类
import sbt._
import sbt.Keys._

import scala.xml.{Comment, Elem, Node, NodeSeq}
import scala.xml.transform.{RewriteRule, RuleTransformer}

object Helpers {

  def dropIfDependency(node: Node): Node = {
      new RuleTransformer(new RewriteRule {
        override def transform(node: Node): NodeSeq = node match {
          case e: Elem if e.label == "dependency" => NodeSeq.Empty
          case _ => node
        }
      }).transform(node).head
    }

  def pickFilesFromSubpaths(
      roots: Seq[String],
      subpath: File,
      predicate: String => Boolean): Seq[(File, String)] = {

    roots
      .map(file(_) / subpath.toString)
      .flatMap({ f =>
        Path
          .allSubpaths(f)
          .filter({ case (_, relativePath) => predicate(relativePath) })
          .toSeq
      })
  }
} 
开发者ID:brthanmathwoag,项目名称:jancy,代码行数:33,代码来源:Helpers.scala


示例2: Attribute

//设置package包名称以及导入依赖的类
package org.cg.scala.dhc.domelments

import org.cg.scala.dhc.util.StringUtil

import scala.xml.Node

case class Attribute(val name: String, val transformation: Option[TransformationElement], val ln: String) {
  override def equals(o: scala.Any): Boolean = o.isInstanceOf[Attribute] && {
    val other = o.asInstanceOf[Attribute]
    name.equals(other.name) &&
      transformation.equals(other.transformation) &&
      ln.equals(other.ln)
  }

  override def toString: String = {
    s"""ATTRIBUTE $name ln $ln
        ${StringUtil.indent(transformation.getOrElse("").toString(), Const.Indent)}
     """.stripMargin
  }
}

object Attribute {

  def apply(a: Node): Attribute = {
    val name = (a \ "name").text
    val ln = (a \ "name" \ "@ln").text

    val transformation: Option[TransformationElement] = TransformationElement.get(a)

    Attribute(name, transformation, ln)
  }
} 
开发者ID:curiosag,项目名称:datahubchecker,代码行数:33,代码来源:Attribute.scala


示例3: RawSource

//设置package包名称以及导入依赖的类
package org.cg.scala.dhc.domelments

import scala.xml.Node



case class RawSource(val rawSource: String, val rawSourceLn: String) {
  override def equals(o: scala.Any): Boolean = o.isInstanceOf[RawSource] && {
    val other = o.asInstanceOf[RawSource]
    rawSource.equals(other.rawSource) &&
      rawSourceLn.equals(other.rawSourceLn)
  }

  override def toString: String = s"RAW SOURCE $rawSource ln $rawSourceLn"
};

object RawSource {
  def apply(t: Node): RawSource = {
    val rawSource = (t \ "rawSource").text
    val rawSourceLn = (t \ "rawSource" \ "@ln").text
    new RawSource(rawSource, rawSourceLn)
  }
} 
开发者ID:curiosag,项目名称:datahubchecker,代码行数:24,代码来源:RawSource.scala


示例4: phonebook

//设置package包名称以及导入依赖的类
package examples.phonebook  

object phonebook {

  val labPhoneBook = 
    <phonebook>
      <descr>
        This is the <b>phonebook</b> of the 
        <a href="http://acme.org">ACME</a> corporation.
      </descr>
      <entry>
        <name>Burak</name> 
        <phone where="work">  +41 21 693 68 67</phone>
        <phone where="mobile">+41 79 602 23 23</phone>
      </entry>
    </phonebook>

  println( labPhoneBook )

  // XML is immutable - adding an element

  import scala.xml.{ Node, Text }

  def add( phonebook:Node, newEntry:Node ):Node = phonebook match {
    case <phonebook>{ ch @ _* }</phonebook> => 
            <phonebook>{ ch }{ newEntry }</phonebook>
  }

  val pb2 = 
    add( labPhoneBook, 
         <entry>
           <name>Kim</name> 
           <phone where="work">  +41 21 111 11 11</phone>
         </entry> )

  def main(args:Array[String]) = println( pb2 )

} 
开发者ID:chenc10,项目名称:spark-SSR-ICDCS17,代码行数:39,代码来源:phonebook.scala


示例5: JunitResultParser

//设置package包名称以及导入依赖的类
package net.white_azalea.models.parsers.junits

import java.io.{ File, FilenameFilter }

import net.white_azalea.datas.junit.{ TestCase, TestFailure }
import net.white_azalea.models.parsers.utils.XML

import scala.xml.Node

class JunitResultParser {

  def parse(xmlDir: File): List[TestCase] = {
    val xmlFiles = xmlDir.listFiles(new FilenameFilter {
      override def accept(dir: File, name: String): Boolean =
        name.endsWith(".xml")
    })

    xmlFiles
      .flatMap(parseSingleFile)
      .toList
  }

  private[junits] def parseSingleFile(file: File): Seq[TestCase] = {
    (XML.load(file) \ "testcase").map(readTestCase)
  }

  private[junits] def readTestCase(node: Node): TestCase = {
    val methodName = node \@ "name"
    val className = node \@ "classname"
    val failures = (node \ "failure").map(readFailure)
    TestCase(methodName, className, failures)
  }

  private[junits] def readFailure(node: Node): TestFailure = {
    val message = node \@ "message"
    val typeMessage = node \@ "type"
    val cause = node.toString()
    TestFailure(message, typeMessage, cause)
  }
} 
开发者ID:Sunao-Yoshii,项目名称:JUnitDocMarge,代码行数:41,代码来源:JunitResultParser.scala


示例6: Img2TxtProcessor

//设置package包名称以及导入依赖的类
package pl.mojepanstwo.sap.toakoma.processors

import java.io.{File, FileInputStream, InputStreamReader}

import org.springframework.batch.item.ItemProcessor
import pl.mojepanstwo.sap.toakoma._

import scala.xml.{Elem, Node, XML}

import scala.xml.transform.RewriteRule
import sys.process._


class Img2TxtProcessor extends ItemProcessor[Model, Model] {

  override def process(item:Model): Model = {

    item.linksHtml.foreach { case (key, dirPath) =>
      try {
        val xml = XML.load(new InputStreamReader(new FileInputStream(item.xmlPath(key)), "UTF-8"))

        val changed = new RewriteRule {
          override def transform(n: Node): Seq[Node] = n match {
            case elem @ Elem(_, "img", _, _, child @ _*) => {
              val src = elem.attribute("src").get
              val imageFile = new File(dirPath + "/" + src)

              val cmd = "tesseract " +
                imageFile.getAbsolutePath + " " +
                "stdout " +
                "-l pol"
              var result = cmd !!

              if(Option(result).exists(_.trim.isEmpty)) return n

              result = result.replaceAll("-\n", "")
              result = result.replaceAll("—\n", "")

              return(<textFromImg>{result}</textFromImg>)
            }
            case elem: Elem => elem copy (child = elem.child flatMap (this transform))
            case other => other
          }
        } transform xml

        XML.save(dirPath + "/text_from_image.xml", changed(0), "UTF-8", true)
        item.xmlPath(key) = dirPath + "/text_from_image.xml"
      } catch {
        case e: Throwable => println(e.printStackTrace())
      }
    }

    item
  }
} 
开发者ID:PrawoPolskie,项目名称:toakoma,代码行数:56,代码来源:Img2TxtProcessor.scala


示例7: SelectionController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}

import scala.xml.{Node, Text}


class SelectionController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {
  def index() = Action {
    implicit request => val xml : UserXML = xmlForm.bindFromRequest().get
    val p = scala.xml.XML.loadString(xml.xml)
    val pageId = (p \ "state" \ "page-id").text
    val title = (p \ "header" \ "title").text
    val selections = p \ "selection"
    var selection = selections
    for (e <- selections){
      if ((e \ "@page-id").text == pageId){
        selection = e
      }
    }
//    val selection = (p \\ "_").filter(attributeEquals("@page-id", Text(pageId)))
    val header1 = (selection \ "header1").text
    val header2 = (selection \ "header2").text

    val options = selection \ "option"
    var optionsCode : String = ""
    for (e <- options){
      val mapToEncode = Map("page-id"->(selection \ "next").text, (selection \ "@tag")-> (e \ "@short"))
      var stringMap = ""
      for ((k, v) <- mapToEncode) {
        stringMap = stringMap + k + "=" + v + ":"
      }
      optionsCode += "<form method=\"POST\" action=\"/bind/\" style=\"text-align: center\">" +
        "<input type=\"text\" name=\"xml\" value=\"" + scala.xml.Utility.escape(xml.xml) + "\" style=\"display: none\" />" +
        "<input type=\"text\" name=\"map\" value=\"" + stringMap + "\" style=\"display: none\" />" +
        "<input type=\"submit\" value=\"> " + (e \ "@value").text + "\" class=\"answer\" onMouseOver=\"document.getElementById('description').innerHTML = '" + e.text + "';\" onMouseOut=\"document.getElementById('description').innerHTML = '';\"/>" +
        "</form>"
    }

    Ok(views.html.main(title)(content = views.html.selection(header1, header2, optionsCode, xml.xml)))
  }

  def attributeEquals(name: String, value: Text)(node: Node) = node.attributes.exists(_ == value)

  val xmlForm = Form(
    mapping(
      "xml" -> nonEmptyText
    )(UserXML.apply)(UserXML.unapply)
  )
} 
开发者ID:Peantab,项目名称:paragraph-framework,代码行数:56,代码来源:SelectionController.scala


示例8: TextController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}

import scala.xml.{Node, Text}


class TextController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {
  def index() = Action {
    implicit request => val xml : UserXML = xmlForm.bindFromRequest().get
    val p = scala.xml.XML.loadString(xml.xml)
    val pageId = (p \ "state" \ "page-id").text
    val title = (p \ "header" \ "title").text
    val texts = p \ "text"
    var text = texts
    for (e <- texts){
      if ((e \ "@page-id").text == pageId){
        text = e
      }
    }
    val header1 = (text \ "header1").text
    val header2 = (text \ "header2").text
    val tag = (text \ "@tag").text
    val default = (text \ "@default").text
    val accept = "> " + (text \ "@accept").text
    val nextPage = (text \ "next").text

    Ok(views.html.main(title)(content = views.html.text(header1, header2, tag, default, accept, nextPage, xml.xml)))
  }

  def attributeEquals(name: String, value: Text)(node: Node) = node.attributes.exists(_ == value)

  val xmlForm = Form(
    mapping(
      "xml" -> nonEmptyText
    )(UserXML.apply)(UserXML.unapply)
  )
} 
开发者ID:Peantab,项目名称:paragraph-framework,代码行数:44,代码来源:TextController.scala


示例9: RunDesignTemplateReader

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



import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.{Calendar, UUID}

import com.pacbio.common.models.{XmlTemplateReader => GenTemplateReader}
import scala.xml.Node

class RunDesignTemplateReader(xmlFile: Path) {
  private def randomId(): UUID = UUID.randomUUID()
  private def randomContextId(): String = toRandomMovieContextId("SIM")
  private var subreadSetUuid : Option[UUID] = None

  def toRandomMovieContextId(instrument:String) = {
    val sx = new SimpleDateFormat("yyMMdd_HHmmss").format(Calendar.getInstance().getTime)
    s"m${instrument}_$sx"
  }


  private val getSubreadsetUuid = {
    subreadSetUuid = Some(randomId())
    subreadSetUuid.get
  }

  def read :Node =
    GenTemplateReader
      .fromFile(xmlFile)
      .globally()            .substitute("{RUN_ID}", randomId())
      .perInstance()         .substitute("{STATUS}", "Ready")
      //.perInstance()         .substitute("{movieLengthInMins}", movieLenInMins())
      .perNode("SubreadSet") .substituteMap {
      val collectionContextId = randomContextId()
      Map(
        "{SUBREAD_ID}"           -> (() => getSubreadsetUuid),
        "{EXTERNAL_RESOURCE_ID}" -> (() => randomId())
        //"{collectionContextId}" -> (() => collectionContextId),
        //"{collectionPathUri}"   -> (() => s"//pbi/collections/xfer-test/$collectionContextId/1_A01/$runId/")
        //"{movieLengthInMins}"   -> (() => movieLengthInMins)
      )
    }.result()

  def readStr = read.mkString

  def readRundesignTemplateInfo = RunDesignTemplateInfo(readStr, subreadSetUuid.get)
} 
开发者ID:PacificBiosciences,项目名称:smrtflow,代码行数:49,代码来源:RunDesignTemplateReader.scala


示例10: 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
  }

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


示例11: 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
  }

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


示例12: ExerciseNine

//设置package包名称以及导入依赖的类
package chapter.sixteen

import scala.xml.transform.{ RuleTransformer, RewriteRule }
import scala.xml.{ Attribute, Elem, Node, Null }

object ExerciseNine {

  def setDefaultImgAlt(input: Node, value: String): Seq[Node] = {
    val rule = new RewriteRule {
      override def transform(n: Node) = n match {
        case img @ <img /> if img \ "@alt" isEmpty => img.asInstanceOf[Elem] % Attribute(null, "alt", value, Null)
        case _ => n
      }
    }

    new RuleTransformer(rule).transform(input)
  }

} 
开发者ID:deekim,项目名称:impatient-scala,代码行数:20,代码来源:ExerciseNine.scala


示例13: ExerciseNineSpec

//设置package包名称以及导入依赖的类
package chapter.sixteen

import ExerciseNine.setDefaultImgAlt

import scala.xml.Node

import org.scalatest._
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith

@RunWith(classOf[JUnitRunner])
class ExerciseNineSpec extends FlatSpec with Matchers {

  "setDefaultImgAlt" should "transform an XHTML document by setting `alt` to TODO to all img elements without the attribute set" in {
    val document: Node =
      <html>
        <img alt="TODO" />
        <img />
        <img alt="TODO" />
      </html>

    val defaultAlt = "TODO"
    val transformed = setDefaultImgAlt(document, defaultAlt)
    transformed should have size 1

    val imgs = transformed(0) \ "img"
    imgs should have size 3
    imgs.foreach { img => img.attribute("alt").get.text should be (defaultAlt) }
  }
} 
开发者ID:deekim,项目名称:impatient-scala,代码行数:31,代码来源:ExerciseNineSpec.scala


示例14: SimpleTransformationStd

//设置package包名称以及导入依赖的类
package net.michalsitko.xml.bench

import java.io.StringWriter

import scala.xml.{Elem, Node, Text, XML}

object SimpleTransformationStd extends SimpleTransformation {
  val doTransform: PartialFunction[Node, Node] = {
    case el: Elem if el.label == "f" =>
      if(el.child.size == 1) {
        val replaceWith = el.child.head match {
          case t: Text =>
            Text(t.text.toUpperCase)
          case a => a
        }
        el.copy(child = List(replaceWith))
      } else {
        el
      }
    case a => a
  }

  override def transform(input: String): String = {
    val xml = XML.loadString(input)

    val transformed = xml.map {
      case el: Elem if el.label == "a" =>
        el.copy(child = el.child.flatMap { el =>
          doTransform(el)
        })
      case a => a
    }

    val writer = new StringWriter

    XML.write(writer, transformed.head, "UTF-8", true, null)
    writer.toString
  }
} 
开发者ID:note,项目名称:xml-lens,代码行数:40,代码来源:SimpleTransformationStd.scala


示例15: Util

//设置package包名称以及导入依赖的类
package trap.xml
//import java.io.BufferedInputStream
//import java.io.BufferedOutputStream
//import java.io.BufferedReader
//import java.io.File
import java.io.FileInputStream
import java.io.InputStreamReader

import scala.xml.Elem
import scala.xml.Attribute
import scala.xml.Text
import scala.xml.Node
import scala.xml.NodeSeq
import scala.xml.Null
import scala.xml.PrettyPrinter
import scala.xml.XML
import trap.Util._
import trap.file.Util._
object Util {
  
  def formatNicely(xmlFile:String) = 
    writeToTextFile(xmlFile, new PrettyPrinter(200, 2).format(loadXML(xmlFile)))

  def formatNicely(xml:Elem) = new PrettyPrinter(200, 2).format(xml)
    
  def getAttributeText(xml:NodeSeq, attrName:String) = {
    printdbg ("    ===> getAttributeTest "+xml+": "+attrName)
    (xml \ ("@"+attrName)).text
  }
  private val r = <root/>
  def getNode(n:String) = r.copy(label=n)
  def addChild(n: Node, newChild: Node) = n match {
    case Elem(prefix, label, attribs, scope, child @ _*) =>
      Elem(prefix, label, attribs, scope, child ++ newChild : _*)
    case _ =>  throw new Exception("Can only add children to elements!")
  }
  def addChildren(n:Node, children:NodeSeq) = children.foldLeft(n)((x, y) => addChild(x, y))
  def addAttribute(n:Elem, attrName:String, attrValue:String) = n % Attribute(None, attrName, Text(attrValue), Null)
  def attr(xml:Node, attrName:String) = (xml \ ("@"+attrName)).text
  def loadXML(fileName:String) =  
    using(new FileInputStream(fileName)){
      fis => using(new InputStreamReader(fis)){
        isr => XML.load(isr)
      }
    }

  def getElementName (x:Node) = x.nameToString(new StringBuilder).toString
  def filterByAttr(xml:NodeSeq, attrName:String, attrValue:String) = 
    xml.filter(x  => (x \ ("@"+attrName)).text == attrValue)
  
  def getElementsWithAttribute(xml:NodeSeq, elementName:String, attrName:String, attrVal:String) = 
    xml \ elementName collect { x => (x \ ("@"+attrName)).map(_.text).contains(attrVal) match {
        case true => x
      }   
    }
  def getElementWithAttribute(xml:NodeSeq, elementName:String, attrName:String, attrVal:String) = 
    ((xml \ elementName).find{ x => (x \ ("@"+attrName)).map(_.text).contains(attrVal) }).get
  def getChildren(xml:NodeSeq) = xml \ "_"
} 
开发者ID:scalahub,项目名称:acc,代码行数:60,代码来源:Util.scala


示例16: Main

//设置package包名称以及导入依赖的类
package test.XDSLToDatalog

import trap.dsl.DSLToXDSL
import trap.xdsl.XDSLBasisUtil
import trap.dsl.DSLConfig
import trap.xdsl.XDSLLoader
import trap.xdsl.XDSLToDatalog
import scala.xml.Node

object Main {
  
  val basis = Array(extendedBasis, reducedBasis).flatten  
  val basisUtil = new XDSLBasisUtil(basis)
  val compiler = new XDSLToDatalog(dslConfig, basisUtil)  

  def getFindQueries(xdsl:Node) = {
    val loader = new XDSLLoader(xdsl, basisUtil.patterns) // Load XML using some patterns
    loader.loadDefinedPatterns 
    loader.getFindPatternMatchers
  }

  def main(args: Array[String]): Unit = {
    args.size match {
      case i if i > 0 => 
        val xdsl = DSLToXDSL.compile(args(0)) // convert DSL to XDSL (XML)
        // println (" ====\n"+xdsl+"\n ====")
        val findQueries = getFindQueries(xdsl) // get find queries in XDSL
        // println ("// ---find---")
        // findQueries foreach println
        val datalogCode = findQueries map (compiler.getFindQuery(_, false))
        println ("// ---rules--- ")
        compiler.getCreatedRules foreach println
        println ("// ---query--- ")
        (findQueries zip datalogCode) foreach (x => println("// "+x._1+"\n"+x._2))
          // following is for testing 
          if (i >= 3) {
            println("Path [Fact("+args(1)+")=>Fact("+args(2)+")]")
            println(basisUtil.getPath(args(1), args(2)))
          }
          if (i >= 5) {
            println("Path [Set("+args(3)+")=>Fact("+args(4)+")]")
            println(basisUtil.getSetsToFactPath(Set(args(3)), args(4)))
          }
      case _ => println ("Usage java -jar JARFile <input_dsl_file> [<start> <end>]")
    }    
  }
} 
开发者ID:scalahub,项目名称:acc,代码行数:48,代码来源:Main.scala


示例17: XDSLGenerator

//设置package包名称以及导入依赖的类
package trap.dsl.compiler

import org.antlr.runtime.tree.CommonTree
import scala.collection.JavaConversions._ 
import scala.xml.Node
import trap.xml.Util._

class XDSLGenerator(tokens:Array[String]) {
  def getXDSL(t:CommonTree, src:String, ver:String) = <dsl ver={ver} file={src}>{getXML(t)}</dsl>
  private def getChildren(tree:CommonTree) = if (tree.getChildren != null) tree.getChildren.map(_.asInstanceOf[CommonTree]) else Seq()
  private def getXML(tree:CommonTree):Node = {
    val node = tokens(tree.getType) match {
      case s if s.startsWith("'") => getNode(tree.getText)
      case any => addAttribute(getNode(any), "name", tree.getText)
    }    
    addChildren(addAttribute(node, "line", tree.getLine.toString), getChildren(tree) map(getXML))
  }
} 
开发者ID:scalahub,项目名称:acc,代码行数:19,代码来源:XDSLGenerator.scala


示例18: Episode

//设置package包名称以及导入依赖的类
package rss

import java.net.URL
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME

import scala.util.{Failure, Success, Try}
import scala.xml.Node

case class Episode(name: String,
                   date: ZonedDateTime,
                   downloadURL: Option[URL]
                  )

case class Feed(feedXML: Node) {

  val name: String = (feedXML \ "channel" \ "title").text

  val episodes: List[Episode] = for {
    item <- (feedXML \ "channel" \ "item").toList
    name = (item \ "title").text
    date = ZonedDateTime.parse((item \ "pubDate").text, RFC_1123_DATE_TIME)
    dUrl = Try {
      new URL((item \ "enclosure" \ "@url").text)
    } match {
      case Success(url) => Some(url)
      case Failure(_) => None
    }
  } yield Episode(name, date, dUrl)

} 
开发者ID:jarrodwb,项目名称:rss,代码行数:32,代码来源:Model.scala


示例19: fetchXML

//设置package包名称以及导入依赖的类
import java.net.URL
import scala.io.Source.fromURL
import io.circe._
import io.circe.parser._
import scala.io.Source
import scala.xml.{Elem, Node, XML}

package object  rss {

  System.setProperty("http.agent", "my rss podcast downloader - jarrodwb.com")

  def fetchXML(url: String): Elem = XML.loadString(Source.fromURL(url).mkString)

  def getItems(xml: Node) = (xml \ "channel" \ "item" \ "enclosure").map( _ \ "@url").map(_.text).toList

  def iTunesFlipper(url: String) = {

    case class ID(value: String)

    def fromITunes(url: String): ID = {
      val myURL = new URL(url)
      ID(myURL.getPath.split("/").last.drop(2))
    }

    def lookup(id: ID): URL = {
      val query = s"https://itunes.apple.com/lookup?id=${id.value}&entity=podcast"
      val json = parse(fromURL(new URL(query)).mkString).getOrElse(Json.Null)
      val hc = json.hcursor
      val urlEither = hc.downField("results").downArray.downField("feedUrl").as[String]
      urlEither match {
        case Right(url) => new URL(url)
        case Left(error) => throw error
      }
    }

    (fromITunes _ andThen lookup)(url)

  }

  def allDownloadURLs(urls: List[String]) = urls map fetchXML flatMap getItems

} 
开发者ID:jarrodwb,项目名称:rss,代码行数:43,代码来源:package.scala


示例20: CustomPage

//设置package包名称以及导入依赖的类
package org.apache.spark.ui

import javax.servlet.http.HttpServletRequest

import scala.xml.Node

abstract class CustomPage(val name: String) extends WebUIPage("") {

  private[ui] var tab: SparkUITab = _
  private[ui] var title: String = _
  private[ui] var ui: SparkUI = _

  def attachRedirectHandler(
    srcPath: String,
    destPath: String,
    beforeRedirect: HttpServletRequest => Unit = x => (),
    basePath: String = "",
    httpMethods: Set[String] = Set("GET")): Unit = {

    // Can't use Jetty interface as it is shaded to org.spark-project; use reflection instead
    val createRedirectHandler = JettyUtils.getClass.getMethods.filter(_.getName == "createRedirectHandler").head
    val handler = createRedirectHandler.invoke(JettyUtils, srcPath, destPath, beforeRedirect, basePath, httpMethods)

    val attachHandler = ui.getClass.getMethods.filter(_.getName == "attachHandler").head
    attachHandler.invoke(ui, handler)
  }

  def renderPage(request: HttpServletRequest): Seq[Node]

  final override def render(request: HttpServletRequest): Seq[Node] = {
    val content = renderPage(request)
    UIUtils.headerSparkPage(title, content, tab, Some(5000))
  }

} 
开发者ID:kakao,项目名称:cuesheet,代码行数:36,代码来源:CustomPage.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Messages类代码示例发布时间:2022-05-23
下一篇:
Scala SecureRandom类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap