18 package org.turro.elephant.impl.context;
21 import java.io.IOException;
22 import java.io.OutputStreamWriter;
23 import java.nio.file.Path;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import javax.servlet.ServletException;
28 import org.turro.string.Strings;
29 import org.jdom.Attribute;
30 import org.jdom.Element;
31 import org.jdom.output.Format;
32 import org.jdom.output.XMLOutputter;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.context.IConstructor;
35 import org.turro.elephant.context.IContext;
36 import org.turro.elephant.context.IElement;
37 import org.turro.elephant.impl.context.vc.FileVersionWrapper;
38 import org.turro.elephant.impl.navigation.Navigator;
39 import org.turro.elephant.impl.navigation.WebMap;
40 import org.turro.elephant.impl.repository.Repository;
41 import org.turro.elephant.impl.util.FileUtil;
42 import org.turro.elephant.impl.util.Files;
43 import org.turro.elephant.layout.IManageable;
44 import org.turro.elephant.search.FoundList;
45 import org.turro.elephant.search.ISearchable;
46 import org.turro.elephant.search.SearchFormatter;
47 import org.turro.elephant.security.IDefendable;
48 import org.turro.elephant.user.menu.UserMenus;
49 import org.turro.elephant.web.ElContext;
50 import org.turro.elephant.web.ElContextMap;
51 import org.turro.elephant.web.context.WebContext;
52 import org.turro.i18n.I_;
53 import org.turro.marker.ElephantMarker;
54 import org.turro.util.CompareUtil;
61 public static final String
92 hash = 79 * hash + (this.path !=
null ? this.path.hashCode() : 0);
98 return file.getName();
114 if(elContext !=
null) {
124 if(elContext !=
null) {
167 public void setName(String lang, String newName) {
197 return Strings.isBlank(title) ?
getName() : title;
225 if(elContext !=
null) {
304 if(elContext !=
null) {
355 return (tmp.length() == 0 ?
"/" : tmp);
361 if(Strings.isBlank(redirection)) {
363 }
else if(redirection.startsWith(
"/")) {
365 }
else if(redirection.contains(
"://")) {
379 return path ==
null ? 0 :
path.split(
"\\/").length - 1;
423 em.
put(
"printPath", printPath);
424 em.
put(
"printVersion",
"<div id='print-version'><a class='newwindow' target='_blank' rel='nofollow' href='" + printPath +
"'>" +
425 I_.
get(
"Printer version") +
430 em.
put(
"nav", navigator);
432 em.
put(
"body", element);
436 em.
process(
"layout",
template);
443 if(elContext !=
null && elContext.
getParent() !=
null) {
455 if(ancestors ==
null) {
456 ArrayList v =
new ArrayList();
458 if(elContext !=
null && !elContext.
getAncestors().isEmpty()) {
460 v.add(child.getContext());
476 ArrayList v =
new ArrayList();
478 if(elContext !=
null && !elContext.
getChildren().isEmpty()) {
480 v.add(child.getContext());
501 ArrayList v =
new ArrayList();
502 if(elContext !=
null) {
504 v.add(child.getContext());
537 TreeSet
set =
new TreeSet();
539 if(
file.isDirectory()) {
541 for(
int i = 0; i <
children.length; i++)
549 return (String[])
set.toArray(
new String[0]);
555 TreeSet
set =
new TreeSet();
558 if(
file.isDirectory()) {
559 for(
int b = 0; b < baseName.length; b++) {
560 for(
int p = 0; p < prefixes.length; p++) {
562 file.getAbsolutePath() +
"/" +
565 if(resource.exists()) {
566 set.add(resource.getName());
572 return (String[])
set.toArray(
new String[0]);
607 List attrs =
conf.getAttributes();
608 Iterator it = attrs.iterator();
610 while(it.hasNext()) {
611 a = (Attribute) it.next();
618 while(it.hasNext()) {
645 ArrayList v =
new ArrayList();
646 String defaultLocale =
null;
648 Locale[] locale =
new Locale[] {
I_.
api().used()};
649 if(!defLocale.isEmpty()) {
650 defaultLocale = defLocale.iterator().next();
653 if(preferredLocale !=
null) {
654 v.add(preferredLocale);
655 if(preferredLocale.equals(defaultLocale))
656 if(!v.contains(
"")) v.add(
"");
659 String language, country, variant, curr;
660 int languageLength, countryLength, variantLength;
661 for(
int l = 0; l < locale.length; l++) {
662 language = locale[l].getLanguage();
663 languageLength = language.length();
664 country = locale[l].getCountry();
665 countryLength = country.length();
666 variant = locale[l].getVariant();
667 variantLength = variant.length();
668 if(languageLength > 0 && countryLength > 0 && variantLength > 0) {
669 curr =
"_" + language +
"_" + country +
"_" + variant;
670 if(!v.contains(curr)) v.add(curr);
671 if(curr.equals(defaultLocale))
672 if(!v.contains(
"")) v.add(
"");
674 if(languageLength > 0 && countryLength > 0) {
675 curr =
"_" + language +
"_" + country;
676 if(!v.contains(curr)) v.add(curr);
677 if(curr.equals(defaultLocale))
678 if(!v.contains(
"")) v.add(
"");
680 if(languageLength > 0) {
681 curr =
"_" + language;
682 if(!v.contains(curr)) v.add(curr);
683 if(curr.equals(defaultLocale))
684 if(!v.contains(
"")) v.add(
"");
693 for(String dl : defLocale) {
694 if(!v.contains(dl)) v.add(dl);
695 if(dl.equals(defaultLocale))
696 if(!v.contains(
"")) v.add(
"");
698 return (String[]) v.toArray(
new String[0]);
705 private String getOrder() {
724 private void saveConfiguration() {
725 try (OutputStreamWriter fw = FileUtil.getFileWriter(
727 Format fm = Format.getPrettyFormat();
729 XMLOutputter xo =
new XMLOutputter(fm);
730 xo.output(
conf.getDocument(), fw);
731 }
catch (IOException ex) {
752 result = CompareUtil.compare(getOrder(), dc.getOrder());
757 result = CompareUtil.compare(
getId(), dc.
getId());
779 if(contextRole ==
null)
return true;
820 path =
path.replaceAll(
"[^\\/a-zA-Z0-9\\-\\_\\.]",
"_");
831 int p =
path.indexOf(
"?");
static String getRealPath(String path)
static String getRootResourcePath()
static String getContextLoad()
static String getRootWebPath()
static String logMsg(String msg)
static String getEncoding()
void setValue(String value)
void setBooleanValue(boolean value)
static final int STRING_ATTR
String getAttributeValue(String name, String defaultValue)
boolean getAttributeBooleanValue(String name, boolean defaultValue)
void addAttribute(AttributeItem attr)
AttributeItem getAttribute(String name)
IConstructor getConstructor()
IElement getDefaultElement()
String[] getLocaleSufixes(String preferredLocale)
static String extractPath(String path)
String getName(String lang)
Set< String > getDefaultLocales()
static final String CONTEXT_FILE
void setIcon(String icon)
IElement getDefaultElement(String type)
FoundList search(String value, boolean ignoreCase)
String[] getLocaleResources(String preferredLocale)
void populateFromParent()
AttributeSupport getAttributes()
IContext[] getAncestors()
void setConstructor(IConstructor constructor, String path)
AttributeSupport attrSupport
String getExactName(String lang)
Repository getRepository()
boolean equals(Object obj)
static String locateRealContext(IConstructor constructor, String path)
boolean inPath(IContext context)
void setName(String lang, String newName)
void setDynamicLoad(boolean dynamicLoad)
static String baseName(String file)
static final String VALID_EXT_REGEXP
static boolean exists(String path)
static String toExisting(String path)
void addItem(String id, String link, String image, String title, String value, double similarity, String query)
static ElContext getContext(IConstructor constructor)
WebContext getWebContext()
TreeSet< ElContext > getChildren()
TreeSet< ElContext > getSiblings()
Set< String > getDefaultLocales()
TreeSet< ElContext > getAncestors()
boolean isControlVersion()
static boolean removeFrom(Path path)
Map< String, String > getNames()
IElement getElementInstance()
boolean isTraversalNavigation()
boolean isShowInNavigators()
static String get(String msg)
static I18nApiWrapper api()
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
boolean isWebAdministering()
HttpServletRequest getRequest()
boolean isInRole(String role)
void setConfiguration(IConstructor constructor, ElContext context)
AttributeSupport getAttributes()