Java Code Examples for org.xml.sax.SAXParseException

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 servicemix4-specs, under directory /jaxb-api-2.0/src/main/java/javax/xml/bind/util/.

Source file: JAXBSource.java

  18 
vote

public void parse() throws SAXException {
  try {
    marshaller.marshal(contentObject,repeater);
  }
 catch (  JAXBException e) {
    SAXParseException se=new SAXParseException(e.getMessage(),null,null,-1,-1,e);
    if (errorHandler != null) {
      errorHandler.fatalError(se);
    }
    throw se;
  }
}
 

Example 2

From project Cours-3eme-ann-e, under directory /XML/examples/sax/.

Source file: SAXExample3.java

  17 
vote

public static void main(String args[]) throws ParserConfigurationException, SAXException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(true);
  XMLReader parser=factory.newSAXParser().getXMLReader();
  parser.setContentHandler(new DefaultHandler());
  parser.setErrorHandler(new MyErrorHandler());
  try {
    parser.parse(args[0]);
    System.out.println("Everything is OK.");
  }
 catch (  IOException e) {
    System.err.printf("Handler in main. I/O error: %s\n",e.getMessage());
  }
catch (  SAXException e) {
    SAXParseException spe=(SAXParseException)e.getException();
    System.err.printf("Handler in main. Parsing error: %s\n",e.getMessage());
    if (spe != null) {
      System.err.println("Additional infos: " + spe.getLineNumber() + "/"+ spe.getColumnNumber());
    }
  }
}
 

Example 3

From project jobcreator-tool, under directory /src/main/java/dk/hlyh/hudson/tools/jobcreator/input/xml/.

Source file: XmlLoader.java

  17 
vote

dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline loadXml(){
  File inputFile=arguments.getInput();
  if (inputFile == null || !inputFile.exists()) {
    throw new ImportException("Pipline file '" + inputFile + "' cannot be found");
  }
  try {
    JAXBContext context=JAXBContext.newInstance(ROOT_NODE);
    Unmarshaller unmarshaller=context.createUnmarshaller();
    Schema schema=loadSchema();
    unmarshaller.setSchema(schema);
    dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline pipeline=(dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline)unmarshaller.unmarshal(new FileInputStream(inputFile));
    LogFacade.info("Successfully loaded pipline from {0}",inputFile);
    return pipeline;
  }
 catch (  FileNotFoundException ex) {
    throw new ImportException("Could not find pipeline file: " + inputFile);
  }
catch (  UnmarshalException ex) {
    if (ex.getCause() instanceof org.xml.sax.SAXParseException) {
      SAXParseException pe=(SAXParseException)ex.getCause();
      LogFacade.severe("Failed to validate the pipeline definition against the schema: \"{0}\"  at line {1}, column={2}",pe.getMessage(),pe.getLineNumber(),pe.getColumnNumber());
    }
 else {
      LogFacade.severe(ex);
    }
    throw new ImportException("Failed to validate the pipeline definition against the schema" + ex);
  }
catch (  JAXBException ex) {
    throw new ImportException("Failed to configure JAXB",ex);
  }
}
 

Example 4

From project jPOS, under directory /jpos/src/test/java/org/jpos/iso/packager/.

Source file: GenericPackagerTest.java

  17 
vote

@Test public void testGenericContentHandlerErrorThrowsSAXParseException() throws Throwable {
  SAXParseException ex2=new SAXParseException("testGenericContentHandlerParam1","testGenericContentHandlerParam2","testGenericContentHandlerParam3",100,1000);
  try {
    new GenericSubFieldPackager().new GenericContentHandler().error(ex2);
    fail("Expected SAXParseException to be thrown");
  }
 catch (  SAXParseException ex) {
    assertEquals("ex.getMessage()","testGenericContentHandlerParam1",ex.getMessage());
    assertEquals("ex.getPublicId()","testGenericContentHandlerParam2",ex.getPublicId());
    assertEquals("ex.getSystemId()","testGenericContentHandlerParam3",ex.getSystemId());
    assertEquals("ex.getLineNumber()",100,ex.getLineNumber());
    assertEquals("ex.getColumnNumber()",1000,ex.getColumnNumber());
    assertNull("ex.getException()",ex.getException());
  }
}
 

Example 5

From project jsword, under directory /src/main/java/org/crosswire/jsword/book/filter/thml/.

Source file: THMLFilter.java

  17 
vote

public List<Content> toOSIS(Book book,Key key,String plain){
  Element ele=cleanParse(book,key,plain);
  if (ele == null) {
    if (error instanceof SAXParseException) {
      SAXParseException spe=(SAXParseException)error;
      int colNumber=spe.getColumnNumber();
      int start=Math.max(0,colNumber - 40);
      int stop=Math.min(finalInput.length(),colNumber + 40);
      int here=stop - start;
      log.warn("Could not fix " + book.getInitials() + '('+ key.getName()+ ") by "+ errorMessage+ ": Error here("+ colNumber+ ','+ finalInput.length()+ ','+ here+ "): "+ finalInput.substring(start,stop));
    }
 else {
      log.warn("Could not fix " + book.getInitials() + "("+ key.getName()+ ") by "+ errorMessage+ ": "+ error.getMessage());
    }
    ele=OSISUtil.factory().createP();
  }
  return ele.removeContent();
}
 

Example 6

From project kabeja, under directory /blocks/svg/src/main/java/org/kabeja/svg/.

Source file: Draft2SVGReader.java

  17 
vote

public void parse(String systemId) throws IOException, SAXException {
  this.initialize();
  try {
    DraftDocument doc=parser.parse(new FileInputStream(systemId),new HashMap());
    SAXGenerator generator=new SVGGenerator();
    generator.setProperties(new HashMap());
    generator.generate(doc,this.getContentHandler(),null);
    doc=null;
    this.parser=null;
  }
 catch (  ParseException e) {
    errorhandler.error(new SAXParseException(e.getMessage(),null));
  }
}
 

Example 7

From project vysper, under directory /nbxml/src/main/java/org/apache/vysper/xml/sax/impl/.

Source file: XMLParser.java

  17 
vote

private void fatalError(String message) throws SAXException {
  log.debug("Fatal error: {}",message);
  state=State.CLOSED;
  tokenizer.close();
  startDocument();
  errorHandler.fatalError(new SAXParseException(message,null));
}
 

Example 8

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

Source file: XmlMerger.java

  16 
vote

@Override public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException {
  if (isModified || !"import".equals(qName))   return;
  String value=attributes.getValue(qNameFile.getLocalPart());
  if (value == null)   throw new SAXParseException("Attribute 'file' is missing",locator);
  File file=new File(basedir,value);
  if (!file.exists())   throw new SAXParseException("Imported file not found. file=" + file.getPath(),locator);
  if (file.isFile() && checkFile(file)) {
    isModified=true;
    return;
  }
  if (file.isDirectory()) {
    String rec=attributes.getValue(qNameRecursiveImport.getLocalPart());
    Collection<File> files=listFiles(file,rec == null ? true : Boolean.valueOf(rec));
    for (    File childFile : files) {
      if (checkFile(childFile)) {
        isModified=true;
        return;
      }
    }
  }
}
 

Example 9

From project logsaw-app, under directory /net.sf.logsaw.dialect.log4j/src/net/sf/logsaw/dialect/log4j/xml/.

Source file: Log4JXMLFilter.java

  16 
