- ItemCategoryStep (not finished yet)
- Some use functions for localization


git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4995 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: de06b4ea4f
pull/2/head
jensp 2017-09-11 16:38:29 +00:00
parent b836066592
commit 2f83b548c1
20 changed files with 802 additions and 410 deletions

View File

@ -100,6 +100,7 @@
<artifactId>ccm-core</artifactId>
<type>jar</type>
<includes>
<include>assets/</include>
<include>VAADIN/</include>
</includes>
</overlay>

View File

@ -35,13 +35,18 @@ import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ItemSelectionModel;
import org.librecms.CmsConstants;
import org.librecms.ui.authoring.ContentItemAuthoringStep;
import java.math.BigDecimal;
/**
*
*
*/
@ContentItemAuthoringStep(
labelBundle = CmsConstants.CMS_BUNDLE,
labelKey = "item_category_step.label",
descriptionBundle = CmsConstants.CMS_BUNDLE,
descriptionKey = "item_category_step.description"
)
public class ItemCategoryStep extends SimpleContainer implements Resettable{
@ -58,7 +63,8 @@ public class ItemCategoryStep extends SimpleContainer implements Resettable{
public ItemCategoryStep(final ItemSelectionModel itemSelectionModel,
final AuthoringKitWizard authoringKitWizard) {
final AuthoringKitWizard authoringKitWizard,
final StringParameter selectedLanguage) {
super("cms:categoryStep", CMS.CMS_XML_NS);

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.authoring;
import org.libreccm.categorization.Category;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class ItemCategoryStepController {
@Inject
private ContentSectionRepository sectionRepo;
@Transactional(Transactional.TxType.REQUIRED)
protected List<Category> getRootCategories(final ContentSection section) {
Objects.requireNonNull(section);
final ContentSection contentSection = sectionRepo
.findById(section.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No ContentSection with ID %d in the database.",
section.getObjectId())));
return contentSection
.getDomains()
.stream()
.map(domainOwnership -> domainOwnership.getDomain())
.map(domain -> domain.getRoot())
.collect(Collectors.toList());
}
}

View File

@ -28,11 +28,9 @@ import com.arsdigita.cms.CMS;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.List;
import java.util.stream.Collectors;
public class ItemCategorySummary extends ACSObjectCategorySummary {
@ -83,13 +81,11 @@ public class ItemCategorySummary extends ACSObjectCategorySummary {
@Override
protected List<Category> getRootCategories(final PageState state) {
final ContentSection section = CMS.getContext().getContentSection();
return section
.getDomains()
.stream()
.map(domainOwnership -> domainOwnership.getDomain())
.map(domain -> domain.getRoot())
.collect(Collectors.toList());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ItemCategoryStepController controller = cdiUtil
.findBean(ItemCategoryStepController.class);
return controller.getRootCategories(CMS.getContext().getContentSection());
}
}

View File

@ -25,12 +25,14 @@ import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.CmsConstants;
import org.librecms.assets.AssetTypeInfo;
import org.librecms.assets.AssetTypesManager;
import java.util.Iterator;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
@ -77,14 +79,18 @@ class AttachmentsTableModel implements TableModel {
case AttachmentsTable.COL_TITLE:
return currentRow.getTitle();
case AttachmentsTable.COL_TYPE: {
final AssetTypesManager typesManager = CdiUtil
.createCdiUtil()
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final AssetTypesManager typesManager = cdiUtil
.findBean(AssetTypesManager.class);
final AssetTypeInfo typeInfo = typesManager
.getAssetTypeInfo(currentRow.getType());
try {
final ResourceBundle bundle = ResourceBundle
.getBundle(typeInfo.getLabelBundle());
return bundle.getString(typeInfo.getLabelKey());
} catch (MissingResourceException ex) {
return typeInfo.getAssetClass().getName();
}
}
case AttachmentsTable.COL_MOVE:
if (moveAttachmentModel.getSelectedAttachment(state) == null) {

View File

@ -88,6 +88,9 @@ public class InternalLinkAddForm
super.add(itemSearchLabel);
super.add(itemSearchWidget);
super.add(saveCancelSection);
super.addProcessListener(this);
super.addSubmissionListener(this);
}
@Override

View File

@ -302,7 +302,13 @@ class RelatedInfoStepController {
final Locale selectedLocale = new Locale(selectedLanguage);
link.getTitle().addValue(selectedLocale, title);
itemAttachmentManager.attachAsset(link, attachmentList);
final AttachmentList list = attachmentListManager
.getAttachmentList(attachmentList.getListId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No AttachmentList with Id %d in the database.",
attachmentList.getListId())));
itemAttachmentManager.attachAsset(link, list);
}
@Transactional(Transactional.TxType.REQUIRED)

View File

@ -0,0 +1,161 @@
package com.arsdigita.london.terms.ui;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.Logger;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleComponent;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
import org.libreccm.categorization.Category;
import com.arsdigita.xml.Element;
import org.apache.logging.log4j.LogManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.GlobalizationHelper;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
/**
* Generate part of the category tree. Used by Assign Category authoring step.
*
* Class is directly used by JSP page(s), eg. load-cat.jsp (currently in
* ~/packages/content-section/www/admin, source in ccm-ldn-aplaws or
* corresponding integration module).
*
* @author Alan Pevec
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CategorySubtree extends SimpleComponent {
private static final Logger LOGGER = LogManager
.getLogger(CategorySubtree.class);
private final StringParameter selectedCatsParam = new StringParameter(
"selectedCats");
private final StringParameter nodeIdParam = new StringParameter("nodeID");
@Override
public void register(final Page page) {
super.register(page);
page.addGlobalStateParam(nodeIdParam);
page.addGlobalStateParam(selectedCatsParam);
}
@Override
public void generateXML(final PageState state, final Element parent) {
final String node = (String) state.getValue(nodeIdParam);
final Set<Long> ids = new HashSet<>();
if (((String) state.getValue(selectedCatsParam)) != null) {
StringTokenizer values = new StringTokenizer((String) state
.getValue(selectedCatsParam), ",");
while (values.hasMoreTokens()) {
ids.add(Long.parseLong(values.nextToken().trim()));
}
}
LOGGER.debug("selected node = {}", node);
final String[] pathElements = StringUtils.split(node, "-");
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository categoryRepo = cdiUtil
.findBean(CategoryRepository.class);
final Category root = categoryRepo
.findById(Long.parseLong(pathElements[pathElements.length - 1]))
.orElseThrow(() -> new UnexpectedErrorException(String
.format("No Category with ID %s in the database.",
pathElements[pathElements.length - 1])));
LOGGER.debug("generating subtree for cat {}...", root.getObjectId());
// TermWidget.generateSubtree(parent, root, ids);
generateSubtreeXml(parent, root, ids);
}
private void generateSubtreeXml(final Element parentElem,
final Category root,
final Set<Long> ids) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategorySubtreeController controller = cdiUtil
.findBean(CategorySubtreeController.class);
final List<Category> subCategories = controller.getSubCategories(root);
final Element rootCategoryElem = generateCategoryXml(parentElem,
root,
ids);
controller
.getSubCategories(root)
.stream()
.sorted((category1, category2) -> {
return category1.getName().compareTo(category2.getName());
})
.forEach(subCategory -> generateCategoryXml(rootCategoryElem,
root,
ids));
}
private Element generateCategoryXml(final Element parentElem,
final Category category,
final Set<Long> ids) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final Element element = parentElem.newChildElement("cms:category",
CMS.CMS_XML_NS);
element.addAttribute("id", Long.toString(category.getObjectId()));
element.addAttribute("name", category.getName());
final String desc = globalizationHelper
.getValueFromLocalizedString(category.getDescription());
element.addAttribute("description", desc);
if (ids.contains(category.getObjectId())) {
element.addAttribute("isSelected", "1");
} else {
element.addAttribute("isSelected", "0");
}
if (category.isAbstractCategory()) {
element.addAttribute("isAbstract", "1");
} else {
element.addAttribute("isAbstract", "0");
}
if (category.isEnabled()) {
element.addAttribute("isEnabled", "1");
} else {
element.addAttribute("isEnabled", "0");
}
final StringBuilder path = new StringBuilder(parentElem
.getAttribute("fullname"));
if (path.length() > 0) {
path.append(" > ");
}
path.append(category.getName());
element.addAttribute("fullname", path.toString());
final StringBuilder nodeId = new StringBuilder(parentElem
.getAttribute("node-id"));
if (nodeId.length() > 0) {
nodeId.append("-");
}
nodeId.append(category.getObjectId());
element.addAttribute("node-id", nodeId.toString());
return element;
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.london.terms.ui;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategorySubtreeController {
@Inject
private CategoryRepository categoryRepo;
protected List<Category> getSubCategories(final Category ofCategory) {
final Category category = categoryRepo
.findById(ofCategory.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Category with ID %d in the database.",
ofCategory.getObjectId())));
return category.getSubCategories();
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.categorization.ui;
import org.libreccm.categorization.Category;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmObjectRepository;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class ACSObjectCategoryController {
@Inject
private CcmObjectRepository ccmObjectRepo;
@Transactional(Transactional.TxType.REQUIRED)
protected List<Category> getCategoriesForObject(final CcmObject object) {
Objects.requireNonNull(object);
final CcmObject ccmObject = ccmObjectRepo
.findById(object.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No CcmObject with ID %d in the database",
object.getObjectId())));
return ccmObject
.getCategories()
.stream()
.map(categorization -> categorization.getCategory())
.collect(Collectors.toList());
}
}

View File

@ -51,7 +51,6 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* abstract class for displaying the categories assigned to an object under one
* or more root nodes. Subclasses should retrieve the object to be assigned and
@ -188,14 +187,13 @@ public abstract class ACSObjectCategorySummary extends SimpleComponent {
getXMLPrefix()),
getXMLNameSpace());
final List<Category> categories = getObject(state)
.getCategories()
.stream()
.map(categorization -> categorization.getCategory())
.collect(Collectors.toList());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ACSObjectCategoryController controller = cdiUtil
.findBean(ACSObjectCategoryController.class);
final List<Category> categories = controller
.getCategoriesForObject(getObject(state));
final CategoryManager categoryManager = CdiUtil
.createCdiUtil()
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
for (final Category category : categories) {

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.categories;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoriesController {
@Inject
private CategoryRepository categoryRepo;
@Inject
private CategoryManager categoryManager;
protected List<Category> getSubCategories(final Category ofCategory) {
final Category category = categoryRepo
.findById(ofCategory.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Category with ID %d in the database.",
ofCategory.getObjectId())));
return category.getSubCategories();
}
protected boolean hasChildren(final Category category) {
return categoryManager.hasSubCategories(category);
}
}

View File

@ -54,24 +54,24 @@ public class CategoriesTreeModel implements TreeModel {
@Override
public boolean hasChildren(final TreeNode node,
final PageState state) {
final CategoryRepository categoryRepo = CdiUtil.createCdiUtil()
.findBean(CategoryRepository.class);
final Category category = categoryRepo.findById(
((CategoryTreeNode) node).getCategory().getObjectId()).get();
return (category.getSubCategories() != null
&& !category.getSubCategories().isEmpty());
final CategoriesController controller = CdiUtil
.createCdiUtil()
.findBean(CategoriesController.class);
return controller.hasChildren(((CategoryTreeNode) node).getCategory());
}
@Override
public Iterator getChildren(final TreeNode node,
final PageState state) {
final CategoryRepository categoryRepo = CdiUtil.createCdiUtil()
.findBean(CategoryRepository.class);
final Category category = categoryRepo.findById(
((CategoryTreeNode) node).getCategory().getObjectId()).get();
return new SubCategoryNodesIterator(category.getSubCategories());
final CategoriesController controller = CdiUtil
.createCdiUtil()
.findBean(CategoriesController.class);
final List<Category> subCategories = controller
.getSubCategories(((CategoryTreeNode) node).getCategory());
return new SubCategoryNodesIterator(subCategories);
}
private class CategoryTreeNode implements TreeNode {

View File

@ -18,15 +18,22 @@
*/
package org.libreccm.l10n;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.configuration.ConfigurationManager;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Provides the locale which has been selected based on the available languages
@ -63,6 +70,9 @@ import java.util.Locale;
@RequestScoped
public class GlobalizationHelper {
private static final Logger LOGGER = LogManager
.getLogger(GlobalizationHelper.class);
private static final String LANG_PARAM = "lang";
@Inject
@ -80,6 +90,7 @@ public class GlobalizationHelper {
* values the first value available locale (ordered alphabetically) is used.
*
* @param localizedString
*
* @return
*/
public String getValueFromLocalizedString(
@ -168,6 +179,80 @@ public class GlobalizationHelper {
return selected;
}
/**
* Retrieve the {@link ResourceBundle} identified by {@code name} for the
* negotiated locale
*
* @param name The fully qualified name of the {@link ResourceBundle} to
* retrieve.
*
* @return The {@link ResourceBundle} identified for the negotiated locale
* or, if the {@link ResourceBundle} is not available for negotiated
* locale, for the default locale. Or both do not exist {@code null}
* is returned.
*/
public ResourceBundle getResourceBundle(final String name) {
try {
return ResourceBundle.getBundle(name, getNegotiatedLocale());
} catch (MissingResourceException ex) {
LOGGER.warn(
"ResourceBundle \"{}\" does not exist for negotiated locale \"{}\".",
name,
getNegotiatedLocale().toString());
LOGGER.warn(ex);
}
final KernelConfig kernelConfig = confManager
.findConfiguration(KernelConfig.class);
final Locale defaultLocale = kernelConfig.getDefaultLocale();
try {
return ResourceBundle.getBundle(name, defaultLocale);
} catch (MissingResourceException ex) {
LOGGER.warn(
"ResourceBundle \"{}\" does not exist for negotiated locale \"{}\".",
name,
defaultLocale);
LOGGER.warn(ex);
}
return null;
}
/**
* Creates a instance of the {@link LocalizedTextsUtil} class for the
* {@link ResourceBundle} identified by {@code bundleName} and the
* {@link #getNegotiatedLocale()}.
*
* The {@link ResourceBundle} is retrieved using
* {@link #getResourceBundle(java.lang.String)}.
*
* @param bundleName The fully qualified name of the {@link ResourceBundle}
* to use.
*
* @return A {@link LocalizedTextsUtil} for the {@link ResourceBundle}
* identified by the provided {@code bundleName}.
*/
public LocalizedTextsUtil getLocalizedTextsUtil(final String bundleName) {
return new LocalizedTextsUtil(bundleName, getResourceBundle(bundleName));
}
/**
* Creates a {@link GlobalizedMessagesUtil} for the {@link ResourceBundle}
* identified by {@code bundleName}.
*
* @param bundleName The fully qualified name of the {@link ResourceBundle}
* to use.
*
* @return A {@link GlobalizedMessagesUtil} for the {@link ResourceBundle}
* identified by {@code bundleName}.
*/
public GlobalizedMessagesUtil getGlobalizedMessagesUtil(
final String bundleName) {
return new GlobalizedMessagesUtil(bundleName);
}
private Locale scanLocale(final String language) {
if (language == null || language.isEmpty()) {
return null;

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.l10n;
import com.arsdigita.globalization.GlobalizedMessage;
import java.util.ResourceBundle;
/**
* A helper class for obtaining {@link GlobalizedMessage}s. This class is
* intended to replace to numerous classes called {@code *GlobalizationUtil} in
* the legacy code.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class GlobalizedMessagesUtil {
/**
* The fully qualified name of the bundle to use.
*/
private final String bundleName;
/**
* Internal constructor only to be invoked by
* {@link GlobalizationHelper#getGlobalizedMessagesUtil(java.lang.String)}.
*
* @param bundleName
*/
GlobalizedMessagesUtil(final String bundleName) {
this.bundleName = bundleName;
}
/**
* Get a {@link GlobalizedMessage} for the provided {@code key} using the
* {@link ResourceBundle} identified by {@link #bundleName}.
*
* @param key The key.
*
* @return The {@link GlobalizedMessage}.
*/
public GlobalizedMessage getGlobalizedMessage(final String key) {
return new GlobalizedMessage(key, bundleName);
}
/**
* Get a {@link GlobalizedMessage} with placeholders for the provided
* {@code key} using the {@link ResourceBundle} identified by
* {@link #bundleName}.
*
* @param key The key.
*
* @return The {@link GlobalizedMessage}.
*/
public GlobalizedMessage getGlobalizedMessage(final String key,
final Object[] arguments) {
return new GlobalizedMessage(key, bundleName, arguments);
}
}

View File

@ -0,0 +1,125 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.l10n;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
/**
* This class provides an wrapper around the {@link ResourceBundle} class. Each
* instance represents a particular {@link ResourceBundle}. Instances of this
* class can be obtained using
* {@link GlobalizationHelper#getLocalizedTexts(java.lang.String)}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class LocalizedTextsUtil {
private static final Logger LOGGER = LogManager.getLogger(
LocalizedTextsUtil.class);
/**
* The name of the bundle to use.
*/
private final String bundleName;
/**
* The {@link ResourceBundle} to use.
*/
private final ResourceBundle bundle;
/**
* Internal constructor, only to be invoked by
* {@link GlobalizationHelper#getLocalizedTexts(java.lang.String)}.
*
* @param bundleName The fully qualified name of the bundle.
* @param bundle The {@link ResourceBundle} to use.
*/
LocalizedTextsUtil(final String bundleName, final ResourceBundle bundle) {
Objects.requireNonNull(bundleName);
this.bundleName = bundleName;
this.bundle = bundle;
}
/**
* Retrieves to string identified by {@code key} from {@link #bundle}. If
* {@link #bundle} is {@code null} or if {@link #bundle} has no value of the
* provided {@code key} the {@link #bundleName} and the key, separated by a
* "{@code /}" are returned.
*
* @param key The key of the string to retrieve from the {@link #bundle}.
*
* @return The string.
*/
public String getText(final String key) {
if (bundle == null) {
LOGGER.warn("No ResourceBundle \"{}\".");
} else {
try {
return bundle.getString(key);
} catch (MissingResourceException ex) {
LOGGER.warn(
"No resource for key \"{}\" in ResourceBundle \"{}\"",
key,
bundleName);
}
}
return String.format("%s/%s", bundleName, key);
}
/**
* Retrieves to string identified by {@code key} from {@link #bundle} and
* uses {@link MessageFormat} to replace the placeholders in the string with
* the provided {@code arguments}. If {@link #bundle} is {@code null} or if
* {@link #bundle} has no value of the provided {@code key} the
* {@link #bundleName} and the key, separated by a "{@code /}" are returned.
*
* @param key The key of the string to retrieve from the {@link #bundle}.
* @param arguments The parameters to use.
*
* @return The string.
*/
public String getText(final String key, final Object[] arguments) {
if (bundle == null) {
LOGGER.warn("No ResourceBundle \"{}\".");
} else {
try {
final String text = bundle.getString(key);
return MessageFormat.format(text, arguments);
} catch (MissingResourceException ex) {
LOGGER.warn(
"No resource for key \"{}\" in ResourceBundle \"{}\"",
key,
bundleName);
}
}
return String.format("%s/%s", bundleName, key);
}
}

File diff suppressed because one or more lines are too long

View File

@ -109,358 +109,7 @@
</tr>
</thead>
<tbody>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
<tr>
<td>
$title
</td>
<td>
$type
</td>
<td>
$place
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -115,6 +115,7 @@ function getItemsForSelectItemDialog(dialogId) {
}
request.open("GET", url);
request.withCredentials = true;
request.addEventListener('load', function (event) {
if (request.status >= 200 && request.status <= 300) {
var items = JSON.parse(request.responseText);

View File

@ -78,6 +78,51 @@
<translation lang="en">Welcome</translation>
</text>
<text id="item-search-widget/table/header/title">
<translation lang="de">Titel</translation>
<translation lang="en">Titel</translation>
</text>
<text id="item-search-widget/table/header/type">
<translation lang="de">Typ</translation>
<translation lang="en">Type</translation>
</text>
<text id="item-search-widget/table/header/place">
<translation lang="de">Ort</translation>
<translation lang="en">Place</translation>
</text>
<text id="item-search-widget/filter-list">
<translation lang="de">Liste filtern</translation>
<translation lang="en">Filter list</translation>
</text>
<text id="item-search-widget/filter-list/apply">
<translation lang="de">Anwenden</translation>
<translation lang="en">Apply</translation>
</text>
<text id="item-search-widget/no-item-selected">
<translation lang="de">Keine Content Item ausgewählt</translation>
<translation lang="en">No item selected</translation>
</text>
<text id="item-search-widget/select-item-button">
<translation lang="de">Item auswählen</translation>
<translation lang="en">Select item</translation>
</text>
<text id="item-search-widget/titlebar">
<translation lang="de">Item auswählen</translation>
<translation lang="en">Select item</translation>
</text>
<text id="item-search-widget/titlebar/close">
<translation lang="de">Schließen</translation>
<translation lang="en">Close</translation>
</text>
<text id="summary/itemSummary/header">
<translation lang="en">Item Summary</translation>
<translation lang="de">Zusammenfassung</translation>