public String getTranslatedContent(String language, XWikiContext context) throws XWikiException { XWikiDocument tdoc = getTranslatedDocument(language, context); return tdoc.getContent(); }
/** * Retrieve the document in the current context language as an XML string. The rendrered document content and all * XObjects are included. Document attachments and archived versions are excluded. You should prefer * toXML(OutputStream, true, true, false, false, XWikiContext)} or toXML(com.xpn.xwiki.util.XMLWriter, true, true, * false, false, XWikiContext) on the translated document when possible to reduce memory load. * * @param context current XWikiContext * @return a string containing an XML representation of the document in the current context language * @throws XWikiException when an error occurs during wiki operation */ public String getXMLContent(XWikiContext context) throws XWikiException { XWikiDocument tdoc = getTranslatedDocument(context); return tdoc.toXML(true, true, false, false, context); }
public XWikiDocument getTranslatedDocument(XWikiContext context) throws XWikiException { String language = context.getWiki().getLanguagePreference(context); return getTranslatedDocument(language, context); }
XWikiDocument tdocBundle = docBundle.getTranslatedDocument(this.context); list.add(tdocBundle); if (!tdocBundle.getRealLanguage().equals(defaultLanguage)) { XWikiDocument defdocBundle = docBundle.getTranslatedDocument(defaultLanguage, this.context); if (tdocBundle != defdocBundle) { list.add(defdocBundle);
/** * Helper method to help get a translated version of a document. It handles any exception raised to make it easy to * use. * * @param documentName the document's name (eg Space.Document) * @return the document object corresponding to the passed document's name. A translated version of the document for * the current Locale is looked for. */ public XWikiDocument getDocumentBundle(String documentName) { XWikiDocument docBundle; if (documentName.length() == 0) { docBundle = null; } else { try { // First, looks for a document suffixed by the language docBundle = this.context.getWiki().getDocument(documentName, this.context); docBundle = docBundle.getTranslatedDocument(this.context); } catch (XWikiException e) { // Error while loading the document. // TODO: A runtime exception should be thrown that will bubble up till the // topmost level. For now simply log the error LOG.error(String.format(LOAD_ERROR_MSG_FMT, documentName), e); docBundle = null; } } return docBundle; }
/** * @return the translated document in the given document */ public Document getTranslatedDocument(String language) throws XWikiException { return this.doc.getTranslatedDocument(language, getXWikiContext()).newDocument(getXWikiContext()); }
/** * @return the tranlated Document if the wiki is multilingual, the language is first checked in the URL, the * cookie, the user profile and finally the wiki configuration if not, the language is the one on the * wiki configuration. */ public Document getTranslatedDocument() throws XWikiException { return this.doc.getTranslatedDocument(getXWikiContext()).newDocument(getXWikiContext()); }
public void deleteAllDocuments(XWikiDocument doc, boolean totrash, XWikiContext context) throws XWikiException { // Delete all documents for (String lang : doc.getTranslationList(context)) { XWikiDocument tdoc = doc.getTranslatedDocument(lang, context); deleteDocument(tdoc, totrash, context); } deleteDocument(doc, context); }
public boolean add(String docFullName, String language, int DefaultAction, XWikiContext context) throws XWikiException { XWikiDocument doc = context.getWiki().getDocument(docFullName, context); if ((language == null) || (language.equals(""))) { add(doc, DefaultAction, context); } else { add(doc.getTranslatedDocument(language, context), DefaultAction, context); } return true; }
/** * Fetch translated document. * * @param documentReference reference to the document to be translated. * @return translated document. * @throws SolrIndexerException if problems occur. */ protected XWikiDocument getTranslatedDocument(DocumentReference documentReference) throws SolrIndexerException { try { XWikiDocument originalDocument = getDocument(documentReference); Locale locale = documentReference.getLocale(); if (locale == null || locale.equals(Locale.ROOT)) { return originalDocument; } XWikiDocument translatedDocument = originalDocument.getTranslatedDocument(locale, this.xcontextProvider.get()); // XWikiDocument#getTranslatedDocument returns the default document when the locale does not exist if (translatedDocument.getRealLocale().equals(locale)) { return translatedDocument; } } catch (Exception e) { throw new SolrIndexerException( String.format("Failed to get translated document for '%s'", documentReference), e); } return null; }
public boolean add(String docFullName, int DefaultAction, XWikiContext context) throws XWikiException { XWikiDocument doc = context.getWiki().getDocument(docFullName, context); add(doc, DefaultAction, context); List<String> languages = doc.getTranslationList(context); for (String language : languages) { if (!((language == null) || (language.equals("")) || (language.equals(doc.getDefaultLanguage())))) { add(doc.getTranslatedDocument(language, context), DefaultAction, context); } } return true; }
/** * Gets the translated version of a document, in the specified language. If the translation does not exist, a new * document translation is created. If the requested language does not correspond to a translation (is not defined * or is the same as the main document), then the main document is returned. * * @param doc the main (default, untranslated) document to translate * @param language the requested document language * @param context the current request context * @return the translated document, or the original untranslated document if the requested language is not a * translation * @throws XWikiException if the translation cannot be retrieved from the database */ protected XWikiDocument getTranslatedDocument(XWikiDocument doc, String language, XWikiContext context) throws XWikiException { XWikiDocument tdoc; if (StringUtils.isBlank(language) || language.equals("default") || language.equals(doc.getDefaultLanguage())) { tdoc = doc; } else { tdoc = doc.getTranslatedDocument(language, context); if (tdoc == doc) { tdoc = new XWikiDocument(doc.getDocumentReference()); tdoc.setLanguage(language); tdoc.setStore(doc.getStore()); } tdoc.setTranslation(1); } return tdoc; }
@Override public EditorDescriptor getDescriptor() { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext); XWikiDocument translatedEditorDocument = editorDocument.getTranslatedDocument(xcontext); this.descriptorBuilder.setName(translatedEditorDocument.getRenderedTitle(Syntax.PLAIN_1_0, xcontext)); this.descriptorBuilder.setDescription(translatedEditorDocument.getRenderedContent(Syntax.PLAIN_1_0, xcontext)); } catch (XWikiException e) { this.logger.warn("Failed to read the editor name and description. Root cause: " + ExceptionUtils.getRootCauseMessage(e)); } return this.descriptorBuilder.build(); }
@Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; // Update the default locale instance. this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget); this.progressManager.endStep(this); // Update the translations. for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } } }
/** * Helper function to prepare the XWiki documents and translations on the context and velocity context. <br> * TODO: check how this code could be written only once (not duplicate the prepareDocuments function in XWiki) * * @param docName the full name of the document to prepare context for * @param language the language of the document * @throws XWikiException if anything goes wrong accessing documents */ private void setUpDocuments(String docName, String language) throws XWikiException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); // prepare the messaging tools and set them on context xwiki.prepareResources(context); XWikiDocument doc = xwiki.getDocument(docName, context); // setup the xwiki context context.put("doc", doc); context.put("cdoc", doc); XWikiDocument tdoc = doc.getTranslatedDocument(language, context); context.put("tdoc", tdoc); // and render the xwikivars to have all the variables set ($has*, $blacklistedSpaces, etc) context.getWiki().renderTemplate("xwikivars.vm", context); }
doc = doc.getTranslatedDocument(getLanguage(), context);
protected int addTranslationOfDocument(DocumentReference documentReference, String language, XWikiContext wikiContext) throws XWikiException, InterruptedException { int retval = 0; XWikiDocument document = wikiContext.getWiki().getDocument(documentReference, wikiContext); XWikiDocument tdocument = document.getTranslatedDocument(language, wikiContext); // In order not to load the whole database in memory, we're limiting the number // of documents that are in the processing queue at a moment. We could use a // Bounded Queue in the index updater, but that would generate exceptions in the // rest of the platform, as the index rebuilder could fill the queue, and then a // user trying to save a document would cause an exception. Thus, it is better // to limit the index rebuilder thread only, and not the index updater. while (this.indexUpdater.getQueueSize() > this.indexUpdater.getMaxQueueSize()) { // Don't leave any database connections open while sleeping // This shouldn't be needed, but we never know what bugs might be there wikiContext.getWiki().getStore().cleanUp(wikiContext); Thread.sleep(RETRYINTERVAL); } addTranslationOfDocument(tdocument, wikiContext); ++retval; if (document == tdocument) { retval += this.indexUpdater.queueAttachments(document, wikiContext); } return retval; }
vcontext.put(VCONTEXT_CDOC, vcontext.get(VCONTEXT_DOC)); XWikiDocument tdoc = doc.getTranslatedDocument(context); context.put(CONTEXT_TDOC, tdoc); vcontext.put(VCONTEXT_TDOC, tdoc.newDocument(context));
XWikiDocument translationDocument = defaultDocument.getTranslatedDocument(locale, xcontext); this.documentLocaleParser.write(translationDocument, this.filter, this.properties); } catch (XWikiException e) {
} else { context.getDoc().getTranslatedDocument(context).setLock(context.getUser(), context);