use of com.webobjects.foundation.NSMutableArray in project wonder-slim by undur.
the class ERXExceptionUtilities method _printSingleStackTrace.
private static void _printSingleStackTrace(Throwable t, PrintWriter writer, int exceptionDepth, boolean cleanupStackTrace) {
NSArray<Pattern> skipPatterns = ERXExceptionUtilities._skipPatterns;
if (cleanupStackTrace && skipPatterns == null) {
String skipPatternsFile = ERXProperties.stringForKey("er.extensions.stackTrace.skipPatternsFile");
if (skipPatternsFile != null) {
NSMutableArray<Pattern> mutableSkipPatterns = new NSMutableArray<>();
Enumeration<String> frameworksEnum = ERXLocalizer.frameworkSearchPath().reverseObjectEnumerator();
while (frameworksEnum.hasMoreElements()) {
String framework = frameworksEnum.nextElement();
URL path = WOApplication.application().resourceManager().pathURLForResourceNamed(skipPatternsFile, framework, null);
if (path != null) {
try {
NSArray<String> skipPatternStrings = (NSArray<String>) ERXUtilities.readPropertyListFromFileInFramework(skipPatternsFile, framework, (NSArray) null, "utf-8");
if (skipPatternStrings != null) {
for (String skipPatternString : skipPatternStrings) {
try {
mutableSkipPatterns.addObject(Pattern.compile(skipPatternString));
} catch (Throwable patternThrowable) {
log.error("Skipping invalid exception pattern '{}' in '{}' in the framework '{}' ({})", skipPatternString, skipPatternsFile, framework, ERXExceptionUtilities.toParagraph(patternThrowable));
}
}
}
} catch (Throwable patternThrowable) {
log.error("Failed to read pattern file '{}' in the framework '{}' ({})", skipPatternsFile, framework, ERXExceptionUtilities.toParagraph(patternThrowable));
}
}
}
skipPatterns = mutableSkipPatterns;
}
if (ERXProperties.booleanForKeyWithDefault("er.extensions.stackTrace.cachePatterns", true)) {
if (skipPatterns == null) {
ERXExceptionUtilities._skipPatterns = NSArray.EmptyArray;
} else {
ERXExceptionUtilities._skipPatterns = skipPatterns;
}
}
}
StackTraceElement[] elements = t.getStackTrace();
indent(writer, exceptionDepth);
if (exceptionDepth > 0) {
writer.print("Caused by a ");
}
if (cleanupStackTrace) {
writer.print(t.getClass().getSimpleName());
} else {
writer.print(t.getClass().getName());
}
String message = t.getLocalizedMessage();
if (message != null) {
writer.print(": ");
writer.print(message);
}
writer.println();
int stackDepth = 0;
int skippedCount = 0;
for (StackTraceElement element : elements) {
boolean showElement = true;
if (stackDepth > 0 && cleanupStackTrace && skipPatterns != null && !skipPatterns.isEmpty()) {
String elementName = element.getClassName() + "." + element.getMethodName();
for (Pattern skipPattern : skipPatterns) {
if (skipPattern.matcher(elementName).matches()) {
showElement = false;
break;
}
}
}
if (!showElement) {
skippedCount++;
} else {
if (skippedCount > 0) {
indent(writer, exceptionDepth + 1);
writer.println(" ... skipped " + skippedCount + " stack elements");
skippedCount = 0;
}
indent(writer, exceptionDepth + 1);
writer.print("at ");
writer.print(element.getClassName());
writer.print(".");
writer.print(element.getMethodName());
writer.print("(");
if (element.isNativeMethod()) {
writer.print("Native Method");
} else if (element.getLineNumber() < 0) {
writer.print(element.getFileName());
writer.print(":Unknown");
} else {
writer.print(element.getFileName());
writer.print(":");
writer.print(element.getLineNumber());
}
writer.print(")");
writer.println();
}
stackDepth++;
}
if (skippedCount > 0) {
indent(writer, exceptionDepth + 1);
writer.println("... skipped " + skippedCount + " stack elements");
}
}
use of com.webobjects.foundation.NSMutableArray in project wonder-slim by undur.
the class WOHTMLWebObjectTag method template.
public WOElement template() {
NSMutableArray nsmutablearray = null;
if (_children == null) {
return null;
}
Enumeration enumeration = _children.objectEnumerator();
if (enumeration != null) {
nsmutablearray = new NSMutableArray(_children.count());
StringBuilder stringbuffer = new StringBuilder(128);
while (enumeration.hasMoreElements()) {
Object obj1 = enumeration.nextElement();
if (obj1 instanceof String) {
stringbuffer.append((String) obj1);
} else {
if (stringbuffer.length() > 0) {
WOHTMLBareString wohtmlbarestring1 = new WOHTMLBareString(stringbuffer.toString());
nsmutablearray.addObject(wohtmlbarestring1);
stringbuffer.setLength(0);
}
nsmutablearray.addObject(obj1);
}
}
if (stringbuffer.length() > 0) {
WOHTMLBareString wohtmlbarestring = new WOHTMLBareString(stringbuffer.toString());
stringbuffer.setLength(0);
nsmutablearray.addObject(wohtmlbarestring);
}
}
WOElement obj = null;
if (nsmutablearray != null && nsmutablearray.count() == 1) {
Object obj2 = nsmutablearray.objectAtIndex(0);
if (obj2 instanceof WOComponentReference) {
obj = new WODynamicGroup(_name, null, (WOElement) obj2);
} else {
obj = (WOElement) obj2;
}
} else {
obj = new WODynamicGroup(_name, null, nsmutablearray);
}
return obj;
}
use of com.webobjects.foundation.NSMutableArray in project wonder-slim by undur.
the class ERXComponentUtilities method componentTree.
/**
* Returns an array of the current component names.
*
* @return array of current component names
*/
public static NSArray<String> componentTree() {
WOContext context = ERXWOContext.currentContext();
NSMutableArray<String> result = new NSMutableArray<>();
if (context != null) {
WOComponent c = context.component();
while (c != null) {
result.addObject(c.name());
c = c.parent();
}
}
return result;
}
use of com.webobjects.foundation.NSMutableArray in project wonder-slim by undur.
the class WOExceptionParser method _parseException.
private void _parseException() {
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter(sWriter, false);
String string;
NSArray lines;
NSArray ignoredPackage;
WOParsedErrorLine aLine;
String line;
int i, size;
try {
_exception.printStackTrace(pWriter);
pWriter.close();
// Added the try/catch as this throws in JDK 1.2
sWriter.close();
// aB.
string = sWriter.toString();
// We skip the name of the
i = _exception.toString().length();
// our parse
if (string.length() > i + 2) {
// certain errors don't contain a
// stack trace
// Skip the exception type and
string = string.substring(i + 2);
// message
lines = NSArray.componentsSeparatedByString(string, "\n");
ignoredPackage = _ignoredPackages();
size = lines.count();
_stackTrace = new NSMutableArray(size);
for (i = 0; i < size; i++) {
line = ((String) lines.objectAtIndex(i)).trim();
if (line.startsWith("at ")) {
// If we don't have an open parenthesis it means that we
// have probably reach the latest stack trace.
aLine = new WOParsedErrorLine(line);
_verifyPackageForLine(aLine, ignoredPackage);
_stackTrace.add(aLine);
}
}
}
} catch (Throwable e) {
NSLog.err.appendln("WOExceptionParser - exception collecting backtrace data " + e + " - Empty backtrace.");
NSLog.err.appendln(e);
}
if (_stackTrace == null) {
_stackTrace = new NSMutableArray();
}
}
use of com.webobjects.foundation.NSMutableArray in project wonder-slim by undur.
the class WOExceptionParser method _ignoredPackages.
private NSArray _ignoredPackages() {
NSBundle bundle;
String path, content;
NSDictionary dic = null;
NSMutableArray<NSBundle> allBundles = new NSMutableArray<>(NSBundle.frameworkBundles());
NSMutableArray<String> ignored = new NSMutableArray<>();
for (Enumeration enumerator = allBundles.objectEnumerator(); enumerator.hasMoreElements(); ) {
bundle = (NSBundle) enumerator.nextElement();
path = WOApplication.application().resourceManager().pathForResourceNamed("WOIgnoredPackage.plist", bundle.name(), null);
if (path != null) {
content = _stringFromFileSafely(path);
if (content != null) {
dic = (NSDictionary) NSPropertyListSerialization.propertyListFromString(content);
if (dic != null && dic.containsKey("ignoredPackages")) {
@SuppressWarnings("unchecked") NSArray<String> tmpArray = (NSArray<String>) dic.objectForKey("ignoredPackages");
if (tmpArray != null && tmpArray.count() > 0) {
ignored.addObjectsFromArray(tmpArray);
}
}
}
}
}
return ignored;
}
Aggregations