Example #1
0
  private LinkedHashMap[] obtenerMapeos(CliGol cliGol, NodeList variables, String[] excluye) {

    LinkedHashMap<String, Object> mapa = new LinkedHashMap<String, Object>();

    LinkedHashMap<String, String> puntos = new LinkedHashMap<String, String>();

    List<String> ex = Arrays.asList(excluye);

    for (int i = 0; i < variables.getLength(); i++) {

      String nom = variables.item(i).getNodeName();

      if (!ex.contains(nom)) {

        String golMapdijo = GolMap.xmlGol(nom);

        String val = null;
        if (golMapdijo != null) {
          val = buscaValEnCli(golMapdijo, cliGol);
          mapa.put(nom, val);

          puntos.put(nom, variables.item(i).getTextContent());
        }
      }
    }

    return new LinkedHashMap[] {mapa, puntos};
  }
  public IXArchElement cloneElement(int depth) {
    synchronized (DOMUtils.getDOMLock(elt)) {
      Document doc = elt.getOwnerDocument();
      if (depth == 0) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      } else if (depth == 1) {
        Element cloneElt = (Element) elt.cloneNode(false);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());

        NodeList nl = elt.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
          Node n = nl.item(i);
          Node cloneNode = (Node) n.cloneNode(false);
          cloneNode = doc.importNode(cloneNode, true);
          cloneElt.appendChild(cloneNode);
        }
        return cloneImpl;
      } else /* depth = infinity */ {
        Element cloneElt = (Element) elt.cloneNode(true);
        cloneElt = (Element) doc.importNode(cloneElt, true);
        AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt);
        cloneImpl.setXArch(getXArch());
        return cloneImpl;
      }
    }
  }
  public IJavaSourceCodeManager getSourceCodeManager() {
    NodeList nl =
        DOMUtils.getChildren(elt, JavasourcecodeConstants.NS_URI, SOURCE_CODE_MANAGER_ELT_NAME);
    if (nl.getLength() == 0) {
      return null;
    } else {
      Element el = (Element) nl.item(0);
      IXArch de = getXArch();
      if (de != null) {
        IXArchElement cachedXArchElt = de.getWrapper(el);
        if (cachedXArchElt != null) {
          return (IJavaSourceCodeManager) cachedXArchElt;
        }
      }

      Object o = makeDerivedWrapper(el, "JavaSourceCodeManager");
      if (o != null) {
        try {
          ((edu.uci.isr.xarch.IXArchElement) o).setXArch(getXArch());
          if (de != null) {
            de.cacheWrapper(el, ((edu.uci.isr.xarch.IXArchElement) o));
          }
          return (IJavaSourceCodeManager) o;
        } catch (Exception e) {
        }
      }
      JavaSourceCodeManagerImpl eltImpl = new JavaSourceCodeManagerImpl(el);
      eltImpl.setXArch(getXArch());
      if (de != null) {
        de.cacheWrapper(el, ((edu.uci.isr.xarch.IXArchElement) eltImpl));
      }
      return eltImpl;
    }
  }
  public void removeRepositoryLocation(IRepositoryLocation repositoryLocationToRemove) {
    if (!(repositoryLocationToRemove instanceof DOMBased)) {
      throw new IllegalArgumentException("Cannot handle non-DOM-based xArch entities.");
    }
    NodeList nl =
        DOMUtils.getChildren(elt, JavasourcecodeConstants.NS_URI, REPOSITORY_LOCATION_ELT_NAME);
    for (int i = 0; i < nl.getLength(); i++) {
      Node n = nl.item(i);
      if (n == ((DOMBased) repositoryLocationToRemove).getDOMNode()) {
        synchronized (DOMUtils.getDOMLock(elt)) {
          elt.removeChild(n);
        }

        IXArch context = getXArch();
        if (context != null) {
          context.fireXArchEvent(
              new XArchEvent(
                  this,
                  XArchEvent.REMOVE_EVENT,
                  XArchEvent.ELEMENT_CHANGED,
                  "repositoryLocation",
                  repositoryLocationToRemove,
                  XArchUtils.getDefaultXArchImplementation().isContainedIn(xArch, this)));
        }

        return;
      }
    }
  }
 private void extractMBeanPolicy(MBeanPolicyConfig pConfig, Node pMBeanNode)
     throws MalformedObjectNameException {
   NodeList params = pMBeanNode.getChildNodes();
   String name = null;
   Set<String> readAttributes = new HashSet<String>();
   Set<String> writeAttributes = new HashSet<String>();
   Set<String> operations = new HashSet<String>();
   for (int k = 0; k < params.getLength(); k++) {
     Node param = params.item(k);
     if (param.getNodeType() != Node.ELEMENT_NODE) {
       continue;
     }
     assertNodeName(param, "name", "attribute", "operation");
     String tag = param.getNodeName();
     if (tag.equals("name")) {
       if (name != null) {
         throw new SecurityException("<name> given twice as MBean name");
       } else {
         name = param.getTextContent().trim();
       }
     } else if (tag.equals("attribute")) {
       extractAttribute(readAttributes, writeAttributes, param);
     } else if (tag.equals("operation")) {
       operations.add(param.getTextContent().trim());
     } else {
       throw new SecurityException("Tag <" + tag + "> invalid");
     }
   }
   if (name == null) {
     throw new SecurityException("No <name> given for <mbean>");
   }
   pConfig.addValues(new ObjectName(name), readAttributes, writeAttributes, operations);
 }
 /**
  * Unmarshall a Genotype instance from a given XML Element representation. Its population of
  * Chromosomes will be unmarshalled from the Chromosome sub-elements.
  *
  * @param a_activeConfiguration the current active Configuration object that is to be used during
  *     construction of the Genotype and Chromosome instances
  * @param a_xmlElement the XML Element representation of the Genotype
  * @return a new Genotype instance, complete with a population of Chromosomes, setup with the data
  *     from the XML Element representation
  * @throws ImproperXMLException if the given Element is improperly structured or missing data
  * @throws InvalidConfigurationException if the given Configuration is in an inconsistent state
  * @throws UnsupportedRepresentationException if the actively configured Gene implementation does
  *     not support the string representation of the alleles used in the given XML document
  * @throws GeneCreationException if there is a problem creating or populating a Gene instance
  * @author Neil Rotstan
  * @author Klaus Meffert
  * @since 1.0
  */
 public static Genotype getGenotypeFromElement(
     Configuration a_activeConfiguration, Element a_xmlElement)
     throws ImproperXMLException, InvalidConfigurationException,
         UnsupportedRepresentationException, GeneCreationException {
   // Sanity check. Make sure the XML element isn't null and that it
   // actually represents a genotype.
   if (a_xmlElement == null || !(a_xmlElement.getTagName().equals(GENOTYPE_TAG))) {
     throw new ImproperXMLException(
         "Unable to build Genotype instance from XML Element: "
             + "given Element is not a 'genotype' element.");
   }
   // Fetch all of the nested chromosome elements and convert them
   // into Chromosome instances.
   // ------------------------------------------------------------
   NodeList chromosomes = a_xmlElement.getElementsByTagName(CHROMOSOME_TAG);
   int numChromosomes = chromosomes.getLength();
   Population population = new Population(a_activeConfiguration, numChromosomes);
   for (int i = 0; i < numChromosomes; i++) {
     population.addChromosome(
         getChromosomeFromElement(a_activeConfiguration, (Element) chromosomes.item(i)));
   }
   // Construct a new Genotype with the chromosomes and return it.
   // ------------------------------------------------------------
   return new Genotype(a_activeConfiguration, population);
 }
  public edu.uci.isr.xarch.instance.IXMLLink getChangeSet() {
    NodeList nl = DOMUtils.getChildren(elt, ChangesetsConstants.NS_URI, CHANGE_SET_ELT_NAME);
    if (nl.getLength() == 0) {
      return null;
    } else {
      Element el = (Element) nl.item(0);
      IXArch de = getXArch();
      if (de != null) {
        IXArchElement cachedXArchElt = de.getWrapper(el);
        if (cachedXArchElt != null) {
          return (edu.uci.isr.xarch.instance.IXMLLink) cachedXArchElt;
        }
      }

      Object o = makeDerivedWrapper(el, "XMLLink");
      if (o != null) {
        try {
          ((edu.uci.isr.xarch.IXArchElement) o).setXArch(getXArch());
          if (de != null) {
            de.cacheWrapper(el, ((edu.uci.isr.xarch.IXArchElement) o));
          }
          return (edu.uci.isr.xarch.instance.IXMLLink) o;
        } catch (Exception e) {
        }
      }
      edu.uci.isr.xarch.instance.XMLLinkImpl eltImpl =
          new edu.uci.isr.xarch.instance.XMLLinkImpl(el);
      eltImpl.setXArch(getXArch());
      if (de != null) {
        de.cacheWrapper(el, ((edu.uci.isr.xarch.IXArchElement) eltImpl));
      }
      return eltImpl;
    }
  }
Example #8
0
  private static MeasurementInfo parseMeasurement(Node parent) throws XmlParserException {
    String id = "";
    String label = "";
    String sampleid = "";
    Vector<FileInfo> files = null;
    Vector<ScanInfo> scans = null;

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("label")) label = element.getTextContent();
      else if (element.getTagName().equals("sampleid")) sampleid = element.getTextContent();
      else if (element.getTagName().equals("scans")) scans = parseScans(node);
      else if (element.getTagName().equals("files")) files = parseFiles(node);
    }

    MeasurementInfo measurement = new MeasurementInfo(Integer.parseInt(id), sampleid);
    measurement.setLabel(label);
    measurement.addFileInfos(files);
    if (scans != null) measurement.addScanInfos(scans);

    return measurement;
  }
Example #9
0
 private static Node xgetAt(Element element, int i) {
   if (hasChildElements(element, "*")) {
     NodeList nodeList = getChildElements(element, "*");
     return nodeList.item(i);
   }
   return null;
 }
Example #10
0
  private void processPanel(Session session, Element element, HashMap additionalInformation) {
    panelElementPresent = true;
    String panelName = element.getAttribute("name");
    if (panelName == null) {
      panelName = "Panel" + panelCounter++;
    }

    List<Track> panelTracks = new ArrayList();
    NodeList elements = element.getChildNodes();
    for (int i = 0; i < elements.getLength(); i++) {
      Node childNode = elements.item(i);
      if (childNode.getNodeName().equalsIgnoreCase(SessionElement.DATA_TRACK.getText())
          || // Is this a track?
          childNode.getNodeName().equalsIgnoreCase(SessionElement.TRACK.getText())) {

        List<Track> tracks = processTrack(session, (Element) childNode, additionalInformation);
        if (tracks != null) {
          panelTracks.addAll(tracks);
        }
      } else {
        process(session, childNode, additionalInformation);
      }
    }

    TrackPanel panel = IGV.getInstance().getTrackPanel(panelName);
    panel.addTracks(panelTracks);
  }