vote

@Override public void endElement(String uri,String localName,String qName) throws SAXException {
  if (uri.equals(NAMESPACE_LOG4J) && localName.equals(ELEMENT_EVENT)) {
    try {
      collector.collect(currentEntry);
    }
 catch (    IOException e) {
      throw new SAXParseException(e.getLocalizedMessage(),documentLocator,e);
    }
    checkMonitorCanceled();
  }
 else   if (uri.equals(NAMESPACE_LOG4J) && localName.equals(ELEMENT_MESSAGE)) {
    currentEntry.put(Log4JFieldProvider.FIELD_MESSAGE,buffer.toString());
    buffer=null;
  }
 else   if (uri.equals(NAMESPACE_LOG4J) && localName.equals(ELEMENT_NDC)) {
    currentEntry.put(Log4JFieldProvider.FIELD_NDC,buffer.toString());
    buffer=null;
  }
 else   if (uri.equals(NAMESPACE_LOG4J) && localName.equals(ELEMENT_THROWABLE)) {
    currentEntry.put(Log4JFieldProvider.FIELD_THROWABLE,buffer.toString());
    buffer=null;
  }
  super.endElement(uri,localName,qName);
}
 

Example 10

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 11

From project BMach, under directory /src/jsyntaxpane/actions/.

Source file: XmlPrettifyAction.java

  15 
vote

@Override public void actionPerformed(ActionEvent e){
  if (transformer == null) {
    return;
  }
  JTextComponent target=getTextComponent(e);
  try {
    SyntaxDocument sdoc=ActionUtils.getSyntaxDocument(target);
    StringWriter out=new StringWriter(sdoc.getLength());
    StringReader reader=new StringReader(target.getText());
    InputSource src=new InputSource(reader);
    Document doc=getDocBuilder().parse(src);
    getTransformer().transform(new DOMSource(doc),new StreamResult(out));
    target.setText(out.toString());
  }
 catch (  SAXParseException ex) {
    showErrorMessage(target,String.format("XML error: %s\nat(%d, %d)",ex.getMessage(),ex.getLineNumber(),ex.getColumnNumber()));
    ActionUtils.setCaretPosition(target,ex.getLineNumber(),ex.getColumnNumber() - 1);
  }
catch (  TransformerException ex) {
    showErrorMessage(target,ex.getMessageAndLocation());
  }
catch (  SAXException ex) {
    showErrorMessage(target,ex.getLocalizedMessage());
  }
catch (  IOException ex) {
    showErrorMessage(target,ex.getLocalizedMessage());
  }
}
 

Example 12

From project Carolina-Digital-Repository, under directory /persistence/src/main/java/edu/unc/lib/dl/ingest/sip/.

Source file: METSParseException.java

  15 
vote

@Override public String getMessage(){
  StringBuilder sb=new StringBuilder();
  sb.append(super.getMessage());
  sb.append("The METS did not meet all requirements.\n");
  for (  SAXParseException e : this.fatalErrors) {
    sb.append(e.getMessage()).append("\n");
  }
  for (  SAXParseException e : this.errors) {
    sb.append(e.getMessage()).append("\n");
  }
  for (  SAXParseException e : this.warnings) {
    sb.append(e.getMessage()).append("\n");
  }
  return sb.toString();
}
 

Example 13

From project CCR-Validator, under directory /src/main/java/org/openhealthdata/validation/.

Source file: MyErrorHandler.java

  15 
vote

private boolean handleError(SAXParseException ex){
  ErrorType er=new ErrorType();
  er.setServerity(ErrorType.FATAL);
  InFileLocation loc=new InFileLocation();
  loc.setColumnNumber(ex.getColumnNumber());
  loc.setLineNumber(ex.getLineNumber());
  er.setInFileLocation(loc);
  er.setMessage(ex.getMessage());
  tResult.add(er);
  return true;
}
 

Example 14

From project cipango, under directory /cipango-server/src/test/java/org/cipango/server/sipapp/.

Source file: SipXmlProcessorTest.java

  15 
vote

@Test public void testXml() throws Exception {
  XmlParser parser=getParser(true);
  try {
    parser.parse(getClass().getResource("sip.xml").toString());
    fail("expected SAXParseException");
  }
 catch (  SAXParseException e) {
  }
  parser=getParser(false);
  parser.parse(getClass().getResource("sip.xml").toString());
}
 

Example 15

From project comm, under directory /src/main/java/io/s4/comm/util/.

Source file: ConfigParser.java

  15 
vote

private static Document createDocument(String configFilename){
  try {
    Document document;
    javax.xml.parsers.DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);
    dbf.setIgnoringComments(true);
    dbf.setIgnoringElementContentWhitespace(true);
    javax.xml.parsers.DocumentBuilder parser=dbf.newDocumentBuilder();
    parser.setErrorHandler(new org.xml.sax.ErrorHandler(){
      public void warning(      SAXParseException e){
        logger.warn("WARNING: " + e.getMessage(),e);
      }
      public void error(      SAXParseException e){
        logger.error("ERROR: " + e.getMessage(),e);
      }
      public void fatalError(      SAXParseException e) throws SAXException {
        logger.error("FATAL ERROR: " + e.getMessage(),e);
        throw e;
      }
    }
);
    InputStream is=getResourceStream(configFilename);
    if (is == null) {
      throw new RuntimeException("Unable to find config file:" + configFilename);
    }
    document=parser.parse(is);
    return document;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 16

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

Source file: XmlValidator.java

  15 
vote

@Override public void warning(SAXParseException e) throws SAXException {
  if (_failOnWarning) {
    throw e;
  }
 else {
    LOGGER.warn("Warning during validation with '" + _schemaFile + "' as '"+ _schemaType+ "'",e);
  }
}
 

Example 17

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

Source file: XmlMessageExtractor.java

  15 
vote

public Object getMessage(){
  if (logger.isTraceEnabled()) {
    logger.trace("getMessage() - entry");
  }
  if (!initialize()) {
    if (logger.isTraceEnabled()) {
      logger.trace("getMessage() - exit - not yet initialized! Returning null.");
    }
    return null;
  }
  String message=null;
  try {
    xmlReader.parse(input);
  }
 catch (  IOException e) {
    logger.error("getMessage()",e);
  }
catch (  SAXEndMessageException e) {
    message=buffer.toString().trim();
  }
catch (  SAXParseException e) {
    if (buffer.length() > 0)     logger.error("getMessage()",e);
  }
catch (  SAXException e) {
    logger.error("getMessage()",e);
  }
  if (logger.isTraceEnabled()) {
    logger.trace("getMessage() - exit - result :" + message);
  }
  return message;
}
 

Example 18

From project descriptors, under directory /metadata-parser/src/main/java/org/jboss/shrinkwrap/descriptor/metadata/dtd/.

Source file: MetadataDtdEventListener.java

  15 
vote

@Override public void warning(SAXParseException err) throws SAXException {
  if (isVerbose) {
    err.printStackTrace();
  }
 else {
    System.out.println("warning:" + err.getMessage());
  }
}
 

Example 19

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

Source file: XmlUtils.java

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

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.core.runtime.compatibility/src-model/org/eclipse/core/internal/model/.

Source file: RegistryLoader.java

  15 
vote

private PluginModel processManifestFile(URL manifest){
  InputStream is=null;
  try {
    is=manifest.openStream();
  }
 catch (  IOException e) {
    if (debug)     debug("No plugin found for: " + manifest);
    return null;
  }
  PluginModel result=null;
  try {
    try {
      InputSource in=new InputSource(is);
      in.setSystemId(manifest.getFile());
      result=new PluginParser((Factory)factory).parsePlugin(in);
    }
  finally {
      is.close();
    }
  }
 catch (  SAXParseException se) {
    factory.error(new Status(IStatus.WARNING,Platform.PI_RUNTIME,Platform.PARSE_PROBLEM,NLS.bind(Messages.parse_errorProcessing,manifest),null));
  }
catch (  Exception e) {
    factory.error(new Status(IStatus.WARNING,Platform.PI_RUNTIME,Platform.PARSE_PROBLEM,NLS.bind(Messages.parse_errorProcessing,manifest + ":  " + e.getMessage()),null));
  }
  return result;
}
 

Example 21

From project en4j, under directory /NBPlatformApp/SearchLucene/src/main/java/com/rubenlaguna/en4j/searchlucene/.

Source file: NoteFinderLuceneImpl.java

  15 
vote

private String getTextFromInputSource(InputSource is) throws SAXException, IOException {
  XMLReader xr=new org.ccil.cowan.tagsoup.Parser();
  ContentHandler handler=new MyHandler();
  xr.setContentHandler(handler);
  xr.setErrorHandler(new ErrorHandler(){
    public void warning(    SAXParseException exception) throws SAXException {
      LOG.log(Level.WARNING,"exception while parsing note contents",exception);
    }
    public void error(    SAXParseException exception) throws SAXException {
      LOG.log(Level.WARNING,"exception while parsing note contents",exception);
    }
    public void fatalError(    SAXParseException exception) throws SAXException {
      LOG.log(Level.WARNING,"exception while parsing note contents",exception);
    }
  }
);
  xr.parse(is);
  String text=handler.toString();
  return text;
}
 

Example 22

From project fiftyfive-wicket, under directory /fiftyfive-wicket-test/src/main/java/fiftyfive/wicket/test/.

Source file: AbstractDocumentValidator.java

  15 
vote

/** 
 * Formats a SAXParseException as a string: error message, followed by five lines of the markup centered around the line where the error occurs.
 */
private String format(SAXParseException ex){
  StringBuffer buf=new StringBuffer();
  buf.append(ex.getMessage());
  buf.append("\n");
  final int ctx=this.numLinesContext;
  for (int offset=-1 * ctx / 2; offset <= ctx / 2; offset++) {
    int line=ex.getLineNumber() + offset;
    if (line >= 1 && line <= this.lines.length) {
      buf.append("   ");
      if (line == ex.getLineNumber()) {
        buf.append("*");
      }
 else {
        buf.append(" ");
      }
      buf.append(String.format("%-5d",line));
      buf.append("| ");
      buf.append(this.lines[line - 1]);
      buf.append("\n");
    }
  }
  return buf.toString();
}
 

Example 23

From project fitnesse, under directory /src/util/.

Source file: XmlUtil.java

  15 
vote

public static Document newDocument(InputStream input) throws IOException, SAXException {
  try {
    return getDocumentBuilder().parse(input);
  }
 catch (  SAXParseException e) {
    throw new SAXException(String.format("SAXParseException at line:%d, col:%d, %s",e.getLineNumber(),e.getColumnNumber(),e.getMessage()));
  }
}
 

Example 24

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

Source file: XMLResource.java

  15 
vote

/** 
 * Adds the default EntityResolved and ErrorHandler for the SAX parser.
 */
private void addHandlers(XMLReader xmlReader){
  try {
    xmlReader.setEntityResolver(FSEntityResolver.instance());
    xmlReader.setErrorHandler(new ErrorHandler(){
      public void error(      SAXParseException ex){
        XRLog.load(ex.getMessage());
      }
      public void fatalError(      SAXParseException ex){
        XRLog.load(ex.getMessage());
      }
      public void warning(      SAXParseException ex){
        XRLog.load(ex.getMessage());
      }
    }
);
  }
 catch (  Exception ex) {
    throw new XRRuntimeException("Failed on configuring SAX parser/XMLReader.",ex);
  }
}
 

Example 25

From project freemind, under directory /freemind/freemind/main/.

Source file: HtmlTools.java

  15 
vote

/** 
 * @return true, if well formed XML.
 */
public boolean isWellformedXml(String xml){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.newSAXParser().parse(new InputSource(new StringReader(xml)),new DefaultHandler());
    return true;
  }
 catch (  SAXParseException e) {
    logger.log(Level.SEVERE,"XmlParseError on line " + e.getLineNumber() + " of "+ xml,e);
  }
catch (  Exception e) {
    logger.log(Level.SEVERE,"XmlParseError",e);
  }
  return false;
}
 

Example 26

From project gansenbang, under directory /s4/s4-comm/src/main/java/io/s4/comm/util/.

Source file: ConfigParser.java

  15 
vote

