Search in sources :

Example 1 with IContentParser

use of org.csstudio.autocomplete.parser.IContentParser in project yamcs-studio by yamcs.

the class AutoCompleteService method parseContent.

/* Handle recursive parsing of a content desc. */
private List<ContentDescriptor> parseContent(ContentDescriptor desc) {
    List<ContentDescriptor> tokenList = new ArrayList<ContentDescriptor>();
    ContentDescriptor newDesc = null;
    // backup data
    int startIndex = desc.getStartIndex();
    int endIndex = desc.getEndIndex();
    AutoCompleteType acType = desc.getAutoCompleteType();
    String defaultDatasource = desc.getDefaultDataSource();
    String originalContent = desc.getOriginalContent();
    // cancel replay
    desc.setReplay(false);
    for (IContentParser parser : parsers) {
        if (parser.accept(desc) && (newDesc = parser.parse(desc)) != null) {
            newDesc.setAutoCompleteType(acType);
            newDesc.setDefaultDataSource(defaultDatasource);
            newDesc.setOriginalContent(originalContent);
            // update indexes
            newDesc.setStartIndex(newDesc.getStartIndex() + startIndex);
            newDesc.setEndIndex(newDesc.getEndIndex() + endIndex);
            if (newDesc.isReplay()) {
                // recursive
                tokenList.addAll(parseContent(newDesc));
            } else {
                tokenList.add(newDesc);
            }
        }
    }
    if (tokenList.isEmpty()) {
        desc.setContentType(ContentType.Undefined);
        tokenList.add(desc);
    }
    return tokenList;
}
Also used : ContentDescriptor(org.csstudio.autocomplete.parser.ContentDescriptor) ArrayList(java.util.ArrayList) IContentParser(org.csstudio.autocomplete.parser.IContentParser)

Example 2 with IContentParser

use of org.csstudio.autocomplete.parser.IContentParser in project yamcs-studio by yamcs.

the class AutoCompleteService method getOSGIParsers.

/* Get providers from OSGI services */
private List<IContentParser> getOSGIParsers() throws InvalidSyntaxException {
    final List<IContentParser> list = new ArrayList<IContentParser>();
    BundleContext context = AutoCompletePlugin.getBundleContext();
    Collection<ServiceReference<IContentParser>> references = context.getServiceReferences(IContentParser.class, null);
    for (ServiceReference<IContentParser> ref : references) {
        IContentParser parser = (IContentParser) context.getService(ref);
        list.add(parser);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) IContentParser(org.csstudio.autocomplete.parser.IContentParser) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ArrayList (java.util.ArrayList)2 IContentParser (org.csstudio.autocomplete.parser.IContentParser)2 ContentDescriptor (org.csstudio.autocomplete.parser.ContentDescriptor)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1