Blog Archive

Thursday, June 29, 2017

Search better than notepad++ sometimes with word :-), might be good for support projects

Om

some times, I feel search better than notepad++
print-layout( multiple page views), layout numbering , search in navigation


Monday, June 26, 2017

Produce target xml from source and custom fileds Groovy xml parse


Om

import groovy.xml.*;
def stringXML = 
        ''+
            '  JohnDoe25'+
            '  JaneSmith31'+
            '  RobertDoe11'+
''+
            '  MichaelSmith55'+
            '  ScottWilliams35'+
            '  AliceAnthony14'+
'
'+
        '
'
    
        def people = new XmlSlurper().parseText(stringXML)
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def books = builder.bind {
    mkp.xmlDeclaration()
    namespaces << [meta:'http://meta/book/info']  // Or mkp.declareNamespace('meta':'http://meta/book/info')
dependencies {
//mkp.yield p.dependencyManagement.dependencies.children()
mycustom{
people.root.person1.findAll { p ->
            p.lastName.toString().startsWith('S') ||  p.age.toString().startsWith('1')
        }.each { p ->
mkp.yield p.children()
}}
//mkp.yield people.children()
   
books(count: 3){
        people.person.findAll { p ->
            p.lastName.toString().startsWith('D')
        }.each { p ->
           // println "${p.lastName}, ${p.firstName}"
book(id: 1) {
title lang:'en', 'Groovy in Action'
meta.isbn "${p.lastName}"
           }
                }
}
}
}

println XmlUtil.serialize(books)




Groovy xml parsing example

Om


import org.custommonkey.xmlunit.*
import groovy.xml.*


def todo = new XmlSlurper().parseText(xml)

// Change node values.
def items = todo.roo1.item.findAll {
  it.@priority.toInteger() < 3
}
items.each { item ->
   item.title = "DO: " + item.title
}


// Change attribute value.
def gpars= todo.root1.item.find {
   it.title =~ /.*GPars.*/
}
gpars.@priority = '1'
// Add extra item node.
todo.root1.appendNode {
   item(priority: 2) {
  title 'Work on blog post'
   }}
// Change node.
def grailsItem = todo.root1.item.find {
   it.title.toString().contains('Grails')
}
grailsItem.replaceNode { node ->
   item(who: 'mrhaki', priority: node.@priority) {
  title 'Download Grails 1.4 M1' }}
   


// Remove node. Index value based on result directly after parsing.
// So here we remove the item about GWT.
todo.root1.item[3].replaceNode {}

// Create output.
def newTodo = new StreamingMarkupBuilder().bind {
   mkp.yield todo
}.toString()


println XmlUtil.serialize( newTodo)
//XMLUtil.ignoreWhitespace = true
//def difference = new Diff(newTodo, expected)
//assert difference.similar()

Sunday, June 25, 2017

Groovy syntax step by step with examples for my reference

Om







Comparing java syntac and groovy syntax together , both works here;


IndexOf, [],  double dot notation



subString



concat and split toList



replaceAll



string output format


Reading input from console



accessing values in list.


List in List and reading.


Add remove isEmpty of List


List reverse, sort, pop


Working with map and list and compare


map size


working with ranges



conditional operators





conditional with ternary ?


using switch and break 





while and break


for loop ( ranges, list, map)


for loop for map


Groovy class and static method


parameters to method and calling in main method


Pass by value


Passing list to method


closure notation in groovy 


recursion method.


assigning value to variable using ternary condition.



closure nation for map iternation


closure : each, find, findAll, any, every, collect






Groovy files ( reading lines, add line, remove and modify lines of the file)
create a file and remove file







directory and file properties display.




Groovy Object oriented programming basics
1. Create calls animal
2. create another class dog which extends animal
3. create objects pass parameters
( also learn this. and super() method usage )