@Test public void toRestTranslationsForRootLocale() throws XWikiException { Document document = mock(Document.class); when(document.getDefaultLocale()).thenReturn(Locale.ROOT); Translations translations = this.modelFactory.toRestTranslations(this.baseURI, document); assertEquals("", translations.getDefault()); assertTrue(translations.getTranslations().isEmpty()); }
public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException { Translations translations = this.objectFactory.createTranslations(); translations.setDefault(doc.getDefaultLocale().toString()); List<Locale> locales = doc.getTranslationLocales(); List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace()); if (!locales.isEmpty() && !Locale.ROOT.equals(doc.getDefaultLocale())) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(doc.getDefaultLocale().toString()); String pageTranslationUri = Utils .createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getDocumentReference().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.getDocumentReference().getName()).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } for (Locale locale : locales) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(locale.toString()); String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getDocumentReference().getName(), locale).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.getDocumentReference().getName(), locale).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } return translations; }
ModelFactory { public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException { Translations translations = this.objectFactory.createTranslations(); translations.setDefault(doc.getDefaultLocale().toString()); List<Locale> locales = doc.getTranslationLocales(); List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace()); if (!locales.isEmpty() && !Locale.ROOT.equals(doc.getDefaultLocale())) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(doc.getDefaultLocale().toString()); String pageTranslationUri = Utils .createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getDocumentReference().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.getDocumentReference().getName()).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } for (Locale locale : locales) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(locale.toString()); String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getDocumentReference().getName(), locale).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.getDocumentReference().getName(), locale).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } return translations; } }
ModelFactory { public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException { Translations translations = this.objectFactory.createTranslations(); translations.setDefault(doc.getDefaultLocale().toString()); List<Locale> locales = doc.getTranslationLocales(); List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace()); if (!locales.isEmpty() && !Locale.ROOT.equals(doc.getDefaultLocale())) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(doc.getDefaultLocale().toString()); String pageTranslationUri = Utils .createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getDocumentReference().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.getDocumentReference().getName()).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } for (Locale locale : locales) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(locale.toString()); String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getDocumentReference().getName(), locale).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.getDocumentReference().getName(), locale).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } return translations; } ModelFactory(); }
ModelFactory { public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException { Translations translations = this.objectFactory.createTranslations(); translations.setDefault(doc.getDefaultLocale().toString()); List<Locale> locales = doc.getTranslationLocales(); List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace()); if (!locales.isEmpty() && !Locale.ROOT.equals(doc.getDefaultLocale())) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(doc.getDefaultLocale().toString()); String pageTranslationUri = Utils .createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getDocumentReference().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.getDocumentReference().getName()).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } for (Locale locale : locales) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(locale.toString()); String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getDocumentReference().getName(), locale).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.getDocumentReference().getName(), locale).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } return translations; } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self); }
ModelFactory { public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException { Translations translations = this.objectFactory.createTranslations(); translations.setDefault(doc.getDefaultLocale().toString()); List<Locale> locales = doc.getTranslationLocales(); List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace()); if (!locales.isEmpty() && !Locale.ROOT.equals(doc.getDefaultLocale())) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(doc.getDefaultLocale().toString()); String pageTranslationUri = Utils .createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getDocumentReference().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.getDocumentReference().getName()).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } for (Locale locale : locales) { Translation translation = this.objectFactory.createTranslation(); translation.setLanguage(locale.toString()); String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getDocumentReference().getName(), locale).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.getDocumentReference().getName(), locale).toString(); Link historyLink = this.objectFactory.createLink(); historyLink.setHref(historyUri); historyLink.setRel(Relations.HISTORY); translation.getLinks().add(historyLink); translations.getTranslations().add(translation); } return translations; } ModelFactory(); boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage); ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); void toObject(com.xpn.xwiki.api.Object xwikiObject, org.xwiki.rest.model.jaxb.Object restObject); Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion,
        Boolean withPrettyNames); Wiki toRestWiki(URI baseUri, String wikiName); Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home); Translations toRestTranslations(URI baseUri, Document doc); PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames); Page toRestPage(URI baseUri, URI self, Document doc, boolean useVersion, Boolean withPrettyNames,
        Boolean withObjects, Boolean withXClass, Boolean withAttachments); Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        Boolean withPrettyNames, boolean versionURL); Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment,
        String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL); Hierarchy toRestHierarchy(EntityReference targetEntityReference, Boolean withPrettyNames); JobRequest toRestJobRequest(Request request); JobId toRestJobId(List<String> id); MapEntry toRestMapEntry(String key, java.lang.Object value); DefaultRequest toJobRequest(JobRequest restJobRequest); JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request,
        boolean progress, boolean log, String logFromLevel); JobProgress toRestJobProgress(org.xwiki.job.event.status.JobProgress progress); JobLog toRestJobLog(LogTail logQueue, URI self, String level, String fromLevel); JobLog toRestJobLog(Iterable<LogEvent> logs, URI self);  }