Exemplo n.º 1
0
  @Override
  public DocumentModel create(
      CoreSession documentManager,
      Blob content,
      String path,
      boolean overwrite,
      String fullname,
      TypeManager typeService)
      throws ClientException, IOException {
    path = getNearestContainerPath(documentManager, path);
    doSecurityCheck(documentManager, path, getNoteTypeName(), typeService);

    String filename = FileManagerUtils.fetchFileName(fullname);

    String title = FileManagerUtils.fetchTitle(filename);

    // Looking if an existing Document with the same filename exists.
    DocumentModel docModel = FileManagerUtils.getExistingDocByTitle(documentManager, path, title);

    if (overwrite && docModel != null) {

      docModel.setProperty(NOTE_SCHEMA, NOTE_FIELD, getString(content));
      docModel.setProperty(NOTE_SCHEMA, MT_FIELD, content.getMimeType());
      docModel = overwriteAndIncrementversion(documentManager, docModel);
    } else {
      PathSegmentService pss;
      try {
        pss = Framework.getService(PathSegmentService.class);
      } catch (Exception e) {
        throw new ClientException(e);
      }
      // Create a new empty DocumentModel of type Note in memory
      docModel = documentManager.createDocumentModel(getNoteTypeName());

      // Update known attributes (title, note)
      docModel.setProperty(DUBLINCORE_SCHEMA, TITLE_FIELD, title);
      docModel.setProperty(NOTE_SCHEMA, NOTE_FIELD, getString(content));
      docModel.setProperty(NOTE_SCHEMA, MT_FIELD, content.getMimeType());

      // Create the new document in the repository
      docModel.setPathInfo(path, pss.generatePathSegment(docModel));
      docModel = documentManager.createDocument(docModel);
    }
    documentManager.save();

    log.debug(
        "Created the Note: "
            + docModel.getName()
            + " with icon: "
            + docModel.getProperty(COMMON_SCHEMA, ICON_FIELD));
    return docModel;
  }
Exemplo n.º 2
0
 @Test
 public void testCreateExistingBlobWithNonNFCNormalizedFilename() throws Exception {
   // Create doc from NFC normalized filename
   String fileName = "ÜÜÜ ÓÓÓ.rtf";
   String nfcNormalizedFileName = Normalizer.normalize(fileName, Normalizer.Form.NFC);
   Blob blob = Blobs.createBlob("Test content", "text/rtf", null, nfcNormalizedFileName);
   service.createDocumentFromBlob(
       coreSession, blob, workspace.getPathAsString(), true, nfcNormalizedFileName);
   assertNotNull(
       FileManagerUtils.getExistingDocByFileName(
           coreSession, workspace.getPathAsString(), nfcNormalizedFileName));
   // Check existing doc with non NFC (NFD) normalized filename
   String nfdNormalizedFileName = Normalizer.normalize(fileName, Normalizer.Form.NFD);
   assertNotNull(
       FileManagerUtils.getExistingDocByFileName(
           coreSession, workspace.getPathAsString(), nfdNormalizedFileName));
 }