/**
  * Unmarshall a Chromosome instance from a given XML Element representation.
  *
  * @param a_activeConfiguration the current active Configuration object that is to be used during
  *     construction of the Chromosome
  * @param a_xmlElement the XML Element representation of the Chromosome
  * @return a new Chromosome instance 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
  * @since 1.0
  */
 public static Chromosome getChromosomeFromElement(
     Configuration a_activeConfiguration, Element a_xmlElement)
     throws ImproperXMLException, InvalidConfigurationException,
         UnsupportedRepresentationException, GeneCreationException {
   // Do some sanity checking. Make sure the XML Element isn't null and
   // that in fact represents a chromosome.
   // -----------------------------------------------------------------
   if (a_xmlElement == null || !(a_xmlElement.getTagName().equals(CHROMOSOME_TAG))) {
     throw new ImproperXMLException(
         "Unable to build Chromosome instance from XML Element: "
             + "given Element is not a 'chromosome' element.");
   }
   // Extract the nested genes element and make sure it exists.
   // ---------------------------------------------------------
   Element genesElement = (Element) a_xmlElement.getElementsByTagName(GENES_TAG).item(0);
   if (genesElement == null) {
     throw new ImproperXMLException(
         "Unable to build Chromosome instance from XML Element: "
             + "'genes' sub-element not found.");
   }
   // Construct the genes from their representations.
   // -----------------------------------------------
   Gene[] geneAlleles = getGenesFromElement(a_activeConfiguration, genesElement);
   // Construct the new Chromosome with the genes and return it.
   // ----------------------------------------------------------
   return new Chromosome(a_activeConfiguration, geneAlleles);
 }
 /**
  * Marshall an array of Genes to an XML Element representation.
  *
  * @param a_geneValues the genes to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given genes
  * @author Neil Rotstan
  * @author Klaus Meffert
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representGenesAsElement(
     final Gene[] a_geneValues, final Document a_xmlDocument) {
   // Create the parent genes element.
   // --------------------------------
   Element genesElement = a_xmlDocument.createElement(GENES_TAG);
   // Now add gene sub-elements for each gene in the given array.
   // -----------------------------------------------------------
   Element geneElement;
   for (int i = 0; i < a_geneValues.length; i++) {
     // Create the allele element for this gene.
     // ----------------------------------------
     geneElement = a_xmlDocument.createElement(GENE_TAG);
     // Add the class attribute and set its value to the class
     // name of the concrete class representing the current Gene.
     // ---------------------------------------------------------
     geneElement.setAttribute(CLASS_ATTRIBUTE, a_geneValues[i].getClass().getName());
     // Create a text node to contain the string representation of
     // the gene's value (allele).
     // ----------------------------------------------------------
     Element alleleRepresentation = representAlleleAsElement(a_geneValues[i], a_xmlDocument);
     // And now add the text node to the gene element, and then
     // add the gene element to the genes element.
     // -------------------------------------------------------
     geneElement.appendChild(alleleRepresentation);
     genesElement.appendChild(geneElement);
   }
   return genesElement;
 }
Пример #3
0
  // read all defense missiles from given id
  protected void readDefensDestructoreMissiles(NodeList missiles, String whoLaunchMeId) {
    String targetId, destructTimeCheck;
    int destructTime;

    int size = missiles.getLength();
    for (int i = 0; i < size; i++) {
      Element missile = (Element) missiles.item(i);
      targetId = missile.getAttribute("id");

      destructTimeCheck = missile.getAttribute("destructAfterLaunch");

      if (destructTimeCheck.equals("")) destructTimeCheck = missile.getAttribute("destructTime");

      try {
        destructTime = Integer.parseInt(destructTimeCheck);

      } catch (NumberFormatException e) {
        destructTime = -1;
        // System.out.println(e.getStackTrace());
      }

      // create the thread of the missile
      createDefenseMissile(whoLaunchMeId, targetId, destructTime);
    }
  }
Пример #4
0
  // read all defense missile from given defense destructor
  protected void readDefenseDestructorFromGivenDestructor(Element destructor) {
    NamedNodeMap attributes = destructor.getAttributes();
    String id = "";
    String type;

    Attr attr = (Attr) attributes.item(0);

    String name = attr.getNodeName();

    // if it's iron dome
    if (name.equals("id")) {
      id = attr.getNodeValue();

      // update id's in the war
      IdGenerator.updateIronDomeId(id);
      // add to war
      war.addIronDome(id);

      NodeList destructdMissiles = destructor.getElementsByTagName("destructdMissile");
      readDefensDestructoreMissiles(destructdMissiles, id);

      // if it's launcher destructor
    } else {
      if (name.equals("type")) {
        type = attr.getNodeValue();

        // add to war
        id = war.addDefenseLauncherDestructor(type);

        NodeList destructedLanuchers = destructor.getElementsByTagName("destructedLanucher");
        readDefensDestructoreMissiles(destructedLanuchers, id);
      }
    }
  }
 /**
  * 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);
 }
Пример #6
0
 private Dim getDim(Element shape) {
   return new Dim(
       Integer.parseInt(shape.getAttribute(ATR_X)),
       Integer.parseInt(shape.getAttribute(ATR_Y)),
       Integer.parseInt(shape.getAttribute(ATR_WIDTH)),
       Integer.parseInt(shape.getAttribute(ATR_HEIGHT)));
 }
Пример #7
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();
    }
  }
Пример #8
0
    private FixedCoords getFixedCoords(Element shape, int width, int height, String suffix) {
      if (suffix == null) suffix = "";
      // parse the coordinates and check if they are fixed or reverse fixed
      String val = shape.getAttribute(ATR_X + suffix);
      int x, y, fixedX = 0, fixedY = 0;
      if (val.endsWith(VAL_RF)) {
        x = width;
        fixedX = x - Integer.parseInt(val.substring(0, val.length() - 2));
      } else if (val.endsWith(VAL_F)) {
        x = Integer.parseInt(val.substring(0, val.length() - 1));
        fixedX = -1;
      } else {
        x = Integer.parseInt(val);
      }
      val = shape.getAttribute(ATR_Y + suffix);
      if (val.endsWith(VAL_RF)) {
        y = height;
        fixedY = y - Integer.parseInt(val.substring(0, val.length() - 2));
      } else if (val.endsWith(VAL_F)) {
        y = Integer.parseInt(val.substring(0, val.length() - 1));
        fixedY = -1;
      } else {
        y = Integer.parseInt(val);
      }

      return new FixedCoords(x, fixedX, y, fixedY);
    }
Пример #9
0
  private void guardaRes(String resu, CliGol cliGol)
      throws ParserConfigurationException, SAXException, IOException {

    String[] nodos = {"NoHit", "Hit", "Buro"};

    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(resu));
    Document xml = db.parse(is);

    Element raiz = xml.getDocumentElement();

    String nombre = obtenerNombre(raiz);

    for (String s : nodos) {

      Node nodo =
          raiz.getElementsByTagName(s) == null ? null : raiz.getElementsByTagName(s).item(0);

      if (nodo != null) {
        String informacion = sustraerInformacionNodo(cliGol, nodo);

        guardarEnListas(nodo.getNodeName(), nombre + "," + informacion);
      }
    }
  }
  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);
  }
Пример #11
0
 protected void setAttribute(String name, String attName, String attValue) {
   Element elt = getElement(name);
   if (elt == null) {
     elt = doc.createElement(name);
     docElt.appendChild(elt);
   }
   elt.setAttribute(attName, attValue);
 }
Пример #12
0
 private Lineprops getLineProps(Element shape) {
   return new Lineprops(
       shape.hasAttribute(ATR_STROKE)
           ? Float.parseFloat(shape.getAttribute(ATR_STROKE))
           : IMPLIED_STROKE,
       shape.hasAttribute(ATR_LINETYPE)
           ? Float.parseFloat(shape.getAttribute(ATR_LINETYPE))
           : IMPLIED_LINE);
 }
Пример #13
0
 public XMLHelper createSubNode(String subnode) {
   int pos = subnode.lastIndexOf(DELIM);
   if (pos >= 0) {
     XMLHelper helper = getSubNode(subnode.substring(0, pos));
     return helper.createSubNode(subnode.substring(pos + 1));
   } else {
     return new XMLHelper(
         (Element) element.appendChild(element.getOwnerDocument().createElement(subnode)), true);
   }
 }
Пример #14
0
  /**
   * ** Gets a virtual DBRecord from the specified remote service ** @param servReq The remote web
   * service ** @return The virtual DBRecord (cannot be saved or reloaded)
   */
  @SuppressWarnings("unchecked")
  public gDBR getVirtualDBRecord(final ServiceRequest servReq) throws DBException {
    String CMD_dbget = DBFactory.CMD_dbget;
    String TAG_Response = servReq.getTagResponse();
    String TAG_Record = DBFactory.TAG_Record;
    String ATTR_command = servReq.getAttrCommand();
    String ATTR_result = servReq.getAttrResult();

    /* send request / get response */
    Document xmlDoc = null;
    try {
      xmlDoc =
          servReq.sendRequest(
              CMD_dbget,
              new ServiceRequest.RequestBody() {
                public StringBuffer appendRequestBody(StringBuffer sb, int indent) {
                  return DBRecordKey.this.toRequestXML(sb, indent);
                }
              });
    } catch (IOException ioe) {
      Print.logException("Error", ioe);
      throw new DBException("Request read error", ioe);
    }

    /* parse 'GTSResponse' */
    Element gtsResponse = xmlDoc.getDocumentElement();
    if (!gtsResponse.getTagName().equalsIgnoreCase(TAG_Response)) {
      Print.logError("Request XML does not start with '%s'", TAG_Response);
      throw new DBException("Response XML does not begin eith '" + TAG_Response + "'");
    }

    /* request command/argument */
    String cmd = StringTools.trim(gtsResponse.getAttribute(ATTR_command));
    String result = StringTools.trim(gtsResponse.getAttribute(ATTR_result));
    if (StringTools.isBlank(result)) {
      result = StringTools.trim(gtsResponse.getAttribute("type"));
    }
    if (!result.equalsIgnoreCase("success")) {
      Print.logError("Response indicates failure");
      throw new DBException("Response does not indicate 'success'");
    }

    /* Record */
    NodeList rcdList = XMLTools.getChildElements(gtsResponse, TAG_Record);
    if (rcdList.getLength() <= 0) {
      Print.logError("No 'Record' tags");
      throw new DBException("GTSResponse does not contain any 'Record' tags");
    }
    Element rcdElem = (Element) rcdList.item(0);

    /* return DBRecord */
    gDBR dbr = (gDBR) DBFactory.parseXML_DBRecord(rcdElem);
    dbr.setVirtual(true);
    return dbr;
  }
