Java Code Examples for org.xml.sax.SAXException

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 and-bible, under directory /IgnoreAndBibleExperiments/experiments/osistohtml/.

Source file: HtmlTextWriter.java

  17 
vote

public void write(String htmlText) throws SAXException {
  try {
    writer.write(htmlText);
  }
 catch (  IOException e) {
    throw new SAXException("I/O error",e);
  }
}
 

Example 2

From project androidquery, under directory /src/com/androidquery/util/.

Source file: XmlDom.java

  17 
vote

/** 
 * Instantiates a new xml dom.
 * @param is Raw XML.
 * @throws SAXException the SAX exception
 */
public XmlDom(InputStream is) throws SAXException {
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder;
  try {
    builder=factory.newDocumentBuilder();
    Document doc=builder.parse(is);
    this.root=(Element)doc.getDocumentElement();
  }
 catch (  ParserConfigurationException e) {
  }
catch (  IOException e) {
    throw new SAXException(e);
  }
}
 

Example 3

From project android_external_tagsoup, under directory /src/org/ccil/cowan/tagsoup/.

Source file: XMLWriter.java

  17 
vote

/** 
 * Write a newline at the end of the document. Pass the event on down the filter chain for further processing.
 * @exception org.xml.sax.SAXException If there is an errorwriting the newline, or if a handler further down the filter chain raises an exception.
 * @see org.xml.sax.ContentHandler#endDocument
 */
public void endDocument() throws SAXException {
  write('\n');
  super.endDocument();
  try {
    flush();
  }
 catch (  IOException e) {
    throw new SAXException(e);
  }
}
 

Example 4

From project apps-for-android, under directory /Samples/Downloader/src/com/google/android/downloader/.

Source file: DownloaderActivity.java

  17 
vote

private static String getRequiredString(Attributes attributes,String localName) throws SAXException {
  String result=attributes.getValue("",localName);
  if (result == null) {
    throw new SAXException("Expected attribute " + localName);
  }
  return result;
}
 

Example 5

From project aviator, under directory /src/main/java/com/googlecode/aviator/asm/xml/.

Source file: ASMContentHandler.java

  17 
vote

/** 
 * Process notification of the end of a document and write generated bytecode into output stream.
 * @exception SAXException if parsing or writing error is to be reported.
 */
public final void endDocument() throws SAXException {
  try {
    os.write(toByteArray());
  }
 catch (  IOException ex) {
    throw new SAXException(ex.toString(),ex);
  }
}
 

Example 6

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/picasa/.

Source file: GDataParser.java

  16 
vote

public void startElement(String uri,String localName,String qName,Attributes attrs) throws SAXException {
switch (mState) {
case STATE_DOCUMENT:
    if (uri.equals(ATOM_NAMESPACE) && localName.equals(FEED_ELEMENT)) {
      mState=STATE_FEED;
    }
 else {
      throw new SAXException();
    }
  break;
case STATE_FEED:
if (uri.equals(ATOM_NAMESPACE) && localName.equals(ENTRY_ELEMENT)) {
  mState=STATE_ENTRY;
  mEntry.clear();
}
 else {
  startProperty(uri,localName,attrs);
}
break;
case STATE_ENTRY:
startProperty(uri,localName,attrs);
break;
}
}
 

Example 7

From project Absolute-Android-RSS, under directory /src/com/AA/Other/.

Source file: RSSParse.java

  15 
vote

/** 
 * Get the XML document for the RSS feed
 * @return the XML Document for the feed on success, on error returns null
 */
private static Document getDocument(){
  Document doc=null;
  try {
    DocumentBuilder builder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
    DefaultHttpClient client=new DefaultHttpClient();
    HttpGet request=new HttpGet(URI);
    HttpResponse response=client.execute(request);
    doc=builder.parse(response.getEntity().getContent());
  }
 catch (  java.io.IOException e) {
    return null;
  }
catch (  SAXException e) {
    Log.e("AARSS","Parse Exception in RSS feed",e);
    return null;
  }
catch (  Exception e) {
    return null;
  }
  return doc;
}
 

Example 8

From project accounted4, under directory /accounted4/stock-quote/stock-quote-tmx/src/main/java/com/accounted4/stockquote/tmx/.

Source file: TmxOptionPageHandler.java

  15 
vote

