// Path: node-projects/src/main/java/org/netbeans/modules/nodejs/json/SimpleJSONParser.java
// public static final class JsonException extends Exception {
//     private final char what;
//     private final int position;
// 
//     JsonException ( String msg, char what, int line, int position, Throwable cause ) {
//         super( "Illegal JSON at line " + line + " offset " + position + " with character '" + what + "': " + msg, cause );
//         this.what = what;
//         this.position = position;
//     }
// 
//     JsonException ( String msg, char what, int line, int position ) {
//         super( "Illegal JSON at line " + line + " offset " + position + " with character '" + what + "': " + msg );
//         this.what = what;
//         this.position = position;
//     }
// }


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import org.netbeans.modules.nodejs.json.SimpleJSONParser.JsonException;
import org.openide.filesystems.FileObject;
import org.openide.util.NbCollections;
/* Copyright (C) 2012 Tim Boudreau

 Permission is hereby granted, free of charge, to any person obtaining a copy 
 of this software and associated documentation files (the "Software"), to 
 deal in the Software without restriction, including without limitation the 
 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 sell copies of the Software, and to permit persons to whom the Software is 
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all 
 copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package org.netbeans.modules.nodejs.json;


public final class JsonPanel extends JPanel {
    public JsonPanel ( FileObject fo ) throws JsonException, IOException {
        this( parse( fo ), null );
    }

    private static Map<String, Object> parse ( FileObject fo ) throws FileNotFoundException, IOException {
        InputStream in = fo.getInputStream();
        try {
            return NbCollections.checkedMapByFilter( ObjectMapperProvider.newObjectMapper().readValue( in, Map.class ), String.class, Object.class, false );
        } catch ( Exception e ) {
            Logger.getLogger( JsonPanel.class.getName() ).log( Level.WARNING, "Bad json in " + fo.getPath(), e );
            in = fo.getInputStream();
            try {
                try {
                    return new SimpleJSONParser( true ).parse( in );
// Path: node-projects/src/main/java/org/netbeans/modules/nodejs/json/SimpleJSONParser.java
// public static final class JsonException extends Exception {
//     private final char what;
//     private final int position;
// 
//     JsonException ( String msg, char what, int line, int position, Throwable cause ) {
//         super( "Illegal JSON at line " + line + " offset " + position + " with character '" + what + "': " + msg, cause );
//         this.what = what;
//         this.position = position;
//     }
// 
//     JsonException ( String msg, char what, int line, int position ) {
//         super( "Illegal JSON at line " + line + " offset " + position + " with character '" + what + "': " + msg );
//         this.what = what;
//         this.position = position;
//     }
// }


// Path: node-projects/src/main/java/org/netbeans/modules/nodejs/json/JsonPanel.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import org.netbeans.modules.nodejs.json.SimpleJSONParser.JsonException;
import org.openide.filesystems.FileObject;
import org.openide.util.NbCollections;

/* Copyright (C) 2012 Tim Boudreau

 Permission is hereby granted, free of charge, to any person obtaining a copy 
 of this software and associated documentation files (the "Software"), to 
 deal in the Software without restriction, including without limitation the 
 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 sell copies of the Software, and to permit persons to whom the Software is 
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all 
 copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package org.netbeans.modules.nodejs.json;


public final class JsonPanel extends JPanel {
    public JsonPanel ( FileObject fo ) throws JsonException, IOException {
        this( parse( fo ), null );
    }

    private static Map<String, Object> parse ( FileObject fo ) throws FileNotFoundException, IOException {
        InputStream in = fo.getInputStream();
        try {
            return NbCollections.checkedMapByFilter( ObjectMapperProvider.newObjectMapper().readValue( in, Map.class ), String.class, Object.class, false );
        } catch ( Exception e ) {
            Logger.getLogger( JsonPanel.class.getName() ).log( Level.WARNING, "Bad json in " + fo.getPath(), e );
            in = fo.getInputStream();
            try {
                try {
                    return new SimpleJSONParser( true ).parse( in );
                } catch ( JsonException ex ) {