KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > linkextraction > LinkType


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.linkextraction;
17
18 public class LinkType {
19     public static final LinkType INLINE = new LinkType("inline", "L");
20     public static final LinkType OUT_OF_LINE = new LinkType("out_of_line", "O");
21     public static final LinkType IMAGE = new LinkType("image", "I");
22     public static final LinkType INCLUDE = new LinkType("include", "A");
23     public static final LinkType OTHER = new LinkType("other", "N");
24     public static final LinkType FIELD = new LinkType("field", "F");
25
26     private final String JavaDoc name;
27     private final String JavaDoc code;
28
29     private LinkType(String JavaDoc name, String JavaDoc code) {
30         this.name = name;
31         this.code = code;
32     }
33
34     public String JavaDoc getCode() {
35         return code;
36     }
37
38     public String JavaDoc toString() {
39         return name;
40     }
41
42     public static LinkType fromString(String JavaDoc name) {
43         if (INLINE.name.equals(name))
44             return INLINE;
45         else if (OUT_OF_LINE.name.equals(name))
46             return OUT_OF_LINE;
47         else if (IMAGE.name.equals(name))
48             return IMAGE;
49         else if (INCLUDE.name.equals(name))
50             return INCLUDE;
51         else if (OTHER.name.equals(name))
52             return OTHER;
53         else if (FIELD.name.equals(name))
54             return FIELD;
55         else
56             throw new RuntimeException JavaDoc("Unrecognized link type name: " + name);
57     }
58
59     public static LinkType getByCode(String JavaDoc code) {
60         if (INLINE.code.equals(code))
61             return INLINE;
62         else if (OUT_OF_LINE.code.equals(code))
63             return OUT_OF_LINE;
64         else if (IMAGE.code.equals(code))
65             return IMAGE;
66         else if (INCLUDE.code.equals(code))
67             return INCLUDE;
68         else if (OTHER.code.equals(code))
69             return OTHER;
70         else if (FIELD.code.equals(code))
71             return FIELD;
72         else
73             throw new RuntimeException JavaDoc("Unrecognized link type code: " + code);
74     }
75 }
76
Popular Tags