List of usage examples for org.apache.commons.logging Log isWarnEnabled
boolean isWarnEnabled();
From source file:net.sf.nmedit.nordmodular.NmFileService.java
public static NMPatch openPatch(File file, File sourceFile, final String title, boolean showExceptionDialog) { NMContextData data = NMContextData.sharedInstance(); try {/* w w w . j ava2s.c om*/ boolean setFilePointerToNull = false; if (isFileAlreadyOpen(file)) { if (JOptionPane.showConfirmDialog(Nomad.sharedInstance().getWindow().getRootPane(), "File \"" + file + "\" is already open.\nDo you want to open a copy of the file?", "Open...", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { Nomad.sharedInstance().setSelectedDocumentByFile(file); return null; } setFilePointerToNull = true; } NMPatch patch = NMPatch.createPatchFromFile(file); patch.setEditSupportEnabled(false); if (title != null) patch.setName(title); final PatchDocument pd = createPatchDoc(patch); if (setFilePointerToNull) { if (sourceFile != null) { String name = sourceFile.getName(); if (name.toLowerCase().endsWith(".pch")) name = name.substring(0, name.length() - 4); patch.setName(name); } } else { if (sourceFile != null) { patch.setProperty("file", sourceFile); pd.setURI(sourceFile); } } patch.setEditSupportEnabled(true); patch.setModified(false); DocumentManager dm = Nomad.sharedInstance().getDocumentManager(); dm.add(pd); dm.setSelection(pd); return patch; } catch (Exception e) { Log log = LogFactory.getLog(NmFileService.class); if (log.isWarnEnabled()) { log.warn("open failed: " + file, e); } if (showExceptionDialog) { ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(), "Could not open file '" + file + "' (" + e.getMessage() + ")", "Could not open file", e); } } return null; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils.java
private static boolean isLevelEnabled(Log log, String level) { if ("fatal".equalsIgnoreCase(level)) { return log.isFatalEnabled(); } else if ("error".equalsIgnoreCase(level)) { return log.isErrorEnabled(); } else if ("warn".equalsIgnoreCase(level)) { return log.isWarnEnabled(); } else if ("info".equalsIgnoreCase(level)) { return log.isInfoEnabled(); } else if ("debug".equalsIgnoreCase(level)) { return log.isDebugEnabled(); } else {//from w ww. ja v a 2 s . com return log.isTraceEnabled(); } }
From source file:edu.vt.middleware.crypt.util.CryptReader.java
/** * Attempts to create a Bouncy Castle <code>DERObject</code> from a byte array * representing ASN.1 encoded data.//from w ww . j a va 2s.c om * * @param data ASN.1 encoded data as byte array. * @param discardWrapper In some cases the value of the encoded data may * itself be encoded data, where the latter encoded data is desired. Recall * ASN.1 data is of the form {TAG, SIZE, DATA}. Set this flag to true to skip * the first two bytes, e.g. TAG and SIZE, and treat the remaining bytes as * the encoded data. * * @return DER object. * * @throws IOException On I/O errors. */ public static DERObject readEncodedBytes(final byte[] data, final boolean discardWrapper) throws IOException { final ByteArrayInputStream inBytes = new ByteArrayInputStream(data); int size = data.length; if (discardWrapper) { inBytes.skip(2); size = data.length - 2; } final ASN1InputStream in = new ASN1InputStream(inBytes, size); try { return in.readObject(); } finally { try { in.close(); } catch (IOException e) { final Log logger = LogFactory.getLog(CryptReader.class); if (logger.isWarnEnabled()) { logger.warn("Error closing ASN.1 input stream.", e); } } } }
From source file:edu.vt.middleware.crypt.util.CryptReader.java
/** * Reads all the data in the given stream and returns the contents as a byte * array./* w ww . j a va 2 s . c om*/ * * @param in Input stream to read. * * @return Entire contents of stream. * * @throws IOException On read errors. */ private static byte[] readData(final InputStream in) throws IOException { final byte[] buffer = new byte[BUFFER_SIZE]; final ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE); int count = 0; try { while ((count = in.read(buffer, 0, BUFFER_SIZE)) > 0) { bos.write(buffer, 0, count); } } finally { try { in.close(); } catch (IOException e) { final Log logger = LogFactory.getLog(CryptProvider.class); if (logger.isWarnEnabled()) { logger.warn("Error closing input stream.", e); } } } return bos.toByteArray(); }
From source file:com.octo.captcha.module.web.image.ImageToJpegHelper.java
/** * retrieve a new ImageCaptcha using ImageCaptchaService and flush it to the response.<br/> Captcha are localized * using request locale.<br/>//from ww w . ja va 2s .c om * <p/> * This method returns a 404 to the client instead of the image if the request isn't correct (missing parameters, * etc...)..<br/> The log may be null.<br/> * * @param theRequest the request * @param theResponse the response * @param log a commons logger * @param service an ImageCaptchaService instance * * @throws java.io.IOException if a problem occurs during the jpeg generation process */ public static void flushNewCaptchaToResponse(HttpServletRequest theRequest, HttpServletResponse theResponse, Log log, ImageCaptchaService service, String id, Locale locale) throws IOException { // call the ImageCaptchaService method to retrieve a captcha byte[] captchaChallengeAsJpeg = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try { BufferedImage challenge = service.getImageChallengeForID(id, locale); // the output stream to render the captcha image as jpeg into ImageIO.write(challenge, "jpg", jpegOutputStream); } catch (IllegalArgumentException e) { // log a security warning and return a 404... if (log != null && log.isWarnEnabled()) { log.warn("There was a try from " + theRequest.getRemoteAddr() + " to render an captcha with invalid ID :'" + id + "' or with a too long one"); theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // render the captcha challenge as a JPEG image in the response theResponse.setHeader("Cache-Control", "no-store"); theResponse.setHeader("Pragma", "no-cache"); theResponse.setDateHeader("Expires", 0); theResponse.setContentType("image/jpeg"); ServletOutputStream responseOutputStream = theResponse.getOutputStream(); responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush(); responseOutputStream.close(); }
From source file:com.octo.captcha.module.web.sound.SoundToWavHelper.java
/** * retrieve a new SoundCaptcha using SoundCaptchaService and flush it to the response. <br/> Captcha are localized * using request locale. <br/>This method returns a 404 to the client instead of the image if the request isn't * correct (missing parameters, etc...).. <br/>The log may be null. <br/> * * @param theRequest the request// ww w . ja v a2 s . c om * @param theResponse the response * @param log a commons logger * @param service an SoundCaptchaService instance * * @throws java.io.IOException if a problem occurs during the jpeg generation process */ public static void flushNewCaptchaToResponse(HttpServletRequest theRequest, HttpServletResponse theResponse, Log log, SoundCaptchaService service, String id, Locale locale) throws IOException { // call the ImageCaptchaService method to retrieve a captcha byte[] captchaChallengeAsWav = null; ByteArrayOutputStream wavOutputStream = new ByteArrayOutputStream(); try { AudioInputStream stream = service.getSoundChallengeForID(id, locale); // call the ImageCaptchaService method to retrieve a captcha AudioSystem.write(stream, AudioFileFormat.Type.WAVE, wavOutputStream); //AudioSystem.(pAudioInputStream, AudioFileFormat.Type.WAVE, pFile); } catch (IllegalArgumentException e) { // log a security warning and return a 404... if (log != null && log.isWarnEnabled()) { log.warn("There was a try from " + theRequest.getRemoteAddr() + " to render an captcha with invalid ID :'" + id + "' or with a too long one"); theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } catch (CaptchaServiceException e) { // log and return a 404 instead of an image... if (log != null && log.isWarnEnabled()) { log.warn( "Error trying to generate a captcha and " + "render its challenge as JPEG", e); } theResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } captchaChallengeAsWav = wavOutputStream.toByteArray(); // render the captcha challenge as a JPEG image in the response theResponse.setHeader("Cache-Control", "no-store"); theResponse.setHeader("Pragma", "no-cache"); theResponse.setDateHeader("Expires", 0); theResponse.setContentType("audio/x-wav"); ServletOutputStream responseOutputStream = theResponse.getOutputStream(); responseOutputStream.write(captchaChallengeAsWav); responseOutputStream.flush(); responseOutputStream.close(); }
From source file:net.sf.nmedit.nomad.core.jpf.JPFServiceInstallerTool.java
private static void activateService(Log log, Map<String, Class<Service>> serviceClassCache, Extension extension, ClassLoader pluginClassLoader) { String serviceClassName = extension.getParameter(SERVICE_CLASS_KEY).valueAsString(); String implementationClassName = extension.getParameter(SERVICE_IMPLEMENTATION_CLASS_KEY).valueAsString(); if (log.isInfoEnabled()) { String description = extension.getParameter(SERVICE_DESCRIPTION_KEY).valueAsString(); log.info("Service implementation / Service: " + implementationClassName + " (description=" + description + ") / " + serviceClassName); }// w w w . ja v a 2 s .co m Class<Service> serviceClass; try { serviceClass = lookupServiceClass(serviceClassCache, serviceClassName, pluginClassLoader); } catch (ClassNotFoundException e) { if (log.isWarnEnabled()) { log.warn("Error loading service class: " + serviceClassName, e); } return; } Class<Service> serviceImplementationClass; try { serviceImplementationClass = lookupServiceImplementationClass(serviceClass, implementationClassName, pluginClassLoader); } catch (ClassNotFoundException e) { if (log.isWarnEnabled()) { log.warn("Error loading service implementation class: " + implementationClassName, e); } return; } Service serviceInstance; try { serviceInstance = serviceImplementationClass.newInstance(); } catch (InstantiationException e) { if (log.isWarnEnabled()) { log.warn("Error instantiating service: " + serviceImplementationClass, e); } return; } catch (IllegalAccessException e) { if (log.isWarnEnabled()) { log.warn("Error instantiating service: " + serviceImplementationClass, e); } return; } try { ServiceRegistry.addService(serviceClass, serviceInstance); } catch (ServiceException e) { if (log.isWarnEnabled()) { log.warn("Error installing service: " + serviceInstance, e); } return; } }
From source file:javadz.beanutils.BeanUtilsBean.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.// w ww . j a va2 s.c o m * * @return A <code>Method<code> for <code>Throwable.initCause</code>, or * <code>null</code> if unavailable. */ private static Method getInitCauseMethod() { try { Class[] paramsClasses = new Class[] { Throwable.class }; return Throwable.class.getMethod("initCause", paramsClasses); } catch (NoSuchMethodException e) { Log log = LogFactory.getLog(BeanUtils.class); if (log.isWarnEnabled()) { log.warn("Throwable does not have initCause() method in JDK 1.3"); } return null; } catch (Throwable e) { Log log = LogFactory.getLog(BeanUtils.class); if (log.isWarnEnabled()) { log.warn("Error getting the Throwable initCause() method", e); } return null; } }
From source file:edu.vt.middleware.ldap.ssl.SingletonTLSSocketFactory.java
/** {@inheritDoc} */ public void setSSLContextInitializer(final SSLContextInitializer initializer) { if (staticContextInitializer != null) { final Log logger = LogFactory.getLog(SingletonTLSSocketFactory.class); if (logger.isWarnEnabled()) { logger.warn("SSLContextInitializer is being overridden"); }/* ww w . j a v a2s. com*/ } staticContextInitializer = initializer; }
From source file:net.sf.nmedit.waldorf.miniworks4pole.WMFileService.java
public void newFile() { try {//from w w w .j av a 2 s. c o m Nomad.sharedInstance().getDocumentManager().add(new MWPatchDoc(MWData.createPatch())); } catch (Exception e) { Log log = LogFactory.getLog(getClass()); if (log.isWarnEnabled()) { log.warn(e); } return; } }