Java Code Examples for javax.xml.parsers.SAXParserFactory

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Aion-Extreme, under directory /AE-go_GameServer/src/com/aionemu/gameserver/dataholders/loadingutils/.

Source file: XmlMerger.java

  33 
vote

/** 
 * Check for modifications of included files.
 * @return <code>true</code> if at least one of included files has modifications.
 * @throws IOException                  IO Error.
 * @throws SAXException                 Document parsing error.
 * @throws ParserConfigurationException if a SAX parser cannotbe created which satisfies the requested configuration.
 */
private boolean checkFileModifications() throws Exception {
  long destFileTime=destFile.lastModified();
  if (sourceFile.lastModified() > destFileTime) {
    logger.debug("Source file was modified ");
    return true;
  }
  Properties metadata=restoreFileModifications(metaDataFile);
  if (metadata == null)   return true;
  SAXParserFactory parserFactory=SAXParserFactory.newInstance();
  SAXParser parser=parserFactory.newSAXParser();
  TimeCheckerHandler handler=new TimeCheckerHandler(baseDir,metadata);
  parser.parse(sourceFile,handler);
  return handler.isModified();
}
 

Example 2

From project jboss-as-quickstart, under directory /xml-jaxp/src/main/java/org/jboss/as/quickstart/xml/.

Source file: SAXXMLParser.java

  33 
vote

SAXXMLParser() throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(false);
  this.parser=factory.newSAXParser();
  this.saxHandler=new SAXHandler();
}
 

Example 3

From project Airports, under directory /src/com/nadmm/airports/wx/.

Source file: AirSigmetParser.java

  32 
vote

public void parse(File xml,AirSigmet airSigmet){
  try {
    airSigmet.fetchTime=xml.lastModified();
    InputSource input=new InputSource(new FileReader(xml));
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    AirSigmetHandler handler=new AirSigmetHandler(airSigmet);
    XMLReader xmlReader=parser.getXMLReader();
    xmlReader.setContentHandler(handler);
    xmlReader.parse(input);
  }
 catch (  Exception e) {
  }
}
 

Example 4

From project and-bible, under directory /AndBible/src/net/bible/service/sword/.

Source file: SwordContentFacade.java

  32 
vote

private SAXParser getSAXParser() throws ParseException {
  try {
    if (saxParser == null) {
      SAXParserFactory spf=SAXParserFactory.newInstance();
      spf.setValidating(false);
      saxParser=spf.newSAXParser();
    }
  }
 catch (  Exception e) {
    log.error("SAX parser error",e);
    throw new ParseException("SAX parser error",e);
  }
  return saxParser;
}
 

Example 5

From project android-thaiime, under directory /makedict/src/com/android/inputmethod/latin/.

Source file: XmlDictInputOutput.java

  32 
vote

/** 
 * Reads a dictionary from an XML file. This is the public method that will parse an XML file and return the corresponding memory representation.
 * @param unigrams the file to read the data from.
 * @return the in-memory representation of the dictionary.
 */
public static FusionDictionary readDictionaryXml(InputStream unigrams,InputStream bigrams) throws SAXException, IOException, ParserConfigurationException {
  final SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  final SAXParser parser=factory.newSAXParser();
  final BigramHandler bigramHandler=new BigramHandler();
  if (null != bigrams)   parser.parse(bigrams,bigramHandler);
  final FusionDictionary dict=new FusionDictionary();
  final UnigramHandler unigramHandler=new UnigramHandler(dict,bigramHandler.getBigramMap());
  parser.parse(unigrams,unigramHandler);
  return dict;
}
 

Example 6

From project android_packages_inputmethods_LatinIME, under directory /tools/makedict/src/com/android/inputmethod/latin/.

Source file: XmlDictInputOutput.java

  32 
vote

/** 
 * Reads a dictionary from an XML file. This is the public method that will parse an XML file and return the corresponding memory representation.
 * @param unigrams the file to read the data from.
 * @return the in-memory representation of the dictionary.
 */
public static FusionDictionary readDictionaryXml(InputStream unigrams,InputStream bigrams) throws SAXException, IOException, ParserConfigurationException {
  final SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  final SAXParser parser=factory.newSAXParser();
  final BigramHandler bigramHandler=new BigramHandler();
  if (null != bigrams)   parser.parse(bigrams,bigramHandler);
  final FusionDictionary dict=new FusionDictionary();
  final UnigramHandler unigramHandler=new UnigramHandler(dict,bigramHandler.getBigramMap());
  parser.parse(unigrams,unigramHandler);
  return dict;
}
 

Example 7

From project ant4eclipse, under directory /org.ant4eclipse.lib.core/src/org/ant4eclipse/lib/core/xquery/.

Source file: XQueryHandler.java

  32 
vote

/** 
 * Runs the queries against the supplied XML file.
 * @param xmlfile The XML file that shall be queried.
 * @param handler The handler which provides all queries.
 */
public static void queryFile(File xmlfile,XQueryHandler handler){
  Assure.isFile("xmlfile",xmlfile);
  Assure.notNull("handler",handler);
  try {
    SAXParserFactory factory=getSAXParserFactory();
    factory.newSAXParser().parse(new FileInputStream(xmlfile),handler);
  }
 catch (  Exception ex) {
    A4ELogging.error(ex.getMessage());
    throw (new Ant4EclipseException(ex,CoreExceptionCode.X_QUERY_PARSE_EXCEPTION));
  }
}
 

Example 8

From project beam-third-party, under directory /beam-meris-veg/src/main/java/org/esa/beam/processor/baer/auxdata/.

Source file: AerPhaseLoader.java

  32 
vote

/** 
 * Parses the aerosol phase function auxiliary file.
 * @param defFile
 */
private void parseFile(URL defFile) throws ParserConfigurationException, SAXException, IOException {
  _luts.clear();
  _lutNames.clear();
  initStateVariables();
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser saxParser=factory.newSAXParser();
  saxParser.parse(defFile.openStream(),new LUTHandler());
}
 

Example 9

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.

Source file: LibraryThingManager.java

  32 
vote

/** 
 * Search for edition data.
 * @param bookData
 */
public static ArrayList<String> searchEditions(String isbn){
  String path=String.format(EDITIONS_URL,isbn);
  if (isbn.equals(""))   throw new RuntimeException("Can not get editions without an ISBN");
  ArrayList<String> editions=new ArrayList<String>();
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SearchLibraryThingEditionHandler entryHandler=new LibraryThingManager.SearchLibraryThingEditionHandler(editions);
  waitUntilRequestAllowed();
  Utils.parseUrlOutput(path,factory,entryHandler);
  return editions;
}
 

Example 10

From project Carolina-Digital-Repository, under directory /fcrepo-irods-storage/src/test/java/.

Source file: MockFedoraIT.java

  32 
vote

private void parseIrodsFile(IrodsIFileSystem module,String testPath) throws LowlevelStorageException {
  InputStream is=module.read(new File(testPath));
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser parser=spf.newSAXParser();
    parser.parse(is,new DefaultHandler());
  }
 catch (  Exception e) {
    throw new RuntimeException("Error with SAX parser",e);
  }
}
 

Example 11

From project chatbots-library, under directory /distribution/src/codeanticode/chatbots/alice/config/.

Source file: TokenizerConfigStream.java

  32 
vote

public TokenizerConfigStream() throws ConfigException {
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    parser=factory.newSAXParser();
  }
 catch (  Exception e) {
    throw new ConfigException(e);
  }
}
 

Example 12

From project CineShowTime-Android, under directory /Libraries/CineShowTime/src/com/binomed/showtime/android/util/.

Source file: CineShowtimeFactory.java

  32 
vote

private XMLReader getReader() throws Exception {
  if (reader == null) {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    reader=sp.getXMLReader();
  }
  return reader;
}
 

Example 13

From project cocos2d, under directory /cocos2d-android/src/org/cocos2d/utils/.

Source file: PlistParser.java

  32 
vote

