예제 #1
0
  /**
   * This will recursively invoke all of the callbacks for a particular element.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void element(Element element, NamespaceStack stack) throws JDOMException {

    AttributesImpl nsAtts = null; // The namespaces as xmlns attributes

    // contentHandler.startPrefixMapping()
    stack.push(element);
    try {
      for (Namespace ns : stack.addedForward()) {
        startPrefixMapping(ns);
        nsAtts = this.addNsAttribute(nsAtts, ns);
      }

      // contentHandler.startElement()
      startElement(element, nsAtts);

      // handle content in the element
      elementContent(element.getContent(), stack);

      // update locator
      if (locator != null) {
        locator.setNode(element);
      }

      // contentHandler.endElement()
      endElement(element);
    } finally {
      stack.pop();
    }

    // contentHandler.endPrefixMapping()
    // de-map in reverse order to the mapping.
    for (Namespace ns : stack.addedReverse()) {
      endPrefixMapping(ns);
    }
  }
예제 #2
0
    /**
     * Returns the content of a JDOM Element detached from it.
     *
     * @param elt the element to get the content from.
     * @return a (possibly empty) list of JDOM nodes, detached from their parent.
     */
    private List getDetachedContent(Element elt) {
      List content = elt.getContent();
      List nodes = new ArrayList(content.size());

      while (content.size() != 0) {
        Object o = content.remove(0);
        nodes.add(o);
      }
      return (nodes);
    }
  /**
   * Returns the index of a content from its Parent point of view, and using JDOM specifications.
   *
   * @param parent
   * @param content
   * @return The index of the Content
   * @throws robusta.commons.exceptions.XmlException
   */
  public int getContentIndex(Element parent, Content content) throws XmlException {

    List contents = parent.getContent();
    for (int i = 0; i < contents.size(); i++) {
      if (contents.get(i) == content) {
        return i;
      }
    }

    throw new XmlException(
        "can't find content " + content.getValue() + " in element " + parent.getName());
  }
예제 #4
0
  /**
   * This will recursively invoke all of the callbacks for a particular element.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void element(Element element, NamespaceStack namespaces) throws JDOMException {
    // used to check endPrefixMapping
    int previouslyDeclaredNamespaces = namespaces.size();

    // contentHandler.startPrefixMapping()
    Attributes nsAtts = startPrefixMapping(element, namespaces);

    // contentHandler.startElement()
    startElement(element, nsAtts);

    // handle content in the element
    elementContent(element.getContent(), namespaces);

    // update locator
    locator.setNode(element);

    // contentHandler.endElement()
    endElement(element);

    // contentHandler.endPrefixMapping()
    endPrefixMapping(namespaces, previouslyDeclaredNamespaces);
  }
예제 #5
0
  public static void removeEventinXmlFilter() {
    Filter filtre =
        new Filter() {
          // On défini les propriétés du filtre à l'aide
          // de la méthode matches
          public boolean matches(Object ob) {
            //		         //1 ère vérification : on vérifie que les objets
            //		         //qui seront filtrés sont bien des Elements
            //		         if(!(ob instanceof Element)){return false;}
            //
            //		         //On crée alors un Element sur lequel on va faire les
            //		         //vérifications suivantes.
            //		         Element element = (Element)ob;
            //
            //		         //On crée deux variables qui vont nous permettre de vérifier
            //		         //les conditions de nom et de prenom
            //		         int verifNom = 0;
            //		         int verifPrenom = 0;
            //
            //		         //2 ème vérification: on vérifie que le nom est bien "CynO"
            //		         if(element.getAttribute("nomEvent").getValue().equalsIgnoreCase("event1"))
            ////		         if(element.getChild("nom").getTextTrim().equals("CynO"))
            //		         {
            //		            verifNom = 1;
            //		         }
            //		         //Si nos conditions sont remplies on retourne true, false sinon
            //		         if(verifNom == 1)
            //		         {
            //		            return true;
            //		         }
            //		         return false;
            return true;
          }

          @Override
          public Filter and(Filter arg0) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public List filter(List arg0) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public Object filter(Object arg0) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public Filter negate() {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public Filter or(Filter arg0) {
            // TODO Auto-generated method stub
            return null;
          }

          @Override
          public Filter refine(Filter arg0) {
            // TODO Auto-generated method stub
            return null;
          }
        }; // Fin du filtre

    // getContent va utiliser notre filtre pour créer une liste d'étudiants répondant
    // à nos critères.
    SAXBuilder sxbuilder = new SAXBuilder();
    Document document;
    try {
      document = sxbuilder.build(new File(xmlDefaultPath));
      Element racine = document.getRootElement();
      List resultat = racine.getContent(filtre);
      System.out.println("size" + resultat.size() + "##");
      // On affiche enfin l'attribut classe de tous les éléments de notre list
      Iterator i = resultat.iterator();
      while (i.hasNext()) {
        Element courant = (Element) i.next();
        System.out.println(courant.getAttributeValue("nomEvent"));
      }

    } catch (JDOMException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }