use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionDeclarationParser method _rawDeclarationsWithoutComment.
private NSMutableDictionary _rawDeclarationsWithoutComment(String declarationStr) {
NSMutableDictionary declarations = new NSMutableDictionary();
StringBuilder declarationWithoutCommentBuffer = new StringBuilder(100);
StringTokenizer tokenizer = new StringTokenizer(declarationStr, "{", true);
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken("{");
if (token.equals("{")) {
token = tokenizer.nextToken("}");
if (token.equals("}")) {
token = "";
} else {
tokenizer.nextToken();
}
String declarationWithoutComment = declarationWithoutCommentBuffer.toString();
if (declarationWithoutComment.startsWith(";")) {
declarationWithoutComment = declarationWithoutComment.substring(1);
}
declarations.setObjectForKey("{" + token + "}", declarationWithoutComment.trim());
declarationWithoutCommentBuffer.setLength(0);
} else {
declarationWithoutCommentBuffer.append(token);
}
}
} catch (NoSuchElementException e) {
log.debug("Failed to parse.", e);
}
return declarations;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class WOHelperFunctionDeclarationParser method _associationsForDictionaryString.
private NSMutableDictionary _associationsForDictionaryString(String declarationHeader, String declarationBody) throws WOHelperFunctionDeclarationFormatException {
NSMutableDictionary associations = new NSMutableDictionary();
String trimmedDeclarationBody = declarationBody.trim();
if (!trimmedDeclarationBody.startsWith("{") && !trimmedDeclarationBody.endsWith("}")) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Internal inconsistency : invalid dictionary for declaration:\n" + declarationHeader + " " + declarationBody);
}
int declarationBodyLength = trimmedDeclarationBody.length();
if (declarationBodyLength <= 2) {
return associations;
}
trimmedDeclarationBody = trimmedDeclarationBody.substring(1, declarationBodyLength - 1).trim();
NSArray bindings = NSArray.componentsSeparatedByString(trimmedDeclarationBody, ";");
Enumeration bindingsEnum = bindings.objectEnumerator();
do {
if (!bindingsEnum.hasMoreElements()) {
break;
}
String binding = ((String) bindingsEnum.nextElement()).trim();
if (binding.length() != 0) {
int equalsIndex = binding.indexOf('=');
if (equalsIndex < 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Invalid line. No equal in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
}
String key = binding.substring(0, equalsIndex).trim();
if (key.length() == 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing binding in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
}
String value = binding.substring(equalsIndex + 1).trim();
if (value.length() == 0) {
throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing value in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
}
WOAssociation association = WOHelperFunctionDeclarationParser._associationWithKey(value, _quotedStrings);
Object quotedString = _quotedStrings.objectForKey(key);
if (quotedString != null) {
associations.setObjectForKey(association, quotedString);
} else {
associations.setObjectForKey(association, key);
}
}
} while (true);
// }
return associations;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class ERXUtilities method informationForBundles.
private static NSMutableDictionary<String, Object> informationForBundles() {
NSMutableDictionary<String, Object> extraInfo = new NSMutableDictionary<>();
NSMutableDictionary<String, Object> bundleVersions = new NSMutableDictionary<String, Object>();
for (Enumeration bundles = NSBundle._allBundlesReally().objectEnumerator(); bundles.hasMoreElements(); ) {
NSBundle bundle = (NSBundle) bundles.nextElement();
String version = versionStringForFrameworkNamed(bundle.name());
if (version == null) {
version = "No version provided";
}
bundleVersions.setObjectForKey(version, bundle.name());
}
extraInfo.setObjectForKey(bundleVersions, "Bundles");
return extraInfo;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class ERXUtilities method informationForContext.
private static NSMutableDictionary<String, Object> informationForContext(WOContext context) {
NSMutableDictionary<String, Object> extraInfo = new NSMutableDictionary<>();
if (context != null) {
if (context.page() != null) {
extraInfo.setObjectForKey(context.page().name(), "CurrentPage");
if (context.component() != null) {
extraInfo.setObjectForKey(context.component().name(), "CurrentComponent");
if (context.component().parent() != null) {
extraInfo.setObjectForKey(ERXWOContext.componentPath(context), "CurrentComponentHierarchy");
}
}
// If this is a D2W component, get its D2W-related information
// from ERDirectToWeb.
NSSelector d2wSelector = new NSSelector("d2wContext");
if (d2wSelector.implementedByObject(context.page())) {
try {
Class erDirectToWebClazz = Class.forName("er.directtoweb.ERDirectToWeb");
NSSelector infoSelector = new NSSelector("informationForContext", new Class[] { WOContext.class });
NSDictionary d2wExtraInfo = (NSDictionary) infoSelector.invoke(erDirectToWebClazz, context);
extraInfo.addEntriesFromDictionary(d2wExtraInfo);
} catch (Exception e) {
}
}
}
if (context.request() != null) {
extraInfo.setObjectForKey(context.request().uri(), "URL");
if (context.request().headers() != null) {
NSMutableDictionary<String, Object> headers = new NSMutableDictionary<>();
for (Object key : context.request().headerKeys()) {
String value = context.request().headerForKey(key);
if (value != null) {
headers.setObjectForKey(value, key.toString());
}
}
extraInfo.setObjectForKey(headers, "Headers");
}
}
if (context.hasSession()) {
if (context.session().statistics() != null) {
extraInfo.setObjectForKey(context.session().statistics(), "PreviousPageList");
}
extraInfo.setObjectForKey(context.session(), "Session");
}
}
return extraInfo;
}
use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.
the class ERXStatsSummary method statsByType.
/**
* Gets the aggregate stats grouped by event type.
* @return the aggregate stats
*/
public NSDictionary statsByType() {
if (null == _statsByType) {
if (hasBinding("aggregateStats")) {
_statsByType = (NSDictionary) valueForBinding("aggregateStats");
} else {
NSMutableDictionary dict = new NSMutableDictionary();
NSArray<ERXStats.LogEntry> entries = ERXStats.aggregateLogEntries();
for (ERXStats.LogEntry logEntry : entries) {
String group = firstPropertyKeyInKeyPath(logEntry.key());
NSMutableArray eventsForType = (NSMutableArray) dict.objectForKey(group);
if (null == eventsForType) {
eventsForType = new NSMutableArray();
dict.setObjectForKey(eventsForType, group);
}
eventsForType.addObject(logEntry);
}
_statsByType = dict;
}
}
return _statsByType;
}
Aggregations