19 package org.turro.publishing;
22 import java.io.IOException;
23 import java.io.Serializable;
24 import java.util.HashMap;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.impl.util.FileUtil;
30 import org.turro.file.FileWatch;
31 import org.turro.reflection.JSONSerializer;
39 private String entityRoot;
40 private HashMap<String, PublishingContext> contexts;
47 return contexts.containsKey(context);
51 return contexts.get(context);
56 return (pc !=
null) ?
checkEntity(pc, entity) :
null;
66 return doLoad(javaClass, root);
71 if(publishing !=
null) {
80 private static final Map<String, Publishing> _pub =
new HashMap<>();
81 private static final Map<String, Long> _lastLoads =
new HashMap<>();
83 protected static <T extends Publishing>
Publishing doLoad(Class<T> javaClass, String publishingFile) {
84 if(_pub.get(publishingFile) ==
null || FileWatch.isNewer(convert(publishingFile), _lastLoads.get(publishingFile))
85 || !FileWatch.exists(convert(publishingFile))) {
88 JSONSerializer ser =
new JSONSerializer(
true);
90 }
catch (IOException ex) {
94 _pub.put(publishingFile, pub);
95 _lastLoads.put(publishingFile, FileWatch.getTime(convert(publishingFile)));
98 return _pub.get(publishingFile);
101 private static String convert(String publishingFile) {
102 if(!publishingFile.contains(
"/")) {
103 publishingFile =
"/WEB-INF/elephant/conf/" + publishingFile +
"-publishing.json";
105 return ElephantContext.getRealPath(publishingFile);
static String logMsg(String msg)
static String getContent(File file)
boolean checkEntity(PublishingContext pc, E entity)
static< T extends Publishing > Publishing doLoad(Class< T > javaClass, String publishingFile)
static< T extends Publishing > PublishingContext getPublishingContext(Class< T > javaClass, String root, String context)
static< T extends Publishing > Publishing getPublishing(Class< T > javaClass, String root)
PublishingContext getContext(String context)
boolean checkEntity(String context, E entity)
boolean hasContext(String context)