Package org.jdom2

Examples of org.jdom2.JDOMException


  private List<Content> processFragments(JDOMFactory factory, XMLStreamReader stream, StAXFilter filter) throws JDOMException {
   
    int state = stream.getEventType();

    if (START_DOCUMENT != state) {
      throw new JDOMException("JDOM requires that XMLStreamReaders " +
          "are at their beginning when being processed.");
    }
    List<Content> ret = new ArrayList<Content>();
   
    int depth = 0;
    String text = null;
   
    try {
      while (stream.hasNext() && (state = stream.next()) != END_DOCUMENT) {
        switch (state) {
          case START_DOCUMENT:
            throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state START_DOCUMENT" );
          case END_DOCUMENT:
            throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state END_DOCUMENT" );
          case END_ELEMENT:
            throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state END_ELEMENT" );

          case START_ELEMENT:
            final QName qn = stream.getName();
            if (filter.includeElement(depth, qn.getLocalPart(),
                Namespace.getNamespace(qn.getPrefix(), qn.getNamespaceURI()))) {
              ret.add(processPrunableElement(factory, stream, depth, filter));
            } else {
              final int back = depth;
              depth++;
             
              while (depth > back && stream.hasNext()) {
                state = stream.next();
                if (state == START_ELEMENT) {
                  depth++;
                } else if (state == END_ELEMENT) {
                  depth--;
                }
              }
            }
            break;

          case DTD:
            if (filter.includeDocType()) {
              ret.add(DTDParser.parse(stream.getText(), factory));
            }
            break;

          case CDATA:
            if ((text = filter.includeCDATA(depth, stream.getText())) != null) {
              ret.add(factory.cdata(text));
            }
            break;

          case SPACE:
          case CHARACTERS:
            if ((text = filter.includeText(depth, stream.getText())) != null) {
              ret.add(factory.text(text));
            }
            break;

          case COMMENT:
            if ((text = filter.includeComment(depth, stream.getText())) != null) {
              ret.add(factory.comment(text));
            }
            break;

          case ENTITY_REFERENCE:
            if (filter.includeEntityRef(depth, stream.getLocalName())) {
              ret.add(factory.entityRef(stream.getLocalName()));
            }
            break;

          case PROCESSING_INSTRUCTION:
            if (filter.includeProcessingInstruction(depth, stream.getPITarget())) {
              ret.add(factory.processingInstruction(
                stream.getPITarget(), stream.getPIData()));
            }
            break;

          default:
            throw new JDOMException("Unexpected XMLStream event " + stream.getEventType());
        }
      }
    } catch (XMLStreamException e) {
      throw new JDOMException("Unable to process fragments from XMLStreamReader.", e);
    }
   
    return ret;
  }
