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.zimbra.common.soap.SoapProtocol.java

License:Open Source License

/**
 * returns the first child in the soap body
 */// w  w w .j  a va  2  s  .  c  o  m
public Element getBodyElement(Element soapEnvelope) {
    if (soapEnvelope == null || !isEnvelope(soapEnvelope)) {
        // FIXME: should this be an exception?
        return null;
    }

    Element body = soapEnvelope.getOptionalElement(getBodyQName());
    if (body == null) {
        //FIXME: should this be an exception?
        return null;
    }

    Iterator<Element> it = body.elementIterator();
    if (it.hasNext())
        return it.next();
    return null;
}

From source file:com.zimbra.common.soap.SoapTestHarness.java

License:Open Source License

private void doRequest(Element request) throws IOException, ServiceException {
    mCurrent.mDocRequest = request.elementIterator().next();
    mCurrent.mDocRequest.detach();//from  ww w . ja va  2 s . com

    ZAuthToken zat = mAuthToken == null ? null : new ZAuthToken(null, mAuthToken, null);
    Element ctxt = SoapUtil.toCtxt(mSoapProto, zat, mSessionId, -1);
    if (mTargetUser != null)
        SoapUtil.addTargetAccountToCtxt(ctxt, null, mTargetUser);
    if (mResponseProto == SoapProtocol.SoapJS)
        SoapUtil.addResponseProtocolToCtxt(ctxt, mResponseProto);
    mCurrent.mSoapRequest = mSoapProto.soapEnvelope(mCurrent.mDocRequest, ctxt);

    long start = System.currentTimeMillis();
    mCurrent.mSoapResponse = mTransport.invokeRaw(mCurrent.mSoapRequest);
    long finish = System.currentTimeMillis();

    mCurrent.mTime = finish - start;
    mCurrent.mDocResponse = mResponseProto.getBodyElement(mCurrent.mSoapResponse);
}

From source file:com.zimbra.cs.account.accesscontrol.RightManager.java

License:Open Source License

private void parseAttrs(Element eAttrs, Right right) throws ServiceException {
    if (!(right instanceof AttrRight))
        throw ServiceException.PARSE_ERROR(E_ATTRS + " is only allowed for admin getAttrs or setAttrs right",
                null);/*from w w w. ja v a  2  s . c  o m*/

    AttrRight attrRight = (AttrRight) right;
    for (Iterator elemIter = eAttrs.elementIterator(); elemIter.hasNext();) {
        Element elem = (Element) elemIter.next();
        if (elem.getName().equals(E_A))
            parseAttr(elem, attrRight);
        else
            throw ServiceException.PARSE_ERROR("invalid element: " + elem.getName(), null);
    }
}

From source file:com.zimbra.cs.account.accesscontrol.RightManager.java

License:Open Source License

private void parseRights(Element eAttrs, Right right) throws ServiceException {
    if (!(right instanceof ComboRight))
        throw ServiceException.PARSE_ERROR(E_RIGHTS + " is only allowed for admin combo right", null);

    ComboRight comboRight = (ComboRight) right;

    for (Iterator elemIter = eAttrs.elementIterator(); elemIter.hasNext();) {
        Element elem = (Element) elemIter.next();
        if (elem.getName().equals(E_R))
            parseRight(elem, comboRight);
        else//from w ww.j  a v  a 2  s.  com
            throw ServiceException.PARSE_ERROR("invalid element: " + elem.getName(), null);
    }
}

From source file:com.zimbra.cs.account.accesscontrol.RightManager.java

License:Open Source License

