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

org.beangle.template.freemarker.SeqModel.scala Maven / Gradle / Ivy

There is a newer version: 0.0.3
Show newest version
package org.beangle.template.freemarker

import freemarker.template.{ ObjectWrapper, TemplateCollectionModel, TemplateModel, TemplateModelIterator, TemplateSequenceModel }
import freemarker.template.TemplateHashModel
import org.beangle.commons.bean.Properties

class SeqModel(val seq: Seq[_], objectWrapper: ObjectWrapper) extends TemplateCollectionModel with TemplateSequenceModel with TemplateHashModel {

  def get(key: String): TemplateModel = {
    objectWrapper.wrap(Properties.get(seq, key))
  }

  def isEmpty: Boolean = {
    seq.isEmpty
  }

  def get(index: Int): TemplateModel = {
    objectWrapper.wrap(seq(index))
  }

  override def size: Int = {
    seq.size
  }

  override def iterator: TemplateModelIterator = {
    new SeqTemplateModelIterator(seq.iterator, objectWrapper)
  }

  class SeqTemplateModelIterator(val iter: Iterator[_], objectWrapper: ObjectWrapper) extends TemplateModelIterator {
    override def next(): TemplateModel = {
      objectWrapper.wrap(iter.next)
    }

    def hasNext: Boolean = {
      iter.hasNext
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy