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);
 }
 private void extractAttribute(
     Set<String> pReadAttributes, Set<String> pWriteAttributes, Node pParam) {
   Node mode = pParam.getAttributes().getNamedItem("mode");
   pReadAttributes.add(pParam.getTextContent().trim());
   if (mode == null || !mode.getNodeValue().equalsIgnoreCase("read")) {
     pWriteAttributes.add(pParam.getTextContent().trim());
   }
 }
  @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;
  }
  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);
        }
      }
    }
  }
Example #5
0
 public double getDoubleContent(double defaultValue) {
   String c = node.getTextContent();
   if (c != null) {
     try {
       return Double.parseDouble(c);
     } catch (NumberFormatException nfe) {
     }
   }
   return defaultValue;
 }
Example #6
0
 public long getLongContent(long defaultValue) {
   String c = node.getTextContent();
   if (c != null) {
     try {
       return Long.parseLong(c);
     } catch (NumberFormatException nfe) {
     }
   }
   return defaultValue;
 }
Example #7
0
 // Get the text value of a child element with a specified name.
 private static String getChildText(Element el, String childName) {
   String value = "";
   Node child = el.getFirstChild();
   while (child != null) {
     if ((child.getNodeType() == Node.ELEMENT_NODE) && child.getNodeName().equals(childName)) {
       return child.getTextContent();
     }
     child = child.getNextSibling();
   }
   return value;
 }
Example #8
0
 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();
       }
     }
   }
 }
Example #9
0
 private void call(Node operation)
     throws ParserConfigurationException, TransformerConfigurationException {
   String opName = operation.getNodeName();
   if (opName.equals("call")) {
     String script =
         Utils.combine(Utils.getParentDir(this.currentScript), operation.getTextContent());
     call(script);
   } else if (opName.equals("apply")) processApply(operation);
   else if (opName.equals("xml")) processXml(operation);
   else if (opName.equals("txt")) processTxt(operation);
   else if (opName.equals("copy")) processCopy(operation);
   else if (opName.equals("delete")) processDelete(operation);
 }
Example #10
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;
     }
   }
 }
Example #11
0
  public AxisName(Node node, XmlQuery xq) throws WCPSException {
    while ((node != null) && node.getNodeName().equals("#" + WCPSConstants.MSG_TEXT)) {
      node = node.getNextSibling();
    }

    if (node != null && node.getNodeName().equals(WCPSConstants.MSG_AXIS)) {
      log.trace(node.getNodeName());
      String axis = node.getTextContent();
      this.name = axis;
      log.trace("  " + WCPSConstants.MSG_AXIS + " " + WCPSConstants.MSG_NAME + ": " + name);
    } else {
      throw new WCPSException(
          ExceptionCode.InvalidRequest, WCPSConstants.ERRTXT_COULD_NOT_FIND_AXIS + " !");
    }
  }
Example #12
0
 private void processDelete(Node operation) {
   String path = absolutePath(operation.getTextContent());
   File target = new File(path);
   if (!target.exists()) {
     Utils.onError(new Error.FileNotFound(target.getPath()));
     return;
   }
   try {
     if (target.isDirectory()) {
       FileUtils.deleteDirectory(target);
     } else {
       FileUtils.forceDelete(target);
     }
   } catch (IOException ex) {
     Utils.onError(new Error.FileDelete(target.getPath()));
   }
 }
  public FieldName(Node node, XmlQuery xq, CoverageInfo covInfo) throws WCPSException {
    while ((node != null) && node.getNodeName().equals("#" + WcpsConstants.MSG_TEXT)) {
      node = node.getNextSibling();
    }

    if (node == null) {
      throw new WCPSException("FieldNameType parsing error.");
    }

    String nodeName = node.getNodeName();
    log.trace(nodeName);

    if (nodeName.equals(WcpsConstants.MSG_NAME)) {
      this.name = node.getTextContent();
      log.trace("Found field name: " + name);
      String coverageName = covInfo.getCoverageName();
      try {
        covMeta = xq.getMetadataSource().read(coverageName);
      } catch (Exception ex) {
        log.error(ex.getMessage());
        throw new WCPSException(ex.getMessage(), ex);
      }
      try {
        nameIndex = covMeta.getRangeIndexByName(name).toString();
      } catch (PetascopeException ex1) {
        boolean wrongFieldSubset = true;
        log.debug("Range field subset " + name + " does not seem by-label: trying by-index.");

        if (MiscUtil.isInteger(name)) {
          try {
            // range subsetting might have been done via range field /index/ (instead of label):
            // check this is a valid index
            nameIndex = name;
            name = covMeta.getRangeNameByIndex(Integer.parseInt(name));
            wrongFieldSubset = false; // indeed subset was by-index
          } catch (PetascopeException ex2) {
            log.debug("Range field subset " + nameIndex + " is neither a valid index.");
          }
        }
        if (wrongFieldSubset) {
          log.error("Illegal range field selection: " + name);
          throw new WCPSException(ex1.getExceptionCode(), ex1.getExceptionText());
        }
      }
    }
  }
Example #14
0
 public static XMLResult readResult(GenericFile file) {
   Node node = readXmlFile(file);
   XMLResult result = new XMLResult();
   NodeList list = node.getChildNodes();
   for (int i = 0; i < list.getLength(); i++) {
     Node n = list.item(i);
     if (n.getNodeName().equals("success")) {
       result.success = string2booleanList(n.getTextContent()).get(0);
     }
     if (n.getNodeName().equals("result")) {
       result.resultValue = new ResultValue(n);
     }
     if (n.getNodeName().equals("error")) {
       result.resultValue = new ResultValue(n);
       result.error = result.resultValue.structResult.get(0).get("identifier").charResult;
       result.message = result.resultValue.structResult.get(0).get("message").charResult;
     }
   }
   return result;
 }
 // ===============================================================================
 // Parsing routines
 private void initTypeSet(Document pDoc) {
   NodeList nodes = pDoc.getElementsByTagName("commands");
   if (nodes.getLength() > 0) {
     // Leave typeSet null if no commands has been given...
     typeSet = new HashSet<JmxRequest.Type>();
   }
   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 commandNode = childs.item(j);
       if (commandNode.getNodeType() != Node.ELEMENT_NODE) {
         continue;
       }
       assertNodeName(commandNode, "command");
       String typeName = commandNode.getTextContent().trim();
       JmxRequest.Type type = JmxRequest.Type.valueOf(typeName.toUpperCase());
       typeSet.add(type);
     }
   }
 }
 private void initHttpMethodSet(Document pDoc) {
   NodeList nodes = pDoc.getElementsByTagName("http");
   if (nodes.getLength() > 0) {
     // Leave typeSet null if no commands has been given...
     httpMethodsSet = 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 commandNode = childs.item(j);
       if (commandNode.getNodeType() != Node.ELEMENT_NODE) {
         continue;
       }
       assertNodeName(commandNode, "method");
       String methodName = commandNode.getTextContent().trim().toLowerCase();
       if (!methodName.equals("post") || methodName.equals("get")) {
         throw new SecurityException(
             "HTTP method must be either GET or POST, but not " + methodName);
       }
       httpMethodsSet.add(methodName);
     }
   }
 }
