Topic - Request.getActiveType() returns different values
Topic - Request.getActiveType() returns different values Topic - Request.getActiveType() returns different values
from forum Component Developer
 forum index   my profile   search 
 new topic  post reply 
moderators: pjr tab
Request.getActiveType() returns different values
Joined: 7-February-2006
Posts: 55
Posted: 22-April-2008 01:47
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. ;)
Yes this is correct
Joined: 7-February-2005
Posts: 249
Location: Uncharted territory
Posted: 22-April-2008 10:59
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
Joined: 7-February-2006
Posts: 55
Posted: 23-April-2008 02: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.
Parsing the URI
Joined: 15-February-2005
Posts: 127
Location: Fort Collins, CO
Posted: 23-April-2008 12:33
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
Joined: 15-February-2005
Posts: 127
Location: Fort Collins, CO
Posted: 23-April-2008 12: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());
Joined: 7-February-2005
Posts: 249
Location: Uncharted territory
Posted: 23-April-2008 13: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.
 new topic  post reply  To find out about new replies to this post as they occur
please subscribe to one of these feeds:
AtomRSS moderate 
© 2003-2006, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.