Mercurial > hg > ISMI_JSONClient
changeset 3:3532f1c49efb
changes for new apu
author | dwinter |
---|---|
date | Thu, 13 Dec 2012 19:29:05 -0500 |
parents | e6c3334e9611 |
children | ceac1f8e896f |
files | .pydevproject JSONClient.py |
diffstat | 2 files changed, 54 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/.pydevproject Wed May 30 16:53:45 2012 +0200 +++ b/.pydevproject Thu Dec 13 19:29:05 2012 -0500 @@ -2,6 +2,6 @@ <?eclipse-pydev version="1.0"?> <pydev_project> -<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> +<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python2.7_zope</pydev_property> <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property> </pydev_project>
--- a/JSONClient.py Wed May 30 16:53:45 2012 +0200 +++ b/JSONClient.py Thu Dec 13 19:29:05 2012 -0500 @@ -8,6 +8,8 @@ import os.path import logging +from lxml import etree + from BTrees.OOBTree import OOBTree class JSONClient(SimpleItem): @@ -42,7 +44,7 @@ def getEntityLink(self,entId): - return "https://openmind-ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.iface?eid="+str(entId) + return "https://openmind-ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.xhtml?eid="+str(entId) def json(self,method,params={},cache=True): """json aufruf""" @@ -64,28 +66,29 @@ def mapEntityAttributesToData(self,entity,type): - attrs=entity.get('attributes') + logging.debug(entity) + attrs=entity.get('atts') attrsHash={} for attr in attrs: - attrsHash[attr.get('name')]=attr.get('ownValue') + attrsHash[attr.get('name')]=attr.get('ov') attrsHash['@type']=type return attrsHash def getOV(self,entId): if (entId)<0: #-1 falls keine Entity gefunden wurde return"" - obj=self.json("getEntity", {'entId':entId}) - return obj.get('entity').get('ownValue') + obj=self.json("get_ent", {'id':entId}) + return obj.get('ent').get('ov') - def getSingleRelationFromEntity(self,jsonHash,type="srcRelations",relName=None,idType="sourceId"): + def getSingleRelationFromEntity(self,jsonHash,type="src_Rrels",relName=None,idType="src_id"): ret = self.getRelationFromEntity(jsonHash,type,relName,maxNum=1) if len(ret)==0: return -1 else: return ret[0].get(idType) - def getRelationFromEntity(self,jsonHash,type="srcRelations",relName=None,maxNum=30): - hash=jsonHash.get("entity") + def getRelationFromEntity(self,jsonHash,type="src_rels",relName=None,maxNum=3000): + hash=jsonHash.get("ent") logging.debug(type) logging.debug(".................") logging.debug(hash) @@ -263,6 +266,45 @@ self._v_jsonCache.update({cacheName:caches}) return hash.get(letter,[]), hash.keys() + + + def xsltTransform(self,path=None,pathXML=None,pathXSL=None,entID=None): + """xlst""" + if path is not None: + pathXML=path+".xml" + pathXSL=path+".xsl" + + + logging.debug(pathXML) + logging.debug(pathXSL) + + url=self.REQUEST['URL2'] + xmlURL=url+pathXML + xslURL=url+pathXSL + + + + logging.debug(xmlURL) + logging.debug(xslURL) + + + + f= urllib.urlopen(xslURL); + txt= f.read() + xslt_root=etree.fromstring(txt) + #xslt_root= etree.parse(xslURL) #verstehe nicht warum das nicht geht?? + + f= urllib.urlopen(xmlURL+"?id="+entID); + txt= f.read() + xml=etree.fromstring(txt) + #xml= etree.parse(xmlURL+"?id="+entID) + + transform=etree.XSLT(xslt_root) + + + result =transform(xml) + return unicode(result) + def manage_addJSONClient(self,id,url,RESPONSE=None): """add a json client""" @@ -280,7 +322,9 @@ pt=zptFile(self, 'zpt/AddJSONClientForm.zpt') return pt() - + + + def zptFile(self, path, orphaned=False): """returns a page template file from the product""" if orphaned: