Java Code Examples for org.xml.sax.helpers.DefaultHandler

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 meaningfulweb, under directory /meaningfulweb-core/src/main/java/org/meaningfulweb/api/.

Source file: MetaContentExtractor.java

  32 
vote

private static void parseMeta(Parser parser,InputStream in,Metadata meta,Map<String,String> ogmeta) throws IOException, SAXException, TikaException {
  parser.parse(in,new DefaultHandler(),meta,new ParseContext());
  String[] propnames=meta.names();
  for (  String propname : propnames) {
    String val=meta.get(propname);
    ogmeta.put(propname,val);
  }
}
 

Example 2

From project zk-service-registry-server, under directory /lib/zk-service-registry-server/zookeeper-3.3.3/src/java/main/org/apache/jute/.

Source file: XmlInputArchive.java

  32 
vote

/** 
 * Creates a new instance of BinaryInputArchive 
 */
public XmlInputArchive(InputStream in) throws ParserConfigurationException, SAXException, IOException {
  valList=new ArrayList<Value>();
  DefaultHandler handler=new XMLParser(valList);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  parser.parse(in,handler);
  vLen=valList.size();
  vIdx=0;
}
 

Example 3

From project zookeeper, under directory /src/java/main/org/apache/jute/.

Source file: XmlInputArchive.java

  32 
vote

/** 
 * Creates a new instance of BinaryInputArchive 
 */
public XmlInputArchive(InputStream in) throws ParserConfigurationException, SAXException, IOException {
  valList=new ArrayList<Value>();
  DefaultHandler handler=new XMLParser(valList);
  SAXParserFactory factory=SAXParserFactory.newInstance();
  SAXParser parser=factory.newSAXParser();
  parser.parse(in,handler);
  vLen=valList.size();
  vIdx=0;
}
 

Example 4

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

Source file: SupXml.java

  31 
vote

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

Example 5

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

Source file: MockFedoraIT.java

  31 
vote

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

Example 6

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

Source file: XMLDocumentReader.java

  31 
vote

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

Example 7

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

Source file: Dump.java

  31 
vote

public static void main(String args[]) throws Exception {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setValidating(true);
  XMLReader parser=factory.newSAXParser().getXMLReader();
  parser.setContentHandler(new MyHandler());
  parser.setErrorHandler(new DefaultHandler());
  parser.parse(args[0]);
}
 

Example 8

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

Source file: UDPBroadcastThreadTest.java

  31 
vote

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

Example 9

From project java-cas-client, under directory /cas-client-core/src/main/java/org/jasig/cas/client/util/.

Source file: XmlUtils.java

  31 
vote

/** 
 * Retrieve the text for a group of elements. Each text element is an entry in a list. <p>This method is currently optimized for the use case of two elements in a list.
 * @param xmlAsString the xml response
 * @param element     the element to look for
 * @return the list of text from the elements.
 */
public static List<String> getTextForElements(final String xmlAsString,final String element){
  final List<String> elements=new ArrayList<String>(2);
  final XMLReader reader=getXmlReader();
  final DefaultHandler handler=new DefaultHandler(){
    private boolean foundElement=false;
    private StringBuilder buffer=new StringBuilder();
    public void startElement(    final String uri,    final String localName,    final String qName,    final Attributes attributes) throws SAXException {
      if (localName.equals(element)) {
        this.foundElement=true;
      }
    }
    public void endElement(    final String uri,    final String localName,    final String qName) throws SAXException {
      if (localName.equals(element)) {
        this.foundElement=false;
        elements.add(this.buffer.toString());
        this.buffer=new StringBuilder();
      }
    }
    public void characters(    char[] ch,    int start,    int length) throws SAXException {
      if (this.foundElement) {
        this.buffer.append(ch,start,length);
      }
    }
  }
;
  reader.setContentHandler(handler);
  reader.setErrorHandler(handler);
  try {
    reader.parse(new InputSource(new StringReader(xmlAsString)));
  }
 catch (  final Exception e) {
    LOG.error(e,e);
    return null;
  }
  return elements;
}
 

Example 10

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

Source file: PermittedTaglibsTLV.java

  31 
vote

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

Example 11

From project JDE-Samples, under directory /com/rim/samples/device/openglspritegamedemo/.

Source file: SpriteGameLevel.java

  31 
vote

/** 
 * Loads from the given material XML file into the given model's material
 * @param levelPath Path to the material file
 * @param animator The animator that the material can use
 */
