View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.serializer;
18  
19  import static org.apache.juneau.commons.utils.StringUtils.*;
20  
21  import java.net.*;
22  
23  import org.apache.juneau.annotation.*;
24  import org.apache.juneau.xml.annotation.*;
25  
26  @Bean(sort=true)
27  public class TestURI {
28  
29  	// String annotated as a URI
30  	@Uri
31  	@Xml(format=XmlFormat.ATTR)
32  	public String f0 = "f0/x0";
33  
34  	// URI properties
35  	public URI
36  		f1a = URI.create("http://www.apache.org/f1a"),
37  		f1b = URI.create("/f1b"),
38  		f1c = URI.create("/f1c/x/y"),
39  		f1d = URI.create("f1d"),
40  		f1e = URI.create("f1e/x/y"),
41  		f1f = URI.create(""),
42  		f1g = URI.create("servlet:/f1g/x"),
43  		f1h = URI.create("servlet:/f1h"),
44  		f1i = URI.create("servlet:/"),
45  		f1j = URI.create("servlet:/.."),
46  		f1k = URI.create("context:/f1j/x"),
47  		f1l = URI.create("context:/f1k"),
48  		f1m = URI.create("context:/"),
49  		f1n = URI.create("context:/.."),
50  		fio = null;
51  
52  	// Strings annotated with @URI properties
53  	@Uri
54  	public String
55  		f2a = "http://www.apache.org/f2a",
56  		f2b = "/f2b",
57  		f2c = "/f2c/x/y",
58  		f2d = "f2d",
59  		f2e = "f2e/x/y",
60  		f2f = "",
61  		f2g = "servlet:/f2g/x",
62  		f2h = "servlet:/f2h",
63  		f2i = "servlet:/",
64  		f2j = "servlet:/..",
65  		f2k = "context:/f2j/x",
66  		f2l = "context:/f2k",
67  		f2m = "context:/",
68  		f2n = "context:/..",
69  		f2o = null;
70  
71  	// Strings with labels
72  	@Uri
73  	public String
74  		f3a = "http://www.apache.org/f3a/x?label=MY_LABEL&foo=bar",
75  		f3b = urlEncode("<>&'\""),
76  		f3c = "<>&'\"";  // Invalid URI, but should produce parsable output.
77  
78  	// @URI on bean
79  	public TestURIb f4 = new TestURIb();
80  
81  	// @URI on bean property method.
82  	@Uri
83  	public String getF5() {
84  		return "f5/x";
85  	}
86  
87  	@Uri
88  	public static class TestURIb {
89  		@Override /* Overridden from Object */
90  		public String toString() {
91  			return "test/uri/b";
92  		}
93  	}
94  }