in modules/compiler/src/java/flex2/compiler/asdoc/TopLevelClassesGenerator.java [1963:2510]
private Element processIncludeExampleTag(String fullName, String exampleStr)
{
if (verbose)
{
System.out.println("processIncludeExampleTag:: fullname : " + fullName + " exampleStr :" + exampleStr);
}
boolean noSwf = false;
Element result = null;
int versionIdx = exampleStr.indexOf("-version");
String versionStr = "";
// remove -noswf from the @includeExample string
int noSwfIdx = exampleStr.indexOf("-noswf");
if (noSwfIdx != -1)
{
noSwf = true;
if (versionIdx != -1 && versionIdx > noSwfIdx)
{
versionStr = exampleStr.substring(versionIdx + 8);
}
exampleStr = exampleStr.substring(0, noSwfIdx);
}
else if (versionIdx != -1)
{
versionStr = exampleStr.substring(versionIdx + 8);
exampleStr = exampleStr.substring(0, versionIdx);
}
// remove whitespace from @includeExample string
exampleStr = exampleStr.replaceAll("\\s*", "");
// generate the examplefilename string
String exampleFileName = exampleStr;
int index = exampleFileName.lastIndexOf('/');
if (index != -1)
{
exampleFileName = exampleFileName.substring(index + 1);
}
// generate the swfpart string
String swfPartFile = exampleStr;
index = swfPartFile.lastIndexOf('.');
if (index != -1)
{
swfPartFile = swfPartFile.substring(0, index);
swfPartFile += ".swf";
}
// construct the location of the mxml code and read in the mxml code
String codePart = null;
String codeFileName = "";
try
{
NodeList includeExamplesList = asDocConfig.getElementsByTagName("includeExamplesDirectory");
if (includeExamplesList != null && includeExamplesList.getLength() != 0)
{
codeFileName = includeExamplesList.item(0).getTextContent();
}
codeFileName += "/";
QualifiedNameInfo qualifiedFullName = asDocUtil.decomposeFullClassName(fullName);
codeFileName += qualifiedFullName.getPackageName().replaceAll("\\.+", "/");
codeFileName += "/";
codeFileName += exampleStr;
codePart = FileUtil.readFile(new File(codeFileName));
}
catch (Exception ex)
{
if (verbose)
{
System.out.print("The file specified in @includeExample, " + exampleStr + ", cannot be found at " + codeFileName);
}
}
if (codePart != null)
{
codeFileName = codeFileName.toLowerCase();
Pattern pattern = Pattern.compile("\n");
Matcher matcher = pattern.matcher(codePart);
codePart = matcher.replaceAll("\n\n");
codePart = codePart.replaceAll("\\t", " ");
StringBuilder output = new StringBuilder();
int descBegin = 0;
int descEnd = 0;
int descEnd1 = 0;
String descText = null;
String descText2 = null;
descBegin = codePart.indexOf("@exampleText");
if (descBegin != -1)
{
descEnd1 = codePart.indexOf("@", descBegin + 1);
// depending upon the extension of the external examples file.. the comment closing will be different.
if (codeFileName.endsWith(".mxml"))
{
descEnd = codePart.indexOf("-->", descBegin); // mxml files have xml comment closing
}
else
{
descEnd = codePart.indexOf("*/", descBegin); // as files have */ comment closing.
}
if (descEnd1 != -1)
{
if (descEnd1 < descEnd)
{
descEnd = descEnd1;
}
}
if (descEnd != -1)
{
String temp = codePart.substring(descBegin + 12, descEnd - 1);
pattern = Pattern.compile("^\\s*\\*", Pattern.MULTILINE);
matcher = pattern.matcher(temp);
descText = matcher.replaceAll("");
if (codeFileName.endsWith(".mxml"))
{
pattern = Pattern.compile("^\\s*-", Pattern.MULTILINE); // for consistency mxml comment may have a - at the line start.
matcher = pattern.matcher(descText);
descText = matcher.replaceAll("");
}
}
else
{
String validationErrors = asDocUtil.getValidationErrors();
validationErrors += "comment not closed correctly in "+ codeFileName + " for " + fullName +" \n";
asDocUtil.setValidationErrors(validationErrors);
asDocUtil.setErrors(true);
}
}
int codeBegin = -1;
// depending upon the extension of the external examples file.. the comment closing will be different.
if (codeFileName.endsWith(".mxml"))
{
if (codePart.indexOf("<!---") != -1)
{
codeBegin = codePart.indexOf("-->"); // mxml files have xml comment closing
}
}
else
{
codeBegin = codePart.indexOf("*/"); // as files have */ comment closing.
}
if (codeBegin == -1)
{
codeBegin = 0;
}
else
{
codeBegin += 2;
if (codeFileName.endsWith(".mxml")) // mxml files have xml comment closing -->, so lets skip one more character.
{
codeBegin += 1;
}
}
int codeEnd = -1;
//depending upon the extension of the external examples file.. the comment beginning will also be different.
if (codeFileName.endsWith(".mxml"))
{
codeEnd = codePart.indexOf("<!---", codeBegin);
}
else
{
codeEnd = codePart.indexOf("/*", codeBegin);
}
if (codeEnd != -1 && codeEnd < codeBegin)
{
codeBegin = 0;
}
String codeBlock = "";
if (codeEnd == -1)
{
codeBlock = codePart.substring(codeBegin);
}
else
{
codeBlock = codePart.substring(codeBegin, codeEnd - 1);
}
if (codeBlock.replaceAll("\\s*", "").length() == 0)
{
if (verbose)
{
System.out.println("warning :: codeblock is empty for " + codeFileName);
}
}
if (codeBegin < descBegin)
{
output.append("<codeblock>");
output.append(asDocUtil.convertToEntity(codeBlock));
output.append("</codeblock>");
if (descText != null)
{
output.append(descText);
}
}
else
{
if (descText != null)
{
output.append(descText);
}
output.append("<codeblock>");
output.append(asDocUtil.convertToEntity(codeBlock));
output.append("</codeblock>");
codeEnd = codeBegin + codeBlock.length();
descBegin = codePart.indexOf("@exampleText", codeEnd);
if (descBegin != -1)
{
descEnd1 = codePart.indexOf("@", descBegin + 1);
// depending upon the extension of the external examples file.. the comment closing will be different.
if (codeFileName.endsWith(".mxml"))
{
descEnd = codePart.indexOf("-->", descBegin);
}
else
{
descEnd = codePart.indexOf("*/", descBegin);
}
if (descEnd1 != -1)
{
if (descEnd1 < descEnd)
{
descEnd = descEnd1;
}
}
if (descEnd != -1)
{
String temp = codePart.substring(descBegin + 12, descEnd - 1);
pattern = Pattern.compile("^\\s*\\*", Pattern.MULTILINE);
matcher = pattern.matcher(temp);
descText2 = matcher.replaceAll("");
if (codeFileName.endsWith(".mxml"))
{
pattern = Pattern.compile("^\\s*-", Pattern.MULTILINE);
matcher = pattern.matcher(descText2);
descText2 = matcher.replaceAll("");
}
output.append(descText2);
}
else
{
String validationErrors = asDocUtil.getValidationErrors();
validationErrors += "comment not closed correctly in "+ codeFileName + " for " + fullName +" \n";
asDocUtil.setValidationErrors(validationErrors);
asDocUtil.setErrors(true);
}
}
}
result = outputObject.createElement("example");
result.setAttribute("conref", exampleFileName);
CDATASection cdata = outputObject.createCDATASection(asDocUtil.validateText(output.toString(), "includeExample " + exampleStr, fullName));
result.appendChild(cdata);
// result.setTextContent(asDocUtil.validateText(output.toString()));
}
if (result == null)
{
result = outputObject.createElement("example");
result.setAttribute("conref", exampleFileName);
}
asDocUtil.convertDescToDITA(result, oldNewNamesMap);
if (!noSwf)
{
Element swfBlock = outputObject.createElement("swfblock");
swfBlock.setAttribute("conref", swfPartFile);
result.appendChild(swfBlock);
}
if (!versionStr.equals(""))
{
int langVersionIdx = versionStr.indexOf("-langversion");
int productVersionIdx = versionStr.indexOf("-productversion");
int playerVersionIdx = versionStr.indexOf("-playerversion");
boolean skipVersions = false;
if (langVersionIdx != -1 && versionStr.indexOf("-langversion", langVersionIdx + 1) != -1)
{
String validationErrors = asDocUtil.getValidationErrors();
validationErrors += "@includeExample for " + fullName + " contains multiple -langversion \n";
asDocUtil.setValidationErrors(validationErrors);
asDocUtil.setErrors(true);
skipVersions = true;
}
if (productVersionIdx != -1 && versionStr.indexOf("-productversion", productVersionIdx + 1) != -1)
{
String validationErrors = asDocUtil.getValidationErrors();
validationErrors += "@includeExample for " + fullName + " contains multiple -productversion \n";
asDocUtil.setValidationErrors(validationErrors);
asDocUtil.setErrors(true);
skipVersions = true;
}
if (playerVersionIdx != -1 && versionStr.indexOf("-playerversion", playerVersionIdx + 1) != -1)
{
String validationErrors = asDocUtil.getValidationErrors();
validationErrors += "@includeExample for " + fullName + " contains multiple -playerversion \n";
asDocUtil.setValidationErrors(validationErrors);
asDocUtil.setErrors(true);
skipVersions = true;
}
if (!skipVersions)
{
ArrayList<Integer> tagIndexs = new ArrayList<Integer>();
if (langVersionIdx != -1)
{
tagIndexs.add(langVersionIdx);
}
if (productVersionIdx != -1)
{
tagIndexs.add(productVersionIdx);
}
if (playerVersionIdx != -1)
{
tagIndexs.add(playerVersionIdx);
}
int tagLength = tagIndexs.size();
Collections.sort(tagIndexs);
Element asMetadata = outputObject.createElement("asMetadata");
Element apiVersion = outputObject.createElement("apiVersion");
asMetadata.appendChild(apiVersion);
Element prolog = outputObject.createElement("prolog");
prolog.appendChild(asMetadata);
if (langVersionIdx != -1)
{
int idx = tagIndexs.indexOf(langVersionIdx);
String langVersion = "";
if (idx != tagLength - 1)
{
langVersion = versionStr.substring(langVersionIdx + 12, tagIndexs.get(idx + 1));
}
else
{
langVersion = versionStr.substring(langVersionIdx + 12);
}
langVersion = langVersion.replaceAll("\n", "").replaceAll("\r", "");
if (langVersion.length() > 0)
{
Element apiLanguage = outputObject.createElement("apiLanguage");
langVersion = langVersion.replaceAll("^\\s+", "");
langVersion = langVersion.replaceAll("^\\s+$", "");
langVersion = langVersion.replaceAll("\\s+", " ");
String[] langVersionArr = langVersion.split(" ");
if (langVersionArr.length > 1)
{
apiLanguage.setAttribute("name", langVersionArr[0]);
apiLanguage.setAttribute("version", langVersionArr[1]);
}
else
{
apiLanguage.setAttribute("version", langVersionArr[0]);
}
apiVersion.appendChild(apiLanguage);
}
}
if (playerVersionIdx != -1)
{
int idx = tagIndexs.indexOf(playerVersionIdx);
String playerVersionStr = "";
if (idx != tagLength - 1)
{
playerVersionStr = versionStr.substring(playerVersionIdx + 14, tagIndexs.get(idx + 1));
}
else
{
playerVersionStr = versionStr.substring(playerVersionIdx + 14);
}
playerVersionStr = playerVersionStr.replaceAll("\n", "").replaceAll("\r", "");
if (playerVersionStr.length() > 0)
{
ArrayList<String[]> playerVersion = new ArrayList<String[]>();
playerVersionStr = playerVersionStr.replaceAll("\\A\\s+", "");
playerVersionStr = playerVersionStr.replaceAll("\\Z\\s+", "");
playerVersionStr = playerVersionStr.replaceAll("\\s+", " ");
String[] playerVersionArr = playerVersionStr.split(",");
for (int ix = 0; ix < playerVersionArr.length; ix++)
{
String tmpPlayerVersion = playerVersionArr[ix].trim();
playerVersion.add(tmpPlayerVersion.split(" "));
}
for (int ix = 0; ix < playerVersion.size(); ix++)
{
String[] tempPlayerVersionArr = playerVersion.get(ix);
StringBuilder versionDescription = new StringBuilder();
if (tempPlayerVersionArr.length > 2)
{
for (int iy = 2; iy < tempPlayerVersionArr.length; iy++)
{
if (!"".equals(tempPlayerVersionArr[iy]) && !"\n".equals(tempPlayerVersionArr[iy]))
{
if ((iy != tempPlayerVersionArr.length - 1) && !tempPlayerVersionArr[iy].matches("\\s"))
{
versionDescription.append(tempPlayerVersionArr[iy].replaceAll("\\s", ""));
versionDescription.append(" ");
}
else
{
versionDescription.append(tempPlayerVersionArr[iy].replaceAll("\\s", ""));
}
}
}
}
if (tempPlayerVersionArr.length > 1)
{
Element apiPlatform = outputObject.createElement("apiPlatform");
apiPlatform.setAttribute("name", tempPlayerVersionArr[0]);
apiPlatform.setAttribute("version", tempPlayerVersionArr[1].replaceAll("\\s", ""));
apiPlatform.setAttribute("description", versionDescription.toString());
apiVersion.appendChild(apiPlatform);
}
}
}
}
if (productVersionIdx != -1)
{
int idx = tagIndexs.indexOf(productVersionIdx);
String productVersionStr = "";
if (idx != tagLength - 1)
{
productVersionStr = versionStr.substring(productVersionIdx + 15, tagIndexs.get(idx + 1));
}
else
{
productVersionStr = versionStr.substring(productVersionIdx + 15);
}
productVersionStr = productVersionStr.replaceAll("\n", "").replaceAll("\r", "");
if (productVersionStr.length() > 0)
{
ArrayList<String[]> productVersion = new ArrayList<String[]>();
productVersionStr = productVersionStr.replaceAll("\\A\\s+", "");
productVersionStr = productVersionStr.replaceAll("\\Z\\s+", "");
productVersionStr = productVersionStr.replaceAll("\\s+", " ");
String[] productVersionArr = productVersionStr.split(",");
for (int ix = 0; ix < productVersionArr.length; ix++)
{
String tmpProductVersion = productVersionArr[ix].trim();
productVersion.add(tmpProductVersion.split(" "));
}
for (int ix = 0; ix < productVersion.size(); ix++)
{
String[] tmpProductVersionArr = productVersion.get(ix);
StringBuilder versionDescription = new StringBuilder();
if (tmpProductVersionArr.length > 2)
{
for (int iy = 2; iy < tmpProductVersionArr.length; iy++)
{
if (!"".equals(tmpProductVersionArr[iy]) && !"\n".equals(tmpProductVersionArr[iy]))
{
if ((iy != tmpProductVersionArr.length - 1) && !tmpProductVersionArr[iy].matches("\\s"))
{
versionDescription.append(tmpProductVersionArr[iy].replaceAll("\\s", ""));
versionDescription.append(" ");
}
else
{
versionDescription.append(tmpProductVersionArr[iy].replaceAll("\\s", ""));
}
}
}
}
if (tmpProductVersionArr.length > 1)
{
Element apiTool = outputObject.createElement("apiTool");
apiTool.setAttribute("name", tmpProductVersionArr[0]);
apiTool.setAttribute("version", tmpProductVersionArr[1].replaceAll("\\s", ""));
apiTool.setAttribute("description", versionDescription.toString());
apiVersion.appendChild(apiTool);
}
}
}
}
result.appendChild(prolog);
}
}
return result;
}