Request.getActiveType() returns different values

Poster Content
nk4um Administrator
Posts: 607
April 23, 2008 12:16
I suppose the general purpose way to do this would be:

String activeType;
if (context.getThisRequest().isActiveURI())
{ activeType=context.getThisRequest().getActiveType();
}
else
{ activeType=context.getThisRequest().getURI();
  int i=activeType.indexOf('':'');
  if (i>=0)
  { activeType=activeType.substring(i+1);
  }
}


or

String uri = context.getThisRequest().getURI();
int i1=0;
int i2=uri.length();
if (uri.indexOf('':'')>=0) i1=uri.indexOf('':'')+1;
if (uri.indexOf(''+'')>=0) i2=uri.indexOf(''+'');
String activeType=uri.substring(i1,i2);


These should work if all nested URIs are correctly escaped.
Like · Post Reply
nk4um Administrator
Posts: 158
April 23, 2008 11:35
Sorry, your uri has the form "env:property-title" so the code would be


String uriString = context.getThisRequest().getURI();
String property = uriString.substring("env".length());
Like · Post Reply
nk4um Administrator
Posts: 158
April 23, 2008 11:33Parsing the URI
Carlos,

Ask for the URI as a string and parse it using Java String processing:


String uriString = context.getThisRequest().getURI();
uriString.subString("properties".length());

is a start down the path.

-- Randy
Like · Post Reply
nk4um User
Posts: 54
April 23, 2008 01:53
Corner cases appear to be my specialty.

I use getActiveType() only because I don''t know how to consistently get the right-hand side of the accessor. For example, for my env: accessor, I want to be able to make one method call and always get the string attached to the env: accessor name. I was using getActiveType() because that appeared to give me that...until I did not have an incoming argument.
Like · Post Reply
nk4um Administrator
Posts: 607
April 22, 2008 09:59Yes this is correct
Yes this is correct though I appreciate the corner case that you have stumbled over.

If you are being pedantic about processing requests inside an accessor you should use the method INKFRequestReadOnly.isActiveURI() before using an of the argument methods or getActiveType(). An identifier is considered active if it pattern matches the active URI syntax specification.

http://tools.ietf.org/draft/draft-butterfield-active-uri/draft-butterfield-active-uri-01.txt
Like · Post Reply
nk4um User
Posts: 54
April 22, 2008 00:47Request.getActiveType() returns different values
I wrote an accessor with the following code snippet:

INKFRequestReadOnly request = context.getThisRequest();
System.out.println("getActiveType: " + request.getActiveType());


A URI of

properties:system-title


(meaning no arguments) returns the following output:

getActiveType: null


A URI of

properties:system-title+arg1@something 


returns the following output:

getActiveType: system-title


Is this the proper behavior? If yes, why? If no, I will post it to bugxter. ;)
Like · Post Reply