com.thoughtworks.xstream.io.xml.xppdom.XppDom类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中com.thoughtworks.xstream.io.xml.xppdom.XppDom类的一些代码示例,展示了XppDom类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XppDom类的具体详情如下:
包路径:com.thoughtworks.xstream.io.xml.xppdom.XppDom
类名称:XppDom

XppDom介绍

[英]Simple Document Object Model for XmlPullParser implementations.
[中]用于XmlPullParser实现的简单文档对象模型。

代码示例

代码示例来源:origin: com.thoughtworks.xstream/xstream

private int compareInternal(final XppDom dom1, final XppDom dom2,
  final StringBuffer xpath, final int count) {
  final int pathlen = xpath.length();
  final String name = dom1.getName();
  int s = name.compareTo(dom2.getName());
  xpath.append(name);
  if (count >= 0) {
  final String[] attributes = dom1.getAttributeNames();
  final String[] attributes2 = dom2.getAttributeNames();
  final int len = attributes.length;
  s = attributes2.length - len;
    s = dom1.getAttribute(attribute).compareTo(dom2.getAttribute(attribute));
    if (s != 0) {
      xpath.append("[@").append(attribute).append(']');
  final int children = dom1.getChildCount();
  s = dom2.getChildCount() - children;
  if (s != 0) {
    xpath.append("::count(*)");
    if (dom1.getValue() != null || dom2.getValue() != null) {
      throw new IllegalArgumentException("XppDom cannot handle mixed mode at "
        + xpath
      final XppDom child1 = dom1.getChild(i);
      final XppDom child2 = dom2.getChild(i);
      final String child = child1.getName();
      if (!names.containsKey(child)) {

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected Object createNode(final String name) {
  final XppDom newNode = new XppDom(encodeNode(name));
  final XppDom top = top();
  if (top != null) {
    top().addChild(newNode);
  }
  return newNode;
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

if (depth > 0) {
  XppDom parent = (XppDom)elements.get(depth - 1);
  parent.addChild(child);
  String name = parser.getAttributeName(i);
  String value = parser.getAttributeValue(i);
  child.setAttribute(name, value);
finalNode.setValue(finishedValue);
if (0 == depth) {
  node = finalNode;

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String getAttribute(int index) {
  return currentElement.getAttribute(currentElement.getAttributeNames()[index]);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String peekNextChild() {
  if (currentElement.getChildCount() == 0) {
    return null;
  }
  return decodeNode(currentElement.getChild(0).getName());
}

代码示例来源:origin: senbox-org/snap-desktop

void AssignDisplayParameters(final XppDom presentationXML) {
  XppDom nodeElem = null;
  for (XppDom elem : presentationXML.getChildren()) {
    final String id = elem.getAttribute("id");
    if (id != null && id.equals(node.getId())) {
      nodeElem = elem;
      break;
    }
  }
  if (nodeElem == null) {
    presentationXML.addChild(displayParameters);
  }
  XppDom dpElem = displayParameters.getChild("displayPosition");
  if (dpElem == null) {
    dpElem = new XppDom("displayPosition");
    displayParameters.addChild(dpElem);
  }
  dpElem.setAttribute("y", String.valueOf(displayPosition.getY()));
  dpElem.setAttribute("x", String.valueOf(displayPosition.getX()));
}

代码示例来源:origin: senbox-org/snap-desktop

private void setParamsToConfiguration(final XppDom config) {
  if (paramMap == null) return;
  final Set<String> keys = paramMap.keySet();                     // The set of keys in the map.
  for (String key : keys) {
    final Object value = paramMap.get(key);             // Get the value for that key.
    if (value == null) continue;
    XppDom xml = config.getChild(key);
    if (xml == null) {
      xml = new XppDom(key);
      config.addChild(xml);
    }
    xml.setValue(value.toString());
  }
}

代码示例来源:origin: senbox-org/snap-desktop

private void AssignAllParameters() throws GraphException {
  final XppDom presentationXML = new XppDom("Presentation");
  // save graph description
  final XppDom descXML = new XppDom("Description");
  descXML.setValue(graphDescription);
  presentationXML.addChild(descXML);
  graphNodeList.assignParameters(presentationXML);
  graph.setAppData("Presentation", presentationXML);
}

代码示例来源:origin: bcdev/beam

public void testReadFromXMLWithAppData() throws Exception {
  String expectedXML =
      "<graph id=\"myOneNodeGraph\">\n" +
          "  <version>1.0</version>\n" +
          "  <node id=\"node1\">\n" +
          "    <operator>Op1</operator>\n" +
          "    <sources/>\n" +
          "  </node>\n" +
          " <applicationData id=\"foo\">\n" +
          "    <font>Big</font>\n" +
          "    <colour>red</colour>\n" +
          " </applicationData>\n" +
          " <applicationData id=\"bar\">\n" +
          "    <textmode>true</textmode>\n" +
          " </applicationData>\n" +
          "</graph>";
  StringReader reader = new StringReader(expectedXML);
  Graph graph = GraphIO.read(reader);
  XppDom fooData = graph.getApplicationData("foo");
  assertNotNull(fooData);
  assertEquals(2, fooData.getChildCount());
  assertEquals("Big", fooData.getChild("font").getValue());
  assertEquals("red", fooData.getChild("colour").getValue());
  XppDom barData = graph.getApplicationData("bar");
  assertNotNull(barData);
  assertEquals(1, barData.getChildCount());
  assertEquals("true", barData.getChild("textmode").getValue());
}

代码示例来源:origin: senbox-org/snap-desktop

@Test
  public void testEscapingXmlParameters() throws Exception {
    DefaultDomElement domElement = new DefaultDomElement("parameter");
    String unescapedString = "12 < 13 && 56 > 42 & \"true\" + 'a name'";
    String escapedString = "12 &lt; 13 &amp;&amp; 56 &gt; 42 &amp; &quot;true&quot; + &apos;a name&apos;";

    domElement.addChild(new DefaultDomElement("expression", unescapedString));
    DefaultDomElement withAttribute = new DefaultDomElement("withAttribute");
    withAttribute.setAttribute("attrib", unescapedString);
    domElement.addChild(withAttribute);

    OperatorMenu.escapeXmlElements(domElement);

    assertEquals(escapedString, domElement.getChild("expression").getValue());
    assertEquals(escapedString, domElement.getChild("withAttribute").getAttribute("attrib"));

    String xmlString = domElement.toXml();
    XppDom readDomElement = OperatorMenu.createDom(xmlString);

    assertEquals(unescapedString, readDomElement.getChild("expression").getValue());
    assertEquals(unescapedString, readDomElement.getChild("withAttribute").getAttribute("attrib"));
  }
}

代码示例来源:origin: senbox-org/snap-desktop

void setDisplayParameters(final XppDom presentationXML) {
  for (XppDom params : presentationXML.getChildren()) {
    final String id = params.getAttribute("id");
    if (id != null && id.equals(node.getId())) {
      displayParameters = params;
      final XppDom dpElem = displayParameters.getChild("displayPosition");
      if (dpElem != null) {
        displayPosition.x = (int) Float.parseFloat(dpElem.getAttribute("x"));
        displayPosition.y = (int) Float.parseFloat(dpElem.getAttribute("y"));
      }
      return;
    }
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String getValue() {
  String text = null;
  try {
    text = currentElement.getValue();
  } catch (Exception e) {
    // do nothing.
  }
  return text == null ? "" : text;
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected Object getChild(int index) {
  return currentElement.getChild(index);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

/**
   * @deprecated As of 1.4, use {@link XppDom#build(XmlPullParser)} instead
   */
  public static Xpp3Dom build(Reader reader) throws Exception {
    XmlPullParser parser = new MXParser();
    parser.setInput(reader);
    try {
      return (Xpp3Dom)XppDom.build(parser);
    } finally {
      reader.close();
    }
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void setValue(final String text) {
  top().setValue(text);
}

代码示例来源:origin: senbox-org/snap-desktop

public void setGraph(final Graph graphFromFile, final boolean addUI) throws GraphException {
  if (graphFromFile != null) {
    graph = graphFromFile;
    graphNodeList.clear();
    final XppDom presentationXML = graph.getApplicationData("Presentation");
    if (presentationXML != null) {
      // get graph description
      final XppDom descXML = presentationXML.getChild("Description");
      if (descXML != null && descXML.getValue() != null) {
        graphDescription = descXML.getValue();
      }
    }
    final Node[] nodes = graph.getNodes();
    for (Node n : nodes) {
      final GraphNode newGraphNode = new GraphNode(n);
      if (presentationXML != null)
        newGraphNode.setDisplayParameters(presentationXML);
      graphNodeList.add(newGraphNode);
      if (addUI) {
        OperatorUI ui = OperatorUIRegistry.CreateOperatorUI(newGraphNode.getOperatorName());
        if (ui == null) {
          throw new GraphException("Unable to load " + newGraphNode.getOperatorName());
        }
        newGraphNode.setOperatorUI(ui);
      }
      notifyGraphEvent(new GraphEvent(events.ADD_EVENT, newGraphNode));
    }
  }
}

代码示例来源:origin: senbox-org/snap-desktop

public GraphNode(final Node n) throws IllegalArgumentException {
  node = n;
  displayParameters = new XppDom("node");
  displayParameters.setAttribute("id", node.getId());
  initParameters();
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void addAttribute(final String key, final String value) {
  top().setAttribute(encodeAttribute(key), value);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String getAttribute(String attributeName) {
  return currentElement.getAttribute(encodeAttribute(attributeName));
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected int getChildCount() {
  return currentElement.getChildCount();
}

相关文章