public void loadLevel(final String levelPath,final Animator animator){
  try {
    _levelWidth=0.0f;
    _levelHeight=0.0f;
    _tiles.removeAllElements();
    _enemies.removeAllElements();
    final SAXParser parser=SAXParserFactory.newInstance().newSAXParser();
    InputStream stream;
    stream=Application.getApplication().getClass().getResourceAsStream(levelPath);
    final DefaultHandler dh=new LevelSaxHandler(animator);
    parser.parse(stream,dh);
  }
 catch (  final ParserConfigurationException e) {
    SpriteGame.errorDialog(e.toString());
  }
catch (  final SAXException e) {
    SpriteGame.errorDialog(e.toString());
  }
catch (  final IOException e) {
    SpriteGame.errorDialog(e.toString());
  }
}
 

Example 12

From project RomRaider, under directory /src/com/romraider/util/.

Source file: SaxParserFactory.java

  31 
vote

public static void main(String args[]){
  try {
    SAXParser parser=SaxParserFactory.getSaxParser();
    BufferedInputStream b=new BufferedInputStream(new FileInputStream(new File("/ecu_defs.xml")));
    System.out.println(b.available());
    parser.parse(b,new DefaultHandler());
    System.out.println(parser.isValidating());
  }
 catch (  Exception ex) {
    System.err.println(ex);
  }
}
 

Example 13

From project supose, under directory /supose-core/src/main/java/com/soebes/supose/core/scan/document/.

Source file: ScanArchiveDocument.java

  31 
vote

private void scan(ByteArrayInputStream in,String path,SVNDirEntry dirEntry){
  try {
    Metadata metadata=new Metadata();
    metadata.set(Metadata.RESOURCE_NAME_KEY,path);
    TikaConfig config=TikaConfig.getDefaultConfig();
    Parser parser=new AutoDetectParser(config);
    DefaultHandler handler=new BodyContentHandler();
    parser.parse(in,handler,metadata);
    getDocument().addTokenizedField(FieldNames.CONTENTS,handler.toString());
  }
 catch (  Exception e) {
    LOGGER.error("We had an exception " + path + " (r"+ dirEntry.getRevision()+ ")",e);
  }
 finally {
    try {
      in.close();
    }
 catch (    Exception e) {
      LOGGER.error("We had an exception " + path + " (r"+ dirEntry.getRevision()+ ")",e);
    }
  }
}
 

Example 14

From project tika, under directory /tika-core/src/main/java/org/apache/tika/extractor/.

Source file: ParserContainerExtractor.java

  31 
vote

public void extract(TikaInputStream stream,ContainerExtractor recurseExtractor,EmbeddedResourceHandler handler) throws IOException, TikaException {
  ParseContext context=new ParseContext();
  context.set(Parser.class,new RecursiveParser(recurseExtractor,handler));
  try {
    parser.parse(stream,new DefaultHandler(),new Metadata(),context);
  }
 catch (  SAXException e) {
    throw new TikaException("Unexpected SAX exception",e);
  }
}
 

Example 15

From project xwiki-rendering, under directory /xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/xhtml/.

Source file: XhtmlParser.java

  31 
vote

/** 
 * @see org.xwiki.rendering.wikimodel.IWikiParser#parse(java.io.Reader,org.xwiki.rendering.wikimodel.IWemListener)
 */
public void parse(Reader reader,IWemListener listener) throws WikiParserException {
  try {
    XMLReader xmlReader=getXMLReader();
    DefaultHandler handler=getHandler(listener);
    xmlReader.setFeature("http://xml.org/sax/features/namespaces",true);
    xmlReader.setEntityResolver(new LocalEntityResolver());
    xmlReader.setContentHandler(handler);
    xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",handler);
    InputSource source=new InputSource(reader);
    xmlReader.parse(source);
  }
 catch (  Exception e) {
    throw new WikiParserException(e);
  }
}
 

Example 16

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

Source file: IPConfig.java

  30 
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 17

From project and-bible, under directory /AndBackendTest/src/net/bible/service/format/.

Source file: HandleScripRef.java

  30 
vote

/** 
 * TSK is Thml format and contains scripRef tags but must be converted to OSIS reference tags
 */
public void testJSwordThmlProcessing() throws Exception {
  Book book=Books.installed().getBook("TSK");
  Key key=book.getKey("Matt 21:21");
  BookData data=new BookData(book,key);
  SAXEventProvider osissep=data.getSAXEventProvider();
  final StringBuilder tags=new StringBuilder();
  ContentHandler saxHandler=new DefaultHandler(){
    @Override public void startElement(    String uri,    String localName,    String qName,    Attributes attributes) throws SAXException {
      tags.append("<" + qName + ">");
    }
  }
;
  osissep.provideSAXEvents(saxHandler);
  String html=tags.toString();
  System.out.println(html);
  assertTrue("Thml not converted to OSIS",html.contains("reference") && !html.contains("scripRef"));
}
 

