com.helger.photon.bootstrap3.pages.appinfo.BasePageAppInfoWebSiteResourceBundles Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ph-oton-bootstrap3-pages Show documentation
Show all versions of ph-oton-bootstrap3-pages Show documentation
Default web pages for the ph-oton stack
/**
* Copyright (C) 2014-2017 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.photon.bootstrap3.pages.appinfo;
import java.io.File;
import java.util.Locale;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.annotation.Translatable;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.compare.ESortOrder;
import com.helger.commons.datetime.PDTToString;
import com.helger.commons.debug.GlobalDebug;
import com.helger.commons.io.file.FileSystemIterator;
import com.helger.commons.text.IMultilingualText;
import com.helger.commons.text.display.IHasDisplayText;
import com.helger.commons.text.resolve.DefaultTextResolver;
import com.helger.commons.text.util.TextHelper;
import com.helger.html.hc.ext.HCExtHelper;
import com.helger.html.hc.html.tabular.HCCol;
import com.helger.html.hc.html.tabular.HCRow;
import com.helger.html.hc.html.tabular.HCTable;
import com.helger.html.hc.html.textlevel.HCBR;
import com.helger.html.hc.impl.HCNodeList;
import com.helger.photon.basic.app.io.WebFileIO;
import com.helger.photon.bootstrap3.alert.BootstrapSuccessBox;
import com.helger.photon.bootstrap3.button.BootstrapButton;
import com.helger.photon.bootstrap3.button.BootstrapButtonToolbar;
import com.helger.photon.bootstrap3.pages.AbstractBootstrapWebPage;
import com.helger.photon.bootstrap3.table.BootstrapTable;
import com.helger.photon.bootstrap3.uictrls.datatables.BootstrapDataTables;
import com.helger.photon.core.EPhotonCoreText;
import com.helger.photon.core.resource.ResourceBundleServlet;
import com.helger.photon.core.resource.WebSiteResourceBundleManager;
import com.helger.photon.core.resource.WebSiteResourceBundleSerialized;
import com.helger.photon.core.resource.WebSiteResourceCache;
import com.helger.photon.uicore.css.CPageParam;
import com.helger.photon.uicore.icon.EDefaultIcon;
import com.helger.photon.uicore.page.EWebPageText;
import com.helger.photon.uicore.page.IWebPageExecutionContext;
import com.helger.photon.uictrls.datatables.DataTables;
import com.helger.photon.uictrls.datatables.column.DTCol;
import com.helger.photon.uictrls.datatables.column.EDTColType;
/**
* Show web site resource bundles.
*
* @author Philip Helger
* @param
* Web Page Execution Context type
*/
public class BasePageAppInfoWebSiteResourceBundles extends
AbstractBootstrapWebPage
{
@Translatable
protected static enum EText implements IHasDisplayText
{
MSG_CACHE_NOW_ENABLED ("Der Cache ist jetzt aktiviert", "Cache is now enabled"),
MSG_CACHE_NOW_DISABLED ("Der Cache ist jetzt deaktiviert", "Cache is now disabled"),
MSG_RESBUNDLE_NOW_ENABLED ("Das ResourceBundleServlet ist jetzt aktiviert", "ResourceBundleServlet is now enabled"),
MSG_RESBUNDLE_NOW_DISABLED ("Das ResourceBundleServlet ist jetzt deaktiviert",
"ResourceBundleServlet is now disabled"),
MSG_RESBUNDLE_SERVLET ("ResourceBundleServlet registriert", "ResourceBundleServlet registered"),
MSG_CACHE_ENABLED ("Cache aktiv", "Cache enabled"),
MSG_RESBUNDLE_ENABLED ("ResourceBundleServlet aktiviert", "ResourceBundleServlet enabled"),
MSG_ID ("ID", "ID"),
MSG_DATE ("Datum", "Date"),
MSG_RESOURCES ("Resourcen", "Resources"),
MSG_COND_COMMENT ("Cond Comment", "Cond comment"),
MSG_CSS_MEDIA ("CSS Medien", "CSS media");
@Nonnull
private final IMultilingualText m_aTP;
private EText (@Nonnull final String sDE, @Nonnull final String sEN)
{
m_aTP = TextHelper.create_DE_EN (sDE, sEN);
}
@Nullable
public String getDisplayText (@Nonnull final Locale aContentLocale)
{
return DefaultTextResolver.getTextStatic (this, m_aTP, aContentLocale);
}
}
private static final String ACTION_CHANGE_CACHE_STATE = "changecachestate";
private static final String ACTION_CHANGE_RESBUNDLE_STATE = "changeresbundlestate";
private final WebSiteResourceBundleManager m_aResBundleMgr;
public BasePageAppInfoWebSiteResourceBundles (@Nonnull @Nonempty final String sID,
@Nonnull final WebSiteResourceBundleManager aResBundleMgr)
{
super (sID, EWebPageText.PAGE_NAME_APPINFO_WEBRESBUNDLE.getAsMLT ());
m_aResBundleMgr = ValueEnforcer.notNull (aResBundleMgr, "ResBundleMgr");
}
public BasePageAppInfoWebSiteResourceBundles (@Nonnull @Nonempty final String sID,
@Nonnull final String sName,
@Nonnull final WebSiteResourceBundleManager aResBundleMgr)
{
super (sID, sName);
m_aResBundleMgr = ValueEnforcer.notNull (aResBundleMgr, "ResBundleMgr");
}
public BasePageAppInfoWebSiteResourceBundles (@Nonnull @Nonempty final String sID,
@Nonnull final String sName,
@Nullable final String sDescription,
@Nonnull final WebSiteResourceBundleManager aResBundleMgr)
{
super (sID, sName, sDescription);
m_aResBundleMgr = ValueEnforcer.notNull (aResBundleMgr, "ResBundleMgr");
}
public BasePageAppInfoWebSiteResourceBundles (@Nonnull @Nonempty final String sID,
@Nonnull final IMultilingualText aName,
@Nullable final IMultilingualText aDescription,
@Nonnull final WebSiteResourceBundleManager aResBundleMgr)
{
super (sID, aName, aDescription);
m_aResBundleMgr = ValueEnforcer.notNull (aResBundleMgr, "ResBundleMgr");
}
@Nonnull
protected final WebSiteResourceBundleManager getResBundleMgr ()
{
return m_aResBundleMgr;
}
@Override
protected void fillContent (@Nonnull final WPECTYPE aWPEC)
{
final HCNodeList aNodeList = aWPEC.getNodeList ();
final Locale aDisplayLocale = aWPEC.getDisplayLocale ();
if (aWPEC.hasAction (ACTION_CHANGE_CACHE_STATE))
{
WebSiteResourceCache.setCacheEnabled (!WebSiteResourceCache.isCacheEnabled ());
final boolean bCacheEnabled = WebSiteResourceCache.isCacheEnabled ();
aWPEC.postRedirectGetInternal (new BootstrapSuccessBox ().addChild (bCacheEnabled ? EText.MSG_CACHE_NOW_ENABLED.getDisplayText (aDisplayLocale)
: EText.MSG_CACHE_NOW_DISABLED.getDisplayText (aDisplayLocale)));
return;
}
if (aWPEC.hasAction (ACTION_CHANGE_RESBUNDLE_STATE))
{
ResourceBundleServlet.setEnabled (!ResourceBundleServlet.isEnabled ());
final boolean bResBundleActive = ResourceBundleServlet.isEnabled ();
aWPEC.postRedirectGetInternal (new BootstrapSuccessBox ().addChild (bResBundleActive ? EText.MSG_RESBUNDLE_NOW_ENABLED.getDisplayText (aDisplayLocale)
: EText.MSG_RESBUNDLE_NOW_DISABLED.getDisplayText (aDisplayLocale)));
return;
}
// Refresh button
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar (aWPEC);
aToolbar.addButton (EPhotonCoreText.BUTTON_REFRESH.getDisplayText (aDisplayLocale),
aWPEC.getSelfHref (),
EDefaultIcon.REFRESH);
aNodeList.addChild (aToolbar);
{
final boolean bCacheEnabled = WebSiteResourceCache.isCacheEnabled ();
final boolean bServletRegistered = ResourceBundleServlet.isServletRegisteredInServletContext ();
final boolean bResBundleActive = ResourceBundleServlet.isEnabled ();
final BootstrapTable aTable = new BootstrapTable (HCCol.star (),
HCCol.star (),
bServletRegistered ? HCCol.star () : null).setStriped (true);
final HCRow aRegisteredRow = aTable.addBodyRow ()
.addCell (EText.MSG_RESBUNDLE_SERVLET.getDisplayText (aDisplayLocale))
.addCell (EPhotonCoreText.getYesOrNo (bServletRegistered, aDisplayLocale));
final HCRow aCacheRow = aTable.addBodyRow ()
.addCell (EText.MSG_CACHE_ENABLED.getDisplayText (aDisplayLocale))
.addCell (EPhotonCoreText.getYesOrNo (bCacheEnabled, aDisplayLocale));
final HCRow aResBundleActiveRow = aTable.addBodyRow ()
.addCell (EText.MSG_RESBUNDLE_ENABLED.getDisplayText (aDisplayLocale))
.addCell (EPhotonCoreText.getYesOrNo (bResBundleActive, aDisplayLocale));
if (bServletRegistered)
{
aRegisteredRow.addCell ();
aCacheRow.addCell (new BootstrapButton ().addChild (bCacheEnabled ? EPhotonCoreText.BUTTON_DISABLE.getDisplayText (aDisplayLocale)
: EPhotonCoreText.BUTTON_ENABLE.getDisplayText (aDisplayLocale))
.setOnClick (aWPEC.getSelfHref ().add (CPageParam.PARAM_ACTION,
ACTION_CHANGE_CACHE_STATE)));
aResBundleActiveRow.addCell (new BootstrapButton ().addChild (bResBundleActive ? EPhotonCoreText.BUTTON_DISABLE.getDisplayText (aDisplayLocale)
: EPhotonCoreText.BUTTON_ENABLE.getDisplayText (aDisplayLocale))
.setOnClick (aWPEC.getSelfHref ()
.add (CPageParam.PARAM_ACTION,
ACTION_CHANGE_RESBUNDLE_STATE)));
}
aNodeList.addChild (aTable);
aNodeList.addChild (new HCBR ());
}
final HCTable aTable = new HCTable (new DTCol (EText.MSG_ID.getDisplayText (aDisplayLocale)).setInitialSorting (ESortOrder.ASCENDING),
new DTCol (EText.MSG_DATE.getDisplayText (aDisplayLocale)).setDisplayType (EDTColType.DATETIME,
aDisplayLocale),
new DTCol (EText.MSG_RESOURCES.getDisplayText (aDisplayLocale)),
new DTCol (EText.MSG_COND_COMMENT.getDisplayText (aDisplayLocale)).setDataSort (3,
1),
new DTCol (EText.MSG_CSS_MEDIA.getDisplayText (aDisplayLocale)).setDataSort (4,
1)).setID (getID ());
final ICommonsList aBundles = m_aResBundleMgr.getAllResourceBundlesSerialized ();
for (final WebSiteResourceBundleSerialized aBundle : aBundles)
{
final HCRow aRow = aTable.addBodyRow ();
aRow.addCell (aBundle.getBundleID ());
aRow.addCell (PDTToString.getAsString (aBundle.getCreationDT (), aDisplayLocale));
aRow.addCell (HCExtHelper.list2divList (aBundle.getBundle ().getAllResourcePaths ()));
aRow.addCell (aBundle.getBundle ().getConditionalComment ());
aRow.addCell (aBundle.getBundle ().hasMediaList () ? aBundle.getBundle ().getMediaList ().getMediaString ()
: null);
}
aNodeList.addChild (aTable);
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables (aWPEC, aTable);
aNodeList.addChild (aDataTables);
if (GlobalDebug.isDebugMode ())
{
aNodeList.addChild (getUIHandler ().createDataGroupHeader ("Resource bundle directory listing"));
final File aDir = WebFileIO.getDataIO ().getFile (WebSiteResourceBundleSerialized.RESOURCE_BUNDLE_PATH);
final HCTable aTable2 = new HCTable (new DTCol ("Filename"), new DTCol ("Active?")).setID (getID () + "2");
for (final File aFile : new FileSystemIterator (aDir))
{
final HCRow aRow = aTable2.addBodyRow ();
aRow.addCell (aFile.getName ());
aRow.addCell (m_aResBundleMgr.containsResourceBundleOfID (aFile.getName ()) ? "yes" : "no");
}
aNodeList.addChild (aTable2);
final DataTables aDataTables2 = BootstrapDataTables.createDefaultDataTables (aWPEC, aTable2);
aNodeList.addChild (aDataTables2);
}
}
}