001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.apidoc.browse; 020 021import java.util.ArrayList; 022import java.util.List; 023 024public class ArtifactLabel implements Comparable<ArtifactLabel> { 025 026 protected final String id; 027 028 protected String label; 029 030 protected String simpleId; 031 032 public ArtifactLabel(String id, String label, String simpleId) { 033 this.id = id; 034 this.label = label; 035 if (simpleId == null) { 036 this.simpleId = label; 037 } else { 038 this.simpleId = simpleId; 039 } 040 } 041 042 public String getId() { 043 return id; 044 } 045 046 public String getSimpleId() { 047 return simpleId; 048 } 049 050 public String getLabel() { 051 return label; 052 } 053 054 @Override 055 public String toString() { 056 return label; 057 } 058 059 @Override 060 public int compareTo(ArtifactLabel other) { 061 return label.compareTo(other.label); 062 } 063 064 public static ArtifactLabel createLabelFromService(String service) { 065 String[] parts = service.split("\\."); 066 String label = parts[parts.length - 1]; 067 return new ArtifactLabel(service, label, null); 068 } 069 070 protected static String removePrefix(String name, List<String> prefixes) { 071 for (String prefix : prefixes) { 072 if (name.startsWith(prefix)) { 073 name = name.substring(prefix.length()); 074 } 075 } 076 return name; 077 } 078 079 public static ArtifactLabel createLabelFromComponent(String component) { 080 String label = component; 081 List<String> prefixes = new ArrayList<String>(); 082 prefixes.add("org.nuxeo.ecm.platform.web.common."); 083 prefixes.add("org.nuxeo.ecm.platform.ui.web."); 084 prefixes.add("org.nuxeo.ecm.platform."); 085 prefixes.add("org.nuxeo.ecm.core."); 086 prefixes.add("org.nuxeo.ecm."); 087 prefixes.add("org.nuxeo."); 088 prefixes.add("webapp."); 089 prefixes.add("webengine."); 090 prefixes.add("api."); 091 label = removePrefix(component, prefixes); 092 return new ArtifactLabel(component, label, null); 093 } 094 095 public static ArtifactLabel createLabelFromExtensionPoint(String extensionPoint) { 096 String[] parts = extensionPoint.split("--"); 097 String component = parts[0]; 098 String ep = parts[1]; 099 return new ArtifactLabel(extensionPoint, ep, component); 100 } 101 102 public static ArtifactLabel createLabelFromContribution(String contribution) { 103 String[] parts = contribution.split("\\."); 104 String label = parts[parts.length - 1]; 105 return new ArtifactLabel(contribution, label, null); 106 } 107 108}