Example #17
0
  /**
   * Construct a Query from an XML document in the form described on the RSNA MIRC wiki.
   *
   * @param queryDoc the MIRCquery XML DOM object.
   */
  public Query(Document queryDoc) {
    super();
    Element root = queryDoc.getDocumentElement();
    unknown = root.getAttribute("unknown").trim().equals("yes");
    bgcolor = root.getAttribute("bgcolor").trim();
    display = root.getAttribute("display").trim();
    icons = root.getAttribute("icons").trim();
    orderby = root.getAttribute("orderby").trim();
    firstresult = StringUtil.getInt(root.getAttribute("firstresult"));
    if (firstresult <= 0) firstresult = 1;
    maxresults = StringUtil.getInt(root.getAttribute("maxresults"));
    if (maxresults <= 0) maxresults = 1;

    StringBuffer sb = new StringBuffer();
    Node child = root.getFirstChild();
    while (child != null) {
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        String dbname = child.getNodeName();
        String text = getTextContent(child);
        if (!text.equals("")) {
          this.put(dbname, text);
          containsNonFreetextQueries = true;
        }
        if (dbname.equals("temp")) isTempQuery = true;
      } else if (child.getNodeType() == Node.TEXT_NODE) {
        sb.append(" " + child.getTextContent());
      }
      child = child.getNextSibling();
    }
    String freetext = sb.toString().replaceAll("\\s+", " ").trim();
    isBlankQuery = freetext.equals("");
    isSpecialQuery = root.getAttribute("special").trim().equals("yes");
    this.put("freetext", freetext);
    setAgeRange(root);
    // log();
  }
