private Element assignRecordsToBatchProcessPart( Element batchProcessElement, int quantityRecordsToAssign, List<String> recordsBatchPart) { List<Element> recordsElements = getRecordsElements(batchProcessElement); int toIndex = recordsElements.size() >= quantityRecordsToAssign ? quantityRecordsToAssign : recordsElements.size(); recordsElements = recordsElements.subList(0, toIndex); Element recordsBatchPartElement = new Element(RECORDS); for (Element recordElement : recordsElements) { recordElement.detach(); recordsBatchPartElement.addContent(recordElement.detach()); recordsBatchPart.add(recordElement.getText()); } return recordsBatchPartElement; }
private void removeBatchPartFromDocument(String computerName) throws ComputerNotFound { boolean found = false; for (Element batchProcessPart : getBatchProcessPartElements()) { if (batchProcessPart.getAttributeValue(COMPUTER_NAME).equals(computerName)) { found = true; batchProcessPart.detach(); } } if (!found) { throw new BatchProcessWriterRuntimeException.ComputerNotFound(computerName); } }
private void removeSpareOperators( final Element element, final Collection<String> spareOperators) { assert element != null && spareOperators != null && !spareOperators.isEmpty(); final List<Element> children = element.getChildren(); for (int i = 0; i < children.size(); i++) { final Element actual = children.get(i); // actual element if (isOperator(actual)) { // Keep special case where asterisk is by itself in a subscript String parent = actual.getParentElement().getName(); if (isSpareOperator(actual, spareOperators) && !(parent.equals("msub")) && !(parent.equals("msubsup") && !(parent.equals("msup")))) { actual.detach(); i--; // move iterator back after detaching so it points to next element LOGGER.log(Level.FINE, "Operator {0} removed", actual); } } else { removeSpareOperators(actual, spareOperators); } } }
/** Parse entry from reader. */ public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder(); final Document entryDoc = builder.build(rd); final Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed(); feed.setFeedType("atom_1.0"); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } final WireFeedInput input = new WireFeedInput(false, locale); final Feed parsedFeed = (Feed) input.build(feedDoc); return parsedFeed.getEntries().get(0); }