List of usage examples for javax.xml.parsers SAXParser parse
public void parse(InputSource is, DefaultHandler dh) throws SAXException, IOException
From source file:com.aurel.track.admin.customize.category.filter.tree.io.TreeFilterParser.java
private void parse(String xml) { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try {//from w w w.j a v a 2 s. com //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs InputSource is = new InputSource(new StringReader(xml)); sp.parse(is, this); } catch (SAXException se) { LOGGER.warn("Parsing expression: " + xml + " failed with " + se.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(se)); } } catch (ParserConfigurationException pce) { LOGGER.warn("Parsing expression: " + xml + " failed with " + pce.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(pce)); } } catch (IOException ie) { LOGGER.warn("Reading expression: " + xml + " failed with " + ie.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(ie)); } }
From source file:egat.cli.strategyregret.StrategyRegretCommandHandler.java
protected void processStrategicGame(MutableStrategicGame game) throws CommandProcessingException { try {//from www . j ava 2s .co m Profile profile = null; if (uniform) { Player[] players = game.players().toArray(new Player[0]); Strategy[] strategies = new Strategy[players.length]; for (int i = 0; i < players.length; i++) { Action[] actions = ((Set<Action>) game.getActions(players[i])).toArray(new Action[0]); Number[] distribution = new Number[actions.length]; Arrays.fill(distribution, 1.0 / distribution.length); strategies[i] = Games.createStrategy(actions, distribution); } profile = Games.createProfile(players, strategies); } else { InputStream inputStream = null; inputStream = new FileInputStream(profilePath); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); ProfileHandler handler = new ProfileHandler(); parser.parse(inputStream, handler); profile = handler.getProfile(); } findRegret(profile, game); } catch (NonexistentPayoffException e) { System.err.println(String.format("Could not calculate regret. %s", e.getMessage())); } catch (FileNotFoundException e) { throw new CommandProcessingException(e); } catch (ParserConfigurationException e) { throw new CommandProcessingException(e); } catch (SAXException e) { throw new CommandProcessingException(e); } catch (IOException e) { throw new CommandProcessingException(e); } }
From source file:egat.cli.strategyregret.StrategyRegretCommandHandler.java
protected void processSymmetricGame(MutableSymmetricGame game) throws CommandProcessingException { try {//w w w.j a v a2 s . com Profile profile = null; if (uniform) { Player[] players = game.players().toArray(new Player[0]); Strategy[] strategies = new Strategy[players.length]; Action[] actions = ((Set<Action>) game.getActions()).toArray(new Action[0]); Number[] distribution = new Number[actions.length]; Arrays.fill(distribution, 1.0 / distribution.length); Strategy strategy = Games.createStrategy(actions, distribution); Arrays.fill(strategies, strategy); profile = Games.createProfile(players, strategies); } else { InputStream inputStream = null; inputStream = new FileInputStream(profilePath); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); ProfileHandler handler = new ProfileHandler(); parser.parse(inputStream, handler); profile = handler.getProfile(); } findRegret(profile, game); } catch (NonexistentPayoffException e) { System.err.println(String.format("Could not calculate regret. %s", e.getMessage())); } catch (FileNotFoundException e) { throw new CommandProcessingException(e); } catch (ParserConfigurationException e) { throw new CommandProcessingException(e); } catch (SAXException e) { throw new CommandProcessingException(e); } catch (IOException e) { throw new CommandProcessingException(e); } }
From source file:com.sshtools.daemon.configuration.PlatformConfiguration.java
/** * * * @param in/*from w w w . ja va 2s . co m*/ * * @throws SAXException * @throws ParserConfigurationException * @throws IOException */ public void reload(InputStream in) throws SAXException, ParserConfigurationException, IOException { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); saxParser.parse(in, new PlatformConfigurationSAXHandler()); }
From source file:mergedoc.core.MergeManager.java
/** * XML ??????????//w ww .ja v a2 s. co m * @param className ?? * @param source Java * @return ?? * @throws MergeDocException ?????? * @throws SAXException SAX ???? * @throws IOException ???? */ private String doFilter(String className, String source) throws MergeDocException, SAXException, IOException { // ??? String path = FastStringUtils.replaceAll(className, "\\.", "/") + ".xml"; ConfigManager config = ConfigManager.getInstance(); File entryXML = config.getFile(path); if (entryXML.exists()) { SAXParser saxParser = config.getSAXPerser(); ReplaceHandler handler = new ReplaceHandler(source); saxParser.parse(entryXML, handler); source = handler.getResult(); } // ???? for (ReplaceEntry entry : pref.getGlobalEntries()) { source = entry.replace(source); } return source; }
From source file:com.frameworkset.orm.engine.transform.XmlToData.java
/** * *///w w w . j a va 2 s .c o m public List parseFile(String xmlFile) throws Exception { data = new ArrayList(); SAXParser parser = saxFactory.newSAXParser(); FileReader fr = new FileReader(xmlFile); BufferedReader br = new BufferedReader(fr); try { InputSource is = new InputSource(br); parser.parse(is, this); } finally { br.close(); } return data; }
From source file:edu.psu.citeseerx.updates.external.metadata.ACMMetadataUpdater.java
public void updateACM() { try {/*from w ww . j ava2 s .c om*/ // Get the SAX factory. SAXParserFactory factory = SAXParserFactory.newInstance(); // Neither we want validation nor namespaces. factory.setNamespaceAware(false); factory.setValidating(true); SAXParser parser = factory.newSAXParser(); /*xmlReader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false);*/ parser.parse(ACMDataFile, acmHandler); } catch (ParserConfigurationException e) { logger.error("The underlaying parser doesn't support the " + "requested feature", e); } catch (SAXException e) { logger.error("Error", e); } catch (IOException e) { logger.error("A parsing error has occurred: " + ACMDataFile, e); } }
From source file:org.openbmap.soapclient.CheckServerTask.java
@Override protected Object[] doInBackground(final String... params) { try {/*w w w. j a v a 2 s .co m*/ final Object[] result = new Object[2]; result[0] = ServerAnswer.UNKNOWN_ERROR; result[1] = "Uninitialized"; //check whether we have a connection to openbmap.org if (!isOnline()) { // if not, check whether connecting, if so wait Log.i(TAG, "No reply from server! Device might just been switched on, so wait a bit"); waitForConnect(); if (!isOnline()) { Log.i(TAG, "Waiting didn't help. Still no connection"); result[0] = ServerAnswer.NO_REPLY; result[1] = "No online connection!"; return result; } } final SAXParserFactory factory = SAXParserFactory.newInstance(); final DefaultHandler handler = new DefaultHandler() { private boolean versionElement = false; public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("ALLOWED")) { versionElement = true; } } public void endElement(final String uri, final String localName, final String qName) throws SAXException { // Log.d(TAG, "End Element :" + qName); } public void characters(final char[] ch, final int start, final int length) throws SAXException { if (versionElement) { serverVersion = new String(ch, start, length); versionElement = false; } } }; Log.i(TAG, "Verifying client version at" + Preferences.VERSION_CHECK_URL); // version file is opened as stream, thus preventing immediate timeout issues final URL url = new URL(Preferences.VERSION_CHECK_URL); final InputStream stream = url.openStream(); final SAXParser saxParser = factory.newSAXParser(); saxParser.parse(stream, handler); stream.close(); if (serverVersion.equals(params[0])) { Log.i(TAG, "Client version is up-to-date: " + params[0]); final boolean anonymousUpload = PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean(Preferences.KEY_ANONYMOUS_UPLOAD, false); if (!anonymousUpload && credentialsAccepted(params[1], params[2])) { result[0] = ServerAnswer.OK; result[1] = "Everything fine! You're using the most up-to-date version!"; } else if (!anonymousUpload && !credentialsAccepted(params[1], params[2])) { result[0] = ServerAnswer.BAD_PASSWORD; result[1] = "Server reports bad user or password!"; } else { result[0] = ServerAnswer.OK; result[1] = "Password validation skipped, anonymous upload!"; } return result; } else { Log.i(TAG, "Client version is outdated: server " + serverVersion + " client " + params[0]); result[0] = ServerAnswer.OUTDATED; result[1] = "New version available:" + serverVersion; return result; } } catch (final IOException e) { Log.e(TAG, "Error while checking version. Are you online?"); return new Object[] { ServerAnswer.NO_REPLY, "Couldn't contact server" }; } catch (final Exception e) { Log.e(TAG, "Error while checking version: " + e.toString(), e); return new Object[] { ServerAnswer.UNKNOWN_ERROR, "Error: " + e.toString() }; } }
From source file:com.aurel.track.exchange.track.importer.ImporterDataParser.java
public List<ExchangeWorkItem> parse(File xml, Map<Integer, Integer> fieldMatcher) { this.fieldMatcher = fieldMatcher; //get a factory SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try {/*from w ww. j a v a 2s.c o m*/ SAXParser saxParser = saxParserFactory.newSAXParser(); LOGGER.debug("Data parser started..."); saxParser.parse(xml, this); LOGGER.debug("Data parser done"); return exchangeWorkItemsList; } catch (SAXException se) { LOGGER.error(ExceptionUtils.getStackTrace(se)); } catch (ParserConfigurationException pce) { LOGGER.error(ExceptionUtils.getStackTrace(pce)); } catch (IOException ie) { LOGGER.error(ExceptionUtils.getStackTrace(ie)); } return null; }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityFactory.java
public Map<Long, CompoundPromiscuityInfo> getCompoundsWithDescriptors(List<Long> ids, String db) throws Exception { log.info("Number of compounds in eSummary request: " + ids.size()); log.info("Memory usage before getting compound eSummary document: " + memUsage()); InputStream is = EUtilsFactory.getInstance().getSummaries(ids, db); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); CompoundESummaryHandler handler = new CompoundESummaryHandler(); saxParser.parse(is, handler); log.info("Memory usage after getting compound eSummary document: " + memUsage()); return handler.getCompoundIdMap(); }