Example #11
0
  public static Element[] filterChildElements(Element parent, String ns, String lname) {
    /*
    way too noisy
            if (LOGGER.isDebugEnabled()) {
                StringBuilder buf = new StringBuilder(100);
                buf.append("XmlaUtil.filterChildElements: ");
                buf.append(" ns=\"");
                buf.append(ns);
                buf.append("\", lname=\"");
                buf.append(lname);
                buf.append("\"");
                LOGGER.debug(buf.toString());
            }
    */

    List<Element> elems = new ArrayList<Element>();
    NodeList nlst = parent.getChildNodes();
    for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
      Node n = nlst.item(i);
      if (n instanceof Element) {
        Element e = (Element) n;
        if ((ns == null || ns.equals(e.getNamespaceURI()))
            && (lname == null || lname.equals(e.getLocalName()))) {
          elems.add(e);
        }
      }
    }
    return elems.toArray(new Element[elems.size()]);
  }
  /**
   * Converts an XML element into an <code>EppCommandRenewXriName</code> object. The caller of this
   * method must make sure that the root node is of an EPP Command Renew entity for EPP XRI I-Name
   * object
   *
   * @param root root node for an <code>EppCommandRenewXriName</code> object in XML format
   * @return an <code>EppCommandRenewXriName</code> object, or null if the node is invalid
   */
  public static EppEntity fromXML(Node root) {
    EppCommandRenewXriName cmd = null;
    String iname = null;
    Calendar curExpDate = null;
    EppPeriod period = null;

    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
      Node node = list.item(i);
      String name = node.getLocalName();
      if (name == null) {
        continue;
      }
      if (name.equals("iname")) {
        iname = EppUtil.getText(node);
      } else if (name.equals("curExpDate")) {
        curExpDate = EppUtil.getDate(node, true);
      } else if (name.equals("period")) {
        period = (EppPeriod) EppPeriod.fromXML(node);
      }
    }
    if (iname != null) {
      cmd = new EppCommandRenewXriName(iname, curExpDate, period, null);
    }

    return cmd;
  }
  private static Command parseCommand(Node n) {
    NamedNodeMap atts = n.getAttributes();
    String name = atts.getNamedItem("name").getNodeValue();
    String desc = atts.getNamedItem("description").getNodeValue();
    String command = atts.getNamedItem("command").getNodeValue();

    Command com = new Command(name, desc, command);

    NodeList children = n.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);

      if (!child.getNodeName().equals("Argument")) continue;

      NamedNodeMap childAtts = child.getAttributes();
      String childName = childAtts.getNamedItem("name").getNodeValue();
      String childDesc = childAtts.getNamedItem("description").getNodeValue();
      String childVal = "";
      if (childAtts.getNamedItem("default") != null)
        childVal = childAtts.getNamedItem("default").getNodeValue();

      Argument arg = new Argument(childName, childDesc, childVal);

      com.addArgument(arg);
    }

    return com;
  }
