Example usage for org.apache.commons.logging Log isWarnEnabled

List of usage examples for org.apache.commons.logging Log isWarnEnabled

Introduction

In this page you can find the example usage for org.apache.commons.logging Log isWarnEnabled.

Prototype

boolean isWarnEnabled();

Source Link

Document

Is warn logging currently enabled?

Usage

From source file:net.sf.nmedit.nordmodular.NMSynthDeviceContext.java

public void openOrSelectPatch(Slot slot) {
    NmSlot nmslot = (NmSlot) slot;// ww  w  .j  a  v a 2  s.  c  om

    NMPatch patch = nmslot.getPatch();

    if (patch != null) {
        // find out if patch is open

        DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager();

        for (Document d : dm.getDocuments()) {
            if (d instanceof PatchDocument) {
                PatchDocument pd = (PatchDocument) d;
                if (pd.getPatch() == patch) {
                    // found -> select

                    dm.setSelection(d);

                    return;
                }
            }
        }

        // not found -> create document

        try {
            final PatchDocument pd = NmFileService.createPatchDoc(patch);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    DocumentManager dm = Nomad.sharedInstance().getDocumentManager();
                    dm.add(pd);
                    dm.setSelection(pd);

                }
            });

        } catch (Exception e) {

            Log log = LogFactory.getLog(getClass());
            if (log.isWarnEnabled()) {
                log.warn(e);
            }

            ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(),

                    e.getMessage(), "could not open patch", e);

            return;
        }

        return;
    }

    try {
        slot.createRequestPatchWorker().requestPatch();
    } catch (SynthException e1) {
        e1.printStackTrace();
    }
}

From source file:net.sf.nmedit.nomad.core.NomadLoader.java

public Nomad createNomad(final NomadPlugin plugin) {
    NomadLoader.plugin = plugin;/*from  w  w w.  j ava 2  s.c o  m*/

    // first get the boot progress callbeck
    final SplashHandler progress = Boot.getSplashHandler();
    // initializing ...
    progress.setText("Initializing Nomad...");
    progress.setProgress(0.1f);
    // now we read all property files
    // 1. nomad.properties
    final Properties nProperties = new Properties();
    getProperties(nProperties, Nomad.getCorePropertiesFile());

    RootSystemProperties sproperties = new RootSystemProperties(nProperties);
    SystemPropertyFactory.sharedInstance().setFactory(new NomadPropertyFactory(sproperties));

    // 1.2 init locale
    initLocale();
    // 1.4 menu layout configuration
    InputStream mlIn = null;
    try {
        ClassLoader loader = getClass().getClassLoader();
        mlIn = loader.getResourceAsStream("./MenuLayout.xml");

        menuLayout = MenuLayout.getLayout(new BufferedInputStream(mlIn));
    } catch (Exception e) {
        Log log = LogFactory.getLog(getClass());
        if (log.isFatalEnabled()) {
            log.fatal("could not read MenuLayout", e);
        }
        throw new RuntimeException(e);
    } finally {
        try {
            if (mlIn != null)
                mlIn.close();
        } catch (IOException e) {
            Log log = LogFactory.getLog(NomadLoader.class);
            if (log.isWarnEnabled()) {
                log.warn("closing menu layout", e);
            }
        }
    }
    // increase progress
    progress.setProgress(0.2f);
    // 1.5 initialize look and feel (important: before creating any swing components)

    String lafClassName = plugin.getDescriptor().getAttribute("javax.swing.LookAndFeel").getValue();
    String themeClassName = plugin.getDescriptor().getAttribute("javax.swing.plaf.metal.MetalTheme").getValue();
    String defaultLafOnPlatform = plugin.getDescriptor().getAttribute("nomad.plaf.usePlatformDefault")
            .getValue();

    initLookAndFeel(lafClassName, themeClassName, defaultLafOnPlatform);
    // 1.6 initialize main window's menu
    progress.setProgress(0.3f);

    /*     NomadActionControl nomadActions = new NomadActionControl( Nomad.sharedInstance() );
          nomadActions.installActions(menuBuilder);
      */
    progress.setProgress(0.5f);
    progress.setText("Initializing main window...");

    activatePlugins();

    progress.setText("Initializing services...");

    JPFServiceInstallerTool.activateAllServices(plugin);
    progress.setText("Starting Nomad...");

    // SwingUtilities.invokeLater(run);

    Nomad nomad = new Nomad(plugin, menuLayout);
    return nomad;
}

