Create a Document.

@param file  The document .
@param title  The document title.
@param format  The document format.

@return A CreateDocumentResponse object containing the information returned by Document.
169032
public CreateDocumentResponse createDocument(File file, String title, String format) {
        CreateDocumentRequest request = new CreateDocumentRequest();
        request.setFile(file);
        request.setTitle(title);
        request.setFormat(format);
        return this.createDocument(request);
    }
66876
Document createDocument(String id) throws RepositoryException
   {
      ItemData data = handler.getContext().getItemStateManager().getItemData(id);
      if (data == null)
      {
         throw new ItemNotFoundException("Item id=" + id + " not found");
      }
      if (!data.isNode())
      {
         throw new RepositoryException("Item with id " + id + " is not a node");
      }
      return createDocument((NodeData)data);

   }
318109
protected static Document createDocument(String document) throws PolicyIndexException {

        // parse policy document and create dom
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(new StringReader(document)));
            return doc;
        } catch (ParserConfigurationException e) {
            throw new PolicyIndexException(e);
        } catch (SAXException e) {
            throw new PolicyIndexException(e);
        } catch (IOException e) {
            throw new PolicyIndexException(e);
        }
    }
629743
function createPost( file, options ) {

	resetDoc();

	var _formatDate = options && typeof options.formatDate === 'function' ?
				options.formatDate : formatDate,
			post = new Post();

	// Parse front matter to get as many post attributes as possible
	parseFrontMatter( file, post, options );

	// Get category from path if not from front matter
	if ( !post.category ) {

		post.category = getCategoryFromPath( file );
	}

	// Get creation date from file if not from front matter
	if ( !post.created ) {

		post.created = _formatDate( file.stat.ctime );
	}

	// Get excerpt from first <p> tag if not from front matter
	if ( !post.excerpt ) {

		post.excerpt = getDefaultExcerpt( post.content );
	}

	// Get title from file name if not from front matter
	if ( !post.title ) {

		post.title = getTitleFromPath( file );
	}

	// Get updated date from file if not from front matter
	if ( !post.updated ) {

		post.updated = _formatDate( file.stat.mtime );

		/*
		 * If updated date from file system matches creation date,
		 * assume udated date should be empty
		 */
		if ( post.updated === post.created ) {

			post.updated = '';
		}
	}

	return JSON.stringify( post );
}
1195175
protected Document createDocument(String spaceId, String key) {
        Document doc = new Document();
        doc.add(new StringField(FIELD_SPACE_ID, spaceId.trim(), Store.YES));
        doc.add(new StringField(FIELD_KEY, key.trim(), Store.YES));
        doc.add(new StringField(FIELD_ID, spaceId.trim() + ":" + key.trim(), Store.NO));
        return doc;
    }
801700
public CreateDocumentFromBosResponse createDocumentFromBos(CreateDocumentFromBosRequest request) {
        checkNotNull(request, "request should not be null.");
        checkNotNull(request.getBucket(), "bucket should not be null.");
        checkNotNull(request.getObject(), "object should not be null.");
        checkNotNull(request.getTitle(), "title should not be null.");
        checkNotNull(request.getFormat(), "format should not be null.");
        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, DOC);
        internalRequest.addParameter("source", "bos");
        String strJson = JsonUtils.toJsonString(request);
        byte[] requestJson = null;
        try {
            requestJson = strJson.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            throw new BceClientException("Unsupported encode.", e);
        }

        internalRequest.addHeader(Headers.CONTENT_LENGTH, String.valueOf(requestJson.length));
        internalRequest.addHeader(Headers.CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
        internalRequest.setContent(RestartableInputStream.wrap(requestJson));
        return invokeHttpClient(internalRequest, CreateDocumentFromBosResponse.class);
    }
321101
public static DownloadResponse exportFile(Drive drive, File file, String format) throws IOException {
	  return exportFile(drive, file.getId(), format);
	}
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
273802
public void fromXML(File file) throws DocumentException
    {
        SAXReader reader = new SAXReader();
        fromXML(reader.read(file));

    }