private Right parseRight(Element eRight) throws ServiceException {
    String name = eRight.attributeValue(A_NAME);

    // system define rights cannot contain a ".".  "." is the separator for inline attr right
    if (name.contains("."))
        throw ServiceException.PARSE_ERROR("righ name cannot contain dot(.): " + name, null);

    boolean userRight = getBooleanAttr(eRight, A_USER_RIGHT, false);

    // System.out.println("Parsing right " + "(" +  (userRight?"user":"admin") + ") " + name);
    Right right;/*ww w  .ja v  a2  s. c  o m*/

    AdminRight.RightType rightType = null;
    String targetTypeStr = eRight.attributeValue(A_TARGET_TYPE, null);

    if (userRight) {
        TargetType targetType;
        if (targetTypeStr != null) {
            targetType = TargetType.fromCode(targetTypeStr);
        } else {
            targetType = TargetType.account; // default target type for user right is account
        }

        right = new UserRight(name);
        right.setTargetType(targetType);

        String fallback = eRight.attributeValue(A_FALLBACK, null);
        if (fallback != null) {
            CheckRightFallback fb = loadFallback(fallback, right);
            right.setFallback(fb);
        }

    } else {
        String rt = eRight.attributeValue(A_TYPE);
        if (rt == null) {
            throw ServiceException.PARSE_ERROR("missing attribute [" + A_TYPE + "]", null);
        }
        rightType = AdminRight.RightType.fromString(rt);

        right = AdminRight.newAdminSystemRight(name, rightType);
        if (targetTypeStr != null) {
            String taregtTypes[] = targetTypeStr.split(TARGET_TYPE_DELIMITER);
            for (String tt : taregtTypes) {
                TargetType targetType = TargetType.fromCode(tt);
                right.setTargetType(targetType);
            }
        }
    }

    String grantTargetTypeStr = eRight.attributeValue(A_GRANT_TARGET_TYPE, null);
    if (grantTargetTypeStr != null) {
        TargetType grantTargetType = TargetType.fromCode(grantTargetTypeStr);
        right.setGrantTargetType(grantTargetType);
    }

    boolean cache = getBooleanAttr(eRight, A_CACHE, false);
    if (cache) {
        right.setCacheable();
    }

    for (Iterator elemIter = eRight.elementIterator(); elemIter.hasNext();) {
        Element elem = (Element) elemIter.next();
        if (elem.getName().equals(E_DESC)) {
            parseDesc(elem, right);
        } else if (elem.getName().equals(E_HELP)) {
            parseHelp(elem, right);
        } else if (elem.getName().equals(E_UI)) {
            parseUI(elem, right);
        } else if (elem.getName().equals(E_DEFAULT)) {
            parseDefault(elem, right);
        } else if (elem.getName().equals(E_ATTRS)) {
            parseAttrs(elem, right);
        } else if (elem.getName().equals(E_RIGHTS)) {
            parseRights(elem, right);
        } else {
            throw ServiceException.PARSE_ERROR("invalid element: " + elem.getName(), null);
        }
    }

    // verify that all required fields are set and populate internal data
    right.completeRight();

    return right;
}

From source file:com.zimbra.cs.account.accesscontrol.RightManager.java

License:Open Source License

private boolean loadSystemRights(File file, List<File> processedFiles, File[] allFiles)
        throws ServiceException, FileNotFoundException {
    Document doc;/*w  w w . j  a  va2 s .co m*/
    try (FileInputStream fis = new FileInputStream(file)) {
        doc = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(fis);
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        ZimbraLog.acl.debug("Problem parsing file %s", file, e);
        throw ServiceException.PARSE_ERROR("Problem parsing file for system rights", null);
    }
    Element root = doc.getRootElement();
    if (!root.getName().equals(E_RIGHTS)) {
        throw ServiceException.PARSE_ERROR("root tag is not " + E_RIGHTS, null);
    }

    // preset rights can only be defined in our core right definition file
    boolean allowPresetRight = CoreRightDefFiles.isCoreRightFile(file);

    boolean seenRight = false;
    for (Iterator iter = root.elementIterator(); iter.hasNext();) {
        Element elem = (Element) iter.next();

        // see if all include files are processed already
        if (elem.getName().equals(E_INCLUDE)) {
            // all <include>'s have to appear before <right>'s
            if (seenRight) {
                throw ServiceException.PARSE_ERROR(
                        E_INCLUDE + " cannot appear after any right definition: " + elem.getName(), null);
            }

            String includeFile = elem.attributeValue(A_FILE);

            // make sure the include file exists
            boolean foundFile = false;
            for (File f : allFiles) {
                if (f.getName().equals(includeFile)) {
                    foundFile = true;
                    break;
                }
            }
            if (!foundFile) {
                throw ServiceException.PARSE_ERROR("cannot find include file " + includeFile, null);
            }

            boolean processed = false;
            for (File f : processedFiles) {
                if (f.getName().equals(includeFile)) {
                    processed = true;
                    break;
                }
            }
            if (!processed) {
                return false;
            } else {
                continue;
            }
        } else if (elem.getName().equals(E_RIGHT)) {
            if (!seenRight) {
                seenRight = true;
                ZimbraLog.acl.debug("Loading %s", file.getAbsolutePath());
            }
            loadRight(elem, file, allowPresetRight);
        } else if (elem.getName().equals(E_HELP)) {
            loadHelp(elem, file);
        } else if (elem.getName().equals(E_UI)) {
            loadUI(elem, file);
        } else {
            throw ServiceException.PARSE_ERROR("unknown element: " + elem.getName(), null);
        }
    }

    return true;
}

