Permalink
Browse files

Added server resource support

  • Loading branch information...
1 parent 5812d19 commit 37fc8d1a3d46f0a002748f5cb55271817ee9e731 @templth templth committed Jan 15, 2013
Showing with 540 additions and 255 deletions.
  1. +98 −41 modules/org.restlet.js/src/js/org/restlet/data/CharacterSet.js
  2. +78 −1 modules/org.restlet.js/src/js/org/restlet/data/ClientInfo.js
  3. +14 −1 modules/org.restlet.js/src/js/org/restlet/data/Encoding.js
  4. +52 −1 modules/org.restlet.js/src/js/org/restlet/data/MediaType.js
  5. +64 −0 modules/org.restlet.js/src/js/org/restlet/data/Parameter.js
  6. +3 −0 modules/org.restlet.js/src/js/org/restlet/engine/adapter/Call.js
  7. +4 −4 modules/org.restlet.js/src/js/org/restlet/engine/adapter/HttpRequest.js
  8. +1 −0 modules/org.restlet.js/src/js/org/restlet/engine/adapter/ServerAdapter.js
  9. +2 −0 modules/org.restlet.js/src/js/org/restlet/engine/adapter/ServerCall.js
  10. +1 −1 modules/org.restlet.js/src/js/org/restlet/engine/headers/CacheDirectiveReader.js
  11. +1 −1 modules/org.restlet.js/src/js/org/restlet/engine/headers/ExpectationReader.js
  12. +90 −54 modules/org.restlet.js/src/js/org/restlet/engine/headers/HeaderReader.js
  13. +23 −21 modules/org.restlet.js/src/js/org/restlet/engine/headers/PreferenceReader.js
  14. +14 −10 modules/org.restlet.js/src/js/org/restlet/engine/resource/AnnotationInfo.js
  15. +3 −3 modules/org.restlet.js/src/js/org/restlet/engine/resource/AnnotationUtils.js
  16. +1 −0 modules/org.restlet.js/src/js/org/restlet/engine/resource/VariantInfo.js
  17. +13 −0 modules/org.restlet.js/src/js/org/restlet/representation/Variant.js
  18. +0 −3 modules/org.restlet.js/src/js/org/restlet/resource/Finder.js
  19. +2 −2 modules/org.restlet.js/src/js/org/restlet/resource/Resource.js
  20. +74 −107 modules/org.restlet.js/src/js/org/restlet/resource/ServerResource.js
  21. +0 −3 modules/org.restlet.js/src/js/org/restlet/routing/Router.js
  22. +2 −2 modules/org.restlet.js/src/js/org/restlet/services/MetadataService.js
