Imports a complete RTF document.

@param readerIn
The Reader to read the RTF document from.
@param rtfDoc
The RtfDocument to add the imported document to.
@throws IOException On I/O errors.
@since 2.1.3
355539
public void importRtfDocument(InputStream readerIn, RtfDocument rtfDoc) throws IOException {
		if(readerIn == null || rtfDoc == null) return;
		this.init(TYPE_IMPORT_FULL, rtfDoc, readerIn, this.document, null);
		this.setCurrentDestination(RtfDestinationMgr.DESTINATION_NULL);
		this.groupLevel = 0;
		try {
			this.tokenise();
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
114577
@Override
    public I importFrom(final File file) throws ArchiveImportException {
        return importFrom(file, Filters.includeAll());
    }
771223
def addAttachment(self, filepath):
        

        proj_id = self.contextId

        fa = self.rtc_obj.getFiledAgainst(self.filedAgainst,
                                          projectarea_id=proj_id)
        fa_id = fa.url.split("/")[-1]

        headers = copy.deepcopy(self.rtc_obj.headers)
        if headers.__contains__("Content-Type"):
            headers.__delitem__("Content-Type")

        filename = os.path.basename(filepath)
        fileh = open(filepath, "rb")
        files = {"attach": (filename, fileh, "application/octet-stream")}

        params = {"projectId": proj_id,
                  "multiple": "true",
                  "category": fa_id}
        req_url = "".join([self.rtc_obj.url,
                           "/service/com.ibm.team.workitem.service.",
                           "internal.rest.IAttachmentRestService/"])
        resp = self.post(req_url,
                         verify=False,
                         headers=headers,
                         proxies=self.rtc_obj.proxies,
                         params=params,
                         files=files)
        raw_data = xmltodict.parse(resp.content)
        json_body = json.loads(raw_data["html"]["body"]["textarea"])
        attachment_info = json_body["files"][0]
        return self._add_attachment_link(attachment_info)
368621
public ImmutableListMultimap<Symbol, EDLMention> loadEDLMentionsByDocFrom(CharSource source) throws IOException {
    final ImmutableList<EDLMention> edlMentions = loadEDLMentionsFrom(source);
    final ImmutableListMultimap.Builder<Symbol, EDLMention> byDocs =
        ImmutableListMultimap.<Symbol, EDLMention>builder()
            .orderKeysBy(SymbolUtils.byStringOrdering());
    for (final EDLMention edlMention : edlMentions) {
      byDocs.put(edlMention.documentID(), edlMention);
    }
    return byDocs.build();
  }
1328914
private void importTable(PdfPTable table) {
        this.rows = new ArrayList();
        this.tableWidthPercent = table.getWidthPercentage();
//        this.tableWidthPercent = table.getWidth();
        this.proportionalWidths = table.getAbsoluteWidths();
//        this.proportionalWidths = table.getProportionalWidths();
        this.cellPadding = (float) (table.spacingAfter() * TWIPS_FACTOR);
//        this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR);
        this.cellSpacing = (float) (table.spacingAfter() * TWIPS_FACTOR);
//        this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR);
//        this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor());
//        this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor());
        this.alignment = table.getHorizontalAlignment();
//        this.alignment = table.getAlignment();
        
        int i = 0;
        Iterator rowIterator = table.getRows().iterator();
//        Iterator rowIterator = table.iterator();
        while(rowIterator.hasNext()) {
            this.rows.add(new RtfRow(this.document, this, (PdfPRow) rowIterator.next(), i));
            i++;
        }
        for(i = 0; i < this.rows.size(); i++) {
            ((RtfRow) this.rows.get(i)).handleCellSpanning();
            ((RtfRow) this.rows.get(i)).cleanRow();
        }
        
        this.headerRows = table.getHeaderRows();
//        this.headerRows = table.getLastHeaderRow();
        this.cellsFitToPage = table.getKeepTogether();
//        this.cellsFitToPage = table.isCellsFitPage();
        this.tableFitToPage = table.getKeepTogether();
//        this.tableFitToPage = table.isTableFitsPage();
//        if(!Float.isNaN(table.getOffset())) {
//            this.offset = (int) (table.getOffset() * 2);
//        }
//        if(!Float.isNaN(table.getOffset())) {
//            this.offset = (int) (table.getOffset() * 2);
//        }
    }
271120
@Scope(DocScope.IO)
    public <T> T read(final Class<T> projectionInterface) throws IOException {
        Document document = readDocument();
        return projector.projectDOMNode(document, projectionInterface);
    }
1148297
public void load(final Reader r) throws IOException
	{
		try (BufferedReader in = new BufferedReader(r))
		{
			entries.clear();
			vars.clear();

			String line = in.readLine();
			while (line != null)
			{
				// Parse the line

				if (line.length() == 0)
				{
					entries.add(new BlankLine());
				}
				else
				{
					char c = line.charAt(0);

					if (c == COMMENT_CHAR)
					{
						if (!line.startsWith(COMMENT_INST))
						{ // Don't load instance comments
							entries.add(new Comment(line.substring(1)));
						}
					}
					else if (c == ' ')
					{
						// If it starts with a space let's call it a blank line
						entries.add(new BlankLine());
					}
					else
					{ // Name=Value pair
						// TODO - handle escaped characters (notably, \= and \n)
						final int equalsIndex = line.indexOf('=');

						if (equalsIndex != -1)
						{
							String name = line.substring(0, equalsIndex).trim();
							String value = line.substring(equalsIndex + 1);

							NameValuePair nvp = new NameValuePair(name, value);
							if (vars.containsKey(nvp.name))
							{
								log.warn("{load} duplicate entry '" + nvp.name + "': overwriting previous value");
							}

							entries.add(nvp);
							vars.put(caseSensitive ? nvp.name : nvp.name.toLowerCase(), nvp);
						}
						else
						{
							log.error("Malformed line in property file: " + line);
						}
					}
				}

				line = in.readLine();
			}

			hook_loaded();
		}
	}
635569
public Document doc() throws IOException {
		// if the stream has already been read, use the text format
		InputSource is;
		if (document == null) {
			if (text == null) {
				is = new InputSource(inputStream);
				is.setEncoding(getCharSet().name());
			} else {
				is = new InputSource(new StringReader(text));
			}
			try {
				document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
			} catch (SAXException e) {
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
			inputStream.close();
		}
		return document;
	}
573642
void addDocuments(final Document[] docs) throws IOException
   {
      final IndexWriter writer = getIndexWriter();

      IOException ioExc = null;
      try
      {
         for (Document doc : docs)
         {
            try
            {
               writer.addDocument(doc);
            }
            catch (Throwable e) //NOSONAR
            {
               if (ioExc == null)
               {
                  if (e instanceof IOException)
                  {
                     ioExc = (IOException)e;
                  }
                  else
                  {
                     ioExc = Util.createIOException(e);
                  }
               }

               log.warn("Exception while inverting document", e);
            }
         }
      }
      finally
      {
         invalidateSharedReader();
      }

      if (ioExc != null)
      {
         throw ioExc;
      }
   }
119320
private void importTable(Table table) {
        this.rows = new ArrayList();
        this.tableWidthPercent = table.getWidth();
        this.proportionalWidths = table.getProportionalWidths();
        this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR);
        this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR);
        this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor());
        this.alignment = table.getAlignment();
        
        int i = 0;
        Iterator rowIterator = table.iterator();
        while(rowIterator.hasNext()) {
            this.rows.add(new RtfRow(this.document, this, (Row) rowIterator.next(), i));
            i++;
        }
        for(i = 0; i < this.rows.size(); i++) {
            ((RtfRow) this.rows.get(i)).handleCellSpanning();
            ((RtfRow) this.rows.get(i)).cleanRow();
        }
        this.headerRows = table.getLastHeaderRow();
        this.cellsFitToPage = table.isCellsFitPage();
        this.tableFitToPage = table.isTableFitsPage();
        if(!Float.isNaN(table.getOffset())) {
            this.offset = (int) (table.getOffset() * 2);
        }
    }
633270
public void addImport(ImportDescr importDescr) {
        for (Dialect dialect : this.map.values()) {
            dialect.addImport(importDescr);
        }
    }
499672
public void writeContent(final OutputStream result) throws IOException
    {
		this.shapeNr = this.doc.getRandomInt();
		
		this.properties.put("ShapeType", new RtfShapeProperty("ShapeType", this.type));
		if(this.position.isShapeBelowText()) {
			this.properties.put("fBehindDocument", new RtfShapeProperty("fBehindDocument", true));
		}
		if(this.inTable) {
			this.properties.put("fLayoutInCell", new RtfShapeProperty("fLayoutInCell", true));
		}
		if(this.properties.containsKey("posh")) {
			this.position.setIgnoreXRelative(true);
		}
		if(this.properties.containsKey("posv")) {
			this.position.setIgnoreYRelative(true);
		}
    	
    	result.write(OPEN_GROUP);
    	result.write(DocWriter.getISOBytes("\\shp"));
    	result.write(DocWriter.getISOBytes("\\shplid"));
    	result.write(intToByteArray(this.shapeNr));
    	this.position.writeContent(result);
    	switch(this.wrapping) {
    	case SHAPE_WRAP_NONE:
    		result.write(DocWriter.getISOBytes("\\shpwr3"));
    		break;
    	case SHAPE_WRAP_TOP_BOTTOM:
    		result.write(DocWriter.getISOBytes("\\shpwr1"));
    		break;
    	case SHAPE_WRAP_BOTH:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk0"));
    		break;
    	case SHAPE_WRAP_LEFT:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk1"));
    		break;
    	case SHAPE_WRAP_RIGHT:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk2"));
    		break;
    	case SHAPE_WRAP_LARGEST:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk3"));
    		break;
    	case SHAPE_WRAP_TIGHT_BOTH:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk0"));
    		break;
    	case SHAPE_WRAP_TIGHT_LEFT:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk1"));
    		break;
    	case SHAPE_WRAP_TIGHT_RIGHT:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk2"));
    		break;
    	case SHAPE_WRAP_TIGHT_LARGEST:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk3"));
    		break;
    	case SHAPE_WRAP_THROUGH:
    		result.write(DocWriter.getISOBytes("\\shpwr5"));
    		break;
    	default:
    		result.write(DocWriter.getISOBytes("\\shpwr3"));
    	}
    	if(this.inHeader) {
    		result.write(DocWriter.getISOBytes("\\shpfhdr1"));
    	} 
    	this.doc.outputDebugLinebreak(result);
    	result.write(OPEN_GROUP);
    	result.write(DocWriter.getISOBytes("\\*\\shpinst"));
    	Iterator it = this.properties.values().iterator();
    	while(it.hasNext()) {
    		RtfShapeProperty rsp = (RtfShapeProperty) it.next();
    		rsp.setRtfDocument(this.doc);
    		rsp.writeContent(result);
    	}
    	if(!this.shapeText.equals("")) {
    		result.write(OPEN_GROUP);
    		result.write(DocWriter.getISOBytes("\\shptxt"));
    		result.write(DELIMITER);
    		result.write(DocWriter.getISOBytes(this.shapeText));
    		result.write(CLOSE_GROUP);
    	}
    	result.write(CLOSE_GROUP);
    	this.doc.outputDebugLinebreak(result);
    	result.write(CLOSE_GROUP);
		
    }