private static Document createDocument(String configFilename){
  try {
    Document document;
    javax.xml.parsers.DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);
    dbf.setIgnoringComments(true);
    dbf.setIgnoringElementContentWhitespace(true);
    javax.xml.parsers.DocumentBuilder parser=dbf.newDocumentBuilder();
    parser.setErrorHandler(new org.xml.sax.ErrorHandler(){
      public void warning(      SAXParseException e){
        logger.warn("WARNING: " + e.getMessage(),e);
      }
      public void error(      SAXParseException e){
        logger.error("ERROR: " + e.getMessage(),e);
      }
      public void fatalError(      SAXParseException e) throws SAXException {
        logger.error("FATAL ERROR: " + e.getMessage(),e);
        throw e;
      }
    }
);
    InputStream is=getResourceStream(configFilename);
    if (is == null) {
      throw new RuntimeException("Unable to find config file:" + configFilename);
    }
    document=parser.parse(is);
    return document;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 27

From project Gedcom, under directory /src/main/java/org/folg/gedcom/tools/.

Source file: CompareGedcom2Gedcom.java

  15 
vote

@SuppressWarnings("unchecked") private boolean equals(List<GedcomTag> gedcomTags,List<GedcomTag> compareGedcomTags) throws SAXParseException, IOException {
  mergeContConcTags(gedcomTags);
  mergeContConcTags(compareGedcomTags);
  removeEmptyTags(gedcomTags);
  removeEmptyTags(compareGedcomTags);
  convertMultipleTextTags(gedcomTags);
  Collections.sort(gedcomTags);
  Collections.sort(compareGedcomTags);
  if (gedcomTags.size() != compareGedcomTags.size()) {
    return false;
  }
  for (int indx=0; indx < gedcomTags.size(); indx++) {
    GedcomTag gedcomTagOne=gedcomTags.get(indx);
    GedcomTag gedcomTagTwo=compareGedcomTags.get(indx);
    if (!gedcomTagOne.equals(gedcomTagTwo)) {
      logger.info("file=" + currentFilename + " !tag="+ gedcomTagOne.toString()+ "<=====>"+ gedcomTagTwo.toString());
      return false;
    }
  }
  return true;
}
 

Example 28

From project gedcom5-conversion, under directory /src/main/java/org/gedcomx/tools/.

Source file: Gedcom2Gedcomx.java

  15 
vote

private void convertXFile(File inFile,OutputStream outputStream) throws SAXParseException, IOException {
  GedcomxFile gxFile=new GedcomxFile(new JarFile(inFile));
  GedcomxOutputStream out=new GedcomxOutputStream(outputStream);
  Map<String,String> attributes=gxFile.getAttributes();
  for (  Map.Entry<String,String> attribute : attributes.entrySet()) {
    out.addAttribute(attribute.getKey(),attribute.getValue());
  }
  for (  GedcomxFileEntry entry : gxFile.getEntries()) {
    if (!entry.getJarEntry().isDirectory() && !entry.getJarEntry().getName().endsWith("MANIFEST.MF")) {
      Object resource=gxFile.readResource(entry);
      String contentType=entry.getContentType();
      if (contentType == null) {
        contentType=CommonModels.GEDCOMX_XML_MEDIA_TYPE;
      }
      out.addResource(contentType,entry.getJarEntry().getName(),resource,null,entry.getAttributes());
    }
  }
  out.close();
}
 

Example 29

From project Guit, under directory /src/main/java/com/guit/rebind/guitview/.

Source file: GuitViewHelper.java

  15 
vote

private static Document getDocument(URL url,TreeLogger logger) throws UnableToCompleteException {
  Document doc=null;
  try {
    doc=new W3cDomHelper(logger).documentFor(url);
  }
 catch (  SAXParseException e) {
    logger.log(TreeLogger.ERROR,String.format("Error parsing XML (line " + e.getLineNumber() + "): "+ e.getMessage(),e));
    throw new UnableToCompleteException();
  }
  return doc;
}
 

Example 30

From project hoop, under directory /hoop-server/src/main/java/com/cloudera/lib/util/.

Source file: XConfiguration.java

  15 
vote

private void parse(Reader reader) throws IOException {
  try {
    DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
    docBuilderFactory.setIgnoringComments(true);
    DocumentBuilder builder=docBuilderFactory.newDocumentBuilder();
    builder.setErrorHandler(new ErrorHandler(){
      @Override public void warning(      SAXParseException exception) throws SAXException {
        throw exception;
      }
      @Override public void error(      SAXParseException exception) throws SAXException {
        throw exception;
      }
      @Override public void fatalError(      SAXParseException exception) throws SAXException {
        throw exception;
      }
    }
);
    Document doc=builder.parse(new InputSource(reader));
    parseDocument(doc);
  }
 catch (  SAXException e) {
    throw new IOException(e);
  }
catch (  ParserConfigurationException e) {
    throw new IOException(e);
  }
}
 

Example 31

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

Source file: DOM4JXMLParser.java

  15 
vote

DOM4JXMLParser() throws Exception {
  this.dom4jReader.setErrorHandler(new ErrorHandler(){
    @Override public void warning(    SAXParseException e) throws SAXException {
      errorHolder.addErrorMessage("warning",e);
    }
    @Override public void fatalError(    SAXParseException e) throws SAXException {
      errorHolder.addErrorMessage("fatal error",e);
    }
    @Override public void error(    SAXParseException e) throws SAXException {
      errorHolder.addErrorMessage("error",e);
    }
  }
);
}
 

Example 32

From project jbpmmigration, under directory /src/main/java/org/jbpm/migration/.

Source file: XmlUtils.java

  15 
vote

/** 
 * Parse a <code>File</code> containing an XML structure into a DOM tree.
 * @param input The input XML file.
 * @return The corresponding DOM tree, or <code>null</code> if the input could not be parsed successfully.
 */
public static Document parseFile(final File input){
  Document output=null;
  try {
    final DocumentBuilder db=FACTORY.newDocumentBuilder();
    db.setErrorHandler(new ParserErrorHandler());
    output=db.parse(input);
  }
 catch (  final Exception ex) {
    String msg="Problem parsing the input XML file";
    if (ex instanceof SAXParseException) {
      msg+=" at line #" + ((SAXParseException)ex).getLineNumber();
    }
    LOGGER.error(msg,ex);
  }
  return output;
}
 

Example 33

From project jsfunit, under directory /jboss-jsfunit-analysis/src/test/java/org/jboss/jsfunit/analysis/util/.

Source file: ParserUtilsTest.java

  15 
vote

/** 
 * Test method for  {@link org.jboss.jsfunit.analysis.util.ParserUtils#getDocument(java.lang.String)}.
 */
public void testGetDocumentBadXml(){
  try {
    Document testDoc=ParserUtils.getDocument("bad xml");
    assertNotNull(testDoc);
  }
 catch (  SAXParseException spe) {
    assertEquals("Content is not allowed in prolog.",spe.getMessage());
  }
catch (  Throwable t) {
    fail("wrong exception " + t.getClass().getName());
  }
}
 

Example 34

From project karaf, under directory /deployer/blueprint/src/main/java/org/apache/karaf/deployer/blueprint/.

Source file: BlueprintDeploymentListener.java

  15 
vote

protected Document parse(File artifact) throws Exception {
  if (dbf == null) {
    dbf=DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
  }
  DocumentBuilder db=dbf.newDocumentBuilder();
  db.setErrorHandler(new ErrorHandler(){
    public void warning(    SAXParseException exception) throws SAXException {
    }
    public void error(    SAXParseException exception) throws SAXException {
    }
    public void fatalError(    SAXParseException exception) throws SAXException {
      throw exception;
    }
  }
);
  return db.parse(artifact);
}
 

Example 35

From project kernel_1, under directory /exo.kernel.container/src/main/java/org/exoplatform/container/configuration/.

Source file: ConfigurationUnmarshaller.java

  15 
vote

public void error(SAXParseException exception) throws SAXException {
  if (exception.getMessage().equals("cvc-elt.1: Cannot find the declaration of element 'configuration'.")) {
    LOG.info("The document " + url + " does not contain a schema declaration, it should have an "+ "XML declaration similar to\n"+ "<configuration\n"+ "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"+ "   xsi:schemaLocation=\"http://www.exoplatform.org/xml/ns/kernel_1_1.xsd "+ "http://www.exoplatform.org/xml/ns/kernel_1_1.xsd\"\n"+ "   xmlns=\"http://www.exoplatform.org/xml/ns/kernel_1_1.xsd\">");
  }
 else {
    LOG.error("In document " + url + "  at ("+ exception.getLineNumber()+ ","+ exception.getColumnNumber()+ ") :"+ exception.getMessage());
  }
  valid=false;
}
 

Example 36

From project lenya, under directory /org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/usecase/xml/.

Source file: UsecaseErrorHandler.java

  15 
vote

protected void addErrorMessage(SAXParseException e,String message){
  String[] params=new String[3];
  params[0]=e.getMessage();
  params[1]=Integer.toString(e.getLineNumber());
  params[2]=Integer.toString(e.getColumnNumber());
  this.usecase.addErrorMessage(message,params);
}
 

Example 37

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

Source file: W3cDomHelper.java

  15 
vote

/** 
 * Creates an XML document model with the given contents.
 */
public Document documentFor(String string,String resourcePath) throws SAXParseException {
  try {
    factory.setFeature("http://xml.org/sax/features/xmlns-uris",true);
    factory.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
    if (resourcePath != null) {
      int pos=resourcePath.lastIndexOf('/');
      resourcePath=(pos < 0) ? "" : resourcePath.substring(0,pos + 1);
    }
    W3cDocumentBuilder handler=new W3cDocumentBuilder(logger,resourcePath,resourceOracle);
    SAXParser parser=factory.newSAXParser();
    InputSource input=new InputSource(new StringReader(string));
    input.setSystemId(resourcePath);
    parser.parse(input,handler);
    return handler.getDocument();
  }
 catch (  SAXParseException e) {
    throw e;
  }
catch (  SAXException e) {
    throw new RuntimeException(e);
  }
catch (  IOException e) {
    throw new RuntimeException(e);
  }
catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
}
 

Example 38

From project litle-sdk-for-java, under directory /lib/xerces-2_11_0/samples/dom/traversal/.

Source file: IteratorView.java

  15 
vote

void store(SAXParseException ex,String type){
  String errorString=type + " at line number, " + ex.getLineNumber()+ ": "+ ex.getMessage()+ "\n";
  Node currentNode=null;
  try {
    currentNode=(Node)parser.getProperty("http://apache.org/xml/properties/dom-node");
  }
 catch (  SAXException se) {
    System.err.println(se.getMessage());
    return;
  }
  if (currentNode == null)   return;
  String previous=(String)errorNodes.get(currentNode);
  if (previous != null)   errorNodes.put(currentNode,previous + errorString);
 else   errorNodes.put(currentNode,errorString);
}
 

Example 39

From project logback, under directory /logback-core/src/test/java/ch/qos/logback/core/joran/action/.

Source file: IncludeActionTest.java

  15 
vote

@Test public void withCorruptFile() throws JoranException, IOException {
  String tmpOut=copyToTemp(INVALID);
  System.setProperty(INCLUDE_KEY,tmpOut);
  tc.doConfigure(TOP_BY_FILE);
  assertEquals(Status.ERROR,statusChecker.getHighestLevel(0));
  assertTrue(statusChecker.containsException(SAXParseException.class));
  File f=new File(tmpOut);
  assertTrue(f.exists());
  assertTrue(f.delete());
}
 

Example 40

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

Source file: ResultReader.java

  15 
vote

@Override public void error(SAXParseException e) throws SAXException {
  if (stopped) {
    return;
  }
  super.error(e);
}
 

Example 41

From project maven-doxia, under directory /doxia-core/src/main/java/org/apache/maven/doxia/util/.

Source file: XmlValidator.java

  15 
vote

/** 
 * {@inheritDoc} 
 */
@Override public void error(SAXParseException e) throws SAXException {
  if (!hasDtdAndXsd) {
    processException(TYPE_ERROR,e);
    return;
  }
  Matcher m=ELEMENT_TYPE_PATTERN.matcher(e.getMessage());
  if (!m.find()) {
    processException(TYPE_ERROR,e);
  }
}
 

Example 42

From project Mockey, under directory /src/java/com/mockey/storage/xml/.

Source file: MockeyXmlFileManager.java

  15 
vote

/** 
 * @param file - xml configuration file for Mockey
 * @throws IOException
 * @throws SAXException
 * @throws SAXParseException
 */
private String getFileContentAsString(File file) throws IOException, SAXParseException, SAXException {
  FileInputStream fstream=new FileInputStream(file);
  BufferedReader br=new BufferedReader(new InputStreamReader(fstream,Charset.forName(HTTP.UTF_8)));
  StringBuffer inputString=new StringBuffer();
  String strLine=null;
  while ((strLine=br.readLine()) != null) {
    inputString.append(new String(strLine.getBytes(HTTP.UTF_8)));
  }
  return inputString.toString();
}
 

Example 43

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

Source file: FeaturesXsdGeneratorTest.java

  15 
vote

public void testXsdGenerator() throws Throwable {
  ModelloCore modello=(ModelloCore)lookup(ModelloCore.ROLE);
  Model model=modello.loadModel(getXmlResourceReader("/features.mdo"));
  Properties parameters=getModelloParameters("1.0.0");
  modello.generate(model,"xsd",parameters);
  SchemaFactory sf=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema=sf.newSchema(new StreamSource(new File(getOutputDirectory(),"features-1.0.0.xsd")));
  Validator validator=schema.newValidator();
  try {
    validator.validate(new StreamSource(getClass().getResourceAsStream("/features.xml")));
  }
 catch (  SAXParseException e) {
    throw new ModelloException("line " + e.getLineNumber() + " column "+ e.getColumnNumber(),e);
  }
  try {
    validator.validate(new StreamSource(getClass().getResourceAsStream("/features-invalid.xml")));
    fail("parsing of features-invalid.xml should have failed");
  }
 catch (  SAXParseException e) {
    assertTrue(String.valueOf(e.getMessage()).indexOf("invalidElement") >= 0);
  }
  try {
    validator.validate(new StreamSource(getClass().getResourceAsStream("/features-invalid-transient.xml")));
    fail("XSD did not prohibit appearance of transient fields");
  }
 catch (  SAXParseException e) {
    assertTrue(String.valueOf(e.getMessage()).indexOf("transientString") >= 0);
  }
}
 

Example 44

From project movsim, under directory /core/src/main/java/org/movsim/input/.

Source file: XmlReaderSimInput.java

  15 
vote

/** 
 * Gets the info to the corresponding exception.
 * @param e the exception
 * @return the info
 */
private String getInfo(SAXParseException e){
  final StringBuilder stringb=new StringBuilder();
  stringb.append("   Public ID: " + e.getPublicId());
  stringb.append("   System ID: " + e.getSystemId());
  stringb.append("   Line number: " + e.getLineNumber());
  stringb.append("   Column number: " + e.getColumnNumber());
  stringb.append("   Message: " + e.getMessage());
  return stringb.toString();
}
 

Example 45

From project ndg-mobile-client, under directory /src/main/java/br/org/indt/ndg/mobile/xmlhandle/.

Source file: Parser.java

  15 
vote

public void parseInputStream(InputStream is){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser saxParser=factory.newSAXParser();
    try {
      saxParser.parse(is,handler);
    }
 catch (    DoneParsingException e) {
    }
catch (    SAXParseException e) {
      Logger.getInstance().logException("SAXParseException on parsing: " + e.getMessage());
      e.printStackTrace();
      error=true;
      AppMIDlet.getInstance().getFileSystem().setError(true);
    }
  }
 catch (  Exception e) {
    Logger.getInstance().logException("Exception on parsing: " + e.getMessage());
    e.printStackTrace();
    error=true;
    GeneralAlert.getInstance().addCommand(ExitCommand.getInstance());
    GeneralAlert.getInstance().show(Resources.ERROR_TITLE,Resources.EPARSE_GENERAL,GeneralAlert.ERROR);
  }
}
 

