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());
   }
 }
Esempio n. 3
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;
  }
  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);
        }
      }
    }
  }
Esempio n. 5
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;
 }
Esempio n. 6
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();
       }
     }
   }
 }
Esempio n. 7
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);
 }
Esempio n. 8
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()));
   }
 }
 // ===============================================================================
 // 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);
     }
   }
 }
Esempio n. 10
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();
  }
Esempio n. 11
0
 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);
     }
   }
 }
 /**
  * @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();
     }
   }
 }
Esempio n. 13
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()));
      }
    }
  }
Esempio n. 14
0
 /**
  * @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;
 }