Skip to content

Commit f4b976d

Browse files
authored
Merge pull request #1421 from restlet/2.5__editions
2.5 editions
2 parents 99750b2 + 8303eaf commit f4b976d

File tree

37 files changed

+408
-257
lines changed

37 files changed

+408
-257
lines changed

modules/org.restlet.ext.httpclient/src/main/java/org/restlet/ext/httpclient/HttpClientHelper.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.restlet.Client;
5353
import org.restlet.Request;
5454
import org.restlet.data.Protocol;
55+
import org.restlet.engine.Edition;
5556
import org.restlet.engine.Engine;
5657
import org.restlet.engine.adapter.ClientCall;
5758
import org.restlet.engine.ssl.DefaultSslContextFactory;
@@ -272,7 +273,10 @@ protected void configure(SchemeRegistry schemeRegistry) {
272273
schemeRegistry.register(new Scheme("http", PlainSocketFactory
273274
.getSocketFactory(), 80));
274275

275-
// [ifndef android]
276+
if (Edition.ANDROID.isCurrentEdition()) {
277+
return; // TODO Compile with Android?
278+
}
279+
276280
SSLSocketFactory sslSocketFactory = null;
277281
SslContextFactory sslContextFactory = SslUtils
278282
.getSslContextFactory(this);
@@ -302,7 +306,6 @@ protected void configure(SchemeRegistry schemeRegistry) {
302306
}
303307

304308
schemeRegistry.register(new Scheme("https", 443, sslSocketFactory));
305-
// [enddef]
306309
}
307310

