/** * Returns the merged content of all children text nodes, if this node has no element children. * <p> * This will work when this node has only text and comment children.<br> * If it has element children, {@code null} is returned. * * @return The merged content of children texts (ignoring comments) or {@code null}. */ public String getText() { return getText(null); }
public Boolean getTextAsOptionalBoolean(Boolean def) { return StringConversion.asOptionalBoolean(getText(), def, FailureReaction.WARN); }
public short getTextAsShort(short def) { return StringConversion.asShort(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public Byte getTextAsOptionalByte(Byte def) { return StringConversion.asOptionalByte(getText(), def, FailureReaction.WARN); }
public long getTextAsLong(long def) { return StringConversion.asLong(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public int getTextAsInt(int def) { return StringConversion.asInt(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public byte getTextAsByte(byte def) { return StringConversion.asByte(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public <E extends Enum<E>> E getTextAsEnum(Class<E> enumClass, E def) { return StringConversion.asEnum(getText(), enumClass, def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public <E extends Enum<E>> E getTextAsOptionalEnum(Class<E> enumClass, E def) { return StringConversion.asOptionalEnum(getText(), enumClass, def, FailureReaction.WARN); }
public boolean getTextAsBoolean(boolean def) { return StringConversion.asBoolean(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public double getTextAsDouble(double def) { return StringConversion.asDouble(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public Double getTextAsOptionalDouble(Double def) { return StringConversion.asOptionalDouble(getText(), def, FailureReaction.WARN); }
public float getTextAsFloat(float def) { return StringConversion.asFloat(getText(), def, FailureReaction.DEFAULT, FailureReaction.WARN); }
public Float getTextAsOptionalFloat(Float def) { return StringConversion.asOptionalFloat(getText(), def, FailureReaction.WARN); }
public Long getTextAsOptionalLong(Long def) { return StringConversion.asOptionalLong(getText(), def, FailureReaction.WARN); }
public Integer getTextAsOptionalInt(Integer def) { return StringConversion.asOptionalInt(getText(), def, FailureReaction.WARN); }
public Short getTextAsOptionalShort(Short def) { return StringConversion.asOptionalShort(getText(), def, FailureReaction.WARN); }
/** * Returns the text content of the first child element that has a given name. * * @param name The child name. * @param def The default value. * @return The text of the first child named {@code name} or {@code def}. */ public String getElementNamedText(String name, String def) { final Element child = getElementNamed(name); if (child != null) { return child.getText(def); } else { return def; } }
private void analyze(File file, Element element) { for (final SPath path : margs.paths) { if (path.matchesElement(element)) { final String s = element.getText(null); checkClassName(s, file, element.getQName()); } for (final Attribute att : element.getAttributes()) { if (path.matchesAttribute(element, att.getName())) { final String s = att.getValue(); checkClassName(s, file, element.getQName() + "/@" + att.getName()); } } } for (final Element child : element.getElements()) { analyze(file, child); } }
@Test public void testChangeTexts() { final Element root = new Element(NAME); root.addText("hello", false); root.addText("HELLO", false); root.changeTexts(String::toUpperCase); assertEquals(2, root.getChildrenCount()); assertEquals("HELLO", root.getChildAt(Text.class, 0).getContent()); assertEquals("HELLO", root.getChildAt(Text.class, 1).getContent()); root.removeChildren(); final Element child1 = root.addElement(NAME1); final Element child2 = root.addElement(NAME2); final Element child3 = root.addElement(NAME1); child1.addText("hello"); child2.addText("hello"); child3.addText("hel"); child3.addText("lo", false); assertEquals(2, child3.getChildrenCount()); root.changeTexts(String::toUpperCase); assertEquals(2, child3.getChildrenCount()); root.changeNamedTexts(NAME1, String::toUpperCase); assertEquals(1, child3.getChildrenCount()); assertEquals("HELLO", child1.getText()); assertEquals("HELLO", child3.getText()); }