@Override public PropertyFile load(InputStream in, String encoding) throws IOException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); TMXHandler handler = new TMXHandler(file); parser.getXMLReader().setEntityResolver(handler); parser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); parser.parse(in, handler); return file; } catch (ParserConfigurationException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } }
PropertyFile file = PropertiesFactory.eINSTANCE.createPropertyFile(); try { Property p = null;
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>()); }
return PropertiesFactory.eINSTANCE.createPropertyFile();
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ @Override public PropertyFile loadProperties() { URI path = absolutPath(); PropertiesResourceImpl resource = new PropertiesResourceImpl(path); Map<String, Object> options = new HashMap<String, Object>(); if(getProjectLocale()!=null && getProjectLocale().getParent()!=null && getProjectLocale().getParent().getParent()!=null) { options.put(PropertiesResourceImpl.OPTION_FILEMODE, getProjectLocale().getParent().getParent().getPropertyType()); } try { resource.load(options); } catch (FileNotFoundException e) { //The file does not exist, create a new one. logger.debug("Tried to load non-existing property file. Path: {}", path.path()); return PropertiesFactory.eINSTANCE.createPropertyFile(); } catch (IOException e) { throw new RuntimeException(e); } return (PropertyFile) resource.getContents().get(0); }