Beispiel #1
0
        def doPost(self, request, response):
                FITS_HOME = "/usr/share/tomcat5.5/webapps/media/WEB-INF/lib/fits/"

                # retrieve the file to the local filesystem.. future version of
                # FITS may make this unnecessary
                url = request.getParameterValues('url')[0]
                outfile = NamedTemporaryFile()
                getLocalFile(url, outfile.name)
                inputFile = java.io.File(outfile.name)

                # Init the java packages
                setClassPath(FITS_HOME)
                from edu.harvard.hul.ois.fits import Fits
                from org.jdom.output import Format
                from org.jdom.output import XMLOutputter
                f = Fits(FITS_HOME)
                res = f.examine(inputFile)
                doc = res.getFitsXml()

                # write the FITS XML response
                toClient = response.getWriter()
                response.setContentType("text/xml")
                o = XMLOutputter(Format.getPrettyFormat())
                o.output(doc, toClient)

                # cleanup
                outfile.close()
Beispiel #2
0
def DiscoveryMain(Framework):
	logger.info('Start Phase 1 ... Pull from ARIS')

	# Set global framework
	global theFramework
	theFramework = Framework

	## Make sure we have an input data file from ARIS
	ARISfileName = Framework.getParameter('ARIS_XML_file') or None
	ARISfile = File(ARISfileName)
	if not (ARISfile and ARISfile.exists() and ARISfile.canRead()):
		excInfo = ('ARIS XML input file is not specified or is invalid!')
		Framework.reportError(excInfo)
		logger.error(excInfo)
		return None

	## Check that the language parameter is set - default to US English
	requestedLocaleID = Framework.getParameter('ARISLocaleId') or '&LocaleId.USen;'
	if not requestedLocaleID:
		logger.warn('ARIS LocaleID parameter is not set...defaulting to US English')
		requestedLocaleID = '&LocaleId.USen;'

	# File and directory names
	userExtDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + '\\TQLExport\\ARIS\\'
	intermediatesDir = userExtDir + 'inter\\'
	mapingFilesListFileName = userExtDir + 'tqls.txt'
	mappingFileNameList = checkDiscoveryResources(mapingFilesListFileName, userExtDir, Framework, intermediatesDir)
	if not mappingFileNameList:
		return None

	## Get attribute names from mapping file(s)
	## This is a list of extended attributes to be retrieved from ARIS
	for mappingFileName in mappingFileNameList:
		(requestedSourceObjectTypeList, requestedSourceRelationshipTypeList) = getMapping(userExtDir + 'data\\' + mappingFileName + '.xml')
		if requestedSourceObjectTypeList and requestedSourceRelationshipTypeList:
			arisObjectMap = processARISXML(ARISfile, requestedSourceObjectTypeList, requestedSourceRelationshipTypeList, requestedLocaleID)
			intermediateXmlDoc = None
			if arisObjectMap:
				intermediateXmlDoc = buildIntermediateXML(arisObjectMap)
				intermediateXmlLocation = intermediatesDir + mappingFileName + '.xml'
			else:
				Framework.reportWarning('No CIs found in the ARIS XML file')

			if intermediateXmlDoc:
				try:
					xmlOutputter = XMLOutputter()
					xmlOutputter.output(intermediateXmlDoc, FileOutputStream(intermediateXmlLocation))
				except:
					excInfo = logger.prepareJythonStackTrace('')
					Framework.reportError('Error writing intermediate file: <%s>' % intermediateXmlLocation)
					logger.warn('[' + SCRIPT_NAME + ':DiscoveryMain] Exception: <%s>' % excInfo)
					pass
			else:
				Framework.reportWarning('Error creating intermediate XML')
		else:
			logger.warn('[' + SCRIPT_NAME + ':DiscoveryMain] Unable to process mapping file: <%s>' % mappingFileName)
			Framework.reportError(' Unable to process mapping file: <%s>' % mappingFileName)

	logger.info('End Phase 1.... Pull from ARIS')
Beispiel #3
0
def writeXmlFile(fileName, xmlData):
    try:
        outputFile = "%s%s%s" % (adapterResWorkDir, FILE_SEPARATOR, fileName)
        outputStream = FileOutputStream(outputFile)
        output = XMLOutputter()
        output.output(xmlData, outputStream)
        logger.debug("Created push debug file: " + outputFile)
        outputStream.close()
    except IOError, ioe:
        logger.debug(ioe)
Beispiel #4
0
def writeXmlFile(fileName, xmlData):
    try:
        outputFile   = "%s%s%s" % (adapterResWorkDir, FILE_SEPARATOR, fileName)
        outputStream = FileOutputStream(outputFile)
        output       = XMLOutputter()
        output.output(xmlData, outputStream)
        logger.debug("Created push debug file: " + outputFile)
        outputStream.close()
    except IOError, ioe:
        logger.debug(ioe)
def createGRLoaderXmlInputFile(fileName, xmlDoc):
    xmlInputFileStr = "%s%s%s" % (adapterResWorkDir, FILE_SEPARATOR, fileName)
    try:
        logger.debug("\tCreating GRLoader input XML file")
        fileOutputStream = FileOutputStream(xmlInputFileStr)
        output = XMLOutputter()
        output.output(xmlDoc, fileOutputStream)
        fileOutputStream.close()
        logger.debug("\tCreated GRLoader input XML file: %s" % xmlInputFileStr)
    except:
        raise Exception, "Unable to create GR Loader Input XML File"
    return xmlInputFileStr
