Example #1
0
 @Override
 public Document getVersion(String versionableId, VersionModel versionModel) {
   Serializable vid = idFromString(versionableId);
   Node versionNode = session.getVersionByLabel(vid, versionModel.getLabel());
   if (versionNode == null) {
     return null;
   }
   versionModel.setDescription(
       versionNode.getSimpleProperty(Model.VERSION_DESCRIPTION_PROP).getString());
   versionModel.setCreated(
       (Calendar) versionNode.getSimpleProperty(Model.VERSION_CREATED_PROP).getValue());
   return newDocument(versionNode);
 }
Example #2
0
  // "readonly" meaningful for proxies and versions, used for import
  private Document newDocument(Node node, boolean readonly) {
    if (node == null) {
      // root's parent
      return null;
    }

    Node targetNode = null;
    String typeName = node.getPrimaryType();
    if (node.isProxy()) {
      Serializable targetId = node.getSimpleProperty(Model.PROXY_TARGET_PROP).getValue();
      if (targetId == null) {
        throw new NoSuchDocumentException("Proxy has null target");
      }
      targetNode = session.getNodeById(targetId);
      typeName = targetNode.getPrimaryType();
    }
    SchemaManager schemaManager = Framework.getLocalService(SchemaManager.class);
    DocumentType type = schemaManager.getDocumentType(typeName);
    if (type == null) {
      throw new NoSuchDocumentException("Unknown document type: " + typeName);
    }

    if (node.isProxy()) {
      // proxy seen as a normal document
      Document proxy = new SQLDocumentLive(node, type, this, false);
      Document target = newDocument(targetNode, readonly);
      return new SQLDocumentProxy(proxy, target);
    } else if (node.isVersion()) {
      return new SQLDocumentVersion(node, type, this, readonly);
    } else {
      return new SQLDocumentLive(node, type, this, false);
    }
  }
Example #3
0
 @Override
 public Document createProxy(Document doc, Document folder) {
   Node folderNode = ((SQLDocument) folder).getNode();
   Node targetNode = ((SQLDocument) doc).getNode();
   Serializable targetId = targetNode.getId();
   Serializable versionableId;
   if (doc.isVersion()) {
     versionableId = targetNode.getSimpleProperty(Model.VERSION_VERSIONABLE_PROP).getValue();
   } else if (doc.isProxy()) {
     // copy the proxy
     targetId = targetNode.getSimpleProperty(Model.PROXY_TARGET_PROP).getValue();
     versionableId = targetNode.getSimpleProperty(Model.PROXY_VERSIONABLE_PROP).getValue();
   } else {
     // working copy (live document)
     versionableId = targetId;
   }
   String name = findFreeName(folderNode, doc.getName());
   Node proxy = session.addProxy(targetId, versionableId, folderNode, name, null);
   return newDocument(proxy);
 }