Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to change encoding ascii to utf-8
How to change encoding ascii to utf-8 [message #1707384] Fri, 04 September 2015 12:11 Go to next message
Serhat Celik is currently offline Serhat CelikFriend
Messages: 10
Registered: July 2015
Junior Member
I created an ecore api from xsd. But when write to xml file, encoding is ascii. I want to change this ascii to utf-8. How can I do that?


    ResourceSet resourceSet = new ResourceSetImpl();

    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
        .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new exampleResourceFactoryImpl());

    resourceSet.getPackageRegistry().put(examplePackage.eNS_URI, examplePackage.eINSTANCE);

    URI uri = URI.createFileURI(location);

    Resource res = resourceSet.getResource(uri, true);

    DocumentRoot documentRoot = exampleFactory.eINSTANCE.createDocumentRoot();

    res.getContents().add(documentRoot);
   
    try {
      res.save(null);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
Re: How to change encoding ascii to utf-8 [message #1707388 is a reply to message #1707384] Fri, 04 September 2015 12:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
You can use org.eclipse.emf.ecore.xmi.XMLResource.OPTION_ENCODING or
org.eclipse.emf.ecore.xmi.XMLResource.setEncoding(String). You might
want to do that in the generated resource factory implementation so that
it's the default.

On 04/09/2015 2:11 PM, Serhat Celik wrote:
> I created an ecore api from xsd. But when write to xml file, encoding
> is ascii. I want to change this ascii to utf-8. How can I do that?
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new
> exampleResourceFactoryImpl());
>
> resourceSet.getPackageRegistry().put(examplePackage.eNS_URI,
> examplePackage.eINSTANCE);
>
> URI uri = URI.createFileURI(location);
>
> Resource res = resourceSet.getResource(uri, true);
>
> DocumentRoot documentRoot =
> exampleFactory.eINSTANCE.createDocumentRoot();
>
> res.getContents().add(documentRoot);
> try {
> res.save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
Re: How to change encoding ascii to utf-8 [message #1707392 is a reply to message #1707388] Fri, 04 September 2015 12:56 Go to previous messageGo to next message
Serhat Celik is currently offline Serhat CelikFriend
Messages: 10
Registered: July 2015
Junior Member
Thanks for reply .I will try that.

[Updated on: Fri, 04 September 2015 14:08]

Report message to a moderator

Re: How to change encoding ascii to utf-8 [message #1707452 is a reply to message #1707392] Fri, 04 September 2015 19:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30541
Registered: July 2009
Senior Member
You (or someone) is loading a resource that doesn't exist. What can I
say. You have a debugger, so you can see what's going on.

On 04/09/2015 2:57 PM, Serhat Celik wrote:
> Thanks for reply .I will try that.
> I want to ask another question. resourceSet.getResource(uri, true)
> In first time , this method throw an exception in runtime but in debug
> there is no exception and create xml file successfully. Why ?
>
> org.eclipse.e4.core.di.InjectionException:
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> java.io.FileNotFoundException:
> C:\Users\3\runtime-EclipseApplication\XmlFile.xml (The system cannot
> find the file specified)
> at
> org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
> at
> org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
> at
> org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
> at
> org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
> at
> org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
> at
> org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
> at
> org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
> at
> org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
> at
> org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
> at
> org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
> at
> org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:659)
> at
> org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:592)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
> at
> org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
> at
> org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
> at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
> at
> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
> Caused by:
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> java.io.FileNotFoundException:
> C:\Users\3\runtime-EclipseApplication\XmlFile.xml (The system cannot
> find the file specified)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
> at com.example.test.Utilities.getResource(Utilities.java:123)
> at com.example.test.Utilities.parse(Parser.java:92)
> at com.example.test.Utilities.<init>(Parser.java:60)
> at
> com.example.test.command.ParseHandler.execute(ParseHandler.java:82)
> at
> org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
> at
> org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
> at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
> ... 38 more
> Caused by: java.io.FileNotFoundException:
> C:\Users\3\runtime-EclipseApplication\XmlFile.xml (The system cannot
> find the file specified)
> at java.io.FileInputStream.open0(Native Method)
> at java.io.FileInputStream.open(Unknown Source)
> at java.io.FileInputStream.<init>(Unknown Source)
> at
> org.eclipse.emf.ecore.resource.impl.FileURIHandlerImpl.createInputStream(FileURIHandlerImpl.java:99)
> at
> org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:360)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1269)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
> ... 49 more
Previous Topic:[EMF] long loading time
Next Topic:FileNotFoundException
Goto Forum:
  


Current Time: Mon Oct 14 16:05:50 GMT 2019

Powered by FUDForum. Page generated in 0.01786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top