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

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

Introduction

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

Prototype

public String attributeValue(String name);

Source Link

Usage

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

protected void importSiteServices(PortletDataContext portletDataContext, List<Element> siteServiceElements)
        throws Exception {

    for (Element serviceElement : siteServiceElements) {
        String path = serviceElement.attributeValue("path");

        Document siteServiceDocument = SAXReaderUtil.read(portletDataContext.getZipEntryAsString(path));

        serviceElement = siteServiceDocument.getRootElement();

        _portletImportController.importServicePortletPreferences(portletDataContext, serviceElement);
    }/*from  w w  w.ja v a  2s.  c  o  m*/
}

From source file:com.liferay.site.internal.exportimport.staged.model.repository.StagedGroupStagedModelRepository.java

License:Open Source License

public Group fetchExistingGroup(PortletDataContext portletDataContext, Element referenceElement) {

    long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));
    long liveGroupId = GetterUtil.getLong(referenceElement.attributeValue("live-group-id"));

    if ((groupId == 0) || (liveGroupId == 0)) {
        return null;
    }//  w  w  w. ja  v a 2 s  .com

    return fetchExistingGroup(portletDataContext, groupId, liveGroupId);
}

From source file:com.liferay.site.teams.web.internal.exportimport.data.handler.TeamStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Team team) throws Exception {

    long userId = portletDataContext.getUserId(team.getUserUuid());

    Team existingTeam = fetchExistingTeam(team.getUuid(), portletDataContext.getScopeGroupId(), team.getName());

    Team importedTeam = null;//from  w  w  w.j a  va2 s.c  o m

    if (existingTeam == null) {
        ServiceContext serviceContext = portletDataContext.createServiceContext(team);

        serviceContext.setUuid(team.getUuid());

        importedTeam = _teamLocalService.addTeam(userId, portletDataContext.getScopeGroupId(), team.getName(),
                team.getDescription(), serviceContext);
    } else {
        importedTeam = _teamLocalService.updateTeam(existingTeam.getTeamId(), team.getName(),
                team.getDescription());
    }

    List<Element> userElements = portletDataContext.getReferenceElements(team, User.class);

    for (Element userElement : userElements) {
        long companyId = GetterUtil.getLong(userElement.attributeValue("company-id"));
        String uuid = userElement.attributeValue("uuid");

        User user = _userLocalService.fetchUserByUuidAndCompanyId(uuid, companyId);

        if ((user != null) && !_userLocalService.hasTeamUser(importedTeam.getTeamId(), user.getUserId())) {

            _userLocalService.addTeamUser(importedTeam.getTeamId(), user);
        }
    }

    List<Element> userGroupElements = portletDataContext.getReferenceElements(team, UserGroup.class);

    for (Element userGroupElement : userGroupElements) {
        long companyId = GetterUtil.getLong(userGroupElement.attributeValue("company-id"));
        String uuid = userGroupElement.attributeValue("uuid");

        UserGroup userGroup = _userGroupLocalService.fetchUserGroupByUuidAndCompanyId(uuid, companyId);

        if ((userGroup != null) && !_userGroupLocalService.hasTeamUserGroup(importedTeam.getTeamId(),
                userGroup.getUserGroupId())) {

            _userGroupLocalService.addTeamUserGroup(importedTeam.getTeamId(), userGroup);
        }
    }

    portletDataContext.importClassedModel(team, importedTeam);
}

From source file:com.liferay.skinny.service.impl.SkinnyServiceImpl.java

License:Open Source License

