Page 1 of 1

concerning the method WordprocessingMLPackage.load(File)……

PostPosted: Thu May 19, 2011 9:04 pm
by tosswang
hi,jason:
i want to creat a instance of WordprocessingMLPackage via the method WordprocessingMLPackage.load(),now i have a inputStream instance,but,load method's paramter is File,i don't want to create a physical File object,how can i do?

thanks in advance!

tosswang

Re: concerning the method WordprocessingMLPackage.load(File)

PostPosted: Fri May 20, 2011 1:50 am
by tinne
As you can read in OpcPackage.load, it depends on whether you bring an XML or ZIP (docx) file. Thus you either have
Code: Select all
  protected OpcPackage loadDocxPackageFromClasspath(final InputStream stream) throws Docx4JException {

    final LoadFromZipNG loader = new LoadFromZipNG();
    final OpcPackage content = loader.get(stream);
    return content;
  }

or go for
Code: Select all
  protected OpcPackage loadXMLFromClasspath(final InputStream stream) throws Docx4JException, JAXBException {

    final StreamSource source = new StreamSource(stream);

    JAXBElement<Package> packageElement;
    final Unmarshaller unmarshaller = Context.jcXmlPackage.createUnmarshaller();
    unmarshaller.setEventHandler(new JaxbValidationEventHandler());
    packageElement = unmarshaller.unmarshal(source, Package.class);

    final Package wmlPackage = packageElement.getValue();
    final FlatOpcXmlImporter importer = new FlatOpcXmlImporter(wmlPackage);

    final OpcPackage content = importer.get();
    return content;
  }

where multiplexing can be done e.g. on the file name.

Re: concerning the method WordprocessingMLPackage.load(File)

PostPosted: Fri May 20, 2011 12:54 pm
by tosswang
thank tinne,i resolve the issue via your post