org.joox.Match.xpath()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(149)

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

Match.xpath介绍

[英]Get an XPath expression describing the first element in the current set of matched elements

This is the same as calling xpath(0)
[中]获取描述当前匹配元素集中第一个元素的XPath表达式
这与呼叫xpath(0)相同

代码示例

代码示例来源:origin: io.teecube.t3/t3-common

public static List<Lifecycle<Phase>> parse(File componentsFile, MavenProject project, MavenSession session) throws SAXException, IOException {
  List<Lifecycle<Phase>> lifecycles = new ArrayList<Lifecycle<Phase>>();
  Match lifecyclesElements;
  lifecyclesElements = JOOX.$(componentsFile).xpath("//component[implementation='org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping']");
  for (Element element : lifecyclesElements) {
    List<Phase> phases = new ArrayList<Phase>();
    Match phasesElements = JOOX.$(element).xpath("configuration/phases/*");
    for (Element phase : phasesElements) {
      phases.add(new Phase(phase.getNodeName(), phase.getTextContent(), project, session));
    }
    lifecycles.add(new Lifecycle<Phase>(JOOX.$(element).xpath("role-hint").text(), phases));
  }
  return lifecycles;
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private List<Lifecycle> parseLifecycles(File componentsFile) throws SAXException, IOException {
  List<Lifecycle> lifecycles = new ArrayList<GenerateLifecyclesDocMojo.Lifecycle>();
  Match lifecyclesElements;
  lifecyclesElements = JOOX.$(componentsFile).xpath("//component[implementation='org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping']");
  for (Element element : lifecyclesElements) {
    List<Phase> phases = new ArrayList<GenerateLifecyclesDocMojo.Phase>();
    Match phasesElements = JOOX.$(element).xpath("configuration/phases/*");
    for (Element phase : phasesElements) {
      phases.add(new Phase(phase.getNodeName(), phase.getTextContent(), project, session));
    }
    lifecycles.add(new Lifecycle(JOOX.$(element).xpath("role-hint").text(), phases));
  }
  return lifecycles;
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void fixLinks(File htmlFile) throws Exception {
  Match document = JOOX.$(htmlFile);
  Match lists = document.xpath("//a");
  for (org.w3c.dom.Element element : lists) {
    Attr href = element.getAttributeNode("href");
    if (href != null) {
      String value = href.getValue();
      if (value != null) {
        href.setValue(value.replaceAll("(?<!(http:|https:))[//]+", "/"));
      }
    }
  }
  printDocument(document.document(), htmlFile);
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void removeIgnoredParameters(File htmlFile) throws Exception {
  Match document = JOOX.$(htmlFile);
  // remove ignored parameters
  Match td = document.xpath("//tr[./td/b/a/@href='#ignoredParameters']");
  td.remove();
  Match hre = document.xpath("//p[./b/a/@name='ignoredParameters']/following-sibling::hr[1]");
  hre.remove();
  Match ul = document.xpath("//p[./b/a/@name='ignoredParameters']/following-sibling::ul[1]");
  ul.remove();
  Match div = document.xpath("//p[./b/a/@name='ignoredParameters']/following-sibling::div[1]");
  div.remove();
  Match p = document.xpath("//p[./b/a/@name='ignoredParameters']");
  p.remove();
  printDocument(document.document(), htmlFile);
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void fixFooter(File htmlFile) throws Exception  {
  Match document = JOOX.$(htmlFile);
  // add non endorsement warning
  document.xpath("//p[@class='copyright']").prepend(this.getPropertyValue("nonEndorsement") + "<br />");
  Match version = JOOX.$(JOOX.$(document.xpath("//p[@class='version-date']").get(0)));
  // add time to the date if we are in SNAPSHOT version
  Element projectVersion = version.xpath("//span[@class='projectVersion']").get(0);
  if (projectVersion != null && projectVersion.getTextContent().contains("SNAPSHOT")) {
    Element publishDate = version.xpath("//span[@class='publishDate']").get(0);
    if (publishDate != null) {
      Calendar cal = Calendar.getInstance();
      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
      publishDate.setTextContent(publishDate.getTextContent().substring(0, publishDate.getTextContent().length()-2) + " " + sdf.format(cal.getTime()));
    }
  }
  printDocument(document.document(), htmlFile);
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void fixAutoclosingElements(Document domDocument) {
  try {
    Match document = JOOX.$(domDocument);
    Match lists = document.xpath(autoclosingElements).filter(new Filter() {
      @Override
      public boolean filter(Context context) {
        return (context.element().getFirstChild() == null); // with no child element (so autoclosing)
      }
    });
    for (org.w3c.dom.Element element : lists) {
      if ("script".equals(element.getNodeName())) {
        element.appendChild(document.document().createTextNode("// preserve auto-closing elements"));
      } else {
        element.appendChild(document.document().createComment("preserve auto-closing elements"));
      }
    }
  } catch (Exception e) {
    // nothing to do
  }
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void addSocial(File htmlFile) throws Exception {
  String socialLinks = this.getPropertyValue("socialLinks");
  if (socialLinks == null || socialLinks.isEmpty()) {
    return;
  }
  Match document = JOOX.$(htmlFile);
  // add non endorsement warning
  document.xpath("//ul[@class='nav pull-right']").prepend(socialLinks);
  printDocument(document.document(), htmlFile);
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

private void processCommandLines(File htmlFile) throws Exception {
  Match document = JOOX.$(htmlFile);
  Match lists = document.xpath("//div[@class='command']");
  for (Iterator<Element> iterator = lists.iterator(); iterator.hasNext();) {
    Element element = (Element) iterator.next();
    Match command = fullCommand.xpath("//span[@id='command']");
    Match arguments = fullCommand.xpath("//span[@class='argument']");
    Match results = fullCommand.xpath("//span[@class='result']");
    Match t = fullCommand.xpath("//div[@class='command']");
    String title = null;
    if (t != null && t.get(0) != null) {

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

@Override
public void processHTMLFile(File htmlFile) throws Exception {
  addHTMLEntities(htmlFile);
  Match document;
  Match reportsMenu;
  Match infosMenu;
  try {
    document = JOOX.$(htmlFile);
    reportsMenu = document.xpath("//div[@id='top-nav-collapse']/ul/li/ul/li[a/@title='Project Reports']");
    infosMenu = document.xpath("//div[@id='top-nav-collapse']/ul/li/ul/li[a/@title='Project Information']");
  } catch (Exception e) {
    removeHTMLEntities(htmlFile);
    return;
  }
  replaceByLine(htmlFile, "<li class=\"disabled\"><a title=\"#reports\">#reports</a></li>", reportsMenu.content());
  replaceByLine(htmlFile, "<li class=\"disabled\"><a title=\"#infos\">#infos</a></li>", infosMenu.content());
  document = JOOX.$(htmlFile);
  document.xpath("//div[@id='top-nav-collapse']/ul/li[ul/li[a/@title='Project Reports']][2]").remove();
  document.xpath("//footer/div/div/div/ul/li[a/@title='#infos']").remove();
  document.xpath("//footer/div/div/div/ul/li[a/@title='#reports']").remove();
  printDocument(document.document(), htmlFile);
  removeHTMLEntities(htmlFile);
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

@Override
public void processHTMLFile(File htmlFile) throws Exception {
  if ("maven-archetype".equals(project.getPackaging()) || "pom".equals(project.getPackaging())) {
    addHTMLEntities(htmlFile);
    Match document = JOOX.$(htmlFile);
    try {
      document.xpath("//div[@class='main-body']/div[@class='row']/div[@class='span8']").attr("class", "span12");
    } catch (Exception e) {
      removeHTMLEntities(htmlFile);
      return;
    }
    getLog().debug(project.getPackaging());
    getLog().debug(htmlFile.getAbsolutePath());
    printDocument(document.document(), htmlFile);
    if ("maven-archetype".equals(project.getPackaging())) {
      HtmlCanvas html = getArchetypeSection();
      replaceByLine(htmlFile,
        "<div class=\"body-content\">.*</p></div>",
        "<div class=\"body-content\">" + html.toHtml() + "</div>");
    }
    removeHTMLEntities(htmlFile);
  }
}

代码示例来源:origin: io.teecube.t3/t3-site-enhancer

if (parameter.description().equals(parameter.property())) continue;
Match td = document.xpath("//tr[./td/b/a/@href='#" + ((ParameterImpl)parameter).field() + "']/td[4]");
String content = td.content();
content = content.replace("(no description)", parameter.description());
td.content(content);
Match div = document.xpath("//p[./b/a/@name='" + ((ParameterImpl)parameter).field() + "']/following-sibling::div[1]");
div.content(parameter.description());

代码示例来源:origin: org.jboss.windup.rules/rules-impl

String clzPkg = $(doc).xpath("/hibernate-mapping").attr("package");
String clzName = $(doc).xpath("/hibernate-mapping/class").attr("name");
String tableName = $(doc).xpath("/hibernate-mapping/class").attr("table");
String schemaName = $(doc).xpath("/hibernate-mapping/class").attr("schema");
String catalogName = $(doc).xpath("/hibernate-mapping/class").attr("catalog");

代码示例来源:origin: org.jboss.windup.rules/rules-impl

.xpath("/s:beans").get().get(0);

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java-ee

String clzPkg = $(doc).xpath("/hibernate-mapping").attr("package");
String clzName = $(doc).xpath("/hibernate-mapping/class").attr("name");
String tableName = $(doc).xpath("/hibernate-mapping/class").attr("table");
String schemaName = $(doc).xpath("/hibernate-mapping/class").attr("schema");
String catalogName = $(doc).xpath("/hibernate-mapping/class").attr("catalog");

代码示例来源:origin: org.jboss.windup.rules.apps/windup-rules-java-ee

String clzPkg = $(doc).xpath("/hibernate-mapping").attr("package");
String clzName = $(doc).xpath("/hibernate-mapping/class").attr("name");
String tableName = $(doc).xpath("/hibernate-mapping/class").attr("table");
String schemaName = $(doc).xpath("/hibernate-mapping/class").attr("schema");
String catalogName = $(doc).xpath("/hibernate-mapping/class").attr("catalog");

代码示例来源:origin: windup/windup

String clzPkg = $(doc).xpath("/hibernate-mapping").attr("package");
String clzName = $(doc).xpath("/hibernate-mapping/class").attr("name");
String tableName = $(doc).xpath("/hibernate-mapping/class").attr("table");
String schemaName = $(doc).xpath("/hibernate-mapping/class").attr("schema");
String catalogName = $(doc).xpath("/hibernate-mapping/class").attr("catalog");

代码示例来源:origin: org.jboss.windup.rules.apps/rules-java-ee

.xpath("/s:beans").get();

代码示例来源:origin: org.jboss.windup.rules.apps/windup-rules-java-ee

.xpath("/s:beans").get();

代码示例来源:origin: windup/windup

.xpath("/s:beans").get();

相关文章