001package ball.tools.javadoc;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: LinkRFCTaglet.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/LinkRFCTaglet.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.Map;
029import lombok.NoArgsConstructor;
030import lombok.ToString;
031
032/**
033 * Inline {@link Taglet} providing links to external RFCs.
034 *
035 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
036 * @version $Revision: 5431 $
037 */
038@ServiceProviderFor({ Taglet.class })
039@TagletName("link.rfc")
040@NoArgsConstructor @ToString
041public class LinkRFCTaglet extends AbstractInlineTaglet
042                           implements SunToolsInternalToolkitTaglet {
043    private static final LinkRFCTaglet INSTANCE = new LinkRFCTaglet();
044
045    public static void register(Map<Object,Object> map) {
046        register(map, INSTANCE);
047    }
048
049    private static final String TEXT = "RFC%d";
050    private static final String PROTOCOL = "https";
051    private static final String HOST = "www.rfc-editor.org";
052    private static final String PATH = "/rfc/rfc%d.txt";
053
054    @Override
055    public FluentNode toNode(Tag tag) throws Throwable {
056        FluentNode node = fragment();
057        int rfc = Integer.valueOf(tag.text().trim());
058
059        node =
060            a(new URI(PROTOCOL, HOST, String.format(PATH, rfc), null),
061              String.format(TEXT, rfc))
062            .add(attr("target", "newtab"));
063
064        return node;
065    }
066}