use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXLoader method insertCommandLineArguments.
/**
* Copies the props from the command line to the static dict propertiesFromArgv.
*/
private static void insertCommandLineArguments() {
NSArray keys = propertiesFromArgv.allKeys();
int count = keys.count();
for (int i = 0; i < count; i++) {
Object key = keys.objectAtIndex(i);
Object value = propertiesFromArgv.objectForKey(key);
NSProperties._setProperty((String) key, (String) value);
}
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXRequest method _cookieDictionary.
/**
* Parses all cookies one at a time catch parse exception which just discards
* that cookie and not all cookies. It uses java.net.HttpCookie as a parser.
* @return a dictionary of cookies, parsed one cookie at a time
*/
private NSDictionary _cookieDictionary() {
if (_cookieDictionary == null) {
NSMutableDictionary<String, NSArray<String>> cookieDictionary = new NSMutableDictionary<String, NSArray<String>>();
//
// from WORequest._cookieDescription()
String cookie = headerForKey("cookie");
if (cookie == null || cookie.length() == 0)
// IIS cookies use a different header
cookie = headerForKey("http_cookie");
if (cookie != null && cookie.length() > 0) {
String[] cookies = cookie.split(";");
for (int i = 0; i < cookies.length; i++) {
try {
//
// only parse one cookie at a time => get(0)
HttpCookie httpCookie = HttpCookie.parse(cookies[i]).get(0);
//
// Cookies with longer paths are listed before cookies with shorter paths:
// see https://stackoverflow.com/a/24214538
// Cookies with longer Patch are more specific than cookies with shorter path
// and should not be replaced by a less specific cookie
// If a cookie with Therfore we do not override cookies if there are already there!
String cookieName = httpCookie.getName();
String cookieValue = httpCookie.getValue();
log.debug("Cookie: '" + cookieName + "' = '" + cookieValue + "'");
NSArray<String> cookieValueArray = cookieDictionary.get(cookieName);
if (cookieValueArray == null) {
cookieValueArray = new NSArray<>();
}
cookieValueArray = cookieValueArray.arrayByAddingObject(cookieValue);
cookieDictionary.put(cookieName, cookieValueArray);
} catch (Throwable t) {
log.warn("Unable to parse cookie '" + cookies[i] + "' : " + t.getMessage());
}
}
}
_cookieDictionary = cookieDictionary.immutableClone();
}
return _cookieDictionary;
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXResourceManager method _initFrameworkProjectBundles.
private void _initFrameworkProjectBundles() {
NSBundle aBundle = null;
NSArray aFrameworkBundleList = NSBundle.frameworkBundles();
for (Enumeration aBundleEnumerator = aFrameworkBundleList.objectEnumerator(); aBundleEnumerator.hasMoreElements(); _erxCachedBundleForFrameworkNamed(aBundle.name())) {
aBundle = (NSBundle) aBundleEnumerator.nextElement();
}
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXResponseRewriter method addResourceInHead.
/**
* Adds a reference to an arbitrary file with a correct resource URL wrapped
* between startTag and endTag in the HTML head tag if it isn't already
* present in the response.
*
* @param response
* the response
* @param context
* the context
* @param framework
* the framework that contains the file
* @param fileName
* the name of the file to add
* @param startTag
* the HTML to prepend before the URL
* @param endTag
* the HTML to append after the URL
* @param fallbackStartTag
* @param fallbackEndTag
* @param tagMissingBehavior
* how to handle the case where the tag is missing
*
* @return whether or not the content was added
*/
public static boolean addResourceInHead(WOResponse response, WOContext context, String framework, String fileName, String startTag, String endTag, String fallbackStartTag, String fallbackEndTag, TagMissingBehavior tagMissingBehavior) {
boolean inserted = true;
String replacementResourceStr = ERXProperties.stringForKey("er.extensions.ERXResponseRewriter.resource." + framework + "." + fileName);
if (replacementResourceStr != null) {
int dotIndex = replacementResourceStr.indexOf('.');
framework = replacementResourceStr.substring(0, dotIndex);
fileName = replacementResourceStr.substring(dotIndex + 1);
}
if (!ERXResponseRewriter.isResourceAddedToHead(context, framework, fileName) && (_delagate == null || _delagate.responseRewriterShouldAddResource(framework, fileName))) {
boolean insert = true;
if (_delagate != null) {
Resource replacementResource = _delagate.responseRewriterWillAddResource(framework, fileName);
if (replacementResource != null) {
framework = replacementResource.framework();
fileName = replacementResource.fileName();
// double-check that the replacement hasn't already been added
if (ERXResponseRewriter.isResourceAddedToHead(context, framework, fileName)) {
insert = false;
}
}
}
if (insert) {
String url;
if (fileName.indexOf("://") != -1 || fileName.startsWith("/")) {
url = fileName;
} else {
WOResourceManager rm = WOApplication.application().resourceManager();
NSArray languages = null;
if (context.hasSession()) {
languages = context.session().languages();
}
url = rm.urlForResourceNamed(fileName, framework, languages, context.request());
boolean generateCompleteResourceURLs = ERXResourceManager._shouldGenerateCompleteResourceURL(context);
boolean secureAllResources = ERXProperties.booleanForKey(ERXResponseRewriter.SECURE_RESOURCES_KEY) && !ERXRequest.isRequestSecure(context.request());
if (generateCompleteResourceURLs || secureAllResources) {
url = ERXResourceManager._completeURLForResource(url, secureAllResources ? Boolean.TRUE : null, context);
}
}
String html = startTag + url + endTag + "\n";
if (fallbackStartTag == null && fallbackEndTag == null) {
inserted = ERXResponseRewriter.insertInResponseBeforeHead(response, context, html, tagMissingBehavior);
} else {
inserted = ERXResponseRewriter.insertInResponseBeforeHead(response, context, html, TagMissingBehavior.Skip);
if (!inserted) {
String fallbackHtml = fallbackStartTag + url + fallbackEndTag + "\n";
inserted = ERXResponseRewriter.insertInResponseBeforeTag(response, context, fallbackHtml, null, TagMissingBehavior.Top);
}
}
if (inserted) {
ERXResponseRewriter.resourceAddedToHead(context, framework, fileName);
}
}
}
return inserted;
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXSession method requestsContextID.
/**
* Utility method that gets the context ID string from the passed in
* request.
*
* @param aRequest
* request to get the context id from
* @return the context id as a string
*/
private String requestsContextID(WORequest aRequest) {
String uri = aRequest.uri();
int idx = uri.indexOf('?');
if (idx != -1)
uri = uri.substring(0, idx);
String eID = NSPathUtilities.lastPathComponent(uri);
NSArray eIDs = NSArray.componentsSeparatedByString(eID, ".");
String reqCID = "1";
if (eIDs.count() > 0) {
reqCID = (String) eIDs.objectAtIndex(0);
}
return reqCID;
}
Aggregations