private static Object parsePlist(InputStream in){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    PlistParser handler=new PlistParser();
    BufferedReader reader=new BufferedReader(new InputStreamReader(in),8192);
    parser.parse(new InputSource(reader),handler);
    return handler.rootDict;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 14

From project codjo-webservices, under directory /codjo-webservices-common/src/main/java/com/tilab/wsig/soap/.

Source file: SoapToJade.java

  32 
vote

/** 
 * Get SAX parser class name
 * @param s
 * @return parser name
 */
private static String getSaxParserName() throws Exception {
  String saxFactory=System.getProperty("org.xml.sax.driver");
  if (saxFactory != null) {
    return saxFactory;
  }
 else {
    SAXParserFactory newInstance=SAXParserFactory.newInstance();
    SAXParser newSAXParser=newInstance.newSAXParser();
    XMLReader reader=newSAXParser.getXMLReader();
    String name=reader.getClass().getName();
    return name;
  }
}
 

Example 15

From project Coffee-Framework, under directory /coffeeframework-core/src/main/java/coffee/.

Source file: CoffeeConfiguration.java

  32 
vote

/** 
 * @param configurationFile
 * @return a parsed coffee configuration
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
public static CoffeeConfiguration parse(InputStream configurationFile) throws ParserConfigurationException, SAXException, IOException {
  CoffeeConfiguration configurationParser=new CoffeeConfiguration();
  SAXParserFactory sax=SAXParserFactory.newInstance();
  sax.setValidating(false);
  sax.setNamespaceAware(true);
  SAXParser parser=sax.newSAXParser();
  parser.parse(configurationFile,configurationParser);
  return configurationParser;
}
 

Example 16

From project core_1, under directory /common/src/main/java/org/switchyard/common/xml/.

Source file: XMLHelper.java

  32 
vote

/** 
 * Compare the specified contents as XML.
 * @param content1 The first content.
 * @param content2 The second content.
 * @return true if equals, false otherwise.
 * @throws ParserConfigurationException Parser confiuration exception
 * @throws SAXException SAX exception
 * @throws IOException If unable to read the stream
 */
public static boolean compareXMLContent(final InputSource content1,final InputSource content2) throws ParserConfigurationException, SAXException, IOException {
  final SAXParserFactory parserFactory=SAXParserFactory.newInstance();
  parserFactory.setNamespaceAware(true);
  final SAXParser parser=parserFactory.newSAXParser();
  final IdentitySAXHandler handler1=new IdentitySAXHandler();
  parser.parse(content1,handler1);
  final IdentitySAXHandler handler2=new IdentitySAXHandler();
  parser.parse(content2,handler2);
  return (handler1.getRootElement().equals(handler2.getRootElement()));
}
 

Example 17

From project Cours-3eme-ann-e, under directory /Java/FerryInpres/src/information_server/.

Source file: MainServer.java

  32 
vote

private static SaxParsingHandler parseDemande(ObjectInputStream obj_in) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException {
  System.out.println("R?ception de la requ?te");
  String str_buffer=(String)obj_in.readObject();
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(true);
  XMLReader parser=factory.newSAXParser().getXMLReader();
  SaxParsingHandler handler=new SaxParsingHandler();
  parser.setContentHandler(handler);
  parser.setErrorHandler(handler);
  System.out.println("Parsing de la requ?te");
  parser.parse(new InputSource(new StringReader(str_buffer)));
  return handler;
}
 

Example 18

From project cpptasks-parallel, under directory /src/main/java/net/sf/antcontrib/cpptasks/.

Source file: DependencyTable.java

  32 
vote

public void load() throws IOException, ParserConfigurationException, SAXException {
  dependencies.clear();
  if (dependenciesFile.exists()) {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser parser=factory.newSAXParser();
    parser.parse(dependenciesFile,new DependencyTableHandler(this,baseDir));
    dirty=false;
  }
}
 

Example 19

From project crash, under directory /jcr/core/src/main/java/org/crsh/jcr/.

Source file: Importer.java

  32 
vote

public void file(String fileName,int length,InputStream data) throws IOException {
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    SAXParser parser=factory.newSAXParser();
    parser.parse(data,attributesHandler);
  }
 catch (  Exception e) {
    Safe.rethrow(IOException.class,e);
  }
}
 

Example 20

From project dawn-isencia, under directory /com.isencia.passerelle.commons.ume/src/main/java/com/isencia/message/extractor/.

Source file: XmlMessageExtractor.java

  32 
vote

/** 
 * Creates a new instance 
 */
public XmlMessageExtractor(){
  SAXParserFactory saxFactory=SAXParserFactory.newInstance();
  try {
    saxParser=saxFactory.newSAXParser();
  }
 catch (  ParserConfigurationException e) {
  }
catch (  SAXException e) {
  }
}
 

Example 21

From project dcm4che, under directory /dcm4che-core/src/main/java/org/dcm4che/data/.

Source file: IOD.java

  32 
vote

public void parse(String uri) throws IOException {
  try {
    SAXParserFactory f=SAXParserFactory.newInstance();
    SAXParser parser=f.newSAXParser();
    parser.parse(uri,new SAXHandler(this));
  }
 catch (  SAXException e) {
    throw new IOException("Failed to parse " + uri,e);
  }
catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
}
 

Example 22

From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/chapitre08/.

Source file: DigitbooksGuestbookXml.java

  32 
vote

public List<HashMap<String,String>> parse(String xml) throws Exception {
  if (xml == null) {
    return null;
  }
  mData=new ArrayList<HashMap<String,String>>();
  InputSource inputSource=new InputSource(new StringReader(xml));
  SAXParserFactory spf=SAXParserFactory.newInstance();
  SAXParser sp=spf.newSAXParser();
  XMLReader xr=sp.getXMLReader();
  xr.setContentHandler(this);
  xr.parse(inputSource);
  return mData;
}
 

Example 23

From project Eclipse, under directory /com.mobilesorcery.sdk.core/src/com/mobilesorcery/sdk/core/.

Source file: LineReader.java

  32 
vote

@Override public final void stop(IOException ioe){
  Exception ex=ioe;
  if (ioe == null) {
    try {
      SAXParserFactory factory=SAXParserFactory.newInstance();
      SAXParser parser=factory.newSAXParser();
      parser.parse(new ByteArrayInputStream(buffer.toString().getBytes()),this);
    }
 catch (    Exception e) {
      ex=e;
    }
  }
  doStop(ex);
}
 

Example 24

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/.

Source file: Activator.java

  32 
vote

public SAXParserFactory getFactory(){
  if (parserTracker == null) {
    parserTracker=new ServiceTracker(bundleContext,SAXParserFactory.class.getName(),null);
    parserTracker.open();
  }
  SAXParserFactory theFactory=(SAXParserFactory)parserTracker.getService();
  if (theFactory != null)   theFactory.setNamespaceAware(true);
  return theFactory;
}
 

Example 25

From project entando-core-engine, under directory /src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/.

Source file: ResourceManager.java

  32 
vote

/** 
 * Valorizza una risorsa prototipo con gli elementi  dell'xml che rappresenta una risorsa specifica. 
 * @param resource Il prototipo di risorsa da specializzare con gli attributi dell'xml.
 * @param xml L'xml della risorsa specifica. 
 * @throws ApsSystemException
 */
protected void fillEmptyResourceFromXml(ResourceInterface resource,String xml) throws ApsSystemException {
  try {
    SAXParserFactory parseFactory=SAXParserFactory.newInstance();
    SAXParser parser=parseFactory.newSAXParser();
    InputSource is=new InputSource(new StringReader(xml));
    ResourceHandler handler=new ResourceHandler(resource,this.getCategoryManager());
    parser.parse(is,handler);
  }
 catch (  Throwable t) {
    ApsSystemUtils.logThrowable(t,this,"fillEmptyResourceFromXml");
    throw new ApsSystemException("Error loading resource",t);
  }
}
 

Example 26

From project faces_1, under directory /impl/src/main/java/org/jboss/seam/faces/projectstage/.

Source file: WebXmlContextParameterParser.java

  32 
vote

/** 
 * Parses the supplied web.xml  {@link InputStream}.
 * @param stream The stream to parse
 * @throws IOException for any errors during the parsing process
 */
public final void parse(InputStream stream) throws IOException {
  try {
    SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    SAXParser parser=saxParserFactory.newSAXParser();
    parser.parse(stream,this);
  }
 catch (  ParserConfigurationException e) {
    throw new IOException(e);
  }
catch (  SAXException e) {
    throw new IOException(e);
  }
}
 

Example 27

From project freemind, under directory /freemind/de/foltin/.

Source file: CompileXsdStart.java

  32 
vote

public void generate() throws ParserConfigurationException, SAXException, IOException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser saxParser=factory.newSAXParser();
  mCurrentHandler=new XsdHandler(null);
  mBindingXml.setLength(0);
  mBindingXml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><binding>\n");
  saxParser.parse(mInputStream,this);
  mBindingXml.append("</binding>\n");
}
 

Example 28

From project galaxyCar, under directory /AndroidColladaLoader/src/ckt/projects/acl/.

Source file: ColladaHandler.java

  32 
vote

public ArrayList<ColladaObject> parseFile(InputStream input){
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(input));
  }
 catch (  Exception e) {
  }
  ArrayList<ColladaObject> result=new ArrayList<ColladaObject>();
  result.add(new ColladaObject(vertices,indices,upAxis));
  return result;
}
 

Example 29

From project GenericKnimeNodes, under directory /com.genericworkflownodes.knime.base_plugin/src/com/genericworkflownodes/knime/config/.

Source file: CTDNodeConfigurationReader.java

  32 
vote

/** 
 * Initializes a SAXReader with the Param and CTD schema.
 * @return A fully configured {@link SAXReader}.
 * @throws SAXException See  {@link SAXReader} documentation.
 * @throws ParserConfigurationException See  {@link SAXReader} documentation.
 */
private SAXReader initializeSAXReader() throws SAXException, ParserConfigurationException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SchemaFactory schemaFactory=SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
  factory.setSchema(schemaFactory.newSchema(new Source[]{new StreamSource(SchemaProvider.class.getResourceAsStream("CTD.xsd")),new StreamSource(SchemaProvider.class.getResourceAsStream("Param_1_3.xsd"))}));
  SAXParser parser=factory.newSAXParser();
  SAXReader reader=new SAXReader(parser.getXMLReader());
  reader.setValidation(false);
  return reader;
}
 

Example 30

From project gh4a, under directory /src/com/gh4a/utils/.

Source file: RssParser.java

  32 
vote

public List<YourActionFeed> parse() throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  RssHandler handler=new RssHandler();
  parser.parse(this.getInputStream(),handler);
  return handler.getFeeds();
}
 

Example 31

From project gxa, under directory /annotator/src/main/java/uk/ac/ebi/gxa/annotator/loader/biomart/.

Source file: MartRegistry.java

  32 
vote

public static MartRegistry parse(InputStream in) throws SAXException, ParserConfigurationException, IOException {
  SAXParserFactory spf=SAXParserFactory.newInstance();
  SAXParser parser=spf.newSAXParser();
  XmlContentHandler handler=new XmlContentHandler();
  parser.parse(in,handler);
  return handler.getRegistry();
}
 

Example 32

From project Holo-Edit, under directory /holoedit/fileio/.

Source file: TjFileReader.java

  32 
vote

public void run(){
  SAXParserFactory factory=SAXParserFactory.newInstance();
  try {
    SAXParser saxParser=factory.newSAXParser();
    File f=new File(filename);
    saxParser.parse(f,this);
  }
 catch (  Throwable t) {
    error=true;
    t.printStackTrace();
    done=true;
  }
}
 

Example 33

From project hudson-test-harness, under directory /src/test/java/hudson/.

Source file: UDPBroadcastThreadTest.java

  32 
vote

/** 
 * Reads a reply from the socket and makes sure its shape is in order.
 */
