Skip to content

Commit

Permalink
Prepare for #89
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdog71 committed Jan 26, 2023
1 parent ad7516f commit f561736
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
6 changes: 6 additions & 0 deletions clownfish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@
<version>4.1.86.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ public Future<ClownfishResponse> makeResponse(String name, List<JsonFormParamete
freemarkerCfg.setTemplateLoader(freemarkerTemplateloader);
freemarkerCfg.setLocalizedLookup(false);
freemarkerCfg.setLocale(Locale.GERMANY);
freemarkerCfg.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);

fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());
isScripted = true;
Expand Down Expand Up @@ -1554,6 +1555,7 @@ private ClownfishResponse getStaticSite(String sitename) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append(System.lineSeparator());
}
cfResponse.setOutput(sb.toString());
cfResponse.setErrorcode(0);
Expand Down Expand Up @@ -1627,6 +1629,7 @@ private String interpretscript(String templatecontent, CfTemplate cftemplate, St
freemarkerCfg.setTemplateLoader(freemarkerStringTemplateloader);
freemarkerCfg.setLocalizedLookup(false);
freemarkerCfg.setLocale(Locale.GERMANY);
freemarkerCfg.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);

fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());

Expand Down Expand Up @@ -1927,8 +1930,11 @@ private String manageLayout(CfSite cfsite, String templatename, String templatec
cflayout.getDivArray().put(div.attr("id"), cfdiv);
}
if (preview) {
doc.head().append("<script src=\"resources/js/axios.js\"></script>");
doc.head().append("<link rel=\"stylesheet\" href=\"resources/css/cf_preview.css\">");
doc.head().append("<script async=\"\" defer=\"\" src=\"resources/js/cf_preview.js\"></script>");
doc.head().append("<link rel=\"stylesheet\" href=\"resources/css/preview_style.css\">");
doc.head().append("<script src=\"resources/js/cf_preview.js\"></script>");
doc.head().append("<script src=\"resources/js/preview_script.js\"></script>");
}
return doc.html();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private void callJob(CfQuartz quartz, long siteref) {
freemarkerCfg.setTemplateLoader(freemarkerTemplateloader);
freemarkerCfg.setLocalizedLookup(false);
freemarkerCfg.setLocale(Locale.GERMANY);
freemarkerCfg.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);

fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());
canExecute = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import org.jsoup.Jsoup;
import org.jsoup.examples.HtmlToPlainText;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
Expand All @@ -41,6 +42,7 @@ public class StaticSiteUtil {
* generateStaticSite
*
* @param sitename
* @param aliasname
* @param content
* @param cfassetService
* @param folderUtil
Expand Down Expand Up @@ -97,7 +99,9 @@ public static void generateStaticSite(String sitename, String aliasname, String
fileStream = new FileOutputStream(new File(folderUtil.getStatic_folder() + File.separator + sitename));
OutputStreamWriter writer = new OutputStreamWriter(fileStream, "UTF-8");
try {
writer.write(doc.html());
doc.outputSettings(new Document.OutputSettings().prettyPrint(false));
String text = doc.toString();
writer.write(text);
writer.close();
} catch (IOException e) {
throw new RuntimeException("Unable to create the destination file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,19 @@ public String replacePlaceholders(String content, CfDiv cfdiv, List<CfLayoutcont

private String surroundInplaceDivs(String content, CfDiv cfdiv, List<CfLayoutcontent> layoutcontent) {
Document doc = Jsoup.parseBodyFragment(content);
reworkElements(doc.body().children(), cfdiv, layoutcontent);
//Elements elements = doc.body().children();
return doc.body().children().toString();
if (null != doc.body().children()) {
reworkElements(doc.body().children(), cfdiv, layoutcontent);
return doc.childNode(0).childNode(1).childNode(0).toString();
} else {
String c = reworkContent(doc.childNode(0).childNode(1).childNode(0).toString(), cfdiv, layoutcontent);
return c;
}
}

private void reworkElements(Elements elements, CfDiv cfdiv, List<CfLayoutcontent> layoutcontent) {
int counter = 0;
for (Element el : elements) {
if (el.childrenSize() > 0) {
if (null != el.children()) {
reworkElements(el.children(), cfdiv, layoutcontent);
} else {
String outerhtml = el.outerHtml();
Expand Down Expand Up @@ -357,7 +362,11 @@ private void reworkElements(Elements elements, CfDiv cfdiv, List<CfLayoutcontent
String attr = classname+":"+contentname+":"+attributname+":"+attributtype;
Attributes attributes = new Attributes();
attributes.put("cf_inplace",attr);

Element surrounddiv = new Element(Tag.valueOf("div"), "", attributes);
surrounddiv.addClass("cf_inplace");
counter++;
surrounddiv.attr("id", "cf_id_" + cfdiv.getName()+"_"+counter);

//System.out.println(surrounddiv.outerHtml());
el.wrap(surrounddiv.toString());
Expand All @@ -366,4 +375,37 @@ private void reworkElements(Elements elements, CfDiv cfdiv, List<CfLayoutcontent
}
}
}

private String reworkContent(String html, CfDiv cfdiv, List<CfLayoutcontent> layoutcontent) {
Pattern pattern = Pattern.compile("\\$\\{sitecontent\\.#C:.+#\\..+\\}");
Matcher matcher = pattern.matcher(html);
boolean matchFound = matcher.find();
if (matchFound) {
String region = html.substring((matcher.start()+2), (matcher.end()-1));
String[] parts = region.split("\\.");
String classparts[] = parts[1].split(":");
String classname = classparts[1];
String attributname = parts[2];

CfClasscontent cfcontent = null;
for (String c : cfdiv.getContentArray()) {
List<CfLayoutcontent> contentlist = layoutcontent.stream().filter(lc -> lc.getCfLayoutcontentPK().getContenttype().compareToIgnoreCase("C") == 0).collect(Collectors.toList());
for (CfLayoutcontent lc : contentlist) {

if ((null != lc.getContentref()) && (lc.getContentref().longValue() > 0)) {
cfcontent = cfclasscontentService.findById(lc.getContentref().longValue());
}
}
}
String contentname = "";
String attributtype = "";
if (null != cfcontent) {
contentname = cfcontent.getName();
attributtype = cfattributService.findByNameAndClassref(attributname, cfcontent.getClassref()).getAttributetypeString();
}
String attr = classname+":"+contentname+":"+attributname+":"+attributtype;
html = "<div id=\"cf_id_" + cfdiv.getName() + "\" class=\"cf_inplace\" cf_inplace=\"" + attr + "\">" + html + "</div>";
}
return html;
}
}

0 comments on commit f561736

Please sign in to comment.