Example 18

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

Source file: TestXmlResultWriter.java

  30 
vote

public void run(){
  try {
    reader=XMLReaderFactory.createXMLReader();
    reader.setFeature(XML_VALIDATION_FEATURE,true);
    reader.setFeature(XML_SCHEMA_FEATURE,true);
    reader.setFeature(XML_SCHEMA_FULL_CHECKING_FEATURE,true);
    reader.setContentHandler(new DefaultHandler());
    reader.setErrorHandler(new PassingSAXErrorHandler());
    reader.parse(new InputSource(in));
  }
 catch (  Exception e) {
    validationMessage=e.getMessage();
    throw new IllegalStateException(e);
  }
 finally {
    latch.countDown();
  }
}
 

Example 19

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

Source file: HtmlTools.java

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

From project jbossportletbridge, under directory /core/portletbridge-impl/src/test/java/org/jboss/portletbridge/config/.

Source file: StateHandlerTest.java

  30 
vote

public void testReturnBack() throws Exception {
  ContentHandler parentHandler=new DefaultHandler(){
    @Override public void startElement(    String uri,    String localName,    String name,    Attributes attributes) throws SAXException {
      throw new SAXException();
    }
    @Override public void endElement(    String uri,    String localName,    String name) throws SAXException {
      throw new SAXException();
    }
  }
;
  StateHandler handler=new StateHandler(reader,parentHandler){
  }
;
  reader.setContentHandler(handler);
  handler.startElement(NS,BAR,PREFIX + BAR,null);
  handler.startElement(NS,BAR,PREFIX + BAR,null);
  handler.endElement(NS,BAR,PREFIX + BAR);
  assertSame(handler,reader.getContentHandler());
  handler.endElement(NS,BAR,PREFIX + BAR);
  assertSame(handler,reader.getContentHandler());
  handler.endElement(NS,BAR,PREFIX + BAR);
  assertSame(parentHandler,reader.getContentHandler());
}
 

Example 21

From project juel, under directory /samples/src/de/odysseus/el/samples/xml/sax/.

Source file: AttributesFilter.java

  30 
vote

/** 
 * Usage example.
 */
public static void main(String[] args) throws SAXException, IOException {
  ELContext context=new SimpleContext();
  context.getELResolver().setValue(context,null,"home","/foo/bar");
  XMLReader reader=new AttributesFilter(XMLReaderFactory.createXMLReader(),context);
  reader.setContentHandler(new DefaultHandler(){
    @Override public void startElement(    String uri,    String localName,    String qName,    Attributes attributes){
      System.out.println("start " + localName);
      for (int i=0; i < attributes.getLength(); i++) {
        System.out.println("  @" + attributes.getLocalName(i) + " = "+ attributes.getValue(i));
      }
    }
    @Override public void endElement(    String uri,    String localName,    String qName){
      System.out.println("end " + localName);
    }
    @Override public void characters(    char[] ch,    int start,    int length) throws SAXException {
      System.out.println("text: " + new String(ch,start,length));
    }
  }
);
  String xml="<test>foo<math>1+2=${1+2}</math><config file='${home}/config.xml'/>bar</test>";
  reader.parse(new InputSource(new StringReader(xml)));
}
 

Example 22

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

Source file: Splitter.java

  30 
vote

public void endElement(String namespaceURI,String localName,String qName) throws SAXException {
  super.endElement(namespaceURI,localName,qName);
  if (depth != 0) {
    depth--;
    if (depth == 0) {
      Enumeration e=namespaces.getPrefixes();
      while (e.hasMoreElements()) {
        String prefix=(String)e.nextElement();
        unmarshallerHandler.endPrefixMapping(prefix);
      }
      String defaultURI=namespaces.getURI("");
      if (defaultURI != null)       unmarshallerHandler.endPrefixMapping("");
      unmarshallerHandler.endDocument();
      setContentHandler(new DefaultHandler());
      try {
        JAXBElement<PurchaseOrderType> result=(JAXBElement<PurchaseOrderType>)unmarshallerHandler.getResult();
        process(result.getValue());
      }
 catch (      JAXBException je) {
        System.err.println("unable to process an order at line " + locator.getLineNumber());
        return;
      }
      unmarshallerHandler=null;
    }
  }
}
 