Example #14
0
 public static final Map parseFrame(Node node) {
   NodeList bones = node.getChildNodes();
   Map bone_infos = new HashMap();
   for (int i = 0; i < bones.getLength(); i++) {
     Node bone = bones.item(i);
     if (bone.getNodeName().equals("transform")) {
       String name = bone.getAttributes().getNamedItem("name").getNodeValue();
       float[] matrix = new float[16];
       matrix[0 * 4 + 0] = getAttrFloat(bone, "m00");
       matrix[0 * 4 + 1] = getAttrFloat(bone, "m01");
       matrix[0 * 4 + 2] = getAttrFloat(bone, "m02");
       matrix[0 * 4 + 3] = getAttrFloat(bone, "m03");
       matrix[1 * 4 + 0] = getAttrFloat(bone, "m10");
       matrix[1 * 4 + 1] = getAttrFloat(bone, "m11");
       matrix[1 * 4 + 2] = getAttrFloat(bone, "m12");
       matrix[1 * 4 + 3] = getAttrFloat(bone, "m13");
       matrix[2 * 4 + 0] = getAttrFloat(bone, "m20");
       matrix[2 * 4 + 1] = getAttrFloat(bone, "m21");
       matrix[2 * 4 + 2] = getAttrFloat(bone, "m22");
       matrix[2 * 4 + 3] = getAttrFloat(bone, "m23");
       matrix[3 * 4 + 0] = getAttrFloat(bone, "m30");
       matrix[3 * 4 + 1] = getAttrFloat(bone, "m31");
       matrix[3 * 4 + 2] = getAttrFloat(bone, "m32");
       matrix[3 * 4 + 3] = getAttrFloat(bone, "m33");
       bone_infos.put(name, matrix);
     }
   }
   return bone_infos;
 }
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
Example #16
0
  private Node[] processIndexNode(
      final Node theNode,
      final Document theTargetDocument,
      final IndexEntryFoundListener theIndexEntryFoundListener) {
    theNode.normalize();

    boolean ditastyle = false;
    String textNode = null;

    final NodeList childNodes = theNode.getChildNodes();
    final StringBuilder textBuf = new StringBuilder();
    final List<Node> contents = new ArrayList<Node>();
    for (int i = 0; i < childNodes.getLength(); i++) {
      final Node child = childNodes.item(i);
      if (checkElementName(child)) {
        ditastyle = true;
        break;
      } else if (child.getNodeType() == Node.ELEMENT_NODE) {
        textBuf.append(XMLUtils.getStringValue((Element) child));
        contents.add(child);
      } else if (child.getNodeType() == Node.TEXT_NODE) {
        textBuf.append(child.getNodeValue());
        contents.add(child);
      }
    }
    textNode = IndexStringProcessor.normalizeTextValue(textBuf.toString());
    if (textNode.length() == 0) {
      textNode = null;
    }

    if (theNode.getAttributes().getNamedItem(elIndexRangeStartName) != null
        || theNode.getAttributes().getNamedItem(elIndexRangeEndName) != null) {
      ditastyle = true;
    }

    final ArrayList<Node> res = new ArrayList<Node>();
    if ((ditastyle)) {
      final IndexEntry[] indexEntries = indexDitaProcessor.processIndexDitaNode(theNode, "");

      for (final IndexEntry indexEntrie : indexEntries) {
        theIndexEntryFoundListener.foundEntry(indexEntrie);
      }

      final Node[] nodes = transformToNodes(indexEntries, theTargetDocument, null);
      for (final Node node : nodes) {
        res.add(node);
      }

    } else if (textNode != null) {
      final Node[] nodes =
          processIndexString(textNode, contents, theTargetDocument, theIndexEntryFoundListener);
      for (final Node node : nodes) {
        res.add(node);
      }
    } else {
      return new Node[0];
    }

    return (Node[]) res.toArray(new Node[res.size()]);
  }