private void receiveAndVerify(DatagramSocket s) throws IOException, SAXException, ParserConfigurationException {
  DatagramPacket p=new DatagramPacket(new byte[1024],1024);
  s.receive(p);
  String xml=new String(p.getData(),0,p.getLength(),"UTF-8");
  System.out.println(xml);
  SAXParserFactory spf=SAXParserFactory.newInstance();
  spf.setNamespaceAware(true);
  spf.newSAXParser().parse(new InputSource(new StringReader(xml)),new DefaultHandler());
}
 

Example 34

From project ICS_LatinIME_QHD, under directory /tools/makedict/src/com/android/inputmethod/latin/.

Source file: XmlDictInputOutput.java

  32 
vote

/** 
 * Reads a dictionary from an XML file. This is the public method that will parse an XML file and return the corresponding memory representation.
 * @param unigrams the file to read the data from.
 * @return the in-memory representation of the dictionary.
 */
public static FusionDictionary readDictionaryXml(InputStream unigrams,InputStream bigrams) throws SAXException, IOException, ParserConfigurationException {
  final SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  final SAXParser parser=factory.newSAXParser();
  final BigramHandler bigramHandler=new BigramHandler();
  if (null != bigrams)   parser.parse(bigrams,bigramHandler);
  final FusionDictionary dict=new FusionDictionary();
  final UnigramHandler unigramHandler=new UnigramHandler(dict,bigramHandler.getBigramMap());
  parser.parse(unigrams,unigramHandler);
  return dict;
}
 

Example 35

From project instibot, under directory /src/main/java/bitoflife/chatterbean/config/.

Source file: TokenizerConfigStream.java

  32 
vote

public TokenizerConfigStream() throws ConfigException {
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    parser=factory.newSAXParser();
  }
 catch (  Exception e) {
    throw new ConfigException(e);
  }
}
 

Example 36

From project jAPS2, under directory /src/com/agiletec/plugins/jacms/aps/system/services/resource/.

Source file: ResourceManager.java

  32 
vote

/** 
 * Valorizza una risorsa prototipo con gli elementi  dell'xml che rappresenta una risorsa specifica. 
 * @param resource Il prototipo di risorsa da specializzare con gli attributi dell'xml.
 * @param xml L'xml della risorsa specifica. 
 * @throws ApsSystemException
 */
protected void fillEmptyResourceFromXml(ResourceInterface resource,String xml) throws ApsSystemException {
  try {
    SAXParserFactory parseFactory=SAXParserFactory.newInstance();
    SAXParser parser=parseFactory.newSAXParser();
    InputSource is=new InputSource(new StringReader(xml));
    ResourceHandler handler=new ResourceHandler(resource,this.getCategoryManager());
    parser.parse(is,handler);
  }
 catch (  Throwable t) {
    ApsSystemUtils.logThrowable(t,this,"fillEmptyResourceFromXml");
    throw new ApsSystemException("Error loading resource",t);
  }
}
 

Example 37

From project jbosgi, under directory /testsuite/example/src/test/java/org/jboss/test/osgi/example/jaxp/.

Source file: SAXParserTestCase.java

  32 
vote

@Test public void testSAXParserFactoryService() throws Exception {
  ServiceReference sref=context.getServiceReference(SAXParserFactory.class.getName());
  assertNotNull("ServiceReference not null");
  SAXParserFactory factory=(SAXParserFactory)context.getService(sref);
  parse(factory);
}
 

Example 38

From project jbosgi-framework, under directory /itest/src/test/java/org/jboss/test/osgi/framework/classloader/support/.

Source file: JavaXMLParserActivator.java

  32 
vote

@Override public void start(BundleContext context) throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser saxParser=factory.newSAXParser();
  ByteArrayInputStream input=new ByteArrayInputStream(TEST_XML.getBytes());
  saxParser.parse(input,new Myhandler());
}
 

Example 39

From project jbosgi-resolver, under directory /api/src/main/java/org/osgi/util/xml/.

Source file: XMLParserActivator.java

  32 
vote

/** 
 * Register SAX Parser Factory Services with the framework.
 * @param parserFactoryClassNames - a <code>List</code> of<code>String</code> objects containing the names of the parser Factory Classes
 * @throws FactoryConfigurationError if thrown from <code>getFactory</code>
 */
private void registerSAXParsers(List parserFactoryClassNames) throws FactoryConfigurationError {
  Iterator e=parserFactoryClassNames.iterator();
  int index=0;
  while (e.hasNext()) {
    String parserFactoryClassName=(String)e.next();
    SAXParserFactory factory=(SAXParserFactory)getFactory(parserFactoryClassName);
    Hashtable properties=new Hashtable(7);
    setDefaultSAXProperties(factory,properties,index);
    properties.put(FACTORYNAMEKEY,parserFactoryClassName);
    context.registerService(SAXFACTORYNAME,this,properties);
    index++;
  }
}
 

Example 40

From project jboss-modules, under directory /src/test/java/org/jboss/modules/.

Source file: JAXPModuleTest.java

  32 
vote

public void checkSax(Class<?> clazz,boolean fake) throws Exception {
  SAXParser parser=invokeMethod(clazz.newInstance(),"saxParser");
  SAXParserFactory factory=invokeMethod(clazz.newInstance(),"saxParserFactory");
  Assert.assertEquals(__SAXParserFactory.class.getName(),factory.getClass().getName());
  if (fake) {
    Assert.assertEquals(FakeSAXParser.class.getName(),parser.getClass().getName());
  }
 else {
    Assert.assertSame(SAXParserFactory.newInstance().newSAXParser().getClass(),parser.getClass());
  }
}
 

Example 41

From project jdcbot, under directory /src/org/elite/jdcbot/shareframework/.

Source file: FilelistConverter.java

  32 
vote

public FLDir parse() throws ParserConfigurationException, SAXException, IOException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  FilelistHandler handler=new FilelistHandler();
  parser.parse(this,handler);
  return fl;
}
 

Example 42

From project jsword, under directory /src/main/java/org/crosswire/common/xml/.

Source file: StringSAXEventProvider.java

  32 
vote

/** 
 * Simple ctor
 */
public StringSAXEventProvider(String xmlstr) throws ParserConfigurationException, SAXException {
  this.xmlstr=xmlstr;
  SAXParserFactory fact=SAXParserFactory.newInstance();
  SAXParser parser=fact.newSAXParser();
  reader=parser.getXMLReader();
}
 

Example 43

From project jugglingLab, under directory /source/jugglinglab/jml/.

Source file: JMLParser.java

  32 
vote

public void parse(Reader read) throws SAXException, IOException {
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(true);
    SAXParser parser=factory.newSAXParser();
    parser.parse(new InputSource(read),this);
  }
 catch (  ParserConfigurationException pce) {
    throw new SAXException(pce.getMessage());
  }
}
 

Example 44

From project junithelper, under directory /core/src/main/java/org/junithelper/core/config/extension/.

Source file: ExtConfigurationLoader.java

  32 
vote

public ExtConfiguration load(InputStream inputStream) throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  ExtConfigurationParserHandler handler=new ExtConfigurationParserHandler();
  parser.parse(inputStream,handler);
  return handler.getExtConfiguration();
}
 

Example 45

From project kabeja, under directory /core/src/main/java/org/kabeja/parser/xml/.

Source file: AbstractSAXParser.java

  32 
vote

public void parse(InputStream input,DraftDocument doc,Map properties) throws ParseException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  try {
    factory.setNamespaceAware(true);
    SAXParser parser=factory.newSAXParser();
    this.doc=doc;
    parser.parse(input,this);
  }
 catch (  Exception e) {
    throw new ParseException(e);
  }
}
 

Example 46

From project Lily, under directory /global/util/src/main/java/org/lilyproject/util/xml/.

Source file: LocalSAXParserFactory.java

  32 
vote

protected SAXParserFactory initialValue(){
  SAXParserFactory parserFactory=SAXParserFactory.newInstance();
  safeSetFeature(parserFactory,"http://xml.org/sax/features/validation",false);
  safeSetFeature(parserFactory,"http://xml.org/sax/features/external-general-entities",false);
  safeSetFeature(parserFactory,"http://xml.org/sax/features/external-parameter-entities",false);
  safeSetFeature(parserFactory,"http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
  parserFactory.setNamespaceAware(true);
  parserFactory.setValidating(false);
  return parserFactory;
}
 

Example 47

From project litle-sdk-for-java, under directory /lib/jaxb/samples/partial-unmarshalling/src/.

Source file: Main.java

  32 
vote

public static void main(String[] args) throws Exception {
  JAXBContext context=JAXBContext.newInstance("primer");
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  XMLReader reader=factory.newSAXParser().getXMLReader();
  Splitter splitter=new Splitter(context);
  reader.setContentHandler(splitter);
  for (int i=0; i < args.length; i++) {
    reader.parse(new File(args[i]).toURL().toExternalForm());
  }
}
 

Example 48

From project logback, under directory /logback-core/src/main/java/ch/qos/logback/core/joran/event/.

Source file: SaxEventRecorder.java

  32 
vote

private SAXParser buildSaxParser() throws JoranException {
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    spf.setValidating(false);
    spf.setNamespaceAware(true);
    return spf.newSAXParser();
  }
 catch (  Exception pce) {
    String errMsg="Parser configuration error occurred";
    addError(errMsg,pce);
    throw new JoranException(errMsg,pce);
  }
}
 

Example 49

From project makegood, under directory /com.piece_framework.makegood.core/src/com/piece_framework/makegood/core/run/.

Source file: ResultReader.java

  32 
vote

public void read() throws ParserConfigurationException, SAXException, IOException {
  if (!log.exists()) {
    log.createNewFile();
  }
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  stream=new SynchronizedFileInputStream(log);
  parser.parse(stream,this);
}
 

Example 50

From project maven-surefire, under directory /maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/.

Source file: TestSuiteXmlParser.java

  32 