308311
/**

modules/org.restlet.ext.jaas/src/main/java/org/restlet/ext/jaas/ChallengeCallbackHandler.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.restlet.Request;
3535
import org.restlet.Response;
36+
import org.restlet.engine.Edition;
3637

3738
/**
3839
* JAAS callback handler that automatically provides the identifier and secret
@@ -90,16 +91,13 @@ public Response getResponse() {
9091
*/
9192
protected void handle(Callback callback)
9293
throws UnsupportedCallbackException {
93-
// [ifndef android]
94-
if (callback instanceof javax.security.auth.callback.NameCallback) {
94+
if (Edition.ANDROID.isNotCurrentEdition() && callback instanceof javax.security.auth.callback.NameCallback) {
9595
javax.security.auth.callback.NameCallback nc = (javax.security.auth.callback.NameCallback) callback;
9696

9797
if (getRequest().getChallengeResponse() != null) {
9898
nc.setName(getRequest().getChallengeResponse().getIdentifier());
9999
}
100-
} else
101-
// [enddef]
102-
if (callback instanceof PasswordCallback) {
100+
} else if (callback instanceof PasswordCallback) {
103101
PasswordCallback pc = (PasswordCallback) callback;
104102

105103
if (getRequest().getChallengeResponse() != null) {

modules/org.restlet.ext.jackson/src/main/java/org/restlet/ext/jackson/JacksonConverter.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.restlet.data.MediaType;
3131
import org.restlet.data.Preference;
32+
import org.restlet.engine.Edition;
3233
import org.restlet.engine.converter.ConverterHelper;
3334
import org.restlet.engine.resource.VariantInfo;
3435
import org.restlet.representation.Representation;
@@ -43,7 +44,7 @@
4344
* @author Thierry Boileau
4445
*/
4546
public class JacksonConverter extends ConverterHelper {
46-
// [ifndef android] instruction
47+
4748
/** Variant with media type application/xml. */
4849
private static final VariantInfo VARIANT_APPLICATION_XML = new VariantInfo(
4950
MediaType.APPLICATION_XML);
@@ -64,7 +65,6 @@ public class JacksonConverter extends ConverterHelper {
6465
private static final VariantInfo VARIANT_TEXT_CSV = new VariantInfo(
6566
MediaType.TEXT_CSV);
6667

67-
// [ifndef android] instruction
6868
/** Variant with media type text/xml. */
6969
private static final VariantInfo VARIANT_TEXT_XML = new VariantInfo(
7070
MediaType.TEXT_XML);
@@ -123,10 +123,10 @@ public List<VariantInfo> getVariants(Class<?> source) {
123123
if (source != null) {
124124
result = addVariant(result, VARIANT_JSON);
125125
result = addVariant(result, VARIANT_JSON_SMILE);
126-
// [ifndef android] instruction
127-
result = addVariant(result, VARIANT_APPLICATION_XML);
128-
// [ifndef android] instruction
129-
result = addVariant(result, VARIANT_TEXT_XML);
126+
if (Edition.ANDROID.isNotCurrentEdition()) { // TODO check why?
127+
result = addVariant(result, VARIANT_APPLICATION_XML);
128+
result = addVariant(result, VARIANT_TEXT_XML);
129+
}
130130
result = addVariant(result, VARIANT_APPLICATION_YAML);
131131
result = addVariant(result, VARIANT_TEXT_YAML);
132132
result = addVariant(result, VARIANT_TEXT_CSV);
@@ -148,10 +148,8 @@ protected boolean isCompatible(Variant variant) {
148148
return (variant != null)
149149
&& (VARIANT_JSON.isCompatible(variant)
150150
|| VARIANT_JSON_SMILE.isCompatible(variant)
151-
// [ifndef android] line
152-
|| VARIANT_APPLICATION_XML.isCompatible(variant)
153-
// [ifndef android] line
154-
|| VARIANT_TEXT_XML.isCompatible(variant)
151+
|| (Edition.ANDROID.isNotCurrentEdition() && VARIANT_APPLICATION_XML.isCompatible(variant))
152+
|| (Edition.ANDROID.isNotCurrentEdition() && VARIANT_TEXT_XML.isCompatible(variant))
155153
|| VARIANT_APPLICATION_YAML.isCompatible(variant)
156154
|| VARIANT_TEXT_YAML.isCompatible(variant) || VARIANT_TEXT_CSV
157155
.isCompatible(variant));
@@ -244,10 +242,10 @@ public <T> void updatePreferences(List<Preference<MediaType>> preferences,
244242
Class<T> entity) {
245243
updatePreferences(preferences, MediaType.APPLICATION_JSON, 1.0F);
246244
updatePreferences(preferences, MediaType.APPLICATION_JSON_SMILE, 1.0F);
247-
// [ifndef android] instruction
248-
updatePreferences(preferences, MediaType.APPLICATION_XML, 1.0F);
249-
// [ifndef android] instruction
250-
updatePreferences(preferences, MediaType.TEXT_XML, 1.0F);
245+
if (Edition.ANDROID.isNotCurrentEdition()) {
246+
updatePreferences(preferences, MediaType.APPLICATION_XML, 1.0F);
247+
updatePreferences(preferences, MediaType.TEXT_XML, 1.0F);
248+
}
251249
updatePreferences(preferences, MediaType.APPLICATION_YAML, 1.0F);
252250
updatePreferences(preferences, MediaType.TEXT_YAML, 1.0F);
253251
updatePreferences(preferences, MediaType.TEXT_CSV, 1.0F);

modules/org.restlet.ext.jackson/src/main/java/org/restlet/ext/jackson/JacksonRepresentation.java

+31-22
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.OutputStream;
2929

3030
import org.restlet.data.MediaType;
31+
import org.restlet.engine.Edition;
3132
import org.restlet.ext.jackson.internal.XmlFactoryProvider;
3233
import org.restlet.representation.OutputRepresentation;
3334
import org.restlet.representation.Representation;
@@ -62,7 +63,7 @@
6263
* The type to wrap.
6364
*/
6465
public class JacksonRepresentation<T> extends OutputRepresentation {
65-
// [ifndef android] member
66+
6667
/**
6768
* True for expanding entity references when parsing XML representations.
6869
* Default value provided by system property
@@ -71,7 +72,6 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
7172
public final static boolean XML_EXPANDING_ENTITY_REFS = Boolean
7273
.getBoolean("org.restlet.ext.xml.expandingEntityRefs");
7374

74-
// [ifndef android] member
7575
/**
7676
* True for validating DTD documents when parsing XML representations.
7777
* Default value provided by system property
@@ -83,7 +83,6 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
8383
/** The modifiable Jackson CSV schema. */
8484
private CsvSchema csvSchema;
8585

86-
// [ifndef android] member
8786
/**
8887
* Specifies that the parser will expand entity reference nodes. By default
8988
* the value of this is set to false.
@@ -108,7 +107,6 @@ public class JacksonRepresentation<T> extends OutputRepresentation {
108107
/** The representation to parse. */
109108
private volatile Representation representation;
110109

111-
// [ifndef android] member
112110
/**
113111
* Indicates the desire for validating this type of XML representations
114112
* against a DTD. Note that for XML schema or Relax NG validation, use the
@@ -137,10 +135,10 @@ public JacksonRepresentation(MediaType mediaType, T object) {
137135
this.objectReader = null;
138136
this.objectWriter = null;
139137
this.csvSchema = null;
140-
// [ifndef android] instruction
141-
this.expandingEntityRefs = XML_EXPANDING_ENTITY_REFS;
142-
// [ifndef android] instruction
143-
this.validatingDtd = XML_VALIDATING_DTD;
138+
if (Edition.ANDROID.isNotCurrentEdition()) {
139+
this.expandingEntityRefs = XML_EXPANDING_ENTITY_REFS;
140+
this.validatingDtd = XML_VALIDATING_DTD;
141+
}
144142
}
145143

146144
/**
@@ -161,10 +159,10 @@ public JacksonRepresentation(Representation representation,
161159
this.objectReader = null;
162160
this.objectWriter = null;
163161
this.csvSchema = null;
164-
// [ifndef android] instruction
165-
this.expandingEntityRefs = XML_EXPANDING_ENTITY_REFS;
166-
// [ifndef android] instruction
167-
this.validatingDtd = XML_VALIDATING_DTD;
162+
if (Edition.ANDROID.isNotCurrentEdition()) {
163+
this.expandingEntityRefs = XML_EXPANDING_ENTITY_REFS;
164+
this.validatingDtd = XML_VALIDATING_DTD;
165+
}
168166
}
169167

170168
/**
@@ -207,9 +205,9 @@ protected ObjectMapper createObjectMapper() {
207205
SmileFactory smileFactory = new SmileFactory();
208206
smileFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
209207
result = new ObjectMapper(smileFactory);
210-
// [ifndef android]
211-
} else if (MediaType.APPLICATION_XML.isCompatible(getMediaType())
212-
|| MediaType.TEXT_XML.isCompatible(getMediaType())) {
208+
209+
} else if (Edition.ANDROID.isNotCurrentEdition() && (MediaType.APPLICATION_XML.isCompatible(getMediaType())
210+
|| MediaType.TEXT_XML.isCompatible(getMediaType()))) {
213211
javax.xml.stream.XMLInputFactory xif = XmlFactoryProvider.newInputFactory();
214212
xif.setProperty(
215213
javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
@@ -222,7 +220,7 @@ protected ObjectMapper createObjectMapper() {
222220
XmlFactory xmlFactory = new XmlFactory(xif, xof);
223221
xmlFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
224222
result = new XmlMapper(xmlFactory);
225-
// [enddef]
223+
226224
} else if (MediaType.APPLICATION_YAML.isCompatible(getMediaType())
227225
|| MediaType.TEXT_YAML.isCompatible(getMediaType())) {
228226
YAMLFactory yamlFactory = new YAMLFactory();
@@ -365,25 +363,30 @@ public ObjectWriter getObjectWriter() {
365363
return this.objectWriter;
366364
}
367365

368-
// [ifndef android] method
369366
/**
370-
* Indicates if the parser will expand entity reference nodes. By default
367+
* Indicates if the parser will expand entity reference nodes. By default,
371368
* the value of this is set to true.
372369
*
373370
* @return True if the parser will expand entity reference nodes.
374371
*/
375372
public boolean isExpandingEntityRefs() {
376-
return expandingEntityRefs;
373+
if (Edition.ANDROID.isCurrentEdition()) {
374+
throw new RuntimeException(); // TODO right thing to do?
375+
}
376+
return expandingEntityRefs;
377377
}
378378

379-
// [ifndef android] method
380379
/**
381380
* Indicates the desire for validating this type of XML representations
382381
* against an XML schema if one is referenced within the contents.
383382
*
384383
* @return True if the schema-based validation is enabled.
385384
*/
386385
public boolean isValidatingDtd() {
386+
if (Edition.ANDROID.isCurrentEdition()) {
387+
throw new RuntimeException(); // TODO right thing to do?
388+
}
389+
387390
return validatingDtd;
388391
}
389392

@@ -397,7 +400,6 @@ public void setCsvSchema(CsvSchema csvSchema) {
397400
this.csvSchema = csvSchema;
398401
}
399402

400-
// [ifndef android] method
401403
/**
402404
* Indicates if the parser will expand entity reference nodes. By default
403405
* the value of this is set to true.
@@ -406,6 +408,10 @@ public void setCsvSchema(CsvSchema csvSchema) {
406408
* True if the parser will expand entity reference nodes.
407409
*/
408410
public void setExpandingEntityRefs(boolean expandEntityRefs) {
411+
if (Edition.ANDROID.isCurrentEdition()) {
412+
throw new RuntimeException(); // TODO right thing to do?
413+
}
414+
409415
this.expandingEntityRefs = expandEntityRefs;
410416
}
411417

@@ -459,7 +465,6 @@ public void setObjectWriter(ObjectWriter objectWriter) {
459465
this.objectWriter = objectWriter;
460466
}
461467

462-
// [ifndef android] method
463468
/**
464469
* Indicates the desire for validating this type of XML representations
465470
* against an XML schema if one is referenced within the contents.
@@ -468,6 +473,10 @@ public void setObjectWriter(ObjectWriter objectWriter) {
468473
* The new validation flag to set.
469474
*/
470475
public void setValidatingDtd(boolean validating) {
476+
if (Edition.ANDROID.isCurrentEdition()) {
477+
throw new RuntimeException(); // TODO right thing to do?
478+
}
479+
471480
this.validatingDtd = validating;
472481
}
473482

modules/org.restlet.ext.json/src/main/java/org/restlet/ext/json/JsonRepresentation.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.json.JSONTokener;
3636
import org.restlet.data.CharacterSet;
3737
import org.restlet.data.MediaType;
38+
import org.restlet.engine.Edition;
3839
import org.restlet.representation.Representation;
3940
import org.restlet.representation.StringRepresentation;
4041
import org.restlet.representation.WriterRepresentation;
@@ -115,7 +116,6 @@ public JsonRepresentation(Map<String, Object> map) {
115116
this(new JSONObject(map));
116117
}
117118

118-
// [ifndef android] method
119119
/**
120120
* Constructor from a bean using reflection to generate JSON names.
121121
*
@@ -124,7 +124,7 @@ public JsonRepresentation(Map<String, Object> map) {
124124
* @see org.json.JSONObject#JSONObject(Object)
125125
*/
126126
public JsonRepresentation(Object bean) {
127-
this(new JSONObject(bean));
127+
this(new JSONObject(bean)); // TODO Should be called if Android edition
128128
}
129129

130130
/**
@@ -227,10 +227,11 @@ private String getJsonText() throws JSONException {
227227
try {
228228
result = this.jsonRepresentation.getText();
229229
} catch (IOException e) {
230-
// [ifndef android] instruction
231-
throw new JSONException(e);
232-
// [ifdef android] instruction uncomment
233-
// throw new JSONException(e.getMessage());
230+
if (Edition.ANDROID.isCurrentEdition()) {
231+
throw new JSONException(e.getMessage());
232+
} else {
233+
throw new JSONException(e);
234+
}
234235
}
235236
}
236237

modules/org.restlet.ext.odata/src/main/java/org/restlet/ext/odata/Service.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.restlet.data.Protocol;
4848
import org.restlet.data.Reference;
4949
import org.restlet.data.Tag;
50+
import org.restlet.engine.Edition;
5051
import org.restlet.engine.header.HeaderConstants;
5152
import org.restlet.engine.header.HeaderReader;
5253
import org.restlet.ext.atom.Content;
@@ -562,25 +563,25 @@ private String getSimpleValue(Representation representation, String tagName)
562563
|| MediaType.TEXT_XML.isCompatible(representation
563564
.getMediaType())) {
564565
DomRepresentation xmlRep = new DomRepresentation(representation);
565-
// [ifndef android] instruction
566-
Node node = xmlRep.getNode("//" + tagName);
567-
568-
// [ifdef android] uncomment
569-
// Node node = null;
570-
// try {
571-
// org.w3c.dom.NodeList nl = xmlRep.getDocument()
572-
// .getElementsByTagName(tagName);
573-
// node = (nl.getLength() > 0) ? nl.item(0) : null;
574-
// } catch (IOException e1) {
575-
// }
576-
// [enddef]
566+
567+
Node node = null;
568+
if (Edition.ANDROID.isCurrentEdition()) {
569+
try {
570+
org.w3c.dom.NodeList nl = xmlRep.getDocument()
571+
.getElementsByTagName(tagName);
572+
node = (nl.getLength() > 0) ? nl.item(0) : null;
573+
} catch (IOException e1) {
574+
}
575+
} else {
576+
node = xmlRep.getNode("//" + tagName);
577+
}
577578

578579
if (node != null) {
579-
// [ifndef android] instruction
580-
result = node.getTextContent();
581-
// [ifdef android] instruction uncomment
582-
// result =
583-
// org.restlet.ext.xml.XmlRepresentation.getTextContent(node);
580+
if (Edition.ANDROID.isCurrentEdition()) {
581+
result = org.restlet.ext.xml.XmlRepresentation.getTextContent(node);
582+
} else {
583+
result = node.getTextContent();
584+
}
584585
}
585586
} else {
586587
result = representation.getText();

modules/org.restlet.ext.servlet/src/main/java/org/restlet/ext/servlet/ServletAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ServletAdapter(ServletContext context) {
102102
* The next Restlet.
103103
*/
104104
public ServletAdapter(ServletContext context, Restlet next) {
105-
// [ifndef gae] instruction
105+
// [ifndef gae] instruction TODO cannot express this with if because super() must be first call
106106
super(new Context(new ServletLogger(context)));
107107
// [ifdef gae] instruction uncomment
108108
// super(new Context());

0 commit comments

Comments
 (0)