@Override public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException {
  if (!underlyingCommodoityPriceFieldToCollect.isEmpty() && qName.equalsIgnoreCase("STRONG")) {
    collectUnderlyingCommodityPrice=true;
    return;
  }
  if (null == optionType) {
    return;
  }
  if (qName.equalsIgnoreCase("TR") && null != attributes.getValue("title")) {
    String title=attributes.getValue("title");
    optionBuilder=new String[6];
    optionBuilder[0]=title;
    optionRowProcessing=true;
    optionColumnIndex=-1;
    return;
  }
  if (optionRowProcessing && qName.equalsIgnoreCase("TD")) {
    optionColumnIndex++;
    optionColumnProcessing=true;
    return;
  }
}
 

Example 9

From project activemq-apollo, under directory /apollo-dto/src/main/java/org/apache/activemq/apollo/dto/.

Source file: XmlCodec.java

  15 
vote

static public <T>T decode(Class<T> clazz,InputStream is,Properties props,ValidationEventHandler validationHandler) throws IOException, XMLStreamException, JAXBException, SAXException {
  ClassLoader original=Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(ClassFinder.class_loader());
    if (is == null) {
      throw new IllegalArgumentException("input stream was null");
    }
    try {
      XMLStreamReader reader=factory.createXMLStreamReader(is);
      if (props != null) {
        reader=new PropertiesFilter(reader,props);
      }
      Unmarshaller unmarshaller=context().createUnmarshaller();
      if (validationHandler != null) {
        try {
          SchemaFactory sf=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          sf.setFeature("http://apache.org/xml/features/validation/schema-full-checking",false);
          Schema schema=sf.newSchema(XmlCodec.class.getResource("apollo.xsd"));
          unmarshaller.setSchema(schema);
          unmarshaller.setEventHandler(validationHandler);
        }
 catch (        Exception e) {
          System.err.println("Could not load schema: " + e.getMessage());
        }
      }
      return clazz.cast(unmarshaller.unmarshal(reader));
    }
  finally {
      is.close();
    }
  }
  finally {
    Thread.currentThread().setContextClassLoader(original);
  }
}
 

Example 10

From project addis, under directory /application/src/main/java/org/drugis/addis/imports/.

Source file: PubMedIDRetriever.java

  15 
vote

public static Document parse(InputStream is) throws IOException {
  DocumentBuilderFactory domFactory=DocumentBuilderFactory.newInstance();
  domFactory.setValidating(false);
  domFactory.setNamespaceAware(false);
  domFactory.setIgnoringElementContentWhitespace(true);
  DocumentBuilder builder=null;
  try {
    builder=domFactory.newDocumentBuilder();
  }
 catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
  Document ret;
  try {
    ret=builder.parse(is);
  }
 catch (  SAXException e) {
    throw new ParseException("Error parsing PubMed response",e);
  }
  return ret;
}
 

Example 11

From project adg-android, under directory /src/com/analysedesgeeks/android/rss/.

Source file: RssHandler.java

  15 
vote

@Override public void endElement(final String uri,final String localName,final String name) throws SAXException {
  super.endElement(uri,localName,name);
  try {
    if (this.currentFeedItem != null) {
      if (localName.equalsIgnoreCase(TITLE)) {
        currentFeedItem.title=builder.toString();
      }
 else       if (localName.equalsIgnoreCase(LINK)) {
        currentFeedItem.link=builder.toString();
      }
 else       if (localName.equalsIgnoreCase(DESCRIPTION)) {
        currentFeedItem.description=builder.toString();
      }
 else       if (localName.equalsIgnoreCase(PUB_DATE)) {
        currentFeedItem.date=DateUtils.Parser.GMT_DATE_PARSER.parse(builder.toString());
      }
 else       if (localName.equalsIgnoreCase(ITEM)) {
        messages.add(currentFeedItem);
      }
      builder.setLength(0);
    }
  }
 catch (  final Exception e) {
    Ln.e(e);
  }
}
 

Example 12

From project adt-maven-plugin, under directory /src/main/java/com/yelbota/plugins/adt/model/.

Source file: AneModel.java

  15 
vote

private void parseXml(byte[] s) throws MojoFailureException {
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  try {
    DocumentBuilder db=dbf.newDocumentBuilder();
    Document dom=db.parse(new InputSource(new ByteArrayInputStream(s)));
    NodeList nl=dom.getDocumentElement().getChildNodes();
    for (int i=0; i < nl.getLength(); i++) {
      Object uel=nl.item(i);
      if (uel instanceof Element) {
        Element el=(Element)uel;
        String nodeName=el.getNodeName();
        if (nodeName.equals("id"))         id=el.getTextContent();
      }
    }
  }
 catch (  ParserConfigurationException e) {
    throwParseFail(file,e);
  }
catch (  SAXException e) {
    throwParseFail(file,e);
  }
catch (  IOException e) {
    throwParseFail(file,e);
  }
}
 