vote

public Collection<ReportTestSuite> parse(String xmlPath) throws ParserConfigurationException, SAXException, IOException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser saxParser=factory.newSAXParser();
  classesToSuites=new HashMap<String,ReportTestSuite>();
  saxParser.parse(new File(xmlPath),this);
  if (currentSuite != defaultSuite) {
    if (defaultSuite.getNumberOfTests() == 0) {
      classesToSuites.remove(defaultSuite.getFullClassName());
    }
  }
  return classesToSuites.values();
}
 

Example 51

From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/news/.

Source file: NewsModel.java

  32 
vote

private List<NewsItem> parseNewsItems(InputStream stream){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    NewsHandler handler=new NewsHandler();
    parser.parse(stream,handler);
    return handler.getNewsItems();
  }
 catch (  Exception e) {
    Log.d("NewsParser","RuntimeException");
    e.printStackTrace();
  }
  return null;
}
 

Example 52

From project mobilis, under directory /MobilisServer/src/de/tudresden/inf/rn/mobilis/server/deployment/helper/.

Source file: MSDLReader.java

  32 
vote

/** 
 * Gets the service dependencies.
 * @param msdlFile the msdl file which should be queried
 * @return the service dependencies
 */
public static List<ServiceDependency> getServiceDependencies(File msdlFile){
  List<ServiceDependency> resultList=new ArrayList<MSDLReader.ServiceDependency>();
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser saxParser=factory.newSAXParser();
    SAXServiceDependencyHandler saxHandler=new MSDLReader.SAXServiceDependencyHandler();
    saxParser.parse(msdlFile.getAbsolutePath(),saxHandler);
    resultList=saxHandler.getResultList();
  }
 catch (  Exception e) {
    MobilisManager.getLogger().log(Level.WARNING,String.format("Exception while reading the service dependencies from msdl: %s",e.getMessage()));
  }
  return resultList;
}
 

Example 53

From project modello, under directory /modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/.

Source file: ModelloXsdGeneratorTest.java

  32 
vote

public void testXsdGenerator() throws Throwable {
  ModelloCore modello=(ModelloCore)lookup(ModelloCore.ROLE);
  Properties parameters=getModelloParameters("1.4.0");
  Model model=modello.loadModel(getTestFile("../../src/main/mdo/modello.mdo"));
  modello.generate(model,"xsd",parameters);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(true);
  factory.setNamespaceAware(true);
  SAXParser saxParser=factory.newSAXParser();
  saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");
  saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",new File(getOutputDirectory(),"modello-1.4.0.xsd"));
  saxParser.parse(getTestFile("../../src/main/mdo/modello.mdo"),new Handler());
  saxParser.parse(getClass().getResourceAsStream("/features.mdo"),new Handler());
}
 

Example 54

From project mylyn.docs, under directory /org.eclipse.mylyn.docs.epub.core/src/org/eclipse/mylyn/internal/docs/epub/core/.

Source file: MetadataScanner.java

  32 
vote

public static void parse(InputSource file,Metadata metadata) throws ParserConfigurationException, SAXException, IOException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setFeature("http://xml.org/sax/features/validation",false);
  factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
  SAXParser parser=factory.newSAXParser();
  MetadataScanner tocGenerator=new MetadataScanner(metadata);
  try {
    parser.parse(file,tocGenerator);
  }
 catch (  SAXException e) {
    e.printStackTrace();
  }
}
 

Example 55

From project android-context, under directory /src/edu/fsu/cs/contextprovider/monitor/.

Source file: WeatherMonitor.java

  31 
vote

@Override public void run(){
  weatherZip=LocationMonitor.getZip();
  URL url;
  try {
    String tmpStr=null;
    String cityParamString=weatherZip;
    Log.d(TAG,"cityParamString: " + cityParamString);
    String queryString="http://www.google.com/ig/api?weather=" + cityParamString;
    url=new URL(queryString.replace(" ","%20"));
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    gwh=new GoogleWeatherHandler();
    xr.setContentHandler(gwh);
    xr.parse(new InputSource(url.openStream()));
    ws=gwh.getWeatherSet();
    if (ws == null)     return;
    WeatherCurrentCondition wcc=ws.getWeatherCurrentCondition();
    if (wcc != null) {
      weatherTemp=null;
      Integer weatherTempInt=wcc.getTempFahrenheit();
      if (weatherTempInt != null) {
        weatherTemp=weatherTempInt;
      }
      weatherCond=wcc.getCondition();
      weatherHumid=wcc.getHumidity();
      weatherWindCond=wcc.getWindCondition();
      weatherHazard=calcHazard();
    }
  }
 catch (  Exception e) {
    Log.e(TAG,"WeatherQueryError",e);
  }
}
 

Example 56

From project android-rss, under directory /src/main/java/org/mcsoxford/rss/.

Source file: RSSParser.java

  31 
vote

/** 
 * Parses input stream as RSS feed. It is the responsibility of the caller to close the RSS feed input stream.
 * @param feed RSS 2.0 feed input stream
 * @return in-memory representation of RSS feed
 * @throws RSSFault if an unrecoverable parse error occurs
 */
@Override public RSSFeed parse(InputStream feed){
  try {
    final SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setFeature("http://xml.org/sax/features/namespaces",false);
    factory.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
    final SAXParser parser=factory.newSAXParser();
    return parse(parser,feed);
  }
 catch (  ParserConfigurationException e) {
    throw new RSSFault(e);
  }
catch (  SAXException e) {
    throw new RSSFault(e);
  }
catch (  IOException e) {
    throw new RSSFault(e);
  }
}
 

Example 57

From project AndroidExamples, under directory /RSSExample/src/com/robertszkutak/androidexamples/rss/.

Source file: RSSExampleActivity.java

  31 
vote

@Override protected RSSFeed doInBackground(String... RSSuri){
  try {
    URL url=new URL(RSSuri[0]);
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    XMLReader xmlreader=parser.getXMLReader();
    RSSHandler theRssHandler=new RSSHandler();
    xmlreader.setContentHandler(theRssHandler);
    InputSource is=new InputSource(url.openStream());
    xmlreader.parse(is);
    return theRssHandler.getFeed();
  }
 catch (  Exception ee) {
    return null;
  }
}
 

Example 58

From project AudioBox.fm-JavaLib, under directory /audiobox.fm-core/src/main/java/fm/audiobox/configurations/.

Source file: DefaultResponseParser.java

  31 
vote

@Override public void parseAsXml(InputStream inputStream,IEntity destEntity) throws ServiceException {
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    xr.setContentHandler(new XmlParser(destEntity));
    xr.parse(new InputSource(inputStream));
  }
 catch (  ParserConfigurationException e) {
    log.error("An error occurred while instantiating XML Parser",e);
    throw new ServiceException(ServiceException.GENERIC_ERROR,e.getMessage());
  }
catch (  SAXException e) {
    log.error("An error occurred while instantiating XML Parser",e);
    throw new ServiceException(ServiceException.GENERIC_ERROR,e.getMessage());
  }
catch (  IllegalStateException e) {
    log.error("An error occurred while parsing response",e);
    throw new ServiceException(ServiceException.GENERIC_ERROR,e.getMessage());
  }
catch (  IOException e) {
    log.error("An error occurred while parsing response",e);
    throw new ServiceException(ServiceException.GENERIC_ERROR,e.getMessage());
  }
}
 

Example 59

From project BBC-News-Reader, under directory /src/org/mcsoxford/rss/.

Source file: RSSParser.java

  31 
vote

/** 
 * Parses input stream as RSS feed. It is the responsibility of the caller to close the RSS feed input stream.
 * @param feed RSS 2.0 feed input stream
 * @return in-memory representation of RSS feed
 * @throws RSSFault if an unrecoverable parse error occurs
 */
public RSSFeed parse(InputStream feed){
  try {
    final SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setFeature("http://xml.org/sax/features/namespaces",false);
    factory.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
    final SAXParser parser=factory.newSAXParser();
    return parse(parser,feed);
  }
 catch (  ParserConfigurationException e) {
    throw new RSSFault(e);
  }
catch (  SAXException e) {
    throw new RSSFault(e);
  }
catch (  IOException e) {
    throw new RSSFault(e);
  }
}
 

Example 60

From project BDSup2Sub, under directory /src/main/java/bdsup2sub/supstream/bdnxml/.

Source file: SupXml.java

  31 
vote

/** 
 * Constructor (for reading)
 * @param fn file name of Xml file to read
 * @throws CoreException
 */
public SupXml(String fn) throws CoreException {
  this.pathName=FilenameUtils.addSeparator(FilenameUtils.getParent(fn));
  this.title=FilenameUtils.removeExtension(FilenameUtils.getName(fn));
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser saxParser;
  try {
    saxParser=factory.newSAXParser();
    DefaultHandler handler=new XmlHandler();
    saxParser.parse(new File(fn),handler);
  }
 catch (  ParserConfigurationException e) {
    throw new CoreException(e.getMessage());
  }
catch (  SAXException e) {
    throw new CoreException(e.getMessage());
  }
catch (  IOException e) {
    throw new CoreException(e.getMessage());
  }
  logger.trace("\nDetected " + numForcedFrames + " forced captions.\n");
}
 

Example 61

From project blacktie, under directory /jatmibroker-nbf/src/main/java/org/jboss/narayana/blacktie/jatmibroker/nbf/.

Source file: NBFParser.java

  31 
vote

public NBFParser(String xsdFilename) throws ConfigurationException {
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    SchemaFactory schemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    factory.setFeature("http://apache.org/xml/features/validation/schema",true);
    File file=new File(xsdFilename);
    if (file.exists()) {
      schema=schemaFactory.newSchema(file);
    }
 else {
      throw new ConfigurationException("Could not find " + xsdFilename);
    }
    factory.setSchema(schema);
    saxParser=factory.newSAXParser();
    PSVIProvider p=(PSVIProvider)saxParser.getXMLReader();
    handler=new NBFHandlers(p);
  }
 catch (  SAXException e) {
    log.error("Could not create a SAXParser: " + e.getMessage(),e);
    throw new ConfigurationException("Could not create a SAXParser: " + e.getMessage());
  }
