use of org.eclipse.epp.internal.mpc.core.model.Marketplace 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;
}
use of org.eclipse.epp.internal.mpc.core.model.Marketplace in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getCategory.
public Category getCategory(ICategory category, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 200);
if (category.getId() != null && category.getUrl() == null) {
List<Market> markets = listMarkets(progress.newChild(50));
ICategory resolvedCategory = null;
outer: for (Market market : markets) {
List<Category> categories = market.getCategory();
for (Category aCategory : categories) {
if (aCategory.equalsId(category)) {
resolvedCategory = aCategory;
break outer;
}
}
}
if (progress.isCanceled()) {
throw new OperationCanceledException();
} else if (resolvedCategory == null) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getId()));
} else {
return getCategory(resolvedCategory, progress.newChild(150));
}
}
Marketplace marketplace = processRequest(category.getUrl(), API_URI_SUFFIX, progress.newChild(200));
if (marketplace.getCategory().isEmpty()) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getUrl()));
} else if (marketplace.getCategory().size() > 1) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, category.getUrl()));
}
Category resolvedCategory = marketplace.getCategory().get(0);
return resolvedCategory;
}
use of org.eclipse.epp.internal.mpc.core.model.Marketplace in project epp.mpc by eclipse.
the class NodeListingContentHandler method endElement.
@Override
public boolean endElement(String uri, String localName) throws SAXException {
if (localName.equals(getRootElementName())) {
if (parentModel instanceof Marketplace) {
Marketplace marketplace = (Marketplace) parentModel;
setMarketplaceResult(marketplace, model);
}
getUnmarshaller().setModel(model);
model = null;
getUnmarshaller().setCurrentHandler(parentHandler);
if (parentHandler != null) {
parentHandler.endElement(uri, localName);
}
return true;
} else if (localName.equals("node")) {
// $NON-NLS-1$
// nothing to do
}
return false;
}
Aggregations