List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.aurel.track.admin.customize.treeConfig.field.FieldConfigBL.java
public static FieldConfigTO createFieldConfigTO(WorkItemContext workItemContext, TFieldBean fieldBean, Locale locale) {//from w w w .java2 s .c om FieldConfigTO fieldConfigTO = new FieldConfigTO(); Integer fieldID = fieldBean.getObjectID(); fieldConfigTO.setFieldID(fieldID); FieldType fieldType = FieldTypeManager.getInstance().getType(fieldID); TypeRendererRT fieldTypeRendererRT = null; IFieldTypeRT fieldTypeRT = null; if (fieldType != null) { fieldType.setFieldID(fieldID); fieldTypeRendererRT = fieldType.getRendererRT(); fieldTypeRT = fieldType.getFieldTypeRT(); } TFieldConfigBean fieldConfigBean = (TFieldConfigBean) workItemContext.getFieldConfigs().get(fieldID); String tooltip = null; if (fieldConfigBean != null) { tooltip = fieldConfigBean.getTooltip(); if (fieldTypeRT != null && tooltip != null) { Map<String, Object> labelContext = fieldTypeRT.getLabelContext(fieldID, workItemContext.getWorkItemBean().getAttribute(fieldID, null), locale); if (labelContext != null && !labelContext.isEmpty()) { Template tooltipTemplate = getTooltipTemplate(tooltip); StringWriter labelWriter = new StringWriter(); try { tooltipTemplate.process(labelContext, labelWriter); tooltip = labelWriter.toString(); } catch (Exception e) { LOGGER.debug("Processing template: " + labelWriter.toString() + " failed with " + e.getMessage()); } } } fieldConfigTO.setLabel(fieldConfigBean.getLabel()); } if (tooltip == null) { tooltip = ""; } fieldConfigTO.setTooltip(tooltip); Integer accesFlag = null; if (workItemContext.getFieldRestrictions() != null) { accesFlag = workItemContext.getFieldRestrictions().get(fieldID); } boolean readonly = false; boolean invisible = false; if (accesFlag != null) { if (accesFlag.intValue() == TRoleFieldBean.ACCESSFLAG.NOACCESS) { readonly = true; invisible = true; } else { invisible = false; readonly = (accesFlag.intValue() == TRoleFieldBean.ACCESSFLAG.READ_ONLY); } } fieldConfigTO.setReadonly(readonly); Set<Integer> readOnlyFields = getReadOnlySet(); if (readOnlyFields.contains(fieldID)) { fieldConfigTO.setReadonly(true); } else { fieldConfigTO.setRequired(fieldBean.isRequiredString() || fieldConfigBean.isRequiredString()); } fieldConfigTO.setInvisible(invisible); boolean hasDependences = ItemFieldRefreshBL.hasDependences(fieldBean, workItemContext); fieldConfigTO.setHasDependences(hasDependences); if (hasDependences) { fieldConfigTO.setClientSideRefresh(ItemFieldRefreshBL.isClientSideRefresh(fieldID)); } //TODO validate JSON if (fieldTypeRendererRT != null) { fieldConfigTO.setJsonData(fieldTypeRendererRT.createJsonData(fieldBean, workItemContext)); } return fieldConfigTO; }
From source file:es.tid.cep.esperanza.Utils.java
public static JSONObject Event2JSONObject(EventBean event) { JSONObject jo = new JSONObject(); Map<String, Object> errors = new HashMap<String, Object>(); String[] propertyNames = event.getEventType().getPropertyNames(); for (String propertyName : propertyNames) { try {/*ww w . ja v a 2s . co m*/ jo.put(propertyName, event.get(propertyName)); } catch (JSONException je) { errors.put(propertyName, je.getMessage()); logger.error(je.getMessage()); } } if (!errors.isEmpty()) { jo.put("errors", errors); } return jo; }
From source file:org.apache.lens.regression.util.Util.java
public static XProperties xPropertiesFromMap(Map<String, String> map) { ObjectFactory xCF = new ObjectFactory(); if (map != null && !map.isEmpty()) { XProperties xp = xCF.createXProperties(); List<XProperty> xpList = xp.getProperty(); for (Map.Entry<String, String> e : map.entrySet()) { XProperty property = xCF.createXProperty(); property.setName(e.getKey()); property.setValue(e.getValue()); xpList.add(property);//www. j ava 2 s . co m } return xp; } return null; }
From source file:com.google.visualization.datasource.render.JsonRenderer.java
/** * Makes a string from a properties map. * * @param propertiesMap The properties map. * * @return A json string./* w ww.j a v a 2 s. c o m*/ */ private static String getPropertiesMapString(Map<String, String> propertiesMap) { String customPropertiesString = null; if ((propertiesMap != null) && (!propertiesMap.isEmpty())) { List<String> customPropertiesStrings = Lists.newArrayList(); for (Map.Entry<String, String> entry : propertiesMap.entrySet()) { customPropertiesStrings.add("\"" + EscapeUtil.jsonEscape(entry.getKey()) + "\":\"" + EscapeUtil.jsonEscape(entry.getValue()) + "\""); } customPropertiesString = new StrBuilder("{").appendWithSeparators(customPropertiesStrings, ",") .append("}").toString(); } return customPropertiesString; }
From source file:com.erudika.para.core.ParaObjectUtils.java
/** * Converts a map of fields/values to a domain object. Only annotated fields are populated. This method forms the * basis of an Object/Grid Mapper.//from ww w.j a v a2 s .c o m * <br> * Map values that are JSON objects are converted to their corresponding Java types. Nulls and primitive types are * preserved. * * @param <P> the object type * @param pojo the object to populate with data * @param data the map of fields/values * @param filter a filter annotation. fields that have it will be skipped * @return the populated object */ public static <P extends ParaObject> P setAnnotatedFields(P pojo, Map<String, Object> data, Class<? extends Annotation> filter) { if (data == null || data.isEmpty()) { return null; } try { if (pojo == null) { // try to find a declared class in the core package pojo = (P) toClass((String) data.get(Config._TYPE)).getConstructor().newInstance(); } List<Field> fields = getAllDeclaredFields(pojo.getClass()); Map<String, Object> props = new HashMap<String, Object>(data); for (Field field : fields) { boolean dontSkip = ((filter == null) ? true : !field.isAnnotationPresent(filter)); String name = field.getName(); Object value = data.get(name); if (field.isAnnotationPresent(Stored.class) && dontSkip) { // try to read a default value from the bean if any if (value == null && PropertyUtils.isReadable(pojo, name)) { value = PropertyUtils.getProperty(pojo, name); } // handle complex JSON objects deserialized to Maps, Arrays, etc. if (!Utils.isBasicType(field.getType()) && value instanceof String) { // in this case the object is a flattened JSON string coming from the DB value = getJsonReader(field.getType()).readValue(value.toString()); } field.setAccessible(true); BeanUtils.setProperty(pojo, name, value); } props.remove(name); } // handle unknown (user-defined) fields if (!props.isEmpty() && pojo instanceof Sysprop) { for (Map.Entry<String, Object> entry : props.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); // handle the case where we have custom user-defined properties // which are not defined as Java class fields if (!PropertyUtils.isReadable(pojo, name)) { if (value == null) { ((Sysprop) pojo).removeProperty(name); } else { ((Sysprop) pojo).addProperty(name, value); } } } } } catch (Exception ex) { logger.error(null, ex); pojo = null; } return pojo; }
From source file:org.apache.lens.regression.util.Util.java
public static List<XProperty> xPropertyFromMap(Map<String, String> map) { List<XProperty> xpList = new ArrayList<XProperty>(); if (map != null && !map.isEmpty()) { for (Map.Entry<String, String> e : map.entrySet()) { XProperty property = new XProperty(); property.setName(e.getKey()); property.setValue(e.getValue()); xpList.add(property);//w w w . java2s . co m } } return xpList; }
From source file:com.activecq.api.helpers.WCMHelper.java
/** * Creates a String HTML representation of the Component's edit block. If * EditType DropTargets equals specified, Block will created by inspecting the * Drop Targets.//from www.j a va2 s . co m * * @param request * @param editType * @param isConfigured will display edit block if evaluates to false * @return */ public static String getEditBlock(SlingHttpServletRequest request, WCMEditType.Type editType, boolean... isConfigured) { final Resource resource = request.getResource(); final com.day.cq.wcm.api.components.Component component = WCMUtils.getComponent(resource); if (!isAuthoringMode(request) || conditionAndCheck(isConfigured)) { return null; } else if (WCMEditType.NONE.equals(editType)) { return "<!-- Edit Mode Placeholder is specified as: " + editType.getName() + " -->"; } String html = "<div class=\"wcm-edit-mode " + CSS_EDIT_MODE + "\">"; if (component == null) { html += getCssStyle(); html += "Could not resolve CQ Component type."; } else if (WCMEditType.NOICON.equals(editType) || WCMEditType.NONE.equals(editType)) { final String title = StringUtils.capitalize(component.getTitle()); html += getCssStyle(); html += "<dl>"; html += "<dt>" + title + " Component</dt>"; if (component.isEditable()) { html += "<dd>Double click or Right click to Edit</dd>"; } if (component.isDesignable()) { html += "<dd>Switch to Design mode and click the Edit button</dd>"; } if (!component.isEditable() && !component.isDesignable()) { html += "<dd>The component cannot be directly authored</dd>"; } html += "</dl>"; } else if (WCMEditType.DROPTARGETS.equals(editType)) { // Use DropTargets ComponentEditConfig editConfig = component.getEditConfig(); Map<String, DropTarget> dropTargets = (editConfig != null) ? editConfig.getDropTargets() : null; if (dropTargets != null && !dropTargets.isEmpty()) { // Auto generate images with drop-targets for (String key : dropTargets.keySet()) { final DropTarget dropTarget = (DropTarget) dropTargets.get(key); html += "<img src=\"/libs/cq/ui/resources/0.gif\"" + " " + "class=\"" + dropTarget.getId() + " " + getWCMEditType(dropTarget).getCssClass() + "\"" + " " + "alt=\"Drop Target: " + dropTarget.getName() + "\"" + " " + "title=\"Drop Target: " + dropTarget.getName() + "\"" + "/>"; } } } else { final String title = StringUtils.capitalize(component.getTitle()); // Use specified EditType html += "<img src=\"/libs/cq/ui/resources/0.gif\"" + " " + "class=\"" + editType.getCssClass() + "\"" + " " + "alt=\"" + title + "\"" + " " + "title=\"" + title + "\"" + "/>"; } html += "</div>"; return html; }
From source file:com.taobao.android.builder.tools.classinject.CodeInjectByJavassist.java
public synchronized static byte[] inject(ClassPool pool, String className, InjectParam injectParam) throws Exception { CtClass cc = pool.get(className);/* w w w . ja v a 2s .c o m*/ cc.defrost(); if (className.equalsIgnoreCase("android.taobao.atlas.framework.FrameworkProperties") || className.equalsIgnoreCase("android.taobao.atlas.version.VersionKernal")) { if (StringUtils.isNotBlank(injectParam.version)) { CtClass ctClass = pool.get("java.lang.String"); CtField ctField = new CtField(ctClass, "version", cc); ctField.setModifiers(Modifier.PRIVATE); CtMethod ctMethod = CtNewMethod.getter("getVersion", ctField); ctMethod.setModifiers(Modifier.PUBLIC); CtField.Initializer initializer = CtField.Initializer.constant(injectParam.version); cc.addField(ctField, initializer); cc.addMethod(ctMethod); logger.info("[android.taobao.atlas.framework.FrameworkProperties] inject version " + injectParam.version); } addField(pool, cc, "bundleInfo", injectParam.bundleInfo); addField(pool, cc, "autoStartBundles", injectParam.autoStartBundles); addField(pool, cc, "preLaunch", injectParam.preLaunch); addField(pool, cc, "group", injectParam.group); addField(pool, cc, "outApp", String.valueOf(injectParam.outApp)); if (null != injectParam.outputFile) { Map output = new HashMap(); output.put("bundleInfo", JSON.parseArray(injectParam.bundleInfo)); output.put("autoStartBundles", injectParam.autoStartBundles); output.put("preLaunch", injectParam.preLaunch); output.put("group", injectParam.group); output.put("outApp", injectParam.outApp); FileUtils.write(injectParam.outputFile, JSON.toJSONString(output, true)); } } ClazzInjecter clazzInjecter = sInjecterMap.get(className); if (null != clazzInjecter) { Map<String, String> stringMap = clazzInjecter.getInjectFields(); if (!stringMap.isEmpty()) { for (String key : stringMap.keySet()) { addField(pool, cc, key, stringMap.get(key)); } } } if (!injectParam.removePreverify) { Collection<String> refClasses = cc.getRefClasses(); if (refClasses.contains("com.taobao.verify.Verifier")) { return cc.toBytecode(); } boolean flag = false; if (className.equalsIgnoreCase("com.ut.mini.crashhandler.IUTCrashCaughtListner")) { flag = true; } if (cc.isInterface()) { final CtClass defClass = pool.get(Class.class.getName()); CtField defField = new CtField(defClass, "_inject_field__", cc); defField.setModifiers(Modifier.STATIC | Modifier.PUBLIC | Modifier.FINAL); cc.addField(defField, CtField.Initializer.byExpr( "Boolean.TRUE.booleanValue()?java.lang.String.class:com.taobao.verify.Verifier" + ".class;")); } else { CtConstructor[] ctConstructors = cc.getDeclaredConstructors(); if (null != ctConstructors && ctConstructors.length > 0) { CtConstructor ctConstructor = ctConstructors[0]; ctConstructor.insertBeforeBody( "if(Boolean.FALSE.booleanValue()){java.lang.String.valueOf(com.taobao.verify.Verifier" + ".class);}"); } else { final CtClass defClass = pool.get(Class.class.getName()); CtField defField = new CtField(defClass, "_inject_field__", cc); defField.setModifiers(Modifier.STATIC); cc.addField(defField, CtField.Initializer .byExpr("Boolean.TRUE.booleanValue()?java.lang.String.class:com.taobao.verify" + ".Verifier.class;")); } } } return cc.toBytecode(); }
From source file:com.astamuse.asta4d.web.dispatch.RedirectUtil.java
public static void redirectToUrlWithSavedFlashScopeData(HttpServletResponse response, int status, String url) { // regulate status if (status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_MOVED_TEMP) { ///*from w w w . j ava2 s . com*/ } else { status = HttpURLConnection.HTTP_MOVED_TEMP; } // check illegal url if (url.indexOf('\n') >= 0 || url.indexOf('\r') >= 0) { throw new RuntimeException("illegal redirct url:" + url); } // before redirect task Map<String, RedirectInterceptor> interceptorMap = Context.getCurrentThreadContext() .getData(RedirectInterceptorMapKey); if (interceptorMap != null) { for (RedirectInterceptor interceptor : interceptorMap.values()) { interceptor.beforeRedirect(); } addFlashScopeData(RedirectInterceptorMapKey, interceptorMap); } // create flash data map Map<String, Object> dataMap = new HashMap<String, Object>(); WebApplicationContext context = Context.getCurrentThreadContext(); List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey); if (dataList != null) { for (Map<String, Object> map : dataList) { dataMap.putAll(map); } } // save flash data map if (!dataMap.isEmpty()) { String flashScopeId = SecureIdGenerator.createEncryptedURLSafeId(); WebApplicationConfiguration.getWebApplicationConfiguration().getExpirableDataManager().put(flashScopeId, dataMap, DATA_EXPIRE_TIME_MILLI_SECONDS); // create target url if (url.contains("?")) { url = url + '&' + KEY_FLASH_SCOPE_ID + '=' + flashScopeId; } else { url = url + '?' + KEY_FLASH_SCOPE_ID + '=' + flashScopeId; } } // do redirection response.setStatus(status); response.addHeader("Location", url); }
From source file:com.moviejukebox.tools.DOMHelper.java
/** * Add a child element to a parent element with a set of attributes * * @param doc//from w ww . ja v a2 s . c o m * @param parentElement * @param elementName * @param elementValue * @param childAttributes */ public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue, Map<String, String> childAttributes) { Element child = doc.createElement(elementName); Text text = doc.createTextNode(elementValue); child.appendChild(text); if (childAttributes != null && !childAttributes.isEmpty()) { for (Map.Entry<String, String> attrib : childAttributes.entrySet()) { child.setAttribute(attrib.getKey(), attrib.getValue()); } } parentElement.appendChild(child); }