当前位置: 首页>>代码示例>>Java>>正文


Java Exceptions.findLocalizedMessage方法代码示例

本文整理汇总了Java中org.openide.util.Exceptions.findLocalizedMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Exceptions.findLocalizedMessage方法的具体用法?Java Exceptions.findLocalizedMessage怎么用?Java Exceptions.findLocalizedMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.util.Exceptions的用法示例。


在下文中一共展示了Exceptions.findLocalizedMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadOnlyFile

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testReadOnlyFile() throws Exception {
    clearWorkDir();
    File f = new File(getWorkDir(), "read-only.txt");
    f.createNewFile();
    FileObject fo = FileUtil.toFileObject(f);
    f.setWritable(false);
    try {
        OutputStream os = fo.getOutputStream();
        fail("Can't get the output stream for read-only file: " + os);
    } catch (IOException ex) {
        String msg = Exceptions.findLocalizedMessage(ex);
        assertNotNull("The exception comes with a localized message", msg);
    } finally {
        f.setWritable(true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FileObjTest.java

示例2: save

import org.openide.util.Exceptions; //导入方法依赖的package包/类
/** Tries to save given data object using its save cookie.
 * Notifies user if excetions appear.
 */
private void save (Savable sc) {
    try {
        if (sc != null) {
            sc.save();
        }
        // only remove the object if the save succeeded
        listModel.removeElement(sc);
    } catch (java.io.IOException exc) {
        Throwable t = exc;
        if (Exceptions.findLocalizedMessage(exc) == null) {
            t = Exceptions.attachLocalizedMessage(exc,
                                              NbBundle.getBundle(ExitDialog.class).getString("EXC_Save"));
        }
        Exceptions.printStackTrace(t);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ExitDialog.java

示例3: testDoNotLoadInvalidProject

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testDoNotLoadInvalidProject() throws Exception {
    String content = projdir.getFileObject("nbproject/project.xml").asText("UTF-8");
    TestFileUtils.writeFile(projdir, "nbproject/project.xml", content.replace("</project>", "<bogus/>\n</project>"));
    try {
        ProjectManager.getDefault().findProject(projdir);
        fail("should not have successfully loaded an invalid project.xml");
    } catch (IOException x) {
        assertTrue(x.toString(), x.getMessage().contains("bogus"));
        // #142079: use simplified error message.
        String loc = Exceptions.findLocalizedMessage(x);
        assertNotNull(loc);
        assertTrue(loc, loc.contains("bogus"));
        assertTrue(loc, loc.contains("project.xml"));
        // Probably should not assert exact string, as this is dependent on parser.
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AntBasedProjectFactorySingletonTest.java

示例4: testAttachLocalizedMessageForWeirdException

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testAttachLocalizedMessageForWeirdException() {
    class WeirdEx extends Exception {
        public WeirdEx(String message) {
            super(message);
        }

        @Override
        public Throwable getCause() {
            return null;
        }
    }

    Exception e = new WeirdEx("Help");
    String msg = "me please";

    Exception expResult = e;
    Exception result = Exceptions.attachMessage(e, msg);
    assertEquals(expResult, result);

    String fnd = Exceptions.findLocalizedMessage(e);

    assertEquals("No localized msg found", null, fnd);

    assertCleanStackTrace(e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ExceptionsTest.java

示例5: inputStream

import org.openide.util.Exceptions; //导入方法依赖的package包/类
@Messages({"# {0} - URL", "ViewConfigAction_could_not_connect=Could not retrieve: {0}"})
@Override public InputStream inputStream() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        URLConnection conn = new ConnectionBuilder().homeURL(new URL(home)).url(url).connection();
        InputStream is = conn.getInputStream();
        try {
            FileUtil.copy(is, baos);
        } finally {
            is.close();
        }
    } catch (IOException x) {
        if (Exceptions.findLocalizedMessage(x) == null) {
            Exceptions.attachLocalizedMessage(x, ViewConfigAction_could_not_connect(url));
        }
        throw x;
    }
    return new ByteArrayInputStream(baos.toByteArray());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ViewConfigAction.java

示例6: nodeRename

import org.openide.util.Exceptions; //导入方法依赖的package包/类
static void nodeRename(final Node n, final String newStr) {
    // bugfix #21589 don't update name if there is not any change
    if (n.getName().equals(newStr)) {
        return;
    }
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                nodeRename(n, newStr);
            }
        });
        return;
    }
    try {
        n.setName(newStr);
    } catch (IllegalArgumentException exc) {
        boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;

        // annotate new localized message only if there is no localized message yet
        if (needToAnnotate) {
            String msg = NbBundle.getMessage(
                    TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr
                );
            Exceptions.attachLocalizedMessage(exc, msg);
        }

        Exceptions.printStackTrace(exc);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ViewUtil.java

示例7: notifyUser

import org.openide.util.Exceptions; //导入方法依赖的package包/类
/**
 * Tries to find an annotation with localized message(primarily) or general
 * message in all exception annotations. If the annotation with the message
 * is found it is notified with original severity. If the message is not
 * found the exception is notified with informational severity.
 *
 * @param e exception to notify
 */
private static void notifyUser(Exception e) {
    String userMessage = Exceptions.findLocalizedMessage(e);

    if (userMessage != null) {
        Exceptions.printStackTrace(e);
    } else {
        // if there is not user message don't bother user, just log an
        // exception
        Logger.getLogger(PropertyDialogManager.class.getName()).log(Level.INFO, null, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:PropertyDialogManager.java

示例8: setState

import org.openide.util.Exceptions; //导入方法依赖的package包/类
/**
 * A setter that should be used by the property editor
 * to change the state of the environment.
 * Even the state property is bound, changes made from the editor itself
 * are allowed without restrictions.
 */
public void setState(Object newState) {
    if (getState().equals(newState)) {
        // no change, no fire vetoable and property change
        return;
    }

    try {
        getSupport().fireVetoableChange(PROP_STATE, getState(), newState);
        state = newState;

        // always notify state change
        getChange().firePropertyChange(PROP_STATE, null, newState);
    } catch (PropertyVetoException pve) {
        // and notify the user that the change cannot happen
        String msg = Exceptions.findLocalizedMessage(pve);
        if (msg == null) {
            msg = pve.getLocalizedMessage();
        }
        if (msg != null) {
            DialogDisplayer.getDefault().notify(
                    new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE));
        } else { // no message for the user, log the exception the standard way
            PropertyDialogManager.notify(pve);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:PropertyEnv.java

示例9: testAttachLocalizedMessage

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testAttachLocalizedMessage() {
    Exception e = new Exception("Help");
    String msg = "me please";
    
    Exception expResult = e;
    Exception result = Exceptions.attachLocalizedMessage(e, msg);
    assertEquals(expResult, result);

    String fnd = Exceptions.findLocalizedMessage(e);

    assertEquals("The same msg", msg, fnd);

    assertCleanStackTrace(e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ExceptionsTest.java

示例10: testAttachLocalizedMessageForClassNFE

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testAttachLocalizedMessageForClassNFE() {
    Exception e = new ClassNotFoundException("Help");
    String msg = "me please";
    
    Exception expResult = e;
    Exception result = Exceptions.attachLocalizedMessage(e, msg);
    assertEquals(expResult, result);

    String fnd = Exceptions.findLocalizedMessage(e);

    assertEquals("The same msg", msg, fnd);

    assertCleanStackTrace(e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ExceptionsTest.java

示例11: testAttachLocalizedMessageForClassNFEIfNoMsg

import org.openide.util.Exceptions; //导入方法依赖的package包/类
public void testAttachLocalizedMessageForClassNFEIfNoMsg() {
    Exception e = new ClassNotFoundException("Help");
    String msg = "me please";
    
    Exception expResult = e;
    Exception result = Exceptions.attachMessage(e, msg);
    assertEquals(expResult, result);

    String fnd = Exceptions.findLocalizedMessage(e);

    assertEquals("No localized msg found", null, fnd);

    assertCleanStackTrace(e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ExceptionsTest.java

示例12: performAction

import org.openide.util.Exceptions; //导入方法依赖的package包/类
protected void performAction(final Node[] activatedNodes) {
    if (activatedNodes == null || activatedNodes.length == 0) {
        return;
    }
    Node n = activatedNodes[0]; // we supposed that one node is activated
    
    // for slow FS perform rename out of EDT
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                performAction(activatedNodes);
            }
        });
        return;
    }

    NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
            NbBundle.getMessage(RenameAction.class, "CTL_RenameLabel"),
            NbBundle.getMessage(RenameAction.class, "CTL_RenameTitle")
        );
    dlg.setInputText(n.getName());

    if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
        String newname = null;

        try {
            newname = dlg.getInputText();

            if (!newname.equals("")) {
                n.setName(dlg.getInputText()); // NOI18N
            }
        } catch (IllegalArgumentException e) {
            // determine if "printStackTrace"  and  "new annotation" of this exception is needed
            boolean needToAnnotate = Exceptions.findLocalizedMessage(e) == null;

            // annotate new localized message only if there is no localized message yet
            if (needToAnnotate) {
                Exceptions.attachLocalizedMessage(e,
                                                  NbBundle.getMessage(RenameAction.class,
                                                                      "MSG_BadFormat",
                                                                      n.getName(),
                                                                      newname));
            }

            Exceptions.printStackTrace(e);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:RenameAction.java


注:本文中的org.openide.util.Exceptions.findLocalizedMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。