catch (  ParserConfigurationException e) {
    log.error("Could not create a SAXParser: " + e.getMessage(),e);
    throw new ConfigurationException("Could not create a SAXParser: " + e.getMessage());
  }
catch (  Throwable e) {
    log.error("Could not create a SAXParser: " + e.getMessage(),e);
    throw new ConfigurationException("Could not create a SAXParser: " + e.getMessage());
  }
}
 

Example 62

From project C-Cat, under directory /util/src/main/java/gov/llnl/ontology/text/corpora/.

Source file: PubMedDocumentReader.java

  31 
vote

/** 
 * Creates a new  {@link PubMedDocumentReader}
 */
public PubMedDocumentReader(){
  b=new StringBuilder();
  SAXParserFactory saxfac=SAXParserFactory.newInstance();
  saxfac.setValidating(false);
  try {
    saxfac.setFeature("http://xml.org/sax/features/validation",false);
    saxfac.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",false);
    saxfac.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
    saxfac.setFeature("http://xml.org/sax/features/external-general-entities",false);
    saxfac.setFeature("http://xml.org/sax/features/external-parameter-entities",false);
    saxParser=saxfac.newSAXParser();
  }
 catch (  SAXNotRecognizedException e1) {
    throw new RuntimeException(e1);
  }
catch (  SAXNotSupportedException e1) {
    throw new RuntimeException(e1);
  }
catch (  ParserConfigurationException e1) {
    throw new RuntimeException(e1);
  }
catch (  SAXException e) {
    throw new RuntimeException(e);
  }
}
 

Example 63

From project closure-templates, under directory /java/src/com/google/template/soy/xliffmsgplugin/.

Source file: XliffParser.java

  31 
vote

/** 
 * Parses the content of a translated XLIFF file and creates a SoyMsgBundle.
 * @param xliffContent The XLIFF content to parse.
 * @return The resulting SoyMsgBundle.
 * @throws SAXException If there's an error parsing the data.
 * @throws SoyMsgException If there's an error in parsing the data.
 */
static SoyMsgBundle parseXliffTargetMsgs(String xliffContent) throws SAXException, SoyMsgException {
  SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
  SAXParser saxParser;
  try {
    saxParser=saxParserFactory.newSAXParser();
  }
 catch (  ParserConfigurationException pce) {
    throw new AssertionError("Could not get SAX parser for XML.");
  }
  XliffSaxHandler xliffSaxHandler=new XliffSaxHandler();
  try {
    saxParser.parse(new InputSource(new StringReader(xliffContent)),xliffSaxHandler);
  }
 catch (  IOException e) {
    throw new AssertionError("Should not fail in reading a string.");
  }
  return new SoyMsgBundleImpl(xliffSaxHandler.getTargetLocaleString(),xliffSaxHandler.getMsgs());
}
 

Example 64

From project Cloud9, under directory /src/dist/edu/umd/hooka/corpora/.

Source file: ParallelCorpusReader.java

  31 
vote

public static void parseXMLDocument(String file,PChunkCallback cb){
  ParallelCorpusReader pcr=new ParallelCorpusReader(cb);
  final SAXParserFactory spf=SAXParserFactory.newInstance();
  try {
    final SAXParser sp=spf.newSAXParser();
    sp.parse(file,pcr);
  }
 catch (  final SAXException se) {
    se.printStackTrace();
  }
catch (  final ParserConfigurationException pce) {
    pce.printStackTrace();
  }
catch (  final IOException ie) {
    ie.printStackTrace();
  }
}
 

Example 65

From project core_5, under directory /exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/.

Source file: XMLDocumentReader.java

  31 
vote

/** 
 * Cleans the string from tags.
 * @param str the string which contain a text with user's tags.
 * @return The string cleaned from user's tags and their bodies.
 */
private String parse(InputStream is){
  final SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
  SAXParser saxParser;
  StringWriter writer=new StringWriter();
  DefaultHandler dh=new WriteOutContentHandler(writer);
  try {
    saxParser=SecurityHelper.doPrivilegedParserConfigurationOrSAXExceptionAction(new PrivilegedExceptionAction<SAXParser>(){
      public SAXParser run() throws Exception {
        return saxParserFactory.newSAXParser();
      }
    }
);
    saxParser.parse(is,dh);
  }
 catch (  SAXException e) {
    return "";
  }
catch (  IOException e) {
    return "";
  }
catch (  ParserConfigurationException e) {
    return "";
  }
  return writer.toString();
}
 

Example 66

From project dreamDroid, under directory /src/net/reichholf/dreamdroid/parsers/.

Source file: GenericSaxParser.java

  31 
vote

@Override public boolean parse(String input){
  try {
    mError=false;
    mErrorText=null;
    ByteArrayInputStream bais=new ByteArrayInputStream(input.getBytes());
    InputSource is=new InputSource();
    is.setByteStream(bais);
    SAXParserFactory spf=SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    xr.setContentHandler(mHandler);
    xr.parse(is);
    return true;
  }
 catch (  ParserConfigurationException e) {
    Log.e(DreamDroid.LOG_TAG,e.toString());
    mError=true;
    mErrorText=e.toString();
    e.printStackTrace();
  }
catch (  SAXException e) {
    Log.e(DreamDroid.LOG_TAG,e.toString());
    mError=true;
    mErrorText=e.toString();
    e.printStackTrace();
  }
catch (  IOException e) {
    Log.e(DreamDroid.LOG_TAG,e.toString());
    mError=true;
    mErrorText=e.toString();
    e.printStackTrace();
  }
  return false;
}
 

Example 67

From project DrmLicenseService, under directory /src/com/sonyericsson/android/drm/drmlicenseservice/.

Source file: CustomDataParser.java

  31 
vote

public String parseXML(ByteArrayBuffer xmlData){
  if (xmlData != null && xmlData.length() > 0) {
    try {
      ByteArrayInputStream bais=new ByteArrayInputStream(xmlData.buffer(),0,xmlData.length());
      SAXParserFactory spf=SAXParserFactory.newInstance();
      SAXParser sp=spf.newSAXParser();
      XMLReader xr=sp.getXMLReader();
      CustomDataXmlHandler triggerHandler=new CustomDataXmlHandler();
      xr.setContentHandler(triggerHandler);
      xr.parse(new InputSource(bais));
      String customData=triggerHandler.getCustomData();
      return customData;
    }
 catch (    ParserConfigurationException e) {
    }
catch (    SAXException e) {
    }
catch (    IOException e) {
    }
  }
  return null;
}
 

Example 68

From project E12Planner, under directory /src/com/neoware/europlanner/.

Source file: E12DataService.java

  31 
vote

private boolean dataIsValid(String data){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    XMLReader reader=parser.getXMLReader();
    reader.parse(new InputSource(new ByteArrayInputStream(data.getBytes())));
  }
 catch (  SAXException ex) {
    return false;
  }
catch (  IOException ex) {
    return false;
  }
catch (  ParserConfigurationException ex) {
    return false;
  }
  return true;
}
 

Example 69

From project EasySOA, under directory /easysoa-registry/easysoa-registry-web/src/main/java/org/easysoa/beans/.

Source file: EasySOAImportBean.java

  31 
vote

private DocumentModel importSoapUIConf(){
  File soapUIConfFile=null;
  try {
    soapUIConfFile=transferBlobToFile();
    if (soapUIConfFile != null) {
      EasySOALocalApi api=new EasySOALocalApi(documentManager);
      EasySOAImportSoapUIParser soapUiParser=new EasySOAImportSoapUIParser(api,targetWorkspaceModel.getTitle());
      SAXParserFactory factory=SAXParserFactory.newInstance();
      SAXParser saxParser=factory.newSAXParser();
      saxParser.parse(soapUIConfFile,soapUiParser);
      return targetWorkspaceModel;
    }
  }
 catch (  Exception e) {
    log.error("Failed to import SoapUI configuration",e);
  }
 finally {
    if (soapUIConfFile != null) {
      soapUIConfFile.delete();
    }
  }
  return null;
}
 

Example 70

From project eclim, under directory /org.eclim.core/java/org/eclim/plugin/core/util/.

Source file: XmlUtils.java

  31 
vote

/** 
 * Validate the supplied xml file.
 * @param project The project name.
 * @param filename The file path to the xml file.
 * @param schema True to use schema validation relying on thexsi:schemaLocation attribute of the document.
 * @param handler The content handler to use while parsing the file.
 * @return A possibly empty list of errors.
 */
public static List<Error> validateXml(String project,String filename,boolean schema,DefaultHandler handler) throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setValidating(true);
  if (schema) {
    factory.setFeature("http://apache.org/xml/features/validation/schema",true);
    factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
  }
  SAXParser parser=factory.newSAXParser();
  filename=ProjectUtils.getFilePath(project,filename);
  filename=filename.replace('\\','/');
  ErrorAggregator errorHandler=new ErrorAggregator(filename);
  EntityResolver entityResolver=new EntityResolver(FileUtils.getFullPath(filename));
  try {
    parser.parse(new File(filename),getHandler(handler,errorHandler,entityResolver));
  }
 catch (  SAXParseException spe) {
    ArrayList<Error> errors=new ArrayList<Error>();
    errors.add(new Error(spe.getMessage(),filename,spe.getLineNumber(),spe.getColumnNumber(),false));
    return errors;
  }
  return errorHandler.getErrors();
}
 

Example 71

From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/.

Source file: SpringCoreUtils.java

  31 
vote

