www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,391 @@
|
|||
package it.acxent.icecat;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Icecat {
|
||||
boolean debug = false;
|
||||
|
||||
private static final String TABLE_HEADER_CATEGORY = "_category";
|
||||
|
||||
private static final String TABLE_ROW_VALUE = "_value";
|
||||
|
||||
private static final String TABLE_ROW_DESC = "_desc";
|
||||
|
||||
private static final String TABLE_ROWS = "<tr>\n<td>_desc</td>\n<td>_value</td></tr>";
|
||||
|
||||
private static final String TABLE_HEADER = "<tr>\n<th colspan='2' >_category</th>\n</tr>";
|
||||
|
||||
private static final String TABLE_START = "<table class='table table-bordered table-indent'><tbody>";
|
||||
|
||||
private static final String J_REASONS_TO_BUY = "ReasonsToBuy";
|
||||
|
||||
private static final String J_PRESENTATION_VALUE = "PresentationValue";
|
||||
|
||||
private static final String J_FEATURE = "Feature";
|
||||
|
||||
private static final String J_FEATURES = "Features";
|
||||
|
||||
private static final String J_VALUE = "Value";
|
||||
|
||||
private static final String J_NAME = "Name";
|
||||
|
||||
private static final String J_FEATURE_GROUP = "FeatureGroup";
|
||||
|
||||
private static final String J_FEATURES_GROUPS = "FeaturesGroups";
|
||||
|
||||
private static final String J_PIC = "Pic";
|
||||
|
||||
private static final String J_GALLERY = "Gallery";
|
||||
|
||||
private static final String J_LONG_SUMMARY_DESCRIPTION = "LongSummaryDescription";
|
||||
|
||||
private static final String J_SHORT_SUMMARY_DESCRIPTION = "ShortSummaryDescription";
|
||||
|
||||
private static final String J_SUMMARY_DESCRIPTION = "SummaryDescription";
|
||||
|
||||
private static final String J_WARRANTY_INFO = "WarrantyInfo";
|
||||
|
||||
private static final String J_DISCLAIMER = "Disclaimer";
|
||||
|
||||
private static final String J_LONG_DESC = "LongDesc";
|
||||
|
||||
private static final String J_DESCRIPTION = "Description";
|
||||
|
||||
private static final String J_GENERATED_INT_TITLE = "GeneratedIntTitle";
|
||||
|
||||
private static final String J_TITLE_INFO = "TitleInfo";
|
||||
|
||||
private static final String J_TITLE = "Title";
|
||||
|
||||
private static final String J_DATA = "data";
|
||||
|
||||
private static final String J_GENERAL_INFO = "GeneralInfo";
|
||||
|
||||
public static final String CONTENT_All = "All";
|
||||
|
||||
public static final String CONTENT_GeneralInfo = "GeneralInfo";
|
||||
|
||||
public static final String CONTENT_Image = "Image";
|
||||
|
||||
public static final String CONTENT_Multimedia = "Multimedia";
|
||||
|
||||
public static final String CONTENT_Gallery = "Gallery";
|
||||
|
||||
public static final String CONTENT_FeatureLogos = "FeatureLogos";
|
||||
|
||||
public static final String CONTENTDescription = "Description";
|
||||
|
||||
public static final String CONTENTReasonsToBuy = "ReasonsToBuy";
|
||||
|
||||
public static final String CONTENT_Reviews = "Reviews";
|
||||
|
||||
public static final String CONTENT_Related = "Related";
|
||||
|
||||
public static final String CONTENT_Dictionary = "Dictionary";
|
||||
|
||||
private static final String SRV_ENDPOINT = "http://live.icecat.biz/api/?";
|
||||
|
||||
private String username;
|
||||
|
||||
private String pwd;
|
||||
|
||||
private String lang;
|
||||
|
||||
private String content;
|
||||
|
||||
private JSONObject jDatasheet;
|
||||
|
||||
public Icecat(String username, String content, String lang) {
|
||||
this.username = username;
|
||||
this.content = content;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Icecat(String username, String lang) {
|
||||
this.username = username;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Icecat(String username) {
|
||||
this.username = username;
|
||||
this.lang = Locale.ITALIAN.getLanguage();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return (this.username == null) ? "openIcecat-live" : this.username.trim();
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getLang() {
|
||||
return this.lang;
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return (this.content == null) ? "All" : this.content.trim();
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getPwd() {
|
||||
return this.pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
public JSONObject getjDatasheet() {
|
||||
return this.jDatasheet;
|
||||
}
|
||||
|
||||
public ResParm fetchGtin(String gtin) {
|
||||
return fetchGtin(getContent(), gtin);
|
||||
}
|
||||
|
||||
public ResParm fetchProductCode(String brand, String productCode) {
|
||||
return fetchProductCode(getContent(), brand, productCode);
|
||||
}
|
||||
|
||||
public ResParm fetchIcecatCode(String icecatCode) {
|
||||
return fetchIcecatCode(getContent(), icecatCode);
|
||||
}
|
||||
|
||||
public ResParm fetchGtin(String content, String gtin) {
|
||||
setjDatasheet(null);
|
||||
StringBuilder sb = new StringBuilder("http://live.icecat.biz/api/?");
|
||||
sb.append("UserName=");
|
||||
sb.append(getUsername());
|
||||
sb.append("&Language=");
|
||||
sb.append(getLang().toLowerCase());
|
||||
sb.append("&Content=");
|
||||
sb.append(content);
|
||||
sb.append(">IN=");
|
||||
sb.append(gtin);
|
||||
ResParm rp = DBAdapter.getJSONObjectFromUrl(sb.toString());
|
||||
if (rp.getStatus()) {
|
||||
setjDatasheet((JSONObject)rp.getReturnObj());
|
||||
} else {
|
||||
DBAdapter.logDebug(this.debug, rp.getMsg());
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm fetchProductCode(String content, String brand, String productCode) {
|
||||
setjDatasheet(null);
|
||||
StringBuilder sb = new StringBuilder("http://live.icecat.biz/api/?");
|
||||
sb.append("UserName=");
|
||||
sb.append(getUsername());
|
||||
sb.append("&Language=");
|
||||
sb.append(getLang().toLowerCase());
|
||||
sb.append("&Content=");
|
||||
sb.append(content);
|
||||
sb.append("&Brand=");
|
||||
sb.append(brand);
|
||||
sb.append("&ProductCode=");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(productCode, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ResParm rp = DBAdapter.getJSONObjectFromUrl(sb.toString());
|
||||
if (rp.getStatus()) {
|
||||
setjDatasheet((JSONObject)rp.getReturnObj());
|
||||
} else {
|
||||
DBAdapter.logDebug(this.debug, rp.getMsg());
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm fetchIcecatCode(String content, String icecatCode) {
|
||||
setjDatasheet(null);
|
||||
StringBuilder sb = new StringBuilder("http://live.icecat.biz/api/?");
|
||||
sb.append("UserName=");
|
||||
sb.append(getUsername());
|
||||
sb.append("&Language=");
|
||||
sb.append(getLang().toLowerCase());
|
||||
sb.append("&Content=");
|
||||
sb.append(content);
|
||||
sb.append("&icecat_id=");
|
||||
sb.append(icecatCode);
|
||||
ResParm rp = DBAdapter.getJSONObjectFromUrl(sb.toString());
|
||||
if (rp.getStatus()) {
|
||||
setjDatasheet((JSONObject)rp.getReturnObj());
|
||||
} else {
|
||||
DBAdapter.logDebug(this.debug, rp.getMsg());
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public void setjDatasheet(JSONObject jDatasheet) {
|
||||
this.jDatasheet = jDatasheet;
|
||||
}
|
||||
|
||||
public String getDSTitle() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("TitleInfo")
|
||||
.getString("GeneratedIntTitle");
|
||||
}
|
||||
|
||||
public String getDSTitleLong() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getString("Title");
|
||||
}
|
||||
|
||||
public String getDSDescriptionLong() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("Description").getString("LongDesc");
|
||||
}
|
||||
|
||||
public String getDSDisclaimer() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("Description").getString("Disclaimer");
|
||||
}
|
||||
|
||||
public String getDSGaranzia() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("Description")
|
||||
.getString("WarrantyInfo");
|
||||
}
|
||||
|
||||
public String getDSSummaryDescriptionShort() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("SummaryDescription")
|
||||
.getString("ShortSummaryDescription");
|
||||
}
|
||||
|
||||
public String getDSSummaryDescriptionLong() {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
return getjDatasheet().getJSONObject("data").getJSONObject("GeneralInfo").getJSONObject("SummaryDescription")
|
||||
.getString("LongSummaryDescription");
|
||||
}
|
||||
|
||||
public LinkedHashSet<String> getDSImageGallery() {
|
||||
LinkedHashSet<String> hsGal = new LinkedHashSet<>();
|
||||
if (getjDatasheet() != null) {
|
||||
JSONArray jGallery = getjDatasheet().getJSONObject("data").getJSONArray("Gallery");
|
||||
jGallery.forEach(item -> {
|
||||
JSONObject gal = (JSONObject)item;
|
||||
hsGal.add(gal.getString("Pic"));
|
||||
});
|
||||
}
|
||||
return hsGal;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, LinkedHashSet<IcecatFeature>> getDSFeatures() {
|
||||
LinkedHashMap<String, LinkedHashSet<IcecatFeature>> hsFeatures = new LinkedHashMap<>();
|
||||
if (getjDatasheet() != null) {
|
||||
JSONArray jRows = getjDatasheet().getJSONObject("data").getJSONArray("FeaturesGroups");
|
||||
jRows.forEach(item -> {
|
||||
JSONObject jrow = (JSONObject)item;
|
||||
String title = jrow.getJSONObject("FeatureGroup").getJSONObject("Name").getString("Value");
|
||||
LinkedHashSet<IcecatFeature> hsFeat = new LinkedHashSet<>();
|
||||
JSONArray jFeatures = jrow.getJSONArray("Features");
|
||||
jFeatures.forEach(item2 -> {
|
||||
JSONObject jFeat = (JSONObject)item2;
|
||||
IcecatFeature icef = new IcecatFeature();
|
||||
icef.setName(jFeat.getJSONObject("Feature").getJSONObject("Name").getString("Value"));
|
||||
icef.setDescrizione(jFeat.getString("Description"));
|
||||
icef.setValue(jFeat.getString("PresentationValue"));
|
||||
hsFeat.add(icef);
|
||||
});
|
||||
hsFeatures.put(title, hsFeat);
|
||||
});
|
||||
}
|
||||
return hsFeatures;
|
||||
}
|
||||
|
||||
public String getDSFeaturesTable(String footer) {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder("<table class='table table-bordered table-indent'><tbody>");
|
||||
LinkedHashMap<String, LinkedHashSet<IcecatFeature>> features = getDSFeatures();
|
||||
for (Map.Entry<String, LinkedHashSet<IcecatFeature>> entry : features.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
sb.append("<tr>\n<th colspan='2' >_category</th>\n</tr>".replace("_category", key));
|
||||
LinkedHashSet<IcecatFeature> icfSet = entry.getValue();
|
||||
for (IcecatFeature icf : icfSet) {
|
||||
String temp = "<tr>\n<td>_desc</td>\n<td>_value</td></tr>".replace("_desc", icf.getName());
|
||||
temp = temp.replace("_value", icf.getValue());
|
||||
sb.append(temp);
|
||||
}
|
||||
}
|
||||
if (!footer.isEmpty())
|
||||
sb.append("<tr>\n<th colspan='2' >_category</th>\n</tr>".replace("_category", footer));
|
||||
sb.append("</tbody>\n</table>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getDSReasonToBuyTable(String intestazione) {
|
||||
if (getjDatasheet() == null)
|
||||
return "";
|
||||
LinkedHashSet<IcecatReason> hres = getDSReasonToBuy();
|
||||
if (hres.size() > 0) {
|
||||
StringBuilder sb = new StringBuilder("<table class='table table-bordered table-indent'><tbody>");
|
||||
sb.append("<tr>\n<th colspan='2' >_category</th>\n</tr>".replace("_category", intestazione));
|
||||
for (IcecatReason icr : hres) {
|
||||
String temp = "<tr>\n<td>_desc</td>\n<td>_value</td></tr>".replace("_desc", icr.getTitle());
|
||||
temp = temp.replace("_value", icr.getValue());
|
||||
sb.append(temp);
|
||||
}
|
||||
sb.append("</tbody>\n</table>");
|
||||
return sb.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public LinkedHashSet<IcecatReason> getDSReasonToBuy() {
|
||||
LinkedHashSet<IcecatReason> hsReason = new LinkedHashSet<>();
|
||||
if (getjDatasheet() != null) {
|
||||
JSONArray jRows = getjDatasheet().getJSONObject("data").getJSONArray("ReasonsToBuy");
|
||||
jRows.forEach(item -> {
|
||||
JSONObject jrow = (JSONObject)item;
|
||||
IcecatReason icer = new IcecatReason();
|
||||
icer.setTitle(jrow.getString("Title"));
|
||||
icer.setValue(jrow.getString("Value"));
|
||||
hsReason.add(icer);
|
||||
});
|
||||
}
|
||||
return hsReason;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getDSFeaturesHasMap() {
|
||||
HashMap<String, String> res = new HashMap<>();
|
||||
if (getjDatasheet() != null) {
|
||||
LinkedHashMap<String, LinkedHashSet<IcecatFeature>> features = getDSFeatures();
|
||||
for (Map.Entry<String, LinkedHashSet<IcecatFeature>> entry : features.entrySet()) {
|
||||
LinkedHashSet<IcecatFeature> icfSet = entry.getValue();
|
||||
for (IcecatFeature icf : icfSet)
|
||||
res.put(icf.getName(), icf.getValue());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Icecat() {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue