use of org.xwiki.rest.model.jaxb.Translations in project xwiki-platform by xwiki.
the class ModelFactory method toRestTranslations.
public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException {
Translations translations = this.objectFactory.createTranslations();
List<String> languages = doc.getTranslationList();
List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace());
if (!languages.isEmpty()) {
if (!doc.getDefaultLanguage().equals("")) {
translations.setDefault(doc.getDefaultLanguage());
Translation translation = this.objectFactory.createTranslation();
translation.setLanguage(doc.getDefaultLanguage());
/* Add the default page with the default translation explicitely */
String pageTranslationUri = Utils.createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getName()).toString();
Link pageTranslationLink = this.objectFactory.createLink();
pageTranslationLink.setHref(pageTranslationUri);
pageTranslationLink.setRel(Relations.PAGE);
translation.getLinks().add(pageTranslationLink);
String historyUri = Utils.createURI(baseUri, PageHistoryResource.class, doc.getWiki(), spaces, doc.getName()).toString();
Link historyLink = this.objectFactory.createLink();
historyLink.setHref(historyUri);
historyLink.setRel(Relations.HISTORY);
translation.getLinks().add(historyLink);
translations.getTranslations().add(translation);
}
}
for (String language : languages) {
Translation translation = this.objectFactory.createTranslation();
translation.setLanguage(language);
String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getName(), language).toString();
Link pageTranslationLink = this.objectFactory.createLink();
pageTranslationLink.setHref(pageTranslationUri);
pageTranslationLink.setRel(Relations.PAGE);
translation.getLinks().add(pageTranslationLink);
String historyUri = Utils.createURI(baseUri, PageTranslationHistoryResource.class, doc.getWiki(), spaces, doc.getName(), language).toString();
Link historyLink = this.objectFactory.createLink();
historyLink.setHref(historyUri);
historyLink.setRel(Relations.HISTORY);
translation.getLinks().add(historyLink);
translations.getTranslations().add(translation);
}
return translations;
}
Aggregations