Search in sources :

Example 1 with NSMutableArray

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");
    }
}
Also used : Pattern(java.util.regex.Pattern) NSArray(com.webobjects.foundation.NSArray) URL(java.net.URL) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Example 2 with NSMutableArray

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;
}
Also used : Enumeration(java.util.Enumeration) NSMutableArray(com.webobjects.foundation.NSMutableArray) WODynamicGroup(com.webobjects.appserver._private.WODynamicGroup) WOHTMLBareString(com.webobjects.appserver._private.WOHTMLBareString) WOHTMLBareString(com.webobjects.appserver._private.WOHTMLBareString) WOComponentReference(com.webobjects.appserver._private.WOComponentReference) WOElement(com.webobjects.appserver.WOElement)

Example 3 with NSMutableArray

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;
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) NSMutableArray(com.webobjects.foundation.NSMutableArray) WOContext(com.webobjects.appserver.WOContext) ERXWOContext(er.extensions.appserver.ERXWOContext)

Example 4 with NSMutableArray

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();
    }
}
Also used : StringWriter(java.io.StringWriter) NSArray(com.webobjects.foundation.NSArray) NSMutableArray(com.webobjects.foundation.NSMutableArray) PrintWriter(java.io.PrintWriter)

Example 5 with 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;
}
Also used : NSBundle(com.webobjects.foundation.NSBundle) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSDictionary(com.webobjects.foundation.NSDictionary) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Aggregations

NSMutableArray (com.webobjects.foundation.NSMutableArray)35 NSArray (com.webobjects.foundation.NSArray)13 Enumeration (java.util.Enumeration)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)6 WOComponent (com.webobjects.appserver.WOComponent)4 WOElement (com.webobjects.appserver.WOElement)3 WODynamicGroup (com.webobjects.appserver._private.WODynamicGroup)3 WOHTMLBareString (com.webobjects.appserver._private.WOHTMLBareString)3 NSBundle (com.webobjects.foundation.NSBundle)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 WOComponentReference (com.webobjects.appserver._private.WOComponentReference)2 NSComparator (com.webobjects.foundation.NSComparator)2 ERXLocalizer (er.extensions.localization.ERXLocalizer)2 File (java.io.File)2 Level (org.apache.log4j.Level)2 Logger (org.apache.log4j.Logger)2 WOActionResults (com.webobjects.appserver.WOActionResults)1 WOContext (com.webobjects.appserver.WOContext)1 WOEvent (com.webobjects.appserver.WOEvent)1