1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.javadoc.internal.doclets.formats.html; 27 28 /** 29 * Index item for search. 30 * 31 * <p><b>This is NOT part of any supported API. 32 * If you write code that depends on this, you do so at your own risk. 33 * This code and its internal interfaces are subject to change or 34 * deletion without notice.</b> 35 */ 36 public class SearchIndexItem { 37 38 enum Category { 39 MODULES, 40 PACKAGES, 41 TYPES, 42 MEMBERS, 43 SEARCH_TAGS 44 } 45 46 private Category category; 47 private String label = ""; 48 private String url = ""; 49 private String containingModule = ""; 50 private String containingPackage = ""; 51 private String containingClass = ""; 52 private String holder = ""; 53 private String description = ""; 54 55 public void setLabel(String l) { 56 label = l; 57 } 58 59 public String getLabel() { 60 return label; 61 } 62 63 public void setUrl(String u) { 64 url = u; 65 } 66 67 public String getUrl() { 68 return url; 69 } 70 71 public void setContainingModule(String m) { 72 containingModule = m; 73 } 74 75 public void setContainingPackage(String p) { 76 containingPackage = p; 77 } 78 79 public void setContainingClass(String c) { 80 containingClass = c; 81 } 82 83 public void setCategory(Category c) { 84 category = c; 85 } 86 87 public void setHolder(String h) { 88 holder = h; 89 } 90 91 public String getHolder() { 92 return holder; 93 } 94 95 public void setDescription(String d) { 96 description = d; 97 } 98 99 public String getDescription() { 100 return description; 101 } 102 103 public String toString() { 104 StringBuilder item = new StringBuilder(""); 105 switch (category) { 106 case MODULES: 107 item.append("{") 108 .append("\"l\":\"").append(label).append("\"") 109 .append("}"); 110 break; 111 case PACKAGES: 112 item.append("{"); 113 if (!containingModule.isEmpty()) { 114 item.append("\"m\":\"").append(containingModule).append("\","); 115 } 116 item.append("\"l\":\"").append(label).append("\""); 117 if (!url.equals("")) { 118 item.append(",\"url\":\"").append(url).append("\""); 119 } 120 item.append("}"); 121 break; 122 case TYPES: 123 item.append("{"); 124 if (!containingPackage.equals("")) { 125 item.append("\"p\":\"").append(containingPackage).append("\","); 126 } 127 item.append("\"l\":\"").append(label).append("\""); 128 if (!url.equals("")) { 129 item.append(",\"url\":\"").append(url).append("\""); 130 } 131 item.append("}"); 132 break; 133 case MEMBERS: 134 item.append("{") 135 .append("\"p\":\"").append(containingPackage).append("\",") 136 .append("\"c\":\"").append(containingClass).append("\",") 137 .append("\"l\":\"").append(label).append("\""); 138 if (!url.equals("")) { 139 item.append(",\"url\":\"").append(url).append("\""); 140 } 141 item.append("}"); 142 break; 143 case SEARCH_TAGS: 144 item.append("{") 145 .append("\"l\":\"").append(label).append("\",") 146 .append("\"h\":\"").append(holder).append("\","); 147 if (!description.equals("")) { 148 item.append("\"d\":\"").append(description).append("\","); 149 } 150 item.append("\"u\":\"").append(url).append("\"") 151 .append("}"); 152 break; 153 default: 154 throw new IllegalStateException("category not set"); 155 } 156 return item.toString(); 157 } 158 159 /** 160 * Get the part of the label after the last dot, or whole label if no dots. 161 * 162 * @return the simple name 163 */ 164 public String getSimpleName() { 165 return label.substring(label.lastIndexOf('.') + 1); 166 } 167 }