Example 23

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

Source file: TaskDescriptionProvider.java

  30 
vote

/** 
 * Returns the (DOM) document as a result of parsing the file with the  specified file name. <P> The file will be loaded as resource, thus must begin with '/' and must be relative to the classpath.
 */
private Document parseFile(String aFileName){
  Document tempDocument=null;
  DocumentBuilderFactory tempFactory=DocumentBuilderFactory.newInstance();
  tempFactory.setIgnoringComments(true);
  tempFactory.setIgnoringElementContentWhitespace(true);
  tempFactory.setCoalescing(true);
  try {
    DocumentBuilder tempDocBuilder=tempFactory.newDocumentBuilder();
    tempDocBuilder.setErrorHandler(new DefaultHandler());
    URL tempURL=getClass().getResource(aFileName);
    InputSource tempInputSource=new InputSource(tempURL.toExternalForm());
    tempDocument=tempDocBuilder.parse(tempInputSource);
  }
 catch (  ParserConfigurationException e) {
    PhingUi.log(e);
  }
catch (  IOException ioException) {
    PhingUi.log(ioException);
  }
catch (  SAXException saxException) {
    PhingUi.log(saxException);
  }
  return tempDocument;
}
 

Example 24

From project spring-security-oauth, under directory /samples/oauth/tonr/src/main/java/org/springframework/security/oauth/examples/tonr/impl/.

Source file: GoogleServiceImpl.java

  30 
vote

public List<String> getLastTenPicasaPictureURLs(){
  byte[] bytes=getGoogleRestTemplate().getForObject(URI.create("https://picasaweb.google.com/data/feed/api/user/default?kind=photo&max-results=10"),byte[].class);
  InputStream photosXML=new ByteArrayInputStream(bytes);
  final List<String> photoUrls=new ArrayList<String>();
  SAXParserFactory parserFactory=SAXParserFactory.newInstance();
  parserFactory.setValidating(false);
  parserFactory.setXIncludeAware(false);
  parserFactory.setNamespaceAware(true);
  try {
    SAXParser parser=parserFactory.newSAXParser();
    parser.parse(photosXML,new DefaultHandler(){
      @Override public void startElement(      String uri,      String localName,      String qName,      Attributes attributes) throws SAXException {
        if ("http://search.yahoo.com/mrss/".equals(uri) && "thumbnail".equalsIgnoreCase(localName)) {
          int width=0;
          try {
            width=Integer.parseInt(attributes.getValue("width"));
            if (width > 100 && width < 200) {
              photoUrls.add(attributes.getValue("url"));
            }
          }
 catch (          NumberFormatException e) {
          }
        }
      }
    }
);
    return photoUrls;
  }
 catch (  ParserConfigurationException e) {
    throw new IllegalStateException(e);
  }
catch (  SAXException e) {
    throw new IllegalStateException(e);
  }
catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}
 

Example 25

From project swtbot, under directory /org.eclipse.swtbot.generator/src/org/eclipse/swtbot/generator/.

Source file: XmlConfigurator.java

  30 
vote

public void load(InputSource inputSource) throws ParserConfigurationException, SAXException, IOException {
  SAXParser saxParser=saxParserFactory.newSAXParser();
  saxParser.parse(inputSource,new DefaultHandler(){
    @Override public void startElement(    String uri,    String localName,    String qName,    Attributes attributes) throws SAXException {
      if (localName.equals("widget")) {
        String className=attributes.getValue("class");
        try {
          addClass(className);
        }
 catch (        ClassNotFoundException e) {
          throw new SAXException("Cannot find Matcher class : " + className);
        }
      }
    }
  }
);
}
 

Example 26

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

Source file: GoodreadsManager.java

  29 
vote

/** 
 * Utility routine called to sign a request and submit it then pass it off to a parser.
 * @author Philip Warner
 * @throws NotAuthorizedException 
 * @throws BookNotFoundException 
 * @throws NetworkException 
 */
