@Override String getText(Object node) { return ((Node) node).getText(); }
private static String findMessageText(List<Document> messageCollectionList, String xpath, String missingMsg) { for (Document document : messageCollectionList) { Node node = document.selectSingleNode(xpath); if (node != null) { return node.getText().trim(); } } return missingMsg; }
/** * This method is used to write out Nodes that contain text * and still allow for xml:space to be handled properly. * */ protected void writeNodeText(Node node) throws IOException { String text = node.getText(); if (text != null && text.length() > 0) { if (escapeText) { text = escapeElementEntities(text); } lastOutputNodeType = Node.TEXT_NODE; writer.write(text); } }
private static String getChildText(Node node, String childName) throws PluginException { Node child = node.selectSingleNode(childName); if (child == null) { throw new PluginException("Could not find child \"" + childName + "\" for node"); } return child.getText(); }
@Override protected void addDataElement(Element element, List<TestDataElement> testDataElements) { int id = Integer.parseInt( element.selectSingleNode( "id" ).getText() ); String type = element.selectSingleNode( "type" ).getText(); String wkt = element.selectSingleNode( "wkt" ).getText(); String sdo = element.selectSingleNode( "sdo" ).getText(); TestDataElement testDataElement = new SDOTestDataElement( id, type, wkt, sdo ); testDataElements.add( testDataElement ); }
protected void addDataElement(Element element, List<TestDataElement> testDataElements) { int id = Integer.parseInt( element.selectSingleNode( "id" ).getText() ); String type = element.selectSingleNode( "type" ).getText(); String wkt = element.selectSingleNode( "wkt" ).getText(); TestDataElement testDataElement = new TestDataElement( id, type, wkt ); testDataElements.add( testDataElement ); }
@Test public void withoutItemsEnumParent() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'VALUE_2']"); assertEquals("TestEnum: VALUE_1", value1.getText()); assertEquals("TestEnum: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
@Test public void withoutItemsEnumBindTarget() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.tag.setPath("testEnum"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = "<div>" + getOutput() + "</div>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']"); Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']"); assertEquals("TestEnum: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText()); assertEquals("TestEnum: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText()); assertEquals(value2, rootElement.selectSingleNode("//input[@checked]")); }
final Document pluginXML = saxReader.read( pluginConfig.toFile() ); final String className = pluginXML.selectSingleNode( "/plugin/class" ).getText().trim(); final Plugin plugin = (Plugin) pluginLoader.loadClass( className ).newInstance();
@Test public void withoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.tag.setItemLabel("enumLabel"); this.tag.setItemValue("enumValue"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_2']"); assertEquals("Label: VALUE_1", value1.getText()); assertEquals("Label: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
@Test public void withoutItemsEnumBindTargetWithExplicitLabelsAndValues() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.tag.setPath("testEnum"); this.tag.setItemLabel("enumLabel"); this.tag.setItemValue("enumValue"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = "<div>" + getOutput() + "</div>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_1']"); Node value2 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_2']"); assertEquals("Label: VALUE_1", rootElement.selectSingleNode("//label[@for = '" + value1.valueOf("@id") + "']").getText()); assertEquals("Label: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText()); assertEquals(value2, rootElement.selectSingleNode("//input[@checked]")); }
buffer = new StringBuilder( lastTextNode.getText() ); buffer.append( node.getText() );
public static String getNodeValue(Node node) throws DOMException { return node.getText(); }
String valueNode = node.getText();
public String toString() { // should maybe do things differently based on content? String text = xmlNode.getText(); return (text != null) ? text.trim() : ""; }
for (Node node : propertyNodes) { String key = node.valueOf("@key"); String value = node.getText(); properties.setProperty(key, value); Node bugsUrlNode = messageNode.getDocument().selectSingleNode("/MessageCollection/Plugin/"+(experimental?"AllBugsUrl":"BugsUrl")); String bugsUrl = bugsUrlNode == null ? null : bugsUrlNode.getText(); continue; String description = bugCodeNode.getText();
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { String xmlText = xml.getText(); return xmlText == null || xmlText.length() == 0 ? null : fromString( xmlText ); }
/** * Retrieves text of a single node. * * @param xpath XPath pointing to a single node (not its text). * @return text of a node. */ public String selectText(String xpath) { try { return ((Node) doc.selectObject(xpath)).getText(); } catch(ClassCastException e){ throw new IllegalArgumentException("Found result is not text, ensure that you have the right expression which evaluates to text."); } catch (Exception e) { throw new RuntimeException(e); } }