本文整理汇总了Python中au.edu.usq.fascinator.common.JsonSimple类的典型用法代码示例。如果您正苦于以下问题:Python JsonSimple类的具体用法?Python JsonSimple怎么用?Python JsonSimple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonSimple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __messages
def __messages(self):
# Generic workflow messages
if self.message_list is not None and len(self.message_list) > 0:
msg = JsonSimple()
msg.getJsonObject().put("oid", self.oid)
message = msg.toString()
for target in self.message_list:
self.utils.sendMessage(target, message)
# Camtasia integration
emailStep = self.params.getProperty("emailStep")
# First pass though... harvest queue
if emailStep is None:
emailStep = "emailOne"
# The next message
self.params.setProperty("emailStep", "emailTwo")
else:
# Second step... render queue
if emailStep == "emailTwo":
self.params.setProperty("emailStep", "completed")
if emailStep is not None and emailStep != "completed":
email = self.params.getProperty("relayEmail")
body = self.__getEmailBody(emailStep)
if email is not None and body is not None:
msg = JsonSimple()
msg.getJsonObject().put("to", email)
msg.getJsonObject().put("body", body)
message = msg.toString()
self.utils.sendMessage("emailnotification", message)
示例2: get_image
def get_image(self):
self.type = "http://www.purl.org/anotar/ns/type/0.1#Tag"
mediaFragType = "http://www.w3.org/TR/2009/WD-media-frags-20091217"
result = '{"result":' + self.search_solr() + "}"
if result:
imageTagList = []
imageTags = JsonSimple(result).getJsonSimpleList(["result"])
for imageTag in imageTags:
imageAno = JsonSimple()
# We only want tags with locators, not basic tags
locators = imageTag.getJsonSimpleList(["annotates", "locators"])
if locators and not locators.isEmpty():
locatorValue = locators.get(0).getString(None, ["value"])
locatorType = locators.get(0).get(None, ["type"])
if locatorValue and locatorValue.find("#xywh=") > -1 and locatorType == mediaFragType:
_, locatorValue = locatorValue.split("#xywh=")
left, top, width, height = locatorValue.split(",")
object = imageAno.getJsonObject()
object.put("top", top)
object.put("left", left)
object.put("width", width)
object.put("height", height)
object.put("creator", imageTag.getString(None, ["creator", "literal"]))
object.put("creatorUri", imageTag.getString(None, ["creator", "uri"]))
object.put("id", imageTag.getString(None, ["id"]))
# tagCount = imageTag.getString(None, ["tagCount"])
object.put("text", imageTag.getString(None, ["content", "literal"]))
object.put("editable", "true")
imageTagList.append(imageAno.toString())
result = "[" + ",".join(imageTagList) + "]"
return result
示例3: __messages
def __messages(self):
if self.message_list is not None and len(self.message_list) > 0:
msg = JsonSimple()
msg.getJsonObject().put("oid", self.oid)
message = msg.toString()
for target in self.message_list:
self.utils.sendMessage(target, message)
示例4: __activate__
def __activate__(self, context):
response = context["response"]
writer = response.getPrintWriter("text/plain; charset=UTF-8")
auth = context["page"].authentication
result = JsonSimple()
obj = result.getJsonObject()
obj.put("status", "error")
obj.put("message", "An unknown error has occurred")
if auth.is_logged_in():
services = context["Services"]
formData = context["formData"]
sessionState = context["sessionState"]
urlBase = context["urlBase"]
if urlBase.endswith("/"):
urlBase = urlBase[:-1]
func = formData.get("func")
portalManager = services.portalManager
if func == "create-view":
try:
fq = [q for q in sessionState.get("fq") if q != 'item_type:"object"']
id = formData.get("id")
description = formData.get("description")
print "Creating view '%s': '%s'" % (id, description)
portal = Portal(id)
portal.setDescription(formData.get("description"))
portal.setQuery(" OR ".join(fq))
portal.setSearchQuery(sessionState.get("searchQuery"))
portal.setFacetFields(portalManager.default.facetFields)
portalManager.add(portal)
portalManager.save(portal)
obj.put("status", "ok")
obj.put("message", "View '%s' successfully created" % id)
obj.put("url", "%s/%s/home" % (urlBase, id))
except Exception, e:
response.setStatus(500)
obj.put("message", str(e))
elif func == "delete-view":
defaultPortal = context["defaultPortal"]
portalId = formData.get("view")
if auth.is_admin():
if not portalId:
response.setStatus(500)
obj.put("message", "No view specified to be deleted")
elif portalId != defaultPortal:
# sanity check: don't delete default portal
print "Deleting view '%s'" % portalId
try:
portalManager.remove(portalId)
obj.put("status", "ok")
obj.put("message", "View '%s' successfully removed" % portalId)
obj.put("url", "%s/%s/home" % (urlBase, defaultPortal))
except Exception, e:
obj.put("message", str(e))
else:
response.setStatus(500)
obj.put("message", "The default view cannot be deleted")
else:
response.setStatus(403)
obj.put("message", "Only administrative users can access this API")
示例5: modify_json
def modify_json(self):
# print "**** anotar.py : add_json() : adding json : " + json
jsonSimple = JsonSimple(self.json)
jsonObj = jsonSimple.getJsonObject()
jsonObj.put("id", self.pid)
rootUri = jsonSimple.getString(None, ["annotates", "rootUri"])
if rootUri is not None:
baseUrl = "http://%s:%s/" % (self.vc("request").serverName, self.vc("serverPort"))
myUri = baseUrl + rootUri + "#" + self.pid
jsonObj.put("uri", myUri)
jsonObj.put("schemaVersionUri", "http://www.purl.org/anotar/schema/0.1")
self.json = jsonSimple.toString()
示例6: __activate__
def __activate__(self, context):
self.velocityContext = context
oid = self.vc("formData").get("oid")
print "--- Creating ePub for: %s ---" % oid
try:
self.__epubMimetypeStream = None
self.__epubContainerStream = None
self.__epubcss = None
self.__orderedItem = []
self.__itemRefDict = {}
# get the package manifest
object = Services.getStorage().getObject(oid)
sourceId = object.getSourceId()
payload = object.getPayload(sourceId)
self.__manifest = JsonSimple(payload.open())
payload.close()
object.close()
# create the epub
self.__getDigitalItems(self.__manifest.getJsonSimpleMap("manifest"))
self.__createEpub()
except Exception, e:
log.error("Failed to create epub", e)
self.vc("response").setStatus(500)
writer = self.vc("response").getPrintWriter("text/plain; charset=UTF-8")
writer.println(str(e))
writer.close()
示例7: __activate__
def __activate__(self, context):
# Prepare variables
self.index = context["fields"]
self.object = context["object"]
self.payload = context["payload"]
self.params = context["params"]
self.utils = context["pyUtils"]
self.config = context["jsonConfig"]
self.wfSecurityExceptions = None
self.message_list = None
# Because the workflow messaging system wants access to this data
# BEFORE it actual hits the index we are going to cache it into an
# object payload too.
self.directIndex = JsonSimple()
# Common data
self.__newDoc()
#print "+++ direct-files.py - itemType='%s'" % self.itemType
# Real metadata
if self.itemType == "object":
self.__previews()
self.__basicData()
self.__metadata()
# Update the 'direct.index' payload - BEFORE messages are sent
directString = String(self.directIndex.toString())
inStream = ByteArrayInputStream(directString.getBytes("UTF-8"))
try:
StorageUtils.createOrUpdatePayload(self.object, "direct.index", inStream)
except StorageException, e:
print " * direct-files.py : Error updating direct payload"
self.__messages()
self.__displayType()
示例8: parseFFmpeg
def parseFFmpeg(self, parent):
if parent is not None:
object = parent.getObject()
if object is not None:
payload = None
try:
payload = object.getPayload("ffmpeg.info")
# Stream the content out to string
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
payload.close()
self.__ffmpegRaw = out.toString("UTF-8")
out.close()
payload.close()
# And parse it
self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
if self.__ffmpegData is None:
return False
else:
self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
return True
except:
if payload is not None:
payload.close()
return False
示例9: queryMoodle
def queryMoodle(self, usernames):
self.roleManager.setActivePlugin("moodle")
rolesMap = {}
courseMap = {}
# codeList = []
# yearList = []
# semesterList = []
# otherList = []
for username in usernames:
roles = self.roleManager.getRoles(username)
for role in roles:
thisRole = JsonSimple()
name = self.__dbGet(role)
if name is not None:
thisRole.getJsonObject().put("name", name)
psData = self.__dbGetPS(role)
if psData is not None:
thisRole.getJsonObject().put("psData", psData)
code, year, semester = psData.split("_")
if code not in self.codeList:
self.codeList.append(code)
if year not in self.yearList:
self.yearList.append(year)
if semester not in self.semesterList:
self.semesterList.append(semester)
courseMap["%s %s %s" % (code, year, semester)] = {"id": role, "name": name, "psData": psData}
else:
courseName = "%s_%s" % (name, role)
if courseName not in self.otherList:
self.otherList.append(courseName)
courseMap[courseName] = {"id": role, "name": name, "psData": None}
#otherList.append({"id": role, "name": name, "psData": None})
rolesMap[role] = thisRole
self.codeList.sort()
self.yearList.sort()
self.yearList.reverse()
self.semesterList.sort()
self.otherList.sort()
return courseMap
示例10: __getPackageTypes
def __getPackageTypes(self):
object = self.sysConfig.getObject(["portal", "packageTypes"])
packageTypes = JsonSimple.toJavaMap(object)
if packageTypes.isEmpty():
defaultPackage = JsonObject()
defaultPackage.put("jsonconfig", "packaging-config.json")
packageTypes.put("default", JsonSimple(defaultPackage))
return packageTypes
示例11: process_tags
def process_tags(self, result):
tags = []
tagsDict = {}
# Build a dictionary of the tags
for doc in result:
# Get Anotar data from Solr data
doc = JsonSimple(doc.get("jsonString"))
# Get actual tag text
tag = doc.getString(None, ["content", "literal"])
# Find out if they have locators
locs = doc.getJsonSimpleList(["annotates", "locators"]).size()
if locs == 0:
# Basic tags, just aggregate counts
if tag in tagsDict:
# We've seen it before, just increment the counter
existing = tagsDict[tag]
count = existing.getInteger(0, ["tagCount"])
existing.getJsonObject().put("tagCount", str(count + 1))
else:
# First time, store this object
doc.getJsonObject().put("tagCount", str(1))
tagsDict[tag] = doc
else:
# Tags with a locator, special case for images etc.
tags.append(doc.toString())
# Push all the 'basic' counts into the list to return
for tag in tagsDict:
tags.append(tagsDict[tag].toString())
return "[" + ",".join(tags) + "]"
示例12: __activate__
def __activate__(self, context):
self.roles = context["page"].authentication.get_roles_list()
self.config = context["systemConfig"]
workflows = JsonSimple.toJavaMap(self.config.getObject(["uploader"]))
self.uploaders = LinkedHashMap()
for workflow in workflows.keySet():
if workflows.get(workflow).getString("", ["upload-template"]):
for role in workflows.get(workflow).getArray(["security"]):
if str(role) in self.roles:
self.uploaders.put(workflow, workflows.get(workflow))
示例13: getJson
def getJson(self, state = "open"):
title = "%s (%s)" % (self.getName(), self.getCount())
json = JsonSimple()
jsonObj = json.getJsonObject()
attributes = JsonObject()
attributes.put("id", self.getId())
attributes.put("fq", self.getFacetQuery())
attributes.put("title", title)
jsonObj.put("data", title)
jsonObj.put("attributes", attributes)
hasSubFacets = not self.getSubFacets().isEmpty()
if hasSubFacets:
jsonObj.put("state", state)
subFacetList = ArrayList()
for subFacet in self.getSubFacets():
subFacetList.add(subFacet.getJson("closed"))
children = JSONArray()
children.addAll(subFacetList)
jsonObj.put("children", children)
return json
示例14: __activate__
def __activate__(self, context):
self.vc = context
responseType = "text/html; charset=UTF-8"
responseMsg = ""
func = self.vc("formData").get("func")
if func == "placeName":
try:
placeName = self.vc("formData").get("q")
url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName
client = BasicHttpClient(url)
get = GetMethod(url)
statusInt = client.executeMethod(get)
r = str(statusInt)
json = JsonSimple(get.getResponseBodyAsString().strip())
for geoName in json.getJsonSimpleList("geonames"):
responseMsg += "%s, %s|%s \n" % (geoName.getString(None, "name"), geoName.getString(None, "countryName"), geoName.getString(None, "geonameId"))
except Exception, e:
print "exception: ", str(e)
r = str(e), None
responseType = "text/plain; charset=UTF-8"
示例15: queryMoodle
def queryMoodle(self):
username = self.vc("formData").get("username")
# We are going to bypass the authentication Jython
# object to directly access the moodle plugin.
self.roleManager.setActivePlugin("moodle")
roles = self.roleManager.getRoles(username)
if len(roles) == 0:
self.throw_error("The given user is invalid or has no courses.")
else:
roleIds = []
roleList = []
# For each role (courseId)
for role in roles:
thisRole = JsonSimple()
# Query the database for the course's name
name = self.__dbGet(role)
if name is not None:
roleIds.append("\"" + role + "\"")
thisRole.getJsonObject().put("name", name)
psData = self.__dbGetPS(role)
if psData is not None:
thisRole.getJsonObject().put("psData", psData)
roleList.append("\"" + role + "\" : " + thisRole.toString())
keys = "\"keys\" : [" + ",".join(roleIds) + "]"
data = "\"data\" : {" + ",".join(roleList) + "}"
response = "{" + keys + "," + data + "}"
self.writer.println(response)
self.writer.close()