Example 46

From project nodebox, under directory /src/test/java/nodebox/versioncheck/.

Source file: UpdaterTest.java

  15 
vote

/** 
 * Test what happens if the appcast file can not be parsed.
 */
@Test public void testUnreadableAppcast(){
  Updater updater=new Updater(new UnreadableHost());
  TestUpdateDelegate delegate=checkForUpdates(updater);
  assertFalse(delegate.checkPerformed);
  assertEquals(SAXParseException.class,delegate.throwable.getClass());
}
 

Example 47

From project ODE-X, under directory /spi/src/main/java/org/apache/ode/spi/repo/.

Source file: XMLValidate.java

  15 
vote

public void error(SAXParseException e) throws SAXException {
  if (e.getMessage().contains("cvc-complex-type.2.4.a")) {
    log.log(Level.SEVERE,"",e);
    return;
  }
  sb.append(String.format("line: %d column: %d error: %s",e.getLineNumber(),e.getColumnNumber(),e.getMessage()));
  error=true;
}
 

Example 48

From project Ohmage_Server_2, under directory /src/org/ohmage/config/xml/.

Source file: CampaignValidator.java

  15 
vote

/** 
 * args[0]: the file name of the file to validate args[1]: the file name of the schema to validate against
 */
public static void main(String[] args) throws IOException, SAXException, ParsingException, ValidityException {
  BasicConfigurator.configure();
  if (args.length < 2) {
    throw new IllegalArgumentException("Invalid arguments: you must pass a file name of the file to be validated as " + "the first argument and a file name of the schema to use in validation as the second argument.");
  }
  String fileName=args[0];
  String schemaFileName=args[1];
  CampaignValidator validator=new CampaignValidator();
  try {
    validator.runAgainstFiles(fileName,schemaFileName);
  }
 catch (  SAXParseException saxe) {
    LOGGER.error("Parsing failed at line number " + saxe.getLineNumber() + " column number "+ saxe.getColumnNumber());
    throw saxe;
  }
}
 

