List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.java
public void render(GrailsWebRequest webRequest, GroovyPageBinding pageScope, Map<String, Object> attrs, Object body, Writer out) throws IOException { Assert.state(groovyPagesTemplateEngine != null, "Property [groovyPagesTemplateEngine] must be set!"); String templateName = getStringValue(attrs, "template"); if (StringUtils.isBlank(templateName)) { throw new GrailsTagException("Tag [render] is missing required attribute [template]"); }//from w w w .ja v a 2s. c o m String uri = webRequest.getAttributes().getTemplateUri(templateName, webRequest.getRequest()); String contextPath = getStringValue(attrs, "contextPath"); String pluginName = getStringValue(attrs, "plugin"); Template t = findAndCacheTemplate(webRequest, pageScope, templateName, contextPath, pluginName, uri); if (t == null) { throw new GrailsTagException( "Template not found for name [" + templateName + "] and path [" + uri + "]"); } makeTemplate(webRequest, t, attrs, body, out); }
From source file:org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.java
/** * <p>Wraps regular request and response objects into Grails request and response objects. * * <p>It can handle maps as model types next to ModelAndView instances. * * @param request HTTP request/* w ww . j a v a 2s . co m*/ * @param response HTTP response * @return the model */ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // Step 1: determine the correct URI of the request. String uri = urlPathHelper.getPathWithinApplication(request); if (LOG.isDebugEnabled()) { LOG.debug("[SimpleGrailsController] Processing request for uri [" + uri + "]"); } RequestAttributes ra = RequestContextHolder.getRequestAttributes(); Assert.state(ra instanceof GrailsWebRequest, "Bound RequestContext is not an instance of GrailsWebRequest"); GrailsWebRequest webRequest = (GrailsWebRequest) ra; ModelAndView mv = grailsControllerHelper.handleURI(uri, webRequest); if (mv != null) { if (LOG.isDebugEnabled()) { LOG.debug("[SimpleGrailsController] Forwarding model and view [" + mv + "] with class [" + (mv.getView() != null ? mv.getView().getClass().getName() : mv.getViewName()) + "]"); } } return mv; }
From source file:org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.java
/** * Delegates to renderMergedOutputModel(..) * * @see #renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * * @param model The view model/*from w w w . j a v a 2 s .c om*/ * @param request The HttpServletRequest * @param response The HttpServletResponse * @throws Exception When an error occurs rendering the view */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected final void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // templateEngine is always same instance in context, can use cached; removed static cache in GrailsViewResolver Assert.state(templateEngine != null, "No GroovyPagesTemplateEngine found in ApplicationContext!"); exposeModelAsRequestAttributes(model, request); renderWithTemplateEngine(templateEngine, model, response, request); // new ModelExposingHttpRequestWrapper(request, model) }
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Helper method for opening output source at given file position. * @param position Set the position/*from w ww . j a va 2 s . c o m*/ * @param restarted Is this execution being restarted */ private void open(final long position, final boolean restarted) { File file; FileOutputStream os = null; try { file = resource.getFile(); FileUtils.setUpOutputFile(file, restarted, overwriteOutput); Assert.state(resource.exists(), "Output resource must exist"); os = new FileOutputStream(file, true); channel = os.getChannel(); setPosition(position); } catch (IOException ioe) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", ioe); } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); if (outputFactory.isPropertySupported("com.ctc.wstx.automaticEndElements")) { // If the current XMLOutputFactory implementation is supplied by // Woodstox >= 3.2.9 we want to disable its // automatic end element feature (see: // http://jira.codehaus.org/browse/WSTX-165) per // http://jira.springframework.org/browse/BATCH-761. outputFactory.setProperty("com.ctc.wstx.automaticEndElements", Boolean.FALSE); } try { if (transactional) { bufferedWriter = new TransactionAwareBufferedWriter(new OutputStreamWriter(os, encoding), new Runnable() { public void run() { closeStream(); } }); } else { bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, encoding)); } delegateEventWriter = outputFactory.createXMLEventWriter(bufferedWriter); eventWriter = new NoStartEndDocumentStreamWriter(delegateEventWriter); if (!restarted) { startDocument(delegateEventWriter); } } catch (XMLStreamException xse) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", xse); } catch (UnsupportedEncodingException e) { throw new DataAccessResourceFailureException( "Unable to write to file resource: [" + resource + "] with encoding=[" + encoding + "]", e); } }
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Write the value objects and flush them to the file. * * @param items//from w ww.ja v a 2 s . c om * the value object * @throws IOException * if there is a problem writing to the resource */ public final void write(final List<? extends T> items) throws IOException { currentRecordCount += items.size(); for (Object object : items) { Assert.state(marshaller.supports(object.getClass()), "Marshaller must support the class of the marshalled object"); try { marshaller.marshal(object, StaxUtils.createStaxResult(eventWriter)); } catch (XmlMappingException e) { throw new IOException(e.getMessage()); } catch (XMLStreamException e) { throw new IOException(e.getMessage()); } } try { eventWriter.flush(); } catch (XMLStreamException e) { throw new WriteFailedException("Failed to flush the events", e); } }
From source file:org.esupportail.publisher.config.FileUploadConfiguration.java
private String getDefinedUploadPath(final String propertyKey) { if (env.containsProperty(propertyKey)) { final String path = env.getProperty(propertyKey); final File file = new File(path); Assert.state(file.exists(), "You defined the property \'" + propertyKey + "\' = '" + path + "' but the path doesn't exist or there isn't read permissions"); Assert.state(file.isDirectory(), "You defined the property \'\" + propertyKey + \"\' = '" + path + "' but the path isn't a directory"); Assert.state(file.canWrite(), "You defined the property \'\" + propertyKey + \"\' = '" + path + "' but the path isn't has write access"); return path; }/*from w w w.jav a2s . c om*/ return null; }
From source file:org.geoserver.backuprestore.writer.CatalogFileWriter.java
private OutputState getOutputState() { if (state == null) { File file;/*from w ww . j a va2 s . c o m*/ try { file = resource.getFile(); } catch (IOException e) { throw new ItemStreamException("Could not convert resource to file: [" + resource + "]", e); } Assert.state(!file.exists() || file.canWrite(), "Resource is not writable: [" + resource + "]"); state = new OutputState(); state.setDeleteIfExists(shouldDeleteIfExists); state.setAppendAllowed(append); state.setEncoding(encoding); } return state; }
From source file:org.kuali.rice.krad.web.bind.UifServletRequestDataBinder.java
/** * Allows for a custom binding result class. * * @see org.springframework.validation.DataBinder#initBeanPropertyAccess() *///ww w . j av a 2 s . c om @Override public void initBeanPropertyAccess() { Assert.state(this.bindingResult == null, "DataBinder is already initialized - call initBeanPropertyAccess before other configuration methods"); this.bindingResult = new UifBeanPropertyBindingResult(getTarget(), getObjectName(), isAutoGrowNestedPaths(), getAutoGrowCollectionLimit()); this.bindingResult.setChangeTracking(this.changeTracking); if (this.conversionService != null) { this.bindingResult.initConversion(this.conversionService); } if (this.dataObjectService == null) { this.dataObjectService = KradDataServiceLocator.getDataObjectService(); } }
From source file:org.nextframework.controller.ExtendedBeanWrapper.java
/** * Internal version of getPropertyDescriptor: * Returns null if not found rather than throwing an exception. *///from w w w .j ava 2 s . c o m protected PropertyDescriptor getPropertyDescriptorInternal(String propertyName) throws BeansException { Assert.state(this.object != null, "BeanWrapper does not hold a bean instance"); ExtendedBeanWrapper nestedBw = getBeanWrapperForPropertyPath(propertyName); return nestedBw.cachedIntrospectionResults.getPropertyDescriptor(getFinalPath(nestedBw, propertyName)); }
From source file:org.opennms.netmgt.poller.remote.support.ScanReportPollerFrontEnd.java
private static void assertNotNull(final Object propertyValue, final String propertyName) { Assert.state(propertyValue != null, propertyName + " must be set for instances of " + ScanReportPollerFrontEnd.class.getName()); }