private Locale getLocale(String name) { for (Locale locale : Locale.getAvailableLocales()) { if (locale.toString().equals(name)) { return locale; } } assert Locale.ROOT.toString().equals(""); if (name.equals(Locale.ROOT.toString())) { return Locale.ROOT; } throw new MorphlineCompilationException("Unknown locale: " + name, getConfig()); }
@Override protected List<ApplicationResource> getSources(ApplicationContext applicationContext) { Collection<ApplicationResource> resources = new ArrayList<>(); Set<String> definitions = getTilesDefinitions(applicationContext.getInitParams()); for (String definition : definitions) { resources.addAll(applicationContext.getResources(definition)); } List<ApplicationResource> filteredResources = new ArrayList<>(); for (ApplicationResource resource : resources) { if (Locale.ROOT.equals(resource.getLocale())) { filteredResources.add(resource); } } return filteredResources; }
@Override public void beginWikiDocumentLocale(Locale locale, FilterEventParameters parameters) throws FilterException { if (this.writer == null) { if (this.wikiWriter == null && (this.properties.isForceDocument() || isTargetTextualContent())) { this.writer = new FilterStreamXMLStreamWriter(this.properties, true); } else { if (this.wikiWriter == null) { this.wikiWriter = new XARWikiWriter( this.properties.getPackageName() != null ? this.properties.getPackageName() : "package", this.properties); } this.writer = new FilterStreamXMLStreamWriter( this.wikiWriter.newEntry( new LocalDocumentReference(this.currentDocumentReference, locale)), this.properties.getEncoding(), this.properties.isFormat(), true); } } this.writer.writeStartDocument(this.properties.getEncoding(), "1.0"); this.writer.writeStartElement(XarDocumentModel.ELEMENT_DOCUMENT); this.writer.writeAttribute( XarDocumentModel.ATTRIBUTE_DOCUMENT_SPECVERSION, XarDocumentModel.VERSION_12); this.writer.writeAttribute( XarDocumentModel.ATTRIBUTE_DOCUMENT_REFERENCE, localSerializer.serialize(this.currentDocumentReference)); this.writer.writeAttribute(XarDocumentModel.ATTRIBUTE_DOCUMENT_LOCALE, toString(locale)); // Legacy space and name if (this.currentDocumentReference.getParent().getParent() == null) { // If single space behave as it used to and put the space name instead of the reference to // keep // compatibility when importing in older version this.writer.writeElement( XarDocumentModel.ELEMENT_SPACE, this.currentDocumentReference.getParent().getName()); } else { // If nested space put the space reference in the field this.writer.writeElement( XarDocumentModel.ELEMENT_SPACE, defaultSerializer.serialize(this.currentDocumentReference.getParent())); } this.writer.writeElement( XarDocumentModel.ELEMENT_NAME, this.currentDocumentReference.getName()); // Legacy locale this.writer.writeElement(XarDocumentModel.ELEMENT_LOCALE, toString(locale)); this.writer.writeElement( XarDocumentModel.ELEMENT_DEFAULTLOCALE, toString(this.currentDocumentParameters.get(XWikiWikiDocumentFilter.PARAMETER_LOCALE))); this.writer.writeElement( XarDocumentModel.ELEMENT_ISTRANSLATION, locale != null && !Locale.ROOT.equals(locale) ? "1" : "0"); if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CREATION_AUTHOR)) { this.writer.writeElement( XarDocumentModel.ELEMENT_CREATION_AUTHOR, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CREATION_AUTHOR)); } if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CREATION_DATE)) { this.writer.writeElement( XarDocumentModel.ELEMENT_CREATION_DATE, toString((Date) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CREATION_DATE))); } if (this.properties.isPreserveVersion() && parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS)) { this.writer.writeElement( XarDocumentModel.ELEMENT_REVISIONS, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS)); } }