Eclipse RCP XMLMultiPageEditorPart errors - rcp

all
When I use XMLMultiPageEditorPart, it makes some errors.
File file = new File(path);
IEditorInput input = new XMLPInput(file);
try {
page.openEditor(input, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");
} catch (PartInitException e) {
MessageDialog.openError(window.getShell(), "", path);
}
Errors:
org.eclipse.ui.PartInitException: Text
editor does not have a document
provider at
org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3075)
at
org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3088)
at
org.eclipse.wst.sse.ui.StructuredTextEditor.init(StructuredTextEditor.java:2553)
at
org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:237)
at
org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:211)
I think XMLMultiPageEditorPart should has its own provider? could anyone help me ?

Where did you get the class XMLPInput from? As you are using File, why can't you use the standard FiledEditorInput or FileStoreEditorInput?

Related

update profile image functionality is not working while hosting as jar

Hi I am new to Springboot I was trying to develop a application, One of its functionality is to upload profile Image. It was working fine in STS but when I pack it in jar and hosting it on AWS EC2 envirnment I am getting some error while processing that image
Error:
handler for profile picture:
#PostMapping("/process-contact")
public String processContact(#ModelAttribute Contact contact, #RequestParam("profileImage") MultipartFile file,
HttpSession session) {
try {
contact.setUser(user);
user.getContacts().add(contact);
// processing and uploading photo
if (file.isEmpty()) {
System.out.println("File is empty");
contact.setImage("contact.png");
} else {
//Processing Image
InputStream inputStream = file.getInputStream();
Path paths = Paths.get(new ClassPathResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
Files.copy(inputStream, paths, StandardCopyOption.REPLACE_EXISTING);
contact.setImage(file.getOriginalFilename());
}
// Success Message
session.setAttribute("message", new Message("Your contact is added...", "success"));
this.userRepository.save(user);
System.out.println("Successfully Added");
} catch (Exception E) {
E.printStackTrace();
// Failed message
session.setAttribute("message", new Message("Something went wrong "+E.getMessage(), "danger"));
}
return "normal/add_contact_form";
}
It is working fine in IDE after some research I found way of writing data in jar is diffrent could some please help me how can I implemenr it for jar also.
Thankyou
all you need to do is replace this line:
Path paths = Paths.get(new ClassPathResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
With:
Path paths = Paths.get(new FileSystemResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
THat will work like charm.

VS UnitTesting a FileContentResult - Can I generate the file when testing

I want to Unit Test a method that returns a FileContentResult of a PDF file. I am doing some tests to check the content type & file name, but it would be great if I could also generate the PDF somehow as part of the test? I currently have a method as follows:
public FileContentResult ConvertToPDF(int baseClassId)
{
try
{
return new DocumentWriter().ConvertDocumentToPDFSharp(baseClassId);
}
catch (Exception ex)
{
Logger.Instance.LogError("Error in Assessments_FormHeaderController ConvertToPDF", ex);
return new FileContentResult(GetBytes("Error fetching pdf, " + ex.Message + Environment.NewLine + ex.StackTrace), "text/plain");
}
}
and I am testing with the following:
[TestMethod]
public void ReturnFileContentResult()
{
DocumentPDFPrinterController pdfController = new DocumentPDFPrinterController();
FileContentResult result = pdfController.ConvertToPDF(0);
Assert.IsTrue(result.ContentType == "application/pdf" && result.FileDownloadName.Contains(".pdf"));
}
Can I add anything to this text which will create the pdf file in a given location(user downloads?).
Should have done some more investigating before putting the question out there. I have found simply adding the following got the job done for me:
System.IO.File.WriteAllBytes(#"C:\Users\username\Downloads\Test.pdf", result.FileContents);
That generates my file nicely.

PCLStorage - How to get path to writable folder?

I need download and save file. I using this code (with Xam.Plugins.DownloadManager and PCLStorage libraries):
public static string DownloadNewXml(string LinkToFile, string PathFile)
{
var downloadManager = CrossDownloadManager.Current;
CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file => {
return PathFile;
});
try
{
var file = downloadManager.CreateDownloadFile(LinkToFile);
downloadManager.Start(file);
return "ok";
}
catch(Exception e)
{
return e.ToString() ;
}
}
Where PathFile is: FileSystem.Current.LocalStorage.Path + "file.xml";
This code throw exception on Android and UWP - i can't write file to this path (FileSystem.Current.LocalStorage.Path). So I have a question. How to get path to writable folder for my application on all platforms (Android, UWP, iOS)? Please help.
Try use Path.Combine(FileSystem.Current.LocalStorage.Path, "file.xml") instead

Open Uri to read JSON file in background task UWP

I have a use case where I have to read a config.json file from an AppService and based on the configuration in json file I have to generate an ID.
I am using following piece of code to generate the Uri so that I can open the file using StorageFile.GetFileFromApplicationUriAsync(fileUri).
Uri fileUri = null;
try
{
Debug.WriteLine("Creating new uri");
fileUri = new Uri(fileName);
if (fileUri == null)
{
Debug.WriteLine("Uri creation failed");
} else
{
Debug.WriteLine("New Uri created");
}
} catch (Exception ex)
{
Debug.WriteLine("Uri creation failed" + ex.Message);
}
Now when I am trying to debug this code my debugger is disappearing after line with new Uri(fileName)
If I just let the code run with no breakpoints I am not seeing any message after Creating new uri. Not even an exception.
Value of fileName is "ms-appx:///config/config.json"
Can anyone please explain what is wrong here? Also is it possible to open and read a file from an AppService?
--
Thanks
Tarun
The uri use appx only can read the resource is content in msbuild.
You can right click the file and select the property and you should select the file's build action as content.
http://jycloud.9uads.com/web/GetObject.aspx?filekey=449e34647d61faca2ce846b773a4da8e
http://jycloud.9uads.com/web/GetObject.aspx?filekey=5423b79037eee8dc66431d0478d79871
http://jycloud.9uads.com/web/GetObject.aspx?filekey=6189eb9547c6f2fa79333df67ab33cef
You can see the last image is use complie and you can change it to content.
Sorry, my visual studio's language is local language.But the visual studio's have the same layout.

write file into spring boot folder

my spring boot project structure is like this
src
|-main
|--|-java
|--|-resources
static
|-css
|-images
|-js
now I want to write a file into the static/images folder
I tried to new File like
BufferedOutputStream stream =new BufferedOutputStream(new FileOutputStream(new File("static/images")));it will throw "No such file or directory" exception
but in other html file I can get the js by "js/jsFile.js"
new File("static/images") is right
I used new File("/static/images") so I got an Exception
I was in the situation where using Spring Boot I had to save the image into one directory which is accessed statically.
Below code worked perfect
byte[] imageByteArray ....
String fileName = "image.png";
String fileLocation = new File("static\\images").getAbsolutePath() + "\\" + fileName;
FileOutputStream fos = new FileOutputStream(fileLocation);
fos.write(imageByteArray);
fos.close();
Hope it helped.
#zhuochen shen is correct.
The thing is to happen me is Eclipse doesn't show write file. So I looked at file explore. File is writing correctly.
try {
Path path=Paths.get("static/images/"+productDto.getImage().getOriginalFilename());
Files.write(path,productDto.getImage().getBytes());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
enter image description here
enter image description here

Resources