本文整理汇总了Java中groovy.util.slurpersupport.GPathResult类的典型用法代码示例。如果您正苦于以下问题:Java GPathResult类的具体用法?Java GPathResult怎么用?Java GPathResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GPathResult类属于groovy.util.slurpersupport包,在下文中一共展示了GPathResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gpath
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
/**
* Matches according to GPath.
*/
public Closure<Boolean> gpath(final String condition) throws TestException {
return new Closure<Boolean>(this, this) {
@Override
public Boolean call(Object request) {
try {
GPathResult gpathRequest = new XmlSlurper().parseText(request.toString());
Binding binding = getBinding();
binding.setVariable("request", gpathRequest);
return (Boolean) new GroovyShell(binding).evaluate(condition);
}
catch (Exception ex) {
ex.printStackTrace(getTestCaseRun().getLog());
getTestCaseRun().getLog().println("Failed to parse request as XML/JSON. Stub response: " + AdapterActivity.MAKE_ACTUAL_CALL);
return false;
}
}
};
}
示例2: locate
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
@Override
public GPathResult locate(GPathResult root, OfflineOptions options) throws Exception {
boolean domain = Type.of(root) == Type.DOMAIN;
Script script = (Script) (
domain ? DOMAIN_SCRIPT_CLASS.newInstance() : STANDALONE_OR_HOST_SCRIPT_CLASS.newInstance()
);
script.setProperty("root", root);
if (domain) {
String defaultSocketBindingGroup = options.defaultProfile + "-sockets";
if ("default".equals(options.defaultProfile)) {
defaultSocketBindingGroup = "standard-sockets";
}
script.setProperty("defaultSocketBindingGroup", defaultSocketBindingGroup);
}
return (GPathResult) script.run();
}
示例3: getLauncherIcons
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
public static List<String> getLauncherIcons(File manifestFile)
throws SAXException, ParserConfigurationException, IOException {
GPathResult manifestXml = new XmlSlurper().parse(manifestFile);
GPathResult applicationNode = (GPathResult) manifestXml.getProperty("application");
String icon = String.valueOf(applicationNode.getProperty("@android:icon"));
String roundIcon = String.valueOf(applicationNode.getProperty("@android:roundIcon"));
List<String> icons = new ArrayList<>(2);
if (!icon.isEmpty()) {
icons.add(icon);
}
if (!roundIcon.isEmpty()) {
icons.add(roundIcon);
}
return unmodifiableList(icons);
}
示例4: parseProject
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
@Override
public AsProject parseProject(GPathResult gPathResult, String projectPath) {
AsProject project = ModelStorage.getInstance().getProject();
project.setPath(projectPath);
project.buildModel(gPathResult);
// Default settings
if (StringUtils.isEmpty(project.getProjectBuildSettings().sdkModel.getFlexSDKPath())) {
project.getProjectBuildSettings().sdkModel.setFlexSDKPath(ASPathUtils.getFlexSDKPath());
}
// Prepare dirs
project.initPaths();
return project;
}
示例5: asString
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
private static String asString(GPathResult node) {
// little bit of hackery to avoid Groovy dependency in this file
try {
Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance();
InvokerHelper.setProperty(builder, "encoding", "UTF-8");
Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node);
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString();
} catch (Exception e) {
return "Couldn't convert node to string because: " + e.getMessage();
}
}
示例6: getDocument
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
/**
* @return The GPathResult instance created by consuming a stream of SAX events
* Note if one of the parse methods has been called then this returns null
* Note if this is called more than once all calls after the first will return null
*/
public GPathResult getDocument() {
try {
// xml namespace is always defined
if (namespaceAware) {
namespaceTagHints.put("xml", "http://www.w3.org/XML/1998/namespace");
}
return new NodeChild(currentNode, null, namespaceTagHints);
} finally {
currentNode = null;
}
}
示例7: parse
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
/**
* Parses the content of the given file as XML turning it into a GPathResult object
*
* @param file the File to parse
* @return An object which supports GPath expressions
* @throws SAXException Any SAX exception, possibly wrapping another exception.
* @throws IOException An IO exception from the parser, possibly from a byte stream
* or character stream supplied by the application.
*/
public GPathResult parse(final File file) throws IOException, SAXException {
final FileInputStream fis = new FileInputStream(file);
final InputSource input = new InputSource(fis);
input.setSystemId("file://" + file.getAbsolutePath());
try {
return parse(input);
} finally {
fis.close();
}
}
示例8: of
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
public static Type of(GPathResult root) {
String rootElement = root.name();
if ("domain".equals(rootElement)) {
return Type.DOMAIN;
} else if ("host".equals(rootElement)) {
return Type.HOST;
} else if ("server".equals(rootElement)) {
return Type.SERVER;
} else {
throw new IllegalArgumentException("Unknown root node '" + rootElement + "'");
}
}
示例9: addIfMissing
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
void addIfMissing(GPathResult root, OfflineOptions options) {
boolean domain = Type.of(root) == Type.DOMAIN;
if (skipInDomain && domain) {
return;
}
try {
Script script = (Script) scriptClass.newInstance();
script.setProperty("root", root);
script.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例10: transformRawDataToGraphml
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
public void transformRawDataToGraphml(Reader in, Writer out) {
try {
GPathResult response = new XmlSlurper().parse(new InputSource(in));
Binding binding = new Binding();
binding.setProperty("input", response);
binding.setProperty("output", out);
// binding = new Binding();
// Expect4Groovy.createBindings(connection, binding, true);
// binding.setProperty("params", params);
// String gseRoots = new File().toURI().toURL().toString();
String[] roots = new String[]{projectPath+"/iDiscover/conf/groovy/"+File.separator};
GroovyScriptEngine gse = new GroovyScriptEngine(roots);
gse.run("RawData2GraphmlTransformer.groovy", binding);
// Class clazz = Class.forName(new File(projectPath,rawData2GraphmlGroovyTransformer).toURI().toURL().toString());
// Constructor constructor = clazz.getDeclaredConstructor(Binding.class);
// Script script = (Script) constructor.newInstance(binding);
// script.run();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: asXml
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
public static GPathResult asXml(String xml) {
try {
return (new XmlSlurper()).parseText(xml);
} catch (Exception e) {
throw new RuntimeException("invalid XML");
}
}
示例12: translate
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
private String translate(GPathResult root) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IndentPrinter printer = createIndentPrinter(baos);
walkXml(printer, (NodeChild) root);
printer.flush();
return baos.toString();
}
示例13: adapter
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
/**
* responder closure call is delayed until stub server calls back
*/
public TestCaseAdapterStub adapter(Closure<Boolean> matcher, Closure<String> responder, Closure<?> init) throws TestException {
final TestCaseAdapterStub adapterStub = new TestCaseAdapterStub(matcher, responder);
if (init != null) {
init.setResolveStrategy(Closure.DELEGATE_FIRST);
init.setDelegate(adapterStub);
init.call();
}
if (responder == null) {
adapterStub.setResponder(new Closure<String>(this, adapterStub) {
@Override
public String call(Object request) {
// binding for request
final TestCaseRun testCaseRun = getTestCaseRun();
if (adapterStub.getResponse().indexOf("${") >= 0) {
try {
Binding binding = getBinding();
if (request.toString().startsWith("{")) {
Object req = new JsonSlurper().parseText(request.toString());
binding.setVariable("request", req);
}
else {
GPathResult gpathRequest = new XmlSlurper().parseText(request.toString());
binding.setVariable("request", gpathRequest);
}
CompilerConfiguration compilerCfg = new CompilerConfiguration();
compilerCfg.setScriptBaseClass(DelegatingScript.class.getName());
GroovyShell shell = new GroovyShell(TestCaseScript.class.getClassLoader(), binding, compilerCfg);
shell.setProperty("out", testCaseRun.getLog());
DelegatingScript script = (DelegatingScript) shell.parse("return \"\"\"" + adapterStub.getResponse() + "\"\"\"");
script.setDelegate(TestCaseScript.this);
return script.run().toString();
}
catch (Exception ex) {
getTestCaseRun().getLog().println("Cannot perform stub substitutions for request: " + request);
ex.printStackTrace(getTestCaseRun().getLog());
}
}
return adapterStub.getResponse();
}
});
}
return adapterStub;
}
示例14: fromString
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
@Converter
public GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException {
return new XmlSlurper().parseText(input);
}
示例15: fromStringSource
import groovy.util.slurpersupport.GPathResult; //导入依赖的package包/类
@Converter
public GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException {
return fromString(input.getText());
}