List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.tactfactory.harmony.utils.XMLUtils.java
License:Open Source License
/** * Find a node in the given node./*from w w w.j a va 2s .c o m*/ * @param baseNode The node in whom to search. * @param newNode The node to search. * @param id The attribute name used for the comparison * @return The found node or null if the node doesn't exists */ public static Element findNode(final Element baseNode, final Element newNode, final String id) { Element result = null; final List<Element> nodes = baseNode.getChildren(newNode.getName()); // Look in the children nodes if one node // has the corresponding key/value couple for (final Element node : nodes) { if (node.hasAttributes() && node.getAttributeValue(id).equals(newNode.getAttributeValue(id))) { result = node; } } return result; }
From source file:com.thoughtworks.go.config.GoConfigMigration.java
License:Apache License
private int getCurrentSchemaVersion(String content) { try {/*from w ww .j a va2 s. co m*/ SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new ByteArrayInputStream(content.getBytes())); Element root = document.getRootElement(); String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion); return Integer.parseInt(currentVersion); } catch (Exception e) { throw bomb(e); } }
From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java
License:Apache License
private static boolean compareAttributeAwareConfigTag(Element e, AttributeAwareConfigTag attributeAwareConfigTag) { return attributeAwareConfigTag.value().equals(e.getName()) && attributeAwareConfigTag.attributeValue() .equals(e.getAttributeValue(attributeAwareConfigTag.attribute())) && e.getNamespace().getURI().equals(attributeAwareConfigTag.namespaceURI()); }
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 w ww .j av a2s . c om*/ 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.thoughtworks.go.util.SvnLogXmlParser.java
License:Apache License
private Modification parseLogEntry(Element logEntry, String path) throws ParseException { Element logEntryPaths = logEntry.getChild("paths"); if (logEntryPaths == null) { /* Path-based access control forbids us from learning * details of this log entry, so skip it. */ return null; }/*from w w w .j av a2s . c om*/ Date modifiedTime = convertDate(logEntry.getChildText("date")); String author = logEntry.getChildText("author"); String comment = logEntry.getChildText("msg"); String revision = logEntry.getAttributeValue("revision"); Modification modification = new Modification(author, comment, null, modifiedTime, revision); List paths = logEntryPaths.getChildren("path"); for (Iterator iterator = paths.iterator(); iterator.hasNext();) { Element node = (Element) iterator.next(); if (underPath(path, node.getText())) { ModifiedAction action = convertAction(node.getAttributeValue("action")); modification.createModifiedFile(node.getText(), null, action); } } return modification; }
From source file:com.versionmaintain.files.LastVersionInfosParser.java
License:Apache License
public List<VersionInfo> getVersionInfo() { SAXBuilder builder = new SAXBuilder(); List<VersionInfo> infos = new ArrayList<VersionInfo>(); try {//ww w . j a v a2 s .co m Document doc = builder.build(new File(System.getProperty("user.dir") + File.separator + FILE_NAME)); Element root = doc.getRootElement(); List<Element> softEles = root.getChildren("software"); for (Element softEle : softEles) { String appName = softEle.getAttribute("name").getValue(); String versionCode = softEle.getChildText("latest-version-code"); String versionName = softEle.getChildText("latest-version"); Element detailEles = softEle.getChild("latest-version-detail"); List<Element> detailItemEles = detailEles.getChildren("item"); List<VersionInfoDetail> details = new ArrayList<VersionInfoDetail>(); for (Element detailItem : detailItemEles) { String title = detailItem.getAttributeValue("name"); List<Element> detailEleList = detailItem.getChildren("detail"); List<String> detailList = new ArrayList<String>(); for (Element detailEle : detailEleList) { String strDetail = detailEle.getText(); detailList.add(strDetail); } details.add(new VersionInfoDetail(title, detailList)); } VersionInfo versionInfo = new VersionInfo(); versionInfo.setAppName(appName); versionInfo.setVersion(versionName); versionInfo.setVersionCode(Integer.parseInt(versionCode)); versionInfo.setDetails(details); infos.add(versionInfo); } } catch (Exception e) { e.printStackTrace(); } return infos; }
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);/*from w w w . j a va 2 s . c om*/ 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 ww . java2 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. j ava 2 s. c o 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.Tomcat.java
public void checkIfInContextFile(Project proj) { LogService.tomcatAddingContext(/*from ww w.j a v a 2 s .co m*/ PropertiesFile.getInstance().getPropertiesUtil().getParam("workingDirContext")); Element racine = _serverXml.getRacine(); Element service = racine.getChild("Service", null); Element engine = service.getChild("Engine", null); Element host = engine.getChild("Host", null); List<Element> listContext = host.getChildren("Context", null); boolean notInContext = true; for (Element context : listContext) { if (context.getAttributeValue("docBase") .equals(proj.getPathProject() + SEP + "target" + SEP + proj.getWebappName())) { notInContext = false; } } if (notInContext) { host.addContent(new Element("Context") .setAttribute("docBase", proj.getPathProject() + SEP + "target" + SEP + proj.getWebappName()) .setAttribute("path", PropertiesFile.getInstance().getPropertiesUtil().getParam("workingDirContext")) .setAttribute("reloadable", "true")); _serverXml.save(); } }