001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.tools.plugin.extractor.annotations.converter.tag.block; 020 021import javax.inject.Named; 022import javax.inject.Singleton; 023 024import org.apache.maven.tools.plugin.extractor.annotations.converter.ConverterContext; 025import org.apache.maven.tools.plugin.extractor.annotations.converter.tag.LinkUtils; 026 027/** 028 * Supports <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/javadoc/doc-comment-spec.html#see">block see 029 * taglet</a>. 030 */ 031@Named("see") 032@Singleton 033public class SeeTagConverter extends JavadocBlockTagToHtmlConverter { 034 private static final String ATTRIBUTE_NAME_IS_FIRST_REFERENCE = "SeeTagletConverter.isFirstReference"; 035 036 @Override 037 public String convert(String value, ConverterContext context) { 038 StringBuilder htmlBuilder = new StringBuilder(); 039 Boolean isFirstReference = context.getAttribute(ATTRIBUTE_NAME_IS_FIRST_REFERENCE, Boolean.class, Boolean.TRUE); 040 if (Boolean.TRUE.equals(isFirstReference)) { 041 // headline only once per instance 042 htmlBuilder.append("<br/><strong>See also:</strong>\n"); 043 context.setAttribute(ATTRIBUTE_NAME_IS_FIRST_REFERENCE, Boolean.FALSE); 044 } else { 045 // multiple links just comma separated, 046 htmlBuilder.append(", "); 047 } 048 // is it regular HTML link? 049 if (value.startsWith("<a href")) { 050 return htmlBuilder.append(value).toString(); 051 } 052 // is it just a soft string reference? 053 if (value.startsWith("\"")) { 054 return htmlBuilder.append(value).toString(); 055 } 056 String link = LinkUtils.createLink(value, context); 057 htmlBuilder.append(link); 058 return htmlBuilder.toString(); 059 } 060}