Search in sources :

Example 1 with PropKey

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;
}
Also used : PropKey(com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey) PortalPropertiesConfiguration(com.liferay.ide.core.properties.PortalPropertiesConfiguration) ArrayList(java.util.ArrayList) PropertiesConfigurationLayout(org.apache.commons.configuration.PropertiesConfigurationLayout)

Example 2 with PropKey

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ILiferayProject(com.liferay.ide.core.ILiferayProject) PropKey(com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Aggregations

PropKey (com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey)2 ArrayList (java.util.ArrayList)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 PortalPropertiesConfiguration (com.liferay.ide.core.properties.PortalPropertiesConfiguration)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 JarFile (java.util.jar.JarFile)1 ZipEntry (java.util.zip.ZipEntry)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 PropertiesConfigurationLayout (org.apache.commons.configuration.PropertiesConfigurationLayout)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 IEditorInput (org.eclipse.ui.IEditorInput)1