/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated NOT */ public Property getProperty(String key) { EList<Property> eList = getProperties(); synchronized (eList) { for (Property property : eList) { if (key.equals(property.getKey())) return property; } } return null; }
private Map<String, Property> buildMap(PropertyFile file) { Map<String, Property> properties = new HashMap<String, Property>(file.getProperties().size()); for (Property property : file.getProperties()) { properties.put(property.getKey(), property); } return properties; }
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated NOT */ public Map<String, Property> asMap() { EList<Property> properties = getProperties(); if(map!=null && properties.size()==map.size()) { return map; } synchronized (properties) { map = new ConcurrentHashMap<String, Property>(properties.size()); for (Property property : getProperties()) { map.put(property.getKey(), property); } return map; } }
private void computeStructuralDiff(Map<String, Property> orignalProperties, PropertyFile modified, List<Notification> noticiations) { List<Property> additions = new ArrayList<Property>(); List<Property> removals = new ArrayList<Property>(); for (Property prop : modified.getProperties()) { Property originalProperty = orignalProperties.get(prop.getKey()); if (originalProperty == null) additions.add(prop); else { orignalProperties.remove(prop.getKey()); Notification change = computeDiff(originalProperty, prop); if(change!=null) noticiations.add(change); } } removals.addAll(orignalProperties.values()); if(!additions.isEmpty()) { Notification notification = new ENotificationImpl((InternalEObject) modified,Notification.ADD_MANY, PropertiesPackage.Literals.PROPERTY_FILE__PROPERTIES,null, additions); noticiations.add(notification); } if(!removals.isEmpty()) { Notification notification = new ENotificationImpl((InternalEObject) modified,Notification.ADD_MANY, PropertiesPackage.Literals.PROPERTY_FILE__PROPERTIES,removals, null); noticiations.add(notification); } }
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'); }
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; }
private void createMessageFile(InputStream in, URI target, boolean isTemplate) throws IOException { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); Property property = null; POHelper helper = new POHelper(); PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); while((property=helper.readProperty(reader))!=null) { if(isTemplate) { property.setValue(property.getKey()); //get rid of the german comment property.setComment(null); } file.getProperties().add(property); } PropertiesResourceImpl resource = new PropertiesResourceImpl(target); resource.getContents().add(file); resource.save(new HashMap<Object, Object>()); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getMessage(),e); } finally { reader.close(); } }
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { boolean template = false; URL url = new URL("http://pootle.locamotion.org/export/terminology/de/essential.po"); InputStream openStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(openStream, "UTF-8")); Property property = null; POHelper helper = new POHelper(); PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); while((property=helper.readProperty(reader))!=null) { if(template) property.setValue(property.getKey()); file.getProperties().add(property); } PropertiesResourceImpl resource = new PropertiesResourceImpl(org.eclipse.emf.common.util.URI.createFileURI("messages.properties")); resource.getContents().add(file); resource.save(new HashMap<Object, Object>()); }
public Property getOrCreateTranslation() { Property property = getTranslation(); if(property==null) { property = PropertiesFactory.eINSTANCE.createProperty(); property.setKey(getTemplate().getKey()); this.translation = property; } return property; }
ret.put(property.getKey(), property);
@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); } } };
/** * Merges a {@link Map} of {@link Property}s into the existing {@link PropertyFileDescriptor}.<br> * TODO: Possibly merge with persist logic in {@link PropertyListPanel}.<br> * * @return count of updated properties.<br> */ private static int merge(Map<String, Property> newProperties, PropertyFileDescriptor descriptor) throws ExecutionException { PropertyFile existingFile = getPersistenceService().loadProperties(descriptor); Map<String, Property> existingProperties = existingFile.asMap(); Map<String, Property> master = descriptor.getMaster().loadProperties().asMap(); int updateCount = 0; for (Property newProperty : newProperties.values()) { Property existingProperty = existingProperties.get(newProperty.getKey()); if (!master.containsKey(newProperty.getKey())) { continue; // we're not creating new K/V pairs, only updating. } if (!updatePropertyValue(newProperty, existingProperty)) { continue; // not setting null, but we allow empty (value deletion). } updateExistingProperty(existingFile, existingProperty, newProperty); updateCount++; // trigger persist. } if (updateCount > 0) { getPersistenceService().saveProperties(descriptor, existingFile); } return updateCount; }
protected List<PropertyPair> createContents() { PropertyFileDescriptor descriptor = model.getObject(); Multimap<String, Review> reviews = reviewModel.getObject(); PropertyFileDescriptor master = descriptor.getMaster(); Map<String, Property> translated = descriptor.loadProperties().asMap(); PropertyFile templateFile = master.loadProperties(); List<PropertyPair> contents = new ArrayList<PropertyPair>(); for (Property property : templateFile.getProperties()) { // IModel<String> bind = model.bind(property.getKey()); // bind.set PropertyPair pair = new PropertyPair(property, translated.remove(property.getKey()),descriptor.getVariant(), descriptor.cdoID()); String key = pair.getKey(); if (mode.apply(pair,reviews.get(key))) contents.add(pair); } for (Property property : translated.values()) { PropertyPair pair = new PropertyPair(null, property,descriptor.getVariant(), descriptor.cdoID()); if (mode.apply(pair,reviews.get(pair.getKey()))) contents.add(pair); } return contents; }
if(current.getValue()==null || current.getKey()==null)
protected List<PropertyPair> createContents() { PropertyFileDescriptor descriptor = model.getObject(); Multimap<String, Review> reviews = reviewModel.getObject(); PropertyFileDescriptor master = descriptor.isMaster() ? descriptor : descriptor.getMaster() ; Map<String, Property> translated = new HashMap<String, Property>(loadProperties(descriptor).asMap()); PropertyFile templateFile = loadProperties(master); List<PropertyPair> contents = new ArrayList<PropertyPair>(); for (Property property : templateFile.getProperties()) { // IModel<String> bind = model.bind(property.getKey()); // bind.set PropertyPair pair = new PropertyPair(property, translated.remove(property.getKey()), descriptor.getVariant(), descriptor.cdoID()); String key = pair.getKey(); if (mode.apply(pair, reviews.get(key))) contents.add(pair); } for (Property property : translated.values()) { PropertyPair pair = new PropertyPair(null, property, descriptor.getVariant(), descriptor.cdoID()); if (mode.apply(pair, reviews.get(pair.getKey()))) contents.add(pair); } return contents; }
/** * 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()); }