use of org.eclipse.epp.mpc.ui.CatalogDescriptor in project epp.mpc by eclipse.
the class MarketplaceViewerSorter method compare.
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
if (o1 == o2) {
return 0;
}
CatalogCategory cat1 = getCategory(o1);
CatalogCategory cat2 = getCategory(o2);
// FIXME filter uncategorized items?
if (cat1 == null) {
return (cat2 != null) ? 1 : 0;
} else if (cat2 == null) {
return 1;
}
int i = categoryComparator.compare(cat1, cat2);
if (i == 0) {
if (o1 instanceof CatalogCategory) {
return -1;
}
if (o2 instanceof CatalogCategory) {
return 1;
}
CatalogItem i1 = (CatalogItem) o1;
CatalogItem i2 = (CatalogItem) o2;
// catalog descriptor comes last
if (i1.getData() instanceof CatalogDescriptor) {
i = 1;
} else if (i2.getData() instanceof CatalogDescriptor) {
i = -1;
} else {
// otherwise we sort by name
String n1 = i1.getName();
String n2 = i2.getName();
if (n1 == null) {
// $NON-NLS-1$
n1 = "";
}
if (n2 == null) {
// $NON-NLS-1$
n2 = "";
}
i = n1.compareToIgnoreCase(n2);
if (i == 0) {
i = n1.compareTo(n2);
if (i == 0) {
// same name, so we sort by id.
String id1 = i1.getId();
String id2 = i2.getId();
if (id1 == null) {
// $NON-NLS-1$
id1 = "";
}
if (id2 == null) {
// $NON-NLS-1$
id2 = "";
}
i = id1.compareTo(id2);
}
}
}
}
return i;
}
use of org.eclipse.epp.mpc.ui.CatalogDescriptor in project epp.mpc by eclipse.
the class MarketplaceDiscoveryStrategy method performNodeQuery.
private ISearchResult performNodeQuery(String nodeUrl, IProgressMonitor progress) throws CoreException {
final INode[] queryNode = new INode[1];
MarketplaceUrlHandler urlHandler = new MarketplaceUrlHandler() {
@Override
protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
queryNode[0] = node;
return true;
}
};
if (urlHandler.handleUri(nodeUrl) && queryNode[0] != null) {
INode node = marketplaceService.getNode(queryNode[0], progress);
SearchResult result = new SearchResult();
result.setMatchCount(1);
result.setNodes(Collections.singletonList((Node) node));
return result;
}
return null;
}
use of org.eclipse.epp.mpc.ui.CatalogDescriptor in project epp.mpc by eclipse.
the class MarketplaceUrlHandlerTest method testHttpsVariants.
@Test
public void testHttpsVariants() {
MarketplaceUrlHandler handler = new MarketplaceUrlHandler() {
@Override
protected boolean handleFeatured(CatalogDescriptor descriptor, String url, String category, String market) {
assertEquals(eclipseMarketplace, descriptor);
assertEquals("featured", url);
return true;
}
};
String url = "http://marketplace.eclipse.org/featured";
assertTrue(handler.handleUri(url));
url = "https://marketplace.eclipse.org/featured";
assertTrue(handler.handleUri(url));
}
use of org.eclipse.epp.mpc.ui.CatalogDescriptor in project epp.mpc by eclipse.
the class MarketplaceUrlHandlerTest method testNodeUrls.
@Test
public void testNodeUrls() throws Exception {
final INode[] testNode = new INode[1];
MarketplaceUrlHandler handler = new MarketplaceUrlHandler() {
@Override
protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
testNode[0] = node;
return true;
}
};
testNode[0] = null;
String url = "http://marketplace.eclipse.org/content/test";
assertTrue(handler.handleUri(url));
assertNotNull(testNode[0]);
assertEquals(url, testNode[0].getUrl());
testNode[0] = null;
String nodeId = "12345";
url = "http://marketplace.eclipse.org/node/" + nodeId;
assertTrue(handler.handleUri(url));
assertNotNull(testNode[0]);
assertEquals(nodeId, testNode[0].getId());
}
use of org.eclipse.epp.mpc.ui.CatalogDescriptor in project epp.mpc by eclipse.
the class CatalogRegistry method findCatalogDescriptor.
public CatalogDescriptor findCatalogDescriptor(String url) {
if (url == null || url.length() == 0) {
return null;
}
CatalogDescriptor matchingDescriptor = doFindCatalogDescriptor(url);
url = URLUtil.toggleHttps(url);
CatalogDescriptor matchingToggledDescriptor = doFindCatalogDescriptor(url);
if (matchingDescriptor == null) {
matchingDescriptor = matchingToggledDescriptor;
} else if (matchingToggledDescriptor != null) {
String matchingUrl = matchingDescriptor.getUrl().toExternalForm();
String matchingToggledUrl = matchingToggledDescriptor.getUrl().toExternalForm();
// $NON-NLS-1$
int protocolDelta = matchingToggledUrl.startsWith("https") ? 1 : -1;
if (matchingToggledUrl.length() - protocolDelta > matchingUrl.length()) {
matchingDescriptor = matchingToggledDescriptor;
}
}
return matchingDescriptor;
}
Aggregations