Beispiel #6
0
def createGRLoaderXmlInputFile(fileName, xmlDoc):
    xmlInputFileStr = "%s%s%s" % (adapterResWorkDir, FILE_SEPARATOR, fileName)
    try:
        logger.debug("\tCreating GRLoader input XML file")
        fileOutputStream = FileOutputStream(xmlInputFileStr)
        output = XMLOutputter()
        output.output(xmlDoc, fileOutputStream)
        fileOutputStream.close()
        logger.debug("\tCreated GRLoader input XML file: %s" % xmlInputFileStr)
    except:
        raise Exception, "Unable to create GR Loader Input XML File"
    return xmlInputFileStr
Beispiel #7
0
from java.net import URL
from java.lang import System
from java.util import Date

from org.jdom.output import XMLOutputter
from org.jdom.contrib.beans import BeanMapper

from de.nava.informa.impl.basic import Item

# create test bean
item = Item("Bugo", "All about it!", URL("http://nava.de/huhu2002"))
item.setFound(Date())

# bean -> jdom
mapper = BeanMapper()
mapper.setBeanPackage("de.nava.informa.impl.basic")

# problems with mapping an URL object
mapper.ignoreProperty("link")

doc = mapper.toDocument(item)
o = XMLOutputter("  ", 1)
o.output(doc, System.out)

# may throw BeanMapperException
Beispiel #8
0
def DiscoveryMain(Framework):
    logger.info('Start Phase 1 ... Pull from ARIS')

    # Set global framework
    global theFramework
    theFramework = Framework

    ## Make sure we have an input data file from ARIS
    ARISfileName = Framework.getParameter('ARIS_XML_file') or None
    ARISfile = File(ARISfileName)
    if not (ARISfile and ARISfile.exists() and ARISfile.canRead()):
        excInfo = ('ARIS XML input file is not specified or is invalid!')
        Framework.reportError(excInfo)
        logger.error(excInfo)
        return None

    ## Check that the language parameter is set - default to US English
    requestedLocaleID = Framework.getParameter(
        'ARISLocaleId') or '&LocaleId.USen;'
    if not requestedLocaleID:
        logger.warn(
            'ARIS LocaleID parameter is not set...defaulting to US English')
        requestedLocaleID = '&LocaleId.USen;'

    # File and directory names
    userExtDir = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder(
    ) + '\\TQLExport\\ARIS\\'
    intermediatesDir = userExtDir + 'inter\\'
    mapingFilesListFileName = userExtDir + 'tqls.txt'
    mappingFileNameList = checkDiscoveryResources(mapingFilesListFileName,
                                                  userExtDir, Framework,
                                                  intermediatesDir)
    if not mappingFileNameList:
        return None

    ## Get attribute names from mapping file(s)
    ## This is a list of extended attributes to be retrieved from ARIS
    for mappingFileName in mappingFileNameList:
        (requestedSourceObjectTypeList,
         requestedSourceRelationshipTypeList) = getMapping(userExtDir +
                                                           'data\\' +
                                                           mappingFileName +
                                                           '.xml')
        if requestedSourceObjectTypeList and requestedSourceRelationshipTypeList:
            arisObjectMap = processARISXML(
                ARISfile, requestedSourceObjectTypeList,
                requestedSourceRelationshipTypeList, requestedLocaleID)
            intermediateXmlDoc = None
            if arisObjectMap:
                intermediateXmlDoc = buildIntermediateXML(arisObjectMap)
                intermediateXmlLocation = intermediatesDir + mappingFileName + '.xml'
            else:
                Framework.reportWarning('No CIs found in the ARIS XML file')

            if intermediateXmlDoc:
                try:
                    xmlOutputter = XMLOutputter()
                    xmlOutputter.output(
                        intermediateXmlDoc,
                        FileOutputStream(intermediateXmlLocation))
                except:
                    excInfo = logger.prepareJythonStackTrace('')
                    Framework.reportError(
                        'Error writing intermediate file: <%s>' %
                        intermediateXmlLocation)
                    logger.warn('[' + SCRIPT_NAME +
                                ':DiscoveryMain] Exception: <%s>' % excInfo)
                    pass
            else:
                Framework.reportWarning('Error creating intermediate XML')
        else:
            logger.warn(
                '[' + SCRIPT_NAME +
                ':DiscoveryMain] Unable to process mapping file: <%s>' %
                mappingFileName)
            Framework.reportError(' Unable to process mapping file: <%s>' %
                                  mappingFileName)

    logger.info('End Phase 1.... Pull from ARIS')

from java.net import URL
from java.lang import System
from java.util import Date

from org.jdom.output import XMLOutputter
from org.jdom.contrib.beans import BeanMapper

from de.nava.informa.impl.basic import Item



# create test bean
item = Item("Bugo", "All about it!", URL("http://nava.de/huhu2002"))
item.setFound(Date())

# bean -> jdom
mapper = BeanMapper()
mapper.setBeanPackage("de.nava.informa.impl.basic")

# problems with mapping an URL object
mapper.ignoreProperty("link")

doc = mapper.toDocument(item)
o = XMLOutputter("  ", 1)
o.output(doc, System.out)

# may throw BeanMapperException
 def _toXml(self):
     from org.jdom.output import XMLOutputter
     return XMLOutputter().outputString(self._javaDomElement)