예제 #1
0
 protected void load(Element root) throws Exception {
   NodeList list;
   int i;
   list = WSHelper.getElementChildren(root, "Messages");
   if (list != null) {
     for (i = 0; i < list.getLength(); i++) {
       Element nc = (Element) list.item(i);
       _Messages.addElement(JanusMessageInfo.loadFrom(nc));
     }
   }
   list = WSHelper.getElementChildren(root, "Rating");
   if (list != null) {
     for (i = 0; i < list.getLength(); i++) {
       Element nc = (Element) list.item(i);
       _Rating.addElement(JanusRatingInfo.loadFrom(nc));
     }
   }
   list = WSHelper.getElementChildren(root, "Moderate");
   if (list != null) {
     for (i = 0; i < list.getLength(); i++) {
       Element nc = (Element) list.item(i);
       _Moderate.addElement(JanusModerateInfo.loadFrom(nc));
     }
   }
 }
예제 #2
0
 private boolean existeAlbum(String titreAlbum, String nomArtiste, int anneeAlbum) {
   NodeList listeAlbums = document.getElementsByTagName("album");
   if (listeAlbums != null) {
     for (int i = 0; i < listeAlbums.getLength(); ++i) {
       String titre =
           ((Element) listeAlbums.item(i)).getElementsByTagName("titre").item(0).getTextContent();
       String artiste =
           ((Element) listeAlbums.item(i))
               .getElementsByTagName("artiste")
               .item(0)
               .getTextContent();
       int annee =
           Integer.parseInt(
               ((Element) listeAlbums.item(i))
                   .getElementsByTagName("annee")
                   .item(0)
                   .getTextContent());
       if (titre.equals(titreAlbum) && artiste.equals(nomArtiste) && annee == anneeAlbum)
         return true;
     }
   } else {
     return true;
   }
   return false;
 }
  private void addRunConfigurationFromXMLTree(Element treeTop, String runManagerName) {
    NodeList list = treeTop.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
      NamedNodeMap nodeMap = list.item(i).getAttributes();
      if (nodeMap != null && nodeMap.getNamedItem("name") != null) {
        if (!runManagerName.equals(nodeMap.getNamedItem("name").getNodeValue())) {
          continue;
        }
        NodeList configList = list.item(i).getChildNodes();
        for (int j = 0; j < configList.getLength(); j++) {
          NamedNodeMap configNodeMap = configList.item(j).getAttributes();
          if (configNodeMap != null
              && configNodeMap.getNamedItem("default") != null
              && configNodeMap.getNamedItem("default").getNodeValue() != null
              && configNodeMap.getNamedItem("default").getNodeValue().equals("false")) {
            try {
              runConfigurations.add(new ASIdeaRunConfiguration(configList.item(j)));
            } catch (ASExternalImporterException e) {
              // Ignore
            }
          }
        }
      }
    }
  }