View Full Code Here


  private static final Element processPrunableElement(final JDOMFactory factory,
      final XMLStreamReader reader, final int topdepth, StAXFilter filter)
          throws XMLStreamException, JDOMException {

    if (START_ELEMENT != reader.getEventType()) {
      throw new JDOMException("JDOM requires that the XMLStreamReader " +
          "is at the START_ELEMENT state when retrieving an " +
          "Element Fragment.");
    }
   
    final Element fragment = processElement(factory, reader);
    Element current = fragment;
    int depth = topdepth + 1;
    String text = null;
    while (depth > topdepth && reader.hasNext()) {
      switch(reader.next()) {
        case START_ELEMENT:
          QName qn = reader.getName();
          if (!filter.pruneElement(depth, qn.getLocalPart(),
              Namespace.getNamespace(
                  qn.getPrefix(), qn.getNamespaceURI()))) {
            Element tmp = processElement(factory, reader);
            current.addContent(tmp);
            current = tmp;
            depth++;
          } else {
            final int edepth = depth;
            depth++;
            int state = 0;
            while (depth > edepth && reader.hasNext() &&
                (state = reader.next()) != END_DOCUMENT) {
              if (state == START_ELEMENT) {
                depth++;
              } else if (state == END_ELEMENT) {
                depth--;
              }
            }
          }
          break;
        case END_ELEMENT:
          current = current.getParentElement();
          depth--;
          break;
        case CDATA:
          if ((text = filter.pruneCDATA(depth, reader.getText())) != null) {
            current.addContent(factory.cdata(text));
          }
          break;

        case SPACE:
        case CHARACTERS:
          if ((text = filter.pruneText(depth, reader.getText())) != null) {
            current.addContent(factory.text(text));
          }
          break;

        case COMMENT:
          if ((text = filter.pruneComment(depth, reader.getText())) != null) {
            current.addContent(factory.comment(text));
          }
          break;

        case ENTITY_REFERENCE:
          if (!filter.pruneEntityRef(depth, reader.getLocalName())) {
            current.addContent(factory.entityRef(reader.getLocalName()));
          }
          break;

        case PROCESSING_INSTRUCTION:
          if (!filter.pruneProcessingInstruction(depth, reader.getPITarget())) {
            current.addContent(factory.processingInstruction(
                reader.getPITarget(), reader.getPIData()));
          }
          break;

        default:
          throw new JDOMException("Unexpected XMLStream event " + reader.getEventType());
      }
     
    }
   
    return fragment;
View Full Code Here

    try {
     
      switch (stream.getEventType()) {

        case START_DOCUMENT:
          throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state START_DOCUMENT" );
        case END_DOCUMENT:
          throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state END_DOCUMENT" );
        case END_ELEMENT:
          throw new JDOMException("Illegal state for XMLStreamReader. Cannot get XML Fragment for state END_ELEMENT" );

        case START_ELEMENT:
          Element emt = processElementFragment(factory, stream);
          stream.next();
          return emt;

        case DTD:
          Content dt = DTDParser.parse(stream.getText(), factory);
          stream.next();
          return dt;

        case CDATA:
          Content cd = factory.cdata(stream.getText());
          stream.next();
          return cd;

        case SPACE:
        case CHARACTERS:
          Content txt = factory.text(stream.getText());
          stream.next();
          return txt;

        case COMMENT:
          Content comment = factory.comment(stream.getText());
          stream.next();
          return comment;

        case ENTITY_REFERENCE:
          Content er = factory.entityRef(stream.getLocalName());
          stream.next();
          return er;

        case PROCESSING_INSTRUCTION:
          Content pi = factory.processingInstruction(
              stream.getPITarget(), stream.getPIData());
          stream.next();
          return pi;

        default:
          throw new JDOMException("Unexpected XMLStream event " + stream.getEventType());

      }
    } catch (final XMLStreamException xse) {
      throw new JDOMException("Unable to process XMLStream. See Cause.", xse);
    }
  }
