Package org.dom4j.tree

Examples of org.dom4j.tree.DefaultElement


   * @param newElement
   * @param id
   * @return
   */
  public boolean addElementAfter(DefaultElement newElement, String id) {
    DefaultElement beforeElement = rootNode.getElementByIdentifier(id);

    if (beforeElement == null) return false;

    if (beforeElement instanceof CPItem) {
      // beforeElement is a <item>
      // ==> newElement has to be an <item>
      CPItem beforeItem = (CPItem) beforeElement;
      DefaultElement parent = beforeItem.getParentElement();
      if (!(newElement instanceof CPItem)) { throw new OLATRuntimeException(CPOrganizations.class, "only <item> element allowed",
          new Exception()); }
      if (parent instanceof CPItem) {
        CPItem p = (CPItem) parent;
        p.addItemAt((CPItem) newElement, beforeItem.getPosition() + 1);
      } else if (parent instanceof CPOrganization) {
        CPOrganization o = (CPOrganization) parent;
        o.addItemAt((CPItem) newElement, beforeItem.getPosition() + 1);
      } else {
        throw new OLATRuntimeException(CPOrganizations.class, "you cannot add an <item> element to a " + parent.getName() + " element",
            new Exception());
      }

    }

View Full Code Here


   * @param booleanFlag indicates whether to remove linked resources as well...!
   *          (needed for moving elements)
   */
  public void removeElement(String identifier, boolean resourceFlag) {

    DefaultElement el = rootNode.getElementByIdentifier(identifier);
    if (el != null) {
      if (el instanceof CPItem) {
        // element is CPItem
        CPItem item = (CPItem) el;

View Full Code Here

    return linkCount;
  }

  public void moveElement(String nodeID, String newParentID, int position) {
    DefaultElement elementToMove = rootNode.getElementByIdentifier(nodeID);
    if (elementToMove != null) {
      if (elementToMove instanceof CPItem) {
        removeElement(nodeID, false);
        addElement(elementToMove, newParentID, position);
      } else if (elementToMove instanceof CPOrganization) {
View Full Code Here

   *
   * @param sourceID
   * @param targetID
   */
  public String copyElement(String sourceID, String targetID) {
    DefaultElement elementToCopy = rootNode.getElementByIdentifier(sourceID);
    if (elementToCopy == null) { throw new OLATRuntimeException(CPOrganizations.class, "element with identifier \"" + sourceID
        + "\" not found..!", new Exception()); }

    if (elementToCopy instanceof CPItem) {
      CPItem newItem = (CPItem) elementToCopy.clone();
      cloneResourceOfItemAndSubitems(newItem);
      addElementAfter(newItem, targetID);
      return newItem.getIdentifier();
    } else {
      // if (elementToCopy.getClass().equals(CPOrganization.class)) {
View Full Code Here

   * is copied.
   *
   * @param item
   */
  private void cloneResourceOfItem(CPItem item) {
    DefaultElement ref = getElementByIdentifier(item.getIdentifierRef());
    if (ref != null && ref instanceof CPResource) {
      CPResource resource = (CPResource) ref;
      // Clone the resource if the linked file is editable (i.e. it is an html,
      // Word or Excel file)
      String href = resource.getFullHref();
View Full Code Here

   * @deprecated use auto-generated id CodeHelper.getGlobalForeverUniqueID()
   */
  private String _getNextCopyID(String identifier) {
    // FIXME: i18n
    int n = 1;
    DefaultElement e = rootNode.getElementByIdentifier(identifier + " (Copy " + n + ")");
    while (e != null) {
      n++;
      e = rootNode.getElementByIdentifier(identifier + " (Copy " + n + ")");
    }
    return identifier + " (Copy " + n + ")";
View Full Code Here

   *
   * @param id
   * @return
   */
  public String getPageByItemID(String id) {
    DefaultElement ele = getElementByIdentifier(id);
    if (ele instanceof CPItem) {
      CPItem item = (CPItem) ele;
      if (item.getIdentifierRef() == null || item.getIdentifierRef().equals("")) { return null; }
      DefaultElement resElement = getElementByIdentifier(item.getIdentifierRef());
      if (resElement instanceof CPResource) {
        CPResource res = (CPResource) resElement;
        return res.getFullHref();
      } else {
        Logger log = Logger.getLogger(this.getClass().getName());
View Full Code Here

   * @param itemID the identifier of the item
   * @return returns the title. returns null if element is not found, or element
   *         is not an <item>
   */
  public String getItemTitle(String itemID) {
    DefaultElement ele = getElementByIdentifier(itemID);
    if (ele == null) { return null; }
    if (ele instanceof CPItem) {
      CPItem item = (CPItem) ele;
      return item.getTitle();
    } else {
View Full Code Here

    cpcore.addElement(newPage, parentID, 0);
    return newPage.getIdentifier();
  }

  protected void updatePage(CPPage page) {
    DefaultElement ele = cpcore.getElementByIdentifier(page.getIdentifier());
    if (ele instanceof CPItem) {
      CPItem item = (CPItem) ele;
      item.setTitle(page.getTitle());
      item.setMetadata(page.getMetadata());
      String itemIdentifierRef = item.getIdentifierRef();
View Full Code Here

    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static DefaultElement readPomDependencies(final Document pomDocument, final List<Dependency> dependencies) {

        DefaultElement dependenciesNode = null;
       
        try {

            HashMap map = new HashMap();
            map.put("default", XmlConstants.POM_DEFAULT_NAMESPACE);
View Full Code Here

TOP

Related Classes of org.dom4j.tree.DefaultElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.