コード例 #1
0
ファイル: CopyTest.java プロジェクト: malajichuan/dom4j
  protected void testCopy(Element element) throws Exception {
    assertTrue("Not null", element != null);

    int attributeCount = element.attributeCount();
    int nodeCount = element.nodeCount();

    Element copy = element.createCopy();

    assertEquals("Node size not equal after copy", element.nodeCount(), nodeCount);
    assertTrue("Same attribute size after copy", element.attributeCount() == attributeCount);

    assertTrue("Copy has same node size", copy.nodeCount() == nodeCount);
    assertTrue("Copy has same attribute size", copy.attributeCount() == attributeCount);

    for (int i = 0; i < attributeCount; i++) {
      Attribute attr1 = element.attribute(i);
      Attribute attr2 = copy.attribute(i);

      assertTrue("Attribute: " + i + " name is equal", attr1.getName().equals(attr2.getName()));
      assertTrue("Attribute: " + i + " value is equal", attr1.getValue().equals(attr2.getValue()));
    }

    for (int i = 0; i < nodeCount; i++) {
      Node node1 = element.node(i);
      Node node2 = copy.node(i);

      assertTrue("Node: " + i + " type is equal", node1.getNodeType() == node2.getNodeType());
      assertTrue("Node: " + i + " value is equal", node1.getText().equals(node2.getText()));
    }
  }
コード例 #2
0
ファイル: XNode.java プロジェクト: fengshao0907/jdbc_shard
 private String getBodyData(Node child) {
   if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
     String data = ((CharacterData) child).getData();
     return data;
   }
   return null;
 }
コード例 #3
0
  /**
   * Constructor
   *
   * @param filename the XML config file
   */
  public LdapConfig(String filename) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = builder.parse(filename);

    // -- root element
    Node node = document.getFirstChild();
    while (node != null && node.getNodeType() != Node.ELEMENT_NODE) node = node.getNextSibling();

    if (node == null || !node.getNodeName().equals("ldap"))
      throw new Exception("root element is different from 'ldap'");

    this.ldapUrl = node.getAttributes().getNamedItem("url").getNodeValue();

    node = node.getFirstChild();
    while (node != null) {
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getNodeName().equals("authentication")) handleAuthentication(node);
        else if (node.getNodeName().equals("plugins")) handlePlugins(node);
        else if (node.getNodeName().equals("services")) handleServices(node);
        else if (node.getNodeName().equals("users")) handleUsers(node);
        else if (node.getNodeName().equals("groups")) handleGroups(node);
        else Logging.getLogger().warning("unexepected node : " + node.getNodeName());
      }
      node = node.getNextSibling();
    }
  }
コード例 #4
0
ファイル: PeakMLParser.java プロジェクト: joewandy/HDP-Align
  private static IPeakSet<? extends IPeak> parsePeakSet(Node parent) throws XmlParserException {
    // retrieve all the properties
    Vector<IPeak> peaks = new Vector<IPeak>();

    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("peaks")) {
        NodeList nodes2 = node.getChildNodes();
        for (int nodeid2 = 0; nodeid2 < nodes2.getLength(); ++nodeid2) {
          Node node2 = nodes2.item(nodeid2);
          if (node2.getNodeType() != Node.ELEMENT_NODE) continue;

          IPeak peak = parseIPeak(node2);
          if (peak != null) peaks.add(peak);
        }
      }
    }

    // create the bugger
    IPeakSet<IPeak> peakset = new IPeakSet<IPeak>(peaks);
    parseIPeak(parent, peakset);
    return peakset;
  }
コード例 #5
0
  public static void vol(int issue_length, NodeList issue_node) {
    for (int i = 0; i < issue_length; i++) {
      Node nnode = issue_node.item(i);
      if (nnode.getNodeType() == Element.ELEMENT_NODE) {
        Element enode = (Element) nnode;

        NodeList article_node = enode.getElementsByTagName("article");
        int article_length = enode.getElementsByTagName("article").getLength();

        for (int j = 0; j < article_length; j++) {
          Node m = article_node.item(j);
          if (m.getNodeType() == Element.ELEMENT_NODE) {
            Element f = (Element) m;
            String title = f.getElementsByTagName("title").item(0).getTextContent();
            // System.out.println(title);
            if (title.equals("Research in Knowledge Base Management Systems.")) {
              // String article = f.getElementsByTagName("title").item(0).getTextContent();
              String endPage = f.getElementsByTagName("endPage").item(0).getTextContent();
              String initPage = f.getElementsByTagName("initPage").item(0).getTextContent();
              String vol_element = enode.getElementsByTagName("volume").item(0).getTextContent();
              String num_element = enode.getElementsByTagName("number").item(0).getTextContent();
              // System.out.println("Title: "+ title);
              System.out.println("Volume: " + vol_element);
              System.out.println("Number: " + num_element);
              System.out.println("Init Page: " + initPage);
              System.out.println("End Page: " + endPage);
            }
          }
        }
      }
    }
  }
