1 17 18 19 20 package org.apache.lenya.cms.cocoon.acting; 21 22 import java.util.Arrays ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.apache.avalon.framework.parameters.Parameters; 28 import org.apache.cocoon.acting.AbstractAction; 29 import org.apache.cocoon.environment.Redirector; 30 import org.apache.cocoon.environment.SourceResolver; 31 import org.apache.lenya.cms.publication.Document; 32 import org.apache.lenya.cms.publication.DocumentDoesNotExistException; 33 import org.apache.lenya.cms.publication.DocumentException; 34 import org.apache.lenya.cms.publication.PageEnvelope; 35 import org.apache.lenya.cms.publication.PageEnvelopeException; 36 import org.apache.lenya.cms.publication.PageEnvelopeFactory; 37 38 43 public class LanguageExistsAction extends AbstractAction { 44 45 64 public Map act( 65 Redirector redirector, 66 SourceResolver resolver, 67 Map objectModel, 68 String source, 69 Parameters parameters) 70 throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException { 71 72 PageEnvelope pageEnvelope = 73 PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel); 74 75 Document doc = pageEnvelope.getDocument(); 76 String language = doc.getLanguage(); 77 78 if (!doc.existsInAnyLanguage()) { 79 throw new DocumentDoesNotExistException("Document " + doc.getId() + " does not exist. Check sitetree, it might need to be reloaded."); 80 } 81 List availableLanguages = Arrays.asList(doc.getLanguages()); 82 83 if (availableLanguages.contains(language)) { 84 return Collections.unmodifiableMap(Collections.EMPTY_MAP); 85 } 86 return null; 87 } 88 } 89 | Popular Tags |