From source file:com.zimbra.cs.account.accesscontrol.RightManager.java

License:Open Source License

private void loadHelp(Element eHelp, File file) throws ServiceException {
    String name = eHelp.attributeValue(A_NAME);
    if (name == null) {
        throw ServiceException.PARSE_ERROR("no name specified", null);
    }/*from w  w w.  j a  v a2 s .  c  om*/

    checkName(name);

    Help help = new Help(name);

    for (Iterator elemIter = eHelp.elementIterator(); elemIter.hasNext();) {
        Element elem = (Element) elemIter.next();
        if (elem.getName().equals(E_DESC)) {
            if (help.getDesc() != null) {
                throw ServiceException.PARSE_ERROR("desc for help " + name + " already set", null);
            }
            help.setDesc(elem.getText());
        } else if (elem.getName().equals(E_ITEM)) {
            help.addItem(elem.getText());
        } else {
            throw ServiceException.PARSE_ERROR("invalid element: " + elem.getName(), null);
        }
    }

    // make all required bits are set in the help
    help.validate();

    sHelp.put(name, help);
}

From source file:com.zimbra.cs.account.AttributeManager.java

License:Open Source License

private void loadAttrs(File file, Document doc) {
    Element root = doc.getRootElement();

    if (!root.getName().equals(E_ATTRS)) {
        error(null, file, "root tag is not " + E_ATTRS);
        return;//from ww  w  .  ja  va 2 s .  c om
    }

    Map<Integer, String> idsSeen = new HashMap<Integer, String>();

    String group = root.attributeValue(A_GROUP);
    String groupIdStr = root.attributeValue(A_GROUP_ID);

    if (group == null ^ groupIdStr == null) {
        error(null, file, A_GROUP + " and " + A_GROUP_ID + " both have to be both specified");
    }
    int groupId = -1;
    if (group != null) {
        try {
            groupId = Integer.valueOf(groupIdStr);
        } catch (NumberFormatException nfe) {
            error(null, file, A_GROUP_ID + " is not a number: " + groupIdStr);
        }
    }
    if (groupId == 2) {
        error(null, file, A_GROUP_ID + " is not valid (used by ZimbraObjectClass)");
    } else if (groupId > 0) {
        if (mGroupMap.containsKey(groupId)) {
            error(null, file, "duplicate group id: " + groupId);
        } else if (mGroupMap.containsValue(group)) {
            error(null, file, "duplicate group: " + group);
        } else {
            mGroupMap.put(groupId, group);
        }
    }

    NEXT_ATTR: for (Iterator iter = root.elementIterator(); iter.hasNext();) {
        Element eattr = (Element) iter.next();
        if (!eattr.getName().equals(E_ATTR)) {
            error(null, file, "unknown element: " + eattr.getName());
            continue;
        }

        AttributeCallback callback = null;
        AttributeType type = null;
        AttributeOrder order = null;
        String value = null;
        String min = null;
        String max = null;
        boolean immutable = false;
        //            boolean ignore = false;
        int id = -1;
        String parentOid = null;
        AttributeCardinality cardinality = null;
        Set<AttributeClass> requiredIn = null;
        Set<AttributeClass> optionalIn = null;
        Set<AttributeFlag> flags = null;

        String canonicalName = null;
        String name = eattr.attributeValue(A_NAME);
        if (name == null) {
            error(null, file, "no name specified");
            continue;
        }
        canonicalName = name.toLowerCase();

        List<AttributeServerType> requiresRestart = null;
        Version deprecatedSinceVer = null;
        List<Version> sinceVer = null;
        Boolean ephemeral = false;

        for (Iterator attrIter = eattr.attributeIterator(); attrIter.hasNext();) {
            Attribute attr = (Attribute) attrIter.next();
            String aname = attr.getName();
            if (aname.equals(A_NAME)) {
                // nothing to do - already processed
            } else if (aname.equals(A_CALLBACK)) {
                callback = loadCallback(attr.getValue());
            } else if (aname.equals(A_IMMUTABLE)) {
                immutable = "1".equals(attr.getValue());
            } else if (aname.equals(A_MAX)) {
                max = attr.getValue();
            } else if (aname.equals(A_MIN)) {
                min = attr.getValue();
            } else if (aname.equals(A_TYPE)) {
                type = AttributeType.getType(attr.getValue());
                if (type == null) {
                    error(name, file, "unknown <attr> type: " + attr.getValue());
                    continue NEXT_ATTR;
                }
            } else if (aname.equals(A_VALUE)) {
                value = attr.getValue();
            } else if (aname.equals(A_PARENT_OID)) {
                parentOid = attr.getValue();
                if (!parentOid.matches("^\\d+(\\.\\d+)+"))
                    error(name, file, "invalid parent OID " + parentOid + ": must be an OID");
            } else if (aname.equals(A_ID)) {
                try {
                    id = Integer.parseInt(attr.getValue());
                    if (id < 0) {
                        error(name, file, "invalid id " + id + ": must be positive");
                    }
                } catch (NumberFormatException nfe) {
                    error(name, file, aname + " is not a number: " + attr.getValue());
                }
            } else if (aname.equals(A_CARDINALITY)) {
                try {
                    cardinality = AttributeCardinality.valueOf(attr.getValue());
                } catch (IllegalArgumentException iae) {
                    error(name, file, aname + " is not valid: " + attr.getValue());
                }
            } else if (aname.equals(A_REQUIRED_IN)) {
                requiredIn = parseClasses(name, file, attr.getValue());
            } else if (aname.equals(A_OPTIONAL_IN)) {
                optionalIn = parseClasses(name, file, attr.getValue());
            } else if (aname.equals(A_FLAGS)) {
                flags = parseFlags(name, file, attr.getValue());
            } else if (aname.equals(A_ORDER)) {
                try {
                    order = AttributeOrder.valueOf(attr.getValue());
                } catch (IllegalArgumentException iae) {
                    error(name, file, aname + " is not valid: " + attr.getValue());
                }
            } else if (aname.equals(A_REQUIRES_RESTART)) {
                requiresRestart = parseRequiresRestart(name, file, attr.getValue());

            } else if (aname.equals(A_DEPRECATED_SINCE)) {
                String depreSince = attr.getValue();
                if (depreSince != null) {
                    try {
                        deprecatedSinceVer = new Version(depreSince);
                    } catch (ServiceException e) {
                        error(name, file,
                                aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")");
                    }
                }

            } else if (aname.equals(A_SINCE)) {
                String since = attr.getValue();
                if (since != null) {
                    try {
                        String[] versions = since.split(",");
                        sinceVer = new ArrayList<Version>();
                        for (String verStr : versions) {
                            sinceVer.add(new Version(verStr.trim()));
                        }
                    } catch (ServiceException e) {
                        error(name, file,
                                aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")");
                    }
                }
            } else {
                error(name, file, "unknown <attr> attr: " + aname);
            }
        }

        List<String> globalConfigValues = new LinkedList<String>();
        List<String> globalConfigValuesUpgrade = null; // note: init to null instead of empty List
        List<String> defaultCOSValues = new LinkedList<String>();
        List<String> defaultExternalCOSValues = new LinkedList<String>();
        List<String> defaultCOSValuesUpgrade = null; // note: init to null instead of empty List
        String description = null;
        String deprecateDesc = null;

        for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) {
            Element elem = (Element) elemIter.next();
            if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE)) {
                globalConfigValues.add(elem.getText());
            } else if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE_UPGRADE)) {
                if (globalConfigValuesUpgrade == null)
                    globalConfigValuesUpgrade = new LinkedList<String>();
                globalConfigValuesUpgrade.add(elem.getText());
            } else if (elem.getName().equals(E_DEFAULT_COS_VALUE)) {
                defaultCOSValues.add(elem.getText());
            } else if (elem.getName().equals(E_DEFAULT_EXTERNAL_COS_VALUE)) {
                defaultExternalCOSValues.add(elem.getText());
            } else if (elem.getName().equals(E_DEFAULT_COS_VALUE_UPGRADE)) {
                if (defaultCOSValuesUpgrade == null)
                    defaultCOSValuesUpgrade = new LinkedList<String>();
                defaultCOSValuesUpgrade.add(elem.getText());
            } else if (elem.getName().equals(E_DESCRIPTION)) {
                if (description != null) {
                    error(name, file, "more than one " + E_DESCRIPTION);
                }
                description = elem.getText();
            } else if (elem.getName().equals(E_DEPRECATE_DESC)) {
                if (deprecateDesc != null) {
                    error(name, file, "more than one " + E_DEPRECATE_DESC);
                }
                deprecateDesc = elem.getText();
            } else {
                error(name, file, "unknown element: " + elem.getName());
            }
        }

        if (deprecatedSinceVer != null && deprecateDesc == null)
            error(name, file, "missing element " + E_DEPRECATE_DESC);
        else if (deprecatedSinceVer == null && deprecateDesc != null)
            error(name, file, "missing attr " + A_DEPRECATED_SINCE);

        if (deprecatedSinceVer != null) {
            String deprecateInfo = "Deprecated since: " + deprecatedSinceVer.toString() + ".  " + deprecateDesc;
            if (description == null)
                description = deprecateInfo;
            else
                description = deprecateInfo + ".  Orig desc: " + description;
        }

        // since is required after(inclusive) oid 525 - first attribute in 5.0
        if (sinceVer == null && id >= 525) {
            error(name, file, "missing since (required after(inclusive) oid 710)");
        }

        // Check that if id is specified, then cardinality is specified.
        if (id > 0 && cardinality == null) {
            error(name, file, "cardinality not specified");
        }

        // Check that if id is specified, then at least one object class is defined
        if (id > 0 && (optionalIn != null && optionalIn.isEmpty())
                && (requiredIn != null && requiredIn.isEmpty())) {
            error(name, file,
                    "atleast one of " + A_REQUIRED_IN + " or " + A_OPTIONAL_IN + " must be specified");
        }

        // Check that if id is specified, it must be unique
        if (id > 0) {
            String idForAttr = idsSeen.get(Integer.valueOf(id));
            if (idForAttr != null) {
                error(name, file, "duplicate id: " + id + " is already used for " + idForAttr);
            } else {
                idsSeen.put(Integer.valueOf(id), name);
            }
        }

        // Check that if it is COS inheritable it is in account and COS classes
        checkFlag(name, file, flags, AttributeFlag.accountInherited, AttributeClass.account, AttributeClass.cos,
                null, requiredIn, optionalIn);

        // Check that if it is COS-domain inheritable it is in account and COS and domain classes
        checkFlag(name, file, flags, AttributeFlag.accountCosDomainInherited, AttributeClass.account,
                AttributeClass.cos, AttributeClass.domain, requiredIn, optionalIn);

        // Check that if it is domain inheritable it is in domain and global config
        checkFlag(name, file, flags, AttributeFlag.domainInherited, AttributeClass.domain,
                AttributeClass.globalConfig, null, requiredIn, optionalIn);

        // Check that if it is server inheritable it is in server and global config
        checkFlag(name, file, flags, AttributeFlag.serverInherited, AttributeClass.server,
                AttributeClass.globalConfig, null, requiredIn, optionalIn);

        // Check that if it is serverPreferAlwaysOn it is in server and alwaysOnCluster
        checkFlag(name, file, flags, AttributeFlag.serverPreferAlwaysOn, AttributeClass.server,
                AttributeClass.alwaysOnCluster, null, requiredIn, optionalIn);

        // Check that is cardinality is single, then not more than one
        // default value is specified
        if (cardinality == AttributeCardinality.single) {
            if (globalConfigValues.size() > 1) {
                error(name, file, "more than one global config value specified for cardinality "
                        + AttributeCardinality.single);
            }
            if (defaultCOSValues.size() > 1 || defaultExternalCOSValues.size() > 1) {
                error(name, file, "more than one default COS value specified for cardinality "
                        + AttributeCardinality.single);
            }
        }

        checkEphemeralFlags(name, file, flags, min, max, cardinality);

        AttributeInfo info = createAttributeInfo(name, id, parentOid, groupId, callback, type, order, value,
                immutable, min, max, cardinality, requiredIn, optionalIn, flags, globalConfigValues,
                defaultCOSValues, defaultExternalCOSValues, globalConfigValuesUpgrade, defaultCOSValuesUpgrade,
                mMinimize ? null : description, requiresRestart, sinceVer, deprecatedSinceVer);

        if (mAttrs.get(canonicalName) != null) {
            error(name, file, "duplicate definiton");
        }
        mAttrs.put(canonicalName, info);

        if (flags != null) {
            for (AttributeFlag flag : flags) {
                mFlagToAttrsMap.get(flag).add(name);
                if (flag == AttributeFlag.accountCosDomainInherited)
                    mFlagToAttrsMap.get(AttributeFlag.accountInherited).add(name);
            }
        }

        if (requiredIn != null || optionalIn != null) {
            if (requiredIn != null) {
                for (AttributeClass klass : requiredIn) {
                    mClassToAttrsMap.get(klass).add(name);
                    mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase());
                }
            }
            if (optionalIn != null) {
                for (AttributeClass klass : optionalIn) {
                    mClassToAttrsMap.get(klass).add(name);
                    mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase());
                }
            }
        }

        if (isBinaryType(type)) {
            mBinaryAttrs.add(canonicalName);
        } else if (isBinaryTransferType(type)) {
            mBinaryTransferAttrs.add(canonicalName);
        }

        if (flags != null && flags.contains(AttributeFlag.ephemeral)) {
            mEphemeralAttrs.put(canonicalName, info);
            mEphemeralAttrsSet.add(name);
            if (!info.isDynamic()) {
                addNonDynamicEphemeralAttr(info);
            }
        }
    }
}

