use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.
the class ERXStyleSheet method appendToResponse.
/**
* Appends the <link> tag, either by using the style sheet name and framework or by using the component content and then generating a link to it.
*/
@Override
public void appendToResponse(WOResponse originalResponse, WOContext wocontext) {
String styleSheetFrameworkName = styleSheetFrameworkName();
String styleSheetName = styleSheetName();
boolean isResourceStyleSheet = styleSheetName != null;
if (isResourceStyleSheet && ERXResponseRewriter.isResourceAddedToHead(wocontext, styleSheetFrameworkName, styleSheetName)) {
// Skip, because this has already been added ...
return;
}
// default to inline for ajax requests
boolean inline = booleanValueForBinding("inline", ERXAjaxApplication.isAjaxRequest(wocontext.request()));
WOResponse response = inline ? originalResponse : new WOResponse();
String href = styleSheetUrl();
if (href == null) {
String key = styleSheetKey();
ERXExpiringCache<String, WOResponse> cache = cache(session());
String md5;
WOResponse cachedResponse = cache.objectForKey(key);
if (cache.isStale(key) || ERXApplication.isDevelopmentModeSafe()) {
cachedResponse = new WOResponse();
super.appendToResponse(cachedResponse, wocontext);
// appendToResponse above will change the response of
// "wocontext" to "newresponse". When this happens during an
// Ajax request, it will lead to backtracking errors on
// subsequent requests, so restore the original response "r"
wocontext._setResponse(originalResponse);
cachedResponse.setHeader("text/css", "content-type");
cache.setObjectForKey(cachedResponse, key);
md5 = md5Hex(cachedResponse.contentString());
cachedResponse.setHeader(md5, "checksum");
}
md5 = cachedResponse.headerForKey("checksum");
NSDictionary<String, Object> query = new NSDictionary<>(md5, "checksum");
href = wocontext.directActionURLForActionNamed(Sheet.class.getName() + "/" + key, query, wocontext.request().isSecure(), 0, false);
}
response._appendContentAsciiString("<link");
if (styleSheetName != null && styleSheetName.toLowerCase().endsWith(".less")) {
response._appendTagAttributeAndValue("rel", "stylesheet/less", false);
} else {
response._appendTagAttributeAndValue("rel", "stylesheet", false);
}
response._appendTagAttributeAndValue("type", "text/css", false);
response._appendTagAttributeAndValue("href", href, false);
response._appendTagAttributeAndValue("media", mediaType(), false);
response._appendContentAsciiString("/>");
response.appendContentString("\n");
boolean inserted = true;
if (!inline) {
String stylesheetLink = response.contentString();
inserted = ERXResponseRewriter.insertInResponseBeforeHead(originalResponse, wocontext, stylesheetLink, ERXResponseRewriter.TagMissingBehavior.Inline);
}
if (inserted) {
if (isResourceStyleSheet) {
ERXResponseRewriter.resourceAddedToHead(wocontext, styleSheetFrameworkName, styleSheetName);
} else if (href != null) {
ERXResponseRewriter.resourceAddedToHead(wocontext, null, href);
}
}
}
use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.
the class ERXComponentRequestHandler method _dispatchWithPreparedSession.
private WOResponse _dispatchWithPreparedSession(WOSession aSession, WOContext aContext, NSDictionary someElements) {
WOComponent aPage = null;
WOResponse aResponse = null;
String aPageName = (String) someElements.objectForKey("wopage");
String oldContextID = aContext._requestContextID();
String oldSessionID = (String) someElements.objectForKey(WOApplication.application().sessionIdKey());
WOApplication anApplication = WOApplication.application();
boolean clearIDsInCookies = false;
if ((oldSessionID == null) || (oldContextID == null)) {
if ((aPageName == null) && (!aSession.storesIDsInCookies())) {
WORequest request = aContext.request();
String cookieHeader = request.headerForKey("cookie");
if ((cookieHeader != null) && (cookieHeader.length() > 0)) {
NSDictionary cookieDict = request.cookieValues();
if ((cookieDict.objectForKey(WOApplication.application().sessionIdKey()) != null) || (cookieDict.objectForKey(WOApplication.application().instanceIdKey()) != null)) {
clearIDsInCookies = true;
}
}
}
aPage = anApplication.pageWithName(aPageName, aContext);
} else {
aPage = _restorePageForContextID(oldContextID, aSession);
if (aPage == null) {
if (anApplication._isPageRecreationEnabled())
aPage = anApplication.pageWithName(aPageName, aContext);
else {
return anApplication.handlePageRestorationErrorInContext(aContext);
}
}
}
aContext._setPageElement(aPage);
aResponse = _dispatchWithPreparedPage(aPage, aSession, aContext, someElements);
if (anApplication.isPageRefreshOnBacktrackEnabled()) {
aResponse.disableClientCaching();
}
aSession._saveCurrentPage();
if ((clearIDsInCookies) && (!aSession.storesIDsInCookies())) {
aSession._clearCookieFromResponse(aResponse);
}
return aResponse;
}
use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.
the class ERXComponentRequestHandler method _handleRequest.
WOResponse _handleRequest(WORequest aRequest) {
WOContext aContext = null;
WOResponse aResponse;
NSDictionary requestHandlerValues = requestHandlerValuesForRequest(aRequest);
WOApplication anApplication = WOApplication.application();
String aSessionID = (String) requestHandlerValues.objectForKey(WOApplication.application().sessionIdKey());
if ((!anApplication.isRefusingNewSessions()) || (aSessionID != null)) {
String aSenderID = (String) requestHandlerValues.objectForKey("woeid");
String oldContextID = (String) requestHandlerValues.objectForKey("wocid");
WOStatisticsStore aStatisticsStore = anApplication.statisticsStore();
if (aStatisticsStore != null)
aStatisticsStore.applicationWillHandleComponentActionRequest();
try {
aContext = anApplication.createContextForRequest(aRequest);
aContext._setRequestContextID(oldContextID);
aContext._setSenderID(aSenderID);
anApplication.awake();
aResponse = _dispatchWithPreparedApplication(anApplication, aContext, requestHandlerValues);
NSNotificationCenter.defaultCenter().postNotification(WORequestHandler.DidHandleRequestNotification, aContext);
anApplication.sleep();
} catch (Exception exception) {
try {
NSLog.err.appendln("<" + getClass().getName() + ">: Exception occurred while handling request:\n" + exception.toString());
if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L)) {
NSLog.debug.appendln(exception);
}
if (aContext == null)
aContext = anApplication.createContextForRequest(aRequest);
else {
aContext._putAwakeComponentsToSleep();
}
WOSession aSession = aContext._session();
aResponse = anApplication.handleException(exception, aContext);
if (aSession != null) {
try {
anApplication.saveSessionForContext(aContext);
anApplication.sleep();
} catch (Exception eAgain) {
NSLog.err.appendln("<WOApplication '" + anApplication.name() + "'>: Another Exception occurred while trying to clean the application:\n" + eAgain.toString());
if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L))
NSLog.debug.appendln(eAgain);
}
}
} finally {
if ((aContext != null) && (aContext._session() != null))
anApplication.saveSessionForContext(aContext);
}
}
if (aResponse != null) {
aResponse._finalizeInContext(aContext);
}
if (aStatisticsStore != null) {
WOComponent aPage = aContext.page();
String aName = null;
if (aPage != null) {
aName = aPage.name();
}
aStatisticsStore.applicationDidHandleComponentActionRequestWithPageNamed(aName);
}
} else {
String newLocationURL = anApplication._newLocationForRequest(aRequest);
String contentString = "Sorry, your request could not immediately be processed. Please try this URL: <a href=\"" + newLocationURL + "\">" + newLocationURL + "</a>";
aResponse = anApplication.createResponseInContext(null);
WOResponse._redirectResponse(aResponse, newLocationURL, contentString);
aResponse._finalizeInContext(null);
}
return aResponse;
}
use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.
the class ERXComponentRequestHandler method _dispatchWithPreparedApplication.
private WOResponse _dispatchWithPreparedApplication(WOApplication anApplication, WOContext aContext, NSDictionary someElements) {
WOSession aSession = null;
WOResponse aResponse = null;
WOResponse errorResponse = null;
String aSessionID = (String) someElements.objectForKey(WOApplication.application().sessionIdKey());
if (aSessionID == null) {
aSession = anApplication._initializeSessionInContext(aContext);
if (aSession == null)
errorResponse = anApplication.handleSessionCreationErrorInContext(aContext);
} else {
aSession = anApplication.restoreSessionWithID(aSessionID, aContext);
if (aSession == null) {
errorResponse = anApplication.handleSessionRestorationErrorInContext(aContext);
}
}
if (errorResponse == null) {
aResponse = _dispatchWithPreparedSession(aSession, aContext, someElements);
} else
aResponse = errorResponse;
aContext._putAwakeComponentsToSleep();
anApplication.saveSessionForContext(aContext);
return aResponse;
}
use of com.webobjects.appserver.WOResponse in project wonder-slim by undur.
the class ERXWOTextField method appendToResponse.
/**
* Overridden to make output XML compatible.
*/
@Override
public void appendToResponse(WOResponse woresponse, WOContext wocontext) {
WOResponse newResponse = ERXPatcher.DynamicElementsPatches.cleanupXHTML ? new WOResponse() : woresponse;
super.appendToResponse(newResponse, wocontext);
ERXPatcher.DynamicElementsPatches.processResponse(this, newResponse, wocontext, 0, nameInContext(wocontext, wocontext.component()));
if (ERXPatcher.DynamicElementsPatches.cleanupXHTML) {
woresponse.appendContentString(newResponse.contentString());
}
}
Aggregations