コード例 #6
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()]);
  }
コード例 #7
0
  /**
   * Method getStrFromNode
   *
   * @param xpathnode
   * @return the string for the node.
   */
  public static String getStrFromNode(Node xpathnode) {

    if (xpathnode.getNodeType() == Node.TEXT_NODE) {

      // we iterate over all siblings of the context node because eventually,
      // the text is "polluted" with pi's or comments
      StringBuffer sb = new StringBuffer();

      for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
          currentSibling != null;
          currentSibling = currentSibling.getNextSibling()) {
        if (currentSibling.getNodeType() == Node.TEXT_NODE) {
          sb.append(((Text) currentSibling).getData());
        }
      }

      return sb.toString();
    } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
      return ((Attr) xpathnode).getNodeValue();
    } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
      return ((ProcessingInstruction) xpathnode).getNodeValue();
    }

    return null;
  }
コード例 #8
0
ファイル: XNode.java プロジェクト: TuWei1992/zswxsqxt
 private String getBodyData(Node child) {
   if (child.getNodeType() == Node.CDATA_SECTION_NODE || child.getNodeType() == Node.TEXT_NODE) {
     String data = ((CharacterData) child).getData();
     data = PropertyParser.parse(data, variables);
     return data;
   }
   return null;
 }
コード例 #9
0
 /**
  * parse plants.xml to get all plants information
  *
  * @param root
  * @return
  */
 public static ArrayList<Plants> getPlant(Node root) {
   ArrayList<Plants> p = new ArrayList<Plants>();
   String code = null;
   String common = null;
   String botanical = null;
   String light = null;
   String zone = null;
   String price = null;
   String available = null;
   root.getChildNodes();
   for (int i = 0; i < root.getChildNodes().getLength(); i++) {
     Node state = root.getChildNodes().item(i);
     if (state.getNodeType() == Node.ELEMENT_NODE) {
       code = state.getAttributes().getNamedItem("code").getNodeValue();
       NodeList plantNodes = state.getChildNodes();
       for (int j = 0; j < plantNodes.getLength(); j++) {
         Node plant = plantNodes.item(j);
         if (plant.getNodeType() == Node.ELEMENT_NODE) {
           // get the pointer point to the node list of plant
           NodeList plantChildren = plant.getChildNodes();
           int m = 0;
           for (int k = 0; k < plantChildren.getLength(); k++) {
             if (plantChildren.item(k).getNodeType() == Node.ELEMENT_NODE) {
               m++;
               NodeList textNodes = plantChildren.item(k).getChildNodes();
               for (int n = 0; n < textNodes.getLength(); n++) {
                 if (textNodes.item(n).getNodeType() == Node.TEXT_NODE) {
                   switch (m) {
                     case 1:
                       common = textNodes.item(n).getNodeValue();
                       break;
                     case 2:
                       botanical = textNodes.item(n).getNodeValue();
                       break;
                     case 3:
                       zone = textNodes.item(n).getNodeValue();
                       break;
                     case 4:
                       light = textNodes.item(n).getNodeValue();
                       break;
                     case 5:
                       price = textNodes.item(n).getNodeValue().substring(1);
                       break;
                     case 6:
                       available = textNodes.item(n).getNodeValue();
                       break;
                   }
                 }
               }
             }
           }
           p.add(new Plants(code, common, botanical, zone, light, price, available));
         }
       }
     }
   }
   return p;
 }
