def _process( self ): filename = "%s - contribution.xml"%self._target.getTitle() from MaKaC.common.output import outputGenerator, XSLTransformer xmlgen = XMLGen() xmlgen.initXml() outgen = outputGenerator(self.getAW(), xmlgen) xmlgen.openTag("event") outgen.confToXML(self._target.getConference(),0,1,1,showContribution=self._target.getId(), overrideCache=True) xmlgen.closeTag("event") basexml = xmlgen.getXml() path = Config.getInstance().getStylesheetsDir() stylepath = "%s.xsl" % (os.path.join(path,self._xmltype)) if self._xmltype != "standard" and os.path.exists(stylepath): try: parser = XSLTransformer(stylepath) data = parser.process(basexml) except: data = "Cannot parse stylesheet: %s" % sys.exc_info()[0] else: data = basexml self._req.headers_out["Content-Length"] = "%s"%len(data) cfg = Config.getInstance() mimetype = cfg.getFileTypeMimeType( "XML" ) self._req.content_type = """%s"""%(mimetype) self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename.replace("\r\n"," ") return data
def _process(self): filename = "%s - contribution.xml" % self._target.getTitle() from MaKaC.common.output import outputGenerator, XSLTransformer xmlgen = XMLGen() xmlgen.initXml() outgen = outputGenerator(self.getAW(), xmlgen) xmlgen.openTag("event") outgen.confToXML(self._target.getConference(), 0, 1, 1, showContribution=self._target.getId(), overrideCache=True) xmlgen.closeTag("event") basexml = xmlgen.getXml() path = Config.getInstance().getStylesheetsDir() stylepath = "%s.xsl" % (os.path.join(path, self._xmltype)) if self._xmltype != "standard" and os.path.exists(stylepath): try: parser = XSLTransformer(stylepath) data = parser.process(basexml) except: data = "Cannot parse stylesheet: %s" % sys.exc_info()[0] else: data = basexml self._req.headers_out["Content-Length"] = "%s" % len(data) cfg = Config.getInstance() mimetype = cfg.getFileTypeMimeType("XML") self._req.content_type = """%s""" % (mimetype) self._req.headers_out[ "Content-Disposition"] = """inline; filename="%s\"""" % cleanHTMLHeaderFilename( filename) return data
def _process(self): filename = "%s - contribution.xml" % self._target.getTitle() from MaKaC.common.output import outputGenerator, XSLTransformer xmlgen = XMLGen() xmlgen.initXml() outgen = outputGenerator(self.getAW(), xmlgen) xmlgen.openTag("event") outgen.confToXML(self._target.getConference(), 0, 1, 1, showContribution=self._target.getId(), overrideCache=True) xmlgen.closeTag("event") basexml = xmlgen.getXml() path = Config.getInstance().getStylesheetsDir() stylepath = "%s.xsl" % (os.path.join(path, self._xmltype)) if self._xmltype != "standard" and os.path.exists(stylepath): try: parser = XSLTransformer(stylepath) data = parser.process(basexml) except: data = "Cannot parse stylesheet: %s" % sys.exc_info()[0] else: data = basexml return send_file(filename, StringIO(data), 'XML')
def preProcess(self, results): path = Config.getInstance().getStylesheetsDir() xslt = XSLTransformer(os.path.join(path, 'marc2short.xsl')) result = [] finalXML = xslt.process(results) doc = minidom.parseString(finalXML) for elem in doc.getElementsByTagName("record"): # make sure it's not an empty (deleted) record if len(elem.getElementsByTagName("identifier")) > 0: result.append(self._processElem(elem)) return result
def _process( self ): filename = "%s - contribution.xml"%self._target.getTitle() from MaKaC.common.output import outputGenerator, XSLTransformer xmlgen = XMLGen() xmlgen.initXml() outgen = outputGenerator(self.getAW(), xmlgen) xmlgen.openTag("event") outgen.confToXML(self._target.getConference(),0,1,1,showContribution=self._target.getId(), overrideCache=True) xmlgen.closeTag("event") basexml = xmlgen.getXml() path = Config.getInstance().getStylesheetsDir() stylepath = "%s.xsl" % (os.path.join(path,self._xmltype)) if self._xmltype != "standard" and os.path.exists(stylepath): try: parser = XSLTransformer(stylepath) data = parser.process(basexml) except: data = "Cannot parse stylesheet: %s" % sys.exc_info()[0] else: data = basexml return send_file(filename, StringIO(data), 'XML')
def createCDSRecord(aw, IndicoID, LODBID, lectureTitle, lectureSpeakers, contentType, videoFormat, languages): '''Retrieve a MARC XML string for the given conference, then web upload it to CDS.''' # Initialize success flag, and result string to which we will append any errors. flagSuccess = True result = "" # generate the basic XML from which we will produce MARC XML for CDS and lecture.xml for micala basexml = getBasicXMLRepresentation(aw, IndicoID, contentType, videoFormat, languages) from MaKaC.common import Config marcxml = "" # Given the IndicoID, retrieve the type of talk and IDs, so we know which XSL file to use. parsed = parseIndicoID(IndicoID) # Choose the appropriate stylesheet: # - cds_marcxml_video_conference.xsl # - cds_marcxml_video_session.xsl # - cds_marcxml_video_contribution.xsl # - cds_marcxml_video_subcontribution.xsl styleSheet = "%s_%s.xsl" % ('cds_marcxml_video', parsed["type"]) stylePath = os.path.join(Config.getInstance().getStylesheetsDir(), styleSheet) if os.path.exists(stylePath): try: # Logger.get('RecMan').info("Trying to do XSLT using path %s" % stylePath) parser = XSLTransformer(stylePath) marcxml = parser.process(basexml) except Exception: flagSuccess = False result += _("Cannot parse stylesheet: %s") % sys.exc_info()[0] else: flagSuccess = False result += _("Stylesheet does not exist: %s") % stylePath # Uncomment these lines when debugging to see the basic XML representation that is being created. # f = open('/tmp/base.xml', 'w') # f.write(basexml) # f.close() # Uncomment these lines when debugging to see the MARC XML being submitted to CDS # f = open('/tmp/marc.xml', 'w') # f.write(marcxml) # f.close() # Submit MARC XML record to CDS data = urlencode({ "file": marcxml, "mode": "-ir" }) headers = {"User-Agent": "invenio_webupload"} url = CollaborationTools.getOptionValue("RecordingManager", "CDSUploadURL") if '%s' in url: callback_url = CollaborationTools.getOptionValue("RecordingManager", "CDSUploadCallbackURL") url = url % quote_plus(callback_url % IndicoID) req = Request(url, data, headers) # Logger.get('RecMan').debug("req = %s" % str(req)) try: f = urlopen(req) cds_response = f.read() # cds_response = "testing" # uncomment for debugging # Successful operations should result in a one-line message that looks like this: # [INFO] Some message here # anything else means there was an error if cds_response.lstrip()[0:6] != "[INFO]": flagSuccess = False result += _("CDS webupload response: %s\n") % cds_response except HTTPError, e: flagSuccess = False result += _("CDS returned an error when submitting to %s: %s\n") % (url, e)
# Given the IndicoID, retrieve the type of talk and IDs, so we know which XSL file to use. parsed = parseIndicoID(IndicoID) # Choose the appropriate stylesheet for the type of talk: # - micala_lecture_conference.xsl # - micala_lecture_session.xsl # - micala_lecture_contribution.xsl # - micala_lecture_subcontribution.xsl styleSheet = "%s_%s.xsl" % ('micala_lecture', parsed["type"]) stylePath = os.path.join(Config.getInstance().getStylesheetsDir(), styleSheet) if os.path.exists(stylePath): try: # Logger.get('RecMan').info("Trying to do XSLT using path %s" % stylePath) parser = XSLTransformer(stylePath) micalaxml = parser.process(basexml) except Exception, e: flagSuccess = False result += _("Cannot parse stylesheet: %s") % sys.exc_info()[0] else: flagSuccess = False result += _("Stylesheet does not exist: %s") % stylePath # temporary, for my own debugging # f = open('/tmp/micala.xml', 'w') # f.write(micalaxml) # f.close() # Web upload metadata to micala server if flagSuccess == True:
def createCDSRecord(aw, IndicoID, LODBID, lectureTitle, lectureSpeakers, contentType, videoFormat, languages): '''Retrieve a MARC XML string for the given conference, then web upload it to CDS.''' # Initialize success flag, and result string to which we will append any errors. flagSuccess = True result = "" # generate the basic XML from which we will produce MARC XML for CDS and lecture.xml for micala basexml = getBasicXMLRepresentation(aw, IndicoID, contentType, videoFormat, languages) from MaKaC.common import Config marcxml = "" # Given the IndicoID, retrieve the type of talk and IDs, so we know which XSL file to use. parsed = parseIndicoID(IndicoID) # Choose the appropriate stylesheet: # - cds_marcxml_video_conference.xsl # - cds_marcxml_video_session.xsl # - cds_marcxml_video_contribution.xsl # - cds_marcxml_video_subcontribution.xsl styleSheet = "%s_%s.xsl" % ('cds_marcxml_video', parsed["type"]) stylePath = os.path.join(Config.getInstance().getStylesheetsDir(), styleSheet) if os.path.exists(stylePath): try: # Logger.get('RecMan').info("Trying to do XSLT using path %s" % stylePath) parser = XSLTransformer(stylePath) marcxml = parser.process(basexml) except Exception: flagSuccess = False result += _("Cannot parse stylesheet: %s") % sys.exc_info()[0] else: flagSuccess = False result += _("Stylesheet does not exist: %s") % stylePath # Uncomment these lines when debugging to see the basic XML representation that is being created. # f = open('/tmp/base.xml', 'w') # f.write(basexml) # f.close() # Uncomment these lines when debugging to see the MARC XML being submitted to CDS # f = open('/tmp/marc.xml', 'w') # f.write(marcxml) # f.close() # Submit MARC XML record to CDS data = urlencode({"file": marcxml, "mode": "-ir"}) headers = {"User-Agent": "invenio_webupload"} url = CollaborationTools.getOptionValue("RecordingManager", "CDSUploadURL") if '%s' in url: callback_url = CollaborationTools.getOptionValue( "RecordingManager", "CDSUploadCallbackURL") url = url % quote_plus(callback_url % IndicoID) req = Request(url, data, headers) # Logger.get('RecMan').debug("req = %s" % str(req)) try: f = urlopen(req) cds_response = f.read() # cds_response = "testing" # uncomment for debugging # Successful operations should result in a one-line message that looks like this: # [INFO] Some message here # anything else means there was an error if cds_response.lstrip()[0:6] != "[INFO]": flagSuccess = False result += _("CDS webupload response: %s\n") % cds_response except HTTPError, e: flagSuccess = False result += _("CDS returned an error when submitting to %s: %s\n") % ( url, e)