当前位置: 首页>>代码示例>>Java>>正文


Java XmlSlurper类代码示例

本文整理汇总了Java中groovy.util.XmlSlurper的典型用法代码示例。如果您正苦于以下问题:Java XmlSlurper类的具体用法?Java XmlSlurper怎么用?Java XmlSlurper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlSlurper类属于groovy.util包,在下文中一共展示了XmlSlurper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gpath

import groovy.util.XmlSlurper; //导入依赖的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;
            }
        }
    };
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:22,代码来源:TestCaseScript.java

示例2: evaluate

import groovy.util.XmlSlurper; //导入依赖的package包/类
public Object evaluate(String expression, Map<String, Object> bindings)
throws ExecutionException {
    binding = new Binding();

    for (String bindName : bindings.keySet()) {
        Object value = bindings.get(bindName);
        DocumentReferenceTranslator docRefTranslator = getDocRefTranslator(value);
        if (docRefTranslator != null) {
            try {
                if (!(docRefTranslator instanceof XmlBeanWrapperTranslator)) {
                    value = new XmlSlurper().parseText(docRefTranslator.realToString(value));
                }
            }
            catch (Exception ex) {
                throw new ExecutionException("Cannot parse document content: '" + bindName + "'", ex);
            }
        }
        binding.setVariable(bindName, value);
    }

    return runScript(expression);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:23,代码来源:GroovyExecutor.java

示例3: getLauncherIcons

import groovy.util.XmlSlurper; //导入依赖的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);

}
 
开发者ID:maskarade,项目名称:gradle-android-ribbonizer-plugin,代码行数:20,代码来源:Resources.java

示例4: neckoParse

import groovy.util.XmlSlurper; //导入依赖的package包/类
/**
 * Method that provides an HTML parser for response configuration (uses necko parser).
 *
 * @param config the chained configuration
 * @param fromServer the server response adapter
 * @return the parsed HTML content (a {@link groovy.util.slurpersupport.GPathResult} object)
 */
public static Object neckoParse(final ChainedHttpConfig config, final FromServer fromServer) {
    try {
        final XMLReader p = new org.cyberneko.html.parsers.SAXParser();
        p.setEntityResolver(NativeHandlers.Parsers.catalogResolver);
        return new XmlSlurper(p).parse(new InputStreamReader(fromServer.getInputStream(), fromServer.getCharset()));
    } catch (IOException | SAXException ex) {
        throw new TransportingException(ex);
    }
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:17,代码来源:Html.java

示例5: getGPathParamValue

import groovy.util.XmlSlurper; //导入依赖的package包/类
private Object getGPathParamValue(String varName, String varType) throws ActivityException {
    Object value = super.getVariableValue(varName);
    com.centurylink.mdw.variable.VariableTranslator translator = VariableTranslator.getTranslator(getPackage(), varType);
    if (translator instanceof DocumentReferenceTranslator) {
        try {
            DocumentReferenceTranslator docRefTranslator = (DocumentReferenceTranslator) translator;
            outputDocumentWriter = new StringWriter();
            if (isOutputDocument(varName)) {
                if (value == null) {
                    MarkupBuilder builder = new MarkupBuilder(outputDocumentWriter);
                    builder.setDoubleQuotes(true);
                    value = builder;
                }
                else {
                    value = new XmlParser().parseText(docRefTranslator.realToString(value));
                }
            }
            else {
                value = new XmlSlurper().parseText(docRefTranslator.realToString(value));
            }
        }
        catch (Exception ex) {
            logger.severeException(ex.getMessage(), ex);
            throw new ActivityException(ex.getMessage(), ex);
        }
    }

    return value;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:30,代码来源:TransformActivity.java

示例6: xmlParser

import groovy.util.XmlSlurper; //导入依赖的package包/类
public static Object xmlParser(String xml){
  try {
    return (new XmlSlurper()).parseText(xml);
  } catch (Throwable e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:detectiveframework,项目名称:detective,代码行数:8,代码来源:Detective.java

示例7: transformRawDataToGraphml

import groovy.util.XmlSlurper; //导入依赖的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();
        }
    }
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:26,代码来源:GraphmlFileLogGroovyDiscoveryListener.java

示例8: asXml

import groovy.util.XmlSlurper; //导入依赖的package包/类
public static GPathResult asXml(String xml) {
    try {
        return (new XmlSlurper()).parseText(xml);
    } catch (Exception e) {
        throw new RuntimeException("invalid XML");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:8,代码来源:JavaExtensions.java

示例9: processTemplate

import groovy.util.XmlSlurper; //导入依赖的package包/类
public Source processTemplate(Source template, Source input, Map<String, Object> parameters) {
	try {
		String templateText = serialize(template);
		HashMap<String, Object>  binding = new HashMap<String, Object> (parameters);
		if (input!=null)
		{
			Document inputDocument = loadDocument(input);
			binding.put(inputDocument.getFirstChild().getLocalName(), new XmlSlurper().parse(new StringReader(serialize(inputDocument))));
		}
		binding.put("IGNORE", "${IGNORE}");
		return new StringSource(templateEngine.createTemplate(templateText).make(binding).toString());
	} catch (Exception e) {
		throw new IllegalArgumentException("Can not process Groovy template.",e);
	}
}
 
开发者ID:lukas-krecan,项目名称:smock,代码行数:16,代码来源:GroovyTemplateProcessor.java

示例10: newXmlSlurper

import groovy.util.XmlSlurper; //导入依赖的package包/类
private XmlSlurper newXmlSlurper() {
    try {
        return new XmlSlurper();
    } catch (ParserConfigurationException | SAXException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:aalmiray,项目名称:griffon2,代码行数:8,代码来源:Xml2Groovy.java

示例11: adapter

import groovy.util.XmlSlurper; //导入依赖的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;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:47,代码来源:TestCaseScript.java

示例12: fromString

import groovy.util.XmlSlurper; //导入依赖的package包/类
@Converter
public GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException {
    return new XmlSlurper().parseText(input);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:GPathResultConverter.java

示例13: newSlurper

import groovy.util.XmlSlurper; //导入依赖的package包/类
private XmlSlurper newSlurper() throws Exception {
    XmlSlurper slurper = new XmlSlurper(newSaxParser());
    slurper.setErrorHandler(getErrorHandler());
    slurper.setKeepWhitespace(isKeepWhitespace());
    return slurper;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:XmlSlurperDataFormat.java

示例14: getLauncherIcon

import groovy.util.XmlSlurper; //导入依赖的package包/类
public static String getLauncherIcon(File manifestFile)
        throws SAXException, ParserConfigurationException, IOException {
    GPathResult manifestXml = new XmlSlurper().parse(manifestFile);
    GPathResult applicationNode = (GPathResult) manifestXml.getProperty("application");
    return String.valueOf(applicationNode.getProperty("@android:icon"));
}
 
开发者ID:dagezi,项目名称:gradle-android-9patch-plugin,代码行数:7,代码来源:Resources.java

示例15: getMapOsm

import groovy.util.XmlSlurper; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public HashMap<String,Object> getMapOsm(String qString){
	HashMap<String,Object> result = new HashMap<String,Object>();
	try {
		BigDecimal latitude = BigDecimal.ZERO;
		BigDecimal longitude = BigDecimal.ZERO;
		RESTClient restClient = new RESTClient("http://nominatim.openstreetmap.org/");
		Map<String,Object> mapQuery = new HashMap<String,Object>();
		mapQuery.put("q", qString);
		mapQuery.put("format", "xml");
		mapQuery.put("polygon", true);
		mapQuery.put("addressdetails", true);
		Map<String,Object> mapHeaders = new HashMap<String,Object>();
		mapHeaders.put("HTTP referrer", "axelor");
		Map<String,Object> mapResponse = new HashMap<String,Object>();
		mapResponse.put("path", "/search");
		mapResponse.put("accept", ContentType.JSON);
		mapResponse.put("query", mapQuery);
		mapResponse.put("headers", mapHeaders);
		mapResponse.put("connectTimeout", 5000);
		mapResponse.put("readTimeout", 10000);
		mapResponse.put("followRedirects", false);
		mapResponse.put("useCaches", false);
		mapResponse.put("sslTrustAllCerts", true);
		Response restResponse = restClient.get(mapResponse);
		GPathResult searchresults = new XmlSlurper().parseText(restResponse.getContentAsString());
		Iterator<Node> iterator = searchresults.childNodes();
		if(iterator.hasNext()){
			Node node = iterator.next();
			Map attributes = node.attributes();
			if(attributes.containsKey("lat") && attributes.containsKey("lon")){
				if(BigDecimal.ZERO.compareTo(latitude) == 0)
					latitude = new BigDecimal(node.attributes().get("lat").toString());
				if(BigDecimal.ZERO.compareTo(longitude) == 0)
					longitude = new BigDecimal(node.attributes().get("lon").toString());
			}
		}
		
		LOG.debug("OSMap qString: {}, latitude: {}, longitude: {}", qString, latitude, longitude);
		
		if(BigDecimal.ZERO.compareTo(latitude) != 0 && BigDecimal.ZERO.compareTo(longitude) != 0){
			result.put("url","map/oneMarker.html?x="+latitude+"&y="+longitude+"&z=18");
			result.put("latitude", latitude);
			result.put("longitude",longitude);
			return result;
		}

	}catch(Exception e)  {
		TraceBackService.trace(e);
	}
	return null;
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:53,代码来源:MapService.java


注:本文中的groovy.util.XmlSlurper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。