コード例 #10
0
  public static void main(String[] args) {
    System.out.println("--------Part 1-------------------------------");
    Document xmlDoc = getDocument("SigmodRecord.xml");
    int issue_length = xmlDoc.getElementsByTagName("issue").getLength();
    NodeList issue_node = xmlDoc.getElementsByTagName("issue");

    for (int i = 0; i < issue_length; i++) {
      Node nnode = issue_node.item(i);
      if (nnode.getNodeType() == Element.ELEMENT_NODE) {
        Element enode = (Element) nnode;
        String vol_element = enode.getElementsByTagName("volume").item(0).getTextContent();
        String num_element = enode.getElementsByTagName("number").item(0).getTextContent();
        if (vol_element.equals("13") && num_element.equals("4")) {
          NodeList article_node = xmlDoc.getElementsByTagName("article");
          int article_length = xmlDoc.getElementsByTagName("article").getLength();
          for (int j = 0; j < article_length; j++) {
            Node m = article_node.item(j);
            if (m.getNodeType() == Element.ELEMENT_NODE) {
              Element f = (Element) m;
              String auth = f.getElementsByTagName("author").item(0).getTextContent();
              if (auth.equals("David Maier")) {
                String title = f.getElementsByTagName("title").item(0).getTextContent();
                System.out.println("Title: " + title);
              }
            }
          }
        }
      }
    }
    // Part 2 of the Program (Print the author names off all articles whose title contains the word
    // "database" or "Database".)
    System.out.println("--------Part 2------------------------------- ");
    NodeList article_node = xmlDoc.getElementsByTagName("article");
    int article_length = xmlDoc.getElementsByTagName("article").getLength();
    for (int j = 0; j < article_length; j++) {
      Node m = article_node.item(j);
      if (m.getNodeType() == Element.ELEMENT_NODE) {
        Element f = (Element) m;
        String article = f.getElementsByTagName("title").item(0).getTextContent();
        if (article.contains("Database") || article.contains("database")) {
          int length = f.getElementsByTagName("author").getLength();
          for (int i = 0; i < length; i++) {
            String auth = f.getElementsByTagName("author").item(i).getTextContent();
            System.out.println("Author: " + auth);
          }
        }
      }
    }
    // Part 3 of the Program (Print the volume/number and the init/end pages of the article titled
    // "Research in Knowledge Base Management Systems.".)
    System.out.println("--------Part 3------------------------------- ");
    vol(issue_length, issue_node);
  }
コード例 #11
0
ファイル: Query.java プロジェクト: johnperry/MIRC2
 private void appendNodeText(StringBuffer sb, Node node) {
   if (node.getNodeType() == Node.TEXT_NODE) {
     sb.append(" " + node.getTextContent());
   } else if (node.getNodeType() == Node.ELEMENT_NODE) {
     if (!node.getNodeName().equals("pt-age")) {
       Node child = node.getFirstChild();
       while (child != null) {
         appendNodeText(sb, child);
         child = child.getNextSibling();
       }
     }
   }
 }
コード例 #12
0
ファイル: CalloutEmitter.java プロジェクト: charan5076/LDP
  /**
   * Examine the areaspec and determine the number and position of callouts.
   *
   * <p>The <code><a href="http://docbook.org/tdg/html/areaspec.html">areaspecNodeSet</a></code> is
   * examined and a sorted list of the callouts is constructed.
   *
   * <p>This data structure is used to augment the result tree fragment with callout bullets.
   *
   * @param areaspecNodeSet The source document &lt;areaspec&gt; element.
   */
  public void setupCallouts(NodeList areaspecNodeList) {
    callout = new Callout[10];
    calloutCount = 0;
    calloutPos = 0;
    lineNumber = 1;
    colNumber = 1;

    // First we walk through the areaspec to calculate the position
    // of the callouts
    //  <areaspec>
    //  <areaset id="ex.plco.const" coords="">
    //    <area id="ex.plco.c1" coords="4"/>
    //    <area id="ex.plco.c2" coords="8"/>
    //  </areaset>
    //  <area id="ex.plco.ret" coords="12"/>
    //  <area id="ex.plco.dest" coords="12"/>
    //  </areaspec>
    int pos = 0;
    int coNum = 0;
    boolean inAreaSet = false;
    Node areaspec = areaspecNodeList.item(0);
    NodeList children = areaspec.getChildNodes();

    for (int count = 0; count < children.getLength(); count++) {
      Node node = children.item(count);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getNodeName().equalsIgnoreCase("areaset")) {
          coNum++;
          NodeList areas = node.getChildNodes();
          for (int acount = 0; acount < areas.getLength(); acount++) {
            Node area = areas.item(acount);
            if (area.getNodeType() == Node.ELEMENT_NODE) {
              if (area.getNodeName().equalsIgnoreCase("area")) {
                addCallout(coNum, area, defaultColumn);
              } else {
                System.out.println("Unexpected element in areaset: " + area.getNodeName());
              }
            }
          }
        } else if (node.getNodeName().equalsIgnoreCase("area")) {
          coNum++;
          addCallout(coNum, node, defaultColumn);
        } else {
          System.out.println("Unexpected element in areaspec: " + node.getNodeName());
        }
      }
    }

    // Now sort them
    java.util.Arrays.sort(callout, 0, calloutCount);
  }