Example 49

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

Source file: PegadiErrorHandler.java

  15 
vote

public void error(SAXParseException arg0) throws SAXException {
  log.error("Error validating XML.");
  printInfo(arg0);
  this.saxe=arg0;
  setValidationError(true);
}
 

Example 50

From project phing-eclipse, under directory /org.ganoro.phing.ui/src/org/ganoro/phing/ui/editors/utils/.

Source file: ProjectHelper.java

  15 
vote

public void characters(char[] buf,int start,int count,AntXMLContext context){
  try {
    super.characters(buf,start,count,context);
  }
 catch (  SAXParseException e) {
    ErrorHelper.handleErrorFromElementText(start,count,context,e);
  }
catch (  BuildException be) {
    ErrorHelper.handleErrorFromElementText(start,count,context,be);
  }
}
 

Example 51

From project Places, under directory /tools/src/main/java/org/folg/places/tools/.

Source file: AnalyzeMatches.java

  15 
vote

public static void main(String[] args) throws SAXParseException, IOException {
  AnalyzeMatches self=new AnalyzeMatches();
  CmdLineParser parser=new CmdLineParser(self);
  try {
    parser.parseArgument(args);
    self.doMain();
  }
 catch (  CmdLineException e) {
    System.err.println(e.getMessage());
    parser.printUsage(System.err);
  }
}
 

Example 52

From project rest-assured, under directory /examples/rest-assured-itest-java/src/test/java/com/jayway/restassured/itest/java/.

Source file: XMLValidationITest.java

  15 
vote

@Test public void throwsExceptionWhenXsdValidationFails() throws Exception {
  exception.expect(SAXParseException.class);
  exception.expectMessage("Cannot find the declaration of element 'shopping'.");
  final InputStream xsd=getClass().getResourceAsStream("/car-records.xsd");
  expect().body(matchesXsd(xsd)).when().get("/shopping");
}
 

Example 53

From project riftsaw-ode, under directory /tools/src/main/java/org/apache/ode/tools/.

Source file: CommandContextErrorHandler.java

  15 
vote

private String formatMessage(SAXParseException e){
  StringBuffer sb=new StringBuffer();
  sb.append('[');
  if (e.getSystemId() == null) {
    sb.append("<<null>>");
  }
 else {
    sb.append(e.getSystemId());
  }
  sb.append(" ");
  sb.append(e.getLineNumber());
  sb.append(':');
  sb.append(e.getColumnNumber());
  sb.append("] ");
  sb.append(e.getMessage());
  return sb.toString();
}
 

Example 54

From project RomRaider, under directory /src/com/romraider/logger/ecu/definition/.

Source file: EcuDataLoaderImpl.java

  15 
vote

public void loadEcuDefsFromXml(File ecuDefsFile){
  checkNotNull(ecuDefsFile,"ecuDefsFile");
  try {
    InputStream inputStream=new BufferedInputStream(new FileInputStream(ecuDefsFile));
    try {
      EcuDefinitionHandler handler=new EcuDefinitionHandler();
      getSaxParser().parse(inputStream,handler);
      ecuDefinitionMap=handler.getEcuDefinitionMap();
    }
  finally {
      inputStream.close();
    }
  }
 catch (  SAXParseException spe) {
    throw new ConfigurationException("Unable to read ECU definition file " + ecuDefsFile + ".  Please make sure the definition file is correct.  If it is in a ZIP archive, unzip the file and try again.");
  }
catch (  FileNotFoundException fnfe) {
    throw new ConfigurationException("The specified ECU definition file " + ecuDefsFile + " does not exist.");
  }
catch (  Exception e) {
    throw new ConfigurationException(e);
  }
}
 

Example 55

From project s4, under directory /s4-comm/src/main/java/org/apache/s4/comm/util/.

Source file: ConfigParser.java

  15 
vote

