Exemplo n.º 1
0
	def __doTransform(self):
		"""Do the work."""

		uri = fixUri(self.uri)

		# Get template
		tplFile = getTemplate(self.uri)
		if not tplFile:
			print "Could not find matching template file for the URI."
			print "Uri was %s" % self.uri
			return False

		# TODO: Temp fix
		trypath = "./" + tplFile
		if exists(trypath):
			tplFile = trypath
		else:
			tplFile = "./web2rdf/" + tplFile

		self.webTransform = WebTransform(self.uri)

		# Web Cache logic
		cachef = CacheMap(self.uri)
		if not cachef.exists() or cachef.isExpired():
			self.webTransform.download()
			self.webTransform.saveHtml(cachef.getCacheFilename())
		else:
			self.webTransform.load(cachef.getCacheFilename())
		
		# Convert & save result
		self.webTransform.convertWithXslt(tplFile)
Exemplo n.º 2
0
class Web2Rdf(object):
	"""Web2Rdf controller class"""

	def __init__(self, uri):
		"""CTOR."""
		self.uri = uri
		self.webTransform = None

	def saveRdf(self, filename = None):
		"""Saves the RDF to a file"""
		if not self.webTransform:
			self.__doTransform()

		if not self.webTransform:
			return False

		if not filename:
			cachef = CacheMap(self.uri)
			filename = cachef.getCacheFilename() + ".cache.rdf"

		print "Saving to %s. " % filename
		self.webTransform.saveRdf(filename)

	def getRdf(self):
		"""Returns the RDF string."""
		if not self.webTransform:
			self.__doTransform()

		if not self.webTransform:
			return False

		# Get the RDF string.
		return str(self.webTransform.rdf)
		
	def __doTransform(self):
		"""Do the work."""

		uri = fixUri(self.uri)

		# Get template
		tplFile = getTemplate(self.uri)
		if not tplFile:
			print "Could not find matching template file for the URI."
			print "Uri was %s" % self.uri
			return False

		# TODO: Temp fix
		trypath = "./" + tplFile
		if exists(trypath):
			tplFile = trypath
		else:
			tplFile = "./web2rdf/" + tplFile

		self.webTransform = WebTransform(self.uri)

		# Web Cache logic
		cachef = CacheMap(self.uri)
		if not cachef.exists() or cachef.isExpired():
			self.webTransform.download()
			self.webTransform.saveHtml(cachef.getCacheFilename())
		else:
			self.webTransform.load(cachef.getCacheFilename())
		
		# Convert & save result
		self.webTransform.convertWithXslt(tplFile)