コード例 #13
0
ファイル: SaxonEngine.java プロジェクト: mleegwt/jlibs
  @Override
  public boolean equals(Object node1, Node node2) {
    if (node1 == node2) return true;
    NodeInfo n1 = (NodeInfo) node1;
    Node n2 = node2;

    while (true) {
      if (!shallowEquals(n1, n2)) return false;
      if (n1 == null) {
        assert n2 == null;
        return true;
      }
      NodeInfo n1Child = new NodeInfoSequence(n1, Axis.CHILD).findNext();
      Node n2Child = null;
      if (n2.getNodeType() == Node.DOCUMENT_NODE || n2.getNodeType() == Node.ELEMENT_NODE)
        n2Child = n2.getFirstChild(); // the jdk's dom impl returns non-null child for attribute etc
      if (!shallowEquals(n1Child, n2Child)) return false;
      if (n1Child == null) {
        assert n2Child == null;

        if (n1 == node1 && n2 == node2) return true;

        while (true) {
          NodeInfo n1Sibling = new NodeInfoSequence(n1, Axis.FOLLOWING_SIBLING).findNext();
          Node n2Sibling = n2.getNextSibling();
          if (!shallowEquals(n1Sibling, n2Sibling)) return false;
          if (n1Sibling == null) {
            assert n2Sibling == null;
            NodeInfo n1Parent = new NodeInfoSequence(n1, Axis.ANCESTOR).findNext();
            Node n2Parent = n2.getParentNode();

            if (n1Parent == null && n2Parent == null) return true;
            if (n1Parent == node1 && n2Parent == node2) return true;
            assert n1Parent != null && n2Parent != null;
            n1 = n1Parent;
            n2 = n2Parent;
          } else {
            assert n2Sibling != null;
            n1 = n1Sibling;
            n2 = n2Sibling;
            break;
          }
        }
      } else {
        n1 = n1Child;
        n2 = n2Child;
      }
    }
  }
コード例 #14
0
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    Document doc;
    NodeList elementList;
    Node employeeNode;
    Node childNode;
    NodeList childNodes;
    int nodeType;
    String childName;
    java.util.List actual = new java.util.ArrayList();

    java.util.List expected = new java.util.ArrayList();
    expected.add("em");
    expected.add("strong");
    expected.add("code");
    expected.add("sup");
    expected.add("var");
    expected.add("acronym");

    doc = (Document) load("hc_staff", false);
    elementList = doc.getElementsByTagName("p");
    employeeNode = elementList.item(1);
    childNodes = employeeNode.getChildNodes();
    for (int indexN1006C = 0; indexN1006C < childNodes.getLength(); indexN1006C++) {
      childNode = (Node) childNodes.item(indexN1006C);
      nodeType = (int) childNode.getNodeType();
      childName = childNode.getNodeName();

      if (equals(1, nodeType)) {
        actual.add(childName);
      } else {
        assertEquals("textNodeType", 3, nodeType);
      }
    }
    assertEqualsAutoCase("element", "elementNames", expected, actual);
  }
