Source:
private void createDocument(CoreSession session, String name, boolean full) { DocumentModel doc = session.createDocumentModel("/", name, "ComplexDoc"); doc.getProperty("common:icon").setValue("/path/to/my/icon"); if (full) { doc.getProperty("common:icon-expanded").setValue("/path/to/my/icon-expanded"); } doc.getProperty("dublincore:modified").setValue(new Date()); doc.getProperty("dublincore:created").setValue(new Date()); doc.getProperty("dublincore:title").setValue("title"); doc.getProperty("dublincore:rights").setValue("rights"); doc.getProperty("dublincore:subjects").setValue(new String[] { "subject1", "subject2", "subject3" }); if (full) { doc.getProperty("dublincore:expired").setValue(new Date()); doc.getProperty("dublincore:issued").setValue(new Date()); doc.getProperty("dublincore:valid").setValue(new Date()); doc.getProperty("dublincore:nature").setValue("nature"); doc.getProperty("dublincore:source").setValue("source"); doc.getProperty("dublincore:format").setValue("format"); doc.getProperty("dublincore:creator").setValue("creator"); doc.getProperty("dublincore:coverage").setValue("coverage"); doc.getProperty("dublincore:language").setValue("language"); doc.getProperty("dublincore:publisher").setValue("publisher"); doc.getProperty("dublincore:description").setValue("description"); doc.getProperty("dublincore:lastContributor").setValue("lastContributor"); doc.getProperty("dublincore:contributors").setValue(new String[] { "contrib1", "contrib2", "contrib3" }); } if (full) { doc.getProperty("complexschema:attachedFile").setValue("name", "attachedFileName"); } ListProperty vignettes = (ListProperty) doc.getProperty("complexschema:attachedFile/vignettes"); for (String label : new String[] { "toto", "titi", "tutu", "tata" }) { vignettes.addValue(createVignette(label, full)); } session.createDocument(doc); }

Target:
private void createDocument(CoreSession session, String name, boolean full) throws IOException { DocumentModel doc = session.createDocumentModel("/", name, "ComplexDoc"); doc.getProperty("common:icon").setValue("/path/to/my/icon"); if (full) { doc.getProperty("common:icon-expanded").setValue("/path/to/my/icon-expanded"); } doc.getProperty("dc:title").setValue("title"); doc.getProperty("dc:rights").setValue("rights"); doc.getProperty("dc:created").setValue(new Date()); doc.getProperty("dc:modified").setValue(new Date()); doc.getProperty("dc:subjects").setValue(new String[] { "subject1", "subject2", "subject3" }); if (full) { doc.getProperty("dc:expired").setValue(new Date()); doc.getProperty("dc:issued").setValue(new Date()); doc.getProperty("dc:valid").setValue(new Date()); doc.getProperty("dc:nature").setValue("nature"); doc.getProperty("dc:source").setValue("source"); doc.getProperty("dc:format").setValue("format"); doc.getProperty("dc:creator").setValue("creator"); doc.getProperty("dc:coverage").setValue("coverage"); doc.getProperty("dc:language").setValue("language"); doc.getProperty("dc:publisher").setValue("publisher"); doc.getProperty("dc:description").setValue("description"); doc.getProperty("dc:lastContributor").setValue("lastContributor"); doc.getProperty("dc:contributors").setValue(new String[] { "contrib1", "contrib2", "contrib3" }); } if (full) { doc.getProperty("complexschema:attachedFile").setValue("name", "attachedFileName"); } ListProperty vignettes = (ListProperty) doc.getProperty("complexschema:attachedFile/vignettes"); for (String label : new String[] { "toto", "titi", "tutu", "tata" }) { vignettes.addValue(createVignette(label, full)); } session.createDocument(doc); }