Skip to content

Commit

Permalink
experiment with sniffing
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Nov 21, 2024
1 parent 776a70b commit 9f9849c
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions core/src/main/java/lucee/transformer/cfml/tag/CFMLTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,46 @@ public Page transform(Factory factory, ConfigPro config, PageSource ps, TagLib[]

Charset charset = config.getTemplateCharset();
boolean dotUpper = ((MappingImpl) ps.getMapping()).getDotNotationUpperCase();
//sc = new PageSourceCode(ps, charset, writeLog);
TagLibTag scriptTag = CFMLTransformer.getTLT(Constants.CFML_SCRIPT_TAG_NAME, config.getIdentification());
TagLibTag componentTag = CFMLTransformer.getTLT(Constants.CFML_COMPONENT_TAG_NAME, config.getIdentification());

String fileExt = ResourceUtil.getExtension(ps.getResource(), "");

// could it be a component?
boolean isCFMLCompExt = Constants.isCFMLComponentExtension(fileExt);

// parse regular
while (true) {
try {
sc = new PageSourceCode(ps, charset, writeLog);
// sc = new PageSourceCode(ps, charset, writeLog);
String srcText = "";
boolean addCfscript = false;
if (Constants.isCFMLScriptExtension(fileExt)) {
addCfscript = true;
srcText = PageSourceCode.toString(ps, charset);
} else if (isCFMLCompExt) {
srcText = PageSourceCode.toString(ps, charset);
String srcTextLower = srcText.toLowerCase();
// sniff to see if the cfc is already tag based
if (!srcTextLower.contains("<" + scriptTag.getFullName())
&& !srcTextLower.contains("<" + componentTag.getFullName())
&& !srcTextLower.contains("<cfinterface")) addCfscript = true;
//srcTextLower = null;
//if (!addCfscript) srcText = null;

// script files (cfs)
if (Constants.isCFMLScriptExtension(ListUtil.last(ps.getRealpath(), '.'))) {
TagLibTag scriptTag = CFMLTransformer.getTLT(sc, Constants.CFML_SCRIPT_TAG_NAME, config.getIdentification());
}

sc.setPos(0);
SourceCode original = sc;
// script files (cfs)
if (addCfscript) {
// sc.setPos(0);
// SourceCode original = sc;

// try inside a cfscript
String text = "<" + scriptTag.getFullName() + ">" + original.getText() + "\n</" + scriptTag.getFullName() + ">";
String text = "<" + scriptTag.getFullName() + ">" + srcText + "\n</" + scriptTag.getFullName() + ">";
sc = new PageSourceCode(ps, text, charset, writeLog);
} else {
sc = new PageSourceCode(ps, charset, writeLog);
}

p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
Expand All @@ -178,8 +202,7 @@ public Page transform(Factory factory, ConfigPro config, PageSource ps, TagLib[]
}
}

// could it be a component?
boolean isCFMLCompExt = Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""));


boolean possibleUndetectedComponent = false;

Expand All @@ -191,7 +214,7 @@ public Page transform(Factory factory, ConfigPro config, PageSource ps, TagLib[]
if (possibleUndetectedComponent) {
Page _p;

TagLibTag scriptTag = CFMLTransformer.getTLT(sc, Constants.CFML_SCRIPT_TAG_NAME, config.getIdentification());
//TagLibTag scriptTag = CFMLTransformer.getTLT(sc, Constants.CFML_SCRIPT_TAG_NAME, config.getIdentification());

sc.setPos(0);
SourceCode original = sc;
Expand All @@ -203,8 +226,8 @@ public Page transform(Factory factory, ConfigPro config, PageSource ps, TagLib[]
try {
while (true) {
if (sc == null) {
sc = new PageSourceCode(ps, charset, writeLog);
text = "<" + scriptTag.getFullName() + ">" + sc.getText() + "\n</" + scriptTag.getFullName() + ">";
//sc = new PageSourceCode(ps, charset, writeLog);
text = "<" + scriptTag.getFullName() + ">" + PageSourceCode.toString(ps, charset) + "\n</" + scriptTag.getFullName() + ">";
sc = new PageSourceCode(ps, text, charset, writeLog);
}
try {
Expand Down Expand Up @@ -247,6 +270,18 @@ public static TagLibTag getTLT(SourceCode cfml, String name, Identification id)
}
}

public static TagLibTag getTLT(String name, Identification id) throws TemplateException {
TagLib tl;
try {
// this is already loaded, oherwise we where not here
tl = TagLibFactory.loadFromSystem(id);
return tl.getTag(name);
}
catch (TagLibException e) {
throw new TemplateException(e.getMessage());
}
}

/**
* Startmethode zum transfomieren einer CFMLString. <br />
* EBNF:<br />
Expand Down

0 comments on commit 9f9849c

Please sign in to comment.