Package org.docx4j.openpackaging

Examples of org.docx4j.openpackaging.Base


   * @throws InvalidFormatException
   */
  private void getPart( OpcPackage pkg, RelationshipsPart rp, Relationship r)
      throws Docx4JException, InvalidFormatException, URISyntaxException {
   
    Base source = null;
    String resolvedPartUri = null;
   
    if (r.getTargetMode() == null
        || !r.getTargetMode().equals("External") ) {
     
      // Usual case
     
//      source = r.getSource();
//      resolvedPartUri = URIHelper.resolvePartUri(r.getSourceURI(), r.getTargetURI() ).toString();   
      source = rp.getSourceP();
      resolvedPartUri = URIHelper.resolvePartUri(rp.getSourceURI(), new URI(r.getTarget() ) ).toString();   

      // Don't drop leading "/' in Xml Package
      // resolvedPartUri = resolvedPartUri.substring(1);       

     
    } else {     
      // EXTERNAL
      /* "When set to External, the target attribute may be a relative
       *  reference or a URI.  If the target attribute is a relative
       *  reference, then that reference is interpreted relative to the
       *  location of the package."
       */

      log.info("Encountered external resource " + r.getTarget()
             + " of type " + r.getType() );
     
      // As of 1 May 2008, we don't do anything with these yet.
      // No need to create a Part out of them until such time as
      // we need to read the contents. (External resources don't
      // seem to necessarily be described in [ContentTypes].xml )
     
      // When the document is saved, the relationship is simply
      // written again.
     
      return;
    }
   
    if (handled.get(resolvedPartUri)!=null) return;
   
    String relationshipType = r.getType();   
     
    Part part = getRawPart(ctm, resolvedPartUri,r);
    rp.loadPart(part, r);
    handled.put(resolvedPartUri, resolvedPartUri);
   

    // The source Part (or Package) might have a convenience
    // method for this
    if (source.setPartShortcut(part, relationshipType ) ) {
      log.debug("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }
   
//    log.info(".. added." );
   
View Full Code Here


   */
  public void getPart(Session jcrSession, Node docxNode,
      OpcPackage pkg, RelationshipsPart rp, Relationship r
      throws Docx4JException, RepositoryException, InvalidFormatException, URISyntaxException {
   
    Base source = null;
    String resolvedPartUri = null;
   
    if (r.getTargetMode() == null
        || !r.getTargetMode().equals("External") ) {
     
      // Usual case
   
      source = rp.getSourceP();
      resolvedPartUri = URIHelper.resolvePartUri(rp.getSourceURI(), new URI(r.getTarget() ) ).toString();   
 
      // Now drop leading "/'
      resolvedPartUri = resolvedPartUri.substring(1);       
 
      // Now normalise it .. ie abc/def/../ghi
      // becomes abc/ghi
  //    target = (new java.net.URI(target)).normalize().toString();
  //    log.info("Normalised, it is " + target );       
   
    } else {     
      // EXTERNAL     
      if (loadExternalTargets &&
          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;
    }
   
    if (handled.get(resolvedPartUri)!=null) return;
   
    String relationshipType = r.getType();   
   
    Part part = getRawPart(jcrSession, nodeMapper, docxNode, ctm, resolvedPartUri);
    if (part instanceof BinaryPart
        || part instanceof DefaultXmlPart) {
      // The constructors of other parts should take care of this...
      part.setRelationshipType(relationshipType);
    }   
    rp.loadPart(part, r);
    handled.put(resolvedPartUri, resolvedPartUri);   
   
    // The source Part (or Package) might have a convenience
    // method for this
    if (source.setPartShortcut(part, relationshipType ) ) {
      log.info("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }       
   
//    unusedJCRNodes.put(resolvedPartUri, new Boolean(false));
    log.info(".. added part '" + part.getPartName() + "'" );
View Full Code Here

   */
  private void getPart(OpcPackage pkg, RelationshipsPart rp,
      Relationship r, ContentTypeManager ctm)
      throws Docx4JException, InvalidFormatException, URISyntaxException {
   
    Base source = null;
    String resolvedPartUri = null;
   
    if (r.getType().equals(Namespaces.HYPERLINK)) {
      // Could be Internal or External
      // Example of Internal is w:drawing/wp:inline/wp:docPr/a:hlinkClick
      log.info("Encountered (but not loading) hyperlink " + r.getTarget()  );       
      return;     
    } else
      if (r.getTargetMode() == null
        || !r.getTargetMode().equals("External") ) {
     
      // Usual case
     
      source = rp.getSourceP();
      resolvedPartUri = URIHelper.resolvePartUri(rp.getSourceURI(), new URI(r.getTarget() ) ).toString();   

      // Now drop leading "/'
      resolvedPartUri = resolvedPartUri.substring(1);       

      // Now normalise it .. ie abc/def/../ghi
      // becomes abc/ghi
      // Maybe this isn't necessary with a zip file,
      // - ZipFile class may be smart enough to do it.
      // But it is certainly necessary in the JCR case.
//      resolvedPartUri = (new java.net.URI(resolvedPartUri)).normalize().toString();
//      log.info("Normalised, it is " + resolvedPartUri );       
     
    } else {     
      // EXTERNAL     
      if (loadExternalTargets &&
          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;
    }
   
   
    String relationshipType = r.getType();   
    Part part;
   
    if (pkg.handled.get(resolvedPartUri)!=null) {
     
      // The source Part (or Package) might have a convenience
      // method for this
      part = pkg.getParts().getParts().get(new PartName("/" + resolvedPartUri));
      if (source.setPartShortcut(part, relationshipType ) ) {
        log.debug("Convenience method established from " + source.getPartName()
            + " to " + part.getPartName());
      }
     
      // v3.2.1: also note this additional source rel
      part.getSourceRelationships().add(r)
     
      return;
    }
   
    part = getRawPart(ctm, resolvedPartUri, r); // will throw exception if null

    // The source Part (or Package) might have a convenience
    // method for this
    if (source.setPartShortcut(part, relationshipType ) ) {
      log.debug("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }

   
    if (part instanceof BinaryPart
View Full Code Here

  //private void getPart(ZipFile zf, Package pkg, RelationshipsPart rp, Relationship r)
  private void getPart(HashMap<String, ByteArray> partByteArrays, OpcPackage pkg, RelationshipsPart rp,
      Relationship r, ContentTypeManager ctm)
      throws Docx4JException, InvalidFormatException, URISyntaxException {
   
    Base source = null;
    String resolvedPartUri = null;
   
    if (r.getType().equals(Namespaces.HYPERLINK)) {
      // Could be Internal or External
      // Example of Internal is w:drawing/wp:inline/wp:docPr/a:hlinkClick
      log.info("Encountered (but not loading) hyperlink " + r.getTarget()  );       
      return;     
    } else
      if (r.getTargetMode() == null
        || !r.getTargetMode().equals("External") ) {
     
      // Usual case
     
      source = rp.getSourceP();
      resolvedPartUri = URIHelper.resolvePartUri(rp.getSourceURI(), new URI(r.getTarget() ) ).toString();   

      // Now drop leading "/'
      resolvedPartUri = resolvedPartUri.substring(1);       

      // Now normalise it .. ie abc/def/../ghi
      // becomes abc/ghi
      // Maybe this isn't necessary with a zip file,
      // - ZipFile class may be smart enough to do it.
      // But it is certainly necessary in the JCR case.
//      resolvedPartUri = (new java.net.URI(resolvedPartUri)).normalize().toString();
//      log.info("Normalised, it is " + resolvedPartUri );       
     
    } else {     
      // EXTERNAL     
      if (loadExternalTargets &&
          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;
    }
   
   
    String relationshipType = r.getType();   
    Part part;
   
    if (pkg.handled.get(resolvedPartUri)!=null) {
     
      // The source Part (or Package) might have a convenience
      // method for this
      part = pkg.getParts().getParts().get(new PartName("/" + resolvedPartUri));
      if (source.setPartShortcut(part, relationshipType ) ) {
        log.debug("Convenience method established from " + source.getPartName()
            + " to " + part.getPartName());
     
     
      // v3.2.1: also note this additional source rel
      part.getSourceRelationships().add(r)
     
      return;
    }
   
    part = getRawPart(partByteArrays, ctm, resolvedPartUri, r); // will throw exception if null

    // The source Part (or Package) might have a convenience
    // method for this
    if (source.setPartShortcut(part, relationshipType ) ) {
      log.debug("Convenience method established from " + source.getPartName()
          + " to " + part.getPartName());
    }

   
    if (part instanceof BinaryPart
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.Base

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.