Example usage for java.lang SecurityException toString

List of usage examples for java.lang SecurityException toString

Introduction

In this page you can find the example usage for java.lang SecurityException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.vuze.android.remote.fragment.FilesFragment.java

@SuppressWarnings("unused")
protected boolean reallyStreamFile(Map<?, ?> selectedFile) {
    final String contentURL = getContentURL(selectedFile);
    if (contentURL != null && contentURL.length() > 0) {
        Uri uri = Uri.parse(contentURL);

        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        String name = MapUtils.getMapString(selectedFile, "name", "video");
        intent.putExtra("title", name);

        String extension = MimeTypeMap.getFileExtensionFromUrl(contentURL).toLowerCase(Locale.US);
        String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mimetype != null && tryLaunchWithMimeFirst) {
            intent.setType(mimetype);/*from  w  w  w . j  a v a 2 s. c  o  m*/
        }
        Class<?> fallBackIntentClass = VideoViewer.class;
        if (mimetype != null && mimetype.startsWith("image")) {
            fallBackIntentClass = ImageViewer.class;
        }

        final PackageManager packageManager = getActivity().getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (AndroidUtils.DEBUG) {
            Log.d(TAG, "num intents " + list.size());
            for (ResolveInfo info : list) {
                ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                Log.d(TAG, info.toString() + "/"
                        + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo)));
            }
        }
        if (list.size() == 0) {
            // Intent will launch, but show message to the user:
            // "Opening web browser links is not supported"
            intent.setClass(getActivity(), fallBackIntentClass);
        }
        if (list.size() == 1) {
            ResolveInfo info = list.get(0);
            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
            if (componentInfo != null && componentInfo.name != null) {
                if ("com.amazon.unifiedshare.actionchooser.BuellerShareActivity".equals(componentInfo.name)
                        || componentInfo.name.startsWith("com.google.android.tv.frameworkpackagestubs.Stubs")) {
                    intent.setClass(getActivity(), fallBackIntentClass);
                }
            }
        }

        try {
            startActivity(intent);
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "Started " + uri + " MIME: " + intent.getType());
            }
        } catch (java.lang.SecurityException es) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "ERROR launching. " + es.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }

                    list = packageManager.queryIntentActivities(intent2, PackageManager.MATCH_DEFAULT_ONLY);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "num intents " + list.size());
                        for (ResolveInfo info : list) {
                            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                            Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null"
                                    : (componentInfo.name + "/" + componentInfo)));
                        }
                    }

                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG,
                                "Started with" + (intent2.getType() == null ? " no" : " ") + " mime: " + uri);
                    }
                    return true;
                } catch (Throwable ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.intent_security_fail), Toast.LENGTH_LONG)
                    .show();
        } catch (android.content.ActivityNotFoundException ex) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "no intent for view. " + ex.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }
                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "Started (no mime set) " + uri);
                    }
                    return true;
                } catch (android.content.ActivityNotFoundException ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.no_intent), Toast.LENGTH_SHORT).show();
        }
        return true;
    }

    return true;
}

From source file:com.hp.hpl.jena.grddl.impl.GRDDL.java

private Transformer transformerFor(final String url) throws TransformerException {
    if (url.equals("RDF/XML")) {
        return xformFactory().newTransformer();
    } else {// w  w  w .j a v  a2 s  .com
        logurl(url);
        try {
            ((GRDDLReaderBase) reader).lastSecurityException = null;
            final Transformer rslt[] = { null };
            // TODO  network and source issues
            final Source src = xsltStreamSource(url);
            runInSandbox(new TERunnable() {
                public void run() throws TransformerException {
                    rslt[0] = xformFactory().newTransformer(src);
                }

            }, true);

            SafeURIResolver safeURIResolver = new SafeURIResolver();
            rslt[0].setURIResolver(safeURIResolver);
            ((Controller) rslt[0]).setUnparsedTextURIResolver(safeURIResolver);

            return rslt[0];

        }
        //         catch (AssertionError e) {
        //            if (e.getMessage().startsWith("Failed to load system function: unparsed-text()"))
        //               throw new GRDDLSecurityException("unparsed-text() not permitted in this implementation");
        //              throw e;
        //         }
        catch (SecurityException e) {
            throw new GRDDLSecurityException(e);
        } catch (TransformerException e) {
            //            if (e.toString().contains("result-document")
            //               || e.toString().contains("disabled")
            //               || e.toString().contains("extension") )
            //               throw new GRDDLSecurityException(e);
            if (((GRDDLReaderBase) reader).lastSecurityException != null)
                throw ((GRDDLReaderBase) reader).lastSecurityException;
            System.err.println("<" + url + "> A.Rethrowing " + e.getMessage());
            throw e;

        } catch (RuntimeException e) {
            System.err.println("<" + url + "> B.Rethrowing " + e.toString() + ":" + e.getMessage());
            throw e;
        }
    }
}

From source file:org.chromium.android_webview.test.AwSettingsTest.java

