here I have code in python and now I want to transfer it in Java.

import logging
import urllib
import re

from waveapi import events
from waveapi import model
from waveapi import robot
from waveapi import document

from django.utils import simplejson
from google.appengine.api import urlfetch

def OnDocChanged(properties, context):
#Get Contents of current blip
blip = context.GetBlipById(properties)
contents = blip.GetDocument().GetText()
#Clean Up Text Remove <br> <br />
p = re.compile('(<( )*br( )*[/]>)')
contents = p.sub('\n',contents)
#Run Search
sRes += "["
sRes += processBlip(contents)

if(sRes != contents):
sRes += "]"
root_wavelet = context.GetRootWavelet()

def processBlip(blip):
text = blip.GetDocument().GetText()
returnText = ""
charsAdded = 0
#Setup Regular Expression to find search strings
p = re.compile("^(.)_ ([0-9a-zA-Z ]+)",re.MULTILINE)
searchStrings = p.finditer(text)
flickrImages = []
#Iterate through search strings
for c in searchStrings:
s = c.groups()
if(s[0] == 'G'):
sRet = '\nGoogle Search for "' + s[1] + '"\n\n'
sRet += searchGoogle(s[1])
#returnText = returnText[0:c.end()+charsAdded] + sRet + '\n'+ returnText[c.end()+charsAdded+1:len(returnText)]
#charsAdded += len(sRet)
elif(s[0] == 'F'):
sRet = searchFlickr(s[1])
for imageURL in sRet:
cImg = document.Image(imageURL)
title = '\nFlickr Search for "' + s[1] + '"\n\n'

def stringToBlip(blip,contents):
#newBlip = blip
newBlip = blip.GetDocument().AppendInlineBlip()

def imageListToBlip(blip,imgList,text):
#newBlip = blip
newBlip = blip.GetDocument().AppendInlineBlip()
for i in imgList:

def searchFlickr(query):
results = []
url = '' % (urllib.quote(query))
content = urlfetch.fetch(url=url).content
content =content[:-1].replace("jsonFlickrApi(","")
for item in simplejson.loads(content):

return results

def searchGoogle(query):
results = ""
#print "Searching Google with query \"" + query + "\""
url = '' % (urllib.quote(query))
content = urlfetch.fetch(url=url).content
for item in simplejson.loads(content):
p = re.compile('<[/ ]?[a-zA-Z ]>')
title = p.sub('',item)
content = p.sub('',item)
returnStr = title + '\n' +\
item + '\n' +\
content + '\n\n'
results += returnStr
return results

def OnRobotAdded(properties, context):
"""Invoked when the robot has been added."""
root_wavelet = context.GetRootWavelet()
root_wavelet.CreateBlip().GetDocument().SetText("Welcome to Wave Search!")

def OnBlipSubmit(properties, context):
blip = context.GetBlipById(properties)

if __name__ == '__main__':
wavesearch = robot.Robot('WaveSearch',
wavesearch.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
wavesearch.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmit)
#wavesearch.RegisterHandler(events.DOCUMENT_CHANGED, OnDocChanged)

Jython comes to mind. It would allow you to run Python code under Java.

I was about to say that.
Jython is Python for Java, so just download Netbeans and the latest version of Jython, and copy the file over and see if it compiles.
I've never worked with Jython, so I can't really help with the details.

This article has been dead for over six months. Start a new discussion instead.