use of com.liferay.ide.portlet.core.model.SupportedLocales in project liferay-ide by liferay.
the class LocaleBundleValidationService method compute.
public Status compute() {
Element modelElement = context(Element.class);
if (!modelElement.disposed() && modelElement instanceof SupportedLocales) {
IProject project = modelElement.adapt(IProject.class);
Portlet portlet = modelElement.nearest(Portlet.class);
IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
if (cpEntries != null) {
String locale = modelElement.property(context(ValueProperty.class)).text(false);
Value<Path> resourceBundle = portlet.getResourceBundle();
if (locale == null) {
return Status.createErrorStatus(Resources.localeMustNotEmpty);
} else {
String bundleName = resourceBundle.text();
if ((resourceBundle != null) && (bundleName != null)) {
String localeString = PortletUtil.localeString(locale);
String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION, localeString);
for (IClasspathEntry iClasspathEntry : cpEntries) {
if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
entryPath = entryPath.append(ioFileName);
IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
return Status.createOkStatus();
} else {
return Status.createWarningStatus(Resources.bind(StringEscapeUtils.unescapeJava(Resources.noResourceBundle), new Object[] { locale, bundleName, localeString }));
}
}
}
}
}
}
}
return Status.createOkStatus();
}
use of com.liferay.ide.portlet.core.model.SupportedLocales in project liferay-ide by liferay.
the class CreatePortletResourceBundleActionHandler method run.
/**
* (non-Javadoc)
*
* @see
* org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
* SapphireRenderingContext)
*/
@Override
protected Object run(Presentation context) {
ITextEditor editor = context.part().adapt(ITextEditor.class);
editor.doSave(new NullProgressMonitor());
List<IFile> missingRBFiles = new ArrayList<>();
Portlet portlet = (Portlet) getModelElement();
IProject project = portlet.adapt(IProject.class);
Value<Path> resourceBundle = portlet.getResourceBundle();
String text = resourceBundle.text();
String defaultRBFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION);
int index = text.lastIndexOf(".");
String packageName = "";
if (index == -1) {
index = text.length();
packageName = "";
} else {
packageName = text.substring(0, index);
}
IFolder rbSourceFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
IPath entryPath = rbSourceFolder.getLocation();
PortletInfo portletInfo = portlet.getPortletInfo();
StringBuilder rbFileBuffer = _buildDefaultRBContent(portletInfo);
if (!getFileFromClasspath(project, defaultRBFileName)) {
IFile drbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
missingRBFiles.add(drbFile);
}
// Create bundles for each supported locale for which the resource bundle is
// missing
List<SupportedLocales> supportedLocales = portlet.getSupportedLocales();
for (SupportedLocales iSupportedLocale : supportedLocales) {
if (iSupportedLocale != null) {
String locale = PortletUtil.localeString(iSupportedLocale.getSupportedLocale().text());
String localizedIOFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION, locale);
if (!getFileFromClasspath(project, localizedIOFileName)) {
IFile rbFile = wroot.getFileForLocation(entryPath.append(localizedIOFileName));
missingRBFiles.add(rbFile);
}
}
}
createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
setEnabled(false);
Portlet p = getModelElement().nearest(Portlet.class);
for (SupportedLocales sl : p.getSupportedLocales()) {
Value<String> locale = sl.getSupportedLocale();
locale.service(LocaleBundleValidationService.class).forceRefresh();
}
return null;
}
Aggregations