use of com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey in project liferay-ide by liferay.
the class LiferayPropertiesSourceViewerConfiguration method _parseKeys.
private PropKey[] _parseKeys(InputStream inputStream) throws ConfigurationException, IOException {
List<PropKey> parsed = new ArrayList<>();
PortalPropertiesConfiguration config = new PortalPropertiesConfiguration();
config.load(inputStream);
inputStream.close();
Iterator<?> keys = config.getKeys();
PropertiesConfigurationLayout layout = config.getLayout();
while (keys.hasNext()) {
String key = keys.next().toString();
String comment = layout.getComment(key);
parsed.add(new PropKey(key, comment == null ? null : comment.replaceAll("\n", "\n<br/>")));
}
PropKey[] parsedKeys = parsed.toArray(new PropKey[0]);
Arrays.sort(parsedKeys, new Comparator<PropKey>() {
@Override
public int compare(PropKey o1, PropKey o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
return parsedKeys;
}
use of com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey in project liferay-ide by liferay.
the class LiferayPropertiesSourceViewerConfiguration method getContentAssistant.
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (_propKeys == null) {
IEditorInput input = getEditor().getEditorInput();
// first fine runtime location to get properties definitions
IPath appServerPortalDir = _getAppServerPortalDir(input);
String propertiesEntry = _getPropertiesEntry(input);
PropKey[] keys = null;
if ((appServerPortalDir != null) && appServerPortalDir.toFile().exists()) {
try {
JarFile jar = new JarFile(appServerPortalDir.append("WEB-INF/lib/portal-impl.jar").toFile());
ZipEntry lang = jar.getEntry(propertiesEntry);
keys = _parseKeys(jar.getInputStream(lang));
jar.close();
} catch (Exception e) {
LiferayUIPlugin.logError("Unable to get portal properties file", e);
}
} else {
return _assitant;
}
Object adapter = input.getAdapter(IFile.class);
if (adapter instanceof IFile && _isHookProject(((IFile) adapter).getProject())) {
ILiferayProject liferayProject = LiferayCore.create(((IFile) adapter).getProject());
ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
if (portal != null) {
Set<String> hookProps = new HashSet<>();
Collections.addAll(hookProps, portal.getHookSupportedProperties());
List<PropKey> filtered = new ArrayList<>();
for (PropKey pk : keys) {
if (hookProps.contains(pk.getKey())) {
filtered.add(pk);
}
}
keys = filtered.toArray(new PropKey[0]);
}
}
_propKeys = keys;
}
if ((_propKeys != null) && (_assitant == null)) {
ContentAssistant ca = new ContentAssistant() {
@Override
public IContentAssistProcessor getContentAssistProcessor(String contentType) {
return new LiferayPropertiesContentAssistProcessor(_propKeys, contentType);
}
};
ca.setInformationControlCreator(getInformationControlCreator(sourceViewer));
_assitant = ca;
}
return _assitant;
}
Aggregations