예제 #4
0
 public void parseChildren(Element e) {
   try {
     NodeList nl = e.getChildNodes();
     for (int i = 0; i < nl.getLength(); i++) {
       // parse Elements only
       if ((nl.item(i).getNodeType() == Node.ELEMENT_NODE)) {
         Element elm = (Element) nl.item(i);
         String tag = elm.getTagName();
         if (tag.equals("canvas")) {
           parseChildren(elm);
         } else if (tag.equals("label")) {
           parseLabel(elm);
         } else if (tag.equals("textfield")) {
           parseTextField(elm);
         } else if (tag.equals("button")) {
           parseButton(elm);
         } else if (tag.equals("textarea")) {
           parseTextArea(elm);
         } else if (tag.equals("progressbar")) {
           parseProgressBar(elm);
         }
       }
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
예제 #5
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);
        }
      }
    }
  }
  /**
   * 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);
  }
  // factory
  private static GenerationTarget createTarget(File templateFile, File root) {
    GenerationTarget target;

    // read XML document
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
      Document doc = docBuilder.parse(templateFile);

      // get name
      NodeList nodes = doc.getElementsByTagName("templates");
      Node node = nodes.item(0);
      NamedNodeMap attrs = node.getAttributes();
      Node attr = attrs.getNamedItem("name");
      String templateName = attr.getNodeValue();
      target = new GenerationTarget(templateFile, root, templateName);

      // get class directives
      nodes = doc.getElementsByTagName("project");
      int nb = nodes.getLength();
      for (int i = 0; i < nb; i++) {
        node = nodes.item(i);
        createProjectDirective(target, node);
      }

    } catch (ParserConfigurationException ex) {
      target = null;
    } catch (IOException ex) {
      target = null;
    } catch (SAXException ex) {
      target = null;
    } // end try

    return target;
  }
예제 #8
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);
            }
          }
        }
      }
    }
  }
예제 #9
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};
  }
예제 #10
0
  /**
   * Pretty prints a node.
   *
   * @param doc The document the node comes from.
   * @param node The node that should be pretty printed.
   */
  public static void prettyPrint(Document doc, Node node) {
    // Get the text before the node and extract the indenting
    Node parent = node.getParentNode();

    String indenting = "";
    NodeList siblingList = parent.getChildNodes();
    for (int i = 1; i < siblingList.getLength(); i++) {
      Node sibling = siblingList.item(i);
      if (sibling == node) {
        Node nodeBefore = siblingList.item(i - 1);
        // Check whether this is a text node
        if (nodeBefore.getNodeName().equals("#text")) {
          // There is text before the node -> Extract the indenting
          String text = nodeBefore.getNodeValue();
          int newlinePos = text.lastIndexOf('\n');
          if (newlinePos != -1) {
            indenting = text.substring(newlinePos);
            if (indenting.trim().length() != 0) {
              // The indenting is no whitespace -> Forget it
              indenting = "";
            }
          }
        }
        break;
      }
    }

    // Now pretty print the node
    prettyPrint(doc, node, indenting);
  }
예제 #11
0
  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;
  }
예제 #12
0
파일: D4.java 프로젝트: sarekautowerke/D4
  public List parsePage(String pageCode) {
    List sections = new ArrayList();
    List folders = new ArrayList();
    List files = new ArrayList();
    int start = pageCode.indexOf("<div id=\"list-view\" class=\"view\"");
    int end = pageCode.indexOf("<div id=\"gallery-view\" class=\"view\"");
    String usefulSection = "";
    if (start != -1 && end != -1) {
      usefulSection = pageCode.substring(start, end);
    } else {
      debug("Could not parse page");
    }
    try {
      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      InputSource is = new InputSource();
      is.setCharacterStream(new StringReader(usefulSection));
      Document doc = db.parse(is);

      NodeList divs = doc.getElementsByTagName("div");
      for (int i = 0; i < divs.getLength(); i++) {
        Element div = (Element) divs.item(i);
        boolean isFolder = false;
        if (div.getAttribute("class").equals("filename")) {
          NodeList imgs = div.getElementsByTagName("img");
          for (int j = 0; j < imgs.getLength(); j++) {
            Element img = (Element) imgs.item(j);
            if (img.getAttribute("class").indexOf("folder") > 0) {
              isFolder = true;
            } else {
              isFolder = false; // it's a file
            }
          }

          NodeList anchors = div.getElementsByTagName("a");
          Element anchor = (Element) anchors.item(0);
          String attr = anchor.getAttribute("href");
          String fileName = anchor.getAttribute("title");
          String fileURL;
          if (isFolder && !attr.equals("#")) {
            folders.add(attr);
            folders.add(fileName);
          } else if (!isFolder && !attr.equals("#")) {
            // Dropbox uses ajax to get the file for download, so the url isn't enough. We must be
            // sneaky here.
            fileURL = "https://dl.dropbox.com" + attr.substring(23) + "?dl=1";
            files.add(fileURL);
            files.add(fileName);
          }
        }
      }
    } catch (Exception e) {
      debug(e.toString());
    }

    sections.add(files);
    sections.add(folders);

    return sections;
  }
예제 #13
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++;
  }