public static SAXParser getSaxParser(){
  if (!SAX_PARSER_ERROR) {
    try {
      SAXParserFactory factory=SAXParserFactory.newInstance();
      factory.setNamespaceAware(true);
      SAXParser parser=factory.newSAXParser();
      return parser;
    }
 catch (    Exception e) {
      StatusHandler.log(new Status(IStatus.INFO,CorePlugin.PLUGIN_ID,"Error creating SaxParserFactory. Switching to OSGI service reference."));
      SAX_PARSER_ERROR=true;
    }
  }
  BundleContext bundleContext=CorePlugin.getDefault().getBundle().getBundleContext();
  ServiceReference reference=bundleContext.getServiceReference(SAXParserFactory.class.getName());
  if (reference != null) {
    try {
synchronized (SAX_PARSER_LOCK) {
        SAXParserFactory factory=(SAXParserFactory)bundleContext.getService(reference);
        return factory.newSAXParser();
      }
    }
 catch (    Exception e) {
      StatusHandler.log(new Status(IStatus.ERROR,CorePlugin.PLUGIN_ID,"Error creating SaxParserFactory",e));
    }
 finally {
      bundleContext.ungetService(reference);
    }
  }
  return null;
}
 

Example 72

From project encog-java-core, under directory /src/main/java/org/encog/ml/bayesian/bif/.

Source file: BIFUtil.java

  31 
vote

/** 
 * Read a BIF file from a stream.
 * @param is The stream to read from.
 * @return The Bayesian network read.
 */
public static BayesianNetwork readBIF(InputStream is){
  try {
    BIFHandler h=new BIFHandler();
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    sp.parse(is,h);
    return h.getNetwork();
  }
 catch (  IOException ex) {
    throw new BayesianError(ex);
  }
catch (  ParserConfigurationException ex) {
    throw new BayesianError(ex);
  }
catch (  SAXException ex) {
    throw new BayesianError(ex);
  }
}
 

Example 73

From project flexmojos, under directory /flexmojos-testing/flexmojos-test-harness/src/test/java/net/flexmojos/oss/test/.

Source file: FMVerifier.java

  31 
vote

public void parse(File file) throws VerificationException {
  try {
    SAXParserFactory saxFactory=SAXParserFactory.newInstance();
    SAXParser parser=saxFactory.newSAXParser();
    InputSource is=new InputSource(new FileInputStream(file));
    parser.parse(is,this);
  }
 catch (  FileNotFoundException e) {
    throw new VerificationException(e);
  }
catch (  IOException e) {
    throw new VerificationException(e);
  }
catch (  ParserConfigurationException e) {
    throw new VerificationException(e);
  }
catch (  SAXException e) {
    throw new VerificationException(e);
  }
}
 

Example 74

From project flexymind-alpha, under directory /src/com/larvalabs/svgandroid/.

Source file: SVGParser.java

  31 
vote

private static SVG parse(InputStream in,Integer searchColor,Integer replaceColor,boolean whiteMode) throws SVGParseException {
  try {
    long start=System.currentTimeMillis();
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    final Picture picture=new Picture();
    SVGHandler handler=new SVGHandler(picture);
    handler.setColorSwap(searchColor,replaceColor);
    handler.setWhiteMode(whiteMode);
    xr.setContentHandler(handler);
    xr.parse(new InputSource(in));
    SVG result=new SVG(picture,handler.bounds);
    if (!Float.isInfinite(handler.limits.top)) {
      result.setLimits(handler.limits);
    }
    return result;
  }
 catch (  Exception e) {
    throw new SVGParseException(e);
  }
}
 

Example 75

From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/model/google/.

Source file: RssParser.java

  31 
vote

public void parse(){
  SAXParserFactory spf=null;
  SAXParser sp=null;
  spf=SAXParserFactory.newInstance();
  try {
    InputSource is=new InputSource(new InputStreamReader(content,"utf-8"));
    if (spf != null) {
      sp=spf.newSAXParser();
      sp=spf.newSAXParser();
      sp.parse(is,this);
    }
  }
 catch (  ParserConfigurationException e) {
    e.printStackTrace();
  }
catch (  SAXException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    try {
    }
 catch (    Exception e) {
    }
  }
}
 

Example 76

From project flyingsaucer, under directory /flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/.

Source file: SplitterTest.java

  31 
vote

public static void main(String[] args) throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setValidating(false);
  XMLReader reader=factory.newSAXParser().getXMLReader();
  reader.setErrorHandler(new ErrorHandler(){
    public void error(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    public void fatalError(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    public void warning(    SAXParseException exception) throws SAXException {
      throw exception;
    }
  }
);
  DocumentSplitter splitter=new DocumentSplitter();
  reader.setContentHandler(splitter);
  reader.parse(args[0]);
  for (Iterator i=splitter.getDocuments().iterator(); i.hasNext(); ) {
    Document doc=(Document)i.next();
    System.out.println(doc.getDocumentElement());
  }
}
 

Example 77

From project God-Save-The-Bag, under directory /src/com/estudio/cheke/game/gstb/.

Source file: SVGParser.java

  31 
vote

private static SVG parse(InputStream in,Integer searchColor,Integer replaceColor,boolean whiteMode) throws SVGParseException {
  SVGHandler svgHandler=null;
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    final Picture picture=new Picture();
    svgHandler=new SVGHandler(picture);
    svgHandler.setColorSwap(searchColor,replaceColor);
    svgHandler.setWhiteMode(whiteMode);
    CopyInputStream cin=new CopyInputStream(in);
    IDHandler idHandler=new IDHandler();
    xr.setContentHandler(idHandler);
    xr.parse(new InputSource(cin.getCopy()));
    svgHandler.idXml=idHandler.idXml;
    xr.setContentHandler(svgHandler);
    xr.parse(new InputSource(cin.getCopy()));
    SVG result=new SVG(picture,svgHandler.bounds);
    if (!Float.isInfinite(svgHandler.limits.top)) {
      result.setLimits(svgHandler.limits);
    }
    return result;
  }
 catch (  Exception e) {
    throw new SVGParseException(e);
  }
}
 

Example 78

From project guj.com.br, under directory /src/net/jforum/security/.

Source file: XMLPermissionControl.java

  31 
vote

/** 
 * @return <code>List</code> object containing <code>Section</code> objects. Each<code>Section</code>  contains many <code>PermissionItem</code> objects,  which represent the permission elements of some section. For its turn, the <code>PermissionItem</code> objects have many <code>FormSelectedData</code> objects, which are the ones responsible to store field values, and which values are checked and which not.
 * @param xmlFile String
 */
public List loadConfigurations(String xmlFile){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser parser=factory.newSAXParser();
    File fileInput=new File(xmlFile);
    if (fileInput.exists()) {
      parser.parse(fileInput,this);
    }
 else {
      InputSource inputSource=new InputSource(xmlFile);
      parser.parse(inputSource,this);
    }
    return this.listSections;
  }
 catch (  Exception e) {
    throw new ForumException(e);
  }
}
 

Example 79

From project hdiv, under directory /hdiv-config/src/main/java/org/hdiv/config/validations/.

Source file: DefaultValidationParser.java

  31 
vote

/** 
 * Read xml file from the given path.
 * @param filePath xml file path
 */
public void readDefaultValidations(String filePath){
  try {
    ClassLoader classLoader=DefaultValidationParser.class.getClassLoader();
    InputStream is=classLoader.getResourceAsStream(filePath);
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    sp.parse(is,this);
  }
 catch (  ParserConfigurationException e) {
    throw new HDIVException(e.getMessage());
  }
catch (  SAXException e) {
    throw new HDIVException(e.getMessage());
  }
catch (  IOException e) {
    throw new HDIVException(e.getMessage());
  }
}
 

Example 80

From project ISAconfigurator, under directory /src/main/java/org/isatools/isacreatorconfigurator/configui/io/xml/.

Source file: SimpleXMLParser.java

  31 
vote

public void parseStructureFile(){
  SAXParserFactory spf=SAXParserFactory.newInstance();
  try {
    SAXParser sp=spf.newSAXParser();
    sp.parse(fileLocation,this);
  }
 catch (  SAXException se) {
    log.error("SAX Exception Caught: \n Details are: \n" + se.getMessage());
  }
catch (  ParserConfigurationException pce) {
    log.error("Parser Configuration Exception Caught: \n Details are: \n" + pce.getMessage());
  }
catch (  IOException ioe) {
    log.error("File not found: \n Details are: \n" + ioe.getMessage());
  }
}
 

Example 81

From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/ontologymanager/bioportal/xmlresulthandlers/.

Source file: BioPortalOntologyListResultHandler.java

  31 
vote

/** 
 * Parse the config.xml file
 * @param fileLoc - location of file to be parsed!
 */
public List<Ontology> parseFile(String fileLoc){
  result=new ArrayList<Ontology>();
  SAXParserFactory spf=SAXParserFactory.newInstance();
  try {
    SAXParser sp=spf.newSAXParser();
    sp.parse(fileLoc,this);
    return result;
  }
 catch (  SAXException se) {
    log.error("SAX Exception Caught: \n Details are: \n" + se.getMessage());
  }
catch (  ParserConfigurationException pce) {
    log.error("Parser Configuration Exception Caught: \n Details are: \n" + pce.getMessage());
  }
catch (  IOException ioe) {
    log.error("File not found: \n Details are: \n" + ioe.getMessage());
  }
  return null;
}
 

Example 82

From project JaamSim, under directory /com/eteks/sweethome3d/j3d/.

Source file: DAELoader.java

  31 
vote

/** 
 * Returns the scene parsed from a Collada XML stream. 
 */
private Scene parseXMLStream(InputStream in,URL baseUrl) throws IOException {
  try {
    SceneBase scene=new SceneBase();
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser saxParser=factory.newSAXParser();
    saxParser.parse(in,new DAEHandler(scene,baseUrl));
    return scene;
  }
 catch (  ParserConfigurationException ex) {
    IOException ex2=new IOException("Can't parse XML stream");
    ex2.initCause(ex);
    throw ex2;
  }
catch (  SAXException ex) {
    IOException ex2=new IOException("Can't parse XML stream");
    ex2.initCause(ex);
    throw ex2;
  }
}
 

