@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String stringValue; if(getValue() == null) stringValue = null; else try { stringValue = BeansUtils.attributeValueToString(this); } catch (InternalErrorException ex) { //WARNING: This error is not catched. There is very low chance to occur. //When this happens, error is logged and there is need to look on attributeValueToString script above. log.error("Attribute value can't be serialize! {}",ex); stringValue = null; } return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", friendlyName=<").append(getFriendlyName() == null ? "\\0" : BeansUtils.createEscaping(getFriendlyName())).append(">").append( ", namespace=<").append(getNamespace() == null ? "\\0" : BeansUtils.createEscaping(getNamespace())).append(">").append( ", type=<").append(getType() == null ? "\\0" : BeansUtils.createEscaping(getType())).append(">").append( ", unique=<").append(isUnique()).append(">").append( ", value=<").append(BeansUtils.createEscaping(stringValue)).append(">").append( ']').toString(); }
private static Destination createDestination(Map<String, String> beanAttr) { if(beanAttr==null) return null; Destination destination = new Destination(); destination.setId(Integer.valueOf(beanAttr.get("id"))); destination.setDestination(BeansUtils.eraseEscaping(beanAttr.get("destination"))); destination.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); destination.setPropagationType(BeansUtils.eraseEscaping(beanAttr.get("propagationtype"))); return destination; }
private static Authorship createAuthorship(Map<String, String> beanAttr) throws InternalErrorException { if(beanAttr==null) return null; Authorship authorship = new Authorship(); authorship.setId(Integer.valueOf(beanAttr.get("id"))); authorship.setPublicationId(Integer.valueOf(beanAttr.get("publicationId"))); authorship.setUserId(Integer.valueOf(beanAttr.get("userId"))); authorship.setCreatedBy(BeansUtils.eraseEscaping(beanAttr.get("createdBy"))); authorship.setCreatedByUid((beanAttr.get("createdByUid").equals("\\0")) ? null : Integer.valueOf(beanAttr.get("createdByUid"))); if(BeansUtils.eraseEscaping(beanAttr.get("createdDate"))== null) authorship.setCreatedDate(null); else { Date date; try { date = BeansUtils.getDateFormatter().parse(BeansUtils.eraseEscaping(beanAttr.get("createdDate"))); } catch (ParseException ex) { throw new InternalErrorException("Error when date was parsing from String to Date.", ex); } authorship.setCreatedDate(date); } return authorship; }
private static Attribute createAttribute(Map<String, String> beanAttr) throws InternalErrorException { if(beanAttr==null) return null; Attribute attribute = new Attribute(); attribute.setId(Integer.valueOf(beanAttr.get("id"))); attribute.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attribute.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attribute.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); attribute.setValue(BeansUtils.stringToAttributeValue(BeansUtils.eraseEscaping(beanAttr.get("value")), attribute.getType())); attribute.setUnique(Boolean.valueOf(beanAttr.get("unique"))); return attribute; }
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String dateString; if(timestamp != null) dateString = BeansUtils.getDateFormatter().format(timestamp); else dateString = "\\0"; return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", taskId=<").append(taskId).append(">").append( ", destinationId=<").append(destinationId).append(">").append( ", errorMessage=<").append(errorMessage== null ? "\\0" : BeansUtils.createEscaping(errorMessage.toString())).append(">").append( ", standardMessage=<").append(standardMessage== null ? "\\0" : BeansUtils.createEscaping(standardMessage.toString())).append(">").append( ", returnCode=<").append(returnCode).append(">").append( ", timestamp=<").append(dateString).append(">").append( ", status=<").append(status == null ? "\\0" : BeansUtils.createEscaping(status.toString())).append(">").append( ", service=<").append(service == null ? "\\0" : service.serializeToString()).append(">").append( ']').toString(); }
if (!BeansUtils.isEscaped(text, i - 1)) { startName = i; if (!BeansUtils.isEscaped(text, i - 1)) { endName = i; notValue = false; if (!BeansUtils.isEscaped(text, i - 1)) { startValue = i; if (!BeansUtils.isEscaped(text, i - 1)) { endValue = i; notValue = true; map.put(BeansUtils.eraseEscaping(text.substring(startName + 1, endName)), BeansUtils.eraseEscaping(text.substring(startValue + 1, endValue))); startName = -1; endName = -1;
/** * Converts attribute value to string (serialize object to string). * This is a wrapper for passing value and type only for specific use. * @see #attributeValueToString(Attribute) * * @param attributeValue value of the attribute * @param type type of resulting attribute * @return string representation of the value * * @throws InternalErrorException */ @SuppressWarnings("unchecked") public static String attributeValueToString(Object attributeValue, String type) throws InternalErrorException { Attribute a = new Attribute(); a.setType(type); a.setValue(attributeValue); return attributeValueToString(a); }
/** * Serialize map to string * * @param map * @return string of escaped map */ static String serializeMapToString(Map<String, String> map) { if(map == null) return "\\0"; Map<String, String> attrNew = new HashMap<String, String>(map); Set<String> keys = new HashSet<String>(attrNew.keySet()); for(String s: keys) { attrNew.put("<" + BeansUtils.createEscaping(s) + ">", "<" + BeansUtils.createEscaping(attrNew.get(s)) + ">"); attrNew.remove(s); } return attrNew.toString(); }
@Override public String toString() { StringBuilder str = new StringBuilder(); str.append(getClass().getSimpleName()).append(":[status='").append(status) .append("', startTime='").append((startTime!=null) ? BeansUtils.getDateFormatter().format(startTime) : startTime) .append("', endTime='").append((endTime!=null) ? BeansUtils.getDateFormatter().format(endTime) : endTime) .append("', returnCode='").append(returnCode) .append("', task='").append(task) .append("', destination='").append(destination) .append("', stdout='").append(stdout) .append("', stderr='").append(stderr) .append("']"); return str.toString(); }
/** * This method get text and all nonescaped characters < and > replace by apostrophe * * @param text * @return text where nonescaped characters < and > will be reaplace by apostrophe ' */ public static String replacePointyBracketsByApostrophe(String text) { StringBuilder stringBuilder = new StringBuilder(text); for(int i=0; i<text.length(); i++) { if(text.charAt(i)=='<' || text.charAt(i)=='>') { if(!isEscaped(text, i-1)) { stringBuilder.setCharAt(i, '\''); } } } return stringBuilder.toString(); }
@Override public void removeAllPoolMessages(Set<Integer> proccessedIds) { if (proccessedIds == null || proccessedIds.isEmpty()) { return; } logger.debug("Removing poolMessages from db with ids: {}", proccessedIds); StringBuffer buffer = new StringBuffer(); buffer.append("delete from pn_pool_message where " + BeansUtils.prepareInSQLClause(new ArrayList<Integer>(proccessedIds), "id")); this.getJdbcTemplate().update(buffer.toString()); logger.debug("PoolMessages with id: {}, removed.", proccessedIds); }
LinkedHashMap<String, String> additionalAttributes = (LinkedHashMap<String, String>)BeansUtils.stringToAttributeValue(app.getFedInfo(), LinkedHashMap.class.getName()); ((PerunBlImpl)perun).setUserExtSourceAttributes(sess, ues, additionalAttributes); } catch (Exception ex) {
public boolean hasRole(Role role, String perunBeanName, int id) { //Use converted beanName instead of classic bean name, because for ex.: RichGroup is the same like Group for this purpose String convertedBeanName = BeansUtils.convertRichBeanNameToBeanName(perunBeanName); return this.get(role).containsKey(convertedBeanName) && this.get(role).get(convertedBeanName).contains(id); }
sb.append(" in ("); List<Integer> partOfBeansIds = beansIds.subList(0, MAX_SIZE_OF_ITEMS_IN_SQL_IN_CLAUSE); sb.append(beanIdsToString(partOfBeansIds)); sb.append(") "); partOfBeansIds.clear(); sb.append(identifier); sb.append(" in ("); sb.append(beanIdsToString(beansIds)); sb.append(") ");
private static Candidate createCandidate(Map<String, String> beanAttr) { if(beanAttr==null) return null; Candidate candidate = new Candidate(); candidate.setAttributes(BeansUtils.deserializeStringToMap(beanAttr.get("attributes"))); //Parse and get ExtSource UserExtSource userExtSource; if(beanAttr.get("userExtSource").equals("\\0")) userExtSource = null; else { List<Pair<String, Map<String, String>>> userExtSourceMap = beansToMap(beanAttr.get("userExtSource")); userExtSource = createUserExtSource(userExtSourceMap.get(0).getRight()); } candidate.setUserExtSource(userExtSource); //Parse and get list of UserExtSources List<UserExtSource> additionalUserExtSources = new ArrayList<UserExtSource>(); if(beanAttr.get("additionalUserExtSources").equals("\\0")) additionalUserExtSources = null; else { List<Pair<String, Map<String, String>>> userExtSourcesList = beansToMap(beanAttr.get("additionalUserExtSources")); for(Pair<String, Map<String, String>> p: userExtSourcesList) { userExtSource = createUserExtSource(p.getRight()); additionalUserExtSources.add(userExtSource); } } candidate.setAdditionalUserExtSources(additionalUserExtSources); return candidate; }
footer = BeansUtils.attributeValueToString(attribute);
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", hostname=<").append(getHostname() == null ? "\\0" : BeansUtils.createEscaping(getHostname())).append(">").append( ']').toString(); }
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String dateString; if(getCreatedDate() != null) dateString = BeansUtils.getDateFormatter().format(getCreatedDate()); else dateString = "\\0"; return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", userId=<").append(getUserId()).append(">").append( ", publicationId=<").append(getPublicationId()).append(">").append( ", createdBy=<").append(getCreatedBy() == null ? "\\0" : BeansUtils.createEscaping(getCreatedBy())).append(">").append( ", createdDate=<").append(dateString).append( ">").append( ", createdByUid=<").append(getCreatedByUid()).append(">").append( "]").toString(); }
@Override public String toString() { StringBuilder str = new StringBuilder(); return str.append(getClass().getSimpleName()) .append(":[base='").append(BeansUtils.getDateFormatter().format(base)) .append("', delay='").append((delay == 0) ? delay : delay/1000).append("s") .append("', remaining='").append(getDelay(TimeUnit.SECONDS)).append("s") .append("', delayCount='").append(delayCount) .append("', task='").append(task) .append("']").toString(); }
/** * This method get text and all escaped \0 replace for text null * * @param text * @return text where \0 is replaced for null */ public static String replaceEscapedNullByStringNull(String text) { StringBuilder stringBuilder = new StringBuilder(text); for(int i=0; i<stringBuilder.length(); i++) { if(stringBuilder.charAt(i)=='0') { if(isEscaped(stringBuilder.toString(), i-1)) { stringBuilder.replace(i-1, i+1, "null"); i=i+2; } } } return stringBuilder.toString(); }