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 java.net.*;
20  
21  import org.apache.juneau.annotation.*;
22  import org.apache.juneau.common.utils.*;
23  import org.apache.juneau.xml.annotation.*;
24  
25  @Bean(sort=true)
26  public class TestURI {
27  
28  	// String annotated as a URI
29  	@Uri
30  	@Xml(format=XmlFormat.ATTR)
31  	public String f0 = "f0/x0";
32  
33  	// URI properties
34  	public URI
35  		f1a = URI.create("http://www.apache.org/f1a"),
36  		f1b = URI.create("/f1b"),
37  		f1c = URI.create("/f1c/x/y"),
38  		f1d = URI.create("f1d"),
39  		f1e = URI.create("f1e/x/y"),
40  		f1f = URI.create(""),
41  		f1g = URI.create("servlet:/f1g/x"),
42  		f1h = URI.create("servlet:/f1h"),
43  		f1i = URI.create("servlet:/"),
44  		f1j = URI.create("servlet:/.."),
45  		f1k = URI.create("context:/f1j/x"),
46  		f1l = URI.create("context:/f1k"),
47  		f1m = URI.create("context:/"),
48  		f1n = URI.create("context:/.."),
49  		fio = null;
50  
51  	// Strings annotated with @URI properties
52  	@Uri
53  	public String
54  		f2a = "http://www.apache.org/f2a",
55  		f2b = "/f2b",
56  		f2c = "/f2c/x/y",
57  		f2d = "f2d",
58  		f2e = "f2e/x/y",
59  		f2f = "",
60  		f2g = "servlet:/f2g/x",
61  		f2h = "servlet:/f2h",
62  		f2i = "servlet:/",
63  		f2j = "servlet:/..",
64  		f2k = "context:/f2j/x",
65  		f2l = "context:/f2k",
66  		f2m = "context:/",
67  		f2n = "context:/..",
68  		f2o = null;
69  
70  	// Strings with labels
71  	@Uri
72  	public String
73  		f3a = "http://www.apache.org/f3a/x?label=MY_LABEL&foo=bar",
74  		f3b = StringUtils.urlEncode("<>&'\""),
75  		f3c = "<>&'\"";  // Invalid URI, but should produce parsable output.
76  
77  	// @URI on bean
78  	public TestURIb f4 = new TestURIb();
79  
80  	// @URI on bean property method.
81  	@Uri
82  	public String getF5() {
83  		return "f5/x";
84  	}
85  
86  	@Uri
87  	public static class TestURIb {
88  		@Override /* Object */
89  		public String toString() {
90  			return "test/uri/b";
91  		}
92  	}
93  }