From source file:com.zimbra.cs.account.AttributeManager.java

License:Open Source License

private void loadObjectClasses(File file, Document doc) {
    Element root = doc.getRootElement();

    if (!root.getName().equals(E_OBJECTCLASSES)) {
        error(null, file, "root tag is not " + E_OBJECTCLASSES);
        return;/*from  w w  w.ja v  a  2  s.  c o m*/
    }

    String group = root.attributeValue(A_GROUP);
    String groupIdStr = root.attributeValue(A_GROUP_ID);
    if (group == null ^ groupIdStr == null) {
        error(null, file, A_GROUP + " and " + A_GROUP_ID + " both have to be both specified");
    }
    int groupId = -1;
    if (group != null) {
        try {
            groupId = Integer.valueOf(groupIdStr);
        } catch (NumberFormatException nfe) {
            error(null, file, A_GROUP_ID + " is not a number: " + groupIdStr);
        }
    }
    if (groupId == 1) {
        error(null, file, A_GROUP_ID + " is not valid (used by ZimbraAttrType)");
    } else if (groupId > 0) {
        if (mOCGroupMap.containsKey(groupId)) {
            error(null, file, "duplicate group id: " + groupId);
        } else if (mOCGroupMap.containsValue(group)) {
            error(null, file, "duplicate group: " + group);
        } else {
            mOCGroupMap.put(groupId, group);
        }
    }

    for (Iterator iter = root.elementIterator(); iter.hasNext();) {
        Element eattr = (Element) iter.next();
        if (!eattr.getName().equals(E_OBJECTCLASS)) {
            error(null, file, "unknown element: " + eattr.getName());
            continue;
        }

        int id = -1;
        ObjectClassType type = null;
        String canonicalName = null;
        String name = eattr.attributeValue(A_NAME);
        if (name == null) {
            error(null, file, "no name specified");
            continue;
        }
        canonicalName = name.toLowerCase();

        for (Iterator attrIter = eattr.attributeIterator(); attrIter.hasNext();) {
            Attribute attr = (Attribute) attrIter.next();
            String aname = attr.getName();
            if (aname.equals(A_NAME)) {
                // nothing to do - already processed
            } else if (aname.equals(A_TYPE)) {
                type = ObjectClassType.valueOf(attr.getValue());
            } else if (aname.equals(A_ID)) {
                try {
                    id = Integer.parseInt(attr.getValue());
                    if (id < 0) {
                        error(name, file, "invalid id " + id + ": must be positive");
                    }
                } catch (NumberFormatException nfe) {
                    error(name, file, aname + " is not a number: " + attr.getValue());
                }
            } else {
                error(name, file, "unknown <attr> attr: " + aname);
            }
        }

        List<String> superOCs = new LinkedList<String>();
        String description = null;
        List<String> comment = null;
        for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) {
            Element elem = (Element) elemIter.next();
            if (elem.getName().equals(E_SUP)) {
                superOCs.add(elem.getText());
            } else if (elem.getName().equals(E_DESCRIPTION)) {
                if (description != null) {
                    error(name, file, "more than one " + E_DESCRIPTION);
                }
                description = elem.getText();
            } else if (elem.getName().equals(E_COMMENT)) {
                if (comment != null) {
                    error(name, file, "more than one " + E_COMMENT);
                }
                comment = new ArrayList<String>();
                String[] lines = elem.getText().trim().split("\\n");
                for (String line : lines)
                    comment.add(line.trim());
            } else {
                error(name, file, "unknown element: " + elem.getName());
            }
        }

        // Check that if all bits are specified
        if (id <= 0) {
            error(name, file, "id not specified");
        }

        if (type == null) {
            error(name, file, "type not specified");
        }

        if (description == null) {
            error(name, file, "desc not specified");
        }

        if (superOCs.isEmpty()) {
            error(name, file, "sup not specified");
        }

        // there must be a one-to-one mapping between enums in AttributeClass and ocs defined in the xml
        AttributeClass attrClass = AttributeClass.getAttributeClass(name);
        if (attrClass == null) {
            error(name, file, "unknown class in AttributeClass: " + name);
        }

        ObjectClassInfo info = new ObjectClassInfo(attrClass, name, id, groupId, type, superOCs,
                mMinimize ? null : description, mMinimize ? null : comment);
        if (mOCs.get(canonicalName) != null) {
            error(name, file, "duplicate objectclass definiton");
        }
        mOCs.put(canonicalName, info);

    }
}

From source file:com.zimbra.cs.client.soap.LmcCheckSpellingRequest.java

License:Open Source License

protected LmcSoapResponse parseResponseXML(Element responseXML) throws ServiceException {
    boolean isAvailable = DomUtil.getAttrBoolean(responseXML, MailConstants.A_AVAILABLE);
    LmcCheckSpellingResponse response = new LmcCheckSpellingResponse(isAvailable);

    Iterator i = responseXML.elementIterator();
    while (i.hasNext()) {
        Element misspelled = (Element) i.next();
        String word = DomUtil.getAttr(misspelled, MailConstants.A_WORD);
        String suggestions = DomUtil.getAttr(misspelled, MailConstants.A_SUGGESTIONS);
        response.addMisspelled(word, suggestions.split(","));
    }/*w w  w  .ja  v a  2 s  .co  m*/

    return response;
}