406439
@Override
  public int nextDoc() throws IOException {
    do {
      IndexDoc indexDoc = mtasCodecInfo.getNextDoc(field, docId);
      if (indexDoc != null) {
        docId = indexDoc.docId;
        minPosition = Math.max(start, indexDoc.minPosition);
        maxPosition = Math.min(end, indexDoc.maxPosition);
        currentStartPosition = -1;
        currentEndPosition = -1;
      } else {
        docId = NO_MORE_DOCS;
        minPosition = NO_MORE_POSITIONS;
        maxPosition = NO_MORE_POSITIONS;
        currentStartPosition = NO_MORE_POSITIONS;
        currentEndPosition = NO_MORE_POSITIONS;
      }
    } while (docId != NO_MORE_DOCS && (minPosition > maxPosition));
    return docId;
  }
1305103
@Override
    public void newDoc() throws IOException {
        sb = new StringBuilder();
        baos = new ByteArrayOutputStream();
        generator = jsonFactory.createJsonGenerator(baos);
        generator.writeStartObject(); 
    }
620092
public static Document buildPDFDocument (com.snowtide.pdf.Document pdf) throws IOException {
        return buildPDFDocument(pdf, DEFAULT_CONFIG);
    }
690289
public static void printDoc(final Document doc) {
        try {
            final Transformer trans = TransformerFactory.newInstance()
                    .newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            trans.transform(new DOMSource(doc), new StreamResult(System.out));
        } catch (final TransformerConfigurationException e) {
            LOG.error("Could not configure transformer", e);
        } catch (final TransformerFactoryConfigurationError e) {
            LOG.error("Could not configure transformer factory", e);
        } catch (final TransformerException e) {
            LOG.error("Error running transformation", e);
        }
    }
1136670
private void importCell(PdfPCell cell) {
        this.content = new ArrayList();
        
        if(cell == null) {
            this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.getParentTable().getBorders());
            return;
        }
        
        // padding
        this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();
        this.cellPaddingBottom = cell.getPaddingBottom();
        this.cellPaddingTop = cell.getPaddingTop();
        this.cellPaddingRight = cell.getPaddingRight();
        this.cellPaddingLeft = cell.getPaddingLeft();
        
        // BORDERS
        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.getBorder(), cell.getBorderWidth(), cell.getBorderColor());

        // border colors
        this.border = cell.getBorder();
        this.borderColor = cell.getBorderColor();
        this.borderColorBottom = cell.getBorderColorBottom();
        this.borderColorTop = cell.getBorderColorTop();
        this.borderColorLeft = cell.getBorderColorLeft();
        this.borderColorRight = cell.getBorderColorRight();
        
        // border widths
        this.borderWidth = cell.getBorderWidth();
        this.borderWidthBottom = cell.getBorderWidthBottom();
        this.borderWidthTop = cell.getBorderWidthTop();
        this.borderWidthLeft = cell.getBorderWidthLeft();
        this.borderWidthRight = cell.getBorderWidthRight();
        
       
        this.colspan = cell.getColspan();
        this.rowspan = 1; //cell.getRowspan();
//        if(cell.getRowspan() > 1) {
//            this.mergeType = MERGE_VERT_PARENT;
//        }

        
        this.verticalAlignment = cell.getVerticalAlignment();
        
        if(cell.getBackgroundColor() == null) {
            this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
        } else {
            this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor());
        }
        
        
        // does it have column composite info?
        java.util.List compositeElements = cell.getCompositeElements();
        if(compositeElements != null) {
	        Iterator cellIterator = compositeElements.iterator();
	        // does it have column info?
	        Paragraph container = null;
	        while(cellIterator.hasNext()) {
	            try {
	                Element element = (Element) cellIterator.next();
	                // should we wrap it in a paragraph
	                if(!(element instanceof Paragraph) && !(element instanceof List)) {
	                    if(container != null) {
	                        container.add(element);
	                    } else {
	                        container = new Paragraph();
	                        container.setAlignment(cell.getHorizontalAlignment());
	                        container.add(element);
	                    }
	                } else {
	                    if(container != null) {
	                        RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
	                        for(int i = 0; i < rtfElements.length; i++) {
	                            rtfElements[i].setInTable(true);
	                            this.content.add(rtfElements[i]);
	                        }
	                        container = null;
	                    }
	                    // if horizontal alignment is undefined overwrite
	                    // with that of enclosing cell
	                    if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
	                        ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());
	                    }
	
	                    RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element);
	                    for(int i = 0; i < rtfElements.length; i++) {
	                        rtfElements[i].setInTable(true);
	                        this.content.add(rtfElements[i]);
	                    }
	                }
	            } catch(DocumentException de) {
	                de.printStackTrace();
	            }
	        }
	        if(container != null) {
	            try {
	                RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
	                for(int i = 0; i < rtfElements.length; i++) {
	                    rtfElements[i].setInTable(true);
	                    this.content.add(rtfElements[i]);
	                }
	            } catch(DocumentException de) {
	                de.printStackTrace();
	            }
	        }
        }

        // does it have image info?

        Image img = cell.getImage();
        if(img != null) {
            try {
				RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(img);
				for (int i = 0; i < rtfElements.length; i++) {
					rtfElements[i].setInTable(true);
					this.content.add(rtfElements[i]);
				}
			} catch (DocumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
        // does it have phrase info?
        Phrase phrase = cell.getPhrase();
        if(phrase != null) {
            try {
				RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(phrase);
				for (int i = 0; i < rtfElements.length; i++) {
					rtfElements[i].setInTable(true);
					this.content.add(rtfElements[i]);
				}
			} catch (DocumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
        // does it have table info?
        PdfPTable table = cell.getTable();
        if(table != null) {
        	this.add(table);
//            try {
//				RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(table);
//				for (int i = 0; i < rtfElements.length; i++) {
//					rtfElements[i].setInTable(true);
//					this.content.add(rtfElements[i]);
//				}
//			} catch (DocumentException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
        }

    }