List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.chingo247.structureapi.plan.document.DocumentPluginElement.java
public Boolean getBooleanValue(String xPath) { Node n = pluginElement.selectSingleNode(xPath); if (n == null) { return null; } else {// w ww . j av a 2s . c o m return Boolean.parseBoolean(n.getText()); } }
From source file:com.chingo247.structureapi.plan.holograms.StructureHologramLoader.java
License:Open Source License
@Override public List<StructureHologram> load(Element hologramsElement) throws StructureDataException { if (hologramsElement == null) { throw new AssertionError("Overviews element was null"); }//from www. j av a2 s . com if (!hologramsElement.getName().equals(Elements.STRUCTURE_HOLOGRAMS)) { throw new AssertionError("Expected '" + Elements.STRUCTURE_HOLOGRAMS + "' element, but got '" + hologramsElement.getName() + "'"); } List<StructureHologram> holograms = new ArrayList<>(); List<Node> hologramNodes = hologramsElement.selectNodes(Elements.STRUCTURE_HOLOGRAM); int count = 0; for (Node hologramNode : hologramNodes) { Node xNode = hologramNode.selectSingleNode(Elements.X); Node yNode = hologramNode.selectSingleNode(Elements.Y); Node zNode = hologramNode.selectSingleNode(Elements.Z); if (xNode == null) { throw new StructureDataException("Missing 'X' node for 'StructureOverview#" + count + "'"); } if (yNode == null) { throw new StructureDataException("Missing 'Y' node for 'StructureOverview#" + count + "'"); } if (zNode == null) { throw new StructureDataException("Missing 'Z' node for 'StructureOverview#" + count + "'"); } try { int x = Integer.parseInt(xNode.getText()); int y = Integer.parseInt(yNode.getText()); int z = Integer.parseInt(zNode.getText()); List<Node> lines = hologramNode.selectNodes("Lines/Line"); String[] tArray = new String[lines.size()]; for (int i = 0; i < tArray.length; i++) { tArray[i] = (lines.get(i)).getText(); } holograms.add(new StructureHologram(x, y, z, tArray)); } catch (NumberFormatException nfe) { throw new StructureDataException( "Values for (x,y,z) are not of type number in 'StructureOverview#" + count + "'"); } count++; } return holograms; }
From source file:com.chingo247.structureapi.plan.holograms.StructureHologramValidator.java
License:Open Source License
@Override public void validate(Element e) throws StructureDataException { List<Node> nodes = e.selectNodes(Nodes.HOLOGRAM_NODE); if (nodes != null && !nodes.isEmpty()) { int count = 0; for (Node n : nodes) { Node xNode = n.selectSingleNode(Elements.X); Node yNode = n.selectSingleNode(Elements.Y); Node zNode = n.selectSingleNode(Elements.Z); if (xNode == null) { throw new StructureDataException("Missing 'X' node for 'Hologram#" + count + "'"); }//ww w. ja v a 2 s. c o m if (yNode == null) { throw new StructureDataException("Missing 'Y' node for 'Hologram#" + count + "'"); } if (zNode == null) { throw new StructureDataException("Missing 'Z' node for 'Hologram#" + count + "'"); } try { Integer.parseInt(xNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException("Invalid X value should 'Hologram#" + count + "'"); } try { Integer.parseInt(yNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException("Invalid Y value for 'Hologram#" + count + "'"); } try { Integer.parseInt(zNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException("Invalid Z value for 'Hologram#" + count + "'"); } Node linesNode = n.selectSingleNode("Lines"); if (linesNode == null) { throw new StructureDataException("Missing 'Lines' node for 'Hologram#" + count + "'"); } List<Node> lineNodes = n.selectNodes("Lines/Line"); if (lineNodes == null || lineNodes.isEmpty()) { throw new StructureDataException("Missing 'Line' nodes for 'Hologram#" + count + "'"); } count++; } } }
From source file:com.chingo247.structureapi.plan.io.document.LineElement.java
License:Open Source License
public void checkNullOrNotEmpty(String xpath) throws ElementValueException { Node notNull = le.selectSingleNode(xpath); if (notNull != null && notNull.getText().trim().isEmpty()) { String element = xpath.substring(xpath.lastIndexOf("/")); throw new ElementValueException( "No value for element <" + element + "> within <" + le.getName() + "> on line " + le.getLine()); }//ww w. j av a 2s. c om }
From source file:com.chingo247.structureapi.plan.overview.StructureOverviewLoader.java
License:Open Source License
@Override public List<StructureOverview> load(Element overviewsElement) throws StructureDataException { if (overviewsElement == null) { throw new AssertionError("Overviews element was null"); }/* ww w . j a v a 2 s.c o m*/ if (!overviewsElement.getName().equals(Elements.STRUCTURE_OVERVIEWS)) { throw new AssertionError("Expected '" + Elements.STRUCTURE_OVERVIEWS + "' element, but got '" + overviewsElement.getName() + "'"); } new StructureOverviewValidator().validate(overviewsElement); List<StructureOverview> overviews = new ArrayList<>(); List<Node> overviewNodes = overviewsElement.selectNodes(Elements.STRUCTURE_OVERVIEW); for (Node overviewNode : overviewNodes) { Node xNode = overviewNode.selectSingleNode(Elements.X); Node yNode = overviewNode.selectSingleNode(Elements.Y); Node zNode = overviewNode.selectSingleNode(Elements.Z); int x = Integer.parseInt(xNode.getText()); int y = Integer.parseInt(yNode.getText()); int z = Integer.parseInt(zNode.getText()); overviews.add(new StructureOverview(x, y, z)); } return overviews; }
From source file:com.chingo247.structureapi.plan.overview.StructureOverviewValidator.java
License:Open Source License
@Override public void validate(Element e) throws StructureDataException { if (!e.getName().equals(Elements.STRUCTURE_OVERVIEWS)) { throw new AssertionError( "Expected '" + Elements.STRUCTURE_OVERVIEWS + "' but got '" + e.getName() + "'"); }//from www . j a v a 2s .c o m List<Node> nodes = e.selectNodes(Elements.STRUCTURE_OVERVIEW); if (nodes != null && !nodes.isEmpty()) { int count = 0; for (Node n : nodes) { Node xNode = n.selectSingleNode(Elements.X); Node yNode = n.selectSingleNode(Elements.Y); Node zNode = n.selectSingleNode(Elements.Z); if (xNode == null) { throw new StructureDataException( "Missing 'X' node for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } if (yNode == null) { throw new StructureDataException( "Missing 'Y' node for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } if (zNode == null) { throw new StructureDataException( "Missing 'Z' node for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } try { Integer.parseInt(xNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException( "Invalid X value for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } try { Integer.parseInt(yNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException( "Invalid Y value for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } try { Integer.parseInt(zNode.getText()); } catch (NumberFormatException nfe) { throw new StructureDataException( "Invalid Z value for '" + Elements.STRUCTURE_OVERVIEW + "#" + count); } count++; } } }
From source file:com.chingo247.structureapi.plan.StructurePlan.java
public void load(AbstractDocument document) throws StructureDataException, IOException { xmlFile = document.getDocumentFile(); pluginElement = document.getPluginElement(Bukkit.getPluginManager().getPlugin("SettlerCraft")); Element scElement = pluginElement.getAsElement(); Node schematicNode = scElement.selectSingleNode(Nodes.SCHEMATIC_NODE); if (schematicNode == null) { throw new StructureDataException( "Missing Structure Schematic in " + document.getDocumentFile().getAbsolutePath()); }// www.j a v a 2s .co m File s = new File(document.getDocumentFile().getParent(), schematicNode.getText()); if (s.exists()) { schematic = s; } else { throw new FileNotFoundException("Couldn't resolve path for " + s.getAbsolutePath() + " for config: " + document.getDocumentFile().getAbsolutePath()); } checksum = FileUtils.checksumCRC32(s); name = pluginElement.getStringValue(Nodes.NAME_NODE); if (name == null) { name = FilenameUtils.getBaseName(schematic.getName()); } category = pluginElement.getStringValue(Nodes.CATEGORY_NODE); if (category == null) { category = "Default"; } description = pluginElement.getStringValue(Nodes.DESCRIPTION_NODE); if (description == null) { description = "-"; } try { price = pluginElement.getDoubleValue(Nodes.PRICE_NODE); } catch (NumberFormatException nfe) { throw new StructureDataException("Value of 'Price' must be a number, error generated in " + document.getDocumentFile().getAbsolutePath()); } if (price == null) { price = 0.0; } Node worldGuardFlagsNode = scElement.selectSingleNode(Nodes.WORLDGUARD_FLAGS_NODE); if (worldGuardFlagsNode != null) { regionFlags = new StructureRegionFlagLoader().load((Element) worldGuardFlagsNode); } else { regionFlags = new LinkedList<>(); } Node structureOverviewsNode = scElement.selectSingleNode(Nodes.STRUCTURE_OVERVIEWS_NODE); if (structureOverviewsNode != null) { overviews = new StructureOverviewLoader().load((Element) structureOverviewsNode); } else { overviews = new LinkedList<>(); } Node structureHologramsNode = scElement.selectSingleNode(Nodes.HOLOGRAMS_NODE); if (structureOverviewsNode != null) { holograms = new StructureHologramLoader().load((Element) structureHologramsNode); } else { holograms = new LinkedList<>(); } }
From source file:com.chingo247.structureapi.plan.util.PlanDocumentUtil.java
License:Open Source License
public void checkNullOrNotEmpty(Element e, String xpath) { checkLocated(e);//from w w w . j a v a 2s . c om Node notNull = e.selectSingleNode(xpath); if (notNull != null && notNull.getText().trim().isEmpty()) { String element = xpath.substring(xpath.lastIndexOf("/")); LocatedElement le = (LocatedElement) e; throw new PlanException( "No value for element <" + element + "> within <" + e.getName() + "> on line " + le.getLine()); } }
From source file:com.christophermrossi.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack); break; case Node.TEXT_NODE: char[] text = node.getText().toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA();//from w w w . j a v a2 s . com break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() ); namespaces.put(declared.getPrefix(), declared.getURI()); //if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); //} //else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); //} break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: //System.err.println( "WARNING: Node type not supported: " + node.getNodeTypeName() ); } } }
From source file:com.cladonia.xml.navigator.XmlElementNode.java
License:Open Source License
public String getValue() { if (value == null) { value = ""; if (element != null) { for (int i = 0; i < element.nodeCount(); i++) { Node node = element.node(i); if (navigator.hasElementContentInResults()) { if (navigator.showElementContent() && (nodes.contains(node) && (node instanceof Text))) { value = value + node.getText(); }//from ww w . j av a2s .c o m } else if (navigator.showElementContent() && node instanceof Text) { value = value + node.getText(); } } } } return value; }