Package com.liferay.portal.kernel.xml

Examples of com.liferay.portal.kernel.xml.Element


        if (fields == null) {
            return null;
        }
        else {
            Element fieldsEl = (Element)fields.get(field + _ELEMENTS_SUFFIX);

            if (fieldsEl == null) {
                return null;
            }
            else {
View Full Code Here


            }
        }

        Document doc = _saxReader.read(is);

        Element root = doc.getRootElement();

        Iterator<Element> itr1 = root.elements("hint-collection").iterator();

        while (itr1.hasNext()) {
            Element hintCollection = itr1.next();

            String name = hintCollection.attributeValue("name");

            Map<String, String> hints = _hintCollections.get(name);

            if (hints == null) {
                hints = new HashMap<String, String>();

                _hintCollections.put(name, hints);
            }

            Iterator<Element> itr2 = hintCollection.elements("hint").iterator();

            while (itr2.hasNext()) {
                Element hint = itr2.next();

                String hintName = hint.attributeValue("name");
                String hintValue = hint.getText();

                hints.put(hintName, hintValue);
            }
        }

        itr1 = root.elements("model").iterator();

        while (itr1.hasNext()) {
            Element model = itr1.next();

            String name = model.attributeValue("name");

            Map<String, String> defaultHints = new HashMap<String, String>();

            _defaultHints.put(name, defaultHints);

            Element defaultHintsEl = model.element("default-hints");

            if (defaultHintsEl != null) {
                Iterator<Element> itr2 = defaultHintsEl.elements(
                        "hint").iterator();

                while (itr2.hasNext()) {
                    Element hint = itr2.next();

                    String hintName = hint.attributeValue("name");
                    String hintValue = hint.getText();

                    defaultHints.put(hintName, hintValue);
                }
            }

            Map<String, Object> fields = (Map<String, Object>)_modelFields.get(name);

            if (fields == null) {
                fields = new LinkedHashMap<String, Object>();

                _modelFields.put(name, fields);
            }

            _models.add(name);

            Iterator<Element> itr2 = model.elements("field").iterator();

            while (itr2.hasNext()) {
                Element field = itr2.next();

                String fieldName = field.attributeValue("name");
                String fieldType = field.attributeValue("type");
                boolean fieldLocalized = GetterUtil.getBoolean(
                        field.attributeValue("localized"));

                Map<String, String> fieldHints = new HashMap<String, String>();

                fieldHints.putAll(defaultHints);

                Iterator<Element> itr3 = field.elements(
                        "hint-collection").iterator();

                while (itr3.hasNext()) {
                    Element hintCollection = itr3.next();

                    Map<String, String> hints = _hintCollections.get(
                            hintCollection.attributeValue("name"));

                    fieldHints.putAll(hints);
                }

                itr3 = field.elements("hint").iterator();

                while (itr3.hasNext()) {
                    Element hint = itr3.next();

                    String hintName = hint.attributeValue("name");
                    String hintValue = hint.getText();

                    fieldHints.put(hintName, hintValue);
                }

                Tuple fieldSanitize = null;

                Element sanitize = field.element("sanitize");

                if (sanitize != null) {
                    String contentType = sanitize.attributeValue(
                            "content-type");
                    String modes = sanitize.attributeValue("modes");

                    fieldSanitize = new Tuple(fieldName, contentType, modes);
                }

                Map<String, Tuple> fieldValidators =
                        new TreeMap<String, Tuple>();

                itr3 = field.elements("validator").iterator();

                while (itr3.hasNext()) {
                    Element validator = itr3.next();

                    String validatorName = validator.attributeValue("name");

                    if (Validator.isNull(validatorName)) {
                        continue;
                    }

                    String validatorErrorMessage = GetterUtil.getString(
                            validator.attributeValue("error-message"));
                    String validatorValue = GetterUtil.getString(
                            validator.getText());
                    boolean customValidator = isCustomValidator(validatorName);

                    if (customValidator) {
                        validatorName = buildCustomValidatorName(validatorName);
                    }
View Full Code Here

    public static final String AUTHOR = "Brian Wing Shun Chan";

    public static String getContent(String fileName) throws Exception {
        Document document = _getContentDocument(fileName);

        Element rootElement = document.getRootElement();

        Element authorElement = null;
        Element namespaceElement = null;
        Map<String, Element> entityElements = new TreeMap<String, Element>();
        Map<String, Element> exceptionElements = new TreeMap<String, Element>();

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

            if (elementName.equals("author")) {
                element.detach();

                if (authorElement != null) {
                    throw new IllegalArgumentException(
                            "There can only be one author element");
                }

                authorElement = element;
            }
            else if (elementName.equals("namespace")) {
                element.detach();

                if (namespaceElement != null) {
                    throw new IllegalArgumentException(
                            "There can only be one namespace element");
                }

                namespaceElement = element;
            }
            else if (elementName.equals("entity")) {
                element.detach();

                String name = element.attributeValue("name");

                entityElements.put(StringUtil.toLowerCase(name), element);
            }
            else if (elementName.equals("exceptions")) {
                element.detach();

                for (Element exceptionElement : element.elements("exception")) {
                    exceptionElement.detach();

                    exceptionElements.put(
                            exceptionElement.getText(), exceptionElement);
                }
            }
        }

        if (authorElement != null) {
            rootElement.add(authorElement);
        }

        if (namespaceElement == null) {
            throw new IllegalArgumentException(
                    "The namespace element is required");
        }
        else {
            rootElement.add(namespaceElement);
        }

        _addElements(rootElement, entityElements);

        if (!exceptionElements.isEmpty()) {
            Element exceptionsElement = rootElement.addElement("exceptions");

            _addElements(exceptionsElement, exceptionElements);
        }

        return document.asXML();
View Full Code Here

            String content = getContent(fileName);

            Document document = SAXReaderUtil.read(content, true);

            Element rootElement = document.getRootElement();

            String packagePath = rootElement.attributeValue("package-path");

            if (Validator.isNull(packagePath)) {
                throw new IllegalArgumentException(
                        "The package-path attribute is required");
            }

            _outputPath =
                    _implDir + "/" + StringUtil.replace(packagePath, ".", "/");

            _serviceOutputPath =
                    _apiDir + "/" + StringUtil.replace(packagePath, ".", "/");

            if (Validator.isNotNull(_testDir)) {
                _testOutputPath =
                        _testDir + "/" + StringUtil.replace(packagePath, ".", "/");
            }

            _packagePath = packagePath;

            _autoNamespaceTables = GetterUtil.getBoolean(
                    rootElement.attributeValue("auto-namespace-tables"),
                    _autoNamespaceTables);

            Element authorElement = rootElement.element("author");

            if (authorElement != null) {
                _author = authorElement.getText();
            }
            else {
                _author = AUTHOR;
            }

            Element portletElement = rootElement.element("portlet");
            Element namespaceElement = rootElement.element("namespace");

            if (portletElement != null) {
                _portletName = portletElement.attributeValue("name");

                _portletShortName = portletElement.attributeValue("short-name");

                _portletPackageName = TextFormatter.format(
                        _portletName, TextFormatter.B);

                _outputPath += "/" + _portletPackageName;

                _serviceOutputPath += "/" + _portletPackageName;

                _testOutputPath += "/" + _portletPackageName;

                _packagePath += "." + _portletPackageName;
            }
            else {
                _portletShortName = namespaceElement.getText();
            }

            _portletShortName = _portletShortName.trim();

            for (char c : _portletShortName.toCharArray()) {
                if (!Validator.isChar(c) && (c != CharPool.UNDERLINE)) {
                    throw new RuntimeException(
                            "The namespace element must be a valid keyword");
                }
            }

            _ejbList = new ArrayList<Entity>();
            _entityMappings = new HashMap<String, EntityMapping>();

            List<Element> entityElements = rootElement.elements("entity");

            for (Element entityElement : entityElements) {
                _parseEntity(entityElement);
            }

            List<String> exceptionList = new ArrayList<String>();

            Element exceptionsElement = rootElement.element("exceptions");

            if (exceptionsElement != null) {
                List<Element> exceptionElements = exceptionsElement.elements(
                        "exception");

                for (Element exceptionElement : exceptionElements) {
                    exceptionList.add(exceptionElement.getText());
                }
View Full Code Here

    private static void _addElements(
            Element element, Map<String, Element> elements) {

        for (Map.Entry<String, Element> entry : elements.entrySet()) {
            Element childElement = entry.getValue();

            element.add(childElement);
        }
    }
View Full Code Here

        String content = FileUtil.read(new File(fileName));

        Document document = SAXReaderUtil.read(content);

        Element rootElement = document.getRootElement();

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

            if (!elementName.equals("service-builder-import")) {
                continue;
            }

            element.detach();

            String dirName = fileName.substring(
                    0, fileName.lastIndexOf(StringPool.SLASH) + 1);
            String serviceBuilderImportFileName = element.attributeValue(
                    "file");

            Document serviceBuilderImportDocument = _getContentDocument(
                    dirName + serviceBuilderImportFileName);

            Element serviceBuilderImportRootElement =
                    serviceBuilderImportDocument.getRootElement();

            for (Element serviceBuilderImportElement :
                    serviceBuilderImportRootElement.elements()) {

                serviceBuilderImportElement.detach();

                rootElement.add(serviceBuilderImportElement);
            }
View Full Code Here

    private void _createRemotingXml() throws Exception {
        StringBundler sb = new StringBundler();

        Document document = SAXReaderUtil.read(new File(_springFileName));

        Element rootElement = document.getRootElement();

        List<Element> beanElements = rootElement.elements("bean");

        for (Element beanElement : beanElements) {
            String beanId = beanElement.attributeValue("id");

            if (beanId.endsWith("Service") &&
View Full Code Here

        List<Element> columnElements = entityElement.elements("column");

        boolean permissionedModel = false;

        if (uuid) {
            Element columnElement = SAXReaderUtil.createElement("column");

            columnElement.addAttribute("name", "uuid");
            columnElement.addAttribute("type", "String");

            columnElements.add(0, columnElement);
        }

        for (Element columnElement : columnElements) {
            String columnName = columnElement.attributeValue("name");

            if (columnName.equals("resourceBlockId") &&
                    !ejbName.equals("ResourceBlock")) {

                permissionedModel = true;
            }

            String columnDBName = columnElement.attributeValue("db-name");

            if (Validator.isNull(columnDBName)) {
                columnDBName = columnName;

                if (_badColumnNames.contains(columnName)) {
                    columnDBName += StringPool.UNDERLINE;
                }
            }

            String columnType = columnElement.attributeValue("type");
            boolean primary = GetterUtil.getBoolean(
                    columnElement.attributeValue("primary"));
            boolean accessor = GetterUtil.getBoolean(
                    columnElement.attributeValue("accessor"));
            boolean filterPrimary = GetterUtil.getBoolean(
                    columnElement.attributeValue("filter-primary"));
            String collectionEntity = columnElement.attributeValue("entity");

            String mappingTable = columnElement.attributeValue("mapping-table");

            if (Validator.isNotNull(mappingTable)) {
                if (_badTableNames.contains(mappingTable)) {
                    mappingTable += StringPool.UNDERLINE;
                }

                if (_autoNamespaceTables) {
                    mappingTable =
                            _portletShortName + StringPool.UNDERLINE + mappingTable;
                }
            }

            String idType = columnElement.attributeValue("id-type");
            String idParam = columnElement.attributeValue("id-param");
            boolean convertNull = GetterUtil.getBoolean(
                    columnElement.attributeValue("convert-null"), false);
            boolean lazy = GetterUtil.getBoolean(
                    columnElement.attributeValue("lazy"), true);
            boolean localized = GetterUtil.getBoolean(
                    columnElement.attributeValue("localized"));
            boolean colJsonEnabled = GetterUtil.getBoolean(
                    columnElement.attributeValue("json-enabled"), jsonEnabled);
            boolean containerModel = GetterUtil.getBoolean(
                    columnElement.attributeValue("container-model"));
            boolean parentContainerModel = GetterUtil.getBoolean(
                    columnElement.attributeValue("parent-container-model"));

            EntityColumn col = new EntityColumn(
                    columnName, columnDBName, columnType, primary, accessor,
                    filterPrimary, collectionEntity, mappingTable, idType, idParam,
                    convertNull, lazy, localized, colJsonEnabled, containerModel,
                    parentContainerModel);

            if (primary) {
                pkList.add(col);
            }

            if (columnType.equals("Collection")) {
                collectionList.add(col);
            }
            else {
                regularColList.add(col);

                if (columnType.equals("Blob")) {
                    blobList.add(col);
                }
            }

            columnList.add(col);

            if (Validator.isNotNull(collectionEntity) &&
                    Validator.isNotNull(mappingTable)) {

                EntityMapping entityMapping = new EntityMapping(
                        mappingTable, ejbName, collectionEntity);

                int ejbNameWeight = StringUtil.startsWithWeight(
                        mappingTable, ejbName);
                int collectionEntityWeight = StringUtil.startsWithWeight(
                        mappingTable, collectionEntity);

                if ((ejbNameWeight > collectionEntityWeight) ||
                        ((ejbNameWeight == collectionEntityWeight) &&
                                (ejbName.compareTo(collectionEntity) > 0))) {

                    _entityMappings.put(mappingTable, entityMapping);
                }
            }
        }

        EntityOrder order = null;

        Element orderElement = entityElement.element("order");

        if (orderElement != null) {
            boolean asc = true;

            if ((orderElement.attribute("by") != null) &&
                    orderElement.attributeValue("by").equals("desc")) {

                asc = false;
            }

            List<EntityColumn> orderColsList = new ArrayList<EntityColumn>();

            order = new EntityOrder(asc, orderColsList);

            List<Element> orderColumnElements = orderElement.elements(
                    "order-column");

            for (Element orderColElement : orderColumnElements) {
                String orderColName = orderColElement.attributeValue("name");
                boolean orderColCaseSensitive = GetterUtil.getBoolean(
                        orderColElement.attributeValue("case-sensitive"), true);

                boolean orderColByAscending = asc;

                String orderColBy = GetterUtil.getString(
                        orderColElement.attributeValue("order-by"));

                if (orderColBy.equals("asc")) {
                    orderColByAscending = true;
                }
                else if (orderColBy.equals("desc")) {
                    orderColByAscending = false;
                }

                EntityColumn col = Entity.getColumn(orderColName, columnList);

                col.setOrderColumn(true);

                col = (EntityColumn)col.clone();

                col.setCaseSensitive(orderColCaseSensitive);
                col.setOrderByAscending(orderColByAscending);

                orderColsList.add(col);
            }
        }

        List<EntityFinder> finderList = new ArrayList<EntityFinder>();

        List<Element> finderElements = entityElement.elements("finder");

        if (uuid) {
            if (columnList.contains(new EntityColumn("companyId"))) {
                Element finderElement = SAXReaderUtil.createElement("finder");

                finderElement.addAttribute("name", "Uuid_C");
                finderElement.addAttribute("return-type", "Collection");

                Element finderColumnElement = finderElement.addElement(
                        "finder-column");

                finderColumnElement.addAttribute("name", "uuid");

                finderColumnElement = finderElement.addElement("finder-column");

                finderColumnElement.addAttribute("name", "companyId");

                finderElements.add(0, finderElement);
            }

            if (columnList.contains(new EntityColumn("groupId"))) {
                Element finderElement = SAXReaderUtil.createElement("finder");

                if (ejbName.equals("Layout")) {
                    finderElement.addAttribute("name", "UUID_G_P");
                }
                else {
                    finderElement.addAttribute("name", "UUID_G");
                }

                finderElement.addAttribute("return-type", ejbName);
                finderElement.addAttribute("unique", "true");

                Element finderColumnElement = finderElement.addElement(
                        "finder-column");

                finderColumnElement.addAttribute("name", "uuid");

                finderColumnElement = finderElement.addElement("finder-column");

                finderColumnElement.addAttribute("name", "groupId");

                if (ejbName.equals("Layout")) {
                    finderColumnElement = finderElement.addElement(
                            "finder-column");

                    finderColumnElement.addAttribute("name", "privateLayout");
                }

                finderElements.add(0, finderElement);
            }

            Element finderElement = SAXReaderUtil.createElement("finder");

            finderElement.addAttribute("name", "Uuid");
            finderElement.addAttribute("return-type", "Collection");

            Element finderColumnElement = finderElement.addElement(
                    "finder-column");

            finderColumnElement.addAttribute("name", "uuid");

            finderElements.add(0, finderElement);
        }

        if (permissionedModel) {
            Element finderElement = SAXReaderUtil.createElement("finder");

            finderElement.addAttribute("name", "ResourceBlockId");
            finderElement.addAttribute("return-type", "Collection");

            Element finderColumnElement = finderElement.addElement(
                    "finder-column");

            finderColumnElement.addAttribute("name", "resourceBlockId");

            finderElements.add(0, finderElement);
        }

        String alias = TextFormatter.format(ejbName, TextFormatter.I);

        if (_badAliasNames.contains(StringUtil.toLowerCase(alias))) {
            alias += StringPool.UNDERLINE;
        }

        for (Element finderElement : finderElements) {
            String finderName = finderElement.attributeValue("name");
            String finderReturn = finderElement.attributeValue("return-type");
            boolean finderUnique = GetterUtil.getBoolean(
                    finderElement.attributeValue("unique"));

            String finderWhere = finderElement.attributeValue("where");

            if (Validator.isNotNull(finderWhere)) {
                for (EntityColumn column : columnList) {
                    String name = column.getName();

                    if (finderWhere.contains(name)) {
                        finderWhere = finderWhere.replaceAll(
                                name, alias + "." + name);
                    }
                }
            }

            boolean finderDBIndex = GetterUtil.getBoolean(
                    finderElement.attributeValue("db-index"), true);

            List<EntityColumn> finderColsList = new ArrayList<EntityColumn>();

            List<Element> finderColumnElements = finderElement.elements(
                    "finder-column");

            for (Element finderColumnElement : finderColumnElements) {
                String finderColName = finderColumnElement.attributeValue(
                        "name");
                boolean finderColCaseSensitive = GetterUtil.getBoolean(
                        finderColumnElement.attributeValue("case-sensitive"), true);
                String finderColComparator = GetterUtil.getString(
                        finderColumnElement.attributeValue("comparator"), "=");
                String finderColArrayableOperator =
                        GetterUtil.getString(
                                finderColumnElement.attributeValue(
                                        "arrayable-operator"));

                EntityColumn col = Entity.getColumn(finderColName, columnList);

                if (!col.isFinderPath()) {
View Full Code Here

  }

  protected boolean isJournalStructureXSD(String xsd) throws Exception {
    Document document = SAXReaderUtil.read(xsd);

    Element rootElement = document.getRootElement();

    Attribute availableLocalesAttribute = rootElement.attribute(
      "available-locales");

    if (availableLocalesAttribute == null) {
      return true;
    }
View Full Code Here

    URL url = bundle.getEntry("WEB-INF/web.xml");

    if (url != null) {
      Document document = SAXReaderUtil.read(url);

      Element rootElement = document.getRootElement();

      readContextParameters(bundle, rootElement, webXML);
      readFilters(bundle, rootElement, webXML);
      readListeners(bundle, rootElement, webXML);
      readServlets(bundle, rootElement, webXML);
View Full Code Here

TOP

Related Classes of com.liferay.portal.kernel.xml.Element

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.