001package ball.tools.javadoc; 002/*- 003 * ########################################################################## 004 * Utilities 005 * $Id: LinkURITaglet.html 5431 2020-02-12 19:03:17Z ball $ 006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/hcf-dev/blog/2019-03-30-java-interface-facades/src/main/resources/javadoc/src-html/ball/tools/javadoc/LinkURITaglet.html $ 007 * %% 008 * Copyright (C) 2008 - 2020 Allen D. Ball 009 * %% 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * ########################################################################## 022 */ 023import ball.annotation.ServiceProviderFor; 024import ball.xml.FluentNode; 025import com.sun.javadoc.Tag; 026import com.sun.tools.doclets.Taglet; 027import java.net.URI; 028import java.util.LinkedHashMap; 029import java.util.Map; 030import lombok.NoArgsConstructor; 031import lombok.ToString; 032 033/** 034 * Inline {@link Taglet} to provide external links. 035 * 036 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 037 * @version $Revision: 5431 $ 038 */ 039@ServiceProviderFor({ Taglet.class }) 040@TagletName("link.uri") 041@NoArgsConstructor @ToString 042public class LinkURITaglet extends AbstractInlineTaglet 043 implements SunToolsInternalToolkitTaglet { 044 private static final LinkURITaglet INSTANCE = new LinkURITaglet(); 045 046 public static void register(Map<Object,Object> map) { 047 register(map, INSTANCE); 048 } 049 050 private static final String SPACES = "[\\p{Space}]+"; 051 052 @Override 053 public FluentNode toNode(Tag tag) throws Throwable { 054 String text = tag.text().trim(); 055 String[] argv = text.split(SPACES, 2); 056 URI href = new URI(argv[0]); 057 058 text = (argv.length > 1) ? argv[1] : null; 059 060 LinkedHashMap<String,String> map = new LinkedHashMap<>(); 061 062 if (text != null) { 063 for (;;) { 064 argv = text.split(SPACES, 2); 065 066 String[] nvp = argv[0].split("=", 2); 067 068 if (argv.length > 1 && nvp.length > 1) { 069 map.put(nvp[0], nvp[1]); 070 text = argv[1]; 071 } else { 072 break; 073 } 074 } 075 } 076 077 return a(href, text) 078 .add(map.entrySet() 079 .stream() 080 .map(t -> attr(t.getKey(), t.getValue()))); 081 } 082}