Пример #15
0
  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;
  }
Пример #16
0
 private Node getTextNode() {
   NodeList list = element.getChildNodes();
   int length = list.getLength();
   for (int i = 0; i < length; i++) {
     Node node = list.item(i);
     if (node.getNodeType() == Node.TEXT_NODE) {
       return node;
     }
   }
   return element.appendChild(element.getOwnerDocument().createTextNode(""));
 }
  /**
   * Get the named properties for this resource and (potentially) its children.
   *
   * @param names an arrary of property names to retrieve
   * @return a MultiStatus of PropertyResponses
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getProperties(PropertyName[] names) throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    MultiStatus newMultiStatus = new MultiStatus();

    Enumeration responses = multiStatus.getResponses();

    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      PropertyResponse newResponse = new PropertyResponse(response.getResource());
      newResponse.setDescription(response.getDescription());
      newMultiStatus.addResponse(newResponse);

      Hashtable properties = (Hashtable) response.getPropertiesByPropName();

      // Hashtable newProperties = (Hashtable) newResponse.getProperties();
      for (int i = 0; i < names.length; i++) {
        if (properties.containsKey(names[i])) {
          PropertyValue srcval = response.getProperty(names[i]);
          newResponse.setProperty(names[i], srcval);

          // newProperties.put(names[i], properties.get(names[i]));
        } else {
          Document factory = null;

          try {
            factory = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
          } catch (Exception e) {
            throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
          }

          // we'll create an xml element with no value because that's
          //    what webdav will need to return for most methods... even if the
          //    property doesn't exist.   That's because the
          //    distinction between a propertyname and propertyvalue
          //    is fuzzy in WebDAV xml. A property name is
          //    essentially an empty property value because
          //    all property values have their property
          //    name stuck on.
          // if we decide to set reviewStatus to null instead (as
          //    we did previously, then the code for MultiStatus.asXML()
          //    needs to be updated to expect null values.
          // (jlc 990520)
          Element elTm = factory.createElementNS("X", "X:" + names[i].getLocal());

          elTm.setAttribute("xmlns:X", names[i].getNamespace());

          newResponse.addProperty(names[i], elTm, WebDAVStatus.SC_NOT_FOUND);
        }
      }
    }

    return newMultiStatus;
  }
Пример #18
0
    public Element reportDtElem() {
      StringBuffer sb = new StringBuffer(255);
      sb.append(shortTypeName);
      sb.append(" [ dataSourceName: ");
      sb.append(pds.getDataSourceName());
      sb.append("; identityToken: ");
      sb.append(pds.getIdentityToken());
      sb.append(" ]");

      Element dtElem = doc.createElement("dt");
      dtElem.appendChild(doc.createTextNode(sb.toString()));
      return dtElem;
    }
Пример #19
0
  private Node generateFieldNode(Document doc, ClassField field) {
    Element fieldEl = doc.createElement(EL_FIELD);

    fieldEl.setAttribute(ATR_NAME, field.getName());
    fieldEl.setAttribute(ATR_TYPE, field.getType());

    if (field.isInput()) fieldEl.setAttribute(ATR_NATURE, "input");
    else if (field.isGoal()) fieldEl.setAttribute(ATR_NATURE, "goal");

    if (field.getValue() != null) fieldEl.setAttribute(ATR_VALUE, field.getValue());

    return fieldEl;
  }
Пример #20
0
  private void addChannel(Document doc, Element root, Integer channel, HashSet<Integer> values) {
    Element el = doc.createElement(_channel);
    Attr attr = doc.createAttribute(_number);
    attr.setValue(Integer.toString(channel + 1));
    el.setAttributeNode(attr);
    Text txt;
    for (Integer x : values) {
      txt = doc.createTextNode(x.toString());
      el.appendChild(txt);
    }

    root.appendChild(el);
  }
Пример #21
0
 public void load(InputStream is) throws IOException, ParserConfigurationException, SAXException {
   doc = db.parse(is);
   docElt = doc.getDocumentElement();
   if (docElt.getTagName().equals(docElementName)) {
     NodeList nl = docElt.getElementsByTagName(trackElementName);
     for (int i = 0; i < nl.getLength(); i++) {
       Element elt = (Element) nl.item(i);
       Track track = new Track(elt);
       tracks.add(track);
       hash.put(track.getKey(), track);
     }
   }
 }
Пример #22
0
  @Override
  public VPackage parse() {

    logger.debug("Starting parsing package: " + xmlFile.getAbsolutePath());

    long startParsing = System.currentTimeMillis();

    try {
      Document document = getDocument();
      Element root = document.getDocumentElement();

      _package = new VPackage(xmlFile);

      Node name = root.getElementsByTagName(EL_NAME).item(0);
      _package.setName(name.getTextContent());
      Node descr = root.getElementsByTagName(EL_DESCRIPTION).item(0);
      _package.setDescription(descr.getTextContent());

      NodeList list = root.getElementsByTagName(EL_CLASS);

      boolean initPainters = false;
      for (int i = 0; i < list.getLength(); i++) {
        PackageClass pc = parseClass((Element) list.item(i));
        if (pc.getPainterName() != null) {
          initPainters = true;
        }
      }

      if (initPainters) {
        _package.initPainters();
      }

      logger.info(
          "Parsing the package '{}' finished in {}ms.\n",
          _package.getName(),
          (System.currentTimeMillis() - startParsing));
    } catch (Exception e) {
      collector.collectDiagnostic(e.getMessage(), true);
      if (RuntimeProperties.isLogDebugEnabled()) {
        e.printStackTrace();
      }
    }

    try {
      checkProblems("Error parsing package file " + xmlFile.getName());
    } catch (Exception e) {
      return null;
    }

    return _package;
  }
Пример #23
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();
    }
  }
Пример #24
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);
            }
          }
        }
      }
    }
  }
  /**
   * WhiteboardObjectTextJabberImpl constructor.
   *
   * @param xml the XML string object to parse.
   */
  public WhiteboardObjectTextJabberImpl(String xml) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
      builder = factory.newDocumentBuilder();
      InputStream in = new ByteArrayInputStream(xml.getBytes());
      Document doc = builder.parse(in);

      Element e = doc.getDocumentElement();
      String elementName = e.getNodeName();
      if (elementName.equals("text")) {
        // we have a text
        String id = e.getAttribute("id");
        double x = Double.parseDouble(e.getAttribute("x"));
        double y = Double.parseDouble(e.getAttribute("y"));
        String fill = e.getAttribute("fill");
        String fontFamily = e.getAttribute("font-family");
        int fontSize = Integer.parseInt(e.getAttribute("font-size"));
        String text = e.getTextContent();

        this.setID(id);
        this.setWhiteboardPoint(new WhiteboardPoint(x, y));
        this.setFontName(fontFamily);
        this.setFontSize(fontSize);
        this.setText(text);
        this.setColor(Color.decode(fill).getRGB());
      }
    } catch (ParserConfigurationException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (IOException ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    } catch (Exception ex) {
      if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml);
    }
  }
Пример #26
0
  public static void main(String[] args) {
    try {
      DocumentBuilderFactory dBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dBuilderFactory.newDocumentBuilder();

      Document document = dBuilder.parse("DOMSample.xml");

      Element rootElement = document.getDocumentElement();

      System.out.println("Root Element's Value : " + rootElement.getTextContent());
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
Пример #27
0
 public XMLHelper getSubNode(String subnode) {
   String nodes[] = subnode.split(REGEX);
   Element sub = element;
   boolean isnew = false;
   for (int i = 0; i < nodes.length; i++) {
     NodeList list = getImediateElementsByTagName(sub, nodes[i]);
     if (list.getLength() > 0) {
       sub = (Element) list.item(0);
     } else {
       sub = (Element) sub.appendChild(element.getOwnerDocument().createElement(nodes[i]));
       isnew = true;
     }
   }
   return new XMLHelper(sub, isnew);
 }
Пример #28
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);
  }
Пример #29
0
 public void remove(Track track) {
   synchronized (this) {
     docElt.removeChild(track.getElement());
     tracks.remove(track);
     hash.remove(track.getKey());
   }
 }
Пример #30
0
 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;
 }