1 28 package net.sf.jasperreports.engine; 29 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 34 40 public class JRHyperlinkHelper 41 { 42 45 public static final String HYPERLINK_TYPE_NONE = "None"; 46 47 50 public static final String HYPERLINK_TYPE_REFERENCE = "Reference"; 51 52 55 public static final String HYPERLINK_TYPE_LOCAL_ANCHOR = "LocalAnchor"; 56 57 60 public static final String HYPERLINK_TYPE_LOCAL_PAGE = "LocalPage"; 61 62 65 public static final String HYPERLINK_TYPE_REMOTE_ANCHOR = "RemoteAnchor"; 66 67 70 public static final String HYPERLINK_TYPE_REMOTE_PAGE = "RemotePage"; 71 72 private static final Map builtinTypes; 73 74 static 75 { 76 builtinTypes = createBuiltinTypes(); 77 } 78 79 private static Map createBuiltinTypes() 80 { 81 Map types = new HashMap (); 82 types.put(HYPERLINK_TYPE_NONE, new Byte (JRHyperlink.HYPERLINK_TYPE_NONE)); 83 types.put(HYPERLINK_TYPE_REFERENCE, new Byte (JRHyperlink.HYPERLINK_TYPE_REFERENCE)); 84 types.put(HYPERLINK_TYPE_LOCAL_ANCHOR, new Byte (JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR)); 85 types.put(HYPERLINK_TYPE_LOCAL_PAGE, new Byte (JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE)); 86 types.put(HYPERLINK_TYPE_REMOTE_ANCHOR, new Byte (JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR)); 87 types.put(HYPERLINK_TYPE_REMOTE_PAGE, new Byte (JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE)); 88 return types; 89 } 90 91 92 99 public static byte getHyperlinkType(JRHyperlink hyperlink) 100 { 101 return getHyperlinkType(hyperlink.getLinkType()); 102 } 103 104 105 112 public static byte getHyperlinkType(String linkType) 113 { 114 byte type; 115 if (linkType == null) 116 { 117 type = JRHyperlink.HYPERLINK_TYPE_NONE; 118 } 119 else 120 { 121 Byte builtinType = (Byte ) builtinTypes.get(linkType); 122 if (builtinType == null) 123 { 124 type = JRHyperlink.HYPERLINK_TYPE_CUSTOM; 125 } 126 else 127 { 128 type = builtinType.byteValue(); 129 } 130 } 131 return type; 132 } 133 134 135 141 public static String getLinkType(byte hyperlinkType) 142 { 143 String type; 144 switch (hyperlinkType) 145 { 146 case JRHyperlink.HYPERLINK_TYPE_NULL: 147 case JRHyperlink.HYPERLINK_TYPE_NONE: 148 type = null; 149 break; 150 case JRHyperlink.HYPERLINK_TYPE_REFERENCE: 151 type = HYPERLINK_TYPE_REFERENCE; 152 break; 153 case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: 154 type = HYPERLINK_TYPE_LOCAL_ANCHOR; 155 break; 156 case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: 157 type = HYPERLINK_TYPE_LOCAL_PAGE; 158 break; 159 case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: 160 type = HYPERLINK_TYPE_REMOTE_ANCHOR; 161 break; 162 case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: 163 type = HYPERLINK_TYPE_REMOTE_PAGE; 164 break; 165 case JRHyperlink.HYPERLINK_TYPE_CUSTOM: 166 throw new JRRuntimeException("Custom hyperlink types cannot be specified using the byte constant"); 167 default: 168 throw new JRRuntimeException("Unknown hyperlink type " + hyperlinkType); 169 } 170 return type; 171 } 172 173 } 174 | Popular Tags |