All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.arktekk.atom.Category.scala Maven / Gradle / Ivy

/*
 * Copyright 2011 Arktekk AS
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package no.arktekk.atom

import com.codecommit.antixml._

/**
 * @author Erlend Hamnaberg
 */
case class Category private[atom](wrapped: Elem) extends ElementWrapper {
  require(Elem.validateNamespace(wrapped, Atom.namespace), "Wrong namespace defined")
  require(wrapped.name == "category", "Wrong name of element")

  type T = Category

  protected val self = this

  lazy val scheme: Option[String] = wrapped.attr("scheme")

  lazy val term: Option[String] = wrapped.attr("term")

  lazy val label: Option[String] = wrapped.attr("label")

  def copy(elem: Elem) = new Category(elem)

  def withScheme(scheme: String): Category = withAttribute("scheme", scheme)

  def withTerm(term: String): Category = withAttribute("term", term)

  def withLabel(label: String): Category = withAttribute("label", label)
}

object Category {
  def apply(scheme: Option[String], term: String, label: Option[String]): Category = {
    val attrs = Attributes() ++ scheme.map((QName("scheme") -> _.toString)) + ("term" -> term) ++ label.map((QName("label") -> _))
    Category(Elem(NamespaceBinding(Atom.namespace), "category", attrs))
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy