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

The following examples show how to use lotus.domino.Document#hasItem() . 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: DominoDocumentItem.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public Object evaluate(RestDocumentService service, Document document) throws ServiceException {
	// TODO: How can we cache the item name so we do not reevaluate it all the time?
	String itemName = getItemName();
	try {
		if(StringUtil.isNotEmpty(itemName) && document.hasItem(itemName)) {
				return document.getItemValue(itemName);
		}
	} catch (NotesException e) {
		throw new ServiceException(e);
	}
	String var = service.getParameters().getVar();
	if(StringUtil.isNotEmpty(var)) {
		// TODO: Do that on a per item basis only...
		Object old = service.getHttpRequest().getAttribute(var); 
		try {
			service.getHttpRequest().setAttribute(var,document);
			return getValue();
		} finally {
			service.getHttpRequest().setAttribute(var,old);
		}
	} else {
		return getValue();
	}
}
 
Example 2
Source File: JsonViewCollectionContent.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
private String getViewName(Document viewDoc) throws NotesException {
	String name = "";
	String[] aliases = null;		
	Vector<?> names = viewDoc.getItemValue(FIELD_TITLE);
	if ( names != null && names.size() > 0 ){
		String title = (String)names.get( 0 );
		//Compute the aliases
		ArrayList<String> aliasesList = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer( title, "|");
		while ( st.hasMoreTokens() ){
			if ( name == null ){
				name = st.nextToken().trim();
			}else{
				aliasesList.add( st.nextToken().trim() );
			}
		}
		for ( int i = 1; i < names.size(); i++ ){
			aliasesList.add( (String)names.get( i ) );
		}
		aliases = aliasesList.toArray( new String[0] );
	}else if ( viewDoc.hasItem( FIELD_TITLE ) ) {
		name="";	//Empty name
	}
	if (name.length() == 0)
		if (aliases != null)
			name = aliases[0];
	return name;
}
 
Example 3
Source File: JsonMessageParser.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public void fromJson(Document document) throws JsonException {

        // SPR #DDEY9L6MX5: Add a Form item
        try {
            if ( !document.hasItem(FORM_ITEM) ) {
                document.replaceItemValue(FORM_ITEM, MEMO_FORM);
            }
        }
        catch (NotesException e) {
            // Ignore exception
        }
        
		JsonFactory factory = new JsonObjectFactory(document);
    	JsonParser.fromJson(factory, _reader);
    }
 
Example 4
Source File: RecentContactsProvider.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * Given a note received from another user, parse the from display name and internet address.
 * 
 * @param doc
 *           Email note to parse for sender data
 * @return
 * @throws NotesException
 */
private List<RecentContact> parseReceivedFromNote(final Document doc) throws NotesException
{
   // Currently only getting from address - may get items like others that were on the email
   // in the future.
   final List<RecentContact> recentContacts = new ArrayList<RecentContact>(1);
   final RecentContact sender = new RecentContact();
   recentContacts.add(sender);

   final Vector dateVec = doc.getItemValue("DeliveredDate"); //$NON-NLS-1$
   if (doc.hasItem("INetFrom")) //$NON-NLS-1$
   {
      sender.InternetAddress = doc.getItemValueString("INetFrom"); //$NON-NLS-1$

      if (sender.InternetAddress.contains("<"))
      {
         processComboInet(sender, sender.InternetAddress);
      }
      else
      {
         sender.DisplayName = doc.getItemValueString("From"); //$NON-NLS-1$
         sender.DisplayName = sender.DisplayName.replaceAll("CN=|OU=|O=|@.*", ""); //$NON-NLS-1$
      }
   }
   else
   {
      processComboInet(sender, doc.getItemValueString("From")); //$NON-NLS-1$
   }

   sender.lastContacted = getDateFromVector(dateVec);

   return recentContacts;
}
 
Example 5
Source File: MimeMessageGenerator.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
private void writeMimeOutput(Document document, String itemName, Writer writer)
		throws NotesException, IOException {

	MIMEEntity mimeEntity = null;
	MIMEEntity mChild = null;
	String contenttype = null;
	String headers = null;
       MimeEntityHelper helper = null;
	
       if (!document.hasItem(itemName)) {
           // SPR# WJBJ9PE86G: The body item doesn't exist, so create one now
           mimeEntity = document.createMIMEEntity(itemName);
       }
       else {
           helper = new MimeEntityHelper(document, itemName);
           mimeEntity = helper.getFirstMimeEntity();
           if (mimeEntity == null) {
               throw new NullPointerException("Invalid item."); // $NLX-MimeMessageGenerator_InvalidItem-1$
           }
       }
	
	try {
		contenttype = mimeEntity.getContentType();
		headers = mimeEntity.getHeaders();
		// TODO: Is there a better way to output the headers?
		if (!headers.startsWith("MIME-Version:")) { //$NON-NLS-1$
			writer.write("MIME-Version: 1.0"); //$NON-NLS-1$
		}
		// Write MIMEEntity.
		writeMimeEntity(writer, mimeEntity);
		if (contenttype.startsWith(MULTIPART)) {
			mChild = mimeEntity.getFirstChildEntity();
			while (mChild != null) {
				// Write MIMEEntity.
				writeMimeEntity(writer, mChild);
				MIMEEntity mChild2 = mChild.getFirstChildEntity();
				if (mChild2 == null) {
					mChild2 = mChild.getNextSibling();
					if (mChild2 == null) {
						mChild2 = mChild.getParentEntity();
						if (mChild2 != null)
							mChild2 = mChild2.getNextSibling();
					}
				}
				mChild.recycle();
				mChild = mChild2;
			}
		}
		writer.write(mimeEntity.getBoundaryEnd());
	} finally {
           if (helper != null) {
               helper.recycle();
           }
	}
}
 
Example 6
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);
	}
}