def addObjectToDom(*args, **kwargs): # required args object = kwargs['object'] doc = kwargs['doc'] service = kwargs['service'] type = kwargs['type'] ns_name = kwargs['ns_name'] ns_uri = kwargs['ns_uri'] try: #import pdb; pdb.set_trace() context = JAXBContext.newInstance(object.getClass()) marshaller = context.createMarshaller() import_element = doc.createElement("import") if 'return_schema' not in kwargs: import_element.setAttribute("seq", next_seq()) if 'csid' in kwargs: import_element.setAttribute("CSID", kwargs['csid']) import_element.setAttribute("service", service) import_element.setAttribute("type", type) doc.getDocumentElement().appendChild(import_element) marshaller.marshal(object, import_element) schema_element = import_element.getFirstChild() schema_element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:"+ns_name, ns_uri); doc.renameNode(schema_element, "", "schema") # rename root element to "schema", also remove default xmlns #cleanup schema_element.removeAttribute("xmlns:ns2") schema_element.removeAttribute("xmlns") schema_element.setAttribute("name",ns_name) # # add the namespace and prefix to everything renameNamespaceRecursive(doc,schema_element,ns_uri,ns_name) if 'extensions' in kwargs: for schema in kwargs['extensions']: import_element.appendChild(schema) if 'return_schema' in kwargs: return schema_element except Exception, e: print e
def __createPackage(self, outputFile=None): title = self.__manifest.getString(None, "title") manifest = self.__createManifest() context = JAXBContext.newInstance("com.googlecode.fascinator.ims") m = context.createMarshaller() m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, True) writer = StringWriter() jaxbElem = ObjectFactory.createManifest(ObjectFactory(), manifest) m.marshal(jaxbElem, writer) writer.close() if outputFile is not None: print "writing to %s..." % outputFile out = FileOutputStream(outputFile) else: print "writing to http output stream..." filename = urllib.quote(title.replace(" ", "_")) response.setHeader("Content-Disposition", "attachment; filename=%s.zip" % filename) out = response.getOutputStream("application/zip") zipOut = ZipOutputStream(out) zipOut.putNextEntry(ZipEntry("imsmanifest.xml")) IOUtils.write(writer.toString(), zipOut) zipOut.closeEntry() oidList = self.__manifest.search("id") for oid in oidList: obj = Services.getStorage().getObject(oid) for pid in obj.getPayloadIdList(): payload = obj.getPayload(pid) if not PayloadType.Annotation.equals(payload.getType()): zipOut.putNextEntry( ZipEntry("resources/%s/%s" % (oid, pid))) IOUtils.copy(payload.open(), zipOut) payload.close() zipOut.closeEntry() obj.close() zipOut.close() out.close()
def __createPackage(self, outputFile=None): title = self.__manifest.getString(None, "title") manifest = self.__createManifest() context = JAXBContext.newInstance("au.edu.usq.fascinator.ims") m = context.createMarshaller() m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, True) writer = StringWriter() jaxbElem = ObjectFactory.createManifest(ObjectFactory(), manifest) m.marshal(jaxbElem, writer) writer.close() if outputFile is not None: print "writing to %s..." % outputFile out = FileOutputStream(outputFile) else: print "writing to http output stream..." filename = urllib.quote(title.replace(" ", "_")) response.setHeader("Content-Disposition", "attachment; filename=%s.zip" % filename) out = response.getOutputStream("application/zip") zipOut = ZipOutputStream(out) zipOut.putNextEntry(ZipEntry("imsmanifest.xml")) IOUtils.write(writer.toString(), zipOut) zipOut.closeEntry() oidList = self.__manifest.search("id") for oid in oidList: obj = Services.getStorage().getObject(oid) for pid in obj.getPayloadIdList(): payload = obj.getPayload(pid) if not PayloadType.Annotation.equals(payload.getType()): zipOut.putNextEntry(ZipEntry("resources/%s/%s" % (oid, pid))) IOUtils.copy(payload.open(), zipOut) payload.close() zipOut.closeEntry() obj.close() zipOut.close() out.close()
def __createPackage(self, outputFile=None): manifest = self.__createManifest() context = JAXBContext.newInstance("au.edu.usq.fascinator.ims") m = context.createMarshaller() m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, True) writer = StringWriter() jaxbElem = ObjectFactory.createManifest(ObjectFactory(), manifest) m.marshal(jaxbElem, writer); writer.close() if outputFile is not None: print " * imscp.py: writing to %s..." % outputFile out = FileOutputStream(outputFile) else: print " * imscp.py: writing to http output stream..." response.setHeader("Content-Disposition", "attachment; filename=%s.zip" % self.__portal.getName()) out = response.getOutputStream("application/zip") zipOut = ZipOutputStream(out) zipOut.putNextEntry(ZipEntry("imsmanifest.xml")) IOUtils.write(writer.toString(), zipOut) zipOut.closeEntry() for key in self.__portalManifest.keySet(): item = self.__portalManifest.get(key) oid = item.get("id") obj = Services.getStorage().getObject(oid) for payload in obj.getPayloadList(): pid = payload.getId() if pid != "SOF-META": zipOut.putNextEntry(ZipEntry("%s/%s" % (key[5:], pid))) IOUtils.copy(payload.getInputStream(), zipOut) zipOut.closeEntry() zipOut.close() out.close()