private static Document createDocument(String configFilename){
  try {
    Document document;
    javax.xml.parsers.DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);
    dbf.setIgnoringComments(true);
    dbf.setIgnoringElementContentWhitespace(true);
    javax.xml.parsers.DocumentBuilder parser=dbf.newDocumentBuilder();
    parser.setErrorHandler(new org.xml.sax.ErrorHandler(){
      public void warning(      SAXParseException e){
        logger.warn("WARNING: " + e.getMessage(),e);
      }
      public void error(      SAXParseException e){
        logger.error("ERROR: " + e.getMessage(),e);
      }
      public void fatalError(      SAXParseException e) throws SAXException {
        logger.error("FATAL ERROR: " + e.getMessage(),e);
        throw e;
      }
    }
);
    InputStream is=getResourceStream(configFilename);
    if (is == null) {
      throw new RuntimeException("Unable to find config file:" + configFilename);
    }
    document=parser.parse(is);
    return document;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 56

From project SIARD-Val, under directory /SIARD-Val/src/main/java/ch/kostceco/tools/siardval/validation/module/impl/.

Source file: ValidationHcontentModuleImpl.java

  15 
vote

@Override public void error(SAXParseException e) throws SAXException {
  if (valid) {
    valid=false;
  }
  logError(e);
}
 

Example 57

From project skalli, under directory /org.eclipse.skalli.testutil/src/main/java/org/eclipse/skalli/testutil/.

Source file: SchemaValidationUtils.java

  15 
vote

private static void validate(final Object o,HierarchicalStreamWriter writer,DocumentBuilderFactory dbf) throws Exception {
  final String xml=writer.toString();
  Reader reader=new StringReader(xml);
  DocumentBuilder db=dbf.newDocumentBuilder();
  db.setErrorHandler(new ErrorHandler(){
    @Override public void warning(    SAXParseException exception) throws SAXException {
      Assert.fail(o.toString() + ": " + exception.getMessage()+ "\n"+ xml);
    }
    @Override public void error(    SAXParseException exception) throws SAXException {
      Assert.fail(o.toString() + ": " + exception.getMessage()+ "\n"+ xml);
    }
    @Override public void fatalError(    SAXParseException exception) throws SAXException {
      Assert.fail(o.toString() + ": " + exception.getMessage()+ "\n"+ xml);
    }
  }
);
  db.parse(new InputSource(reader));
}
 

Example 58

From project smart-cms, under directory /spi-modules/content-spi-type-validators-impl/src/main/java/com/smartitengineering/cms/spi/impl/type/validator/.

Source file: XMLSchemaBasedTypeValidator.java

  15 
vote

private Document getDocumentForSource(InputStream contentTypeDef) throws SAXException, ParserConfigurationException, IOException {
  final DocumentBuilderFactory docBuilderFactor=DocumentBuilderFactory.newInstance();
  docBuilderFactor.setNamespaceAware(true);
  DocumentBuilder parser=docBuilderFactor.newDocumentBuilder();
  parser.setErrorHandler(new ErrorHandler(){
    public void warning(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    public void error(    SAXParseException exception) throws SAXException {
      throw exception;
    }
    public void fatalError(    SAXParseException exception) throws SAXException {
      throw exception;
    }
  }
);
  Document document=parser.parse(contentTypeDef);
  return document;
}
 

Example 59

From project sojo, under directory /src/main/java/net/sf/sojo/interchange/xmlrpc/.

Source file: XmlRpcParser.java

  15 
vote

public Object parse(final String pvXmlRpcString) throws XmlRpcException {
  Object lvReturn=null;
  boolean lvIsFault=false;
  try {
    if (pvXmlRpcString != null) {
      SAXParserFactory lvFactory=SAXParserFactory.newInstance();
      SAXParser lvParser=lvFactory.newSAXParser();
      XMLReader lvReader=lvParser.getXMLReader();
      XmlRpcContentHandler lvContentHandler=new XmlRpcContentHandler();
      lvContentHandler.setReturnValueAsList(getReturnValueAsList());
      lvReader.setContentHandler(lvContentHandler);
      ByteArrayInputStream lvArrayInputStream=new ByteArrayInputStream(pvXmlRpcString.getBytes());
      lvReader.parse(new InputSource(lvArrayInputStream));
      lvReturn=lvContentHandler.getResults();
      methodName=lvContentHandler.getMethodName();
      lvIsFault=lvContentHandler.isFault();
    }
  }
 catch (  SAXParseException e) {
    throw new XmlRpcException(e.getMessage(),e);
  }
catch (  Exception e) {
    throw new XmlRpcException("Exception by parse XML-RPC-String: " + pvXmlRpcString,e);
  }
  if (lvIsFault == true && getConvertResult2XmlRpcExceptionAndThrow()) {
    Map<?,?> lvMap=(Map<?,?>)lvReturn;
    Object lvFaultCode=lvMap.get("faultCode");
    Object lvMessage=lvMap.get("faultString");
    throw new XmlRpcException(lvFaultCode + ": " + lvMessage);
  }
  return lvReturn;
}
 

Example 60

From project SPDX-Tools, under directory /lib-source/grddl-src/com/hp/hpl/jena/grddl/impl/.

Source file: GRDDL.java

  15 
vote

private boolean transformWith(String string,boolean needRewind){
  try {
    try {
      final Transformer t=transformerFor(string);
      String mimetype=mimetype(t);
      final Result result=resultFor(mimetype);
      if (result == null)       return false;
      final Source in=input.startAfresh(needRewind);
      runInSandbox(new TERunnable(){
        public void run() throws TransformerException {
          t.transform(in,result);
        }
      }
,true);
      postProcess(mimetype,result);
      return true;
    }
 catch (    TransformerException e) {
      error(e);
      return false;
    }
catch (    SAXParseException e) {
      error(e);
      return false;
    }
catch (    InterruptedException e) {
      throw new InterruptedIOException("In GRDDL transformWith");
    }
 finally {
      input.close();
      if (subThread != null)       subThread.interrupt();
    }
  }
 catch (  IOException ioe) {
    error(ioe);
    return false;
  }
}
 

Example 61

From project spring-dbunit, under directory /spring-dbunit-core/src/main/java/com/excilys/ebi/spring/dbunit/dataset/xml/flyweight/.

Source file: FlyWeightFlatXmlProducer.java

  15 
vote

/** 
 * Wraps a  {@link SAXException} into a {@link DataSetException}
 * @param cause The cause to be wrapped into a  {@link DataSetException}
 * @return A {@link DataSetException} that wraps the given{@link SAXException}
 */
protected final static DataSetException buildException(SAXException cause){
  int lineNumber=-1;
  if (cause instanceof SAXParseException) {
    lineNumber=((SAXParseException)cause).getLineNumber();
  }
  Exception exception=cause.getException() == null ? cause : cause.getException();
  String message;
  if (lineNumber >= 0) {
    message="Line " + lineNumber + ": "+ exception.getMessage();
  }
 else {
    message=exception.getMessage();
  }
  if (exception instanceof DataSetException) {
    return (DataSetException)exception;
  }
 else {
    return new DataSetException(message,exception);
  }
}
 

Example 62

From project spring-js, under directory /src/test/java/org/springframework/aop/config/.

Source file: AopNamespaceHandlerAdviceTypeTests.java

  15 
vote

@Test public void testParsingOfAdviceTypesWithError(){
  try {
    new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml",getClass());
    fail("Expected BeanDefinitionStoreException");
  }
 catch (  BeanDefinitionStoreException ex) {
    assertTrue(ex.contains(SAXParseException.class));
  }
}
 

Example 63

From project static-jsfexpression-validator, under directory /static-jsfexpression-validator-jsf12/src/main/java/com/sun/facelets/compiler/.

Source file: JsfelcheckSAXCompiler.java

  15 
vote

public void fatalError(SAXParseException e) throws SAXException {
  if (this.locator != null) {
    throw new SAXException("Error Traced[line: " + this.locator.getLineNumber() + "] "+ e.getMessage());
  }
 else {
    throw e;
  }
}
 

Example 64

From project tempo, under directory /tms-common/src/main/java/org/intalio/tempo/workflow/task/xml/.

Source file: DocumentBuilderPool.java

  15 
vote

@Override public Object makeObject() throws Exception {
  DocumentBuilder newDocumentBuilder=factory.newDocumentBuilder();
  newDocumentBuilder.setErrorHandler(new ErrorHandler(){
    public void error(    SAXParseException exception) throws SAXException {
      if (LOG.isDebugEnabled())       LOG.debug(exception.toString());
    }
    public void fatalError(    SAXParseException exception) throws SAXException {
      if (LOG.isDebugEnabled())       LOG.debug(exception.toString());
    }
    public void warning(    SAXParseException exception) throws SAXException {
      if (LOG.isDebugEnabled())       LOG.debug(exception.toString());
    }
  }
);
  return newDocumentBuilder;
}
 

Example 65

From project thymeleaf, under directory /src/main/java/org/thymeleaf/templateparser/xmlsax/.

Source file: AbstractNonValidatingSAXTemplateParser.java

  15 
vote

private final Document parseTemplateUsingPool(final Configuration configuration,final String documentName,final Reader reader,final ResourcePool<SAXParser> poolToBeUsed){
  final SAXParser saxParser=poolToBeUsed.allocate();
  final TemplatePreprocessingReader templateReader=getTemplatePreprocessingReader(reader);
  try {
    final Document document=doParse(configuration,documentName,templateReader,saxParser);
    if (this.canResetParsers) {
      try {
        saxParser.reset();
      }
 catch (      final UnsupportedOperationException e) {
        if (this.logger.isWarnEnabled()) {
          this.logger.warn("[THYMELEAF] The SAX Parser implementation being used (\"{}\") does not implement " + "the \"reset\" operation. This will force Thymeleaf to re-create parser instances " + "each time they are needed for parsing templates, which is more costly. Enabling template "+ "cache is recommended, and also using a parser library which implements \"reset\" such as "+ "xerces version 2.9.1 or newer.",saxParser.getClass().getName());
        }
        this.canResetParsers=false;
      }
    }
    return document;
  }
 catch (  final IOException e) {
    throw new TemplateInputException("Exception parsing document",e);
  }
catch (  final TemplateProcessingException e) {
    throw e;
  }
catch (  final SAXParseException e) {
    final String message=String.format("Exception parsing document: template=\"%s\", line %d - column %d",documentName,Integer.valueOf(e.getLineNumber()),Integer.valueOf(e.getColumnNumber()));
    throw new TemplateInputException(message,e);
  }
catch (  final SAXException e) {
    throw new TemplateInputException("Exception parsing document",e);
  }
 finally {
    if (this.canResetParsers) {
      poolToBeUsed.release(saxParser);
    }
 else {
      poolToBeUsed.discardAndReplace(saxParser);
    }
  }
}
 

Example 66

From project turmeric-monitoring, under directory /SOAMetricsQueryServiceImpl/src/main/java/org/ebayopensource/turmeric/monitoring/util/.

Source file: XMLParseUtil.java

  15 
vote

public void error(SAXParseException e) throws SAXParseException {
  reportError(Level.SEVERE,e);
  if (m_checkLevel.equals(SchemaValidationLevel.ERROR)) {
    throw e;
  }
}
 

Example 67

From project turmeric-releng, under directory /utils/TurmericUtils/src/org/ebayopensource/turmeric/utils/.

Source file: XMLParseUtils.java

  15 
vote

public void error(SAXParseException e) throws SAXParseException {
  reportError(Level.SEVERE,e);
  if (m_checkLevel.equals(SchemaValidationLevel.ERROR)) {
    throw e;
  }
}
 

Example 68

From project VooDooDriver, under directory /src/org/sugarcrm/vddlogger/.

Source file: VddSummaryReporter.java

  15 
vote

private HashMap<String,Object> parseXMLFile(File xml) throws Exception {
  DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
  HashMap<String,Object> result=new HashMap<String,Object>();
  DocumentBuilder db=dbf.newDocumentBuilder();
  db.setErrorHandler(new VddErrorHandler());
  try {
    dom=db.parse(xml);
  }
 catch (  SAXParseException e) {
    System.out.println("(!)Error parsing log file (" + e.getMessage() + ").  Retrying with end tag hack...");
    InputSource is=endTagHack(xml);
    dom=db.parse(is);
    System.out.println("(*)Success!");
  }
  result=getSuiteData(dom);
  return result;
}
 

Example 69

From project Weave, under directory /WeaveServices/src/weave/config/.

Source file: SQLConfigManager.java

  15 
vote

/** 
 * getConfig If the configuration file has not been loaded yet, it will be loaded.
 * @return The ISQLConfig object this class manages
 * @throws RemoteException
 */
synchronized public ISQLConfig getConfig() throws RemoteException {
  if (config == null) {
    if (configFileName == null)     throw new RemoteException("Server failed to initialize because no configuration file was specified.");
    try {
      _lastModifiedTime=0L;
      new File(configFileName).getAbsoluteFile().getParentFile().mkdirs();
      config=new SQLConfigXML(configFileName);
      try {
        config=new DatabaseConfig(config);
        System.out.println("Successfully initialized Weave database connection");
      }
 catch (      Exception e) {
        e.printStackTrace();
        System.out.println("Using configuration stored in " + configFileName);
      }
      _lastModifiedTime=new File(configFileName).lastModified();
    }
 catch (    SAXParseException e) {
      String msg=String.format("%s parse error: Line %d, column %d: %s",new File(configFileName).getName(),e.getLineNumber(),e.getColumnNumber(),e.getMessage());
      throw new RemoteException(msg);
    }
catch (    Exception e) {
      e.printStackTrace();
      throw new RemoteException("Server configuration error.",e);
    }
  }
  return config;
}
 

Example 70

From project winstone, under directory /src/java/winstone/.

Source file: WebXmlParser.java

  15 
vote

public void error(SAXParseException exception) throws SAXException {
  if (this.rethrowValidationExceptions) {
    throw exception;
  }
 else {
    Logger.log(Logger.WARNING,Launcher.RESOURCES,"WebXmlParser.XMLParseError",exception.getLineNumber() + "",exception.getMessage());
  }
}
 

Example 71

From project ws, under directory /exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/provider/.

Source file: DOMSourceEntityProvider.java

  15 
vote

/** 
 * {@inheritDoc}
 */
public DOMSource readFrom(Class<DOMSource> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,final InputStream entityStream) throws IOException {
  try {
    final DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    Document d=SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Document>(){
      public Document run() throws Exception {
        return factory.newDocumentBuilder().parse(entityStream);
      }
    }
);
    return new DOMSource(d);
  }
 catch (  PrivilegedActionException pae) {
    Throwable cause=pae.getCause();
    if (cause instanceof SAXParseException) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(cause.getLocalizedMessage(),cause);
      }
      return null;
    }
 else     if (cause instanceof SAXException) {
      throw new IOException("Can't read from input stream " + cause,cause);
    }
 else     if (cause instanceof ParserConfigurationException) {
      throw new IOException("Can't read from input stream " + cause,cause);
    }
 else     if (cause instanceof IOException) {
      throw (IOException)cause;
    }
 else     if (cause instanceof RuntimeException) {
      throw (RuntimeException)cause;
    }
 else {
      throw new RuntimeException(cause);
    }
  }
}
 