914763
public void setFormat(final String format) {
        if (format == null && this.format == null) {
            return;
        } else if (format == null) {
            removeChild(this.format);
            this.format = null;
        } else if (this.format == null) {
            this.format = new KeyValueNode<String>(CommonConstants.CS_FORMAT_TITLE, format);
            appendChild(this.format, false);
        } else {
            this.format.setValue(format);
        }
    }
428762
public static Document createDocument(InputStream input) throws IOException
    {
        Check.notNull(input);

        try
        {
            return getDocumentFactory().parse(input);
        }
        catch (final SAXException exception)
        {
            throw new IOException(exception);
        }
    }
550935
public static void createSummaryInformation(String filePath, String title) {

        if (filePath == null) {
            return;
        }
        try {
            File poiFilesystem = new File(filePath);
            InputStream is = new FileInputStream(poiFilesystem);
            POIFSFileSystem poifs = new POIFSFileSystem(is);
            is.close();
            DirectoryEntry dir = poifs.getRoot();

            SummaryInformation si = PropertySetFactory.newSummaryInformation();
            si.setTitle(title);
            si.setAuthor(ReleaseInfoAdapter.getCompany());
            si.setApplicationName("NextReports " + ReleaseInfoAdapter.getVersionNumber());
            si.setSubject("Created by NextReports Designer" + ReleaseInfoAdapter.getVersionNumber());
            si.setCreateDateTime(new Date());
            si.setKeywords(ReleaseInfoAdapter.getHome());

            si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);

            OutputStream out = new FileOutputStream(poiFilesystem);
            poifs.writeFilesystem(out);
            out.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
1059177
public static PdfLayer createTitle(String title, PdfWriter writer) {
        if (title == null)
            throw new NullPointerException("Title cannot be null.");
        PdfLayer layer = new PdfLayer(title);
        writer.registerLayer(layer);
        return layer;
    }
278507
@Override
  public <T> void createCollection(String collectionName) {
    CollectionMetaData cmd = cmdMap.get(collectionName);
    if (null == cmd) {
      throw new InvalidJsonDbApiUsageException(
          "No class found with @Document Annotation and attribute collectionName as: " + collectionName);
    }
    @SuppressWarnings("unchecked")
    Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
    if (null != collection) {
      throw new InvalidJsonDbApiUsageException("Collection by name '" + collectionName + "' already exists.");
    }

    cmd.getCollectionLock().writeLock().lock();

    // Some other thread might have created same collection when this thread reached this point
    if(collectionsRef.get().get(collectionName) != null) {
      return;
    }

    try {
      String collectionFileName = collectionName + ".json";
      File fileObject = new File(dbConfig.getDbFilesLocation(), collectionFileName);
      try {
        fileObject.createNewFile();
      } catch (IOException e) {
        logger.error("IO Exception creating the collection file {}", collectionFileName, e);
        throw new InvalidJsonDbApiUsageException("Unable to create a collection file for collection: " + collectionName);
      }

      if (Util.stampVersion(dbConfig, fileObject, cmd.getSchemaVersion())) {
        collection = new LinkedHashMap<Object, T>();
        collectionsRef.get().put(collectionName, collection);
        contextsRef.get().put(collectionName, JXPathContext.newContext(collection.values())) ;
        fileObjectsRef.get().put(collectionName, fileObject);
        cmd.setActualSchemaVersion(cmd.getSchemaVersion());
      } else {
        fileObject.delete();
        throw new JsonDBException("Failed to stamp version for collection: " + collectionName);
      }
    } finally {
      cmd.getCollectionLock().writeLock().unlock();
    }
  }
568138
private void createFile(String filename, int position, String content, Hashtable properties) {

        String vfsFileName = (String)m_fileIndex.get(filename.replace('\\', '/'));

        if (vfsFileName != null) {
            try {

                m_report.print(Messages.get().container(Messages.RPT_CREATE_FILE_0), I_CmsReport.FORMAT_NOTE);
                m_report.print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        vfsFileName));
                m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

                // check if we have to set the navpos property.
                if ((properties.get(CmsPropertyDefinition.PROPERTY_NAVPOS) == null)
                    && (properties.get(CmsPropertyDefinition.PROPERTY_NAVTEXT) != null)) {
                    // set the position in the folder as navpos
                    // we have to add one to the position, since it is counted from 0
                    properties.put(CmsPropertyDefinition.PROPERTY_NAVPOS, (position + 1) + "");
                }

                // create new XML page
                Locale locale = CmsLocaleManager.getLocale(m_locale);
                CmsXmlPage page = new CmsXmlPage(locale, OpenCms.getSystemInfo().getDefaultEncoding());
                page.addValue(m_element, locale);
                page.setStringValue(m_cmsObject, m_element, locale, content);

                // check links
                CmsLinkTable linkTable = page.getLinkTable(m_element, locale);
                Iterator i = linkTable.iterator();
                while (i.hasNext()) {
                    CmsLink link = (CmsLink)i.next();
                    String target = link.getTarget();
                    // do only update internal links
                    if (link.isInternal()) {
                        target = m_cmsObject.getRequestContext().getFileTranslator().translateResource(target);
                        // update link
                        link.updateLink(target, link.getAnchor(), link.getQuery());
                        link.checkConsistency(m_cmsObject);
                    }
                }
                // marshal XML page and get the content
                byte[] contentByteArray = page.marshal();
                List oldProperties = new ArrayList();

                int xmlPageId = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeXmlPage.getStaticTypeName()).getTypeId();
                if (!m_overwrite) {
                    m_cmsObject.createResource(vfsFileName, xmlPageId, contentByteArray, new ArrayList());
                } else {
                    try {
                        // try if the file is there
                        oldProperties = m_cmsObject.readPropertyObjects(vfsFileName, false);
                        CmsLock lock = m_cmsObject.getLock(vfsFileName);
                        if (lock.getType() != CmsLockType.EXCLUSIVE) {
                            m_cmsObject.lockResource(vfsFileName);
                        }
                        m_cmsObject.deleteResource(vfsFileName, CmsResource.DELETE_PRESERVE_SIBLINGS);
                    } catch (CmsException e) {
                        // the file did not exist, so we do not have to delete it
                    } finally {
                        // create the new resource
                        m_report.print(Messages.get().container(Messages.RPT_OVERWRITE_0), I_CmsReport.FORMAT_NOTE);
                        m_report.print(
                            org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
                        m_cmsObject.createResource(vfsFileName, xmlPageId, contentByteArray, new ArrayList());
                    }
                }
                // create all properties and put them in an ArrayList
                Iterator it = properties.entrySet().iterator();
                List propertyList = new ArrayList();
                while (it.hasNext()) {
                    // get property and value
                    Map.Entry entry = (Map.Entry)it.next();
                    String propertyKey = (String)entry.getKey();
                    String propertyVal = (String)entry.getValue();
                    // create new Property Object
                    CmsProperty property = new CmsProperty(propertyKey, propertyVal, propertyVal);
                    // create implicitly if Property doesn't exist already
                    property.setAutoCreatePropertyDefinition(true);
                    // add new property to the list
                    propertyList.add(property);
                }
                // try to write the properties
                try {
                    m_cmsObject.writePropertyObjects(vfsFileName, propertyList);
                    // write the old properties if available
                    m_cmsObject.writePropertyObjects(vfsFileName, oldProperties);
                } catch (CmsException e1) {
                    e1.printStackTrace();
                }
                m_report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);
            } catch (CmsException e) {
                m_report.println(e);
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
1211452
public static Attachment writeAttachmentWithErrorMessage(Throwable throwable, String title) {
        String message = throwable.getMessage();
        try {
            return writeAttachment(message.getBytes(CONFIG.getAttachmentsEncoding()), title);
        } catch (Exception e) {
            e.addSuppressed(throwable);
            LOGGER.error(String.format("Can't write attachment \"%s\"", title), e);
        }
        return new Attachment();
    }
1136367
public static synchronized DocumentBuilder createDocumentBuilder() {
        DocumentBuilder result;
        try {
            result = FACTORY_NON_VALIDATING.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("createDocumentBuilder failed", e);
        }
        result.setErrorHandler(ERROR_HANDLER);
        return result;
    }