Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

In this page you can find the example usage for org.dom4j Element elementIterator.

Prototype

Iterator<Element> elementIterator();

Source Link

Document

Returns an iterator over all this elements child elements.

Usage

From source file:com.sun.tools.xjc.reader.dtd.bindinfo.BIElement.java

License:Open Source License

/**
 * Wraps a given &lt;element> element in the binding file.
 * //from  w w  w  .ja  v a 2 s.  com
 * <p>
 * Should be created only from {@link BindInfo}.
 */
BIElement(BindInfo bi, Element _e) {
    this.parent = bi;
    this.e = _e;

    {
        Element c = e.element("content");
        if (c != null) {
            if (c.attribute("property") != null) {
                // if @property is there, this is a general declaration
                this.rest = BIContent.create(c, this);
            } else {
                // this must be a model-based declaration
                Iterator itr = c.elementIterator();
                while (itr.hasNext()) {
                    Element p = (Element) itr.next();
                    if (p.getName().equals("rest"))
                        this.rest = BIContent.create(p, this);
                    else
                        this.contents.add(BIContent.create(p, this));
                }
            }
        }
    }

    // parse <attribute>s
    Iterator itr = e.elementIterator("attribute");
    while (itr.hasNext()) {
        BIAttribute a = new BIAttribute(this, (Element) itr.next());
        attributes.put(a.name(), a);
    }

    if (isClass()) {
        // if this is a class-declaration, create JClass object now
        String className = e.attributeValue("class");
        if (className == null)
            // none was specified. infer the name.
            className = parent.nameConverter.toClassName(name());
        clazz = parent.classFactory.createInterface(parent.getTargetPackage(), className, null); // TODO: source location support
    } else {
        // this is not an element-class declaration
        clazz = null;
    }

    // process conversion declarations
    itr = e.elementIterator("conversion");
    while (itr.hasNext()) {
        BIConversion c = new BIUserConversion(bi, (Element) itr.next());
        conversions.put(c.name(), c);
    }
    itr = e.elementIterator("enumeration");
    while (itr.hasNext()) {
        BIConversion c = BIEnumeration.create((Element) itr.next(), this);
        conversions.put(c.name(), c);
    }

    // parse <constructor>s
    itr = e.elementIterator("constructor");
    while (itr.hasNext())
        constructors.add(new BIConstructor((Element) itr.next()));
}

From source file:com.synesoft.fisp.app.common.utils.urlcfg.UrlBackXmlCfg.java

License:Open Source License

public static UrlBackConfiguration analyzeXmlFile() throws DocumentException {

    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(new File(urlcfgPath + "urlback.xml"));
    // get root element
    Element messageElement = document.getRootElement();

    // get root's sub element
    Iterator<Element> oneLevelElementItor = messageElement.elementIterator();

    List<UrlCfg> urlList = new ArrayList<UrlCfg>();
    List<UrlCfgs> urlCfgsList = new ArrayList<UrlCfgs>();

    while (oneLevelElementItor.hasNext()) {
        Element e1 = oneLevelElementItor.next();
        Iterator<Element> twoLevelElementItor = e1.elementIterator();
        // get url list
        if (e1.getName().equals("url-list")) {
            while (twoLevelElementItor.hasNext()) {
                Element e2 = twoLevelElementItor.next();
                UrlCfg uc = new UrlCfg();
                uc.setId(e2.attributeValue("id"));
                uc.setValue(e2.attributeValue("value"));
                urlList.add(uc);/*from www  . jav a  2  s. co  m*/
            }
        } else if (e1.getName().equals("url-cfgs")) {
            // get url back cfgs
            while (twoLevelElementItor.hasNext()) {
                UrlCfgs urlcfgs = new UrlCfgs();
                Element e2 = twoLevelElementItor.next();
                List<UrlCfg> urlBackCfgList = new ArrayList<UrlCfg>();
                Iterator<Element> threeLevelElementItor = e2.elementIterator();
                while (threeLevelElementItor.hasNext()) {
                    Element e3 = threeLevelElementItor.next();
                    UrlCfg uc = new UrlCfg();
                    uc.setId(e3.attributeValue("id"));
                    urlBackCfgList.add(uc);
                }
                urlcfgs.setUrlCfgList(urlBackCfgList);
                urlcfgs.setId(e2.attributeValue("id"));
                urlCfgsList.add(urlcfgs);
            }
        }
    }

    UrlBackConfiguration ubcfg = new UrlBackConfiguration();
    ubcfg.setUrlList(urlList);
    ubcfg.setUrlCfgs(urlCfgsList);
    return ubcfg;
}

