Java Code Examples for org.jdom2.Element#removeContent()

The following examples show how to use org.jdom2.Element#removeContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCRXSLInfoServlet.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private void listTemplates() {
    List<Element> list = xsl.getChildren("template", MCRConstants.XSL_NAMESPACE);
    IteratorIterable<Element> callTemplateElements = xsl
        .getDescendants(Filters.element("call-template", MCRConstants.XSL_NAMESPACE));
    LinkedList<Element> templates = new LinkedList<>(list);
    HashSet<String> callNames = new HashSet<>();
    for (Element callTemplate : callTemplateElements) {
        String name = callTemplate.getAttributeValue("name");
        if (callNames.add(name)) {
            templates.add(callTemplate);
        }
    }
    for (Element template : templates) {
        Element copy = template.clone();
        copy.removeContent();
        this.templates.add(copy);
    }
}
 
Example 2
Source File: MCRFileStoreTest.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private void sortChildren(Element parent) throws Exception {
    @SuppressWarnings("unchecked")
    List<Element> children = parent.getChildren();
    if (children == null || children.size() == 0) {
        return;
    }

    ArrayList<Element> copy = new ArrayList<>();
    copy.addAll(children);

    copy.sort((a, b) -> {
        String sa = a.getName() + "/" + a.getAttributeValue("name");
        String sb = b.getName() + "/" + b.getAttributeValue("name");
        return sa.compareTo(sb);
    });

    parent.removeContent();
    parent.addContent(copy);

    for (Element child : copy) {
        sortChildren(child);
    }
}
 
Example 3
Source File: DesktopData.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method moves an element (entry-node or bullet-point) one position
 * up- or downwards, depending on the parameter {@code movement}.
 *
 * @param movement indicates whether the element should be moved up or down.
 * use following constants:<br> - {@code CConstants.MOVE_UP}<br> -
 * {@code CConstants.MOVE_DOWN}<br>
 * @param timestamp
 */
public void moveElement(int movement, String timestamp) {
    // get the selected element, independent from whether it's a node or a bullet
    Element e = findEntryElementFromTimestamp(getCurrentDesktopElement(), timestamp);
    if (e != null) {
        // get the element's parent
        Element p = e.getParentElement();
        // get the index of the element that should be moved
        int index = p.indexOf(e);
        // remove the element that should be moved
        Element dummy = (Element) p.removeContent(index);
        try {
            // and insert element one index-position below the previous index-position
            p.addContent((Constants.MOVE_UP == movement) ? index - 1 : index + 1, dummy);
            // change modifed state
            setModified(true);
        } catch (IllegalAddException ex) {
            Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage());
        }
    }
}
 
Example 4
Source File: Synonyms.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method sets a new synonm-line, i.e. a synonym (as index-word) with its related synonyms.
 * The new synonyms have to passed as string-parameter {@code synline}.
 *
 * @param nr the number of the requested synonym, with a range from 0 to (getCount()-1)
 * @param synline a string-array with the first element being the index-word, and the following
 * elements being the related synonyms
 */
public void setSynonymLine(int nr, String[] synline) {
    // get element
    Element synonym = retrieveElement(nr);
    // remove all child-content (i.e. all synonyms)
    synonym.removeContent();
    try {
        // set the original word as value-attribute to the "entry"-element
        synonym.setAttribute("indexword", synline[0]);
        // now go through the rest of the string-array
        for (int cnt = 1; cnt < synline.length; cnt++) {
            // create a sub-child "syn" for each further synonym
            Element syn = new Element("syn");
            // set text from string array
            syn.setText(synline[cnt]);
            // add child to synonym-element
            synonym.addContent(syn);
            setModified(true);
        }
    } catch (IllegalDataException | IllegalNameException ex) {
        Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
    }
}
 
Example 5
Source File: MapFilePreprocessor.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void processChildren(Path file, Element parent) throws InvalidXMLException {
    for(int i = 0; i < parent.getContentSize(); i++) {
        Content content = parent.getContent(i);
        if(!(content instanceof Element)) continue;

        Element child = (Element) content;
        List<Content> replacement = null;

        switch(child.getName()) {
            case "include":
                replacement = processIncludeElement(file, child);
                break;

            case "if":
                replacement = processConditional(child, false);
                break;

            case "unless":
                replacement = processConditional(child, true);
                break;
        }

        if(replacement != null) {
            parent.removeContent(i);
            parent.addContent(i, replacement);
            i--; // Process replacement content
        } else {
            processChildren(file, child);
        }
    }
}
 
Example 6
Source File: MCRQLSearchUtils.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Rename elements conditionN to condition. Transform condition with multiple child values to OR-condition.
 */
protected static void renameElements(Element element) {
    if (element.getName().startsWith("condition")) {
        element.setName("condition");

        String field = new StringTokenizer(element.getAttributeValue("field"), " -,").nextToken();
        String operator = element.getAttributeValue("operator");
        if (operator == null) {
            LOGGER.warn("No operator defined for field: {}", field);
            operator = "=";
        }
        element.setAttribute("operator", operator);

        List<Element> values = element.getChildren("value");
        if (values != null && values.size() > 0) {
            element.removeAttribute("field");
            element.setAttribute("operator", "or");
            element.setName("boolean");
            for (Element value : values) {
                value.setName("condition");
                value.setAttribute("field", field);
                value.setAttribute("operator", operator);
                value.setAttribute("value", value.getText());
                value.removeContent();
            }
        }
    } else if (element.getName().startsWith("boolean")) {
        element.setName("boolean");
        for (Object child : element.getChildren()) {
            if (child instanceof Element) {
                renameElements((Element) child);
            }
        }
    }
}
 