Example 83

From project jangaroo-tools, under directory /exml/exml-compiler/src/main/java/net/jangaroo/exml/parser/.

Source file: ExmlToModelParser.java

  31 
vote

private Document buildDom(InputStream inputStream) throws SAXException, IOException {
  SAXParser parser;
  final Document doc;
  try {
    final SAXParserFactory saxFactory=SAXParserFactory.newInstance();
    saxFactory.setNamespaceAware(true);
    parser=saxFactory.newSAXParser();
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    doc=factory.newDocumentBuilder().newDocument();
  }
 catch (  ParserConfigurationException e) {
    throw new IllegalStateException("a default dom builder should be provided",e);
  }
  PreserveLineNumberHandler handler=new PreserveLineNumberHandler(doc);
  parser.parse(inputStream,handler);
  return doc;
}
 

Example 84

From project jboss-jstl-api_spec, under directory /src/main/java/javax/servlet/jsp/jstl/tlv/.

Source file: PermittedTaglibsTLV.java

  31 
vote

public synchronized ValidationMessage[] validate(String prefix,String uri,PageData page){
  try {
    this.uri=uri;
    permittedTaglibs=readConfiguration();
    DefaultHandler h=new PermittedTaglibsHandler();
    SAXParserFactory f=SAXParserFactory.newInstance();
    f.setValidating(true);
    SAXParser p=f.newSAXParser();
    p.parse(page.getInputStream(),h);
    if (failed)     return vmFromString("taglib " + prefix + " ("+ uri+ ") allows only the "+ "following taglibs to be imported: "+ permittedTaglibs);
 else     return null;
  }
 catch (  SAXException ex) {
    return vmFromString(ex.toString());
  }
catch (  ParserConfigurationException ex) {
    return vmFromString(ex.toString());
  }
catch (  IOException ex) {
    return vmFromString(ex.toString());
  }
}
 

Example 85

From project jdocbook-core, under directory /src/main/java/org/jboss/jdocbook/util/.

Source file: FileUtils.java

  31 
vote

/** 
 * Create a SAXSource from a given <tt>file</tt>. <p/> NOTE: the result <b>is</b>  {@link java.io.BufferedInputStream buffered}.
 * @param file The file from which to generate a SAXSource
 * @param resolver An entity resolver to apply to the file reader.
 * @param valueInjections The values to be injected
 * @return An appropriate SAXSource
 */
public static SAXSource createSAXSource(File file,EntityResolver resolver,final LinkedHashSet<ValueInjection> valueInjections){
  try {
    final InputSource source=createInputSource(file,valueInjections);
    SAXParserFactory factory=new SAXParserFactoryImpl();
    factory.setXIncludeAware(true);
    XMLReader reader=factory.newSAXParser().getXMLReader();
    reader.setEntityResolver(resolver);
    reader.setFeature(Constants.DTD_LOADING_FEATURE,true);
    reader.setFeature(Constants.DTD_VALIDATION_FEATURE,false);
    return new SAXSource(reader,source);
  }
 catch (  ParserConfigurationException e) {
    throw new JDocBookProcessException("unable to build SAX Parser/Factory [" + e.getMessage() + "]",e);
  }
catch (  SAXException e) {
    throw new JDocBookProcessException("unable to build SAX Parser/Factory [" + e.getMessage() + "]",e);
  }
}
 

Example 86

From project jforum2, under directory /src/net/jforum/security/.

Source file: XMLPermissionControl.java

  31 
vote

/** 
 * @return <code>List</code> object containing <code>Section</code> objects. Each<code>Section</code>  contains many <code>PermissionItem</code> objects,  which represent the permission elements of some section. For its turn, the <code>PermissionItem</code> objects have many <code>FormSelectedData</code> objects, which are the ones responsible to store field values, and which values are checked and which not.
 * @param xmlFile String
 */
public List loadConfigurations(String xmlFile){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser parser=factory.newSAXParser();
    File fileInput=new File(xmlFile);
    if (fileInput.exists()) {
      parser.parse(fileInput,this);
    }
 else {
      InputSource inputSource=new InputSource(xmlFile);
      parser.parse(inputSource,this);
    }
    return this.listSections;
  }
 catch (  Exception e) {
    throw new ForumException(e);
  }
}
 

Example 87

From project jreepad, under directory /src/jreepad/io/.

Source file: XmlReader.java

  31 
vote

public JreepadTreeModel read(InputStream in) throws IOException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  Handler handler=null;
  try {
    SAXParser parser=factory.newSAXParser();
    handler=new Handler();
    parser.parse(in,handler);
  }
 catch (  ParserConfigurationException e) {
    throw new IOException(e.toString());
  }
catch (  SAXException e) {
    throw new IOException(e.toString());
  }
  JreepadTreeModel document=new JreepadTreeModel(handler.getRoot());
  document.setFileType(JreepadPrefs.FILETYPE_XML);
  return document;
}
 

Example 88

From project karaf, under directory /features/core/src/main/java/org/apache/karaf/features/internal/model/.

Source file: JaxbUtil.java

  31 
vote

/** 
 * Read in a Features from the input stream.
 * @param in       input stream to read
 * @param validate whether to validate the input.
 * @return a Features read from the input stream
 * @throws ParserConfigurationException is the SAX parser can not be configured
 * @throws SAXException                 if there is an xml problem
 * @throws JAXBException                if the xml cannot be marshalled into a T.
 */
public static Features unmarshal(InputStream in,boolean validate){
  InputSource inputSource=new InputSource(in);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setValidating(validate);
  SAXParser parser;
  try {
    parser=factory.newSAXParser();
    Unmarshaller unmarshaller=FEATURES_CONTEXT.createUnmarshaller();
    unmarshaller.setEventHandler(new ValidationEventHandler(){
      public boolean handleEvent(      ValidationEvent validationEvent){
        System.out.println(validationEvent);
        return false;
      }
    }
);
    XMLFilter xmlFilter=new NoSourceAndNamespaceFilter(parser.getXMLReader());
    xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
    SAXSource source=new SAXSource(xmlFilter,inputSource);
    return (Features)unmarshaller.unmarshal(source);
  }
 catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
catch (  JAXBException e) {
    throw new RuntimeException(e);
  }
catch (  SAXException e) {
    throw new RuntimeException(e);
  }
}
 

Example 89

From project kumvandroid, under directory /src/com/ijuru/kumva/search/.

Source file: OnlineSearch.java

  31 
vote

/** 
 * @see com.ijuru.kumva.search.Search#doSearch(String)
 */
@Override public SearchResult doSearch(String query,int limit){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    QueryXMLHandler handler=new QueryXMLHandler();
    handler.addListener(this);
    URL url=dictionary.createQueryURL(query,limit);
    URLConnection connection=url.openConnection();
    connection.setRequestProperty("Accept-Encoding","gzip");
    connection.setConnectTimeout(timeout);
    connection.setReadTimeout(timeout);
    InputStream stream=connection.getInputStream();
    if ("gzip".equals(connection.getContentEncoding()))     stream=new GZIPInputStream(stream);
    InputSource source=new InputSource(stream);
    parser.parse(source,handler);
    stream.close();
    return new SearchResult(handler.getSuggestion(),results);
  }
 catch (  Exception e) {
    Log.e("Kumva",e.getMessage(),e);
    return null;
  }
}
 

Example 90

From project LitHub, under directory /LitHub-Android/src/us/lithub/data/.

Source file: BookParser.java

  31 
vote

public static Map<String,String> getBookAttributesFromUpc(String upc){
  try {
    final URL url=new URL("http://isbndb.com/api/books.xml?access_key=MIIRXTQX&index1=isbn&value1=" + upc);
    final SAXParserFactory spf=SAXParserFactory.newInstance();
    final SAXParser sp=spf.newSAXParser();
    final XMLReader xr=sp.getXMLReader();
    final IsbnDbHandler handler=new IsbnDbHandler();
    xr.setContentHandler(handler);
    xr.parse(new InputSource(url.openStream()));
    return handler.getAttributes();
  }
 catch (  MalformedURLException e) {
    Log.e(TAG,e.getMessage());
  }
catch (  SAXException e) {
    Log.e(TAG,e.getMessage());
  }
catch (  ParserConfigurationException e) {
    Log.e(TAG,e.getMessage());
  }
catch (  IOException e) {
    Log.e(TAG,e.getMessage());
  }
  return null;
}
 

Example 91

From project lor-jamwiki, under directory /jamwiki-core/src/main/java/org/jamwiki/migrate/.

Source file: MediaWikiXmlImporter.java

  31 
vote

/** 
 */
private void importWikiXml(File file) throws MigrationException {
  System.setProperty("entityExpansionLimit","1000000");
  SAXParserFactory factory=SAXParserFactory.newInstance();
  FileInputStream fis=null;
  try {
    fis=new FileInputStream(file);
    SAXParser saxParser=factory.newSAXParser();
    saxParser.parse(fis,this);
  }
 catch (  ParserConfigurationException e) {
    throw new MigrationException(e);
  }
catch (  IOException e) {
    throw new MigrationException(e);
  }
catch (  SAXException e) {
    if (e.getCause() instanceof DataAccessException || e.getCause() instanceof WikiException) {
      throw new MigrationException(e.getCause());
    }
 else {
      throw new MigrationException(e);
    }
  }
 finally {
    IOUtils.closeQuietly(fis);
  }
}
 

Example 92

From project maven-shared, under directory /maven-verifier/src/main/java/org/apache/maven/it/.

Source file: Verifier.java

  31 
vote