protected void populateSkinnyJournalArticle(SkinnyJournalArticle skinnyJournalArticle, Element parentElement) {

    List<Element> elements = parentElement.elements();

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

        if (elementName.equals("dynamic-element")) {
            Element dynamicElementElement = element.element("dynamic-content");

            if (dynamicElementElement != null) {
                skinnyJournalArticle.addDynamicElement(element.attributeValue("name"),
                        dynamicElementElement.getTextTrim());
            }//from   w  w w . ja  v a 2s.  c om
        } else {
            populateSkinnyJournalArticle(skinnyJournalArticle, element);
        }
    }
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected void checkServiceXMLFinders(String fileName, Element entityElement, String entityName)
        throws Exception {

    _columnNames = getColumnNames(fileName, entityName);

    FinderElementComparator finderElementComparator = new FinderElementComparator();

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

    for (int i = 1; i < finderElements.size(); i++) {
        Element finderElement = finderElements.get(i);
        Element previousFinderElement = finderElements.get(i - 1);

        if (finderElementComparator.compare(previousFinderElement, finderElement) > 0) {

            String finderName = finderElement.attributeValue("name");

            processErrorMessage(fileName, "order: " + fileName + " " + entityName + " " + finderName);
        }//  w w  w  . j a  v a2 s .  co m
    }
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected void checkServiceXMLReferences(String fileName, Element entityElement, String entityName) {

    String previousReferenceEntity = StringPool.BLANK;
    String previousReferencePackagePath = StringPool.BLANK;

    List<Element> referenceElements = entityElement.elements("reference");

    for (Element referenceElement : referenceElements) {
        String referenceEntity = referenceElement.attributeValue("entity");
        String referencePackagePath = referenceElement.attributeValue("package-path");

        if (Validator.isNotNull(previousReferencePackagePath)) {
            if ((previousReferencePackagePath.compareToIgnoreCase(referencePackagePath) > 0)
                    || (previousReferencePackagePath.equals(referencePackagePath)
                            && (previousReferenceEntity.compareToIgnoreCase(referenceEntity) > 0))) {

                processErrorMessage(fileName, "sort: " + fileName + " " + entityName + " " + referenceEntity);
            }//  w  w  w  . jav a 2s  . c o  m
        }

        previousReferenceEntity = referenceEntity;
        previousReferencePackagePath = referencePackagePath;
    }
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected String formatAntXML(String fileName, String content) throws Exception {

    String newContent = trimContent(content, true);

    newContent = fixAntXMLProjectName(fileName, newContent);

    Document document = saxReaderUtil.read(newContent);

    Element rootElement = document.getRootElement();

    String previousName = StringPool.BLANK;

    List<Element> targetElements = rootElement.elements("target");

    for (Element targetElement : targetElements) {
        String name = targetElement.attributeValue("name");

        if (name.equals("Test")) {
            name = StringUtil.toLowerCase(name);
        }//  w  w w . j  a  v a2 s .  co  m

        if (name.compareTo(previousName) < -1) {
            processErrorMessage(fileName, fileName + " has an unordered target " + name);

            break;
        }

        previousName = name;
    }

    return newContent;
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected String formatFriendlyURLRoutesXML(String absolutePath, String content) throws Exception {

    if (isExcluded(_friendlyUrlRoutesSortExclusions, absolutePath)) {
        return content;
    }/*from  ww  w.j  a v a2  s. c  o  m*/

    Document document = saxReaderUtil.read(content);

    Element rootElement = document.getRootElement();

    List<ComparableRoute> comparableRoutes = new ArrayList<ComparableRoute>();

    for (Element routeElement : rootElement.elements("route")) {
        String pattern = routeElement.elementText("pattern");

        ComparableRoute comparableRoute = new ComparableRoute(pattern);

        for (Element generatedParameterElement : routeElement.elements("generated-parameter")) {

            String name = generatedParameterElement.attributeValue("name");
            String value = generatedParameterElement.getText();

            comparableRoute.addGeneratedParameter(name, value);
        }

        for (Element ignoredParameterElement : routeElement.elements("ignored-parameter")) {

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

            comparableRoute.addIgnoredParameter(name);
        }

        for (Element implicitParameterElement : routeElement.elements("implicit-parameter")) {

            String name = implicitParameterElement.attributeValue("name");
            String value = implicitParameterElement.getText();

            comparableRoute.addImplicitParameter(name, value);
        }

        for (Element overriddenParameterElement : routeElement.elements("overridden-parameter")) {

            String name = overriddenParameterElement.attributeValue("name");
            String value = overriddenParameterElement.getText();

            comparableRoute.addOverriddenParameter(name, value);
        }

        comparableRoutes.add(comparableRoute);
    }

    Collections.sort(comparableRoutes);

    String mainReleaseVersion = getMainReleaseVersion();

    StringBundler sb = new StringBundler();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append("<!DOCTYPE routes PUBLIC \"-//Liferay//DTD Friendly URL ");
    sb.append("Routes ");
    sb.append(mainReleaseVersion);
    sb.append("//EN\" \"http://www.liferay.com/dtd/");
    sb.append("liferay-friendly-url-routes_");
    sb.append(StringUtil.replace(mainReleaseVersion, StringPool.PERIOD, StringPool.UNDERLINE));
    sb.append(".dtd\">\n\n<routes>\n");

    for (ComparableRoute comparableRoute : comparableRoutes) {
        sb.append("\t<route>\n");
        sb.append("\t\t<pattern>");
        sb.append(comparableRoute.getPattern());
        sb.append("</pattern>\n");

        Map<String, String> generatedParameters = comparableRoute.getGeneratedParameters();

        for (Map.Entry<String, String> entry : generatedParameters.entrySet()) {

            sb.append("\t\t<generated-parameter name=\"");
            sb.append(entry.getKey());
            sb.append("\">");
            sb.append(entry.getValue());
            sb.append("</generated-parameter>\n");
        }

        Set<String> ignoredParameters = comparableRoute.getIgnoredParameters();

        for (String entry : ignoredParameters) {
            sb.append("\t\t<ignored-parameter name=\"");
            sb.append(entry);
            sb.append("\" />\n");
        }

        Map<String, String> implicitParameters = comparableRoute.getImplicitParameters();

        for (Map.Entry<String, String> entry : implicitParameters.entrySet()) {

            sb.append("\t\t<implicit-parameter name=\"");
            sb.append(entry.getKey());
            sb.append("\">");
            sb.append(entry.getValue());
            sb.append("</implicit-parameter>\n");
        }

        Map<String, String> overriddenParameters = comparableRoute.getOverriddenParameters();

        for (Map.Entry<String, String> entry : overriddenParameters.entrySet()) {

            sb.append("\t\t<overridden-parameter name=\"");
            sb.append(entry.getKey());
            sb.append("\">");
            sb.append(entry.getValue());
            sb.append("</overridden-parameter>\n");
        }

        sb.append("\t</route>\n");
    }

    sb.append("</routes>");

    return sb.toString();
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected void formatServiceXML(String fileName, String content) throws Exception {

    Document document = saxReaderUtil.read(content);

    Element rootElement = document.getRootElement();

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

    String previousEntityName = StringPool.BLANK;

    for (Element entityElement : entityElements) {
        String entityName = entityElement.attributeValue("name");

        if (Validator.isNotNull(previousEntityName)
                && (previousEntityName.compareToIgnoreCase(entityName) > 0)) {

            processErrorMessage(fileName, "sort: " + fileName + " " + entityName);
        }//from ww  w  .  j a  v a2  s .  co m

        checkServiceXMLFinders(fileName, entityElement, entityName);
        checkServiceXMLReferences(fileName, entityElement, entityName);

        previousEntityName = entityName;
    }

    checkServiceXMLExceptions(fileName, rootElement);
}

From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java

License:Open Source License

protected void formatStrutsConfigXML(String fileName, String content) throws Exception {

    Document document = saxReaderUtil.read(content);

    Element rootElement = document.getRootElement();

    Element actionMappingsElement = rootElement.element("action-mappings");

    List<Element> actionElements = actionMappingsElement.elements("action");

    String previousPath = StringPool.BLANK;

    for (Element actionElement : actionElements) {
        String path = actionElement.attributeValue("path");

        if (Validator.isNotNull(previousPath) && (previousPath.compareTo(path) > 0)
                && (!previousPath.startsWith("/portal/") || path.startsWith("/portal/"))) {

            processErrorMessage(fileName, "sort: " + fileName + " " + path);
        }//  w w  w .j  ava 2s  . c  om

        previousPath = path;
    }
}