001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thierry Delprat 016 */ 017package org.nuxeo.apidoc.browse; 018 019import java.util.ArrayList; 020import java.util.List; 021 022public class ArtifactLabel implements Comparable<ArtifactLabel> { 023 024 protected final String id; 025 026 protected String label; 027 028 protected String simpleId; 029 030 public ArtifactLabel(String id, String label, String simpleId) { 031 this.id = id; 032 this.label = label; 033 if (simpleId == null) { 034 simpleId = label; 035 } else { 036 this.simpleId = simpleId; 037 } 038 } 039 040 public String getId() { 041 return id; 042 } 043 044 public String getSimpleId() { 045 return simpleId; 046 } 047 048 public String getLabel() { 049 return label; 050 } 051 052 @Override 053 public String toString() { 054 return label; 055 } 056 057 @Override 058 public int compareTo(ArtifactLabel other) { 059 return label.compareTo(other.label); 060 } 061 062 public static ArtifactLabel createLabelFromService(String service) { 063 String[] parts = service.split("\\."); 064 String label = parts[parts.length - 1]; 065 return new ArtifactLabel(service, label, null); 066 } 067 068 protected static String removePrefix(String name, List<String> prefixes) { 069 for (String prefix : prefixes) { 070 if (name.startsWith(prefix)) { 071 name = name.substring(prefix.length()); 072 } 073 } 074 return name; 075 } 076 077 public static ArtifactLabel createLabelFromComponent(String component) { 078 String label = component; 079 List<String> prefixes = new ArrayList<String>(); 080 prefixes.add("org.nuxeo.ecm.platform.web.common."); 081 prefixes.add("org.nuxeo.ecm.platform.ui.web."); 082 prefixes.add("org.nuxeo.ecm.platform."); 083 prefixes.add("org.nuxeo.ecm.core."); 084 prefixes.add("org.nuxeo.ecm."); 085 prefixes.add("org.nuxeo."); 086 prefixes.add("webapp."); 087 prefixes.add("webengine."); 088 prefixes.add("api."); 089 label = removePrefix(component, prefixes); 090 return new ArtifactLabel(component, label, null); 091 } 092 093 public static ArtifactLabel createLabelFromExtensionPoint(String extensionPoint) { 094 String[] parts = extensionPoint.split("--"); 095 String component = parts[0]; 096 String ep = parts[1]; 097 String label = ep + " (" + component + ")"; 098 return new ArtifactLabel(extensionPoint, label, component); 099 } 100 101 public static ArtifactLabel createLabelFromContribution(String contribution) { 102 String[] parts = contribution.split("\\."); 103 String label = parts[parts.length - 1]; 104 return new ArtifactLabel(contribution, label, null); 105 } 106 107}