/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.document.library.internal.display.context;
import com.liferay.document.library.configuration.DLConfiguration;
import com.liferay.document.library.display.context.DLMimeTypeDisplayContext;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified;
/**
* @author Roberto Díaz
*/
@Component(
configurationPid = "com.liferay.document.library.configuration.DLConfiguration",
configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true
)
public class DefaultDLMimeTypeDisplayContext
implements DLMimeTypeDisplayContext {
@Override
public String getCssClassFileMimeType(String mimeType) {
if (_containsMimeType(_dlConfiguration.codeFileMimeTypes(), mimeType)) {
return "file-icon-color-7";
}
else if (_containsMimeType(
_dlConfiguration.compressedFileMimeTypes(), mimeType)) {
return "file-icon-color-1";
}
else if (_containsMimeType(
_dlConfiguration.multimediaFileMimeTypes(), mimeType)) {
return "file-icon-color-3";
}
else if (_containsMimeType(
_dlConfiguration.presentationFileMimeTypes(), mimeType)) {
return "file-icon-color-4";
}
else if (_containsMimeType(
_dlConfiguration.spreadSheetFileMimeTypes(), mimeType)) {
return "file-icon-color-2";
}
else if (_containsMimeType(
_dlConfiguration.textFileMimeTypes(), mimeType)) {
return "file-icon-color-6";
}
else if (_containsMimeType(
_dlConfiguration.vectorialFileMimeTypes(), mimeType)) {
return "file-icon-color-5";
}
return "file-icon-color-0";
}
@Activate
@Modified
protected void activate(Map<String, Object> properties) {
_dlConfiguration = ConfigurableUtil.createConfigurable(
DLConfiguration.class, properties);
}
private boolean _containsMimeType(String[] mimeTypes, String mimeType) {
for (String curMimeType : mimeTypes) {
int pos = curMimeType.indexOf("/");
if (pos != -1) {
if (mimeType.equals(curMimeType)) {
return true;
}
}
else {
if (mimeType.startsWith(curMimeType)) {
return true;
}
}
}
return false;
}
private volatile DLConfiguration _dlConfiguration;
}