Example 13

From project Agot-Java, under directory /src/main/java/got/pojo/.

Source file: GameInfo.java

  15 
vote

public void readTerritoriesXML() throws ParserConfigurationException, SAXException, IOException {
  DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
  DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
  Document doc;
  doc=dBuilder.parse(getClass().getResourceAsStream("/got/resource/xml/territory.xml"));
  doc.getDocumentElement().normalize();
  NodeList nList=doc.getElementsByTagName("Territory");
  for (int temp=0; temp < nList.getLength(); temp++) {
    TerritoryInfo ti=new TerritoryInfo();
    Node nNode=nList.item(temp);
    String name=nNode.getAttributes().getNamedItem("Name").getNodeValue();
    String mustering=nNode.getAttributes().getNamedItem("Mustering").getNodeValue();
    String supply=nNode.getAttributes().getNamedItem("Supply").getNodeValue();
    String power=nNode.getAttributes().getNamedItem("Power").getNodeValue();
    String port=nNode.getAttributes().getNamedItem("Port").getNodeValue();
    String type=nNode.getAttributes().getNamedItem("Type").getNodeValue();
    ti.setName(name);
    ti.setMustering(Integer.valueOf(mustering));
    ti.setSupply(Integer.valueOf(supply));
    ti.setPower(Integer.valueOf(power));
    ti.setType(TerritoryType.values()[Integer.valueOf(type)]);
    ti.setAction(Action.NONE);
    for (    Arm arm : Arm.values()) {
      ti.getConquerArms().put(arm,0);
    }
    getTerrMap().put(ti.getName(),ti);
    getConnTerritories().put(ti.getName(),new ArrayList<String>());
  }
}
 

Example 14

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

Source file: IPConfig.java

  15 
vote

/** 
 * Method that loads IPConfig
 */
static void load(){
  try {
    SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
    parser.parse(new File(CONFIG_FILE),new DefaultHandler(){
      @Override public void startElement(      String uri,      String localName,      String qName,      Attributes attributes) throws SAXException {
        if (qName.equals("ipconfig")) {
          defaultAddress=IPRange.toByteArray(attributes.getValue("default"));
        }
 else         if (qName.equals("iprange")) {
          String min=attributes.getValue("min");
          String max=attributes.getValue("max");
          String address=attributes.getValue("address");
          IPRange ipRange=new IPRange(min,max,address);
          ranges.add(ipRange);
        }
      }
    }
);
  }
 catch (  Exception e) {
    log.fatal("Critical error while parsing ipConfig",e);
    throw new Error("Can't load ipConfig",e);
  }
}
 

Example 15

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

Source file: AirSigmetParser.java

  15 
vote

@Override public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException {
  String attr;
  if (qName.equalsIgnoreCase("AIRSIGMET")) {
    entry=new AirSigmetEntry();
  }
 else   if (qName.equalsIgnoreCase("altitude")) {
    attr=attributes.getValue("min_ft_msl");
    if (attr != null) {
      entry.minAltitudeFeet=Integer.valueOf(attr);
    }
    attr=attributes.getValue("max_ft_msl");
    if (attr != null) {
      entry.maxAltitudeFeet=Integer.valueOf(attr);
    }
  }
 else   if (qName.equalsIgnoreCase("hazard")) {
    entry.hazardType=attributes.getValue("type");
    entry.hazardSeverity=attributes.getValue("severity");
  }
 else   if (qName.equalsIgnoreCase("area")) {
    entry.points=new ArrayList<AirSigmetPoint>();
  }
 else   if (qName.equalsIgnoreCase("point")) {
    point=new AirSigmetPoint();
  }
 else {
    text.setLength(0);
  }
}
 

Example 16

From project amplafi-sworddance, under directory /src/main/java/com/sworddance/util/.

Source file: AbstractXmlParser.java

  15 
vote