Example #17
0
 public static String text(NodeList nodeList) {
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < nodeList.getLength(); i++) {
     sb.append(text(nodeList.item(i)));
   }
   return sb.toString();
 }
Example #18
0
  private static SetInfo parseSet(Node parent) throws XmlParserException {
    String id = "";
    String type = "";
    String measurementids = null;

    NodeList nodes = parent.getChildNodes();
    Vector<SetInfo> sets = new Vector<SetInfo>();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("set")) sets.add(parseSet(element));
      else if (element.getTagName().equals("type")) type = element.getTextContent();
      else if (element.getTagName().equals("measurementids"))
        measurementids = element.getTextContent();
    }

    // create the set
    SetInfo set = new SetInfo(id, Integer.parseInt(type));
    if (measurementids != null) {
      int mids[] = ByteArray.toIntArray(Base64.decode(measurementids), ByteArray.ENDIAN_LITTLE, 32);
      for (int mid : mids) set.addMeasurementID(mid);
    }

    // add the children
    for (SetInfo s : sets) set.addChild(s);

    return set;
  }
Example #19
0
  private static Header parseHeader(Node parent) throws XmlParserException {
    Header header = new Header();

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      try {
        if (element.getTagName().equals("nrpeaks"))
          header.setNrPeaks(Integer.parseInt(element.getTextContent()));
        else if (element.getTagName().equals("date")) header.setDate(element.getTextContent());
        else if (element.getTagName().equals("owner")) header.setOwner(element.getTextContent());
        else if (element.getTagName().equals("description"))
          header.setDescription(element.getTextContent());
        else if (element.getTagName().equals("sets")) header.addSetInfos(parseSets(element));
        else if (element.getTagName().equals("measurements"))
          header.addMeasurementInfos(parseMeasurements(element));
        else if (element.getTagName().equals("annotations")) {
          Vector<Annotation> annotations = parseAnnotations(element);
          if (annotations != null)
            for (Annotation annotation : annotations) header.addAnnotation(annotation);
        }
      } catch (Exception e) {
        throw new XmlParserException(
            "Invalid value in header (" + element.getTagName() + "): '" + e.getMessage() + "'.");
      }
    }

    return header;
  }