static void assertFileIsReadable(String filePath) {
    File file = new File(filePath);
    try {// www  .  j  ava2 s . co m
        assertTrue("Test file \"" + filePath + "\" is not readable."
                + "Please make sure that files from android_webview/test/data/device_files/ "
                + "has been pushed to the device before testing", file.canRead());
    } catch (SecurityException e) {
        fail("Got a SecurityException for \"" + filePath + "\": " + e.toString());
    }
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private ParcelFileDescriptor startVPN(Builder builder) throws SecurityException {
    try {//w ww .  ja v a 2 s.c o  m
        return builder.establish();
    } catch (SecurityException ex) {
        throw ex;
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        return null;
    }
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Open the document with external viewer.
 *
 * @param externalLink Document to open//  w w w .  j ava 2s .c  o  m
 */
public void doExternal(String externalLink) {
    logger.debug("doExternal('" + externalLink + "') entered");

    String lowerL = externalLink.toLowerCase();

    // is link home or result?
    if (externalLink.equals("home") || externalLink.equals("results")) {
        showMessage(I18n.getString("not_externally_viewable"),
                I18n.getString("not_externally_viewable_message"));
        return;
    }

    // get handler of link
    String app = new DocTypeHandlerUtils().hasHandler(handlerList, externalLink);

    // special handling of file
    if (lowerL.startsWith("file:/")) {
        // remove "file:/"
        externalLink = externalLink.substring(6, externalLink.length());

        // handle of / and win32
        if (OSType.WIN_32 == env.getOSType()) {
            // replace all / with \
            externalLink = Utils.replaceAll("/", externalLink, "\\");
        }
    }

    // special handling of http
    if (lowerL.startsWith("http")) {
        // replace whitespace with %20
        externalLink = Utils.replaceAll(" ", externalLink, "%20");
    }

    // handler found and not http
    if (app.equals("") || lowerL.startsWith("http")) {
        app = defaultHndlr;
    } else {
        logger.debug("doExternal() using user specified handler '" + app + "'");
    }

    // open external application with file or link
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("doExternal() Executing runtime command " + Layout.LINE_SEP + "application=" + app
                    + Layout.LINE_SEP + "file=" + externalLink);
        }

        // status bar
        setStatus(app + " " + externalLink);

        // build command
        String[] cmdArray = new String[2];
        cmdArray[0] = app;
        cmdArray[1] = externalLink;

        // exec comman
        Runtime.getRuntime().exec(cmdArray);
    } catch (SecurityException se) {
        showMessage(I18n.getString("error"), "\n" + app + " " + externalLink + "\n" + se.toString());
    } catch (IOException ioe) {
        showMessage(I18n.getString("error"), "\n" + app + " " + externalLink + "\n" + ioe.toString());
    }
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Handle's main GUI events//from ww w  .j  a va2  s . c  om
 */
public void handleEventCommand(String s) {
    logger.debug("handleEventCommand('" + s + "') entered");

    try {
        // we run validation in a thread so as not to interfere
        // with repaints of GUI
        if (s.equals("ac_exit")) {
            doExit();
        } else if (s.equals("ac_makecd")) {
            doSearchableCdWiz();
        } else if (s.equals("ac_settings")) {
            doHandlers();
        } else if (s.equals("ac_newspiderindex")) {
            doNewSpiderIdx();
        } else if (s.equals("ac_refresh")) {
            setPage(curPage);
        } else if (s.equals("ac_metadata_report")) {
            doMetaReport();
        } else if (s.equals("ac_servlet_log_report")) {
            getSeachLogReport();
        } else if (s.equals("ac_about")) {
            showMessage(I18n.getString("windowtitle.about"), I18n.getString("version") + " "
                    + I18n.getString("ds.version") + "\n\n" + I18n.getString("windowcontent.about"));
        } else if (s.equals("ac_open")) {
            doOpen();
        } else if (s.equals("ac_save")) {
            doSave();
        } else if (s.equals("ac_print")) {
            doPrint();
        } else if (s.equals("ac_search_tips")) {
            showMessage(I18n.getString("windowtitle.search_tips"), I18n.getString("windowcontent.search_tips"));
        } else if (s.equals("ac_openinbrowser")) {
            doExternal(curPage);
        } else if (s.equals("ac_newindex")) {
            doNewIndex();
        } else if (s.equals("ac_rebuildindexes")) {
            rebuildIndexes();
        } else if (s.equals("ac_stop")) {
            doStop();
        } else if (s.equals("ac_search")) {
            doThreadedSearch();
        } else if (s.equals("ac_manageindex")) {
            doManageIndexes();
        } else if (s.equals("ac_importindex")) {
            getImportInfo();
        } else if (s.equals("ac_addbookmark")) {
            doBookmark();
        } else if (s.equals("ac_deleteallbookmarks")) {
            // TODO extra method
            bookmarksList.clear();
            File bmf = new File(fEnv.getBookmarkFile());
            boolean wasCleared = true;
            String errString = null;
            if (bmf.exists()) {
                try {
                    if (!bmf.delete()) {
                        wasCleared = false;
                        errString = "Bookmarks not deleted";
                    }
                } catch (SecurityException se) {
                    logger.fatal("handleEventCommand() failed with SecurityException", se);
                    wasCleared = false;
                    errString = se.toString();
                }
            }

            if (!wasCleared) {
                showMessage(I18n.getString("error_remove_bookmarks"), errString);
            } else {
                showMessage(I18n.getString("bookmarks_cleared"), I18n.getString("bookmarks_cleared_info"));
            }
        } else if (s.equals("ac_result")) {
            editorPane.setContentType("text/html");
            editorPane.setText(lastSearch);
            editorPane.select(0, 0);

            curPage = "results";
        } else if (s.equals("ac_home")) {
            editorPane.setContentType("text/html");
            if (hasStartPage) {
                if (!setPage("home")) {
                    // error message
                    // TODO better error message
                    editorPane.setText(errString);
                }

                curPage = "home";
            } else {
                editorPane.setText(lastSearch);
                editorPane.select(0, 0);
                curPage = "results";
            }
        } else {
            if (s.startsWith("file:/") || s.startsWith("http")) {
                setPage(s);
            }
        }
    } catch (Exception e) {
        logger.error("handleEventCommand() action thread was stopped!", e);
    }
}