List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:net.ymate.platform.mvc.web.view.impl.HttpStatusView.java
protected void renderView() throws Exception { if (StringUtils.isNotBlank(body)) { IOUtils.write(body, WebContext.getResponse().getOutputStream(), StringUtils.defaultIfEmpty( WebMVC.getConfig().getCharsetEncoding(), WebContext.getResponse().getCharacterEncoding())); }/*from w ww . j av a2 s .c o m*/ if (StringUtils.isNotBlank(msg)) { WebContext.getResponse().sendError(status, msg); } else { if (__error) { WebContext.getResponse().sendError(status); } else { WebContext.getResponse().setStatus(status); } } }
From source file:net.ymate.platform.mvc.web.view.impl.JsonView.java
/** * @param callback ??//from www .ja v a 2 s . co m * @return JSONP????callbackcallback??? */ public JsonView withJsonpCallback(String callback) { this.jsonpCallback = StringUtils.defaultIfEmpty(callback, null); return this; }
From source file:net.ymate.platform.mvc.web.view.impl.JsonView.java
protected void renderView() throws Exception { HttpServletResponse response = WebContext.getResponse(); if (StringUtils.isNotBlank(getContentType())) { response.setContentType(getContentType()); } else if (this.withContentType) { if (this.jsonpCallback == null) { response.setContentType(JSON_CONTENT_TYPE); } else {// ww w .j ava2s .c o m response.setContentType(JAVASCRIPT_CONTENT_TYPE); } } StringBuilder _jsonStr = new StringBuilder(jsonObj.toString()); if (this.jsonpCallback != null) { _jsonStr.insert(0, this.jsonpCallback + "(").append(");"); } IOUtils.write(_jsonStr.toString(), response.getOutputStream(), StringUtils .defaultIfEmpty(WebMVC.getConfig().getCharsetEncoding(), response.getCharacterEncoding())); }
From source file:net.ymate.platform.mvc.web.view.impl.TextView.java
protected void renderView() throws Exception { if (StringUtils.isNotBlank(getContentType())) { WebContext.getResponse().setContentType(getContentType()); }//from w w w . ja v a 2s. c o m IOUtils.write(this.text, WebContext.getResponse().getOutputStream(), StringUtils.defaultIfEmpty( WebMVC.getConfig().getCharsetEncoding(), WebContext.getResponse().getCharacterEncoding())); }
From source file:net.ymate.platform.mvc.web.WebMVC.java
/** * ?WebMVC?/*from w w w . jav a 2s . co m*/ * * @param config */ public static void initialize(IWebMvcConfig config) { __doInitialize(config, new WebRequestProcessor()); if (config.isI18n()) { final String _localKey = StringUtils .defaultIfEmpty(config.getExtendParams().get(Optional.I18N_LANGUAGE_KEY), "lang"); I18N.setEventHandler(new II18NEventHandler() { public Locale loadCurrentLocale() { // ??URL??? String _langStr = (String) WebContext.getContext().get(_localKey); if (_langStr == null) { // ???? _langStr = WebContext.getRequest().getParameter(_localKey); if (_langStr == null) { // ???Cookies BlurObject _langCookie = CookieHelper.create().getCookie(_localKey); if (_langCookie != null) { _langStr = _langCookie.toStringValue(); } } } return MVC.localeFromStr(_langStr, MVC.getConfig().getLocale()); } public void onLocaleChanged(Locale locale) { CookieHelper.create().setCookie(_localKey, locale.toString()); } public InputStream onLoadProperties(String resourceName) throws IOException { if (Cfgs.isInited()) { File _resourcefile = Cfgs.search("i18n/" + resourceName); if (_resourcefile != null) { return new FileInputStream(_resourcefile); } } return null; } }); } }
From source file:net.ymate.platform.persistence.jdbc.scaffold.EntityGenerator.java
private void buildTargetFile(String targetFileName, String tmplFile, Map<String, Object> propMap) { Writer _outWriter = null;/*from w w w . j a v a 2s .c o m*/ try { File _outputFile = new File( RuntimeUtils.replaceEnvVariable(StringUtils .defaultIfBlank(__owner.getConfig().getParam("jdbc.output_path"), "${root}")), new File(((String) propMap.get("packageName")).replace('.', '/'), targetFileName).getPath()); File _path = _outputFile.getParentFile(); if (!_path.exists()) { _path.mkdirs(); } Template _template = __freemarkerConfig.getTemplate(__templateRootPath + tmplFile); _outWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(_outputFile), StringUtils.defaultIfEmpty( __freemarkerConfig.getOutputEncoding(), __freemarkerConfig.getDefaultEncoding()))); _template.process(propMap, _outWriter); System.out.println("Output file \"" + _outputFile + "\"."); } catch (Exception e) { _LOG.warn("", e); } finally { if (_outWriter != null) { try { _outWriter.flush(); _outWriter.close(); } catch (IOException e) { _LOG.warn("", e); } } } }
From source file:net.ymate.platform.persistence.jdbc.scaffold.JdbcScaffold.java
private void buildTargetFile(String targetFileName, String tmplFile, Map<String, Object> propMap) { Writer _outWriter = null;//w ww .j av a 2 s . c o m try { File _outputFile = new File(TARGET_ROOT_PATH, new File(((String) propMap.get("packageName")).replace('.', '/'), targetFileName).getPath()); FileUtils.mkdirs(_outputFile.getParent(), true); Template _template = FREEMARKER_CONF.getTemplate(TEMPLATE_ROOT_PATH + tmplFile); _outWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(_outputFile), StringUtils .defaultIfEmpty(FREEMARKER_CONF.getOutputEncoding(), FREEMARKER_CONF.getDefaultEncoding()))); _template.process(propMap, _outWriter); System.out.println("Output file \"" + _outputFile + "\"."); } catch (Exception e) { e.printStackTrace(System.err); } finally { if (_outWriter != null) { try { _outWriter.flush(); _outWriter.close(); } catch (IOException e) { } } } }
From source file:net.ymate.platform.persistence.jdbc.support.AbstractEntityRepository.java
/** * @return ?????????? */ protected String getDataSourceName() { return StringUtils.defaultIfEmpty(this.__dsName, JDBC.DATASOURCE_DEFAULT_NAME); }
From source file:net.ymate.platform.persistence.support.EntityMeta.java
/** * ?/*from ww w . j a v a2 s . c o m*/ * * TODO ???name???? * <p>?DAO????NULL</p> */ private void __init(Class<?> entityClass) { // @Column for (Field _f : ClassUtils.getFields(entityClass, true)) { Property _c = _f.getAnnotation(Property.class); if (_c != null) { this.getColumnMap().put(_c.name(), new ColumnInfo(_c.name(), _f.getName(), _c.defaultValue(), _c.isAutoIncrement(), _c.sequenceName())); String _cName = StringUtils.defaultIfEmpty(_c.name(), _f.getName()); this.getColumnNames().add(_cName); this.getClassAttributeMap().put(_cName, buildFieldNameToClassAttribute(_cName)); if (_c.isAutoIncrement()) { this.__autoIncrementColumns.add(_cName); } } } if (!this.__isSimple) { // @Id List<PairObject<Field, Id>> _results = ClassUtils.getFieldAnnotations(entityClass, Id.class, true); if (_results.size() > 0) { Field _idF = _results.get(0).getKey(); this.__primaryKeyClass = _idF.getType(); PK _pk = _idF.getType().getAnnotation(PK.class); if (_pk != null) { // ??? if (!ClassUtils.isInterfaceOf(_idF.getType(), IEntityPK.class)) { throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.jdbc.entity_class_need_entitypk", entityClass.getName())); } this.__isCompositeKey = true; for (Field _pkF : ClassUtils.getFields(_idF.getType(), true)) { // PK @Column Property _pkC = _pkF.getAnnotation(Property.class); if (_pkC != null) { this.getColumnMap().put(_pkC.name(), new ColumnInfo(_pkC.name(), _pkF.getName(), _pkC.defaultValue(), _pkC.isAutoIncrement(), _pkC.sequenceName())); String _cName = StringUtils.defaultIfEmpty(_pkC.name(), _pkF.getName()); this.getColumnNames().add(_cName); this.getClassAttributeMap().put(_cName, buildFieldNameToClassAttribute(_cName)); this.getPrimaryKeys().add(_cName); if (_pkC.isAutoIncrement()) { this.__autoIncrementColumns.add(_cName); } } } } else { Property _idC = _idF.getAnnotation(Property.class); if (_idC != null) { this.getPrimaryKeys().add(StringUtils.defaultIfEmpty(_idC.name(), _idF.getName())); } } } // if (this.getPrimaryKeys().isEmpty()) { throw new RuntimeException(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.jdbc.entity_class_need_anno_id", entityClass.getName())); } } }
From source file:net.ymate.platform.plugin.impl.DefaultPluginConfig.java
/** * //from w w w . j a v a 2s . com * @param factory * @param parser * @param extraParser * @param pluginHome * @param manifestFile * @param includeClassPath * @param allowAutomatic */ public DefaultPluginConfig(IPluginFactory factory, IPluginParser parser, IPluginExtraParser extraParser, String pluginHome, String manifestFile, boolean includeClassPath, boolean allowAutomatic) { __pluginFactoryImpl = factory; __pluginParserImpl = parser; __extraParserImpl = extraParser; __includeClassPath = includeClassPath; __allowAutomatic = allowAutomatic; __pluginHome = pluginHome; __manifestFile = StringUtils.defaultIfEmpty(manifestFile, PLUGIN_MAINIFEST_FILE); }