public void parse(File file) throws VerificationException {
  try {
    SAXParserFactory saxFactory=SAXParserFactory.newInstance();
    SAXParser parser=saxFactory.newSAXParser();
    InputSource is=new InputSource(new FileInputStream(file));
    parser.parse(is,this);
  }
 catch (  FileNotFoundException e) {
    throw new VerificationException("file not found path : " + file.getAbsolutePath(),e);
  }
catch (  IOException e) {
    throw new VerificationException(" IOException path : " + file.getAbsolutePath(),e);
  }
catch (  ParserConfigurationException e) {
    throw new VerificationException(e);
  }
catch (  SAXException e) {
    throw new VerificationException("Parsing exception for file " + file.getAbsolutePath(),e);
  }
}
 

Example 93

From project mediautilities, under directory /src/com/larvalabs/svgandroid/.

Source file: SVGParser.java

  31 
vote

private static SVG parse(InputStream in,Integer searchColor,Integer replaceColor,boolean whiteMode) throws SVGParseException {
  SVGHandler svgHandler=null;
  try {
    SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser sp=spf.newSAXParser();
    XMLReader xr=sp.getXMLReader();
    final Picture picture=new Picture();
    svgHandler=new SVGHandler(picture);
    svgHandler.setColorSwap(searchColor,replaceColor);
    svgHandler.setWhiteMode(whiteMode);
    CopyInputStream cin=new CopyInputStream(in);
    IDHandler idHandler=new IDHandler();
    xr.setContentHandler(idHandler);
    xr.parse(new InputSource(cin.getCopy()));
    svgHandler.idXml=idHandler.idXml;
    xr.setContentHandler(svgHandler);
    xr.parse(new InputSource(cin.getCopy()));
    SVG result=new SVG(picture,svgHandler.bounds);
    if (!Float.isInfinite(svgHandler.limits.top)) {
      result.setLimits(svgHandler.limits);
    }
    return result;
  }
 catch (  Exception e) {
    throw new SVGParseException(e);
  }
}
 

Example 94

From project MEditor, under directory /editor-common/editor-common-server/src/main/java/cz/mzk/editor/server/fedora/utils/.

Source file: DocumentLoader.java

  31 
vote

public static Document loadDocument(InputStream in,boolean validate) throws DocumentException {
  try {
    SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();
    SAXParser saxParser=saxParserFactory.newSAXParser();
    XMLReader parser=saxParser.getXMLReader();
    parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
    parser.setFeature("http://xml.org/sax/features/validation",false);
    SAXReader reader=new SAXReader(parser);
    return reader.read(in);
  }
 catch (  ParserConfigurationException ex) {
    Logger.getLogger(DocumentLoader.class.getName()).log(Level.SEVERE,null,ex);
    return null;
  }
catch (  SAXException ex) {
    Logger.getLogger(DocumentLoader.class.getName()).log(Level.SEVERE,null,ex);
    return null;
  }
}
 

Example 95

From project mkgmap, under directory /src/uk/me/parabola/mkgmap/reader/osm/xml/.

Source file: Osm5MapDataSource.java

  31 
vote

/** 
 * Load the .osm file and produce the intermediate format.
 * @param name The filename to read.
 * @throws FileNotFoundException If the file does not exist.
 */
public void load(String name) throws FileNotFoundException, FormatException {
  try {
    InputStream is=Utils.openFile(name);
    SAXParserFactory parserFactory=SAXParserFactory.newInstance();
    parserFactory.setXIncludeAware(true);
    parserFactory.setNamespaceAware(true);
    SAXParser parser=parserFactory.newSAXParser();
    try {
      Osm5XmlHandler handler=new Osm5XmlHandler(getConfig());
      Osm5XmlHandler.SaxHandler saxHandler=handler.new SaxHandler();
      setupHandler(handler);
      parser.parse(is,saxHandler);
      osmReadingHooks.end();
      elementSaver.finishLoading();
      elementSaver.convert(getConverter());
      addBackground();
    }
 catch (    IOException e) {
      throw new FormatException("Error reading file",e);
    }
  }
 catch (  SAXException e) {
    throw new FormatException("Error parsing file",e);
  }
catch (  ParserConfigurationException e) {
    throw new FormatException("Internal error configuring xml parser",e);
  }
}
 

Example 96

From project android-rackspacecloud, under directory /src/com/rackspace/cloud/servers/api/client/.

Source file: FlavorManager.java

  29 
vote

public ArrayList<Flavor> createList(boolean detail,Context context){
  CustomHttpClient httpclient=new CustomHttpClient(context);
  HttpGet get=new HttpGet(Account.getAccount().getServerUrl() + "/flavors/detail.xml?now=cache_time2");
  ArrayList<Flavor> flavors=new ArrayList<Flavor>();
  get.addHeader("X-Auth-Token",Account.getAccount().getAuthToken());
  try {
    HttpResponse resp=httpclient.execute(get);
    BasicResponseHandler responseHandler=new BasicResponseHandler();
    String body=responseHandler.handleResponse(resp);
    if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) {
      FlavorsXMLParser flavorsXMLParser=new FlavorsXMLParser();
      SAXParser saxParser=SAXParserFactory.newInstance().newSAXParser();
      XMLReader xmlReader=saxParser.getXMLReader();
      xmlReader.setContentHandler(flavorsXMLParser);
      xmlReader.parse(new InputSource(new StringReader(body)));
      flavors=flavorsXMLParser.getFlavors();
    }
  }
 catch (  ClientProtocolException cpe) {
  }
catch (  IOException e) {
  }
catch (  ParserConfigurationException e) {
  }
catch (  SAXException e) {
  }
catch (  FactoryConfigurationError e) {
  }
  return flavors;
}
 

Example 97

From project bel-editor, under directory /org.openbel.editor.core/src/org/openbel/editor/core/builder/.

Source file: BELCompileBuilder.java

  29 
vote

private SAXParser getParser() throws ParserConfigurationException, SAXException {
  if (parserFactory == null) {
    parserFactory=SAXParserFactory.newInstance();
  }
  return parserFactory.newSAXParser();
}
 

Example 98

From project ChkBugReport, under directory /src/com/sonyericsson/chkbugreport/util/.

Source file: XMLNode.java

  29 
vote

public static XMLNode parse(InputStream is){
  XMLNodeHandler handler=new XMLNodeHandler();
  try {
    SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
    parser.parse(is,handler);
    return handler.mRoot;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 99

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/chainsaw/.

Source file: LoadXMLAction.java

  29 
vote

/** 
 * Creates a new <code>LoadXMLAction</code> instance.
 * @param aParent the parent frame
 * @param aModel the model to add events to
 * @exception SAXException if an error occurs
 * @throws ParserConfigurationException if an error occurs
 */
LoadXMLAction(JFrame aParent,MyTableModel aModel) throws SAXException, ParserConfigurationException {
  mParent=aParent;
  mHandler=new XMLFileHandler(aModel);
  mParser=SAXParserFactory.newInstance().newSAXParser().getXMLReader();
  mParser.setContentHandler(mHandler);
}
 

Example 100

From project jgraphx, under directory /src/com/mxgraph/reader/.

Source file: mxGraphViewImageReader.java

  29 
vote

/** 
 * Creates the image for the given display XML input source. (Note: The XML is an encoded mxGraphView, not mxGraphModel.)
 * @param inputSource Input source that contains the display XML.
 * @return Returns an image representing the display XML input source.
 */
public static BufferedImage convert(InputSource inputSource,mxGraphViewImageReader viewReader) throws ParserConfigurationException, SAXException, IOException {
  BufferedImage result=null;
  SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
  XMLReader reader=parser.getXMLReader();
  reader.setContentHandler(viewReader);
  reader.parse(inputSource);
  if (viewReader.getCanvas() instanceof mxImageCanvas) {
    result=((mxImageCanvas)viewReader.getCanvas()).destroy();
  }
  return result;
}
 

Example 101

From project lib-gwt-svg, under directory /src/main/java/com/google/gwt/uibinder/rebind/.

Source file: W3cDomHelper.java

  29 
vote

public W3cDomHelper(TreeLogger logger,ResourceOracle resourceOracle){
  this.logger=logger;
  this.resourceOracle=resourceOracle;
  factory=SAXParserFactory.newInstance();
  try {
    factory.setFeature(LOAD_EXTERNAL_DTD,true);
  }
 catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
catch (  SAXException e) {
  }
  factory.setNamespaceAware(true);
}
 

Example 102

From project liquibase, under directory /liquibase-core/src/main/java/liquibase/parser/core/xml/.

Source file: XMLChangeLogSAXParser.java

  29 
vote

public XMLChangeLogSAXParser(){
  saxParserFactory=SAXParserFactory.newInstance();
  if (System.getProperty("java.vm.version").startsWith("1.4")) {
    saxParserFactory.setValidating(false);
    saxParserFactory.setNamespaceAware(false);
  }
 else {
    saxParserFactory.setValidating(true);
    saxParserFactory.setNamespaceAware(true);
  }
}
 

Example 103

From project log4jna, under directory /thirdparty/log4j/src/main/java/org/apache/log4j/chainsaw/.

Source file: LoadXMLAction.java

  29 
vote

/** 
 * Creates a new <code>LoadXMLAction</code> instance.
 * @param aParent the parent frame
 * @param aModel the model to add events to
 * @exception SAXException if an error occurs
 * @throws ParserConfigurationException if an error occurs
 */
LoadXMLAction(JFrame aParent,MyTableModel aModel) throws SAXException, ParserConfigurationException {
  mParent=aParent;
  mHandler=new XMLFileHandler(aModel);
  mParser=SAXParserFactory.newInstance().newSAXParser().getXMLReader();
  mParser.setContentHandler(mHandler);
}
 

Example 104

From project mwe, under directory /plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/internal/core/ast/parser/.

Source file: WorkflowParser.java

  29 
vote

public AbstractASTBase parse(final InputStream in,final String resourceName,final Issues issues){
  resource=resourceName;
  this.issues=issues;
  try {
    final SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
    parser.parse(in,this);
  }
 catch (  final Exception e) {
    root=null;
    log.error(e.getMessage(),e);
    issues.addError(e.getMessage(),resourceName);
  }
  return root;
}