public static void pasteADocFragment(ADocument aDoc, int position, ADocumentFragment fragment){
	String text = fragment.getText();
	HashMap <DocSection, AttributeSet> styleMap = fragment.getStyleMap(); 
	HashMap <DocSection, AData> fragMap = fragment.getaDataMap();        
	
	
	try {
		// inserting plain text
		    //aDoc.blockUndoEvents(true);
			if (text != null )aDoc.insertString(position, text, aDoc.defaultStyle);
			
		//  inserting styles
		if (styleMap !=null){
			Set <DocSection> keys = styleMap.keySet();
			Iterator <DocSection> it = keys.iterator();
			DocSection section = null;

			while (it.hasNext()){
				section = it.next();
				aDoc.setCharacterAttributes(position+section.getStart(), 
											section.getLength(), 
											styleMap.get(section), 
											true);
			}
			
		}	
		
		//  inserting AData
		
		if (fragMap !=null){
			HashMap<ASection, AData> aDataMap = aDoc.getADataMap();
			
			Set <DocSection> keys = fragMap.keySet();
			Iterator <DocSection> it = keys.iterator();
			DocSection section = null;

			while (it.hasNext()){
				section = it.next();
				aDataMap.put(aDoc.new ASection(	aDoc.createPosition(position+section.getStart()), aDoc.createPosition(position+section.getEnd())), 
											fragMap.get(section));
			}
			
		}				
		//aDoc.blockUndoEvents(false);
	} catch (BadLocationException e) {
		e.printStackTrace();
	}
	
}