
com.mle.appbundler.PlistWriter.scala Maven / Gradle / Ivy
The newest version!
package com.mle.appbundler
import java.nio.file.Path
import com.mle.file.FileUtilities
import scala.xml.dtd.{DocType, PublicID}
import scala.xml._
/**
* Do not format this document with IntelliJ IDEA.
*
* @author Michael
*/
object PlistWriter extends XmlWriter{
// val PLIST_DTD = ""
val docType = DocType("plist", PublicID("-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"), Nil)
def writeConf(conf: InfoPlistConf, dest: Path) = writePretty(confXml(conf), dest)
// def writeDaemon(appIdentifier: String, displayName: String, dest: Path) =
// writePretty(daemonXml(appIdentifier, displayName), dest)
override def prefix: String = decl() + docTypeString(docType)
// def daemonXml(appIdentifier: String, displayName: String) = plistXml {
// Label
// {appIdentifier}
// ProgramArguments
//
// /Applications/{displayName}.app/Contents/MacOS/JavaAppLauncher
//
// KeepAlive
//
// RunAtLoad
//
// }
def docTypeString(docType: DocType) = s"$docType\n"
def confXml(conf: InfoPlistConf): Node = plistXml {
conf.singles.map(p => toProperty(p._1, p._2)) ++ conf.arrays.map(a => toArray(a._1, a._2))
}
def plistXml(dictContent: Iterable[NodeSeq]): Node = {
{dictContent}
}
def toProperty(key: String, value: String): NodeSeq = {
{key}
{value}
}
def toArray(key: String, values: Seq[String]): NodeSeq = {
{key}
{values.map(toValue)}
}
def toValue(value: String): NodeSeq = {
{value}
}
def toBool(key: String, value: Boolean) = {
{key} ++ toBoolean(value)
}
def toBoolean(bool: Boolean) =
if(bool)
else
def dictionary(key: String, kvs: Map[String,String]) = {
{key}
{kvs.map(p => toProperty(p._1, p._2))}
}
def booleanDict(key: String, bool: Boolean) = {
{key}
{toBoolean(bool)}
}
def optionalProperty(key: String, value: Option[String]) = {
value.fold(NodeSeq.Empty)(toProperty(key, _))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy