Example usage for org.springframework.util.xml SimpleNamespaceContext bindNamespaceUri

List of usage examples for org.springframework.util.xml SimpleNamespaceContext bindNamespaceUri

Introduction

In this page you can find the example usage for org.springframework.util.xml SimpleNamespaceContext bindNamespaceUri.

Prototype

public void bindNamespaceUri(String prefix, String namespaceUri) 

Source Link

Document

Bind the given prefix to the given namespace.

Usage

From source file:com.seajas.search.utilities.web.WebPages.java

private XPath getXPathEngine() {
    XPath engine = xPathEngine;//w ww  .  j a  v a  2 s.  com
    if (engine == null) {
        XPathFactory factory = XPathFactory.newInstance();
        engine = factory.newXPath();
        SimpleNamespaceContext namespaces = new SimpleNamespaceContext();
        namespaces.bindNamespaceUri("ht", "http://www.w3.org/1999/xhtml");
        engine.setNamespaceContext(namespaces);
        xPathEngine = engine;
    }
    return engine;
}

From source file:cz.strmik.cmmitool.cmmi.DefaultRatingScalesProvider.java

private List<RatingScale> readScales(String id, String lang) {
    List<RatingScale> scales = new ArrayList<RatingScale>();
    try {// w ww .j  a  v  a 2  s  .co m
        Document document = getScalesDocument();

        XPathFactory factory = XPathFactory.newInstance();
        XPath xPath = factory.newXPath();

        SimpleNamespaceContext ns = new SimpleNamespaceContext();
        ns.bindNamespaceUri("s", SCALES_XML_NS);
        xPath.setNamespaceContext(ns);

        XPathExpression exprScales = xPath.compile("/s:ratings/s:rating[@id='" + id + "']/s:scale");
        XPathExpression exprName = xPath.compile("s:name[@lang='" + lang + "']");
        XPathExpression exprColor = xPath.compile("s:color[@type='html']");

        NodeList nodes = (NodeList) exprScales.evaluate(document, XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            int score = Integer.parseInt(node.getAttributes().getNamedItem("score").getTextContent());

            String name = exprName.evaluate(node);
            String color = exprColor.evaluate(node);
            RatingScale rs = new RatingScale(name, i, score, color);
            if (i == 0) {
                rs.setDefaultRating(true);
            }
            scales.add(rs);
        }
    } catch (Exception ex) {
        _log.warn(
                "Unable to load default scales for id=" + id + ",lang=" + lang + " ratings from " + SCALES_XML,
                ex);
    }
    return scales;
}

From source file:com.servicelibre.jxsl.scenario.test.xspec.XspecTestScenarioRunner.java

private void init() {

    XPath xpath = null;/*w ww  .java  2s. co m*/
    try {
        xpath = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath();
    } catch (XPathFactoryConfigurationException e1) {
        logger.error("Error while creating XPathFactory", e1);
        return;
    }

    SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
    namespaceContext.bindNamespaceUri("x", "http://www.jenitennison.com/xslt/xspec");
    xpath.setNamespaceContext(namespaceContext);

    try {

        successXpath = xpath.compile("count(//x:test[@successful ='false'] ) = 0");
        testFailedCount = xpath.compile("count(//x:test[@successful ='false'] )");
        testCount = xpath.compile("count(//x:test)");
    } catch (XPathExpressionException e) {
        logger.error("Error while initializing {}.", this.getClass().getName(), e);
    }

    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);

    try {
        xmlBuilder = docFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        logger.error("Error while configuring XML parser", e);
    }

}

From source file:com.consol.citrus.admin.service.ProjectService.java

/**
 * Loads Citrus project from project home.
 * @param projectHomeDir/*w  w w . ja v  a  2 s. co  m*/
 * @return
 */
public void load(String projectHomeDir) {
    Project project = new Project(projectHomeDir);
    if (project.getProjectInfoFile().exists()) {
        project.loadSettings();
    } else if (!validateProject(project)) {
        throw new ApplicationRuntimeException("Invalid project home - not a proper Citrus project");
    }

    if (project.isMavenProject()) {
        try {
            String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile()));
            SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
            nsContext.bindNamespaceUri("mvn", "http://maven.apache.org/POM/4.0.0");

            Document pomDoc = XMLUtils.parseMessagePayload(pomXml);
            project.setName(evaluate(pomDoc, "/mvn:project/mvn:artifactId", nsContext));

            String version = evaluate(pomDoc, "/mvn:project/mvn:version", nsContext);
            String parentVersion = evaluate(pomDoc, "/mvn:project/mvn:parent/mvn:version", nsContext);
            if (StringUtils.hasText(version)) {
                project.setVersion(version);
            } else if (StringUtils.hasText(parentVersion)) {
                project.setVersion(parentVersion);
            }

            project.getSettings().setBasePackage(evaluate(pomDoc, "/mvn:project/mvn:groupId", nsContext));

            String citrusVersion = evaluate(pomDoc, "/mvn:project/mvn:properties/mvn:citrus.version",
                    nsContext);
            if (StringUtils.hasText(citrusVersion)) {
                project.getSettings().setCitrusVersion(citrusVersion);
            }

            project.setDescription(evaluate(pomDoc, "/mvn:project/mvn:description", nsContext));

            project.getSettings().setConnectorActive(StringUtils.hasText(evaluate(pomDoc,
                    "/mvn:project/mvn:dependencies/mvn:dependency/mvn:artifactId[. = 'citrus-admin-connector']",
                    nsContext)));
        } catch (IOException e) {
            throw new ApplicationRuntimeException("Unable to open Maven pom.xml file", e);
        }
    } else if (project.isAntProject()) {
        try {
            String buildXml = FileUtils.readToString(new FileSystemResource(project.getAntBuildFile()));
            SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

            Document buildDoc = XMLUtils.parseMessagePayload(buildXml);
            project.setName(evaluate(buildDoc, "/project/@name", nsContext));

            String citrusVersion = evaluate(buildDoc, "/project/property[@name='citrus.version']/@value",
                    nsContext);
            if (StringUtils.hasText(citrusVersion)) {
                project.getSettings().setCitrusVersion(citrusVersion);
            }

            project.setDescription(evaluate(buildDoc, "/project/@description", nsContext));
        } catch (IOException e) {
            throw new ApplicationRuntimeException("Unable to open Apache Ant build.xml file", e);
        }
    }

    saveProject(project);

    this.project = project;
    if (!this.recentlyOpened.contains(projectHomeDir)) {
        if (projectHomeDir.endsWith("/")) {
            this.recentlyOpened.add(projectHomeDir.substring(0, projectHomeDir.length() - 1));
        } else {
            this.recentlyOpened.add(projectHomeDir);
        }
    }
    System.setProperty(Application.PROJECT_HOME, projectHomeDir);
}

From source file:org.geoserver.kml.KMLReflectorTest.java

void initXPath(XPath xpath) {
    SimpleNamespaceContext ctx = new SimpleNamespaceContext();
    ctx.bindNamespaceUri("kml", "http://www.opengis.net/kml/2.2");
    xpath.setNamespaceContext(ctx);/*www. j a va  2s  .c  o m*/
}