Search in sources :

Example 11 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.

the class NodeContentHandler method startElement.

@Override
public void startElement(String uri, String localName, Attributes attributes) {
    if (localName.equals("node")) {
        // $NON-NLS-1$
        model = new Node();
        // $NON-NLS-1$
        model.setId(attributes.getValue(NS_URI, "id"));
        // $NON-NLS-1$
        model.setName(attributes.getValue(NS_URI, "name"));
        // $NON-NLS-1$
        model.setUrl(attributes.getValue(NS_URI, "url"));
    } else if (localName.equals("favorited")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("installstotal")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("installsrecent")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("type")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("categories")) {
        // $NON-NLS-1$
        CategoriesContentHandler childHandler = new CategoriesContentHandler();
        childHandler.setParentModel(model);
        childHandler.setParentHandler(this);
        childHandler.setUnmarshaller(getUnmarshaller());
        getUnmarshaller().setCurrentHandler(childHandler);
        childHandler.startElement(uri, localName, attributes);
    } else if (localName.equals("tags")) {
        // $NON-NLS-1$
        TagsContentHandler childHandler = new TagsContentHandler();
        childHandler.setParentModel(model);
        childHandler.setParentHandler(this);
        childHandler.setUnmarshaller(getUnmarshaller());
        getUnmarshaller().setCurrentHandler(childHandler);
        childHandler.startElement(uri, localName, attributes);
    } else if (localName.equals("owner")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("shortdescription")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("body")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("created")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("changed")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("foundationmember")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("homepageurl")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("image")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("screenshot")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("version")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("license")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("companyname")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("status")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("eclipseversion")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("supporturl")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("updateurl")) {
        // $NON-NLS-1$
        capturingContent = true;
    } else if (localName.equals("ius")) {
        // $NON-NLS-1$
        IusContentHandler childHandler = new IusContentHandler();
        childHandler.setParentModel(model);
        childHandler.setParentHandler(this);
        childHandler.setUnmarshaller(getUnmarshaller());
        getUnmarshaller().setCurrentHandler(childHandler);
        childHandler.startElement(uri, localName, attributes);
    } else if (localName.equals("platforms")) {
        // $NON-NLS-1$
        PlatformsContentHandler childHandler = new PlatformsContentHandler();
        childHandler.setParentModel(model);
        childHandler.setParentHandler(this);
        childHandler.setUnmarshaller(getUnmarshaller());
        getUnmarshaller().setCurrentHandler(childHandler);
        childHandler.startElement(uri, localName, attributes);
    }
}
Also used : Node(org.eclipse.epp.internal.mpc.core.model.Node)

Example 12 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.

the class DefaultMarketplaceService method getNodesByUrl.

private void getNodesByUrl(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, nodes.size());
    int remaining = nodes.size();
    for (INode node : nodes) {
        if (node.getId() == null && node.getUrl() != null) {
            Node resolvedNode = getNode(node, progress.newChild(1));
            resolvedNodeMapping.put(node, resolvedNode);
        }
        progress.setWorkRemaining(--remaining);
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 13 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.

the class DefaultMarketplaceService method getNodesById.

private void getNodesById(Collection<? extends INode> nodes, Map<INode, INode> resolvedNodeMapping, IProgressMonitor monitor) throws CoreException {
    StringBuilder nodeIdQuery = new StringBuilder();
    Map<String, INode> nodeIds = new HashMap<String, INode>(nodes.size());
    for (INode node : nodes) {
        if (node.getId() == null) {
            continue;
        }
        nodeIds.put(node.getId(), node);
        String encodedId = urlEncode(node.getId());
        if (nodeIdQuery.length() > 0) {
            // $NON-NLS-1$
            nodeIdQuery.append(",");
        }
        nodeIdQuery.append(encodedId);
    }
    Marketplace marketplace = processRequest(API_NODE_URI + '/' + nodeIdQuery + '/' + API_URI_SUFFIX, monitor);
    List<Node> resolvedNodes = marketplace.getNode();
    for (Node node : resolvedNodes) {
        INode inputNode = nodeIds.get(node.getId());
        if (inputNode != null) {
            resolvedNodeMapping.put(inputNode, node);
        } else {
            throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, nodeIdQuery));
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Example 14 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.

the class DefaultMarketplaceService method processSearchRequest.

private SearchResult processSearchRequest(String relativeUrl, String queryText, IProgressMonitor monitor) throws CoreException {
    SearchResult result = new SearchResult();
    if (relativeUrl == null) {
        // empty search
        result.setMatchCount(0);
        result.setNodes(new ArrayList<Node>());
    } else {
        Marketplace marketplace;
        try {
            marketplace = processRequest(relativeUrl, monitor);
        } catch (CoreException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof FileNotFoundException) {
                throw new CoreException(createErrorStatus(NLS.bind(Messages.DefaultMarketplaceService_UnsupportedSearchString, queryText), cause));
            }
            throw ex;
        }
        Search search = marketplace.getSearch();
        if (search != null) {
            result.setMatchCount(search.getCount());
            result.setNodes(search.getNode());
        } else if (marketplace.getCategory().size() == 1) {
            Category category = marketplace.getCategory().get(0);
            result.setMatchCount(category.getNode().size());
            result.setNodes(category.getNode());
        } else {
            throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, relativeUrl));
        }
    }
    return result;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) Category(org.eclipse.epp.internal.mpc.core.model.Category) ICategory(org.eclipse.epp.mpc.core.model.ICategory) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) Search(org.eclipse.epp.internal.mpc.core.model.Search) FileNotFoundException(java.io.FileNotFoundException) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Example 15 with Node

use of org.eclipse.epp.internal.mpc.core.model.Node in project epp.mpc by eclipse.

the class MarketplaceUrlHandler method handleNode.

private boolean handleNode(CatalogDescriptor descriptor, String url) {
    Matcher matcher = NODE_URL_PATTERN.matcher(url);
    String id = null;
    if (matcher.find()) {
        id = matcher.group(1);
    }
    Node node = new Node();
    node.setId(id);
    return handleNode(descriptor, url, node);
}
Also used : Matcher(java.util.regex.Matcher) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Aggregations

Node (org.eclipse.epp.internal.mpc.core.model.Node)20 INode (org.eclipse.epp.mpc.core.model.INode)19 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)5 HashSet (java.util.HashSet)4 CoreException (org.eclipse.core.runtime.CoreException)4 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)4 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)3 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 Ius (org.eclipse.epp.internal.mpc.core.model.Ius)2 ICategory (org.eclipse.epp.mpc.core.model.ICategory)2 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1