예제 #14
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++;
  }
 /**
  * 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;
 }
예제 #16
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;
  }
예제 #17
0
 public ResultValue(Node node) {
   NodeList list = node.getChildNodes();
   for (int i = 0; i < list.getLength(); i++) {
     Node n = list.item(i);
     if (n.getNodeName().equals("class")) {
       matlabClass = n.getTextContent();
     }
     if (n.getNodeName().equals("size")) {
       size = string2intList(n.getTextContent());
       numdims = size.size();
       numel = 1;
       for (int d : size) {
         numel *= d;
       }
     }
     if (n.getNodeName().equals("matrix")) {
       resultType = RESULT_TYPE.MATRIX;
       matrixResult = string2doubleList(n.getTextContent());
     }
     if (n.getNodeName().equals("imagMatrix")) {
       isReal = false;
       resultType = RESULT_TYPE.MATRIX;
       imagMatrixResult = string2doubleList(n.getTextContent());
     }
     if (n.getNodeName().equals("char")) {
       resultType = RESULT_TYPE.CHAR;
       charResult = n.getTextContent();
     }
     if (n.getNodeName().equals("logical")) {
       resultType = RESULT_TYPE.LOGICAL;
       logicalResult = string2booleanList(n.getTextContent());
     }
     if (n.getNodeName().equals("handle")) {
       resultType = RESULT_TYPE.HANDLE;
     }
     if (n.getNodeName().equals("struct")) {
       resultType = RESULT_TYPE.STRUCT;
       // create struct list for first occurence of struct
       if (structResult == null) {
         structResult = new ArrayList<HashMap<String, ResultValue>>();
       }
       // build struct
       HashMap<String, ResultValue> struct = new HashMap<String, ResultValue>();
       NodeList children = n.getChildNodes();
       for (int j = 0; j < children.getLength(); j++) {
         Node child = children.item(j);
         if (child.getNodeType() == Node.ELEMENT_NODE) {
           struct.put(child.getNodeName(), new ResultValue(child));
         }
       }
       structResult.add(struct);
     }
     if (n.getNodeName().equals("cell")) {
       resultType = RESULT_TYPE.CELL;
     }
   }
 }
예제 #18
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;
  }
예제 #19
0
  private void loadFromXml(String fileName)
      throws ParserConfigurationException, SAXException, IOException, ParseException {
    System.out.println("NeuralNetwork : loading network topology from file " + fileName);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document doc = parser.parse(fileName);

    Node nodeNeuralNetwork = doc.getDocumentElement();
    if (!nodeNeuralNetwork.getNodeName().equals("neuralNetwork"))
      throw new ParseException(
          "[Error] NN-Load: Parse error in XML file, neural network couldn't be loaded.", 0);
    // nodeNeuralNetwork ok
    // indexNeuralNetworkContent -> indexStructureContent -> indexLayerContent -> indexNeuronContent
    // -> indexNeuralInputContent
    NodeList nodeNeuralNetworkContent = nodeNeuralNetwork.getChildNodes();
    for (int innc = 0; innc < nodeNeuralNetworkContent.getLength(); innc++) {
      Node nodeStructure = nodeNeuralNetworkContent.item(innc);
      if (nodeStructure.getNodeName().equals("structure")) { // for structure element
        NodeList nodeStructureContent = nodeStructure.getChildNodes();
        for (int isc = 0; isc < nodeStructureContent.getLength(); isc++) {
          Node nodeLayer = nodeStructureContent.item(isc);
          if (nodeLayer.getNodeName().equals("layer")) { // for layer element
            NeuralLayer neuralLayer = new NeuralLayer(this);
            this.listLayers.add(neuralLayer);
            NodeList nodeLayerContent = nodeLayer.getChildNodes();
            for (int ilc = 0; ilc < nodeLayerContent.getLength(); ilc++) {
              Node nodeNeuron = nodeLayerContent.item(ilc);
              if (nodeNeuron.getNodeName().equals("neuron")) { // for neuron in layer
                Neuron neuron =
                    new Neuron(
                        Double.parseDouble(((Element) nodeNeuron).getAttribute("threshold")),
                        neuralLayer);
                neuralLayer.listNeurons.add(neuron);
                NodeList nodeNeuronContent = nodeNeuron.getChildNodes();
                for (int inc = 0; inc < nodeNeuronContent.getLength(); inc++) {
                  Node nodeNeuralInput = nodeNeuronContent.item(inc);
                  // if (nodeNeuralInput==null) System.out.print("-"); else System.out.print("*");

                  if (nodeNeuralInput.getNodeName().equals("input")) {
                    //                                        System.out.println("neuron at
                    // STR:"+innc+" LAY:"+isc+" NEU:"+ilc+" INP:"+inc);
                    NeuralInput neuralInput =
                        new NeuralInput(
                            Double.parseDouble(((Element) nodeNeuralInput).getAttribute("weight")),
                            neuron);
                    neuron.listInputs.add(neuralInput);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
예제 #20
0
  /**
   * Carries out preprocessing that makes JEuclid handle the document better.
   *
   * @param doc Document
   */
  static void preprocessForJEuclid(Document doc) {
    // underbrace and overbrace
    NodeList list = doc.getElementsByTagName("mo");
    for (int i = 0; i < list.getLength(); i++) {
      Element mo = (Element) list.item(i);
      String parentName = ((Element) mo.getParentNode()).getTagName();
      if (parentName == null) {
        continue;
      }
      if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) {
        mo.setAttribute("stretchy", "true");
        mo.removeChild(mo.getFirstChild());
        mo.appendChild(doc.createTextNode("\u23df"));
      } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) {
        mo.setAttribute("stretchy", "true");
        mo.removeChild(mo.getFirstChild());
        mo.appendChild(doc.createTextNode("\u23de"));
      }
    }

    // menclose for long division doesn't allow enough top padding. Oh, and
    // <mpadded> isn't implemented. And there isn't enough padding to left of
    // the bar either. Solve by adding an <mover> with just an <mspace> over#
    // the longdiv, contained within an mrow that adds a <mspace> before it.
    list = doc.getElementsByTagName("menclose");
    for (int i = 0; i < list.getLength(); i++) {
      Element menclose = (Element) list.item(i);
      // Only for longdiv
      if (!"longdiv".equals(menclose.getAttribute("notation"))) {
        continue;
      }
      Element mrow = doc.createElementNS(WebMathsService.NS, "mrow");
      Element mover = doc.createElementNS(WebMathsService.NS, "mover");
      Element mspace = doc.createElementNS(WebMathsService.NS, "mspace");
      Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace");
      boolean previousElement = false;
      for (Node previous = menclose.getPreviousSibling();
          previous != null;
          previous = previous.getPreviousSibling()) {
        if (previous.getNodeType() == Node.ELEMENT_NODE) {
          previousElement = true;
          break;
        }
      }
      if (previousElement) {
        mspaceW.setAttribute("width", "4px");
      }
      menclose.getParentNode().insertBefore(mrow, menclose);
      menclose.getParentNode().removeChild(menclose);
      mrow.appendChild(mspaceW);
      mrow.appendChild(mover);
      mover.appendChild(menclose);
      mover.appendChild(mspace);
    }
  }
