List of usage examples for org.xml.sax SAXParseException getMessage
public String getMessage()
From source file:org.kuali.kfs.sys.exception.XmlErrorHandler.java
private String assembleMessage(String messageType, SAXParseException e) { StringBuffer message = new StringBuffer(messageType); message.append(" Parsing error was encountered on line "); message.append(e.getLineNumber());//from w w w. j a va 2s . c o m message.append(", column "); message.append(e.getColumnNumber()); message.append(": "); message.append(e.getMessage()); return message.toString(); }
From source file:org.lnicholls.galleon.util.Configurator.java
private void loadDocument(AppManager appManager, File file) { ServerConfiguration serverConfiguration = Server.getServer().getServerConfiguration(); // Need to handle previous version of configuration file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //factory.setValidating(true); //factory.setNamespaceAware(true); try {/*w w w . jav a2 s . co m*/ FileInputStream in = null; DocumentBuilder builder = factory.newDocumentBuilder(); in = new FileInputStream(file); Document document = builder.parse(in); in.close(); in = null; // <configuration> Node domNode = document.getFirstChild(); if (log.isDebugEnabled()) log.debug("document:" + domNode.getNodeName()); if (domNode.getNodeName().equalsIgnoreCase(TAG_CONFIGURATION)) { NamedNodeMap namedNodeMap = domNode.getAttributes(); if (namedNodeMap != null) { // Check for required attributes Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_VERSION); if (log.isDebugEnabled()) log.debug(domNode.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); loadDocument(domNode, appManager); if (!attribute.getNodeValue().equals(serverConfiguration.getVersion())) save(appManager); } } } catch (SAXParseException spe) { // Error generated by the parser log.error("Parsing error, line " + spe.getLineNumber() + ", uri " + spe.getSystemId()); log.error(" " + spe.getMessage()); Tools.logException(Configurator.class, spe); // Use the contained exception, if any Exception x = spe; if (spe.getException() != null) x = spe.getException(); Tools.logException(Configurator.class, x); } catch (SAXException sxe) { // Error generated during parsing) Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); Tools.logException(Configurator.class, x); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built log.error("Cannot get context" + file.getAbsolutePath()); Tools.logException(Configurator.class, pce); } catch (IOException ioe) { // I/O error log.error("Cannot get context" + file.getAbsolutePath()); Tools.logException(Configurator.class, ioe); } finally { } }
From source file:org.lnicholls.galleon.util.Configurator.java
private void loadDocument(Node configurationNode, AppManager appManager) { ServerConfiguration serverConfiguration = Server.getServer().getServerConfiguration(); try {/*from w ww . j ava 2s .c o m*/ // <server>, <app> for (int i = 0; i < configurationNode.getChildNodes().getLength(); i++) { Node node = configurationNode.getChildNodes().item(i); if (log.isDebugEnabled()) log.debug("node:" + node.getNodeName()); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals(TAG_SERVER)) { if (log.isDebugEnabled()) log.debug("Found server"); NamedNodeMap namedNodeMap = node.getAttributes(); if (namedNodeMap != null) { Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_RELOAD); // Required attributes if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); try { int reload = Integer.parseInt(attribute.getNodeValue()); serverConfiguration.setReload(reload); } catch (NumberFormatException ex) { log.error("Invalid " + ATTRIBUTE_RELOAD + " for " + TAG_SERVER + ": " + attribute.getNodeValue()); } } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PORT); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); try { int port = Integer.parseInt(attribute.getNodeValue()); serverConfiguration.setPort(port); } catch (NumberFormatException ex) { log.error("Invalid " + ATTRIBUTE_PORT + " for " + TAG_SERVER + ": " + attribute.getNodeValue()); } } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_HTTP_PORT); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); try { int port = Integer.parseInt(attribute.getNodeValue()); serverConfiguration.setHttpPort(port); } catch (NumberFormatException ex) { log.error("Invalid " + ATTRIBUTE_HTTP_PORT + " for " + TAG_SERVER + ": " + attribute.getNodeValue()); } } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_TITLE); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration.setName(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_IP_ADDRESS); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); String address = attribute.getNodeValue(); // Fix IP address if needed if (!Tools.isLocalAddress(address)) { log.error("Invalid server IP address: " + address); address = Tools.getLocalIpAddress(); log.debug("Changing IP address to: " + address); } serverConfiguration.setIPAddress(address); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PUBLIC_IP_ADDRESS); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration.setPublicIPAddress(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PIN); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue().length()); serverConfiguration.setPin(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PASSWORD); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue().length()); serverConfiguration.setPassword(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_SHUFFLE_ITEMS); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration .setShuffleItems(Boolean.valueOf(attribute.getNodeValue()).booleanValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_GENERATE_THUMBNAILS); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration.setGenerateThumbnails( Boolean.valueOf(attribute.getNodeValue()).booleanValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_RECORDINGS_PATH); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration.setRecordingsPath(Tools .unEscapeXMLChars(URLDecoder.decode(attribute.getNodeValue(), ENCODING))); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_MEDIA_ACCESS_KEY); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue().length()); serverConfiguration.setMediaAccessKey(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_SKIN); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue().length()); serverConfiguration.setSkin(attribute.getNodeValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_DEBUG); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration .setDebug(Boolean.valueOf(attribute.getNodeValue()).booleanValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_TIMEOUT); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration.setDisableTimeout( Boolean.valueOf(attribute.getNodeValue()).booleanValue()); } attribute = namedNodeMap.getNamedItem(ATTRIBUTE_MENU); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); serverConfiguration .setMenu(Boolean.valueOf(attribute.getNodeValue()).booleanValue()); } } } else if (node.getNodeName().equals(TAG_APP)) { if (log.isDebugEnabled()) log.debug("Found app"); NamedNodeMap namedNodeMap = node.getAttributes(); if (namedNodeMap != null) { String title = null; String className = null; Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_NAME); // Check for required attributes if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); title = attribute.getNodeValue(); } else log.error("Missing required " + ATTRIBUTE_NAME + " attribute for " + TAG_APP); attribute = namedNodeMap.getNamedItem(ATTRIBUTE_CLASS); if (attribute != null) { if (log.isDebugEnabled()) log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "=" + attribute.getNodeValue()); className = attribute.getNodeValue(); } else log.error("Missing required " + ATTRIBUTE_CLASS + " attribute for " + TAG_APP); if (className != null) { if (className.indexOf('$') != -1) className = className.substring(0, className.indexOf('$')); else className = className.substring(0, className.length() - "Configuration".length()); Object appConfiguration = null; Iterator appDescriptorIterator = appManager.getAppDescriptors().iterator(); while (appDescriptorIterator.hasNext()) { AppDescriptor appDescriptor = (AppDescriptor) appDescriptorIterator.next(); if (appDescriptor.getClassName().equals(className)) { AppContext appContext = new AppContext(appDescriptor); if (appContext.getConfiguration() != null) { try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("app", appContext.getConfiguration().getClass()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); appConfiguration = beanReader.parse(xmlReader); appContext.setConfiguration(appConfiguration); appManager.createApp(appContext); if (log.isDebugEnabled()) log.debug("App=" + appContext); } catch (IntrospectionException ex) { log.error("Could not load app " + title + " (" + className + ")"); } } else log.error("Could not find app " + title + " (" + className + ")"); } } if (appConfiguration == null) { log.error("Could not find app " + title + " (" + className + ")"); } } } } else if (node.getNodeName().equals(TAG_TIVO)) { if (log.isDebugEnabled()) log.debug("Found TiVo"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("tivo", TiVo.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); TiVo tivo = (TiVo) beanReader.parse(xmlReader); serverConfiguration.addTiVo(tivo); if (log.isDebugEnabled()) log.debug("TiVo=" + tivo); } catch (IntrospectionException ex) { log.error("Could not load tivo"); } } else if (node.getNodeName().equals(TAG_RULE)) { if (log.isDebugEnabled()) log.debug("Found Rule"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("rule", Rule.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); Rule rule = (Rule) beanReader.parse(xmlReader); serverConfiguration.addRule(rule); if (log.isDebugEnabled()) log.debug("Rule=" + rule); } catch (IntrospectionException ex) { log.error("Could not load rule"); } } else if (node.getNodeName().equals(TAG_MUSIC_PLAYER_CONFIGURATION)) { if (log.isDebugEnabled()) log.debug("Found Music Player Configuration"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("musicPlayerConfiguration", MusicPlayerConfiguration.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); MusicPlayerConfiguration musicPlayerConfiguration = (MusicPlayerConfiguration) beanReader .parse(xmlReader); serverConfiguration.setMusicPlayerConfiguration(musicPlayerConfiguration); if (log.isDebugEnabled()) log.debug("MusicPlayerConfiguration=" + musicPlayerConfiguration); } catch (IntrospectionException ex) { log.error("Could not load Music Player Configuration"); } } else if (node.getNodeName().equals(TAG_DATA_CONFIGURATION)) { if (log.isDebugEnabled()) log.debug("Found Data Configuration"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("dataConfiguration", DataConfiguration.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); DataConfiguration dataConfiguration = (DataConfiguration) beanReader.parse(xmlReader); serverConfiguration.setDataConfiguration(dataConfiguration); if (log.isDebugEnabled()) log.debug("DataConfiguration=" + dataConfiguration); } catch (IntrospectionException ex) { log.error("Could not load Data Configuration"); } } else if (node.getNodeName().equals(TAG_GOBACK_CONFIGURATION)) { if (log.isDebugEnabled()) log.debug("Found GoBack Configuration"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("goBackConfiguration", GoBackConfiguration.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); GoBackConfiguration goBackConfiguration = (GoBackConfiguration) beanReader .parse(xmlReader); serverConfiguration.setGoBackConfiguration(goBackConfiguration); if (log.isDebugEnabled()) log.debug("GoBackConfiguration=" + goBackConfiguration); } catch (IntrospectionException ex) { log.error("Could not load GoBack Configuration"); } } else if (node.getNodeName().equals(TAG_DOWNLOAD_CONFIGURATION)) { if (log.isDebugEnabled()) log.debug("Found Download Configuration"); try { BeanReader beanReader = new BeanReader(); beanReader.getXMLIntrospector().setAttributesForPrimitives(true); beanReader.registerBeanClass("downloadConfiguration", DownloadConfiguration.class); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputFormat of = new OutputFormat("XML", ENCODING, true); XMLSerializer serializer = new XMLSerializer(bos, of); serializer.asDOMSerializer(); serializer.serialize((Element) node); StringReader xmlReader = new StringReader(bos.toString()); bos.close(); DownloadConfiguration downloadConfiguration = (DownloadConfiguration) beanReader .parse(xmlReader); serverConfiguration.setDownloadConfiguration(downloadConfiguration); if (log.isDebugEnabled()) log.debug("DownloadConfiguration=" + downloadConfiguration); } catch (IntrospectionException ex) { log.error("Could not load Download Configuration"); } } } } } catch (SAXParseException spe) { // Error generated by the parser log.error("Parsing error, line " + spe.getLineNumber() + ", uri " + spe.getSystemId()); log.error(" " + spe.getMessage()); Tools.logException(Configurator.class, spe); // Use the contained exception, if any Exception x = spe; if (spe.getException() != null) x = spe.getException(); Tools.logException(Configurator.class, x); } catch (SAXException sxe) { // Error generated during parsing) Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); Tools.logException(Configurator.class, x); } catch (IOException ioe) { // I/O error Tools.logException(Configurator.class, ioe, "Cannot get context"); } catch (Exception ioe) { // I/O error Tools.logException(Configurator.class, ioe, "Cannot get context"); } finally { } }
From source file:ORG.oclc.os.SRW.SRUServerTester.java
public Document renderXML(String record) { Document document;//w ww . j a v a 2s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //factory.setValidating(true); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { // ignore fatal errors (an exception is guaranteed) @Override public void fatalError(SAXParseException exception) throws SAXException { } // treat validation errors as fatal @Override public void error(SAXParseException e) throws SAXParseException { throw e; } // dump warnings too @Override public void warning(SAXParseException err) throws SAXParseException { out("** Warning"); out(", line "); out(err.getLineNumber()); out(", uri "); out(err.getSystemId()); out('\n'); out(" "); out(err.getMessage()); out('\n'); } }); document = builder.parse(new InputSource(new StringReader(record))); } catch (java.io.IOException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } catch (javax.xml.parsers.ParserConfigurationException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } catch (org.xml.sax.SAXException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } return document; }
From source file:org.opencastproject.metadata.dublincore.DublinCoreXmlFormat.java
@Override public void error(SAXParseException e) throws SAXException { logger.warn("Error parsing DublinCore catalog: " + e.getMessage()); super.error(e); }
From source file:org.opencastproject.metadata.dublincore.DublinCoreXmlFormat.java
@Override public void fatalError(SAXParseException e) throws SAXException { logger.warn("Fatal error parsing DublinCore catalog: " + e.getMessage()); super.fatalError(e); }
From source file:org.opencastproject.metadata.dublincore.DublinCoreXmlFormat.java
@Override public void warning(SAXParseException e) throws SAXException { logger.warn("Warning parsing DublinCore catalog: " + e.getMessage()); super.warning(e); }
From source file:org.opencds.terminology.SimpleTerminologyManager.java
private void initialize() throws DSSRuntimeExceptionFault { // load code system OID to display name map and displayName to OID map String openCDSCodeSystems = SimpleKnowledgeRepository.getResourceAsString("resourceAttributes", "openCDSCodeSystems.xml"); XmlEntity codeSystemsRootEntity = null; try {//www .jav a 2 s. c o m codeSystemsRootEntity = XmlConverter.getInstance().unmarshalXml(openCDSCodeSystems, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault("SimpleTerminologyService.initialize() failed to unmarshall '" + openCDSCodeSystems + "' " + e.getMessage()); } // get target OpenCDS resource element ArrayList<XmlEntity> codeSystemEntitites = codeSystemsRootEntity.getChildrenWithLabel("codeSystem"); for (XmlEntity codeSystemEntity : codeSystemEntitites) { String codeSystemOid = codeSystemEntity.getAttributeValue("codeSystemOID"); String codeSystemDisplayName = codeSystemEntity.getAttributeValue("codeSystemDisplayName"); myCodeSystemOIDtoCodeSystemDisplayNameMap.put(codeSystemOid, codeSystemDisplayName); myCodeSystemDisplayNametoCodeSystemOIDMap.put(codeSystemDisplayName, codeSystemOid); log.trace("codeSystem: " + codeSystemOid + ", name: " + codeSystemDisplayName); } /* // load ConceptType name to value map String openCDSConceptTypes = SimpleKnowledgeRepository.getInstance().getResourceAsString("resourceAttributes","openCDSConceptTypes.xml"); XmlEntity conceptTypesfileRootEntity = null; try { conceptTypesfileRootEntity = XmlConverter.getInstance().unmarshalXml(openCDSConceptTypes, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault("SimpleTerminologyService.initialize() failed to unmarshall '" + openCDSConceptTypes + "' " + e.getMessage()); } // get target OpenCDS resource element ArrayList<XmlEntity> conceptTypeEntities = conceptTypesfileRootEntity.getChildrenWithLabel("ConceptType"); for (XmlEntity conceptTypeEntity : conceptTypeEntities) { myConceptTypesNametoConceptTypeMap.put(conceptTypeEntity.getAttributeValue("name"), conceptTypeEntity.getAttributeValue("value")); } */ /* * Above code replaced by single line below, since openCDSConceptTypes.xml file is deprecated in the KR, des 2012-03-14 */ // load ConceptType name to value map from OpenCDSConceptTypes.java OpenCDSConceptTypes.getOpenCdsConceptTypes(myConceptTypesNametoConceptTypeMap); // load concept specification files String extendedPath = "conceptMappingSpecifications//autoGeneratedMappings"; List<String> fileNames = SimpleKnowledgeRepository.listResourceNamesByType(extendedPath); loadEachFile(fileNames, extendedPath); String extendedPath2 = "conceptMappingSpecifications//manualMappings"; List<String> fileNames2 = SimpleKnowledgeRepository.listResourceNamesByType(extendedPath2); loadEachFile(fileNames2, extendedPath2); }
From source file:org.opencds.terminology.SimpleTerminologyManager.java
private void loadEachFile(List<String> fileNames, String extendedPath) throws DSSRuntimeExceptionFault { for (String fileName : fileNames) { String fileNameLowerCase = fileName.toLowerCase(); //so we catch .xml, .XML, .XmL, etc. des 20121112 if (fileNameLowerCase.endsWith(".xml")) // without this check, when packaged into jars, seems to find a filename of "" that gets processed {//from w ww . j a v a 2 s . c o m String fileXmlAsString = SimpleKnowledgeRepository.getResourceAsXML(extendedPath, fileName); XmlEntity fileNamesRootEntity = null; try { fileNamesRootEntity = XmlConverter.getInstance().unmarshalXml(fileXmlAsString, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleTerminologyService.initialize() failed to unmarshall '" + fileXmlAsString + "' " + e.getMessage()); } // get target OpenCDS concept XmlEntity openCdsConceptEntity = fileNamesRootEntity.getFirstChildWithLabel("openCdsConcept"); CD openCdsConcept = new CD(CodeSystems.CODE_SYSTEM_OID_OPENCDS_CONCEPTS, getCodeSystemFromOID(CodeSystems.CODE_SYSTEM_OID_OPENCDS_CONCEPTS), openCdsConceptEntity.getAttributeValue("code"), openCdsConceptEntity.getAttributeValue("displayName")); // get concept determination method XmlEntity conceptDeterminationMethodEntity = fileNamesRootEntity .getFirstChildWithLabel("conceptDeterminationMethod"); CD conceptDeterminationMethod = new CD(CodeSystems.CODE_SYSTEM_OID_OPENCDS_CONCEPTS, getCodeSystemFromOID(CodeSystems.CODE_SYSTEM_OID_OPENCDS_CONCEPTS), conceptDeterminationMethodEntity.getAttributeValue("code"), conceptDeterminationMethodEntity.getAttributeValue("displayName")); ObjectPair targetObjectPair = new ObjectPair(); targetObjectPair.setObject1(openCdsConcept); targetObjectPair.setObject2(conceptDeterminationMethod); log.trace("OpenCdsConcept: " + openCdsConcept.toString() + ", ConceptDeterminationMethod: " + conceptDeterminationMethod.toString() + ", mappingFile: " + fileName); // get members for code system XmlEntity membersForCodeSystemEntity = fileNamesRootEntity .getFirstChildWithLabel("membersForCodeSystem"); String codeSystem = membersForCodeSystemEntity.getAttributeValue("codeSystem"); for (XmlEntity csEntity : (ArrayList<XmlEntity>) membersForCodeSystemEntity.getChildren()) { CD cd = new CD(codeSystem, csEntity.getAttributeValue("code")); log.trace(" - OpenCdsConcept code: " + csEntity.getAttributeValue("code") + ", codeSystem: " + codeSystem.toString()); if ((myCdToOpenCdsConceptObjectPairSetMap != null) && (myCdToOpenCdsConceptObjectPairSetMap.containsKey(cd))) { HashSet<ObjectPair> targetSet = myCdToOpenCdsConceptObjectPairSetMap.get(cd); targetSet.add(targetObjectPair); } else { HashSet<ObjectPair> objectPairSet = new HashSet<ObjectPair>(); objectPairSet.add(targetObjectPair); myCdToOpenCdsConceptObjectPairSetMap.put(cd, objectPairSet); } } } } }
From source file:org.opencds.terminology.SimpleTerminologyManager.java
@Override /**/*from w w w . j ava 2 s . c om*/ * Returns a HashMap containing the OpenCDSConcepts supported by the terminology service. * * All OpenCDSConcept types are represented. If there are n matching OpenCDSConcepts for the type, an empty * HashSet is associated with the key. * * Key = supported OpenCDSConcept type enumerated in org.opencds.terminology.OpenCDSConceptTypes. * Target = HashSet of supported OpenCDSConcepts for type. * * @return */ public HashMap<String, HashSet<CD>> getSupportedOpenCDSConcepts() throws DSSRuntimeExceptionFault { HashMap<String, HashSet<CD>> mapToReturn = new HashMap<String, HashSet<CD>>(); // load config file with contents //InputStream configFileStream = this.getClass().getClassLoader().getResourceAsStream("SupportedConceptsConfigFile.xml"); //String configFileXmlAsString = StreamUtility.getInstance().getStringFromInputStream_depleteStream(configFileStream); String configFileXmlAsString = SimpleKnowledgeRepository.getResourceAsString("resourceAttributes", "supportedConceptsConfigFile.xml"); XmlEntity configFileRootEntity = null; try { configFileRootEntity = XmlConverter.getInstance().unmarshalXml(configFileXmlAsString, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SAXParseException in SimpleTerminologyManager.getSupportedOpenCDSConcepts: " + e.getMessage()); } for (XmlEntity supportedConceptsForTypeEntity : (ArrayList<XmlEntity>) configFileRootEntity.getChildren()) { String openCdsConceptType = supportedConceptsForTypeEntity.getFirstChildWithLabel("openCdsConceptType") .getValue(); ArrayList<XmlEntity> supportedOpenCdsConceptEntities = (ArrayList<XmlEntity>) supportedConceptsForTypeEntity .getChildrenWithLabel("supportedOpenCdsConcept"); HashSet<CD> openCdsConceptsForType = new HashSet<CD>(); for (XmlEntity supportedOpenCdsConceptEntity : supportedOpenCdsConceptEntities) { XmlEntity openCdsConceptEntity = supportedOpenCdsConceptEntity .getFirstChildWithLabel("openCdsConcept"); // CD openCdsConcept = new CD("2.16.840.1.113883.3.795.12.1.1", "OpenCDS concepts", openCdsConceptEntity.getAttributeValue("code"), openCdsConceptEntity.getAttributeValue("displayName")); CD openCdsConcept = new CD(CodeSystems.CODE_SYSTEM_OID_OPENCDS_CONCEPTS, "OpenCDS concepts", openCdsConceptEntity.getAttributeValue("code"), openCdsConceptEntity.getAttributeValue("displayName")); openCdsConceptsForType.add(openCdsConcept); } mapToReturn.put(openCdsConceptType, openCdsConceptsForType); } ArrayList<String> openCdsConceptTypes = OpenCDSConceptTypes.getOpenCdsConceptTypes(); for (String openCdsConceptType : openCdsConceptTypes) { if (!mapToReturn.containsKey(openCdsConceptType)) { mapToReturn.put(openCdsConceptType, new HashSet<CD>()); } } return mapToReturn; }