For creating new spaces in repository, you can write your own java-backed webscript and using create() method of fileFolderService, can create the new spaces in the repository. This would be pretty simple.
Just to add on to above, if you want to write your own webscript to create content in space, you may refer to AddContentDialog.java class - saveContent() method. It will give you a clear idea.