コード例 #15
0
  private void initAllowedHosts(Document pDoc) {
    NodeList nodes = pDoc.getElementsByTagName("remote");
    if (nodes.getLength() == 0) {
      // No restrictions found
      allowedHostsSet = null;
      return;
    }

    allowedHostsSet = new HashSet<String>();
    for (int i = 0; i < nodes.getLength(); i++) {
      Node node = nodes.item(i);
      NodeList childs = node.getChildNodes();
      for (int j = 0; j < childs.getLength(); j++) {
        Node hostNode = childs.item(j);
        if (hostNode.getNodeType() != Node.ELEMENT_NODE) {
          continue;
        }
        assertNodeName(hostNode, "host");
        String host = hostNode.getTextContent().trim().toLowerCase();
        if (SUBNET_PATTERN.matcher(host).matches()) {
          if (allowedSubnetsSet == null) {
            allowedSubnetsSet = new HashSet<String>();
          }
          allowedSubnetsSet.add(host);
        } else {
          allowedHostsSet.add(host);
        }
      }
    }
  }
コード例 #16
0
ファイル: PeakMLParser.java プロジェクト: joewandy/HDP-Align
  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;
  }
コード例 #17
0
  private void gatherNamespaces(Element element, List<URI> namespaceSources) throws SAXException {
    NamedNodeMap attributes = element.getAttributes();
    int attributeCount = attributes.getLength();

    for (int i = 0; i < attributeCount; i++) {
      Attr attribute = (Attr) attributes.item(i);
      String namespace = attribute.getNamespaceURI();

      if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace)) {
        try {
          namespaceSources.add(new URI(attribute.getValue()));
        } catch (URISyntaxException e) {
          throw new SAXException(
              "Cannot validate this document with this class.  Namespaces must be valid URIs.  Found Namespace: '"
                  + attribute.getValue()
                  + "'.",
              e);
        }
      }
    }

    NodeList childNodes = element.getChildNodes();
    int childCount = childNodes.getLength();
    for (int i = 0; i < childCount; i++) {
      Node child = childNodes.item(i);

      if (child.getNodeType() == Node.ELEMENT_NODE) {
        gatherNamespaces((Element) child, namespaceSources);
      }
    }
  }
コード例 #18
0
ファイル: TestMimbuild3.java プロジェクト: jdramsey/tetrad
  private Graph changeLatentNames(Graph full, Clusters measurements, List<String> latentVarList) {
    Graph g2 = null;

    try {
      g2 = (Graph) new MarshalledObject(full).get();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    for (int i = 0; i < measurements.getNumClusters(); i++) {
      List<String> d = measurements.getCluster(i);
      String latentName = latentVarList.get(i);

      for (Node node : full.getNodes()) {
        if (!(node.getNodeType() == NodeType.LATENT)) {
          continue;
        }

        List<Node> _children = full.getChildren(node);

        _children.removeAll(ReidentifyVariables.getLatents(full));

        List<String> childNames = getNames(_children);

        if (new HashSet<String>(childNames).equals(new HashSet<String>(d))) {
          g2.getNode(node.getName()).setName(latentName);
        }
      }
    }

    return g2;
  }
コード例 #19
0
ファイル: PeakMLParser.java プロジェクト: joewandy/HDP-Align
  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;
  }
コード例 #20
0
ファイル: TimeLagGraph.java プロジェクト: renjiey/tetrad
  /** Nodes may be added into the getModel time step only. That is, node.getLag() must be 0. */
  public boolean addNode(Node node) {

    NodeId id = getNodeId(node);

    if (id.getLag() != 0) {
      node = node.like(id.getName());
      //            throw new IllegalArgumentException("Nodes may be added into the getModel time
      // step only.");
    }

    boolean added = getGraph().addNode(node);

    if (!lag0Nodes.contains(node)) {
      lag0Nodes.add(node);
    }

    if (node.getNodeType() == NodeType.ERROR) {
      for (int i = 1; i <= getMaxLag(); i++) {
        Node node1 = node.like(id.getName() + ":" + i);

        if (i < getNumInitialLags()) {
          getGraph().addNode(node1);
        }
      }
    } else {
      for (int i = 1; i <= getMaxLag(); i++) {
        Node node1 = node.like(id.getName() + ":" + i);
        getGraph().addNode(node1);
      }
    }

    getPcs().firePropertyChange("editingFinished", null, null);

    return added;
  }
