Example usage for com.liferay.portal.kernel.xml Element isRootElement

List of usage examples for com.liferay.portal.kernel.xml Element isRootElement

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element isRootElement.

Prototype

public boolean isRootElement();

Source Link

Usage

From source file:com.liferay.portlet.dynamicdatamapping.service.impl.DDMStructureLocalServiceImpl.java

License:Open Source License

protected void validate(List<Element> elements, Set<String> names) throws PortalException {

    for (Element element : elements) {
        String elementName = element.getName();

        if (elementName.equals("meta-data")) {
            continue;
        }/*from  w  w  w  . ja  v a  2 s. c om*/

        String name = element.attributeValue("name", StringPool.BLANK);
        String type = element.attributeValue("type", StringPool.BLANK);

        if (Validator.isNull(name) || name.startsWith(DDMStructureConstants.XSD_NAME_RESERVED)) {

            throw new StructureXsdException();
        }

        char[] charArray = name.toCharArray();

        for (int i = 0; i < charArray.length; i++) {
            if (!Character.isLetterOrDigit(charArray[i]) && (charArray[i] != CharPool.DASH)
                    && (charArray[i] != CharPool.UNDERLINE)) {

                throw new StructureXsdException();
            }
        }

        String path = name;

        Element parentElement = element.getParent();

        while (!parentElement.isRootElement()) {
            path = parentElement.attributeValue("name", StringPool.BLANK) + StringPool.SLASH + path;

            parentElement = parentElement.getParent();
        }

        path = path.toLowerCase();

        if (names.contains(path)) {
            throw new StructureDuplicateElementException();
        } else {
            names.add(path);
        }

        if (Validator.isNull(type)) {
            throw new StructureXsdException();
        }

        validate(element.elements(), names);
    }
}

From source file:com.liferay.portlet.journal.service.impl.JournalStructureLocalServiceImpl.java

License:Open Source License

protected void validate(List<Element> elements, Set<String> elNames) throws PortalException {

    for (Element element : elements) {
        if (element.getName().equals("meta-data")) {
            continue;
        }//from   w ww . j av a2 s.  co m

        String elName = element.attributeValue("name", StringPool.BLANK);
        String elType = element.attributeValue("type", StringPool.BLANK);

        if (Validator.isNull(elName) || elName.startsWith(JournalStructureConstants.RESERVED)) {

            throw new StructureXsdException();
        } else {
            char[] c = elType.toCharArray();

            for (int i = 0; i < c.length; i++) {
                if ((!Validator.isChar(c[i])) && (!Validator.isDigit(c[i])) && (c[i] != CharPool.DASH)
                        && (c[i] != CharPool.UNDERLINE)) {

                    throw new StructureXsdException();
                }
            }

            String completePath = elName;

            Element parentElement = element.getParent();

            while (!parentElement.isRootElement()) {
                completePath = parentElement.attributeValue("name", StringPool.BLANK) + StringPool.SLASH
                        + completePath;

                parentElement = parentElement.getParent();
            }

            String elNameLowerCase = completePath.toLowerCase();

            if (elNames.contains(elNameLowerCase)) {
                throw new DuplicateStructureElementException();
            } else {
                elNames.add(elNameLowerCase);
            }
        }

        if (Validator.isNull(elType)) {
            throw new StructureXsdException();
        }

        validate(element.elements(), elNames);
    }
}