Example #18
0
  private void processTxt(Node operation) {
    List<Node> targets = getChildNodes(operation, "target");
    List<Node> optionNodes = getChildNodes(operation, "opt");
    List<Node> separatorNode = getChildNodes(operation, "separator");
    if (targets.isEmpty() || optionNodes.isEmpty()) {
      return;
    }
    String defaultSeparator = "=";
    String globalSeparator = defaultSeparator;
    if (!separatorNode.isEmpty()) {
      globalSeparator = separatorNode.get(0).getTextContent();
      if (globalSeparator.length() != 1) {
        globalSeparator = defaultSeparator;
      }
    }
    Map<String, String> options = new HashMap<String, String>();
    Map<String, String> processedOptions = new HashMap<String, String>();
    for (int i = 0; i < optionNodes.size(); i++) {
      Node option = optionNodes.get(i);
      String name = option.getAttributes().getNamedItem("name").getNodeValue();
      String value = option.getTextContent();
      if (options.containsKey(name)) {
        options.remove(name);
      }
      options.put(name, value);
    }
    for (int t = 0; t < targets.size(); t++) {
      File target = new File(absolutePath(targets.get(t).getTextContent()));
      File tmpFile = new File(Utils.timestamp());
      BufferedWriter bw = null;
      BufferedReader br = null;
      try {
        Node separatorAttr = targets.get(t).getAttributes().getNamedItem("separator");
        String separator = (separatorAttr == null) ? globalSeparator : separatorAttr.getNodeValue();
        if (separator.length() != 1) {
          separator = globalSeparator;
        }
        bw = new BufferedWriter(new FileWriter(tmpFile));
        if (target.exists()) {
          br = new BufferedReader(new FileReader(target));
          for (String line; (line = br.readLine()) != null; ) {
            String[] parts = line.split(separator);
            if (parts.length < 2) {
              bw.write(line);
              bw.newLine();
              continue;
            }

            String optName = parts[0].trim();
            if (options.containsKey(optName)) {
              String optValue = options.get(optName);
              bw.write(optName + " " + separator + " " + optValue);
              bw.newLine();
              processedOptions.put(optName, optValue);
              options.remove(optName);
            } else if (processedOptions.containsKey(optName)) {
              bw.write(optName + " " + separator + " " + processedOptions.get(optName));
              bw.newLine();
            } else {
              bw.write(line);
              bw.newLine();
            }
          }
          br.close();
        }
        for (Map.Entry<String, String> entry : options.entrySet()) {
          bw.write(entry.getKey() + " " + separator + " " + entry.getValue());
          bw.newLine();
        }
        bw.close();
        FileUtils.copyFile(tmpFile, target);
        FileUtils.forceDelete(tmpFile);
      } catch (IOException ex) {
        Utils.onError(new Error.WriteTxtConfig(target.getPath()));
      }
    }
  }
 /**
  * @see
  *     org.kuali.kra.proposaldevelopment.budget.service.BudgetSubAwardService#updateSubAwardBudgetDetails(org.kuali.kra.budget.core.Budget,
  *     org.kuali.kra.proposaldevelopment.budget.bo.BudgetSubAwards, java.util.List)
  */
 public boolean updateSubAwardBudgetDetails(
     Budget budget, BudgetSubAwards budgetSubAward, List<String[]> errors) throws Exception {
   boolean result = true;
   // extarct xml from the pdf because the stored xml has been modified
   if (budgetSubAward.getSubAwardXfdFileData() == null
       || budgetSubAward.getSubAwardXfdFileData().length == 0) {
     errors.add(new String[] {Constants.SUBAWARD_FILE_NOT_EXTRACTED});
     return false;
   }
   PdfReader reader = new PdfReader(budgetSubAward.getSubAwardXfdFileData());
   byte[] xmlContents = getXMLFromPDF(reader);
   if (xmlContents == null) {
     return false;
   }
   javax.xml.parsers.DocumentBuilderFactory domParserFactory =
       javax.xml.parsers.DocumentBuilderFactory.newInstance();
   javax.xml.parsers.DocumentBuilder domParser = domParserFactory.newDocumentBuilder();
   ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlContents);
   org.w3c.dom.Document document = domParser.parse(byteArrayInputStream);
   NodeList budgetYearList =
       XPathAPI.selectNodeList(document, "//*[local-name(.) = 'BudgetYear']");
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
   boolean fnfForm = StringUtils.contains(budgetSubAward.getFormName(), "RR_FedNonFedBudget");
   for (int i = 0; i < budgetYearList.getLength(); i++) {
     Node budgetYear = budgetYearList.item(i);
     Node startDateNode = XPathAPI.selectSingleNode(budgetYear, "BudgetPeriodStartDate");
     if (startDateNode == null) {
       startDateNode = XPathAPI.selectSingleNode(budgetYear, "PeriodStartDate");
     }
     Node endDateNode = XPathAPI.selectSingleNode(budgetYear, "BudgetPeriodEndDate");
     if (endDateNode == null) {
       endDateNode = XPathAPI.selectSingleNode(budgetYear, "PeriodEndDate");
     }
     Date startDate = dateFormat.parse(startDateNode.getTextContent());
     Date endDate = dateFormat.parse(endDateNode.getTextContent());
     // attempt to find a matching budget period
     BudgetSubAwardPeriodDetail periodDetail =
         findBudgetSubAwardPeriodDetail(budget, budgetSubAward, startDate, endDate);
     if (periodDetail != null) {
       Node directCostNode, indirectCostNode, costShareNode = null;
       if (fnfForm) {
         directCostNode = XPathAPI.selectSingleNode(budgetYear, "DirectCosts/FederalSummary");
         indirectCostNode =
             XPathAPI.selectSingleNode(
                 budgetYear, "IndirectCosts/TotalIndirectCosts/FederalSummary");
         costShareNode = XPathAPI.selectSingleNode(budgetYear, "TotalCosts/NonFederalSummary");
       } else {
         directCostNode = XPathAPI.selectSingleNode(budgetYear, "DirectCosts");
         indirectCostNode =
             XPathAPI.selectSingleNode(budgetYear, "IndirectCosts/TotalIndirectCosts");
       }
       if (directCostNode != null) {
         periodDetail.setDirectCost(
             new BudgetDecimal(Float.parseFloat(directCostNode.getTextContent())));
       }
       if (indirectCostNode != null) {
         periodDetail.setIndirectCost(
             new BudgetDecimal(Float.parseFloat(indirectCostNode.getTextContent())));
       }
       if (costShareNode != null) {
         periodDetail.setCostShare(
             new BudgetDecimal(Float.parseFloat(costShareNode.getTextContent())));
       } else {
         periodDetail.setCostShare(BudgetDecimal.ZERO);
       }
       periodDetail.computeTotal();
     } else {
       Node budgetPeriodNode = XPathAPI.selectSingleNode(budgetYear, "BudgetPeriod");
       String budgetPeriod = null;
       if (budgetPeriodNode != null) {
         budgetPeriod = budgetPeriodNode.getTextContent();
       }
       LOG.debug(
           "Unable to find matching period for uploaded period '"
               + budgetPeriod
               + "' -- "
               + startDateNode.getTextContent()
               + " - "
               + endDateNode.getTextContent());
       errors.add(
           new String[] {
             Constants.SUBAWARD_FILE_PERIOD_NOT_FOUND,
             budgetPeriod,
             startDateNode.getTextContent(),
             endDateNode.getTextContent()
           });
     }
   }
   return result;
 }
 /**
  * @param list
  * @param parent
  * @exception NumberFormatException
  * @exception DicomException
  */
 void addAttributesFromNodeToList(AttributeList list, Node parent)
     throws NumberFormatException, DicomException {
   if (parent != null) {
     Node node = parent.getFirstChild();
     while (node != null) {
       String elementName = node.getNodeName();
       NamedNodeMap attributes = node.getAttributes();
       if (attributes != null) {
         Node vrNode = attributes.getNamedItem("vr");
         Node groupNode = attributes.getNamedItem("group");
         Node elementNode = attributes.getNamedItem("element");
         if (vrNode != null && groupNode != null && elementNode != null) {
           String vrString = vrNode.getNodeValue();
           String groupString = groupNode.getNodeValue();
           String elementString = elementNode.getNodeValue();
           if (vrString != null && groupString != null && elementString != null) {
             byte[] vr = vrString.getBytes();
             int group = Integer.parseInt(groupString, 16);
             int element = Integer.parseInt(elementString, 16);
             AttributeTag tag = new AttributeTag(group, element);
             if ((group % 2 == 0 && element == 0)
                 || (group == 0x0008 && element == 0x0001)
                 || (group == 0xfffc && element == 0xfffc)) {
               // System.err.println("ignoring group length or length to end or dataset trailing
               // padding "+tag);
             } else {
               if (vrString.equals("SQ")) {
                 SequenceAttribute a = new SequenceAttribute(tag);
                 // System.err.println("Created "+a);
                 if (node.hasChildNodes()) {
                   Node childNode = node.getFirstChild();
                   while (childNode != null) {
                     String childNodeName = childNode.getNodeName();
                     // System.err.println("childNodeName = "+childNodeName);
                     if (childNodeName != null && childNodeName.equals("Item")) {
                       // should check item number, but ignore for now :(
                       // System.err.println("Adding item to sequence");
                       AttributeList itemList = new AttributeList();
                       addAttributesFromNodeToList(itemList, childNode);
                       a.addItem(itemList);
                     }
                     // else may be a #text element in between
                     childNode = childNode.getNextSibling();
                   }
                 }
                 // System.err.println("Sequence Attribute is "+a);
                 list.put(tag, a);
               } else {
                 Attribute a = AttributeFactory.newAttribute(tag, vr);
                 // System.err.println("Created "+a);
                 if (node.hasChildNodes()) {
                   Node childNode = node.getFirstChild();
                   while (childNode != null) {
                     String childNodeName = childNode.getNodeName();
                     // System.err.println("childNodeName = "+childNodeName);
                     if (childNodeName != null && childNodeName.equals("value")) {
                       // should check value number, but ignore for now :(
                       String value = childNode.getTextContent();
                       // System.err.println("Value value = "+value);
                       if (value != null) {
                         value =
                             StringUtilities.removeLeadingOrTrailingWhitespaceOrISOControl(
                                 value); // just in case
                         a.addValue(value);
                       }
                     }
                     // else may be a #text element in between
                     childNode = childNode.getNextSibling();
                   }
                 }
                 // System.err.println("Attribute is "+a);
                 list.put(tag, a);
               }
             }
           }
         }
       }
       node = node.getNextSibling();
     }
   }
 }
