Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2007-2008, Plutext Pty Ltd.
   *   
   *  This file is part of docx4j.
  
      docx4j is licensed under the Apache License, Version 2.0 (the "License"); 
      you may not use this file except in compliance with the License. 
  
      You may obtain a copy of the License at 
 
         http://www.apache.org/licenses/LICENSE-2.0 
 
     Unless required by applicable law or agreed to in writing, software 
     distributed under the License is distributed on an "AS IS" BASIS, 
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     See the License for the specific language governing permissions and 
     limitations under the License.
 
  */
 
 
 package org.docx4j.openpackaging;
 
 
 import java.util.Map;
 
 
 
 
 public abstract class Base {
 
 	protected static Logger log = LoggerFactory.getLogger(Base.class);
 
 	public abstract OpcPackage getPackage(); 
 	
 	private Map<StringObjectuserData = new HashMap<StringObject>();

Parameters:
key
Returns:
:
since 3.0.0
 
 	public Object getUserData(String key) {
 		return .get(key);
 	}
An object allowing the user of the docx4j API to associate arbitrary data with this package/part while the package is in memory. Note that the data is not saved when the package is saved.

Parameters:
key
value
:
since 3.0.0
 
 	public void setUserData(String keyObject value) {
 		.put(keyvalue);
 	}

relationships - the package and each part can have one of these See eg 11. WordprocessingML [11.2 Package Structure]. (Each Part is also the _target_ of a RelationshipPart, so see Part for definition of a corresponding field.)
 
Get the relationship part. From 2.7.1, the part will be created if it doesn't exist. (SaveToZipFile will only save it if it contains rels)

Returns:
The relationship part name.
 
 		return getRelationshipsPart(true);
 	}

Get the relationship part.

Parameters:
create whether to create it if it doesn't exist
Returns:
Since:
2.7.1
 
 	public RelationshipsPart getRelationshipsPart(boolean createIfAbsent) {
 //			throws InvalidOperationException {
			// a relationship part can't have a relationship part
			// but should we throw an error here?
			//throw new InvalidOperationException();
			return null;
		if ( == null 
				&& createIfAbsent) {
			 = RelationshipsPart.createRelationshipsPartForPart(this);
		}
	}
	public void setRelationships(RelationshipsPart relationships) {
		if (relationships!=null) {
			relationships.setPackagegetPackage() );
		}
		this. = relationships;
	}
	public String getContentType() {
		if (!=null ) {
else {
			.warn("WARNING: content type was null. " +
					"You should set this before adding the part.");
			return null;
		}
	}
	public void setContentType(ContentType contentType) {
		.debug("\nSet contentType " + contentType + " on part " + this.getPartName().getName() +"\n\n");
		this. = contentType;
	}


The part name. (required by the specification [M1.1]) Note that in docx4J, part names should be resolved, before being set, so that they are absolute (ie start with '/'). We will assume the Package has a part name of "/"
	public PartName partName;

Returns:
the uri
	public PartName getPartName() {
		if (==null) {
			.error("PartName was null!");
			try {
				return new PartName("/null");
catch (Exception e) {
				// TODO: handle exception
			}
		}
		return ;
	}


Tell the source Part about this target Part, so the source can use this part via a convenience method.

Parameters:
part
relationshipType
Returns:
true if the source Part does use the target Part in a convenience method.
 
	public abstract boolean setPartShortcut(Part partString relationshipType);
//	/**
//	 * Flag if a modification has been made.  
//	 * The semantics are as follows:
//	 * - on a Part: the Part, its relationships part, or a target part
//	 *   has been modified
//	 * - on the Package: its relationships part, or a target part
//	 *   has been modified. 
//	 */
//	protected boolean isDirty = false;
//	
//	public boolean isDirty() {
//		return isDirty;
//	}
//
//	public void setDirty(boolean isDirty) {
//		this.isDirty = isDirty;
//	}
Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work.

Parameters:
targetpart The part to add to this part's relationships
mode whether to overwrite, rename or abort if the part name already exists
proposedRelId
Returns:
Throws:
org.docx4j.openpackaging.exceptions.InvalidFormatException
Since:
2.7.1
	public Relationship addTargetPart(Part targetpartAddPartBehaviour mode
		return addTargetPart(targetpartmodenull);
	}

Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. The added part will replace any existing part with the same name (ie same target in the rels part). In other words, if you want to use the one image as the target of 2 rels, don't use this method.

Parameters:
targetpart The part to add to this part's relationships
	public Relationship addTargetPart(Part targetpartthrows InvalidFormatException {
		return this.addTargetPart(targetpart.null);
	}

Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. The added part will replace any existing part with the same name (ie same target in the rels part). In other words, if you want to use the one image as the target of 2 rels, don't use this method.

Parameters:
targetpart The part to add to this part's relationships
	public Relationship addTargetPart(Part targetpartString proposedRelId
		return addTargetParttargetpart.proposedRelId);
	}


Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. The added part will replace any existing part with the same name (ie same target in the rels part). In other words, if you want to use the one image as the target of 2 rels, don't use this method.

Parameters:
targetpart The part to add to this part's relationships
mode whether to overwrite, rename or abort if the part name already exists
proposedRelId
Returns:
Throws:
org.docx4j.openpackaging.exceptions.InvalidFormatException
Since:
2.7.1
	public Relationship addTargetPart(Part targetpartAddPartBehaviour modeString proposedRelId
		if ( this.getPackage()==null ) {						
			throw new InvalidFormatException("Package not set; if you are adding part2 to part1, make sure part1 is added first.");
		}
		if ( this instanceof RelationshipsPart ) {			
			throw new InvalidFormatException("You should add your part to the target part, not the target part's relationships part.");
		}
		// Now add the targetpart to the relationships
		Relationship rel = this.getRelationshipsPart().addPart(targetpartmode
				getPackage().getContentTypeManager(), proposedRelId);
		// Finally, set part shortcut if there is one to set
		boolean shortcutSet = setPartShortcut(targetparttargetpart.getRelationshipType());
		if (shortcutSet) {
			.info("shortcut was set");			
		}
		return rel;
	}
New to GrepCode? Check out our FAQ X