44 * This code and its internal interfaces are subject to change or 45 * deletion without notice.</b> 46 */ 47 public class Links { 48 49 private final DocPath file; 50 51 /** 52 * Creates a {@code Links} object for a specific file, to be written in a specific HTML version. 53 * The version is used by the {@link #getName(String) getName} method 54 * to help determine valid HTML names (ids), and to determine whether 55 * to use an {@code id} or {@code name} attribute when creating anchors. 56 * 57 * @param file the file 58 */ 59 public Links(DocPath file) { 60 this.file = file; 61 } 62 63 /** 64 * Creates an anchor of the form {@code <a id="name"><!-- --></a>}. 65 * 66 * @param name the value for the {@code id} or {@code name} attribute 67 * @return a content tree for the anchor 68 */ 69 public Content createAnchor(String name) { 70 return createAnchor(getName(name), null); 71 } 72 73 /** 74 * Creates an anchor of the form {@code <a id="sectionName"><!-- --></a>}. 75 * 76 * @param sectionName the value for the {@code id} or {@code name} attribute 77 * @return a content tree for the anchor 78 */ 79 public Content createAnchor(SectionName sectionName) { 80 return createAnchor(sectionName.getName(), null); 81 } 82 83 /** 84 * Creates an anchor of the form {@code <a id="sectionNameName"><!-- --></a>}. 85 * 86 * @param sectionName the first part of the value for the {@code id} or {@code name} attribute 87 * @param name the second part of the value for the {@code id} or {@code name} attribute 88 * @return a content tree for the anchor 89 */ 90 public Content createAnchor(SectionName sectionName, String name) { 91 return createAnchor(sectionName.getName() + getName(name), null); 92 } 93 94 /** 95 * Creates an anchor of the form {@code <a id="anchorName">content</a>}. 96 * 97 * @param name the value for the {@code id} or {@code name} attribute 98 * @param content the content that should be added to the anchor, 99 * or null, to use an empty comment 100 * @return a content tree for the marker anchor 101 */ 102 public Content createAnchor(String name, Content content) { 103 return HtmlTree.A_ID(getName(name), (content == null ? EMPTY_COMMENT : content)); 104 } 105 106 private static final Content EMPTY_COMMENT = new Comment(" "); 107 108 /** 109 * Creates a link of the form {@code <a href="#where">label</a>}. 110 * 111 * @param where the position of the link in the file 112 * @param label the content for the link 113 * @return a content tree for the link 114 */ 115 public Content createLink(String where, Content label) { 116 DocLink l = DocLink.fragment(getName(where)); 117 return createLink(l, label, "", ""); 118 } 119 120 /** 121 * Creates a link of the form {@code <a href="#sectionName">label</a>}. 122 * 123 * @param sectionName the section name to which the link will be created 124 * @param label the content for the link 125 * @return a content tree for the link 126 */ 127 public Content createLink(SectionName sectionName, Content label) { 128 DocLink l = DocLink.fragment(sectionName.getName()); | 44 * This code and its internal interfaces are subject to change or 45 * deletion without notice.</b> 46 */ 47 public class Links { 48 49 private final DocPath file; 50 51 /** 52 * Creates a {@code Links} object for a specific file, to be written in a specific HTML version. 53 * The version is used by the {@link #getName(String) getName} method 54 * to help determine valid HTML names (ids), and to determine whether 55 * to use an {@code id} or {@code name} attribute when creating anchors. 56 * 57 * @param file the file 58 */ 59 public Links(DocPath file) { 60 this.file = file; 61 } 62 63 /** 64 * Creates a link of the form {@code <a href="#where">label</a>}. 65 * 66 * @param where the position of the link in the file 67 * @param label the content for the link 68 * @return a content tree for the link 69 */ 70 public Content createLink(String where, Content label) { 71 DocLink l = DocLink.fragment(getName(where)); 72 return createLink(l, label, "", ""); 73 } 74 75 /** 76 * Creates a link of the form {@code <a href="#sectionName">label</a>}. 77 * 78 * @param sectionName the section name to which the link will be created 79 * @param label the content for the link 80 * @return a content tree for the link 81 */ 82 public Content createLink(SectionName sectionName, Content label) { 83 DocLink l = DocLink.fragment(sectionName.getName()); |