Return-Path: Delivered-To: apmail-cocoon-lenya-cvs-archive@cocoon.apache.org Received: (qmail 28213 invoked by uid 500); 13 Aug 2003 10:02:18 -0000 Mailing-List: contact lenya-cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: "Lenya CVS Mailing List" Delivered-To: mailing list lenya-cvs@cocoon.apache.org Received: (qmail 28200 invoked from network); 13 Aug 2003 10:02:18 -0000 Date: 13 Aug 2003 10:02:35 -0000 Message-ID: <20030813100235.1831.qmail@minotaur.apache.org> From: egli@apache.org To: cocoon-lenya-cvs@apache.org Subject: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication DefaultDocumentBuilder.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N egli 2003/08/13 03:02:35 Modified: src/java/org/apache/lenya/cms/publication DefaultDocumentBuilder.java Log: Be a little bit more clever when it comes to picking a language if none is specified. It used to simply choose the default language, but that might not exist for this document. So check if the document has a version in the default lang, if not pick the first one from the list of langs that the document has. Revision Changes Path 1.11 +36 -8 cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java Index: DefaultDocumentBuilder.java =================================================================== RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- DefaultDocumentBuilder.java 12 Aug 2003 16:27:12 -0000 1.10 +++ DefaultDocumentBuilder.java 13 Aug 2003 10:02:35 -0000 1.11 @@ -55,12 +55,12 @@ */ package org.apache.lenya.cms.publication; +import java.util.HashMap; + /** * @author andreas * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments */ public class DefaultDocumentBuilder implements DocumentBuilder { /** @@ -104,7 +104,9 @@ String fullLanguage = "".equals(language) ? "" : ("_" + language); documentURL = documentURL.substring(0, documentURL.length() - fullLanguage.length()); + boolean defaultLanguageForced = false; if ("".equals(language)) { + defaultLanguageForced = true; language = publication.getDefaultLanguage(); } @@ -119,6 +121,30 @@ DefaultDocument document = new DefaultDocument(publication, documentId, area, language); document.setExtension(extension); document.setDocumentURL(originalURL); + + if (defaultLanguageForced) { + // unfortunatelly we cannot count on the document to always be available + // in the default language. So if the default language is not in the list + // of available languages for this document, simply use the first available + // language. + HashMap languagesMap = new HashMap(); + String[] languages = null; + try { + languages = document.getLanguages(); + } catch (DocumentException e) { + throw new DocumentBuildException(e); + } + // If the document has no languages, we'll just leave it + // as it is (i.e. we leave it at the default language) + if (languages.length > 0) { + for (int i = 0; i < languages.length; i++) { + languagesMap.put(languages[i], languages[i]); + } + if (!languagesMap.containsKey(document.getLanguage())) { + document.setLanguage(languages[0]); + } + } + } return document; } @@ -157,17 +183,19 @@ /** * @see org.apache.lenya.cms.publication.DocumentBuilder#isDocument(org.apache.lenya.cms.publication.Publication, java.lang.String) */ - public boolean isDocument(Publication publication, String url) throws DocumentBuildException { + public boolean isDocument(Publication publication, String url) + throws DocumentBuildException { boolean isDocument = false; - - String publicationURI = url.substring(("/" + publication.getId()).length()); + + String publicationURI = + url.substring(("/" + publication.getId()).length()); if (publicationURI.startsWith("/")) { publicationURI = publicationURI.substring(1); - + int slashIndex = publicationURI.indexOf("/"); if (slashIndex > -1) { String area = publicationURI.substring(0, slashIndex); - + String documentUri = publicationURI.substring(slashIndex); if (documentUri.startsWith("/")) { isDocument = true; --------------------------------------------------------------------- To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org