@@ -1,46 +1,103 @@
var CharacterSet = new [class Class](Metadata, {
initialize: function(name, description) {
- this.name = name;
- this.description = description;
+ if (name!=null) {
+ name == name.toUpperCase();
+ }
+ if (description==null) {
+ description = "Character set or range of character sets";
+ }
+ this.callSuperCstr(CharacterSet.getIanaName(name), description);
},
- getName: function() {
- return this.name;
- },
- getDescription: function() {
- return this.description;
- }
+
+ equals: function(object) {
+ return (object instanceof CharacterSet)
+ && this.getName()
+ .equalsIgnoreCase(object.getName());
+ },
+
+ getParent: function() {
+ return this.equals(CharacterSet.ALL) ? null : CharacterSet.ALL;
+ },
+
+ includes: function(included) {
+ return this.equals(CharacterSet.ALL) || (included == null) || equals(included);
+ }
});
-CharacterSet.extend({
- ALL: new CharacterSet("*", "All character sets"),
- ISO_8859_1: new CharacterSet(
- "ISO-8859-1", "ISO/IEC 8859-1 or Latin 1 character set"),
- ISO_8859_2: new CharacterSet(
- "ISO-8859-2", "ISO/IEC 8859-2 or Latin 2 character set"),
- ISO_8859_3: new CharacterSet(
- "ISO-8859-3", "ISO/IEC 8859-3 or Latin 3 character set"),
- ISO_8859_4: new CharacterSet(
- "ISO-8859-4", "ISO/IEC 8859-4 or Latin 4 character set"),
- ISO_8859_5: new CharacterSet(
- "ISO-8859-5", "ISO/IEC 8859-5 or Cyrillic character set"),
- ISO_8859_6: new CharacterSet(
- "ISO-8859-6", "ISO/IEC 8859-6 or Arabic character set"),
- ISO_8859_7: new CharacterSet(
- "ISO-8859-7", "ISO/IEC 8859-7 or Greek character set"),
- ISO_8859_8: new CharacterSet(
- "ISO-8859-8", "ISO/IEC 8859-8 or Hebrew character set"),
- ISO_8859_9: new CharacterSet(
- "ISO-8859-9", "ISO/IEC 8859-9 or Latin 5 character set"),
- ISO_8859_10: new CharacterSet(
- "ISO-8859-10", "ISO/IEC 8859-10 or Latin 6 character set"),
- MACINTOSH: new CharacterSet("macintosh",
- "Mac OS Roman character set"),
- US_ASCII: new CharacterSet("US-ASCII",
- "US ASCII character set"),
- UTF_16: new CharacterSet("UTF-16",
- "UTF 16 character set"),
- UTF_8: new CharacterSet("UTF-8",
- "UTF 8 character set"),
- WINDOWS_1252: new CharacterSet(
- "windows-1252", "Windows 1232 character set")
-});
+CharacterSet.getIanaName = function(name) {
+ if (name != null) {
+ name = name.toUpperCase();
+
+ if (name.equalsIgnoreCase("MACROMAN")) {
+ name = CharacterSet.MACINTOSH.getName();
+ } else if (name.equalsIgnoreCase("ASCII")) {
+ name = CharacterSet.US_ASCII.getName();
+ } else if (name.equalsIgnoreCase("latin1")) {
+ name = CharacterSet.ISO_8859_1.getName();
+ } else if (name.equalsIgnoreCase("latin2")) {
+ name = CharacterSet.ISO_8859_2.getName();
+ } else if (name.equalsIgnoreCase("latin3")) {
+ name = CharacterSet.ISO_8859_3.getName();
+ } else if (name.equalsIgnoreCase("latin4")) {
+ name = CharacterSet.ISO_8859_4.getName();
+ } else if (name.equalsIgnoreCase("cyrillic")) {
+ name = CharacterSet.ISO_8859_5.getName();
+ } else if (name.equalsIgnoreCase("arabic")) {
+ name = CharacterSet.ISO_8859_6.getName();
+ } else if (name.equalsIgnoreCase("greek")) {
+ name = CharacterSet.ISO_8859_7.getName();
+ } else if (name.equalsIgnoreCase("hebrew")) {
+ name = CharacterSet.ISO_8859_8.getName();
+ } else if (name.equalsIgnoreCase("latin5")) {
+ name = CharacterSet.ISO_8859_9.getName();
+ } else if (name.equalsIgnoreCase("latin6")) {
+ name = CharacterSet.ISO_8859_10.getName();
+ }
+ }
+
+ return name;
+};
+
+CharacterSet.ALL = new CharacterSet("*", "All character sets");
+CharacterSet.ISO_8859_1 = new CharacterSet("ISO-8859-1", "ISO/IEC 8859-1 or Latin 1 character set");
+CharacterSet.ISO_8859_2 = new CharacterSet("ISO-8859-2", "ISO/IEC 8859-2 or Latin 2 character set");
+CharacterSet.ISO_8859_3 = new CharacterSet("ISO-8859-3", "ISO/IEC 8859-3 or Latin 3 character set");
+CharacterSet.ISO_8859_4 = new CharacterSet("ISO-8859-4", "ISO/IEC 8859-4 or Latin 4 character set");
+CharacterSet.ISO_8859_5 = new CharacterSet("ISO-8859-5", "ISO/IEC 8859-5 or Cyrillic character set");
+CharacterSet.ISO_8859_6 = new CharacterSet("ISO-8859-6", "ISO/IEC 8859-6 or Arabic character set");
+CharacterSet.ISO_8859_7 = new CharacterSet("ISO-8859-7", "ISO/IEC 8859-7 or Greek character set");
+CharacterSet.ISO_8859_8 = new CharacterSet("ISO-8859-8", "ISO/IEC 8859-8 or Hebrew character set");
+CharacterSet.ISO_8859_9 = new CharacterSet("ISO-8859-9", "ISO/IEC 8859-9 or Latin 5 character set");
+CharacterSet.ISO_8859_10 = new CharacterSet("ISO-8859-10", "ISO/IEC 8859-10 or Latin 6 character set");
+CharacterSet.MACINTOSH = new CharacterSet("macintosh", "Mac OS Roman character set");
+CharacterSet.US_ASCII = new CharacterSet("US-ASCII", "US ASCII character set");
+CharacterSet.UTF_16 = new CharacterSet("UTF-16", "UTF 16 character set");
+CharacterSet.UTF_8 = new CharacterSet("UTF-8", "UTF 8 character set");
+CharacterSet.WINDOWS_1252 = new CharacterSet("windows-1252", "Windows 1232 character set");
+
+CharacterSet.valueOf = function(name) {
+ var result = null;
+ name = CharacterSet.getIanaName(name);
+
+ if ((name != null) && !name.equals("")) {
+ if (name.equalsIgnoreCase(CharacterSet.ALL.getName())) {
+ result = CharacterSet.ALL;
+ } else if (name.equalsIgnoreCase(CharacterSet.ISO_8859_1.getName())) {
+ result = CharacterSet.ISO_8859_1;
+ } else if (name.equalsIgnoreCase(CharacterSet.US_ASCII.getName())) {
+ result = CharacterSet.US_ASCII;
+ } else if (name.equalsIgnoreCase(CharacterSet.UTF_8.getName())) {
+ result = CharacterSet.UTF_8;
+ } else if (name.equalsIgnoreCase(CharacterSet.UTF_16.getName())) {
+ result = CharacterSet.UTF_16;
+ } else if (name.equalsIgnoreCase(CharacterSet.WINDOWS_1252.getName())) {
+ result = CharacterSet.WINDOWS_1252;
+ } else if (name.equalsIgnoreCase(CharacterSet.MACINTOSH.getName())) {
+ result = CharacterSet.MACINTOSH;
+ } else {
+ result = new CharacterSet(name);
+ }
+ }
+
+ return result;
+};
@@ -12,33 +12,110 @@ var ClientInfo = new [class Class]({
}
this.forwardedAddresses = [];
this.from = null;
+
+ //private volatile Map<String, String> agentAttributes;
+ //private volatile Product agentMainProduct;
+ //private volatile List<Product> agentProducts;
+ this.authenticated = false;
+ //private volatile List<java.security.cert.Certificate> certificates;
+ //private volatile String cipherSuite;
+ this.expectations = [];
+ //private volatile List<java.security.Principal> principals;
+ //private volatile List<org.restlet.security.Role> roles;
+ //private volatile org.restlet.security.User user;
},
- getAddress: function() {
+ accept: function() {
+ if (arguments.length==1) {
+ _acceptList.accept(arguments[0]);
+ } else if (arguments.length==2) {
+ _acceptSingleElement.accept(arguments[0], arguments[1]);
+ }
+ },
+
+ _acceptList: function(metadata) {
+ if (metadata != null) {
+ for (var i=0;i<metadata.length;i++) {
+ var md = metadata[i];
+ this._acceptSingleElement(md, 1.0);
+ }
+ }
+ },
+
+ _acceptSingleElement: function(metadata, quality) {
+ if (metadata instanceof [class MediaType]) {
+ this.getAcceptedMediaTypes().add(
+ new [class Preference](metadata, quality));
+ } else if (metadata instanceof [class Language]) {
+ this.getAcceptedLanguages().add(
+ new [class Preference](metadata, quality));
+ } else if (metadata instanceof [class Encoding]) {
+ this.getAcceptedEncodings().add(
+ new [class Preference](metadata, quality));
+ } else {
+ this.getAcceptedCharacterSets().add(
+ new [class Preference](metadata, quality));
+ }
+ },
+
+ getAddress: function() {
return this.address;
},
+ setAddress: function(address) {
+ this.address = address;
+ },
getAgent: function() {
return this.agent;
},
+ setAgent: function(agent) {
+ this.agent = agent;
+ },
getPort: function() {
return this.port;
},
+ setPort: function(port) {
+ this.port = port;
+ },
getAcceptedCharacterSets: function() {
return this.acceptedCharacterSets;
},
+ setAcceptedCharacterSets: function(acceptedCharacterSets) {
+ this.acceptedCharacterSets = acceptedCharacterSets;
+ },
getAcceptedEncodings: function() {
return this.acceptedEncodings;
},
+ setAcceptedEncodings: function(acceptedEncodings) {
+ this.acceptedEncodings = acceptedEncodings;
+ },
getAcceptedLanguages: function() {
return this.acceptedLanguages;
},
+ setAcceptedLanguages: function(acceptedLanguages) {
+ this.acceptedLanguages = acceptedLanguages;
+ },
getAcceptedMediaTypes: function() {
return this.acceptedMediaTypes;
},
+ setAcceptedMediaTypes: function(acceptedMediaTypes) {
+ this.acceptedMediaTypes = acceptedMediaTypes;
+ },
getForwardedAddresses: function() {
return this.forwardedAddresses;
},
+ setForwardedAddresses: function(forwardedAddresses) {
+ this.forwardedAddresses = forwardedAddresses;
+ },
+ getExpectations: function() {
+ return this.expectations;
+ },
+ setExpectations: function(expectations) {
+ this.expectations = expectations;
+ },
getFrom: function() {
return this.from;
+ },
+ setFrom: function(from) {
+ this.from = from;
}
});
@@ -6,7 +6,20 @@ var Encoding = new [class Class](Metadata, {
}
this.name = name;
this.description = description;*/
- }
+ },
+
+ equals: function(object) {
+ return (object instanceof [class Encoding])
+ && this.getName().equalsIgnoreCase(object.getName());
+ },
+
+ getParent: function() {
+ return this.equals(Encoding.ALL) ? null : Encoding.ALL;
+ },
+
+ includes: function(included) {
+ return this.equals(Encoding.ALL) || (included == null) || this.equals(included);
+ }
});
Encoding.extend({
/** All encodings acceptable. */
@@ -6,6 +6,28 @@ var MediaType = new [class Class](Metadata, {
this.callSuperCstr(MediaType.normalizeType(name, parameters), description);
},
+ equals: function(obj, ignoreParameters) {
+ if (ignoreParameters==null) {
+ ignoreParameters = false;
+ }
+ var result = (obj == this);
+
+ // if obj == this no need to go further
+ if (!result) {
+ // if obj isn't a mediatype or is null don't evaluate further
+ if (obj instanceof MediaType) {
+ var that = obj;
+ if (this.getMainType().equals(that.getMainType())
+ && this.getSubType().equals(that.getSubType())) {
+ result = ignoreParameters
+ || this.getParameters().equals(that.getParameters());
+ }
+ }
+ }
+
+ return result;
+ },
+
getMainType: function() {
var result = null;
@@ -81,6 +103,33 @@ var MediaType = new [class Class](Metadata, {
}
return result;
+ },
+
+ includes: function(included) {
+ var result = this.equals(MediaType.ALL) || this.equals(included);
+
+ if (!result && (included instanceof MediaType)) {
+ var includedMediaType = included;
+
+ if (this.getMainType().equals(includedMediaType.getMainType())) {
+ // Both media types are different
+ if (this.getSubType().equals(includedMediaType.getSubType())) {
+ result = true;
+ } else if (this.getSubType().equals("*")) {
+ result = true;
+ } else if (this.getSubType().startsWith("*+")
+ && includedMediaType.getSubType().endsWith(
+ this.getSubType().substring(2))) {
+ result = true;
+ }
+ }
+ }
+
+ return result;
+ },
+
+ isConcrete: function() {
+ return !this.getName().contains("*");
}
});
@@ -225,4 +274,6 @@ MediaType.APPLICATION_JSON = MediaType.register("application/json", "");
MediaType.APPLICATION_JSONP = MediaType.register("application/jsonp", "");
MediaType.TEXT_JSON = MediaType.register("text/json", "");
MediaType.APPLICATION_XML = MediaType.register("application/xml", "");
-MediaType.TEXT_XML = MediaType.register("text/xml", "");
+MediaType.TEXT_XML = MediaType.register("text/xml", "");
+MediaType.TEXT_HTML = MediaType.register("text/html", "");
+MediaType.TEXT_PLAIN = MediaType.register("text/plain", "");
Oops, something went wrong.

0 comments on commit 37fc8d1

Please sign in to comment.