Esempio n. 1
0
 private void processApply(Node operation)
     throws ParserConfigurationException, TransformerConfigurationException {
   List<Node> targets = getChildNodes(operation, "target");
   List<Node> scripts = getChildNodes(operation, "script");
   for (int t = 0; t < targets.size(); t++) {
     String path = absolutePath(targets.get(t).getTextContent());
     NodeList[] operations = new NodeList[scripts.size()];
     for (int s = 0; s < scripts.size(); s++) {
       operations[s] = scripts.get(s).getChildNodes();
     }
     apply(path, operations);
   }
 }
Esempio n. 2
0
 public AlbumBean[] getResult() {
   synchronized (libraryList) {
     AlbumBean[] res;
     res = libraryList.toArray(new AlbumBean[libraryList.size()]);
     return res;
   }
 }
Esempio n. 3
0
 /**
  * @param expected the expected value
  * @param typeAdapter the body adapter for the cell
  * @param formatter the formatter
  * @param minLenForToggle the value determining whether the content should be rendered as a
  *     collapseable section.
  * @return the formatted content for a cell with a wrong expectation
  */
 public static String makeContentForWrongCell(
     String expected,
     RestDataTypeAdapter typeAdapter,
     CellFormatter<?> formatter,
     int minLenForToggle) {
   StringBuffer sb = new StringBuffer();
   sb.append(Tools.toHtml(expected));
   if (formatter.isDisplayActual()) {
     sb.append(toHtml("\n"));
     sb.append(formatter.label("expected"));
     String actual = typeAdapter.toString();
     sb.append(toHtml("-----"));
     sb.append(toHtml("\n"));
     if (minLenForToggle >= 0 && actual.length() > minLenForToggle) {
       sb.append(makeToggleCollapseable("toggle actual", toHtml(actual)));
     } else {
       sb.append(toHtml(actual));
     }
     sb.append(toHtml("\n"));
     sb.append(formatter.label("actual"));
   }
   List<String> errors = typeAdapter.getErrors();
   if (errors.size() > 0) {
     sb.append(toHtml("-----"));
     sb.append(toHtml("\n"));
     for (String e : errors) {
       sb.append(toHtml(e + "\n"));
     }
     sb.append(toHtml("\n"));
     sb.append(formatter.label("errors"));
   }
   return sb.toString();
 }
Esempio n. 4
0
  private void processXml(Node operation)
      throws ParserConfigurationException, TransformerConfigurationException {
    List<Node> targets = getChildNodes(operation, "target");
    List<Node> appendOpNodes = getChildNodes(operation, "append");
    List<Node> setOpNodes = getChildNodes(operation, "set");
    List<Node> replaceOpNodes = getChildNodes(operation, "replace");
    List<Node> removeOpNodes = getChildNodes(operation, "remove");
    if (targets.isEmpty()) {
      return;
    }
    for (int t = 0; t < targets.size(); t++) {
      File target = new File(absolutePath(targets.get(t).getTextContent()));
      if (!target.exists()) {
        Utils.onError(new Error.FileNotFound(target.getPath()));
        return;
      }
      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = null;
      try {
        doc = db.parse(target);
      } catch (Exception ex) {
        Utils.onError(new Error.FileParse(target.getPath()));
        return;
      }
      for (int i = 0; i < removeOpNodes.size(); i++) removeXmlEntry(doc, removeOpNodes.get(i));
      for (int i = 0; i < replaceOpNodes.size(); i++) replaceXmlEntry(doc, replaceOpNodes.get(i));
      for (int i = 0; i < setOpNodes.size(); i++) setXmlEntry(doc, setOpNodes.get(i));
      for (int i = 0; i < appendOpNodes.size(); i++) appendXmlEntry(doc, appendOpNodes.get(i));

      try {
        OutputFormat format = new OutputFormat(doc);
        format.setOmitXMLDeclaration(true);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(4);
        Writer out = new FileWriter(target);
        XMLSerializer serializer = new XMLSerializer(out, format);
        serializer.serialize(doc);
      } catch (IOException e) {
        Utils.onError(new Error.WriteXmlConfig(target.getPath()));
      }
    }
  }
Esempio n. 5
0
 private static void assertEqualList(List<?> a, Collection<?> b) {
   if (a.size() == b.size()) {
     for (Object x : a) {
       if (!b.contains(x))
         throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
     }
     return;
   }
   throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
 }
Esempio n. 6
0
  public EvaluationResult evaluate(List<Evaluatable> inputs, EvaluationCtx context) {

    // Evaluate the arguments
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues);
    if (result != null) {
      return result;
    }

    switch (getFunctionId()) {
      case ID_XPATH_NODE_COUNT:
        {
          XPathAttribute xpathAttribute = ((XPathAttribute) argValues[0]);
          String xpathValue = xpathAttribute.getValue();
          String category = xpathAttribute.getXPathCategory();

          Node contextNode = null;

          // this must be XACML 3
          Set<Attributes> attributesSet = ((XACML3EvaluationCtx) context).getAttributes(category);
          if (attributesSet != null) {
            // only one attributes can be there
            Attributes attributes = attributesSet.iterator().next();
            contextNode = attributes.getContent();
          }

          if (contextNode != null) {
            // now apply XPath
            try {
              NodeList nodeList = getXPathResults(contextNode, xpathValue);
              return new EvaluationResult(new IntegerAttribute(nodeList.getLength()));
            } catch (XPathExpressionException e) {
              List<String> codes = new ArrayList<String>();
              codes.add(Status.STATUS_SYNTAX_ERROR);
              Status status = new Status(codes, e.getMessage());
              return new EvaluationResult(status);
            }
          }
        }

      case ID_XPATH_NODE_EQUAL:
        {
          // TODO
        }
    }

    List<String> codes = new ArrayList<String>();
    codes.add(Status.STATUS_SYNTAX_ERROR);
    Status status = new Status(codes, "Not supported function");
    return new EvaluationResult(status);
  }
Esempio n. 7
0
 /** Given an input string, level, and optionally a tag length, find a matching prefix. */
 private PrefixMatch findPrefixMatch(
     String input, TagLengthList tagLength, LevelTypeList level_type) {
   List<PrefixMatch> match_list = new ArrayList<PrefixMatch>();
   PrefixTree<PrefixMatch> tree = prefix_tree_map.get(level_type);
   assert tree != null;
   List<PrefixMatch> list = tree.search(input);
   if (!list.isEmpty()) {
     if (tagLength == null) match_list.addAll(list);
     else {
       for (PrefixMatch match : list)
         if (match.getScheme().getTagLength() == tagLength) match_list.add(match);
     }
   }
   if (match_list.isEmpty())
     throw new TDTException("No schemes or levels matched the input value");
   else if (match_list.size() > 1)
     throw new TDTException("More than one scheme/level matched the input value");
   else return match_list.get(0);
 }
Esempio n. 8
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. 9
0
 public int getCount() {
   synchronized (libraryList) {
     return libraryList.size();
   }
 }