예제 #21
0
  public void getClassName() {

    try {
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
      Document doc = docBuilder.parse(new File("src/resources/classdata.xml"));

      doc.getDocumentElement().normalize();

      NodeList listOfClasses = doc.getElementsByTagName("class");

      classes = new String[listOfClasses.getLength()];
      amountClasses = listOfClasses.getLength();
      String classID;
      String className;
      int classIDint;

      for (int s = 0; s < listOfClasses.getLength(); s++) {

        Node firstPersonNode = listOfClasses.item(s);
        if (firstPersonNode.getNodeType() == Node.ELEMENT_NODE) {

          Element firstClassElement = (Element) firstPersonNode;
          NodeList idList = firstClassElement.getElementsByTagName("id");
          Element idElement = (Element) idList.item(0);
          NodeList textLNList = idElement.getChildNodes();
          classID = ((Node) textLNList.item(0)).getNodeValue().trim();

          NodeList NameList = firstClassElement.getElementsByTagName("name");
          Element NameElement = (Element) NameList.item(0);
          NodeList textFNList = NameElement.getChildNodes();
          className = ((Node) textFNList.item(0)).getNodeValue().trim();
          classIDint = Integer.parseInt(classID);

          classes[classIDint] = className;
        } // end of if clause
      } // end of for loop with s var

    } catch (SAXParseException err) {
      System.out.println(
          "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
      System.out.println(" " + err.getMessage());

    } catch (SAXException e) {
      Exception x = e.getException();
      ((x == null) ? e : x).printStackTrace();

    } catch (Throwable t) {
      t.printStackTrace();
    }

    // System.exit (0);

  }
예제 #22
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);
  }
