Search in sources :

Example 1 with AssetTag

use of com.liferay.portlet.asset.model.AssetTag in project liferay-ide by liferay.

the class MediaWikiImporter method processSpecialPages.

protected void processSpecialPages(long userId, WikiNode node, Element rootElement, List<String> specialNamespaces) throws PortalException {
    ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
    List<Element> pageElements = rootElement.elements("page");
    for (int i = 0; i < pageElements.size(); i++) {
        Element pageElement = pageElements.get(i);
        String title = pageElement.elementText("title");
        if (!title.startsWith("Category:")) {
            if (isSpecialMediaWikiPage(title, specialNamespaces)) {
                rootElement.remove(pageElement);
            }
            continue;
        }
        String categoryName = title.substring("Category:".length());
        categoryName = normalize(categoryName, 75);
        Element revisionElement = pageElement.element("revision");
        String description = revisionElement.elementText("text");
        description = normalizeDescription(description);
        try {
            AssetTag assetTag = null;
            try {
                assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
            } catch (NoSuchTagException nste) {
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setAddGroupPermissions(true);
                serviceContext.setAddGuestPermissions(true);
                serviceContext.setScopeGroupId(node.getGroupId());
                assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
                if (PropsValues.ASSET_TAG_PROPERTIES_ENABLED && Validator.isNotNull(description)) {
                    AssetTagPropertyLocalServiceUtil.addTagProperty(userId, assetTag.getTagId(), "description", description);
                }
            }
        } catch (SystemException se) {
            _log.error(se, se);
        }
        if ((i % 5) == 0) {
            progressTracker.setPercent((i * 10) / pageElements.size());
        }
    }
}
Also used : AssetTag(com.liferay.portlet.asset.model.AssetTag) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException) SystemException(com.liferay.portal.kernel.exception.SystemException) ProgressTracker(com.liferay.portal.kernel.util.ProgressTracker) ServiceContext(com.liferay.portal.service.ServiceContext) Element(com.liferay.portal.kernel.xml.Element)

Example 2 with AssetTag

use of com.liferay.portlet.asset.model.AssetTag in project liferay-ide by liferay.

the class MediaWikiImporter method readAssetTagNames.

protected String[] readAssetTagNames(long userId, WikiNode node, String content) throws PortalException, SystemException {
    Matcher matcher = _categoriesPattern.matcher(content);
    List<String> assetTagNames = new ArrayList<String>();
    while (matcher.find()) {
        String categoryName = matcher.group(1);
        categoryName = normalize(categoryName, 75);
        AssetTag assetTag = null;
        try {
            assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
        } catch (NoSuchTagException nste) {
            ServiceContext serviceContext = new ServiceContext();
            serviceContext.setAddGroupPermissions(true);
            serviceContext.setAddGuestPermissions(true);
            serviceContext.setScopeGroupId(node.getGroupId());
            assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
        }
        assetTagNames.add(assetTag.getName());
    }
    if (content.contains(_WORK_IN_PROGRESS)) {
        assetTagNames.add(_WORK_IN_PROGRESS_TAG);
    }
    return assetTagNames.toArray(new String[assetTagNames.size()]);
}
Also used : AssetTag(com.liferay.portlet.asset.model.AssetTag) NoSuchTagException(com.liferay.portlet.asset.NoSuchTagException) Matcher(java.util.regex.Matcher) ServiceContext(com.liferay.portal.service.ServiceContext) ArrayList(java.util.ArrayList)

Aggregations

ServiceContext (com.liferay.portal.service.ServiceContext)2 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)2 AssetTag (com.liferay.portlet.asset.model.AssetTag)2 SystemException (com.liferay.portal.kernel.exception.SystemException)1 ProgressTracker (com.liferay.portal.kernel.util.ProgressTracker)1 Element (com.liferay.portal.kernel.xml.Element)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1