Java Code Examples for org.dom4j.Element#getParent()

The following examples show how to use org.dom4j.Element#getParent() . 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: AbstractComponentLoader.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Nonnull
protected String loadActionId(Element element) {
    String id = element.attributeValue("id");
    if (id == null) {
        Element component = element;
        for (int i = 0; i < 2; i++) {
            if (component.getParent() != null)
                component = component.getParent();
            else
                throw new GuiDevelopmentException("No action ID provided", context);
        }
        throw new GuiDevelopmentException("No action ID provided", context,
                "Component ID", component.attributeValue("id"));
    }
    return id;
}
 
Example 2
Source File: GetXmlData.java    From hop with Apache License 2.0 5 votes vote down vote up
public void prepareNSMap( Element l ) {
  @SuppressWarnings( "unchecked" )
  List<Namespace> namespacesList = l.declaredNamespaces();
  for ( Namespace ns : namespacesList ) {
    if ( ns.getPrefix().trim().length() == 0 ) {
      data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() );
      String path = "";
      Element element = l;
      while ( element != null ) {
        if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) {
          path = GetXmlDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path;
        } else {
          path = GetXmlDataMeta.N0DE_SEPARATOR + element.getName() + path;
        }
        element = element.getParent();
      }
      data.NSPath.add( path );
    } else {
      data.NAMESPACE.put( ns.getPrefix(), ns.getURI() );
    }
  }

  @SuppressWarnings( "unchecked" )
  List<Element> elementsList = l.elements();
  for ( Element e : elementsList ) {
    prepareNSMap( e );
  }
}
 
Example 3
Source File: XMLTree.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replace nodes previously identified by the method compute() accordingly
 * to the XMLElementReplacer.
 *
 * @throws java.lang.Exception
 */
public void replace(XMLElementReplacer replacer, ParameterPool parameterPool) throws Exception {
    if (null == replacer) {
        throw new ExecutionException("XMLElementReplacer must not be null");
    }

    for (Element e : elementsOrder) {
        List<Element> newNodesList = replacer.replace(e, parameterPool);

        /* FH remove for SIGTRAN reason work with DIAMETER
        if (newNodesList.isEmpty()) {
            Element element = new DefaultElement("removedElement");
            newNodesList.add(element);
        }
        */

        elementsMap.put(e, newNodesList);

        AbstractElement parent = (AbstractElement) e.getParent();
        if (null != parent) {
            for (Element newChild : newNodesList) {
                DefaultElementInterface.insertNode((DefaultElement) parent, e, newChild);
            }
            e.detach();
            parent.remove(e);

            if (1 == newNodesList.size() && e == root) {
                root = newNodesList.get(0);
            }
        } else if (1 == newNodesList.size()) {
            newNodesList.get(0);
            root = newNodesList.get(0);
            e.detach();
        } else {
            // some error
        }
    }
}
 
Example 4
Source File: AbstractComponentLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Nullable
protected String getParentDataContainer(Element element) {
    Element parent = element.getParent();
    while (parent != null) {
        if (layoutLoaderConfig.getLoader(parent.getName()) != null) {
            return parent.attributeValue("dataContainer");
        }
        parent = parent.getParent();
    }
    return null;
}
 
Example 5
Source File: GetXMLData.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void prepareNSMap( Element l ) {
  @SuppressWarnings( "unchecked" )
  List<Namespace> namespacesList = l.declaredNamespaces();
  for ( Namespace ns : namespacesList ) {
    if ( ns.getPrefix().trim().length() == 0 ) {
      data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() );
      String path = "";
      Element element = l;
      while ( element != null ) {
        if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) {
          path = GetXMLDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path;
        } else {
          path = GetXMLDataMeta.N0DE_SEPARATOR + element.getName() + path;
        }
        element = element.getParent();
      }
      data.NSPath.add( path );
    } else {
      data.NAMESPACE.put( ns.getPrefix(), ns.getURI() );
    }
  }

  @SuppressWarnings( "unchecked" )
  List<Element> elementsList = l.elements();
  for ( Element e : elementsList ) {
    prepareNSMap( e );
  }
}
 
Example 6
Source File: XmlText.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
/**
 * Replace a XML element.
 *
 * @param xpath XPath , pointing to a XML element
 * @param object the new XML element
 * @return this instance
 * @throws XMLException
 */
@PublicAtsApi
public XmlText replace(
                        String xpath,
                        Object object ) throws XMLException {

    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }

    if (object == null) {
        throw new XMLException("Null object is not allowed for replacement."
                               + "If you want to remove existing XML element, use XMLText.remove().");
    }

    Element newElement = null;

    if (object instanceof XmlText) {
        newElement = ((XmlText) object).root;
    }

    if (object instanceof String) {
        if (StringUtils.isNullOrEmpty((String) object)) {

            throw new XMLException("Null/empty String object is not allowed for replacement."
                                   + "If you want to remove existing XML element, use XMLText.remove().");

        }
        newElement = new XmlText((String) object).root;
    }

    if (newElement == null) {
        throw new XMLException("Given object for replacing an existing one is from invallid class instance. "
                               + "Use String or XMLText instances only.");
    }

    Element oldElement = findElement(xpath);

    if (oldElement != null) {

        if (oldElement.isRootElement()) {
            throw new XMLException("You cannot replace the root element of the XML document.");
        }

        Element parent = oldElement.getParent();
        if (parent != null) {
            parent.elements().set(parent.elements().indexOf(oldElement), newElement);
        } else {
            throw new XMLException("Parent for element with xpath '" + xpath + "' could not be found.");
        }

    } else {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }

    return this;
}
 
Example 7
Source File: ScreensHelper.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected boolean isFieldGroupColumn(Element element) {
    return "column".equals(element.getName())
            && element.getParent() != null
            && FieldGroup.NAME.equals(element.getParent().getName());
}
 
Example 8
Source File: ScreensHelper.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected boolean isFormColumn(Element element) {
    return "column".equals(element.getName())
            && element.getParent() != null
            && Form.NAME.equals(element.getParent().getName());
}
 
Example 9
Source File: ScreensHelper.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected boolean isTableRows(Element element) {
    return "rows".equals(element.getName())
            && element.getParent() != null
            && StringUtils.containsIgnoreCase(element.getParent().getName(), Table.NAME);
}
 
Example 10
Source File: SubnavTag.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the {@link AdminPageBean} instance from the request. If it doesn't exist then execution is stopped
 * and nothing is printed. If it exists, retrieve values from it and render the sidebar items. The body content
 * of the tag is assumed to have an A tag in it with tokens to replace (see class description) as well
 * as having a subsidebar tag..
 *
 * @return {@link #EVAL_PAGE} after rendering the tabs.
 * @throws JspException if an exception occurs while rendering the sidebar items.
 */
@Override
public int doEndTag() throws JspException {
    // Start by getting the request from the page context
    HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();

    // Check for body of this tag and the child tag
    if (getBodyContent().getString() == null) {
        throw new JspException("Error, no template (body value) set for the sidebar tag.");
    }

    // Get the initial subpage and page IDs
    String subPageID = (String)request.getAttribute("subPageID");
    String pageID = (String)request.getAttribute("pageID");

    // If the pageID is null, use the subPageID to set it. If both the pageID and
    // subPageIDs are null, return because these are key to execution of the tag.
    if (subPageID != null || pageID != null) {

        if (pageID == null) {
            Element subPage = AdminConsole.getElemnetByID(subPageID);
            pageID = subPage.getParent().getParent().attributeValue("id");
        }

        // Top level menu items
        if (AdminConsole.getModel().elements().size() > 0) {
            JspWriter out = pageContext.getOut();
            StringBuilder buf = new StringBuilder();

            Element current = null;
            Element subcurrent = null;
            Element subnav = null;
            if (subPageID != null) {
                subcurrent = AdminConsole.getElemnetByID(subPageID);
            }
            current = AdminConsole.getElemnetByID(pageID);
            if (current != null) {
                if (subcurrent != null) {
                    subnav = subcurrent.getParent().getParent().getParent();
                }
                else {
                    subnav = current.getParent();
                }
            }

            Element currentTab = (Element)AdminConsole.getModel().selectSingleNode(
                    "//*[@id='" + pageID + "']/ancestor::tab");

            // Loop through all items in the root, print them out
            if (currentTab != null) {
                Collection items = currentTab.elements();
                if (items.size() > 0) {
                    buf.append("<ul>");
                    for (Object itemObj : items) {
                        Element item = (Element) itemObj;
                        if (item.elements().size() > 0) {
                            Element firstSubItem = (Element)item.elements().get(0);
                            String pluginName = item.attributeValue("plugin");
                            String subitemID = item.attributeValue("id");
                            String subitemName = item.attributeValue("name");
                            String subitemURL = firstSubItem.attributeValue("url");
                            String subitemDescr = item.attributeValue("description");
                            String value = getBodyContent().getString();
                            if (value != null) {
                                value = StringUtils.replace(value, "[id]", clean(subitemID));
                                value = StringUtils.replace(value, "[name]",
                                        clean(AdminConsole.getAdminText(subitemName, pluginName)));
                                value = StringUtils.replace(value, "[description]",
                                        clean(AdminConsole.getAdminText(subitemDescr, pluginName)));
                                value = StringUtils.replace(value, "[url]",
                                        request.getContextPath() + "/" + clean(subitemURL));
                            }
                            String css = getCss();
                            boolean isCurrent = subnav != null && item.equals(subnav);
                            if (isCurrent) {
                                css = getCurrentcss();
                            }
                            buf.append("<li class=\"").append(css).append("\">").append(value).append("</li>");
                        }
                    }
                    buf.append("</ul>");
                    try {
                        out.write(buf.toString());
                    }
                    catch (IOException e) {
                        throw new JspException(e);
                    }
                }
            }
        }
    }
    return EVAL_PAGE;
}