コード例 #21
0
  // Lee la configuracion que se encuentra en conf/RegistryConf
  private void readConfXml() {
    try {
      File inputFile = new File("src/java/Conf/RegistryConf.xml");
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(inputFile);
      doc.getDocumentElement().normalize();
      NodeList nList = doc.getElementsByTagName("RegistryConf");
      for (int i = 0; i < nList.getLength(); i++) {
        Node nNode = nList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
          Element eElement = (Element) nNode;
          RegistryConf reg = new RegistryConf();
          String aux;
          int idSensor;
          int value;
          aux = eElement.getElementsByTagName("idSensor").item(0).getTextContent();
          idSensor = Integer.parseInt(aux);
          reg.setIdSensor(idSensor);

          aux = eElement.getElementsByTagName("saveType").item(0).getTextContent();
          reg.setSaveTypeString(aux);

          aux = eElement.getElementsByTagName("value").item(0).getTextContent();
          value = Integer.parseInt(aux);
          reg.setValue(value);

          registryConf.add(reg);
          lastRead.put(idSensor, 0);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #22
0
 /*
  * If the element contains an attribute 'makeOnly' with a value of 'true',
  * create a child element before any existing children which will display a node
  * which will display only the elements records.
  * Compute the query attribute, which is the appended result of all of the children
  * appended to this element name. If noQuery=true. then do not generate a query term
  * for this element.
  */
 String computeQuery(Element e) {
   String query = "";
   if (!(e.getAttribute("noQuery").equalsIgnoreCase("true"))) {
     query = e.getAttribute("name");
   }
   String makeOnly = e.getAttribute("makeOnly");
   boolean madeOnly = false;
   NodeList children = e.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     Node child = children.item(i);
     if (child.getNodeType() == Node.ELEMENT_NODE) {
       if (makeOnly.equalsIgnoreCase("true") && !madeOnly) {
         // need to make an ...-Only node and populate it
         String onlyTagName = e.getTagName() + "-Only";
         Element only = ((Document) dom.getNode()).createElement(onlyTagName);
         only.setAttribute("name", e.getAttribute("name") + "-Only");
         only.setAttribute("query", e.getAttribute("name"));
         e.insertBefore(only, child);
         i++;
         madeOnly = true;
       }
       if (query.length() > 0) {
         query += ",";
       }
       query += computeQuery((Element) child);
     }
   }
   log.info("setting query for " + e.getNodeName() + "   " + query);
   e.setAttribute("query", query);
   return query;
 }
コード例 #23
0
ファイル: Game.java プロジェクト: rpdai/paris
  public void statusReport(PrintWriter writer) {

    // Game has ended and graph shut down
    if (gameOverRequest != null) {
      if (gameStartRequest != null) {
        writer.print("[GAME START]: " + gameStartRequest + "\n");
      }

      for (GameRequest request : turnRequests) {
        writer.print("[TURN " + request.getCurrentTurn() + "]: " + request.getStates() + "\n");
      }
      writer.print("[GAME OVER]: " + gameOverRequest.getStates() + "\n");
    } else {
      for (Node node : gameState.getNodesSortedById()) {
        writer.print("Node " + node.getNodeId() + "\n");
        writer.print("  type: " + node.getNodeType() + "\n");
        writer.print("  vp worth: " + node.getVictoryPointWorth() + "\n");
        writer.print("  solders per turn: " + node.getSoldiersGrantedPerTurn() + "\n");
        writer.print("  owner: " + node.getOwner() + "\n");
        writer.print("  soldiers present: " + node.getNumberOfSolders() + "\n");
        writer.print("  inbound neighbouring nodes:  ");
        for (Node neighbour : node.getInboundNeighbours()) {
          writer.print(neighbour.getNodeId() + " ");
        }
        writer.print("\n");
        writer.print("  outbound neighbouring nodes: ");
        for (Node neighbour : node.getOutboundNeighbours()) {
          writer.print(neighbour.getNodeId() + " ");
        }
        writer.print("\n");
      }
    }
  }
コード例 #24
0
 private void buildHierarchyDOM() {
   TransformerFactory factory = TransformerFactory.newInstance();
   StreamSource src =
       new StreamSource(
           this.getServletContext()
               .getResourceAsStream("/WEB-INF/classes/gpt/search/browse/ownerHierarchy.xml"));
   log.info("initializing src from stream " + src);
   try {
     Transformer t = factory.newTransformer();
     dom = new DOMResult();
     t.transform(src, dom);
     // now go thru tree, setting up the query attribute for each node
     Node tree = dom.getNode();
     NodeList children = tree.getChildNodes();
     log.info("dom tree contains " + children.getLength() + " nodes");
     for (int i = 0; i < children.getLength(); i++) {
       Node child = children.item(i);
       if (child.getNodeType() == Node.ELEMENT_NODE) {
         Element e = (Element) child;
         String query = computeQuery(e);
         e.setAttribute("query", query);
       }
     }
   } catch (Exception e) {
     log.severe("Could not init ownerHierarchy because exception thrown:");
     StringWriter sw = new StringWriter();
     e.printStackTrace(new PrintWriter(sw));
     log.severe(sw.toString());
   }
 }
コード例 #25
0
  /*
   * Output this item. Then, if the element has child elements, output each.
   */
  private void outputItem(Element e, PrintWriter out) {
    int chk = 0;
    HashMap collection = new HashMap();
    String key = null;
    Element collectionElement = null;
    log.fine("outputing item for " + e.getAttribute("name") + ":   " + e.getAttribute("query"));
    out.println("<item>");
    out.println("<name>" + e.getAttribute("name") + "</name>");
    if (e.getTagName().equalsIgnoreCase("collection")) {

      // change made by NETTY (change collectionlist to collection)
      out.println(
          "<query>collection="
              + e.getAttribute("col_id")
              + "&amp;xsl=metadata_to_html_full</query>");
    } else {
      out.println(
          "<query>owner=" + e.getAttribute("query") + "&amp;xsl=metadata_to_html_full</query>");
    }
    // now output children

    NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        chk++;
        outputItem((Element) child, out);
      }
    }

    out.println("</item>");
  }