예제 #23
0
  /**
   * 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);
  }
예제 #24
0
  public apiParser(String sdkfile) {
    System.out.println(sdkfile);
    File file = new File(sdkfile);
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();

      Document doc = db.parse(file);
      NodeList apiList = doc.getElementsByTagName("n1:api");
      NodeList inputList = doc.getElementsByTagName("n1:input");
      NodeList typeList = doc.getElementsByTagName("n1:type");

      for (int i = 0; i < apiList.getLength(); i++) {
        Node api_node = apiList.item(i);
        String api_id = api_node.getAttributes().getNamedItem("id").getNodeValue();
        String api_name = api_node.getAttributes().getNamedItem("name").getNodeValue();
        String input_type_id =
            inputList.item(i).getAttributes().getNamedItem("type_ref").getNodeValue();

        // System.out.println(api_id + " : " + api_name + " : " + input_type_id);
        ArrayList<String> api_params = new ArrayList<String>();

        for (int j = 0; j < typeList.getLength(); j++) {

          if (input_type_id.equalsIgnoreCase(
              typeList.item(j).getAttributes().getNamedItem("id").getNodeValue())) {
            Element e1 = (Element) typeList.item(j);

            NodeList param_l = e1.getElementsByTagName("n1:param");

            for (int k = 0; k < param_l.getLength(); k++) {

              String param_name =
                  param_l.item(k).getAttributes().getNamedItem("name").getNodeValue();
              // String param_desc =
              // param_l.item(k).getAttributes().getNamedItem("desc").getNodeValue();
              api_params.add(param_name);
              // System.out.println(param_name +":"+param_desc);
            }

            break;
          }
        }
        apiRoom s_room = new apiRoom(api_id, api_name, api_params);
        apiRooms.add(s_room);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #25
0
  public static ArrayList<String> getFilterNames() {

    ArrayList<String> filters = new ArrayList<String>();

    try {

      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
      Document doc = docBuilder.parse(new File("filters.xml"));

      // normalize text representation
      doc.getDocumentElement().normalize();
      NodeList listOfPersons = doc.getElementsByTagName("filter");
      int totalPersons = listOfPersons.getLength();
      System.out.println("Total of filters : " + totalPersons);

      for (int s = 0; s < listOfPersons.getLength(); s++) {

        Node firstPersonNode = listOfPersons.item(s);
        if (firstPersonNode.getNodeType() == Node.ELEMENT_NODE) {

          Element firstPersonElement = (Element) firstPersonNode;

          // -------
          NodeList firstNameList = firstPersonElement.getElementsByTagName("name");
          Element firstNameElement = (Element) firstNameList.item(0);

          NodeList textFNList = firstNameElement.getChildNodes();

          System.out.println("Filter Name : " + ((Node) textFNList.item(0)).getNodeValue().trim());

          filters.add(((Node) textFNList.item(0)).getNodeValue().trim());
        } // end of if clause
      } // end of for loop with s var

    } catch (SAXParseException err) {
      System.out.println(
          "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
      System.out.println(" " + err.getMessage());

    } catch (SAXException e) {
      Exception x = e.getException();
      ((x == null) ? e : x).printStackTrace();

    } catch (Throwable t) {
      t.printStackTrace();
    }
    // System.exit (0);

    return filters;
  } // end of main
예제 #26
0
  /** @see com.levelonelabs.aim.XMLizable#readState(Element) */
  public void readState(Element fullStateElement) {
    // parse group
    String group = fullStateElement.getAttribute("group");
    if (group == null || group.trim().equals("")) {
      group = AIMSender.DEFAULT_GROUP;
    }
    setGroup(group);

    // parse banned
    String ban = fullStateElement.getAttribute("isBanned");
    if (ban.equalsIgnoreCase("true")) {
      setBanned(true);
    } else {
      setBanned(false);
    }

    // parse roles
    roles = new HashMap();
    NodeList list = fullStateElement.getElementsByTagName("role");
    for (int i = 0; i < list.getLength(); i++) {
      Element roleElem = (Element) list.item(i);
      String role = roleElem.getAttribute("name");
      addRole(role);
    }

    // parse messages
    messages = new ArrayList();
    list = fullStateElement.getElementsByTagName("message");
    for (int i = 0; i < list.getLength(); i++) {
      Element messElem = (Element) list.item(i);
      NodeList cdatas = messElem.getChildNodes();
      for (int j = 0; j < cdatas.getLength(); j++) {
        Node node = cdatas.item(j);
        if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
          String message = node.getNodeValue();
          addMessage(message);
          break;
        }
      }
    }

    // parse prefs
    preferences = new HashMap();
    list = fullStateElement.getElementsByTagName("preference");
    for (int i = 0; i < list.getLength(); i++) {
      Element prefElem = (Element) list.item(i);
      String pref = prefElem.getAttribute("name");
      String val = prefElem.getAttribute("value");
      this.setPreference(pref, val);
    }
  }