Example #20
0
 public static void traverseAMLforObjectNames(
     HashMap partialMap, Node currentNode, HashMap ObjDef_LinkId, HashMap ModelId_ModelType) {
   if (currentNode.hasChildNodes()) {
     for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) {
       Node currentChild = currentNode.getChildNodes().item(i);
       if (currentChild.getNodeName().equals("Group")) {
         traverseAMLforObjectNames(partialMap, currentChild, ObjDef_LinkId, ModelId_ModelType);
       }
       if (currentChild.getNodeName().equals("Model")) {
         if (currentChild.hasAttributes()) {
           String mid = currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue();
           String type = currentChild.getAttributes().getNamedItem("Model.Type").getNodeValue();
           ModelId_ModelType.put(mid, type);
         }
         // traverseAMLforObjectNames(partialMap, currentChild,
         // ObjDef_LinkId);
       }
       if (currentChild.getNodeName().equals("ObjDef")) {
         String id = currentChild.getAttributes().getNamedItem("ObjDef.ID").getNodeValue();
         NodeList currentChildren = currentChild.getChildNodes();
         String ObjName = "";
         for (int k = 0; k < currentChildren.getLength(); k++) {
           Node Child = currentChildren.item(k);
           if (!Child.getNodeName().equals("AttrDef")) {
             continue;
           } else if (!Child.getAttributes()
               .getNamedItem("AttrDef.Type")
               .getNodeValue()
               .equals("AT_NAME")) {
             continue;
           } else if (Child.hasChildNodes()) {
             for (int l = 0; l < Child.getChildNodes().getLength(); l++) {
               if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) {
                 continue;
               } else {
                 ObjName = getTextContent(Child.getChildNodes().item(l));
                 ObjName = ObjName.replaceAll("\n", "\\\\n");
                 break;
               }
             }
           }
         }
         partialMap.put(id, ObjName);
         for (int j = 0; j < currentChild.getAttributes().getLength(); j++) {
           if (currentChild.getAttributes().item(j).getNodeName().equals("LinkedModels.IdRefs")) {
             String links =
                 currentChild.getAttributes().getNamedItem("LinkedModels.IdRefs").getNodeValue();
             /*
              * if (links.indexOf(" ") > -1) {
              * Message.add("yes, yes, yes"); links =
              * links.substring(0, links.indexOf(" ")); }
              */
             ObjDef_LinkId.put(id, links);
           }
         }
       }
     }
   }
 }
 private Element getElement(String eltName) {
   NodeList nodeList = docElt.getElementsByTagName(eltName);
   if (nodeList.getLength() != 0) {
     Node node = nodeList.item(0);
     if (node instanceof Element) return (Element) node;
   }
   return null;
 }
Example #22
0
  public static void removeTextNodes(Node node) {
    NodeList nl = node.getChildNodes();

    int i = 0;
    while (i < nl.getLength())
      if (nl.item(i).getNodeType() == Node.TEXT_NODE) node.removeChild(nl.item(i));
      else i++;
  }
Example #23
0
 private static List<Node> childNodes(Node parent) {
   ArrayList<Node> childNodes = new ArrayList<Node>();
   NodeList children = parent.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     childNodes.add(children.item(i));
   }
   return childNodes;
 }
Example #24
0
  public static void removeNodesByName(Node node, String name) {
    NodeList nl = node.getChildNodes();

    int i = 0;
    while (i < nl.getLength())
      if (nl.item(i).getNodeName().equals(name)) node.removeChild(nl.item(i));
      else i++;
  }
Example #25
0
 public static String[] allTextFromImmediateChildElements(
     Element parent, String tagName, boolean trim) throws DOMException {
   NodeList nl = immediateChildElementsByTagName(parent, tagName);
   int len = nl.getLength();
   String[] out = new String[len];
   for (int i = 0; i < len; ++i) out[i] = allText((Element) nl.item(i), trim);
   return out;
 }
Example #26
0
 public int getLength() {
   int length = 0;
   for (int i = 0; i < nodeLists.size(); i++) {
     NodeList nl = (NodeList) nodeLists.get(i);
     length += nl.getLength();
   }
   return length;
 }
Example #27
0
  public static Collection<Node> getNodesByName(Node node, String name) {
    Collection<Node> list = new LinkedList<Node>();

    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
      if (nl.item(i).getNodeName().equals(name)) list.add(nl.item(i));

    return list;
  }
Example #28
0
  public static Collection<Node> getChildNodes(Node node) {
    Collection<Node> list = new LinkedList<Node>();

    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
      if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) list.add(nl.item(i));

    return list;
  }
Example #29
0
 private void removeNodes(NodeList nl) {
   int count = nl.getLength();
   for (int i = 0; i < count; i++) {
     Node node = nl.item(i);
     Node parent = node.getParentNode();
     if (parent == null) continue;
     parent.removeChild(node);
   }
 }
Example #30
0
 public static NodeList breadthFirst(Element self) {
   List result = new ArrayList();
   NodeList thisLevel = createNodeList(self);
   while (thisLevel.getLength() > 0) {
     result.add(thisLevel);
     thisLevel = getNextLevel(thisLevel);
   }
   return new NodeListsHolder(result);
 }