コード例 #26
0
ファイル: PeakMLParser.java プロジェクト: joewandy/HDP-Align
  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;
  }
コード例 #27
0
 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);
 }
コード例 #28
0
ファイル: DomParser.java プロジェクト: nickitalebed1/mydemo
 private void removeEvenNodes(Node node) {
   boolean toDelete = false;
   NodeList childNodesList = node.getChildNodes();
   for (int i = 0; i < node.getChildNodes().getLength(); i++) {
     Node child = childNodesList.item(i);
     if (toDelete && child.getNodeType() == Node.ELEMENT_NODE) {
       node.removeChild(childNodesList.item(i));
       toDelete = false;
     } else {
       if (child.getNodeType() == Node.ELEMENT_NODE) {
         toDelete = true;
       }
     }
     removeEvenNodes(childNodesList.item(i));
   }
 }
コード例 #29
0
ファイル: XmlNodeUtil.java プロジェクト: hazendaz/beanio
  /**
   * Returns a sibling element that matches a given definition, or <tt>null</tt> if no match is
   * found.
   *
   * @param sibling the sibling DOM element to begin the search
   * @param target the node to search for
   * @return the matching element, or <tt>null</tt> if not found
   */
  public static Element findSibling(Element sibling, XmlNode target) {
    String xmlName = target.getLocalName();
    String xmlNamespace = target.getNamespace();

    Node node = sibling;
    if (node == null) {
      return null;
    }

    while ((node = node.getNextSibling()) != null) {
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element element = (Element) node;
      if (!element.getLocalName().equals(xmlName)) {
        continue;
      }
      if (target.isNamespaceAware()) {
        String ns = element.getNamespaceURI();
        if (ns == null) {
          if (xmlNamespace != null) {
            continue;
          }
        } else {
          if (!ns.equals(xmlNamespace)) {
            continue;
          }
        }
      }
      return element;
    }
    return null;
  }
コード例 #30
0
  public List<Customer> unmarshallCustomers(String fileStringPathname) {
    List<Customer> customerList = new ArrayList<Customer>();
    File docFile = new File(fileStringPathname);
    Document document = null;
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      dbf.setValidating(true);
      dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "customers.xsd");
      DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
      document = documentBuilder.parse(docFile);
    } catch (Exception e) {
      System.out.println(
          e
              .getMessage()); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    Element root = document.getDocumentElement();
    NodeList children = root.getChildNodes();
    Node node;
    for (int i = 0; i < children.getLength(); i++) {
      node = children.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        customerList.add(customerUnmarshaller(node));
      }
    }
    return customerList;
  }