Example #21
0
 public String getContent(String defaultValue) {
   String s = node.getTextContent();
   return (s != null) ? s : defaultValue;
 }
Example #22
0
 /** @param defaultValue the default value of the attribute */
 public int getIntContent(int defaultValue) {
   return PApplet.parseInt(node.getTextContent(), defaultValue);
 }
Example #23
0
 /** @param defaultValue the default value of the attribute */
 public float getFloatContent(float defaultValue) {
   return PApplet.parseFloat(node.getTextContent(), defaultValue);
 }
Example #24
0
  public void parseXML(Node rootNode) {
    try {
      NumberFormat nf = WLPNumberFormat.getInstance();
      NamedNodeMap attrs = rootNode.getAttributes();
      if (attrs != null) {
        Node nameNode = attrs.getNamedItem(nameTag);
        if (nameNode != null) {
          name = nameNode.getTextContent().trim();
        }
        Node guidNode = attrs.getNamedItem(guidTag);
        if (guidNode != null) {
          guid = guidNode.getTextContent().trim();
        }
      }

      Node mergedNode = XmlHelper.getChildNode(rootNode, mergedTag);
      if (mergedNode != null) {
        merged = Boolean.parseBoolean(mergedNode.getTextContent().trim());
      }

      Node durationNode = XmlHelper.getChildNode(rootNode, durationTag);
      if (durationNode != null) {
        duration = nf.parse(durationNode.getTextContent().trim()).doubleValue();
      }

      Node activeDurationNode = XmlHelper.getChildNode(rootNode, activeDurationTag);
      if (activeDurationNode != null) {
        activeDuration = nf.parse(activeDurationNode.getTextContent().trim()).doubleValue();
      }

      Node numMobsNode = XmlHelper.getChildNode(rootNode, numMobsTag);
      if (numMobsNode != null) {
        numMobs = Integer.parseInt(numMobsNode.getTextContent().trim());
      }

      Node totalDamageNode = XmlHelper.getChildNode(rootNode, totalDamageTag);
      if (totalDamageNode != null) {
        totalDamage = Long.parseLong(totalDamageNode.getTextContent().trim());
      }

      Node victimNode = XmlHelper.getChildNode(rootNode, victimTag);
      if (victimNode != null) {
        Node victimFightparticipantNode =
            XmlHelper.getChildNode(victimNode, XMLFightParticipant.fightParticipantTag);
        if (victimFightparticipantNode != null) {
          xmlVictim = new XMLFightParticipant();
          xmlVictim.parseXML(victimFightparticipantNode);
        }
      }
      List<Node> fightParticipantNodes =
          XmlHelper.getChildNodes(rootNode, XMLFightParticipant.fightParticipantTag);
      fightParticipants = new ArrayList<XMLFightParticipant>();
      for (Node partNode : fightParticipantNodes) {
        if (partNode != null) {
          XMLFightParticipant xmlPart = new XMLFightParticipant();
          xmlPart.parseXML(partNode);
          fightParticipants.add(xmlPart);
        }
      }
    } catch (ParseException ex) {
      throw new NumberFormatException();
    }
  }
Example #25
0
 /**
  * Return the #PCDATA content of the element. If the element has a combination of #PCDATA content
  * and child elements, the #PCDATA sections can be retrieved as unnamed child objects. In this
  * case, this method returns null.
  *
  * @webref xml:method
  * @brief Gets the content of an element
  * @return the content.
  * @see XML#getIntContent()
  * @see XML#getFloatContent()
  */
 public String getContent() {
   return node.getTextContent();
 }