Package org.docx4j.openpackaging.parts.WordprocessingML

Examples of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart


          return null;         
        }
      } catch (PartUnrecognisedException e) {
       
        // Try to get it as a binary part       
        part = new BinaryPart(new PartName("/" + resolvedPartUri));
        ((BinaryPart) part).setBinaryData(is);
         
      }
    } catch (Exception ex) {
      // PathNotFoundException, ValueFormatException, RepositoryException, URISyntaxException
View Full Code Here


  URI targetURI = null;
  URL targetURL = null;
  int p = absoluteTarget.lastIndexOf('.');
  String fileExtension = (p > -1 ? absoluteTarget.substring(p+1).toLowerCase() : null);
  String contentType = (fileExtension != null ? CONTENT_TYPE_MAP.get(fileExtension) : null);
  BinaryPart binaryPart = null;
  InputStream inStream = null;
    try {
      targetURI = new URI(absoluteTarget.replace('\\', '/'));
    }
    catch (URISyntaxException use) {
      throw new Docx4JException("Invalid absolute Target: '" + absoluteTarget + "'", use);
    }
    try {
      targetURL = targetURI.toURL();
    } catch (MalformedURLException mue) {
      throw new Docx4JException("Invalid absolute Target: '" + absoluteTarget + "'", mue);
    }
    try {
      inStream = targetURL.openStream();
      binaryPart = createBinaryPart(absoluteTarget, contentType);
      binaryPart.setBinaryData(inStream);
    } catch (IOException ioe) {
      throw new Docx4JException("Could not load external resource: '" + absoluteTarget + "'", ioe);
    }
    return binaryPart;
  }
View Full Code Here

    return binaryPart;
  }
 
  protected static BinaryPart createBinaryPart(String absoluteTarget, String contentType) {
  ExternalTarget externalTarget = new ExternalTarget(absoluteTarget);
  BinaryPart ret = null;
    if (ContentTypes.IMAGE_JPEG.equals(contentType))
      ret = new ImageJpegPart(externalTarget);
    else if (ContentTypes.IMAGE_PNG.equals(contentType))
        ret = new ImagePngPart(externalTarget);
    else if (ContentTypes.IMAGE_GIF.equals(contentType))
      ret = new ImageGifPart(externalTarget);
    else if (ContentTypes.IMAGE_TIFF.equals(contentType))
      ret = new ImageTiffPart(externalTarget);
    else if (ContentTypes.IMAGE_BMP.equals(contentType))
      ret = new ImageBmpPart(externalTarget);
    else if (ContentTypes.IMAGE_EMF.equals(contentType))
      ret = new MetafileEmfPart(externalTarget);
    else if (ContentTypes.IMAGE_WMF.equals(contentType))
      ret = new MetafileWmfPart(externalTarget);
    else
      ret = new BinaryPart(externalTarget);
   
    return ret;
  }
View Full Code Here

       
      } catch (PartUnrecognisedException e) {

        // Try to get it as a binary part
        log.error("Part unrecognised: " + pkgPart.getName());
        part = new BinaryPart( new PartName(pkgPart.getName())); // /?
        ((BinaryPart)part).setBinaryData( pkgPart.getBinaryData() );
      }
    } catch (Exception ex) {
      // IOException, URISyntaxException
      ex.printStackTrace();
View Full Code Here

          r.getType().equals( Namespaces.IMAGE ) ) {
          // It could instead be, for example, of type hyperlink,
          // and we don't want to try to fetch that       
        log.warn("Loading external resource " + r.getTarget()
               + " of type " + r.getType() );
        BinaryPart bp = getExternalResource(r.getTarget());
        pkg.getExternalResources().put(bp.getExternalTarget(), bp);     
      } else {       
        log.warn("Encountered (but not loading) external resource " + r.getTarget()
               + " of type " + r.getType() );       
      }           
      return;
View Full Code Here

//      Property jcrData = contentNode.getProperty("jcr:data");
      Property jcrData = nodeMapper.getJcrData(contentNode);     
      in = jcrData.getStream();

      part = new BinaryPart(new PartName("/" + resolvedPartUri));

      ((BinaryPart) part).setBinaryData(in);
      log.info("Stored as BinaryData");

    } catch (Exception ex) {
View Full Code Here

      return new org.docx4j.openpackaging.parts.DrawingML.DiagramDrawingPart(new PartName(partName));
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.drawing")) {
      try {
        return JaxbDmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.presentation")
        || contentType.equals(ContentTypes.PRESENTATIONML_MACROENABLED)
        || contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE)
        || contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED)
            ) {
      try {
        return JaxbPmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK)
        || contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED)
        || contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE)
        || contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE_MACROENABLED)) {
      try {
        return new WorkbookPart(new PartName(partName));
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
     
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml")) {
      try {
        return JaxbSmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_THEME_OVERRIDE)) {
      return new org.docx4j.openpackaging.parts.DrawingML.ThemeOverridePart(new PartName(partName));   
    } else if (contentType.equals(ContentTypes.DIGITAL_SIGNATURE_XML_SIGNATURE_PART)) {
      return new org.docx4j.openpackaging.parts.digitalsignature.XmlSignaturePart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.APPLICATION_XML)
        || partName.endsWith(".xml")) {
     
      // Rarely (but sometimes) used, owing to OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE above.
     
      // Simple minded detection of XML content.
      // If it turns out not to be XML, the zip loader
      // will catch the error and load it as a binary part instead.
      log.warn("DefaultPart used for part '" + partName
          + "' of content type '" + contentType + "'");
      return CreateDefaultXmlPartObject(partName );
     
    } else if (contentType.equals(ContentTypes.PRESENTATIONML_FONT_DATA)) {
     
      return new FontDataPart(new PartName(partName));
     
    } else {
     
      log.error("No subclass found for " + partName + "; defaulting to binary");
      //throw new PartUnrecognisedException("No subclass found for " + partName + " (content type '" + contentType + "')");   
      return new BinaryPart( new PartName(partName));
    }

  }
View Full Code Here

          r.getType().equals( Namespaces.IMAGE ) ) {
          // It could instead be, for example, of type hyperlink,
          // and we don't want to try to fetch that
        log.info("Loading external resource " + r.getTarget()
               + " of type " + r.getType() );
        BinaryPart bp = ExternalResourceUtils.getExternalResource(r.getTarget());
        pkg.getExternalResources().put(bp.getExternalTarget(), bp);     
      } else {       
        log.info("Encountered (but not loading) external resource " + r.getTarget()
               + " of type " + r.getType() );       
      }           
      return;
View Full Code Here

    Part part = null;
    InputStream is = null;         
    try {
      is = partStore.loadPart(resolvedPartUri);
      //in = partByteArrays.get(resolvedPartUri).getInputStream();
      part = new BinaryPart( new PartName("/" + resolvedPartUri));
     
      // Set content type
      part.setContentType(
          new ContentType(
              ctm.getContentType(new PartName("/" + resolvedPartUri)) ) );
View Full Code Here

          r.getType().equals( Namespaces.IMAGE ) ) {
          // It could instead be, for example, of type hyperlink,
          // and we don't want to try to fetch that
        log.info("Loading external resource " + r.getTarget()
               + " of type " + r.getType() );
        BinaryPart bp = ExternalResourceUtils.getExternalResource(r.getTarget());
        pkg.getExternalResources().put(bp.getExternalTarget(), bp);     
      } else {       
        log.info("Encountered (but not loading) external resource " + r.getTarget()
               + " of type " + r.getType() );       
      }           
      return;
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.