public HttpResponse execute(HttpUriRequest request,DefaultHandler requestHandler,boolean requiresSignature) throws ClientProtocolException, IOException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, NotAuthorizedException, BookNotFoundException, NetworkException {
  HttpClient httpClient=newHttpClient();
  if (requiresSignature) {
    m_consumer.setTokenWithSecret(m_accessToken,m_accessSecret);
    m_consumer.sign(request);
  }
  waitUntilRequestAllowed();
  HttpResponse response;
  try {
    response=httpClient.execute(request);
  }
 catch (  Exception e) {
    throw new NetworkException(e);
  }
  int code=response.getStatusLine().getStatusCode();
  if (code == 200 || code == 201)   parseResponse(response,requestHandler);
 else   if (code == 401) {
    m_hasValidCredentials=false;
    throw new NotAuthorizedException(null);
  }
 else   if (code == 404) {
    throw new BookNotFoundException(null);
  }
 else   throw new RuntimeException("Unexpected status code from API: " + response.getStatusLine().getStatusCode() + "/"+ response.getStatusLine().getReasonPhrase());
  return response;
}
 

Example 27

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

Source file: ValidateCommand.java

  29 
vote

/** 
 * Validate the supplied file.
 * @param project The project name.
 * @param file The file to validate.
 * @param schema true to use declared schema, false otherwise.
 * @param handler The DefaultHandler to use while parsing the xml file.
 * @return The list of errors.
 */
protected List<Error> validate(String project,String file,boolean schema,DefaultHandler handler) throws Exception {
  List<Error> errors=XmlUtils.validateXml(project,file,schema,handler);
  for (Iterator<Error> ii=errors.iterator(); ii.hasNext(); ) {
    Error error=ii.next();
    if (error.getMessage().indexOf(NO_GRAMMER) != -1 || error.getMessage().indexOf(DOCTYPE_ROOT_NULL) != -1) {
      ii.remove();
    }
  }
  return errors;
}
 

Example 28

From project HapiPodcastJ, under directory /src/info/xuluan/podcast/parser/.

Source file: FeedParser.java

  29 
vote

public void parse(InputStream input,DefaultHandler handler){
  try {
    SAXParser parser=saxParserFactory.newSAXParser();
    parser.parse(input,handler);
  }
 catch (  SAXException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
catch (  IOException e) {
    throw new RuntimeException(e);
  }
catch (  ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
 finally {
    if (input != null) {
      try {
        input.close();
      }
 catch (      IOException e) {
      }
    }
  }
}
 

Example 29

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

Source file: SAXParserTestCase.java

  29 
vote

@Deployment public static JavaArchive createdeployment(){
  final JavaArchive archive=ShrinkWrap.create(JavaArchive.class,"sax-parser.jar");
  archive.addAsResource(SAXParserTestCase.class.getPackage(),"simple.xml","simple.xml");
  archive.setManifest(new Asset(){
    public InputStream openStream(){
      OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
      builder.addBundleSymbolicName(archive.getName());
      builder.addBundleManifestVersion(2);
      builder.addImportPackages(SAXParser.class,SAXException.class,DefaultHandler.class);
      return builder.openStream();
    }
  }
);
  return archive;
}
 

Example 30

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

Source file: SAXParserTestCase.java

  29 
vote

@Deployment public static JavaArchive createdeployment(){
  final JavaArchive archive=ShrinkWrap.create(JavaArchive.class,"sax-parser");
  archive.addAsResource("jaxp/simple.xml");
  archive.setManifest(new Asset(){
    public InputStream openStream(){
      OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
      builder.addBundleSymbolicName(archive.getName());
      builder.addBundleManifestVersion(2);
      builder.addImportPackages(SAXParser.class,SAXException.class,DefaultHandler.class);
      return builder.openStream();
    }
  }
);
  return archive;
}
 

Example 31

From project libra, under directory /plugins/org.eclipse.libra.warproducts.ui/src/org/eclipse/libra/warproducts/ui/editor/.

Source file: WebXMLModel.java

  29 
vote

protected DefaultHandler createDocumentHandler(final IModel model,final boolean reconciling){
  if (documentHandler == null) {
    documentHandler=new WebXmlDocumentHandler(getDocument(),nodeFactory,reconciling);
  }
  return documentHandler;
}
 

Example 32

From project static-jsfexpression-validator, under directory /static-jsfexpression-validator-jsf20/src/main/java/org/apache/myfaces/view/facelets/compiler/.

Source file: JsfelcheckSAXCompiler.java

  29 
vote

private final SAXParser createSAXParser(DefaultHandler handler) throws SAXException, ParserConfigurationException {
  SAXParserFactory factory=SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
  factory.setFeature("http://xml.org/sax/features/validation",this.isValidating());
  factory.setValidating(this.isValidating());
  SAXParser parser=factory.newSAXParser();
  XMLReader reader=parser.getXMLReader();
  reader.setProperty("http://xml.org/sax/properties/lexical-handler",handler);
  reader.setErrorHandler(handler);
  reader.setEntityResolver(handler);
  return parser;
}