Example #1
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)
Example #2
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
Example #3
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
Example #4
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')
Example #5
0
 def _toXml(self):
     from org.jdom.output import XMLOutputter
     return XMLOutputter().outputString(self._javaDomElement)