View Full Code Here

  private static final Element processElementFragment(final JDOMFactory factory,
      final XMLStreamReader reader) throws XMLStreamException, JDOMException {

    if (START_ELEMENT != reader.getEventType()) {
      throw new JDOMException("JDOM requires that the XMLStreamReader " +
          "is at the START_ELEMENT state when retrieving an " +
          "Element Fragment.");
    }
   
    final Element fragment = processElement(factory, reader);
    Element current = fragment;
    int depth = 1;
    while (depth > 0 && reader.hasNext()) {
      switch(reader.next()) {
        case START_ELEMENT:
          Element tmp = processElement(factory, reader);
          current.addContent(tmp);
          current = tmp;
          depth++;
          break;
        case END_ELEMENT:
          current = current.getParentElement();
          depth--;
          break;
        case CDATA:
          current.addContent(factory.cdata(reader.getText()));
          break;

        case SPACE:
        case CHARACTERS:
          current.addContent(factory.text(reader.getText()));
          break;

        case COMMENT:
          current.addContent(factory.comment(reader.getText()));
          break;

        case ENTITY_REFERENCE:
          current.addContent(factory.entityRef(reader.getLocalName()));
          break;

        case PROCESSING_INSTRUCTION:
          current.addContent(factory.processingInstruction(
              reader.getPITarget(), reader.getPIData()));
          break;

        default:
          throw new JDOMException("Unexpected XMLStream event " + reader.getEventType());
      }
     
    }
   
    return fragment;
View Full Code Here

  private void internalSetFeature(final XMLReader parser, final String feature,
      final boolean value, final String displayName) throws JDOMException {
    try {
      parser.setFeature(feature, value);
    } catch (final SAXNotSupportedException e) {
      throw new JDOMException(
          displayName + " feature not supported for SAX driver " + parser.getClass().getName());
    } catch (final SAXNotRecognizedException e) {
      throw new JDOMException(
          displayName + " feature not recognized for SAX driver " + parser.getClass().getName());
    }
  }
View Full Code Here

  private void internalSetProperty(final XMLReader parser, final String property,
      final Object value, final String displayName) throws JDOMException {
    try {
      parser.setProperty(property, value);
    } catch (final SAXNotSupportedException e) {
      throw new JDOMException(
          displayName + " property not supported for SAX driver " + parser.getClass().getName());
    } catch (final SAXNotRecognizedException e) {
      throw new JDOMException(
          displayName + " property not recognized for SAX driver " + parser.getClass().getName());
    }
  }
View Full Code Here

    try
    {
      Document xml=this.loadURL(url);
      if(language.equals("en"))
      {
        for(Element div:xml.getDescendants(new ElementFilter("a")))
        {
          if(div.getAttributeValue("href")!=null&&div.getAttributeValue("href").equals("/wiki/Special:Statistics"))
          {
            String str=div.getValue();
            System.out.println(str);
            this.glossCount=Double.parseDouble(str.replace(",", ""));
            break;
          }
        }
      }
      else
      {
        for(Element div:xml.getDescendants(new ElementFilter("li")))
        {
          if(div.getAttributeValue("id")!=null && div.getAttributeValue("id").contains("lang-"))
          {
            for(Element span:div.getDescendants(new ElementFilter("span")))
            {
              if(span.getAttributeValue("lang").equals(language))
              {
                String str=div.getValue();
                str=str.substring(0,str.indexOf(" articles"));
View Full Code Here

    {
      ArrayList<URL> urls=new ArrayList<URL>();
      ArrayList<Integer> levels=new ArrayList<Integer>();
      ArrayList<Integer> hindex=new ArrayList<Integer>();
      ArrayList<String> heads=new ArrayList<String>();
      for(Element div:xml.getDescendants(new ElementFilter("div")))
      {
        if(div.getAttributeValue("id")!=null&&div.getAttributeValue("id").equals("content"))
        {
          ElementFilter f=new ElementFilter("a");
          Filter<? extends Content> or=f.or(new ElementFilter("span"));
          for(Content c:div.getDescendants(or))
          {
            if(c.getCType()==CType.Element)
            {
              Element word=(Element)c;
View Full Code Here

    URL count=new URL(this.path+"/w/index.php?title=Special%3ASearch&profile=default&search="+lemma.replace(" ", "%20")+"&fulltext=Search");   
    Document xml=this.loadURL(count)
    if(xml!=null)
    {
      String aux="mw-search-formheader";
      for(Element e:this.getContentNode(xml).getDescendants(new ElementFilter("div")))
      {
        if(aux.equals(e.getAttributeValue("class")))
        {
          for(Element x:e.getDescendants(new ElementFilter("div")))
          {
            aux="results-info";
            if(aux.equals(x.getAttributeValue("class")))
            {
              aux=e.getValue().substring(e.getValue().indexOf(this.countText)+this.countText.length());;
View Full Code Here

          }
         
        }
      }
      Element navbox=null;
      for(Element e:xml.getRootElement().getDescendants(new ElementFilter("table")))
      {
        if(e.getAttributeValue("class")!=null&&e.getAttributeValue("class").equals("navbox"))
        {
            navbox=e;
            break;
        }
      }
      //Add inNavBox relations
      if(navbox!=null)
      {
        for(Element e:navbox.getDescendants(new ElementFilter("a")))
        {
          String nurl=e.getAttributeValue("href");
          if(nurl!=null&&!this.isNotAnArticle(nurl))
          {
            s.addRelation("inNavBox", new Relation("inNavBox", nurl.replace("/wiki/", ""), ""));
          }
        }
      }
      //Add in CatLinks relations
      Element catlinks=null;
      String aux="catlinks";
      for(Element e:body.getParent().getDescendants(new ElementFilter("div")))
      {
        if(aux.equals(e.getAttributeValue("id")))
        {
          catlinks=e;
          break;
        }
      }
      if(catlinks!=null)
      {
        for(Element e:catlinks.getDescendants(new ElementFilter("a")))
        {
          String nurl=e.getAttributeValue("href");
          if(nurl!=null&&!this.isNotAnArticle(nurl))
          {
            s.addRelation("inCatLinks", new Relation("inCatLinks", nurl.replace("/wiki/", ""), ""));
View Full Code Here

TOP

Related Classes of org.jdom2.JDOMException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.