Compatibility issues with Aspose.Words for Java Beta 10.0.0 Java

Hi,
I’ve tried to migrate existing code to Aspose.Words for Java Beta 10.0.0. The following syntax errors occurred on formerly correct code:

constructors missing:

Document(java.io.InputStream stream, java.lang.String baseUri, int loadFormat, java.lang.String password)
Document(java.lang.String fileName, int loadFormat, java.lang.String password)

Constant names have changed:

PaperSize.A5 ->PaperSize.A_5 …

method missing:

Document.saveToPdf

class missing:

PdfOptions

method missing:

Document.getSaveOptions() 

cannot find symbol:

com.aspose.words.ExportImageSavingEventHandler

incorrect method return type:
DocumentBuilder 4.0.2:

public FieldStart insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)

DocumentBuilder 10 beta:

public Field insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)

NodeList fieldStarts = getDocumentBuilder().getDocument().selectNodes("//FieldStart");
for (Node fieldStartNode: fieldStarts)
{}

required com.aspose.words.Node, found java.lang.Object

BuiltInDocumentProperties.getCreatedTime / setCreatedTime -> methods do not exist
DocumentProperty dp;
dp.toDateTime() -> Method does not exist

for (Section srcSection: srcDocument.getSections())
{…}

required com.aspose.words.Section, found java.lang.Object

VariableCollection variableCollectionSrc = p_docSource.getVariables();
for (Map.Entry entry: variableCollectionSrc)
{…}

required Map.entry, found java.lang.Object
Will these errors be corrected in the release version?

BR, Torsten

Hi
Thanks for your request. Yes, you are right, API of Aspose.Words for Java was changed a bit, but no functionality was lost.

THaase:
constructors missing:
Document(java.io.InputStream stream, java.lang.String baseUri, int loadFormat, java.lang.String password)
Document(java.lang.String fileName, int loadFormat, java.lang.String password)

You should use Document(InputSteam stream, LoadOptions options) and Document(String fileName, LoadOptions options) constructopr instead of these two.

THaase:
Constant names have changed:
PaperSize.A5 ->PaperSize.A_5 …

Yes, constants were renamed.Now you should use PaperSize.A_5 instead of old PaperSize.A5

THaase:
method missing:
Document.saveToPdf

Yes, this method was removed. Now you should use Document.save method and specify extension, SaveFormat or Saveoptions to specify output format. For example to save to PDF you should use code like this:

// Open document.
Document doc = new Document("C:\\Temp\\in.doc");
// Save as PDF.
doc.save("C:\\Temp\\out.pdf");

THaase:
class missing:
PdfOptions

This class was replaced with PdfSaveOptions:

// Open document.
Document doc = new Document("C:\\Temp\\in.doc");
// Create PdfSaveoptions.
PdfSaveOptions opt = new PdfSaveOptions();
opt.setJpegQuality(80);
// Save as PDF.
doc.save("C:\\Temp\\out.pdf", opt);

THaase:
method missing:
Document.getSaveOptions()

This property was removed. Now you should spacify SaveOptions as a parameter of Document.save method, just like shown in the code example above. There are save options for each format, like OoxmlSaveOptions, HtmlSaveOptions, DocSaveOptions, PdfSaveOptions, XpsSaveOptions, SwfSaveOptions, RtfSaveOptions…

THaase:
cannot find symbol:
com.aspose.words.ExportImageSavingEventHandler

Now you should use IImageSavingCallback. Please see the code below:

@Test
public void Test001() throws Exception
{
    Document doc = new Document("C:\\Temp\\in.doc");
    HtmlSaveOptions opt = new HtmlSaveOptions(SaveFormat.HTML);
    opt.setImageSavingCallback(new ImageSavingCallback());
    doc.save("C:\\Temp\\out.html", opt);
}
private class ImageSavingCallback implements IImageSavingCallback
{
    public void imageSaving(ImageSavingArgs imageSavingArgs) throws Exception
    {
        // implement your logic here.
    }
}

THaase:
incorrect method return type:
DocumentBuilder 4.0.2:
public FieldStart insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)
DocumentBuilder 10 beta:
public Field insertHyperlink(java.lang.String displayText, java.lang.String urlOrBookmark, boolean isBookmark)

In the new API insertHyperlink method returns an instance of Field class. If you need to get FieldStart, you can use code like this:

DocumentBuilder builder = new DocumentBuilder();
Field fld = builder.insertHyperlink("www.aspose.com", "www.aspose.com", false);
FieldStart fldStart = fld.getStart();

THaase:
NodeList fieldStarts = getDocumentBuilder().getDocument().selectNodes("//FieldStart");
for (Node fieldStartNode : fieldStarts)
{}
required com.aspose.words.Node, found java.lang.Object

Yes, in the current version there is a problem with generic collections. We will resolve this problem before releasing a production version of Aspose.Words for Java.

THaase:
BuiltInDocumentProperties.getCreatedTime/setCreatedTime -> methods do not exist

Yes, I see this problem. We are still working on the public API. Currently this property is named CreatedTimePublic. We will rename it in the production version.

THaase:
DocumentProperty dp;
dp.toDateTime() ->Method does not exist

The same problem as described in previous item. Currently this method is named DocumentProperty.toDateTimePublic() .

THaase:
for (Section srcSection : srcDocument.getSections())
{…}
required com.aspose.words.Section, found java.lang.Object

The same problem with generic collections as described earlier.

THaase:
VariableCollection variableCollectionSrc = p_docSource.getVariables();
for (Map.Entry entry : variableCollectionSrc)
{…}
required Map.entry, found java.lang.Object

The same problem with generic collections as described earlier.
Best regards,

The issues you have found earlier (filed as 25810) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(28)

Hi there,
Just to clarify, the issues fixed in the latest version is the issues related to generics missing off NodeCollection based classes and the incorrectly named members ending with “Public”.
Thanks,