1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.qa.glnm.aem;
21
22 import java.net.MalformedURLException;
23 import java.net.URL;
24
25 import io.wcm.qa.glnm.exceptions.GaleniumException;
26
27
28
29
30
31
32 public class AemComponentUrlBuilder {
33
34
35 private static final String NO_CONTENT_PATH_CONFIGURED = "CONTENT_PATH_FROM_AEM__COMPONENT_URL_BUILDER";
36 private static final String NO_COMPONENT_NAME_CONFIGURED = "COMPONENT_NAME_FROM_AEM__COMPONENT_URL_BUILDER";
37
38 private String protocol = "http";
39 private String host = "localhost";
40 private int port = 4502;
41 private String componentName = NO_COMPONENT_NAME_CONFIGURED;
42 private String contentPath = NO_CONTENT_PATH_CONFIGURED;
43 private boolean authorInstance = true;
44 private String extension = "html";
45
46
47 AemComponentUrlBuilder() {
48 }
49
50
51
52
53
54
55 public URL build() {
56 try {
57 return new URL(getProtocol(), getHost(), getPort(), getFile());
58 }
59 catch (MalformedURLException ex) {
60 StringBuilder stringBuilder = new StringBuilder()
61 .append("could not construct URL: [protocol: '")
62 .append(getProtocol())
63 .append("host: '")
64 .append(getHost())
65 .append("', port: ")
66 .append(getPort())
67 .append("file: '")
68 .append(getFile())
69 .append("']");
70 throw new GaleniumException(stringBuilder.toString(), ex);
71 }
72 }
73
74
75
76
77
78
79
80 public AemComponentUrlBuilder setAuthorInstance(boolean isAuthor) {
81 this.authorInstance = isAuthor;
82 return this;
83 }
84
85
86
87
88
89
90
91 public AemComponentUrlBuilder setComponentName(String name) {
92 this.componentName = name;
93 return this;
94 }
95
96
97
98
99
100
101
102 public AemComponentUrlBuilder setContentPath(String path) {
103 this.contentPath = path;
104 return this;
105 }
106
107
108
109
110
111
112
113 public AemComponentUrlBuilder setExtension(String renderFormat) {
114 this.extension = renderFormat;
115 return this;
116 }
117
118
119
120
121
122
123
124 public AemComponentUrlBuilder setHost(String hostName) {
125 this.host = hostName;
126 return this;
127 }
128
129
130
131
132
133
134
135 public AemComponentUrlBuilder setPort(int aemPort) {
136 this.port = aemPort;
137 return this;
138 }
139
140
141
142
143
144
145
146 public AemComponentUrlBuilder setProtocol(String networkProtocol) {
147 this.protocol = networkProtocol;
148 return this;
149 }
150
151 private String getFile() {
152 StringBuilder builder = new StringBuilder()
153 .append(getContentPath())
154 .append("/jcr:content/")
155 .append(getComponentName())
156 .append(".")
157 .append(getExtension());
158 if (isAuthorInstance()) {
159 builder.append("?wcmmode=disabled");
160 }
161 return builder.toString();
162 }
163
164 protected String getComponentName() {
165 return componentName;
166 }
167
168 protected String getContentPath() {
169 return contentPath;
170 }
171
172 protected String getExtension() {
173 return extension;
174 }
175
176 protected String getHost() {
177 return host;
178 }
179
180 protected int getPort() {
181 return port;
182 }
183
184 protected String getProtocol() {
185 return protocol;
186 }
187
188 protected boolean isAuthorInstance() {
189 return authorInstance;
190 }
191
192 }