gpt4 book ai didi

org.xembly.Xembler类的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 12:01:05 28 4
gpt4 key购买 nike

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

Xembler介绍

[英]Processor of Xembly directives, main entry point to the package.

For example, to modify a DOM document:

Document dom = DocumentBuilderFactory.newInstance() 
.newDocumentBuilder().newDocument(); 
dom.appendChild(dom.createElement("root")); 
new Xembler( 
new Directives() 
.xpath("/root") 
.addIfAbsent("employees") 
.add("employee") 
.attr("id", 6564) 
).apply(dom);

You can also convert your Xembly directives directly to XML document:

String xml = new Xembler( 
new Directives() 
.xpath("/root") 
.addIfAbsent("employees") 
.add("employee") 
.attr("id", 6564) 
).xml("root");

Since version 0.18 you can convert directives to XML without a necessity to catch checked exceptions. Use *Quietly() methods for that: #xmlQuietly(), #domQuietly(), and #applyQuietly(org.w3c.dom.Node).
[中]Xembly指令的处理器,包的主要入口点。
例如,要修改DOM文档:

Document dom = DocumentBuilderFactory.newInstance() 
.newDocumentBuilder().newDocument(); 
dom.appendChild(dom.createElement("root")); 
new Xembler( 
new Directives() 
.xpath("/root") 
.addIfAbsent("employees") 
.add("employee") 
.attr("id", 6564) 
).apply(dom);

还可以将Xembly指令直接转换为XML文档:

String xml = new Xembler( 
new Directives() 
.xpath("/root") 
.addIfAbsent("employees") 
.add("employee") 
.attr("id", 6564) 
).xml("root");

自版本0.18以来,您可以将指令转换为XML,而无需捕获已检查的异常。为此使用*quilly()方法:#xmlquilly()、#domquilly()和#applyquilly(org.w3c.dom.Node)。

代码示例

代码示例来源:origin: jcabi/jcabi-github

@Override
public void apply(
  final Iterable<Directive> dirs
) throws IOException {
  synchronized (this.name) {
    FileUtils.write(
      new File(this.name),
      new XMLDocument(
        new Xembler(dirs).applyQuietly(this.xml().node())
      ).toString(),
      StandardCharsets.UTF_8
    );
  }
}
@Override

代码示例来源:origin: com.jcabi.incubator/xembly

/**
 * Convert to XML document, without checked exceptions.
 * @return XML document
 * @since 0.18
 */
public String xmlQuietly() {
  try {
    return this.xml();
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to build XML quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: yegor256/xembly

/**
 * Apply all changes to the document/node, without any checked exceptions.
 * @param dom DOM document/node
 * @return The same document/node
 * @since 0.18
 */
public Node applyQuietly(final Node dom) {
  try {
    return this.apply(dom);
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalArgumentException(
      String.format(
        "failed to apply to DOM quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: yegor256/s3auth

new XMLDocument(new Xembler(dirs).xml())
  ).toString().getBytes(Charsets.UTF_8);
} catch (final ImpossibleModificationException ex) {

代码示例来源:origin: etsy/arbiter

new Xembler(directives).apply(xmlDoc);
} catch (ImpossibleModificationException e) {
  throw new RuntimeException(e);

代码示例来源:origin: yegor256/jpeek

new Xembler(new Index(this.output)).xmlQuietly()
App.xsl("badge.xsl").transform(
  new XMLDocument(
    new Xembler(
      new Directives().add("badge").set(
        index.xpath("/index/@score").get(0)
      ).attr("style", "round")
    ).xmlQuietly()
App.xsl("matrix-post.xsl").transform(
  new XMLDocument(
    new Xembler(new Matrix(this.output)).xmlQuietly()

代码示例来源:origin: com.jcabi.incubator/xembly

/**
 * Apply all changes to an empty DOM, without checked exceptions.
 * @return DOM created
 * @since 0.18
 */
public Document domQuietly() {
  try {
    return this.dom();
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to create DOM quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: yegor256/s3auth

new XMLDocument(new Xembler(dirs).xml())
  ).toString().getBytes(Charsets.UTF_8);
} catch (final ImpossibleModificationException ex) {

代码示例来源:origin: yegor256/jpeek

final XML xml = new StrictXML(
  new XMLDocument(
    new Xembler(
      new Directives()
        .add("skeleton")
    ).xmlQuietly()
  ),
  Skeleton.SCHEMA

代码示例来源:origin: yegor256/xembly

/**
 * Apply all changes to an empty DOM, without checked exceptions.
 * @return DOM created
 * @since 0.18
 */
public Document domQuietly() {
  try {
    return this.dom();
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to create DOM quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: yegor256/takes

/**
 * Render source as XML.
 * @param dom DOM node to build upon
 * @param src Source
 * @return XML
 * @throws IOException If fails
 */
private static InputStream render(final Node dom,
  final XeSource src) throws IOException {
  final Node copy = cloneNode(dom);
  final ByteArrayOutputStream baos =
    new ByteArrayOutputStream();
  final Node node = new Xembler(src.toXembly()).applyQuietly(copy);
  try {
    TransformerFactory.newInstance().newTransformer().transform(
      new DOMSource(node),
      new StreamResult(
        new Utf8OutputStreamWriter(baos)
      )
    );
  } catch (final TransformerException ex) {
    throw new IllegalStateException(ex);
  }
  return new ByteArrayInputStream(baos.toByteArray());
}

代码示例来源:origin: com.rempl/rempl

@Override
public void save(final OutputStream output) throws IOException {
  final Directives dirs = new Directives().add("xmi");
  for (final Instance instance : this.instances) {
    dirs.add("instance").add("slots");
    for (final String slot : instance.slots()) {
      dirs.add("slot").add("key").set(slot).up()
        .add("value").set(instance.get(slot)).up().up();
    }
    dirs.up().add("name").set(instance.name()).up()
      .add("type").set(instance.type()).up().up();
  }
  try {
    IOUtils.write(
      new Xembler(dirs).xml().toString().getBytes(Charsets.UTF_8),
      output
    );
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalStateException(ex);
  }
}

代码示例来源:origin: yegor256/xembly

/**
 * Convert to XML document, without checked exceptions.
 * @return XML document
 * @since 0.18
 */
public String xmlQuietly() {
  try {
    return this.xml();
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to build XML quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: com.jcabi.incubator/xembly

/**
 * Apply all changes to the document/node, without any checked exceptions.
 * @param dom DOM document/node
 * @return The same document/node
 * @since 0.18
 */
public Node applyQuietly(final Node dom) {
  try {
    return this.apply(dom);
  } catch (final ImpossibleModificationException ex) {
    throw new IllegalArgumentException(
      String.format(
        "failed to apply to DOM quietly: %s",
        this.directives
      ),
      ex
    );
  }
}

代码示例来源:origin: com.jcabi.incubator/xembly

try {
  transformer.transform(
    new DOMSource(this.dom()),
    new StreamResult(writer)
  );

代码示例来源:origin: org.takes/takes

/**
 * Render source as XML.
 * @param dom DOM node to build upon
 * @param src Source
 * @return XML
 * @throws IOException If fails
 */
private static InputStream render(final Node dom,
  final XeSource src) throws IOException {
  final Node copy = cloneNode(dom);
  final ByteArrayOutputStream baos =
    new ByteArrayOutputStream();
  final Node node = new Xembler(src.toXembly()).applyQuietly(copy);
  try {
    TransformerFactory.newInstance().newTransformer().transform(
      new DOMSource(node),
      new StreamResult(
        new Utf8OutputStreamWriter(baos)
      )
    );
  } catch (final TransformerException ex) {
    throw new IllegalStateException(ex);
  }
  return new ByteArrayInputStream(baos.toByteArray());
}

代码示例来源:origin: com.jcabi.incubator/xembly

/**
 * Apply all changes to an empty DOM.
 * @return DOM created
 * @throws ImpossibleModificationException If can't modify
 * @since 0.9
 */
public Document dom() throws ImpossibleModificationException {
  final Document dom;
  try {
    dom = Xembler.BFACTORY.newDocumentBuilder().newDocument();
  } catch (final ParserConfigurationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to obtain a new DOM document from %s",
        Xembler.BFACTORY.getClass().getCanonicalName()
      ),
      ex
    );
  }
  this.apply(dom);
  return dom;
}

代码示例来源:origin: yegor256/xembly

try {
  transformer.transform(
    new DOMSource(this.dom()),
    new StreamResult(writer)
  );

代码示例来源:origin: yegor256/jpeek

new Xembler(
    new Directives()
      .xpath("/metric")
      .add("defects")
      .set(Double.toString(defects / total)).up()
  ).applyQuietly(xml.node())
);

代码示例来源:origin: yegor256/xembly

/**
 * Apply all changes to an empty DOM.
 * @return DOM created
 * @throws ImpossibleModificationException If can't modify
 * @since 0.9
 */
public Document dom() throws ImpossibleModificationException {
  final Document dom;
  try {
    dom = Xembler.BFACTORY.newDocumentBuilder().newDocument();
  } catch (final ParserConfigurationException ex) {
    throw new IllegalStateException(
      String.format(
        "failed to obtain a new DOM document from %s",
        Xembler.BFACTORY.getClass().getCanonicalName()
      ),
      ex
    );
  }
  this.apply(dom);
  return dom;
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com