Example 72

From project XcodeProjectJavaAPI, under directory /src/test/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/.

Source file: JAXBPlistParserTest.java

  15 
vote

@Test public void convertOpenStepToXML() throws Exception {
  JAXBPlistParser parser=new JAXBPlistParser();
  try {
    parser.load(fileNameOpenStep);
    Assert.fail();
  }
 catch (  javax.xml.bind.UnmarshalException e) {
    if (!(e.getCause().getClass() == SAXParseException.class)) {
      Assert.fail();
    }
  }
  File xmlProj=File.createTempFile("project",".pbxproj");
  xmlProj.deleteOnExit();
  parser.convert(fileNameOpenStep,xmlProj.getAbsolutePath());
  Plist plist=parser.load(xmlProj.getAbsolutePath());
  assertEquals("1.0",plist.getVersion());
}
 

Example 73

From project xmlcalabash1, under directory /src/com/xmlcalabash/library/.

Source file: ValidateJing.java

  15 
vote

public void error(SAXParseException e) throws SAXException {
  TreeWriter treeWriter=new TreeWriter(runtime);
  treeWriter.startDocument(docBaseURI);
  treeWriter.addStartElement(XProcConstants.c_error);
  if (e.getLineNumber() != -1) {
    treeWriter.addAttribute(_line,"" + e.getLineNumber());
  }
  if (e.getColumnNumber() != -1) {
    treeWriter.addAttribute(_column,"" + e.getColumnNumber());
  }
  treeWriter.startContent();
  treeWriter.addText(e.toString());
  treeWriter.addEndElement();
  treeWriter.endDocument();
  step.reportError(treeWriter.getResult());
  if (err != null) {
    err=e;
  }
}