From source file:com.taobao.sqlautoreview.XmlToSQL.java

License:Open Source License

@SuppressWarnings("unchecked")
private void dealInclude(Element root) {
    String refid;// w  w  w . ja v a  2 s. com
    String refsql;
    Element sqlElement;
    for (Iterator<Element> iterator = root.elementIterator(); iterator.hasNext();) {
        sqlElement = iterator.next();
        if (sqlElement.getName().equals("sql") && sqlElement.attributeValue("id") != null) {
            refid = sqlElement.attributeValue("id");
            refsql = getRealSQL(sqlElement);
            hash.put(refid, refsql);
        } else {
            continue;
        }
    }
}

From source file:com.thinkberg.moxo.dav.LockHandler.java

License:Apache License

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {//from w w  w .ja  v  a 2  s .  c om
        Lock lock = LockManager.getInstance().checkCondition(object, getIf(request));
        if (lock != null) {
            sendLockAcquiredResponse(response, lock);
            return;
        }
    } catch (LockException e) {
        // handle locks below
    }

    try {
        SAXReader saxReader = new SAXReader();
        Document lockInfo = saxReader.read(request.getInputStream());
        //log(lockInfo);

        Element rootEl = lockInfo.getRootElement();
        String lockScope = null, lockType = null;
        Object owner = null;
        Iterator elIt = rootEl.elementIterator();
        while (elIt.hasNext()) {
            Element el = (Element) elIt.next();
            if (TAG_LOCKSCOPE.equals(el.getName())) {
                lockScope = el.selectSingleNode("*").getName();
            } else if (TAG_LOCKTYPE.equals(el.getName())) {
                lockType = el.selectSingleNode("*").getName();
            } else if (TAG_OWNER.equals(el.getName())) {
                // TODO correctly handle owner
                Node subEl = el.selectSingleNode("*");
                if (subEl != null && TAG_HREF.equals(subEl.getName())) {
                    owner = new URL(el.selectSingleNode("*").getText());
                } else {
                    owner = el.getText();
                }
            }
        }

        log("LOCK(" + lockType + ", " + lockScope + ", " + owner + ")");

        Lock requestedLock = new Lock(object, lockType, lockScope, owner, getDepth(request),
                getTimeout(request));
        try {
            LockManager.getInstance().acquireLock(requestedLock);
            sendLockAcquiredResponse(response, requestedLock);
        } catch (LockConflictException e) {
            response.sendError(SC_LOCKED);
        } catch (IllegalArgumentException e) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.thinkberg.moxo.dav.PropFindHandler.java

License:Apache License

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    SAXReader saxReader = new SAXReader();
    try {//  www  .ja v a2  s  .com
        Document propDoc = saxReader.read(request.getInputStream());
        // log(propDoc);
        Element propFindEl = propDoc.getRootElement();
        Element propEl = (Element) propFindEl.elementIterator().next();
        String propElName = propEl.getName();

        List<String> requestedProperties = new ArrayList<String>();
        boolean ignoreValues = false;
        if (TAG_PROP.equals(propElName)) {
            for (Object id : propEl.elements()) {
                requestedProperties.add(((Element) id).getName());
            }
        } else if (TAG_ALLPROP.equals(propElName)) {
            requestedProperties = DavResource.ALL_PROPERTIES;
        } else if (TAG_PROPNAMES.equals(propElName)) {
            requestedProperties = DavResource.ALL_PROPERTIES;
            ignoreValues = true;
        }

        FileObject object = getResourceManager().getFileObject(request.getPathInfo());
        if (object.exists()) {
            // respond as XML encoded multi status
            response.setContentType("text/xml");
            response.setCharacterEncoding("UTF-8");
            response.setStatus(SC_MULTI_STATUS);

            Document multiStatusResponse = getMultiStatusRespons(object, requestedProperties,
                    getBaseUrl(request), getDepth(request), ignoreValues);
            //log(multiStatusResponse);

            // write the actual response
            XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat());
            writer.write(multiStatusResponse);
            writer.flush();
            writer.close();

        } else {
            log("!! " + object.getName().getPath() + " NOT FOUND");
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } catch (DocumentException e) {
        log("!! inavlid request: " + e.getMessage());
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.thinkberg.webdav.LockHandler.java

License:Apache License

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {//from   w  ww  .j a va  2  s. co  m
        final LockManager manager = LockManager.getInstance();
        final LockManager.EvaluationResult evaluation = manager.evaluateCondition(object, getIf(request));
        if (!evaluation.result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        } else {
            if (!evaluation.locks.isEmpty()) {
                LOG.debug(String.format("discovered locks: %s", evaluation.locks));
                sendLockAcquiredResponse(response, evaluation.locks.get(0));
                return;
            }
        }
    } catch (LockConflictException e) {
        List<Lock> locks = e.getLocks();
        for (Lock lock : locks) {
            if (Lock.EXCLUSIVE.equals(lock.getType())) {
                response.sendError(SC_LOCKED);
                return;
            }
        }
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }

    try {
        SAXReader saxReader = new SAXReader();
        Document lockInfo = saxReader.read(request.getInputStream());
        //log(lockInfo);

        Element rootEl = lockInfo.getRootElement();
        String lockScope = null, lockType = null;
        Object owner = null;
        Iterator elIt = rootEl.elementIterator();
        while (elIt.hasNext()) {
            Element el = (Element) elIt.next();
            if (TAG_LOCKSCOPE.equals(el.getName())) {
                lockScope = el.selectSingleNode("*").getName();
            } else if (TAG_LOCKTYPE.equals(el.getName())) {
                lockType = el.selectSingleNode("*").getName();
            } else if (TAG_OWNER.equals(el.getName())) {
                // TODO correctly handle owner
                Node subEl = el.selectSingleNode("*");
                if (subEl != null && TAG_HREF.equals(subEl.getName())) {
                    owner = new URL(el.selectSingleNode("*").getText());
                } else {
                    owner = el.getText();
                }
            }
        }

        LOG.debug("LOCK(" + lockType + ", " + lockScope + ", " + owner + ")");

        Lock requestedLock = new Lock(object, lockType, lockScope, owner, getDepth(request),
                getTimeout(request));
        try {
            LockManager.getInstance().acquireLock(requestedLock);
            sendLockAcquiredResponse(response, requestedLock);
        } catch (LockConflictException e) {
            response.sendError(SC_LOCKED);
        } catch (IllegalArgumentException e) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void createPipelineAsFirstPipelineInGroup(String pipelineName, String groupName) {
    Element groupContents = getGroup(groupName);
    ArrayList<Element> pipelines = new ArrayList<Element>();
    while (groupContents.elementIterator().hasNext()) {
        Element pipelineElement = (Element) groupContents.elementIterator().next();
        pipelines.add(pipelineElement);/*from   w  ww .j a  v  a  2  s.  com*/
        groupContents.remove(pipelineElement);
    }

    createASimpleGitPipeline(pipelineName);

    for (Element e : pipelines) {
        groupContents.add(e);
    }
}

From source file:com.wavemaker.runtime.data.spring.ConfigurationExt.java

License:Open Source License

@Override
protected void add(org.dom4j.Document doc) throws MappingException {
    Element hmNode = doc.getRootElement();
    Iterator rootChildren = hmNode.elementIterator();

    while (rootChildren.hasNext()) {
        final Element element = (Element) rootChildren.next();
        final String elementName = element.getName();

        if ("query".equals(elementName)) {
            String query = element.getText();
            query = insertTenantIdInQuery(query);
            element.setText(query);//from  w w  w  . ja  v  a2 s .  c om
        }
    }

    super.add(doc);
}

From source file:com.webslingerz.jpt.PageTemplateImpl.java

License:Open Source License

/**
 * With all of our namespace woes, getting an XPath expression to work has
 * proven futile, so we'll recurse through the tree ourselves to find what
 * we need.//w  w  w  .j  a v a  2 s .co  m
 */
private void findSlots(Element element, Map<String, Slot> slots) {
    // System.err.println( "element: " + element.getName() );
    for (Iterator i = element.attributes().iterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        // System.err.println( "\t" + attribute.getName() + "\t" +
        // attribute.getQualifiedName() );
    }

    // Look for our attribute
    // String qualifiedAttributeName = this.metalNamespacePrefix +
    // ":fill-slot";
    // String name = element.attributeValue( qualifiedAttributeName );
    String name = element.attributeValue("fill-slot");
    if (name != null) {
        slots.put(name, new SlotImpl(element));
    }

    // Recurse into child elements
    for (Iterator i = element.elementIterator(); i.hasNext();) {
        findSlots((Element) i.next(), slots);
    }
}

From source file:com.wifi.util.msg.MessageBuilder.java

@SuppressWarnings("unchecked")
public AppMessage buildAppMessage() throws DocumentException {
    AppMessage msg = new AppMessage();
    try {/* w w w. j a  v  a2s  .co  m*/
        Document document = DocumentHelper.parseText(this.xmlText);
        Element rootElt = document.getRootElement();
        if (!rootElt.getName().equals(AppMessage.MESSAGE_TAG)) {
            System.err.println("The xml message tag is incorrect!" + rootElt.getName());
            return null;
        }

        Element headElt = rootElt.element(AppMessage.HEADER_TAG);
        if (headElt == null) {
            System.err.println("The message content is incorrect [no message header]!");
            return null;
        }

        MessageHeader header = new MessageHeader();

        header.setDevMac(headElt.elementTextTrim(MessageHeader.DEV_MAC_TAG));
        header.setHwId(headElt.elementTextTrim(MessageHeader.HW_ID_TAG));
        header.setLicense(headElt.elementTextTrim(MessageHeader.LICENSE_TAG));
        header.setMagic(headElt.elementTextTrim(MessageHeader.MAGIC_TAG));
        header.setMsgId(headElt.elementTextTrim(MessageHeader.MSG_ID_TAG));
        header.setSrcIp(headElt.elementTextTrim(MessageHeader.SRC_IP_TAG));
        header.setTargetIp(headElt.elementTextTrim(MessageHeader.TARGET_IP_TAG));
        msg.setHeader(header);
        System.out.println(header);

        Element bodyElt = rootElt.element(AppMessage.BODY_TAG);
        if (bodyElt == null) {
            System.out.println("The message doesn't exists message body!");
        } else {
            MessageBody body = new MessageBody();
            Map<String, String> map = new HashMap<>();
            Iterator<Element> bdyIterator = bodyElt.elementIterator();
            while (bdyIterator.hasNext()) {
                Element element = bdyIterator.next();
                map.put(element.getName(), element.getTextTrim());
            }
            body.setItemsMap(map);
            msg.setBody(body);
            System.out.println(body);
        }

    } catch (Exception e) {
        System.err.println("parse error: " + e.getMessage());
        return null;
    }

    return msg;
}