List of usage examples for org.xml.sax SAXParseException getCause
public Throwable getCause()
From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java
/** Read the CrawlerSettings object from a specific file. * * @param settings the settings object to be updated with data from the * persistent storage.// w w w .j a v a 2 s. c o m * @param f the file to read from. * @return the updated settings object or null if there was no data for this * in the persistent storage. */ protected final CrawlerSettings readSettingsObject(CrawlerSettings settings, File f) { CrawlerSettings result = null; try { InputStream is = null; if (!f.exists()) { // Perhaps the file we're looking for is on the CLASSPATH. // DON'T look on the CLASSPATH for 'settings.xml' files. The // look for 'settings.xml' files happens frequently. Not looking // on classpath for 'settings.xml' is an optimization based on // ASSUMPTION that there will never be a 'settings.xml' saved // on classpath. if (!f.getName().startsWith(settingsFilename)) { is = XMLSettingsHandler.class.getResourceAsStream(f.getPath()); } } else { is = new FileInputStream(f); } if (is != null) { XMLReader parser = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); InputStream file = new BufferedInputStream(is); parser.setContentHandler(new CrawlSettingsSAXHandler(settings)); InputSource source = new InputSource(file); source.setSystemId(f.toURL().toExternalForm()); parser.parse(source); result = settings; } } catch (SAXParseException e) { logger.warning(e.getMessage() + " in '" + e.getSystemId() + "', line: " + e.getLineNumber() + ", column: " + e.getColumnNumber()); } catch (SAXException e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (ParserConfigurationException e) { logger.warning(e.getMessage() + ": " + e.getCause().getMessage()); } catch (FactoryConfigurationError e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (IOException e) { logger.warning("Could not access file '" + f.getAbsolutePath() + "': " + e.getMessage()); } return result; }
From source file:org.archive.crawler.settings.XMLSettingsHandler.java
/** Read the CrawlerSettings object from a specific file. * * @param settings the settings object to be updated with data from the * persistent storage.// w w w .ja v a2s . co m * @param f the file to read from. * @return the updated settings object or null if there was no data for this * in the persistent storage. */ protected final CrawlerSettings readSettingsObject(CrawlerSettings settings, File f) { CrawlerSettings result = null; try { InputStream is = null; if (!f.exists()) { // Perhaps the file we're looking for is on the CLASSPATH. // DON'T look on the CLASSPATH for 'settings.xml' files. The // look for 'settings.xml' files happens frequently. Not looking // on classpath for 'settings.xml' is an optimization based on // ASSUMPTION that there will never be a 'settings.xml' saved // on classpath. if (!f.getName().startsWith(settingsFilename)) { is = XMLSettingsHandler.class.getResourceAsStream(toResourcePath(f)); } } else { is = new FileInputStream(f); } if (is != null) { XMLReader parser = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); InputStream file = new BufferedInputStream(is); parser.setContentHandler(new CrawlSettingsSAXHandler(settings)); InputSource source = new InputSource(file); source.setSystemId(f.toURL().toExternalForm()); parser.parse(source); result = settings; } } catch (SAXParseException e) { logger.warning(e.getMessage() + " in '" + e.getSystemId() + "', line: " + e.getLineNumber() + ", column: " + e.getColumnNumber()); } catch (SAXException e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (ParserConfigurationException e) { logger.warning(e.getMessage() + ": " + e.getCause().getMessage()); } catch (FactoryConfigurationError e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (IOException e) { logger.warning("Could not access file '" + f.getAbsolutePath() + "': " + e.getMessage()); } return result; }
From source file:org.eclipse.rdf4j.http.server.repository.statements.StatementsController.java
/** * Process several actions as a transaction. *///w w w . j a va2s . c o m private ModelAndView getTransactionResultResult(Repository repository, HttpServletRequest request, HttpServletResponse response) throws IOException, ClientHTTPException, ServerHTTPException, HTTPException { InputStream in = request.getInputStream(); try (RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request)) { logger.debug("Processing transaction..."); TransactionReader reader = new TransactionReader(); Iterable<? extends TransactionOperation> txn = reader.parse(in); repositoryCon.begin(); for (TransactionOperation op : txn) { op.execute(repositoryCon); } repositoryCon.commit(); logger.debug("Transaction processed "); return new ModelAndView(EmptySuccessView.getInstance()); } catch (SAXParseException e) { ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_DATA, e.getMessage()); throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString()); } catch (SAXException e) { throw new ServerHTTPException("Failed to parse transaction data: " + e.getMessage(), e); } catch (IOException e) { throw new ServerHTTPException("Failed to read data: " + e.getMessage(), e); } catch (RepositoryException e) { if (e.getCause() != null && e.getCause() instanceof HTTPException) { // custom signal from the backend, throw as HTTPException // directly // (see SES-1016). throw (HTTPException) e.getCause(); } else { throw new ServerHTTPException("Repository update error: " + e.getMessage(), e); } } }
From source file:org.opencds.knowledgeRepository.SimpleKnowledgeRepository.java
protected static void initialize(String submittedFullPathToKRData) throws DSSRuntimeExceptionFault { String startTime = DateUtility.getInstance().getDateAsString(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"); System.out.println();/* www . j av a 2 s .c o m*/ System.out.println( startTime + " <<< Initializing OpenCDS SimpleKnowledgeRepository at " + fullPathToKRData + " >>>"); // save the fullPathToKRData where we can use it. fullPathToKRData = submittedFullPathToKRData.trim(); // add a trailing / if it is missing... if (!"/".equals(fullPathToKRData.substring(fullPathToKRData.length()))) { fullPathToKRData = fullPathToKRData + "/"; } log.info("Path to SimpleKnowledgeRepository data: " + fullPathToKRData); // read executionEngines resource String executionEngines = ""; try { executionEngines = getResourceAsString("resourceAttributes", "openCdsExecutionEngines.xml"); } catch (DSSRuntimeExceptionFault e1) { e1.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to getResourceAsString('resourceAttributes','openCdsExecutionEngines.xml': " + e1.getCause()); } XmlEntity executionEnginesRootEntity = null; try { executionEnginesRootEntity = XmlConverter.getInstance().unmarshalXml(executionEngines, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to unmarshall openCdsExecutionEngines.xml " + executionEngines + " " + e.getCause()); } // load executionEngine array List<XmlEntity> executionEngineList = executionEnginesRootEntity.getChildrenWithLabel("executionEngine"); for (XmlEntity executionEngine : executionEngineList) { // load kmId supported operations String engineName = executionEngine.getAttributeValue("name"); String logEngine = engineName; List<String> supportedDSSOperationStringList = new ArrayList<String>(); Set<String> supportedOps = executionEngine.getAttributeLabels(); Iterator<String> it = supportedOps.iterator(); while (it.hasNext()) { String thisSupportedOperationName = it.next(); String thisSupportedOperationValue = executionEngine.getAttributeValue(thisSupportedOperationName); if ("true".equals(thisSupportedOperationValue)) { supportedDSSOperationStringList.add(thisSupportedOperationName); logEngine = logEngine + ", " + thisSupportedOperationName; } } log.debug("Execution Engine: " + logEngine + ", name: " + engineName); myExecutionEngineToSupportedOperationsMap.put(engineName, supportedDSSOperationStringList); } // read semanticSignifiers resource String semanticSignifiers = ""; try { semanticSignifiers = getResourceAsString("resourceAttributes", "semanticSignifiers.xml"); } catch (DSSRuntimeExceptionFault e1) { e1.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to getResourceAsString('resourceAttributes','semanticSignifiers.xml': " + e1.getCause()); } XmlEntity semanticSignifiersRootEntity = null; try { semanticSignifiersRootEntity = XmlConverter.getInstance().unmarshalXml(semanticSignifiers, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to unmarshall semanticSignifiers.xml " + executionEngines + " " + e.getCause()); } // load SSID arrays List<XmlEntity> semanticSignifierList = semanticSignifiersRootEntity .getChildrenWithLabel("semanticSignifier"); for (XmlEntity semanticSignifier : semanticSignifierList) { // load ssid supported operations XmlEntity dataModelElement = semanticSignifier.getFirstChildWithLabel("dataModel"); String dataModel = dataModelElement.getValue(); XmlEntity unmarshalClassName = semanticSignifier.getFirstChildWithLabel("unmarshalClass"); mySSIdToUnmarshallerClassNameMap.put(dataModel, unmarshalClassName.getValue()); XmlEntity marshalClassName = semanticSignifier.getFirstChildWithLabel("marshalClass"); mySSIdToPayloadCreatorMap.put(dataModel, marshalClassName.getValue()); log.debug("SSID: " + dataModel + ", marshalClassName: " + marshalClassName); } // read knowledgeModules String knowledgeModules = ""; try { knowledgeModules = getResourceAsString("resourceAttributes", "knowledgeModules.xml"); } catch (DSSRuntimeExceptionFault e1) { e1.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to getResourceAsString('resourceAttributes','knowledgeModules.xml': " + e1.getCause()); } XmlEntity kmMetadataRootEntity = null; try { kmMetadataRootEntity = XmlConverter.getInstance().unmarshalXml(knowledgeModules, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to unmarshall knowledgeModules.xml " + knowledgeModules + " " + e.getCause()); } // load km arrays List<XmlEntity> kmMetadataList = kmMetadataRootEntity.getChildrenWithLabel("kmMetadata"); for (XmlEntity kmMetadata : kmMetadataList) { // load kmId to dataModel map XmlEntity identifier = kmMetadata.getFirstChildWithLabel("identifier"); String kmId = identifier.getAttributeValue("scopingEntityId") + "^" + identifier.getAttributeValue("businessId") + "^" + identifier.getAttributeValue("version"); XmlEntity dataModel = kmMetadata.getFirstChildWithLabel("dataModel"); EntityIdentifier dataModelEI = DSSUtility.makeEI(dataModel.getValue()); myKMIdToSSIdMap.put(kmId, dataModelEI); // load kmId to inference engine adapter map XmlEntity executionEngine = kmMetadata.getFirstChildWithLabel("executionEngine"); myKMIdToInferenceEngineAdapterMap.put(kmId, executionEngine.getValue()); // load kmId to primary process name map XmlEntity knowledgeModulePrimaryProcessName = kmMetadata .getFirstChildWithLabel("knowledgeModulePrimaryProcessName"); if ((knowledgeModulePrimaryProcessName != null) && (knowledgeModulePrimaryProcessName.getValue() != null) && !("".equals(knowledgeModulePrimaryProcessName.getValue()))) { myKMIdToPrimaryProcessNameMap.put(kmId, knowledgeModulePrimaryProcessName.getValue()); } else { myKMIdToPrimaryProcessNameMap.put(kmId, ""); } // load kmId to supported operations map if (myExecutionEngineToSupportedOperationsMap.get(executionEngine) != null) { myKMIdToSupportedOperationsMap.put(kmId, myExecutionEngineToSupportedOperationsMap.get(executionEngine)); log.debug("KMiD: " + kmId); } } // private HashMap<String, String> myCodeSystemOIDtoCodeSystemDisplayNameMap = new HashMap<String, String>(); // // key = String containing OID, target = displayName for OID // read codeSystem String codeSystems = ""; try { codeSystems = getResourceAsString("resourceAttributes", "openCDSCodeSystems.xml"); } catch (DSSRuntimeExceptionFault e1) { e1.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to getResourceAsString('resourceAttributes','openCDSCodeSystems.xml': " + e1.getCause()); } XmlEntity codeSystemsRootEntity = null; try { codeSystemsRootEntity = XmlConverter.getInstance().unmarshalXml(codeSystems, false, null); } catch (SAXParseException e) { e.printStackTrace(); throw new DSSRuntimeExceptionFault( "SimpleKnowledgeRepository failed to unmarshall openCDSCodeSystems.xml " + codeSystems + " " + e.getCause()); } // load codeSystem arrays List<XmlEntity> codeSystemsList = codeSystemsRootEntity.getChildrenWithLabel("codeSystem"); for (XmlEntity codeSystem : codeSystemsList) { // load oid to codeSystemName map String oid = codeSystem.getAttributeValue("codeSystemOID"); String name = codeSystem.getAttributeValue("codeSystemDisplayName"); String apelonNamespace = codeSystem.getAttributeValue("apelonNamespaceName"); boolean isOntylog = "true".equals(codeSystem.getAttributeValue("isApelonOntylog")); myCodeSystemOIDtoCodeSystemDisplayNameMap.put(oid, name); if (apelonNamespace != null) { myCodeSystemOIDtoApelonNamespaceName.put(oid, apelonNamespace); myApelonNamespaceNameToCodeSystemOID.put(apelonNamespace, oid); } myCodeSystemOIDtoIsOntylog.put(oid, isOntylog); //load OIDs myOpenCdsCodeSystemOIDs.add(oid); log.debug("OpenCDSCodeSystems: " + oid + ", name: " + name); } // load codeSystem arrays List<String> conceptTypesList = OpenCDSConceptTypes.getOpenCdsConceptTypes();//conceptTypesRootEntity.getChildrenWithLabel("ConceptType"); for (String conceptType : conceptTypesList) { // load concepts myOpenCdsConceptTypes.add(conceptType); log.trace("OpenCDSConceptTypes: " + conceptType); } String initTime = DateUtility.getInstance().getDateAsString(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"); System.out.println(initTime + " <<< OpenCDS SimpleKnowledgeRepository Initialized >>>"); System.out.println(); setKnowledgeRepositoryInitialized(true); }
From source file:org.openrdf.http.server.repository.statements.StatementsController.java
/** * Process several actions as a transaction. *///from w w w . j a v a 2 s . c om private ModelAndView getTransactionResultResult(Repository repository, HttpServletRequest request, HttpServletResponse response) throws IOException, ClientHTTPException, ServerHTTPException, HTTPException { InputStream in = request.getInputStream(); try { logger.debug("Processing transaction..."); TransactionReader reader = new TransactionReader(); Iterable<? extends TransactionOperation> txn = reader.parse(in); RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request); synchronized (repositoryCon) { repositoryCon.begin(); for (TransactionOperation op : txn) { op.execute(repositoryCon); } repositoryCon.commit(); } logger.debug("Transaction processed "); return new ModelAndView(EmptySuccessView.getInstance()); } catch (SAXParseException e) { ErrorInfo errInfo = new ErrorInfo(ErrorType.MALFORMED_DATA, e.getMessage()); throw new ClientHTTPException(SC_BAD_REQUEST, errInfo.toString()); } catch (SAXException e) { throw new ServerHTTPException("Failed to parse transaction data: " + e.getMessage(), e); } catch (IOException e) { throw new ServerHTTPException("Failed to read data: " + e.getMessage(), e); } catch (RepositoryException e) { if (e.getCause() != null && e.getCause() instanceof HTTPException) { // custom signal from the backend, throw as HTTPException directly // (see SES-1016). throw (HTTPException) e.getCause(); } else { throw new ServerHTTPException("Repository update error: " + e.getMessage(), e); } } }