public AbstractXmlParser(InputStream inputStream){
  DocumentBuilder newDocumentBuilder=createDocumentBuilder();
  try {
    this.xmlDocument=newDocumentBuilder.parse(inputStream);
  }
 catch (  SAXException e) {
    throw new ApplicationGeneralException(e);
  }
catch (  IOException e) {
    throw new ApplicationGeneralException(e);
  }
}
 

Example 17

From project android-client_1, under directory /src/com/googlecode/asmack/connection/impl/.

Source file: FeatureNegotiationEngine.java

  15 
vote

/** 
 * Bind a given resource, probably resuming an old session.
 * @param resource String The preferred resource string.
 * @return String The actual resource string.
 * @throws XmppException On Error.
 */
public String bind(String resource) throws XmppException {
  Log.d("BC/XMPP/Negotiation","bind " + resource);
  try {
    if (!TextUtils.isEmpty(resource)) {
      xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>" + resource + "</resource>"+ "</bind>"+ "</iq>");
    }
 else {
      xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "</bind>"+ "</iq>");
    }
    Stanza stanza=xmppInput.nextStanza();
    Node node=XMLUtils.getDocumentNode(stanza.getXml());
    Node bind=XMLUtils.getFirstChild(node,"urn:ietf:params:xml:ns:xmpp-bind","bind");
    Node jid=XMLUtils.getFirstChild(bind,null,"jid");
    if (sessionsSupported) {
      startSession();
    }
    return jid.getTextContent();
  }
 catch (  IllegalArgumentException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
catch (  IllegalStateException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
catch (  SAXException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
}
 

Example 18

From project android-context, under directory /defunct/finance/.

Source file: GoogleFinanceHandler.java

  15 
vote

@Override public void endElement(String uri,String localName,String qName) throws SAXException {
  Log.i(PKG,TAG + ": endElement()");
  if (localName.contentEquals("finance")) {
    inQuote=false;
    quotes.add(currentQuote);
  }
}
 

Example 19

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

Source file: FlavorManager.java

  15 
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 20

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

Source file: RSSParser.java

  15 
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 21

From project android-tether, under directory /src/og/android/tether/.

Source file: RSSReader.java

  15 
vote

void parseRSS(InputStream feed){
  XMLReader parser=null;
  try {
    parser=XMLReaderFactory.createXMLReader();
    parser.setContentHandler(getRSSContentHandler());
    parser.parse(new InputSource(feed));
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
catch (  SAXException e) {
    e.printStackTrace();
  }
}
 

Example 22

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

Source file: DictionaryMaker.java

  15 
vote

/** 
 * Invoke the right input method according to args.
 * @param args the parsed command line arguments.
 * @return the read dictionary.
 */
private static FusionDictionary readInputFromParsedArgs(final Arguments args) throws IOException, UnsupportedFormatException, ParserConfigurationException, SAXException, FileNotFoundException {
  if (null != args.mInputBinary) {
    return readBinaryFile(args.mInputBinary);
  }
 else   if (null != args.mInputUnigramXml) {
    return readXmlFile(args.mInputUnigramXml,args.mInputBigramXml);
  }
 else {
    throw new RuntimeException("No input file specified");
  }
}
 

Example 23

From project Android_1, under directory /org.eclipse.ecf.android/src/org/eclipse/ecf/android/.

Source file: ServerConfigParser.java

  15 
vote

public List load(InputStream ins) throws ParserConfigurationException, SAXException, IOException {
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  DocumentBuilder db=dbf.newDocumentBuilder();
  Document doc=db.parse(ins);
  return loadConnectors(doc);
}
 

Example 24

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

Source file: DictionaryMaker.java

  15 
vote

/** 
 * Invoke the right input method according to args.
 * @param args the parsed command line arguments.
 * @return the read dictionary.
 */
private static FusionDictionary readInputFromParsedArgs(final Arguments args) throws IOException, UnsupportedFormatException, ParserConfigurationException, SAXException, FileNotFoundException {
  if (null != args.mInputBinary) {
    return readBinaryFile(args.mInputBinary);
  }
 else   if (null != args.mInputUnigramXml) {
    return readXmlFile(args.mInputUnigramXml,args.mInputBigramXml);
  }
 else {
    throw new RuntimeException("No input file specified");
  }
}
 

Example 25

From project Anki-Android, under directory /src/com/tomgibara/android/veecheck/.

Source file: VeecheckResult.java

  15 
vote

@Override public void startElement(String uri,String localName,String qName,Attributes attrs) throws SAXException {
  if (skip) {
    return;
  }
  if (!uri.equals(XML_NAMESPACE)) {
    return;
  }
  if (recordNext) {
    if (!localName.equals(INTENT_TAG)) {
      return;
    }
    action=attrs.getValue("action");
    data=attrs.getValue("data");
    type=attrs.getValue("type");
    extras=toMap(attrs.getValue("extras"));
    recordMatch(true);
  }
 else {
    if (!localName.equals(VERSION_TAG)) {
      return;
    }
    VeecheckVersion version=new VeecheckVersion(attrs);
    recordNext=this.version.matches(version);
  }
}
 

Example 26

From project anode, under directory /src/net/haltcondition/anode/.

Source file: ServiceParser.java

  15 
vote

public Service parse(InputStream in){
  try {
    Xml.parse(in,Xml.Encoding.UTF_8,this);
  }
 catch (  IOException e) {
    Log.e(TAG,"IOException " + e.getMessage());
    return null;
  }
catch (  SAXException e) {
    Log.e(TAG,"SAXException " + e.getMessage());
    return null;
  }
  return service;
}
 

Example 27

From project ant4eclipse, under directory /org.ant4eclipse.ant.pde/src/org/ant4eclipse/ant/pde/.

Source file: TargetPlatformDefinitionDataType.java

  15 
vote

/** 
 * {@inheritDoc}
 */
@Override protected void doValidate(){
  if (this._id == null || "".equals(this._id)) {
    throw new Ant4EclipseException(PdeExceptionCode.ANT_ATTRIBUTE_NOT_SET,"id");
  }
  if (this._targetFile != null) {
    if (!this._targetFile.exists()) {
      throw new Ant4EclipseException(PdeExceptionCode.TARGET_FILE_NOT_FOUND,this._targetFile.toString());
    }
    try {
      XMLReader reader=XMLReaderFactory.createXMLReader();
      reader.setContentHandler(new TargetPlattformContentHandler(this._targetFile,this));
      FileInputStream in=new FileInputStream(this._targetFile);
      try {
        reader.parse(new InputSource(new InputStreamReader(in,"UTF-8")));
      }
  finally {
        in.close();
      }
    }
 catch (    SAXException e) {
      Ant4EclipseException exeption=new Ant4EclipseException(PdeExceptionCode.TARGET_PARSING_FAILED,this._targetFile.toString(),e.toString());
      exeption.initCause(e);
      throw exeption;
    }
catch (    IOException e) {
      Ant4EclipseException exeption=new Ant4EclipseException(PdeExceptionCode.TARGET_PARSING_FAILED,this._targetFile.toString(),e.toString());
      exeption.initCause(e);
      throw exeption;
    }
  }
  if (this._targetPlatformDefinition.getLocations().length == 0) {
    A4ELogging.warn("Target definition with id %s does not contain any locations!",this._id);
  }
  TargetPlatformRegistry targetPlatformRegistry=ServiceRegistryAccess.instance().getService(TargetPlatformRegistry.class);
  targetPlatformRegistry.addTargetPlatformDefinition(this._id,this._targetPlatformDefinition);
}
 

Example 28

From project any23, under directory /core/src/main/java/org/apache/any23/extractor/html/.

Source file: TagSoupParser.java

  15 
vote

/** 
 * Returns the DOM of the given document URI. 
 * @return the <i>HTML</i> DOM.
 * @throws IOException
 */
public Document getDOM() throws IOException {
  if (result == null) {
    long startTime=System.currentTimeMillis();
    try {
      result=parse();
    }
 catch (    SAXException ex) {
      throw new RuntimeException("Shouldn not happen, it's a tag soup parser",ex);
    }
catch (    TransformerException ex) {
      throw new RuntimeException("Shouldn not happen, it's a tag soup parser",ex);
    }
catch (    NullPointerException ex) {
      if (ex.getStackTrace()[0].getClassName().equals("java.io.Reader")) {
        throw new RuntimeException("Bug in NekoHTML, try upgrading to newer release!",ex);
      }
 else {
        throw ex;
      }
    }
 finally {
      long elapsed=System.currentTimeMillis() - startTime;
      logger.debug("Parsed " + documentURI + " with NekoHTML, "+ elapsed+ "ms");
    }
  }
  result.setDocumentURI(documentURI);
  return result;
}
 

Example 29

From project apb, under directory /modules/apb-base/src/apb/idegen/.

Source file: IdeaTask.java

  15 
vote

private Document readIdeaFile(@NotNull File ideaFile,final String defaultTemplate){
  Document result=null;
  try {
    DocumentBuilder reader=DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputStream is;
    if (!env.forceBuild() && ideaFile.exists()) {
      is=new FileInputStream(ideaFile);
    }
 else     if (template != null && template.exists()) {
      is=new FileInputStream(template);
    }
 else {
      is=getClass().getResourceAsStream(defaultTemplate);
    }
    result=reader.parse(is);
  }
 catch (  ParserConfigurationException e) {
    env.handle(e);
  }
catch (  IOException e) {
    env.handle(e);
  }
catch (  SAXException e) {
    env.handle(e);
  }
  return result;
}
 

Example 30

From project Application-Builder, under directory /src/main/java/org/silverpeas/xml/.

Source file: ClasspathEntityResolver.java

  15 
vote

@Override public InputSource resolveEntity(String publicId,String systemId) throws SAXException, IOException {
  if (defaultResolver != null) {
    try {
      return defaultResolver.resolveEntity(publicId,systemId);
    }
 catch (    IOException ioex) {
      return resolveInClasspath(publicId,systemId);
    }
  }
  return resolveInClasspath(publicId,systemId);
}
 

Example 31

From project aranea, under directory /server/src/main/java/no/dusken/aranea/admin/control/.

Source file: ImportStvMediaController.java

  15 
vote

private Document parseXmlFile(File file){
  Document dom=null;
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  try {
    DocumentBuilder db=dbf.newDocumentBuilder();
    dom=db.parse(file);
  }
 catch (  ParserConfigurationException pce) {
    pce.printStackTrace();
  }
catch (  SAXException se) {
    se.printStackTrace();
  }
catch (  IOException ioe) {
    ioe.printStackTrace();
  }
  return dom;
}
 

Example 32

From project Archimedes, under directory /br.org.archimedes.io.xml/src/br/org/archimedes/io/xml/parsers/.

Source file: XMLParser.java

  15 
vote

/** 
 * @param xmlInputStream The file to be parsed
 * @return The document
 */
private Document getDocument(InputStream xmlInputStream){
  DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
  docBuilderFactory.setNamespaceAware(true);
  DocumentBuilder docBuilder=null;
  try {
    docBuilder=docBuilderFactory.newDocumentBuilder();
  }
 catch (  ParserConfigurationException e) {
    e.printStackTrace();
  }
  Document doc=null;
  try {
    doc=docBuilder.parse(xmlInputStream);
    doc.normalize();
  }
 catch (  SAXException e) {
  }
catch (  IOException e) {
  }
  return doc;
}
 

Example 33

From project arquillian-core, under directory /config/impl-base/src/test/java/org/jboss/arquillian/config/descriptor/impl/.

Source file: ArquillianDescriptorTestCase.java

  15 
vote

private void validateXML(String xml) throws Exception {
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  dbf.setValidating(true);
  dbf.setNamespaceAware(true);
  dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");
  DocumentBuilder db=dbf.newDocumentBuilder();
  db.setErrorHandler(new ErrorHandler(){
    @Override public void warning(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    @Override public void fatalError(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    @Override public void error(    SAXParseException exception) throws SAXException {
      throw exception;
    }
  }
);
  db.setEntityResolver(new EntityResolver(){
    @Override public InputSource resolveEntity(    String publicId,    String systemId) throws SAXException, IOException {
      if ("http://jboss.org/schema/arquillian/arquillian_1_0.xsd".equals(systemId)) {
        return new InputSource(this.getClass().getClassLoader().getResourceAsStream("arquillian_1_0.xsd"));
      }
      return null;
    }
  }
);
  db.parse(new ByteArrayInputStream(xml.getBytes()));
}
 

Example 34

From project arquillian-extension-persistence, under directory /impl/src/main/java/org/jboss/arquillian/persistence/core/configuration/.

Source file: PersistenceDescriptorParser.java

  15 
vote

public String obtainDataSourceName(final String descriptor){
  try {
    final Document document=factory.newDocumentBuilder().parse(new ByteArrayInputStream(descriptor.getBytes()));
    final NodeList persistenceUnits=document.getElementsByTagName("persistence-unit");
    if (persistenceUnits.getLength() > 1) {
      throw new MultiplePersistenceUnitsException("Multiple persistence units defined. Please specify default data source either in 'arquillian.xml' or by using @DataSource annotation");
    }
    final Node persistenceUnit=persistenceUnits.item(0);
    Node dataSource=getJtaDataSource(persistenceUnit);
    if (dataSource == null) {
      dataSource=getNonJtaDataSource(persistenceUnit);
    }
    return dataSource.getTextContent();
  }
 catch (  SAXException e) {
    throw new PersistenceDescriptorParsingException("Unable to parse descriptor " + descriptor,e);
  }
catch (  IOException e) {
    throw new PersistenceDescriptorParsingException("Unable to parse descriptor " + descriptor,e);
  }
catch (  ParserConfigurationException e) {
    throw new PersistenceDescriptorParsingException("Unable to parse descriptor " + descriptor,e);
  }
}
 

Example 35

From project arquillian-rusheye, under directory /rusheye-impl/src/test/java/org/jboss/rusheye/parser/.

Source file: AbstractVisualSuiteDefinitionTest.java

  15 
vote

@BeforeMethod public void prepareEnvironment() throws IOException, SAXException {
  stub=new VisualSuiteStub();
  PipedInputStream in=new PipedInputStream();
  PipedOutputStream writerOut=new PipedOutputStream(in);
  documentOutputStream=new ByteArrayOutputStream();
  TeeOutputStream out=new TeeOutputStream(writerOut,documentOutputStream);
  OutputFormat format=new OutputFormat("\t",true);
  writer=new XMLWriter(out,format);
  inputStream=in;
  parser=new Parser();
  handler=parser.getHandler();
}
 

Example 36

From project as3-commons-jasblocks, under directory /src/main/java/org/as3commons/asblocks/impl/.

Source file: SWCResourceRoot.java

  15 
vote

public SWCResourceRoot(File path) throws IOException {
  this.path=path;
  ZipFile zip=new ZipFile(path.getAbsolutePath());
  try {
    ZipEntry entry=zip.getEntry(CATALOG_FILENAME);
    if (entry == null) {
      throw new IllegalArgumentException("No " + CATALOG_FILENAME + " in swc: "+ path.getAbsolutePath());
    }
    qnames=readCatalog(zip.getInputStream(entry));
  }
 catch (  ParserConfigurationException e) {
    throw new IOException(e.toString());
  }
catch (  SAXException e) {
    throw new IOException(e.toString());
  }
catch (  XPathExpressionException e) {
    throw new IOException(e.toString());
  }
 finally {
    zip.close();
  }
}
 

Example 37

From project AsmackService, under directory /src/com/googlecode/asmack/connection/impl/.

Source file: FeatureNegotiationEngine.java

  15 
vote

/** 
 * Bind a given resource, probably resuming an old session.
 * @param resource String The preferred resource string.
 * @return String The actual resource string.
 * @throws XmppException On Error.
 */
public String bind(String resource) throws XmppException {
  try {
    if (!TextUtils.isEmpty(resource)) {
      xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>" + resource + "</resource>"+ "</bind>"+ "</iq>");
    }
 else {
      xmppOutput.sendUnchecked("<iq type=\"set\" id=\"bind_1\">" + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "</bind>"+ "</iq>");
    }
    Stanza stanza=xmppInput.nextStanza();
    Node node=XMLUtils.getDocumentNode(stanza.getXml());
    Node bind=XMLUtils.getFirstChild(node,"urn:ietf:params:xml:ns:xmpp-bind","bind");
    Node jid=XMLUtils.getFirstChild(bind,null,"jid");
    if (sessionsSupported) {
      startSession();
    }
    return jid.getTextContent();
  }
 catch (  IllegalArgumentException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
catch (  IllegalStateException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
catch (  SAXException e) {
    throw new XmppMalformedException("bind malformed",e);
  }
}
 

Example 38

From project ATHENA, under directory /src/main/java/com/synaptik/athena/.

Source file: Athena.java

  15 
vote

String getPackageNameFromManifest(File root) throws IOException {
  File manifest=new File(root.getAbsolutePath() + "/AndroidManifest.xml");
  String result=null;
  if (manifest.exists()) {
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder db=dbf.newDocumentBuilder();
      Document dom=db.parse(manifest);
      result=dom.getElementsByTagName("manifest").item(0).getAttributes().getNamedItem("package").getNodeValue();
    }
 catch (    ParserConfigurationException pce) {
      pce.printStackTrace();
    }
catch (    SAXException se) {
      se.printStackTrace();
    }
catch (    IOException ioe) {
      ioe.printStackTrace();
    }
  }
 else {
    throw (new IOException("Could not find an Android Manifest file: " + manifest.getAbsolutePath()));
  }
  return result;
}
 

Example 39

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

Source file: DefaultResponseParser.java

  15 
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 40

From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/coreutils/.

Source file: XMLUtil.java

  15 
vote

/** 
 * Utility to validate XML files against pre-defined schema files. The schema files are extracted automatically when this function is called, the XML being validated is not. Be sure the XML file is already extracted otherwise it will return false.
 * @param xmlfile The XML file to validate, in DOMSource format
 * @param type The file name of the schema to validate against, must exist as a resource in the same package as where this function is being called.For example usages, please see KeywordSearchListsXML, HashDbXML, or IngestModuleLoader.
 */
public static boolean xmlIsValid(DOMSource xmlfile,Class clazz,String schemaFile){
  try {
    PlatformUtil.extractResourceToUserConfigDir(clazz,schemaFile);
    File schemaLoc=new File(PlatformUtil.getUserConfigDirectory() + File.separator + schemaFile);
    SchemaFactory schm=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try {
      Schema schema=schm.newSchema(schemaLoc);
      Validator validator=schema.newValidator();
      DOMResult result=new DOMResult();
      validator.validate(xmlfile,result);
      return true;
    }
 catch (    SAXException e) {
      Logger.getLogger(clazz.getName()).log(Level.WARNING,"Unable to validate XML file.",e);
      return false;
    }
  }
 catch (  IOException e) {
    Logger.getLogger(clazz.getName()).log(Level.WARNING,"Unable to load XML file [" + xmlfile.toString() + "] of type ["+ schemaFile+ "]",e);
    return false;
  }
}
 

Example 41

From project azure-sdk-for-java-samples, under directory /WAAD.WebSSO.JAVA/java/code/libraries/waad-federation/src/main/java/com/microsoft/samples/federation/.

Source file: SamlTokenValidator.java

  15 
vote

private static SignableSAMLObject getSamlTokenFromSamlResponse(String samlResponse) throws ParserConfigurationException, SAXException, IOException, UnmarshallingException {
  Document document=getDocument(samlResponse);
  Unmarshaller unmarshaller=Configuration.getUnmarshallerFactory().getUnmarshaller(document.getDocumentElement());
  org.opensaml.saml2.core.Response response=(org.opensaml.saml2.core.Response)unmarshaller.unmarshall(document.getDocumentElement());
  SignableSAMLObject samlToken=(SignableSAMLObject)response.getAssertions().get(0);
  return samlToken;
}
 

Example 42

From project bbb-java, under directory /src/main/java/org/mconf/bbb/api/.

Source file: JoinedMeeting.java

  15 
vote

public void parse(String str) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException {
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  DocumentBuilder db=dbf.newDocumentBuilder();
  Document doc=db.parse(new ByteArrayInputStream(str.getBytes("UTF-8")));
  doc.getDocumentElement().normalize();
  Element nodeResponse=(Element)doc.getElementsByTagName("response").item(0);
  returncode=ParserUtils.getNodeValue(nodeResponse,"returncode");
  if (returncode.equals("SUCCESS")) {
    fullname=ParserUtils.getNodeValue(nodeResponse,"fullname");
    confname=ParserUtils.getNodeValue(nodeResponse,"confname");
    meetingID=ParserUtils.getNodeValue(nodeResponse,"meetingID");
    externUserID=ParserUtils.getNodeValue(nodeResponse,"externUserID");
    role=ParserUtils.getNodeValue(nodeResponse,"role");
    conference=ParserUtils.getNodeValue(nodeResponse,"conference");
    room=ParserUtils.getNodeValue(nodeResponse,"room");
    voicebridge=ParserUtils.getNodeValue(nodeResponse,"voicebridge");
    webvoiceconf=ParserUtils.getNodeValue(nodeResponse,"webvoiceconf");
    mode=ParserUtils.getNodeValue(nodeResponse,"mode");
    record=ParserUtils.getNodeValue(nodeResponse,"record");
    welcome=ParserUtils.getNodeValue(nodeResponse,"welcome");
    server=ParserUtils.getNodeValue(nodeResponse,"server");
  }
 else {
    message=ParserUtils.getNodeValue(nodeResponse,"message");
  }
}
 

Example 43

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

Source file: RSSParser.java

  15 
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 44

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

Source file: SupXml.java

  15 
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");
}