Java Code Examples for lotus.domino.Document#removeItem()

The following examples show how to use lotus.domino.Document#removeItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MimeMessageParser.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
private static void writeAddresses(Document document, String itemName, AddressList addresses) throws NotesException {

        document.removeItem(itemName);
        
        if ( addresses != null && addresses.size() > 0 ) {
            Vector<String> values = new Vector<String>();
            for ( int i = 0; i < addresses.size(); i++ ) {
                Address address = addresses.get(i);
                values.add(address.toString());
            }
            
            document.replaceItemValue(itemName, values);
        }
    }
 
Example 2
Source File: JsonMimeEntityAdapter.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * When parsing the JSON representation of a MIME entity, we temporarily cache the JSON properties
 * in memory.  Call this method to flush the entire entity to the document.
 * 
 * @param lastEntity
 */
public void flushJsonProperties(boolean lastEntity) throws JsonException {
	
	Document document = _context.getDocument();
	String itemName = _context.getItemName();
	MIMEEntity entity = null;
	
	try {
		
		// Create the MIMEEntity
		
		if ( _context.getRootEntity() == null ) {
	        if (document.hasItem(itemName)) {
	            document.removeItem(itemName);
	        }
	        
			entity = document.createMIMEEntity(itemName);
			_context.setRootEntity(entity);
		}
		else {
			// Whose child are we?
			
			MIMEEntity parentEntity = null;
			String boundary = (String)_objectCache.getJsonProperty(BOUNDARY_PROP);
			if ( !StringUtil.isEmpty(boundary) ) {
				parentEntity = _context.getEntity(boundary);
			}
			
			if ( parentEntity == null ) {
				/* entity = _context.getRootEntity().createChildEntity(); */
				throw new JsonException(new ParseException(boundary));
			}
			else {
				entity = parentEntity.createChildEntity();
			}
		}
		
		// Add this entity to the map
		
		String contentType = (String)_objectCache.getJsonProperty(CONTENT_TYPE_PROP);
		String key = getKeyFromContentType(contentType);
		if ( key != null ) {
			_context.addEntity(key, entity);
		}
		
		// Write the headers
		
		addHeader(CONTENT_TYPE_PROP, CONTENT_TYPE_HEADER, entity);
		addHeader(CONTENT_DISPOSITION_PROP, CONTENT_DISPOSITION_HEADER, entity);
		addHeader(CONTENT_ID_PROP, CONTENT_ID_HEADER, entity);
		addHeader(CONTENT_TRANSFER_ENCODING_PROP, CONTENT_TRANSFER_ENCODING_HEADER, entity);
		
		// Write the data
		
		String data = (String)_objectCache.getJsonProperty(DATA_PROP);
           if (!StringUtil.isEmpty(data)) {
               int encoding = MIMEEntity.ENC_NONE;
               String contentEncoding = (String)_objectCache.getJsonProperty(CONTENT_TRANSFER_ENCODING_PROP);
               if (!StringUtil.isEmpty(contentEncoding)) {
                   if(contentEncoding.contains(ENCODING_BASE64)) 
                       encoding = MIMEEntity.ENC_BASE64;
                   else if(contentEncoding.contains(ENCODING_7BIT)) 
                       encoding = MIMEEntity.ENC_IDENTITY_7BIT;
                   else if(contentEncoding.contains(ENCODING_8BIT)) 
                       encoding = MIMEEntity.ENC_IDENTITY_8BIT;
                   else if(contentEncoding.contains(ENCODING_BINARY)) 
                       encoding = MIMEEntity.ENC_IDENTITY_BINARY;
                   else if(contentEncoding.contains(ENCODING_QUOTED_PRINTABLE)) 
                       encoding = MIMEEntity.ENC_QUOTED_PRINTABLE;
               }
               Session session = document.getParentDatabase().getParent();
               Stream stream = session.createStream();
               stream.writeText(data);   
               entity.setContentFromText(stream, contentType, encoding); 
               stream.close();
               stream.recycle();
           }
		
		
		// Dereference the cached object so it can be GC'd
		
		_objectCache = null;
		
		// Clean up for the last entity in the array
		
		if ( lastEntity ) {
	        document.closeMIMEEntities(true, itemName);
            _context.getRootEntity().recycle();
		}
	}
	catch (NotesException e) {
		throw new JsonException(e);
	}
}