From source file:edu.vt.middleware.ldap.LdapTLSSocketFactory.java

/**
 * This returns a keystore as an <code>InputStream</code>. If the keystore
 * could not be loaded this method returns null.
 *
 * @param  filename  <code>String</code> to read
 * @param  pt  <code>PathType</code> how to read file
 *
 * @return  <code>InputStream</code> keystore
 *///  w  w  w . j  a  va  2  s.c o  m
private InputStream getInputStream(final String filename, final PathType pt) {
    final Log logger = LogFactory.getLog(LdapTLSSocketFactory.class);
    InputStream is = null;
    if (pt == PathType.CLASSPATH) {
        is = LdapTLSSocketFactory.class.getResourceAsStream(filename);
    } else if (pt == PathType.FILEPATH) {
        File file;
        try {
            file = new File(URI.create(filename));
        } catch (IllegalArgumentException e) {
            file = new File(filename);
        }
        try {
            is = new FileInputStream(file);
        } catch (IOException e) {
            if (logger.isWarnEnabled()) {
                logger.warn("Error loading keystore from " + filename, e);
            }
        }
    }
    if (is != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Successfully loaded " + filename + " from " + pt);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to load " + filename + " from " + pt);
        }
    }
    return is;
}

From source file:com.flexive.shared.exceptions.FxApplicationException.java

/**
 * Log a message at a given level (or error if no level given)
 *
 * @param log     Log to use/*from   ww w  . ja v  a  2s.  c o m*/
 * @param message message to LOG
 * @param level   log4j level to apply
 */
private void logMessage(Log log, String message, LogLevel level) {
    this.messageLogged = true;
    if (FxContext.get() != null && FxContext.get().isTestDivision())
        return; //dont log exception traces during automated tests
    final Throwable cause = getCause() != null ? getCause() : this;
    if (level == null)
        log.error(message, cause);
    else {
        switch (level) {
        case DEBUG:
            if (log.isDebugEnabled())
                log.debug(message);
            break;
        case ERROR:
            if (log.isErrorEnabled())
                log.error(message, cause);
            break;
        case FATAL:
            if (log.isFatalEnabled())
                log.fatal(message, cause);
            break;
        case INFO:
            if (log.isInfoEnabled())
                log.info(message);
            break;
        //                case Level.WARN_INT:
        default:
            if (log.isWarnEnabled())
                log.warn(message);
        }
    }
}

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

/**
 * Returns a <code>Method<code> allowing access to
 * {@link Throwable#initCause(Throwable)} method of {@link Throwable},
 * or <code>null</code> if the method does not exist.
 *
 * @return A <code>Method<code> for <code>Throwable.initCause</code>, or
 *         <code>null</code> if unavailable.
 *///from   w  w w.  j av  a  2  s  . c  o m
