private Notification computeDiff(Property orignalPropertery, Property modifiedProperty) { if (orignalPropertery.getValue() == null && modifiedProperty.getValue() == null) return null; // if both are null, it's all good if (orignalPropertery.getValue() == null && modifiedProperty.getValue() != null) { return new CustomNotification(Notification.SET, null, modifiedProperty.getValue(), modifiedProperty); } if (modifiedProperty.getValue() == null && orignalPropertery.getValue() != null) { return new CustomNotification(Notification.UNSET, orignalPropertery.getValue(), null, modifiedProperty); } if(modifiedProperty.getValue().equals(orignalPropertery.getValue())) return null; return new CustomNotification(Notification.SET, orignalPropertery.getValue(), modifiedProperty.getValue(), modifiedProperty); }
/** * Decide if we need to update the old {@link Property} with the value of the new one.<br> */ private static boolean updatePropertyValue(Property newProperty, Property oldProperty) { String oldValue = oldProperty == null ? null : oldProperty.getValue(); String newValue = newProperty == null ? null : newProperty.getValue(); /* no translation value was sent. */ if (newProperty == null) { return false; } /* if new is empty, but old is not, we will want to update */ if (!hasValue(oldValue) && !hasValue(newValue)) { return false; } /* only update if values differ */ return !newValue.equals(oldValue); }
public String getOriginal() { if(getTemplate()==null) return ""; //$NON-NLS-1$ return getTemplate().getValue(); }
private List<TerminologyTranslation> analyze(IModel<PropertyPair> pair, Map<String, Property> terminology) { List<TerminologyTranslation> translations = new ArrayList<TerminologyTranslation>(); if(terminology==null || terminology.isEmpty() || pair==null || pair.getObject()==null || pair.getObject().getTemplate() == null) return translations; Collection<String> tokens = getTokens(pair.getObject().getTemplate().getValue(), terminology); for (String term : tokens) { Property property = terminology.get(term); if(property==null) property = terminology.get(term.toLowerCase()); if(property!=null) { translations.add(new TerminologyTranslation(property.getKey(), property.getValue(), property.getComment())); } } return translations; }
public String getTranslated() { if(getTranslation()==null) return ""; //$NON-NLS-1$ return getTranslation().getValue(); }
public void writeProperty(Writer writer, Property property) throws IOException { writeCommentAndAnnotations(writer, property); String key = property.getKey(); key = key.replaceAll("([ :=\n])", "\\\\$1"); if(unicodeEscaping) writer.write(NativeToAsciiConverter.convertUnicodeToEncoded(key,true)); else writer.write(key); writer.write(" = "); String value = property.getValue(); if(value!=null) { //leading spaces need to be masked //see https://github.com/jutzig/jabylon/issues/186 if(value.startsWith(" ")) value = "\\"+value; value = value.replace("\r", "\\r"); value = value.replace("\n", "\\n"); if(unicodeEscaping) value = NativeToAsciiConverter.convertUnicodeToEncoded(value, true); writer.write(value); } writer.write('\n'); }
Field analyzedKey = new Field(QueryService.FIELD_KEY, nullSafe(property.getKey()), Store.YES, Index.ANALYZED); doc.add(analyzedKey); doc.add(new Field(QueryService.FIELD_TMX_VALUE, nullSafe(property.getValue()), Store.YES, Index.ANALYZED));
if(masterProperties.get(property.getKey())!=null && masterProperties.get(property.getKey()).getValue()!=null) { Field masterValueField = new Field(QueryService.FIELD_MASTER_VALUE, masterProperties.get(property.getKey()).getValue(), Store.YES, Index.ANALYZED); doc.add(masterValueField); Field analyzedKey = new Field(QueryService.FIELD_KEY, nullSafe(property.getKey()), Store.YES, Index.ANALYZED); doc.add(analyzedKey); Field value = new Field(QueryService.FIELD_VALUE, nullSafe(property.getValue()), Store.YES, Index.ANALYZED); doc.add(value); String templateLocation = descriptor.getMaster() == null ? "" : descriptor.getMaster().getLocation().toString();
if(current.getValue()==null || current.getKey()==null)
/** * If we make it here, we know that the {@link Property} exists in the master * {@link PropertyFileDescriptor}, but we don't know if a corresponding {@link Property} exists * for the existing {@link PropertyFile}. If it does not, we create a new {@link Property}.<br> * * Hence perform a quick check, and create a new {@link Property} which we add to this * {@link PropertyFileDescriptor} if it does not yet exist.<br> */ private static void updateExistingProperty(PropertyFile existingFile, Property existingProperty, Property newProperty) { if (existingProperty == null) { existingProperty = PropertiesFactory.eINSTANCE.createProperty(); existingProperty.setKey(newProperty.getKey()); existingFile.getProperties().add(existingProperty); } existingProperty.setValue(newProperty.getValue()); existingProperty.setComment(newProperty.getComment()); }
@Override protected void onSubmit() { super.onSubmit(); IModel<List<? extends PropertyPair>> model = getModel(); List<? extends PropertyPair> list = model.getObject(); PropertyFileDescriptor descriptor = PropertyEditorPanel.this.getModelObject(); PropertyFile file = descriptor.loadProperties(); Map<String, Property> map = file.asMap(); for (PropertyPair pair : list) { Property translation = pair.getTranslation(); if(translation==null) continue; if (map.containsKey(translation.getKey())) { Property property = map.get(translation.getKey()); property.setComment(translation.getComment()); property.setValue(translation.getValue()); } else file.getProperties().add(translation); } propertyPersistence.saveProperties(descriptor, file); getSession().info("Saved successfully"); try { //TODO: this is very unclean... // give it some time to store the values Thread.sleep(500); } catch (InterruptedException e) { logger.error("Interrupted while waiting for property persistence",e); } } };
Property property = map.get(translation.getKey()); property.setComment(translation.getComment()); property.setValue(translation.getValue()); } else if (!isEmpty(translation.getValue())) { file.getProperties().add(translation); if (translation.getValue() != null) { for (Review review : reviews) { if (review.getState() == ReviewState.OPEN && Review.KIND_SUGGESTION.equals(review.getReviewType())) { if (translation.getValue().equals(review.getMessage())) { try { TransactionUtil.commit(review, new Modification<Review, Review>() { review.setCreated(System.currentTimeMillis()); review.setKey(translation.getKey()); review.setMessage(translation.getValue()); review.setSeverity(Severity.INFO); review.setReviewType(Review.KIND_SUGGESTION);
if(origProp==null) continue; if(newProp.getValue()!=null && !newProp.getValue().isEmpty() && !newProp.getValue().equals(origProp.getValue())) origProp.setValue(newProp.getValue()); origProp.setComment(newProp.getComment()); if(origProp==null) continue; if(newProp.getValue()!=null && !newProp.getValue().isEmpty() && !newProp.getValue().equals(origProp.getValue())) review.setCreated(System.currentTimeMillis()); review.setKey(newProp.getKey()); review.setMessage(newProp.getValue()); review.setSeverity(Severity.INFO); review.setReviewType(Review.KIND_SUGGESTION);