Example 7
Source File: ResourceServiceInterface.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Map<String, List<Element>> removeReservations(Document rup, String statusToBe)
           throws JDOMException {
	Map<String, List<Element>> res = new HashMap<String, List<Element>>();
	String where = statusToBe == null ? "" : "[" + XML_STATUSTOBE + "='" + statusToBe + "']";
	String xpath = XMLUtils.getXPATH_ActivityElement(null, XML_RESERVATION + where, null);
	List<Element> reservations = XMLUtils.getXMLObjects(rup, xpath);
	for (Element reservation : reservations) {
		Element activity = reservation.getParentElement();
		activity.removeContent(reservation);

		List<Element> l = res.get(activity.getChildText(XML_ACTIVITYNAME));
		if (l == null)	l = new ArrayList<Element>();

		Element reservationId = reservation.getChild(XML_RESERVATIONID);
		if (reservationId == null) {
			reservation.addContent(new Element(XML_RESERVATIONID));
		}
		else {
			reservationId.setText("");
		}

		l.add(reservation);
		res.put(activity.getChildText(XML_ACTIVITYNAME), l);
	}

	return res;
}
 
Example 8
Source File: Bookmarks.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method deletes a category from the data file. The category that
 * should be deleted is indicated by the category's index-number, passed as
 * parameter "nr". If the index-number is not known, use
 * {@link #deleteCategory(java.lang.String) deleteCategory(String cat)} to
 * delete that category or
 * {@link #getCategoryPosition getCategoryPosition(int nr)} to retrieve that
 * number.
 * <br><br>
 * <b>Attention!</b> All related bookmarks that are assigned to this
 * category are deleted as well!
 *
 * @param nr the index-number of the to be deleted category.
 */
public void deleteCategory(int nr) {
    // get cat-element
    Element category = bookmarks.getRootElement().getChild("category");
    // delete category from the xml-file
    if (category != null && category.removeContent(nr) != null) {
        // if we have successfully deleted a category, delete all bookmarks from
        // that category as well
        for (int cnt = getCount() - 1; cnt >= 0; cnt--) {
            // get each bookmark
            Element bm = retrieveBookmarkElement(cnt);
            try {
                // get category-atribute
                String cat = bm.getAttributeValue("cat");
                // check whether attribute exists
                if (cat != null) {
                    // get cat id
                    int catid = Integer.parseInt(cat);
                    // if catid equals the deleted category, delete bookmark
                    if (catid == nr) {
                        // get bookmark-element
                        Element child = bookmarks.getRootElement().getChild("bookmark");
                        // if it exists, remove it
                        if (child != null) {
                            child.removeContent(cnt);
                        }
                    } // in case the category-id was greater than the deleted category index-number,
                    // we have to update the category-index-number of the non-deleted bookmark
                    else if (catid > nr) {
                        bm.setAttribute("cat", String.valueOf(catid - 1));
                    }
                }
            } catch (NumberFormatException | IllegalNameException | IllegalDataException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            }
            // change modified state
            setModified(true);
        }
    }
}
 
Example 9
Source File: BlockPICreate.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String removeUnneededData (String s, List<EntityID> eids) {
	myLog.debug("REMOVEUNNEEDEDDATA");
	List<Element> eltsRemove = new ArrayList<Element>();
	Element dataList = JDOMUtil.stringToElement(s).clone();
	myLog.debug("dataList:" + JDOMUtil.elementToString(dataList));
	//Element eidData = dataList.getChild("entity");
	Element eidData = dataList;
	if (eidData != null) {
		myLog.debug("have entities");
		List<Element> children = eidData.getChildren("entity");
		for (Element child : children) {
			myLog.debug("have entity");
			Element emid = child.getChild("entity_id");
			String value = emid.getValue().trim();
			myLog.debug("value:" + value);
			// check if this one occurs in eids
			boolean match = false;
			for (EntityID eid : eids) {
				if (eid.getEmid().getValue().equals(value)) {
					// match
					myLog.debug("found match");
					match = true;
					break;
				}
			}
			if (!match) {
				eltsRemove.add(child);
			}
		}
	}
	myLog.debug("eltsRemove:" + eltsRemove.toString());
	Element eidData2 = dataList;
	if (eidData != null) {
		myLog.debug("have entities");
		for (Element eltSave : eltsRemove) {
			eidData2.removeContent(eltSave);
		}
	}
	String outputStr = JDOMUtil.elementToString(eidData2);
	myLog.debug("outputStr:" + outputStr);
	return outputStr;
}
 
Example 10
Source File: Database.java    From CardinalPGM with MIT License 4 votes vote down vote up
public void remove(Rank rank, UUID player) {
    Element rankElement = getRankElement(rank);
    if (rankContainsPlayer(rankElement, player)) {
        rankElement.removeContent(getRankPlayer(rankElement, player));
    }
}