private static Method getInitCauseMethod() {
    try {
        final Class<?>[] paramsClasses = new Class<?>[] { Throwable.class };
        return Throwable.class.getMethod("initCause", paramsClasses);
    } catch (final NoSuchMethodException e) {
        final Log log = LogFactory.getLog(QPropertyUtils.class);
        if (log.isWarnEnabled()) {
            log.warn("Throwable does not have initCause() method in JDK 1.3");
        }
        return null;
    } catch (final Throwable e) {
        final Log log = LogFactory.getLog(QPropertyUtils.class);
        if (log.isWarnEnabled()) {
            log.warn("Error getting the Throwable initCause() method", e);
        }
        return null;
    }
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static boolean warn(final Log log) {
    return (log.isWarnEnabled());
}

From source file:org.alfresco.repo.admin.Log4JHierarchyInitTest.java

public void testSetUp() throws Throwable {
    // Check that the bean is present
    ctx.getBean("log4JHierarchyInit");
    // Make sure that the default log4j.properties is being picked up
    Log log = LogFactory.getLog("log4j.logger.org.alfresco");
    assertFalse("Expect log level ERROR for 'org.alfresco'.", log.isWarnEnabled());
}

From source file:org.alfresco.repo.webdav.auth.BaseNTLMAuthenticationFilter.java

/**
 * Process a type 3 NTLM message//w ww. ja va 2s.  c  o m
 * 
 * @param type3Msg Type3NTLMMessage
 * @param req HttpServletRequest
 * @param res HttpServletResponse
 *
 * @exception IOException
 * @exception ServletException
 */
protected boolean processType3(Type3NTLMMessage type3Msg, ServletContext context, HttpServletRequest req,
        HttpServletResponse res) throws IOException, ServletException {
    Log logger = getLogger();

    if (logger.isDebugEnabled())
        logger.debug("Received type3 " + type3Msg);

    // Get the existing NTLM details
    NTLMLogonDetails ntlmDetails = null;
    SessionUser user = null;

    user = getSessionUser(context, req, res, true);
    HttpSession session = req.getSession();
    ntlmDetails = (NTLMLogonDetails) session.getAttribute(NTLM_AUTH_DETAILS);

    // Get the NTLM logon details
    String userName = type3Msg.getUserName();
    String workstation = type3Msg.getWorkstation();
    String domain = type3Msg.getDomain();

    // ALF-10997 fix, normalize the userName
    //the system runAs is acceptable because we are resolving a username i.e. it's a system-wide operation that does not need permission checks

    final String userName_f = userName;
    String normalized = transactionService.getRetryingTransactionHelper()
            .doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<String>() {
                public String execute() throws Throwable {
                    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>() {
                        public String doWork() throws Exception {
                            String normalized = personService.getUserIdentifier(userName_f);
                            return normalized;
                        }
                    }, AuthenticationUtil.SYSTEM_USER_NAME);
                }
            }, true);

    if (normalized != null) {
        userName = normalized;
    }

    boolean authenticated = false;

    // Check if we are using cached details for the authentication
    if (user != null && ntlmDetails != null && ntlmDetails.hasNTLMHashedPassword()) {
        // Check if the received NTLM hashed password matches the cached password
        byte[] ntlmPwd = type3Msg.getNTLMHash();
        byte[] cachedPwd = ntlmDetails.getNTLMHashedPassword();

        if (ntlmPwd != null) {
            authenticated = Arrays.equals(cachedPwd, ntlmPwd);
        }

        if (logger.isDebugEnabled())
            logger.debug("Using cached NTLM hash, authenticated = " + authenticated);

        onValidate(context, req, res, new NTLMCredentials(userName, ntlmPwd));

        // Allow the user to access the requested page
        return true;
    } else {
        WebCredentials credentials;
        // Check if we are using local MD4 password hashes or passthru authentication
        if (nltmAuthenticator.getNTLMMode() == NTLMMode.MD4_PROVIDER) {
            // Check if guest logons are allowed and this is a guest logon
            if (m_allowGuest && userName.equalsIgnoreCase(authenticationComponent.getGuestUserName())) {
                credentials = new GuestCredentials();
                // Indicate that the user has been authenticated
                authenticated = true;

                if (getLogger().isDebugEnabled())
                    getLogger().debug("Guest logon");
            } else {
                // Get the stored MD4 hashed password for the user, or null if the user does not exist
                String md4hash = getMD4Hash(userName);

                if (md4hash != null) {
                    authenticated = validateLocalHashedPassword(type3Msg, ntlmDetails, authenticated, md4hash);
                    credentials = new NTLMCredentials(ntlmDetails.getUserName(),
                            ntlmDetails.getNTLMHashedPassword());
                } else {
                    // Check if unknown users should be logged on as guest
                    if (m_mapUnknownUserToGuest) {
                        // Reset the user name to be the guest user
                        userName = authenticationComponent.getGuestUserName();
                        authenticated = true;
                        credentials = new GuestCredentials();

                        if (logger.isDebugEnabled())
                            logger.debug("User " + userName + " logged on as guest, no Alfresco account");
                    } else {
                        if (logger.isDebugEnabled())
                            logger.debug("User " + userName + " does not have Alfresco account");

                        // Bypass NTLM authentication and display the logon screen,
                        // as user account does not exist in Alfresco
                        credentials = new UnknownCredentials();
                        authenticated = false;
                    }
                }
            }
        } else {
            credentials = new NTLMCredentials(type3Msg.getUserName(), type3Msg.getNTLMHash());
            //  Determine if the client sent us NTLMv1 or NTLMv2
            if (type3Msg.hasFlag(NTLM.Flag128Bit) && type3Msg.hasFlag(NTLM.FlagNTLM2Key)
                    || (type3Msg.getNTLMHash() != null && type3Msg.getNTLMHash().length > 24)) {
                // Cannot accept NTLMv2 if we are using passthru auth
                if (logger.isErrorEnabled())
                    logger.error("Client " + workstation
                            + " using NTLMv2 logon, not valid with passthru authentication");
            } else {
                if (ntlmDetails == null) {
                    if (logger.isWarnEnabled())
                        logger.warn(
                                "Authentication failed: NTLM details can not be retrieved from session. Client must support cookies.");
                    restartLoginChallenge(context, req, res);
                    return false;
                }
                // Passthru mode, send the hashed password details to the passthru authentication server
                NTLMPassthruToken authToken = (NTLMPassthruToken) ntlmDetails.getAuthenticationToken();
                authToken.setUserAndPassword(type3Msg.getUserName(), type3Msg.getNTLMHash(),
                        PasswordEncryptor.NTLM1);
                try {
                    // Run the second stage of the passthru authentication
                    nltmAuthenticator.authenticate(authToken);
                    authenticated = true;

                    // Check if the user has been logged on as guest
                    if (authToken.isGuestLogon()) {
                        userName = authenticationComponent.getGuestUserName();
                    }

                    // Set the authentication context
                    authenticationComponent.setCurrentUser(userName);
                } catch (BadCredentialsException ex) {
                    if (logger.isDebugEnabled())
                        logger.debug("Authentication failed, " + ex.getMessage());
                } catch (AuthenticationException ex) {
                    if (logger.isDebugEnabled())
                        logger.debug("Authentication failed, " + ex.getMessage());
                } finally {
                    // Clear the authentication token from the NTLM details
                    ntlmDetails.setAuthenticationToken(null);
                }
            }
        }

        // Check if the user has been authenticated, if so then setup the user environment
        if (authenticated == true) {
            boolean userInit = false;
            if (user == null) {
                try {
                    user = createUserEnvironment(session, userName);
                    userInit = true;
                } catch (AuthenticationException ex) {
                    if (logger.isDebugEnabled())
                        logger.debug("Failed to validate user " + userName, ex);

                    onValidateFailed(context, req, res, session, credentials);
                    return false;
                }
            }

            onValidate(context, req, res, credentials);

            // Update the NTLM logon details in the session
            String srvName = getServerName();
            if (ntlmDetails == null) {
                // No cached NTLM details
                ntlmDetails = new NTLMLogonDetails(userName, workstation, domain, false, srvName);
                ntlmDetails.setNTLMHashedPassword(type3Msg.getNTLMHash());
                session.setAttribute(NTLM_AUTH_DETAILS, ntlmDetails);

                if (logger.isDebugEnabled())
                    logger.debug("No cached NTLM details, created");
            } else {
                // Update the cached NTLM details
                ntlmDetails.setDetails(userName, workstation, domain, false, srvName);
                ntlmDetails.setNTLMHashedPassword(type3Msg.getNTLMHash());

                if (logger.isDebugEnabled())
                    logger.debug("Updated cached NTLM details");
            }

            if (logger.isDebugEnabled())
                logger.debug("User logged on via NTLM, " + ntlmDetails);

            if (onLoginComplete(context, req, res, userInit)) {
                // Allow the user to access the requested page
                return true;
            }
        } else {
            restartLoginChallenge(context, req, res);
        }
    }
    return false;
}

