def __activate__(self, context): self.velocityContext = context responseType = "text/html; charset=UTF-8" responseMsg = "" func = self.vc("formData").get("func") if func == "url-history": responseType = "text/plain; charset=UTF-8" responseMsg = "\n".join(self.getUrls()) else: try: url = self.vc("formData").get("url") title = self.vc("formData").get("title") username = self.vc("formData").get("username") password = self.vc("formData").get("password") try: auth = ProxyBasicAuthStrategy(username, password, url) self.__service = AtomClientFactory.getAtomService(url, auth) oid = self.vc("formData").get("oid") if oid is not None: self.__object = Services.getStorage().getObject(oid) sourceId = self.__object.getSourceId() payload = self.__object.getPayload(sourceId) print "payload=%s,%s" % (payload, payload.getContentType()) # FIXME see https://fascinator.usq.edu.au/trac/ticket/647 if payload and sourceId.endswith(".tfpackage"): #payload.getContentType() == "application/x-fascinator-package": jsonManifest = JsonConfigHelper(payload.open()) #print jsonManifest.toString() content = self.__getManifestContent(jsonManifest) payload.close() else: content = self.__getContent(oid) self.__object.close() else: content = "<div>Object not found!</div>" success, value = self.__post(title, content) except Exception, e: e.printStackTrace() success = False value = e.getMessage() if success: altLinks = value.getAlternateLinks() if altLinks is not None: self.saveUrl(url) responseMsg = "<p>Success! Visit the <a href='%s' target='_blank'>blog post</a>.</p>" % altLinks[0].href else: responseMsg = "<p class='warning'>The server did not return a valid link!</p>" else: responseMsg = "<p class='error'>%s</p>" % value except Exception, e: print "Failed to post: %s" % e.getMessage() responseMsg = "<p class='error'>%s</p>" % e.getMessage()
def __init__(self): responseType = "text/html" responseMsg = "" func = formData.get("func") if func == "url-history": responseType = "text/plain" responseMsg = "\n".join(self.getUrls()) else: try: url = formData.get("url") title = formData.get("title") username = formData.get("username") password = formData.get("password") try: auth = ProxyBasicAuthStrategy(username, password, url) self.__service = AtomClientFactory.getAtomService(url, auth) oid = formData.get("oid") if oid is not None: content = self.__getContent(oid) else: content = self.__getManifestContent(formData.get("portalId")) success, value = self.__post(title, content) except Exception, e: e.printStackTrace() success = False value = e.getMessage() if success: altLinks = value.getAlternateLinks() if altLinks is not None: self.saveUrl(url) responseMsg = "<p>Success! Visit the <a href='%s' target='_blank'>blog post</a>.</p>" % altLinks[0].href else: responseMsg = "<p class='warning'>The server did not return a valid link!</p>" else: responseMsg = "<p class='error'>%s</p>" % value except Exception, e: print " * blog.py: Failed to post: %s" % e.getMessage() responseMsg = "<p class='error'>%s</p>" % e.getMessage()
def __init__(self): responseMsg = "" try: url = formData.get("url") title = formData.get("title") username = formData.get("username") password = formData.get("password") try: auth = ProxyBasicAuthStrategy(username, password, url) self.__service = AtomClientFactory.getAtomService(url, auth) content = self.__getContent(formData.get("oid")) success, value = self.__post(title, content) except Exception, e: e.printStackTrace() success = False value = e.getMessage() if success: altLinks = value.getAlternateLinks() if altLinks is not None: responseMsg = "<p>Success! Visit the <a href='%s' target='_blank'>blog post</a>.</p>" % altLinks[0].href else: responseMsg = "<p class='warning'>The server did not return a valid link!</p>" else: responseMsg = "<p class='error'>%s</p>" % value