Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix GET.groovy for jcr.mixinTypes and other multivalued properties.

...

Code Block
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");

log.info "Groovin' on ${resource}"

def mb = new groovy.xml.MarkupBuilder(out)

mb.html {

   // Shouldn't javax.jcr.Property.getString() take care of this for us?
   def formatMultipleValues = { prop ->
      if (prop.definition.isMultiple()) {
         prop.values.string.join('; ')
      } else {
         prop.string
      }
   }
   
   def tableForMap = { cap, map ->
      table {
         caption { h2 cap }
         tr { th 'property' ; th 'value' }
         map.each { key, value -> tr { td key ; td value } }
      }
   }

   meta {
      title 'Groovy Scripting Sample for Sling'
   }
   body {
      h1 "Hello World !" 
      p "This is Groovy Speaking" 
      p "You requested the Resource ${resource} (yes, this is a GString)" 
      table {
         caption { h2 'Current Node Properties' }
         tr { th 'property' ; th 'value' }
         currentNode.properties.each { prop -> tr { td prop.name ; td formatMultipleValues(prop.string) } }
      }
      tableForMap 'Resource Properties', resource.properties
      tableForMap 'Script Bindings', this.binding.variables
      tableForMap 'Request Properties', request.properties
   }
}

...