From source file:org.alfresco.service.cmr.repository.NodeRef.java

private static void logNodeRefError(String nodeRefId, Log logger) {
    if (logger.isWarnEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Target Node: ").append(nodeRefId);
        msg.append(" is not a valid NodeRef and has been ignored.");
        logger.warn(msg.toString());//from   ww w  .j  a  va  2 s . c om
    }
}

From source file:org.apache.http.conn.util.PublicSuffixMatcherLoader.java

public static PublicSuffixMatcher getDefault() {
    if (DEFAULT_INSTANCE == null) {
        synchronized (PublicSuffixMatcherLoader.class) {
            if (DEFAULT_INSTANCE == null) {
                final URL url = PublicSuffixMatcherLoader.class.getResource("/mozilla/public-suffix-list.txt");
                if (url != null) {
                    try {
                        DEFAULT_INSTANCE = load(url);
                    } catch (IOException ex) {
                        // Should never happen
                        final Log log = LogFactory.getLog(PublicSuffixMatcherLoader.class);
                        if (log.isWarnEnabled()) {
                            log.warn("Failure loading public suffix list from default resource", ex);
                        }/*from   w ww .  jav  a  2s .  c o m*/
                    }
                } else {
                    DEFAULT_INSTANCE = new PublicSuffixMatcher(Arrays.asList("com"), null);
                }
            }
        }
    }
    return DEFAULT_INSTANCE;
}