List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren()
List
of all the child elements nested directly (one level deep) within this element, as Element
objects. From source file:com.sun.syndication.io.impl.ModuleParsers.java
License:Open Source License
private boolean hasElementsFrom(Element root, Namespace namespace) { boolean hasElements = false; // boolean hasElements = namespace.equals(root.getNamespace()); if (!hasElements) { List children = root.getChildren(); for (int i = 0; !hasElements && i < children.size(); i++) { Element child = (Element) children.get(i); hasElements = namespace.equals(child.getNamespace()); }/*from w w w.j a v a2s . com*/ } return hasElements; }
From source file:com.sun.syndication.io.impl.RSS091UserlandGenerator.java
License:Open Source License
protected void checkChannelConstraints(Element eChannel) throws FeedException { checkNotNullAndLength(eChannel, "title", 1, 100); checkNotNullAndLength(eChannel, "description", 1, 500); checkNotNullAndLength(eChannel, "link", 1, 500); checkNotNullAndLength(eChannel, "language", 2, 5); checkLength(eChannel, "rating", 20, 500); checkLength(eChannel, "copyright", 1, 100); checkLength(eChannel, "pubDate", 1, 100); checkLength(eChannel, "lastBuildDate", 1, 100); checkLength(eChannel, "docs", 1, 500); checkLength(eChannel, "managingEditor", 1, 100); checkLength(eChannel, "webMaster", 1, 100); Element skipHours = eChannel.getChild("skipHours"); if (skipHours != null) { List hours = skipHours.getChildren(); for (int i = 0; i < hours.size(); i++) { Element hour = (Element) hours.get(i); int value = Integer.parseInt(hour.getText().trim()); if (isHourFormat24()) { if ((value < 1) || (value > 24)) { throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24"); }// ww w .j a va 2s . co m } else { if ((value < 0) || (value > 23)) { throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23"); } } } } }
From source file:com.swordlord.gozer.builder.Parser.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseElement(Element element, ObjectBase parent) { if (!_objectTags.containsKey(element.getName())) { String msg = MessageFormat.format("Element {0} unknown, parsing aborted.", element.getName()); LOG.error(msg);/*ww w . j av a 2s. c om*/ return; } ObjectBase ob = instantiateClass(_objectTags.get(element.getName())); if (ob == null) { String msg = MessageFormat.format("Class for {0} could not be instantiated, parsing aborted.", element); LOG.error(msg); return; } if (element.getText() != null) { ob.setContent(element.getText()); } List attributes = element.getAttributes(); Iterator itAttributes = attributes.iterator(); while (itAttributes.hasNext()) { Attribute attr = (Attribute) itAttributes.next(); ob.putAttribute(attr.getName(), attr.getValue()); } if (parent != null) { ob.inheritParent(parent); parent.putChild(ob); } else { _objectTree.setRoot(ob); } List children = element.getChildren(); Iterator itChildren = children.iterator(); while (itChildren.hasNext()) { parseElement((Element) itChildren.next(), ob); } }
From source file:com.thoughtworks.go.config.GoConfigFieldWriter.java
License:Apache License
@SuppressWarnings("unchecked") private Collection parseCollection(Element e, Class<?> collectionType) { ConfigCollection collection = collectionType.getAnnotation(ConfigCollection.class); Class<?> type = collection.value(); Object o = newInstance(collectionType); bombUnless(o instanceof Collection, "Must be some sort of list. Was: " + collectionType.getName()); Collection baseCollection = (Collection) o; for (Element childElement : (List<Element>) e.getChildren()) { if (isInCollection(childElement, type)) { baseCollection.add(parseType(childElement, type)); }/*from ww w . j a v a 2 s. c om*/ } bombIf(baseCollection.size() < collection.minimum(), "Required at least " + collection.minimum() + " subelements to '" + e.getName() + "'. " + "Found " + baseCollection.size() + "."); return baseCollection; }
From source file:com.thoughtworks.go.server.service.lookups.CommandSnippetXmlParser.java
License:Apache License
public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) { try {//from ww w . j av a 2 s. c o m Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd")); CommandSnippetComment comment = getComment(document); Element execTag = document.getRootElement(); String commandName = execTag.getAttributeValue("command"); List<String> arguments = new ArrayList<>(); for (Object child : execTag.getChildren()) { Element element = (Element) child; arguments.add(element.getValue()); } return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath); } catch (Exception e) { String errorMessage = String.format("Reason: %s", e.getMessage()); LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage); return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment()); } }
From source file:com.ucuenca.dao.BaseXMLDao.java
public Table getTable() throws MalformedURLException, JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); URL url = new URL(path); InputStream stream = url.openStream(); Document document = null;//w ww. ja v a 2s.c om try { document = builder.build(stream); } catch (JDOMException e) { } Table table = new Table_Excel(); // Get Root Element and name Element root = document.getRootElement(); String rootName = root.getName(); // Get Second Level Elements, the rows of the data table List<Element> items = root.getChildren(); // Get column names, using the first element List<Element> firstItem = items.get(0).getChildren(); List<Column> columns = new ArrayList<Column>(); for (Element col : firstItem) { Column column = new Column(); column.setTitle(col.getName()); column.setStorageFormat(formatColumn(""));//pendiente columns.add(column); } // Get data and identify type data // for (Element item : items) { // ArrayList<String> row = new ArrayList<String>(); // for (Element col : item.getChildren()) { // row.add(col.getText()); // } // // } return table; }
From source file:com.webfront.app.utils.PDFImporter.java
@Override public void doImport(BufferedReader reader) throws IOException, ParseException { PDFTextStripper pdfStripper = new PDFTextStripper(); BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(fileName)); try (PDDocument document = PDDocument.load(inStream)) { txtOutput = pdfStripper.getText(document); try (FileWriter writer = new FileWriter(cfg.getTmpDir() + cfg.getFileSep() + "pdfOut.txt")) { writer.write(txtOutput);// w ww . j a va 2 s. com writer.close(); txtReader = new BufferedReader(new FileReader(cfg.getTmpDir() + cfg.getFileSep() + "pdfOut.txt")); String text = ""; while (text != null) { text = txtReader.readLine(); buffer.put(currentLine++, text); } } getConfig(); currentLine = 0; Element root = xmlDoc.getRootElement(); int maxLines = buffer.size() - 3; int markedLine = 0; // Scan the output and mark the start of each section for (Element el : root.getChildren()) { for (Element section : el.getChildren()) { String sectionName = section.getAttributeValue("content"); Element startElement = section.getChild("start"); Element endElement = section.getChild("end"); if (startElement != null) { boolean endHasBounds = true; if (endElement.getAttribute("bounded") != null) { String bounds = endElement.getAttributeValue("bounded"); if (bounds.equals("false")) { endHasBounds = false; } } Pattern linePattern = Pattern.compile(startElement.getText()); String text = ""; boolean elementFound = false; while (currentLine < maxLines) { text = buffer.get(currentLine++); if (linePattern.matcher(text).matches()) { markedLine = currentLine - 1; markers.put(sectionName, markedLine); elementFound = true; if (!endHasBounds) { currentLine--; } break; } } if (!elementFound) { currentLine = markedLine; } } } } ArrayList<Integer> lineNumbers = new ArrayList<>(markers.values()); lineNumbers.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }); sectionMarks = new TreeSet(markers.values()); currentLine = 0; for (Element element : root.getChildren()) { int lines = 0; if (element.getAttribute("lines") != null) { lines = element.getAttribute("lines").getIntValue(); } for (Element section : element.getChildren()) { String contentDesc; contentDesc = (section.getAttribute("content") == null ? "" : section.getAttributeValue("content")); if (markers.containsKey(contentDesc)) { currentLine = markers.get(contentDesc); processSection(section); } } } } catch (DataConversionException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } catch (ElementNotFoundException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } entries.sort(LedgerEntry.LedgerComparator); for (LedgerEntry item : entries) { java.util.Date date = new java.util.Date(DateConvertor.toLong(item.getDate(), "MM/dd/yyyy")); String amountString = item.getAmount(); boolean isCredit = true; if (item.getAmount().startsWith("-")) { isCredit = false; String amt = item.getAmount().replaceFirst("-", ""); item.setAmount(amt); } float amount = Float.parseFloat(amountString); if (isCredit) { lastBalance += amount; totalDeposits += amount; } else { lastBalance -= amount; totalWithdrawals += amount; } Ledger ledger = new Ledger(null, date, amount, lastBalance, accountId); if (item.getDescription().length() > 120) { item.setDescription(item.getDescription().substring(0, 119)); } if (item.getCheckNumber() != null && !item.getCheckNumber().isEmpty()) { ledger.setCheckNum(item.getCheckNumber()); totalChecks -= amount; } ledger.setTransDesc(item.getDescription()); getItemList().add(ledger); } }
From source file:com.webfront.app.utils.PDFImporter.java
public void processSection(Element section) throws ElementNotFoundException { String name = section.getName(); boolean hasEntry = false; String contentDesc = (section.getAttribute("content") == null ? "" : section.getAttributeValue("content")); int lines = 1; int maxLines = 0; int linesProcessed = 0; boolean endHasBounds = true; Element startElement = section.getChild("start"); Element endElement = section.getChild("end"); Element dataDefinition = section.getChild("data"); Element lineDefinition = section.getChild("line"); Pattern dataPattern = null;//w w w . ja v a 2 s.c o m Pattern linePattern = null; String transType = (section.getAttribute("type") == null ? "info" : section.getAttributeValue("type")); String prevLine = ""; int nextSection = buffer.size() - 1; if (sectionMarks.higher(currentLine) != null) { nextSection = (int) sectionMarks.higher(currentLine); } if (startElement.getAttributeValue("lines") != null) { lines = Integer.parseInt(startElement.getAttributeValue("lines")); currentLine += lines; } if (lineDefinition != null) { linePattern = Pattern.compile(lineDefinition.getText()); if (lineDefinition.getAttribute("lines") != null) { String l = lineDefinition.getAttributeValue("lines"); if (!l.equals("+")) { maxLines = Integer.parseInt(lineDefinition.getAttributeValue("lines")); } } } if (endElement.getAttribute("bounded") != null) { String bounds = endElement.getAttributeValue("bounded"); if (bounds.equals("false")) { endHasBounds = false; } } Pattern endPattern = Pattern.compile(endElement.getText()); while (currentLine < nextSection) { prevLine = buffer.get(currentLine - 1); String text = buffer.get(currentLine++); Matcher lineMatcher = null; if (lineDefinition != null) { lineMatcher = linePattern.matcher(text); } Matcher endMatcher = endPattern.matcher(text); if (endMatcher.matches()) { if (!endHasBounds) { currentLine -= 1; } break; } else { if (currentLine >= buffer.size()) { throw new ElementNotFoundException("Not found"); } } if (lineMatcher != null && lineMatcher.matches()) { if (!contentDesc.equals("discard")) { // System.out.println(text); } hasEntry = false; if (dataDefinition != null) { LedgerEntry entry = new LedgerEntry(); for (Element dataLine : dataDefinition.getChildren()) { String tag = dataLine.getAttributeValue("content"); String regex = dataLine.getText(); Matcher matcher = Pattern.compile(regex).matcher(text); String value = ""; if (matcher.find()) { value = matcher.group(); } switch (tag) { case "beginningBalance": beginningBalance = Float.parseFloat(value.replaceAll(",", "")); break; case "totalDeposits": value.replaceAll(",", ""); totalDeposits = Float.parseFloat(value.replaceAll(",", "")); break; case "totalWithdrawals": value.replaceAll(",", ""); totalWithdrawals = Float.parseFloat(value.replaceAll(",", "")); break; case "endingBalance": value.replaceAll(",", ""); endingBalance = Float.parseFloat(value.replaceAll(",", "")); break; case "accountNumber": summary.put("accountNumber", value); break; case "periodFrom": summary.put("startDate", value); break; case "periodTo": summary.put("endDate", value); break; case "date": entry.setDate(value); text = matcher.replaceFirst(""); break; case "check": entry.setCheckNumber(value); break; case "amount": if (transType.equals("debit")) { value = "-" + value; } entry.setAmount(value); text = matcher.replaceFirst(""); if (section.getAttributeValue("content").equals("fees")) { String amt = entry.getAmount(); amt = amt.replaceAll("-", ""); amt = amt.replaceAll(",", ""); totalFees += Float.parseFloat(amt); } break; case "description": entry.setDescription(value); break; } } if (maxLines > 0 && ++linesProcessed == maxLines) { return; } if (!contentDesc.equals("dailyBalance") && !contentDesc.endsWith("Info")) { entries.add(entry); hasEntry = true; } } } else { if (linePattern.matcher(prevLine).matches() && hasEntry) { if (!contentDesc.equals("dailyBalance")) { int lastEntry = entries.size() - 1; LedgerEntry entry = entries.get(lastEntry); entry.setDescription(entry.getDescription() + " " + text); entries.set(lastEntry, entry); hasEntry = false; } } } } }
From source file:com.webfront.app.utils.PDFImporter.java
private void getConfig() { jdomBuilder = new SAXBuilder(); String xmlSource = cfg.getInstallDir() + cfg.getFileSep() + "pnc.xml"; try {//ww w. ja v a 2s .co m xmlDoc = jdomBuilder.build(xmlSource); Element root = xmlDoc.getRootElement(); List<Content> configContent = root.getContent(); List<Element> childElements = root.getChildren(); Element header = root.getChild("header"); for (Element e : header.getChildren()) { String content = e.getAttributeValue("content"); String format = e.getAttributeValue("format"); String text = e.getText(); } } catch (JDOMException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PDFImporter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:compile.util.XMLUtil.java
public List<Element> getChildrenFromNode(Element node) { return node.getChildren(); }