Package org.jdom.xpath

Examples of org.jdom.xpath.XPath.selectSingleNode()


     *   such element exists
     * @throws JDOMException
     */
  public Element getFormWithName(Element elt, String formName) throws JDOMException {
    XPath xpath = getXPath("xhtml", String.format(".//xhtml:form[@name='%s']", formName));
    return (Element)xpath.selectSingleNode(elt);
  }

    /**
     * Find in the given XML document a <form>
     * tag with the given @name attribute.
View Full Code Here


      List<NameValuePair> keyvals)
      throws JDOMException {
    String selectName = select.getAttributeValue("name");
    String expr = String.format("//xhtml:option[@value='%s']",chosenValue);
    XPath optionPath = XhtmlParser.getXPath("xhtml", expr);
    if (optionPath.selectSingleNode(select) == null) {
      String msg = String.format("value '%s' was not one of the available options for select '%s'",
                    chosenValue, selectName);
      throw new IllegalArgumentException(msg);
    }
    keyvals.add(new BasicNameValuePair(selectName, chosenValue));
View Full Code Here

  private void addDefaultOption(Element select, List<NameValuePair> keyvals)
      throws JDOMException {
    String selectName = select.getAttributeValue("name");
    XPath defaultPath = XhtmlParser.getXPath("xhtml","//xhtml:option[@selected]");
    Element defaultOption = (Element)defaultPath.selectSingleNode(select);
    if (defaultOption != null) {
      keyvals.add(new BasicNameValuePair(selectName, defaultOption.getAttributeValue("value","")));
    }
  }
View Full Code Here

    }

    private Element getMatch(Object doc, String xpath) {
        try {
            XPath path = XPath.newInstance(xpath);
            return (Element)path.selectSingleNode(doc);
        } catch (JDOMException e) {
            throw new DatabindingException("Error evaluating xpath " + xpath, e);
        }
    }
View Full Code Here

        final XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
        final XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );

        assertEquals( "role", ( (Text) role.selectSingleNode( doc ) ).getText() );
        assertNull( hint.selectSingleNode( doc ) );
        assertEquals( "impl", ( (Text) implementation.selectSingleNode( doc ) ).getText() );
    }

    public void testAddToArchive_ShouldWriteComponentWithHintToFile()
        throws IOException, ArchiverException, JDOMException
    {
View Full Code Here

        final XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
        final XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );

        assertEquals( "role", ( (Text) role.selectSingleNode( doc ) ).getText() );
        assertEquals( "hint", ( (Text) hint.selectSingleNode( doc ) ).getText() );
        assertEquals( "impl", ( (Text) implementation.selectSingleNode( doc ) ).getText() );
    }

    public void testAddToArchive_ShouldWriteTwoComponentToFile()
        throws IOException, ArchiverException, JDOMException
    {
View Full Code Here

        final XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
        final XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );

        assertEquals( "role", ( (Text) role.selectSingleNode( doc ) ).getText() );
        assertEquals( "hint", ( (Text) hint.selectSingleNode( doc ) ).getText() );
        assertEquals( "impl", ( (Text) implementation.selectSingleNode( doc ) ).getText() );

        final XPath role2 = XPath.newInstance( "//component[position()=2]/role/text()" );
        final XPath hint2 = XPath.newInstance( "//component[position()=2]/role-hint/text()" );
        final XPath implementation2 = XPath.newInstance( "//component[position()=2]/implementation/text()" );
View Full Code Here

        final XPath hint2 = XPath.newInstance( "//component[position()=2]/role-hint/text()" );
        final XPath implementation2 = XPath.newInstance( "//component[position()=2]/implementation/text()" );

        assertEquals( "role", ( (Text) role2.selectSingleNode( doc ) ).getText() );
        assertEquals( "hint2", ( (Text) hint2.selectSingleNode( doc ) ).getText() );
        assertEquals( "impl", ( (Text) implementation2.selectSingleNode( doc ) ).getText() );

    }

    public void testAddToArchive_ShouldWriteTwoComponentToArchivedFile()
        throws IOException, ArchiverException, JDOMException
View Full Code Here

        final XPath hint = XPath.newInstance( "//component[position()=1]/role-hint/text()" );
        final XPath implementation = XPath.newInstance( "//component[position()=1]/implementation/text()" );

        assertEquals( "role", ( (Text) role.selectSingleNode( doc ) ).getText() );
        assertEquals( "hint", ( (Text) hint.selectSingleNode( doc ) ).getText() );
        assertEquals( "impl", ( (Text) implementation.selectSingleNode( doc ) ).getText() );

        final XPath role2 = XPath.newInstance( "//component[position()=2]/role/text()" );
        final XPath hint2 = XPath.newInstance( "//component[position()=2]/role-hint/text()" );
        final XPath implementation2 = XPath.newInstance( "//component[position()=2]/implementation/text()" );
View Full Code Here

        final XPath hint2 = XPath.newInstance( "//component[position()=2]/role-hint/text()" );
        final XPath implementation2 = XPath.newInstance( "//component[position()=2]/implementation/text()" );

        assertEquals( "role", ( (Text) role2.selectSingleNode( doc ) ).getText() );
        assertEquals( "hint2", ( (Text) hint2.selectSingleNode( doc ) ).getText() );
        assertEquals( "impl", ( (Text) implementation2.selectSingleNode( doc ) ).getText() );

    }

    private Xpp3Dom createComponentDom( final ComponentDef def )
    {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.