List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:net.sourceforge.fenixedu.util.UniqueAcronymCreator.java
public GenericPair<String, Set<T>> create(T object) throws Exception { initialize();//from ww w .j av a 2 s .c o m final String slotValue = (String) PropertyUtils.getProperty(object, slotName); final String slotValueWithNoAccents = noAccent(slotValue); if (logger.isDebugEnabled()) { logger.info("slotValue -> " + slotValue); logger.info("slotValueWithNoAccents -> " + slotValueWithNoAccents); } this.object = object; splitsName = slotValueWithNoAccents.split(" "); String acronym = constructBasicAcronym(new StringBuilder()); if (canAccept(acronym)) { return new GenericPair<String, Set<T>>(acronym, colisions); } else { acronym = constructExtendedAcronym(acronym); if (canAccept(acronym)) { return new GenericPair<String, Set<T>>(acronym, colisions); } else { int index = 3; StringBuilder acronymAux = new StringBuilder(acronym.toString()); while (!canAccept(acronym.toString()) && (index <= slotValueWithNoAccents.length())) { acronymAux = appendLastChar(index, acronymAux); acronym = acronymAux.toString(); if (canAccept(acronym)) { return new GenericPair<String, Set<T>>(acronym, colisions); } index++; } } } throw new Exception("unable to create acronym!"); }
From source file:com.bstek.dorado.view.output.OutputUtils.java
/** * Java?JavaScript//from w w w . ja va 2 s . c o m * * @param writer * Writer * @param owner * JavaScript? * @param object * Java * @param property * ??? * @param escapeValue * Java? * @throws Exception * @see #DEFAULT_VALUE */ public static void outputProperty(Writer writer, String owner, Object object, String property, Object escapeValue) throws Exception { Object value = PropertyUtils.getProperty(object, property); if (value == escapeValue || (escapeValue != null && escapeValue.equals(value))) { return; } writer.write(owner); writer.write('.'); writer.write(property); writer.write('='); if (value == null) { writer.write("null"); } else if (value instanceof String) { writer.write("\""); writer.write((String) value); writer.write("\""); } else if (value instanceof Number || value instanceof Boolean) { writer.write(value.toString()); } else if (value instanceof Date) { writer.write("new Date("); writer.write(String.valueOf(((Date) value).getTime())); writer.write(")"); } else { writer.write("\""); writer.write(value.toString()); writer.write("\""); } writer.write(";\n"); }
From source file:com.esofthead.mycollab.module.project.ui.form.ProjectFormWatcherSelectField.java
public ProjectFormWatcherSelectField(V bean, String type) { super();/*ww w. j ava 2 s .c o m*/ this.memberService = ApplicationContextUtil.getSpringBean(ProjectMemberService.class); this.monitorItemService = ApplicationContextUtil.getSpringBean(MonitorItemService.class); this.type = type; try { this.typeId = (Integer) PropertyUtils.getProperty(bean, "id"); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOG.error("Error", e); } }
From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.AltQuestionText.java
public int doStartTag() throws javax.servlet.jsp.JspException { HttpServletRequest req;//from www.j a v a 2 s .c o m JspWriter out; try { req = (HttpServletRequest) pageContext.getRequest(); out = pageContext.getOut(); Question currQuestion = (Question) pageContext.getAttribute(questionBeanId); String longName = currQuestion.getLongName(); DataElement de = currQuestion.getDataElement(); if (questionProperty != null && orgModuleBeanId != null) { // Get the property from the Question in the orgModule // If its a new Question the get the property value from // the DataElement for deProperty if deProperty is defined Module orgModule = (Module) pageContext.getSession().getAttribute(orgModuleBeanId); if (orgModule == null) throw new JspException("No Bean by name " + orgModuleBeanId + "in session"); List orgQuestions = orgModule.getQuestions(); String propValue = null; if (orgQuestions.contains(currQuestion)) { Question orgQuestion = getQuestionFromList(currQuestion.getQuesIdseq(), orgQuestions); propValue = (String) PropertyUtils.getProperty(orgQuestion, questionProperty); } else// get the value from the de { if (deProperty != null) { if (de != null) propValue = (String) PropertyUtils.getProperty(de, deProperty); } } /*if(propValue==null) return Tag.SKIP_BODY; */ /* for saved question, use the default question text when CDE does not have preferred question text This is a temporary fix for GF1437 - to keep saved question behavior consistent for CDE with/without Preferred Question Text */ if ((propValue == null || propValue.length() == 0) && "longCDEName".equals(deProperty) && "longName".equals(questionProperty)) { propValue = "Data Element " + de.getLongName() + " does not have Preferred Question Text"; } String script = generateJavaScript("question", formIndex, questionIndex, questionProperty, propValue); StringBuffer linkStr = new StringBuffer( "<a href=\"javascript:question" + questionIndex + questionProperty + "populate()\">"); linkStr.append(propValue); linkStr.append("</a>"); out.print(script); out.print(linkStr.toString()); } else if (de != null) { String propValue = (String) PropertyUtils.getProperty(de, deProperty); /*if(propValue==null) return Tag.SKIP_BODY; */ /* for saved question, use the default question text when CDE does not have preferred question text This is a temporary fix for GF1437 - to keep saved question behavior consistent for CDE with/without Preferred Question Text */ if (propValue == null && "longCDEName".equals(deProperty) && "longName".equals(questionProperty)) { propValue = "Data Element " + de.getLongName() + " does not have Preferred Question Text"; } if (propValue.equals(longName)) { out.print(propValue); } else { String script = generateJavaScript("questionde", formIndex, questionIndex, deProperty, propValue); StringBuffer linkStr = new StringBuffer( "<a href=\"javascript:questionde" + questionIndex + deProperty + "populate()\">"); linkStr.append(propValue); linkStr.append("</a>"); out.print(script); out.print(linkStr.toString()); } } //out.print(getTableFooter()); } catch (Exception ioe) { throw new JspException("I/O Error : " + ioe.getMessage()); } //end try/catch return Tag.SKIP_BODY; }
From source file:com.neelo.glue.st.SelectTool.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private StringBuilder map(Map<String, Object> def, Map<String, Object> options, HttpServletRequest request) throws Exception { String listProperty = options.get("map").toString(); Lifecycle wrapper = (Lifecycle) request.getAttribute(Lifecycle.class.getName()); if (wrapper == null) return skip(def); Map<String, Object> context = Literals.map("this", wrapper.getBean()); Object map = PropertyUtils.getProperty(context, listProperty); if (!(map instanceof Map)) return skip(def); Iterable<Entry<String, Object>> it = ((Map) map).entrySet(); StringBuilder sb = new StringBuilder(); start(def, sb);// ww w . j a va2 s .co m Object prompt = options.get("prompt"); if (prompt != null) sb.append("<option value=\"\">").append(prompt).append("</option>\n"); Object defaults = options.get("default"); String name = def.get("name").toString(); // TODO: selected object may be a list for multi-select Object selected = PropertyUtils.getProperty(wrapper.getBean(), name); for (Entry<String, Object> option : it) { sb.append("<option value=\"").append(option.getKey()).append("\""); if (selected != null) { if (ObjectUtils.equals(option.getKey(), selected.toString())) { sb.append(" selected=\"selected\""); } } else if (defaults != null) { if (ObjectUtils.equals(option.getKey(), defaults.toString())) { sb.append(" selected=\"selected\""); } } sb.append(">"); sb.append(option.getValue()).append("</option>\n"); } end(def, sb); return sb; }
From source file:name.martingeisse.common.util.ContextAwareXmlWriter.java
/** * Writes an element with the specified element name whose text content is the string-ified value * of the property with the specified property name of the current context. If the property value * is null, a nil element is written.// w ww . j av a 2 s .c o m * @param propertyName the name of the property of the current context * @param elementName the name of the element to write */ public final void writePropertyElement(String propertyName, String elementName) { try { Object value = PropertyUtils.getProperty(currentContext, propertyName); String valueText = (value == null) ? null : value.toString(); writeValueElementOrNil(elementName, valueText); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.tonbeller.wcf.table.TableHandler.java
public void initialize(RequestContext context, XmlComponent xmlComp, Element element) throws Exception { super.initialize(context, xmlComp, element); // must access the bean, so it has to be a FormComponent formComp = (FormComponent) xmlComp;// w ww. j av a 2 s .co m String ref = XoplonCtrl.getModelReference(element); Object bean = formComp.getBean(); TableModel tm = (TableModel) PropertyUtils.getProperty(bean, ref); table = createTableComp(element.getAttribute("id"), formComp, tm); DefaultSelectionModel dsm = new DefaultSelectionModel(); String selmode = element.getAttribute("selmode"); if ("href".equals(selmode)) dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF); else if ("single".equals(selmode)) dsm.setMode(SelectionModel.SINGLE_SELECTION); else if ("multi".equals(selmode)) dsm.setMode(SelectionModel.MULTIPLE_SELECTION); else dsm.setMode(SelectionModel.NO_SELECTION); table.setSelectionModel(dsm); if (tm instanceof SelectionChangeListener) dsm.addSelectionListener((SelectionChangeListener) tm); table.setClosable(false); String border = element.getAttribute("border"); if (border.length() > 0) table.setBorder(border); String width = element.getAttribute("width"); if (width.length() > 0) table.setWidth(width); if ("false".equals(element.getAttribute("colHeaders"))) table.setColHeaders(false); // override renderId always table.setRenderId(element.getAttribute("id")); table.addFormListener(formComp); formComp.addFormListener(table); table.initialize(context); }
From source file:com.qperior.gsa.oneboxprovider.implementations.jive.rest.QPJiveJsonObject.java
/** * Converts a JSON-String to OneBox result. * If an error accours it returns null./*w ww. ja v a 2 s .c o m*/ * * @param json * @return QPIOneBoxResults or null (if error) */ public QPIOneBoxResults convertJsonToResult(String json) { try { this.log.info("Converting JSON message: " + json); QPIOneBoxResults results = new QPOneBoxResults(); JSONObject jsonObject = JSONObject.fromObject(json); MorphDynaBean bean = (MorphDynaBean) JSONObject.toBean(jsonObject); ArrayList<MorphDynaBean> data = (ArrayList<MorphDynaBean>) PropertyUtils.getProperty(bean, JSON_DATA); MorphDynaBean links = this.ensureBeanProperty(bean, JSON_LINKS); if (links != null) { //String next = this.ensureStringProperty(links, JSON_NEXT ); //String previous = this.ensureStringProperty( links, JSON_PREVIOUS ); } MorphDynaBean dataBean; for (int i = 0; i < data.size(); i++) { dataBean = data.get(i); if (dataBean != null) { String type = this.ensureStringProperty(dataBean, JSON_TYPE); String subject = this.ensureStringProperty(dataBean, JSON_SUBJECT); MorphDynaBean author = this.ensureBeanProperty(dataBean, JSON_AUTHOR); String authorName = null; if (author != null) { authorName = this.ensureStringProperty(author, JSON_NAME); //String username = this.ensureStringProperty( author, JSON_USERNAME ); MorphDynaBean authorLinks = this.ensureBeanProperty(author, JSON_LINKS); if (authorLinks != null) { //String alt = this.ensureStringProperty( authorLinks, JSON_ALT ); //String avatar = this.ensureStringProperty( authorLinks, JSON_AVATAR ); } } //Integer replycount = this.ensureIntegerProperty( dataBean, JSON_REPLYCOUNT ); //Integer likecount = this.ensureIntegerProperty( dataBean, JSON_LIKECOUNT ); String contentsummary = this.ensureStringProperty(dataBean, JSON_CONTENTSUMMARY); String htmlref = null; MorphDynaBean resources = this.ensureBeanProperty(dataBean, JSON_RESOURCES); if (resources != null) { MorphDynaBean self = this.ensureBeanProperty(resources, JSON_SELF); if (self != null) { //String selfref = this.ensureStringProperty( self, JSON_REF ); //String selfallowed = this.ensureStringProperty( self, JSON_ALLOWED ); } MorphDynaBean html = this.ensureBeanProperty(resources, JSON_HTML); if (html != null) { htmlref = this.ensureStringProperty(html, JSON_REF); //String htmlallowed = this.ensureStringProperty( html, JSON_ALLOWED ); } } ; //String moddate = this.ensureStringProperty( dataBean, JSON_MODDATE ); MorphDynaBean dataLinks = this.ensureBeanProperty(dataBean, JSON_LINKS); if (dataLinks != null) { //String alt = this.ensureStringProperty( dataLinks, JSON_ALT ); } QPModuleResult result = new QPModuleResult(subject, htmlref); QPModuleResultField field; if (type != null) { field = new QPModuleResultField("type", type); result.addField(field); } if (authorName != null) { field = new QPModuleResultField("author", authorName); result.addField(field); } if (contentsummary != null) { // convert e.g. " " to " " // see http://de.selfhtml.org/html/referenz/zeichen.htm#benannte_iso8859_1 //field = new QPModuleResultField("summary", contentsummary); //result.addField(field); } results.addResult(result); } } this.log.info("Finished converting JSON message."); return results; } catch (Exception exc) { this.log.error("Exception in converting JSON message: ", exc); return null; } }
From source file:gov.nih.nci.calims2.ui.administration.contactinformation.ContactInformationFormTest.java
/** * Test the controller getSubmittedEntity method. * @throws Exception /*from w w w .j a v a 2 s. co m*/ */ @SuppressWarnings("unchecked") @Test public void testGetSubmittedEntity() throws Exception { ContactInformationForm form = new ContactInformationForm(); CRUDFormTestHelper.setNotes(form); form.setStatus(ContactInformationStatus.ACTIVE.name()); form.setTypeId(1L); Stack<StackFrame> context = FlowContextHolder.newContext(); StackFrame frame = new BaseStackFrame(); context.push(frame); frame.addAttribute("persistentClass", persistentClass); frame.addAttribute("id", new Long(1)); ContactInformation entity = form.getSubmittedEntity(); assertNotNull("No submitted Entity", entity); CRUDFormTestHelper.assertNotes(entity); assertEquals("Wrong status in the entity", ContactInformationStatus.ACTIVE, entity.getStatus()); CRUDFormAssert.assertEntity(Type.class, entity.getType(), 1L); EntityWithId result = (EntityWithId) PropertyUtils.getProperty(entity, propertyName); CRUDFormAssert.assertEntity((Class<EntityWithId>) persistentClass, result, 1L); }
From source file:io.fabric8.core.jmx.BeanUtils.java
private static void addProperty(Object obj, String field, Map<String, Object> map) { try {/* w w w .j a v a 2 s. c o m*/ Object prop = PropertyUtils.getProperty(obj, field); map.put(field, prop); } catch (Exception e) { throw new FabricException("Failed to initialize DTO", e); } }