예제 #27
0
  public static Node getNodeByName(Node node, String name) {
    if (node == null) return null;

    NodeList nl = node.getChildNodes();

    Node n = null;
    int i = 0;
    while (n == null && i < nl.getLength()) {
      if (nl.item(i).getNodeName().equals(name)) n = nl.item(i);
      i++;
    }

    return n;
  }
예제 #28
0
  public Room buildRoom(Node n_in) {
    NodeList na = ((Element) n_in).getElementsByTagName("name");
    this.name = ((Element) na.item(0)).getTextContent();
    NodeList ty = ((Element) n_in).getElementsByTagName("type");
    this.type = ((Element) ty.item(0)).getTextContent();
    NodeList desc = ((Element) n_in).getElementsByTagName("description");
    this.description = ((Element) desc.item(0)).getTextContent();
    NodeList bord = ((Element) n_in).getElementsByTagName("border");
    for (int i = 0; i < bord.getLength(); i++) {
      this.border.add(new Border(((Element) bord.item(i))));
    }
    NodeList cont = ((Element) n_in).getElementsByTagName("container");
    for (int i = 0; i < cont.getLength(); i++) {
      this.containers.add(((Element) cont.item(i)).getTextContent());
    }
    NodeList it = ((Element) n_in).getElementsByTagName("item");
    for (int i = 0; i < it.getLength(); i++) {
      this.items.add(((Element) it.item(i)).getTextContent());
    }
    NodeList cr = ((Element) n_in).getElementsByTagName("creature");
    for (int i = 0; i < cr.getLength(); i++) {
      this.creatures.add(((Element) cr.item(i)).getTextContent());
    }
    NodeList trig = ((Element) n_in).getElementsByTagName("trigger");
    for (int i = 0; i < trig.getLength(); i++) {
      Trigger t = new Trigger(trig.item(i));
      this.triggers.add(t);
      if (t.getCondition() != null) {
        this.status = t.getCondition().getStatus();
      }
    }

    return this;
  }
예제 #29
0
  public MapFileReader(String path) {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.parse(new File(path.replace(".data", ".xml")));
      NodeList nList = document.getElementsByTagName("map");
      background = ((Element) nList.item(0)).getElementsByTagName("File").item(0).getTextContent();
      nList = document.getElementsByTagName("vertex");
      GraphModel g2 = new GraphModel(false);
      g2.setAllowLoops(true);
      Vertex root = new Vertex();
      root.setLocation(new GraphPoint(0, 0));
      g2.addVertex(root);
      for (int temp = 0; temp < nList.getLength(); temp++) {

        Node nNode = nList.item(temp);

        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
          Element eElement = (Element) nNode;
          boolean isRoot = eElement.getAttribute("type").equals("root");
          String id = eElement.getAttribute("id");
          int x = Integer.parseInt(eElement.getElementsByTagName("x").item(0).getTextContent());
          int y = Integer.parseInt(eElement.getElementsByTagName("y").item(0).getTextContent());
          int value = 0;

          Vertex newVertex = new Vertex();
          newVertex.setLocation(new GraphPoint(x, y));
          newVertex.setLabel(id);

          if (!isRoot) {
            g2.addVertex(newVertex);
            value =
                Integer.parseInt(eElement.getElementsByTagName("value").item(0).getTextContent());
            Edge e = new Edge(newVertex, root);
            e.setWeight(value);
            g2.addEdge(e);
          } else {
            root.setLocation(newVertex.getLocation());
            root.setLabel(newVertex.getLabel());
            //	root =  newVertex;
          }
        }
      }
      this.setGraph(g2);

    } catch (DOMException | ParserConfigurationException | SAXException | IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  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;
      }
    }
  }