Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First pass of apptacular engine.

  • Loading branch information...
commit 0a79e5ac53b0c80d9e1d377b202d9ebffb587cee 0 parents
@tpryan authored
12 .project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Apptacular</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.adobe.ide.coldfusion.projectNature</nature>
+ </natures>
+</projectDescription>
3  .settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Fri Nov 20 21:56:59 EST 2009
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
64 handlers/cfc/code/CFPage.cfc
@@ -0,0 +1,64 @@
+<cfcomponent displayname="CFPage" hint="A cfc representation of a cfpage." accessors="true" >
+ <cfproperty name="name" hint="The name of the page" />
+ <cfproperty name="fileLocation" hint="File path of the page" />
+ <cfproperty name="extension" />
+
+
+ <cfscript>
+ public CFPage function init(required string name, required string fileLocation){
+
+ This.setExtension('cfm');
+ This.setName(arguments.Name);
+ This.setFileLocation(arguments.fileLocation);
+ variables.NL = createObject("java", "java.lang.System").getProperty("line.separator");
+ variables.body = CreateObject("java","java.lang.StringBuilder").Init();
+ variables.bodyScript = CreateObject("java","java.lang.StringBuilder").Init();
+
+ return This;
+ }
+
+ public function appendBody(string bodyContent=""){
+ variables.body.append(arguments.bodyContent & variables.NL);
+ }
+
+ public function appendBodyScript(string bodyContent=""){
+ variables.bodyScript.append(arguments.bodyContent & variables.NL);
+ }
+
+ public string function getCFML(){
+ return variables.body;
+ }
+
+ private string function getFileName(){
+ return "#This.getFileLocation()#/#This.getName()#.#This.getExtension()#";
+ }
+
+ public void function write(required string format="cfml"){
+ conditionallyCreateDirectory(This.getFileLocation());
+
+ if (CompareNoCase(arguments.format, "cfscript") eq 0)
+ fileWrite(getFileName(), Trim(getCFScript()));
+ else{
+ fileWrite(getFileName(), Trim(getCFML()));
+ }
+ }
+
+
+
+ </cfscript>
+
+
+
+
+
+ <cffunction access="public" name="conditionallyCreateDirectory" output="false" returntype="void" description="Checks to see if a directory exists if it doesn't it creates it." >
+ <cfargument name="directory" type="string" required="yes" default="" hint="Driectory to create if it doesn't already exist." />
+
+ <cfif not DirectoryExists(arguments.directory)>
+ <cfdirectory directory="#arguments.directory#" action="create" />
+ </cfif>
+
+ </cffunction>
+
+
+</cfcomponent>
128 handlers/cfc/code/applicationCFC.cfc
@@ -0,0 +1,128 @@
+component extends="cfc" accessors="true" {
+
+ public applicationCFC function init(){
+ variables.lineBreak = createObject("java", "java.lang.System").getProperty("line.separator");
+
+ This.setOutput(FALSE);
+ This.setExtension('cfc');
+ variables.constructorArray = ArrayNew(1);
+ variables.functionArray = ArrayNew(1);
+ variables.propertyArray = ArrayNew(1);
+ variables.appPropertyArray = ArrayNew(1);
+
+ return This;
+ }
+
+ /**
+ * @hint Adds the code of a property to the CFC.
+ */
+ public function addApplicationProperty( required string name,
+ required string value,
+ boolean surroundWithQuotes){
+ var appProp = structNew();
+ appProp.name = arguments.name;
+ appProp.value = arguments.value;
+
+ if (structKeyExists(arguments, "surroundwithQuotes")){
+ appProp.quote = arguments.surroundwithQuotes;
+ }
+ else{
+ appProp.quote = "";
+ }
+
+ ArrayAppend(variables.appPropertyArray, appProp);
+
+ }
+
+
+ /**
+ * @hint Adds the code of a property to the CFC.
+ */
+ public string function generateCFMLApplicationProperties(){
+ var props = variables.lineBreak;
+ var i = 0;
+ var propStruct = structNew();
+ for(i = 1; i lte ArrayLen(variables.appPropertyArray); i++ ){
+ propStruct = variables.appPropertyArray[i];
+ if (( isNumeric(propStruct.value) OR
+ isBoolean(propStruct.value)) OR
+ (ISBoolean(propStruct.quote) and not propStruct.quote) )
+ {
+ props = props & ' <cfset This.' & propStruct.name & ' = ' & propStruct.value & ' />' & variables.lineBreak ;
+ }
+ else{
+ props = props & ' <cfset This.' & propStruct.name & ' = "' & propStruct.value & '" />' & variables.lineBreak ;
+ }
+ }
+
+ return props;
+
+ }
+
+ public string function generateCFScriptApplicationProperties(){
+ var props = variables.lineBreak;
+ var i = 0;
+ var propStruct = structNew();
+
+
+ for(i = 1; i lte ArrayLen(variables.appPropertyArray); i++ ){
+ propStruct = variables.appPropertyArray[i];
+ if (( isNumeric(propStruct.value) OR
+ isBoolean(propStruct.value)) OR
+ (ISBoolean(propStruct.quote) and not propStruct.quote) )
+ {
+ props = props & ' This.' & propStruct.name & ' = ' & propStruct.value & ';' & variables.lineBreak ;
+ }
+ else{
+ props = props & ' This.' & propStruct.name & ' = "' & propStruct.value & '";' & variables.lineBreak ;
+ }
+ }
+
+ return props;
+
+ }
+
+ /**
+ * @hint Returns the actual cfml cfc code.
+ */
+ public string function getCFML(){
+ var results = "";
+
+ /* Add the header to the cfc feed. */
+ results = results & generateCFMLHeader();
+ results = results & generateCFMLProperties() ;
+ results = results & generateCFMLApplicationProperties() ;
+ results = results & generateCFMLConstructor();
+ results = results & generateCFMLFunctions();
+ /* Add the footer to the cfc feed. */
+ results = results & generateCFMLFooter();
+
+ return results;
+ }
+
+
+ /**
+ * @hint Returns the actual cfscript cfc code.
+ */
+ public string function getCFScript(){
+ var results = "";
+
+ /* Add the header to the cfc feed. */
+ results = results & generateCFScriptHeader();
+ results = results & generateCFScriptProperties() ;
+ results = results & generateCFScriptApplicationProperties() ;
+ results = results & generateCFScriptConstructor();
+ results = results & generateCFScriptFunctions();
+ /* Add the footer to the cfc feed. */
+ results = results & generateCFScriptFooter();
+
+ return results;
+ }
+}
+
+
+
+
+
+
+
64 handlers/cfc/code/argument.cfc
@@ -0,0 +1,64 @@
+component accessors="true" {
+
+ property name="name";
+ property name="type";
+ property name="required";
+ property name="defaultvalue";
+ property name="hint";
+
+ public function init(){
+ variables.lineBreak = createObject("java", "java.lang.System").getProperty("line.separator");
+ return This;
+ }
+
+ public string function getCFML(){
+ var argCFML = '<cfargument';
+
+ argCFML = ListAppend(argCFML, 'name="#This.getName()#"', ' ');
+
+ if (len(This.getType())){
+ argCFML = ListAppend(argCFML, 'type="#This.getType()#"', ' ');
+ }
+
+ if (len(This.getRequired()) gt 0 and IsBoolean(This.getRequired()) and This.getRequired()){
+ argCFML = ListAppend(argCFML, 'required="#This.getRequired()#"', ' ');
+ }
+
+ if (len(This.getDefaultvalue()) gt 0 and IsBoolean(This.getRequired()) and not This.getRequired()){
+ argCFML = ListAppend(argCFML, 'default="#This.getDefaultvalue()#"', ' ');
+ }
+
+ if (len(This.getHint())){
+ argCFML = ListAppend(argCFML, 'hint="#This.getHint()#"', ' ');
+ }
+
+ argCFML = ListAppend(argCFML, ' />' & variables.lineBreak, ' ');
+
+ return argCFML;
+
+ }
+
+ public string function getCFScript(){
+ var argCFML = '';
+
+ argCFML = ListAppend(argCFML, '#This.getName()#', ' ');
+
+ if (len(This.getType())){
+ argCFML = ListPrepend(argCFML, '#This.getType()#', ' ');
+ }
+
+ if (len(This.getRequired()) gt 0 and IsBoolean(This.getRequired()) and This.getRequired()){
+ argCFML = ListPrepend(argCFML, 'required', ' ');
+ }
+
+ if (len(This.getDefaultvalue()) gt 0){
+ argCFML = ListAppend(argCFML, '="#This.getDefaultvalue()#"', ' ');
+ }
+
+
+ return argCFML;
+
+ }
+
+
+}
189 handlers/cfc/code/cfc.cfc
@@ -0,0 +1,189 @@
+component extends="CFPage" accessors="true" {
+ property string extends;
+ property string table;
+ property string entityname;
+ property name="output" type="boolean" default="false";
+ property name="persistent" type="boolean" default="false";
+
+ public function init(){
+
+ variables.lineBreak = createObject("java", "java.lang.System").getProperty("line.separator");
+ This.setExtension('cfc');
+ This.setOutput(FALSE);
+
+ variables.constructorArray = ArrayNew(1);
+ variables.functionArray = ArrayNew(1);
+ variables.propertyArray = ArrayNew(1);
+
+ }
+
+ public string function generateCFMLHeader(){
+ var header = '<cfcomponent';
+
+ if (len(This.getExtends()) gt 0){
+ header = ListAppend(header, 'extends="#This.getExtends()#"', ' ') ;
+ }
+
+ if (len(This.getPersistent())){
+ header = ListAppend(header, 'persistent="#This.getPersistent()#"', ' ') ;
+ }
+
+ if (len(This.getTable()) gt 0){
+ header = ListAppend(header, 'table="#This.getTable()#"', ' ') ;
+ }
+
+ if (len(This.getEntityName()) gt 0){
+ header = ListAppend(header, 'entityName="#This.getEntityName()#"', ' ') ;
+ }
+
+ if (This.getOutput()){
+ header = ListAppend(header, 'output="#This.getOutput()#"', ' ') ;
+ }
+
+ header = ListAppend(header, '>' & variables.lineBreak, ' ') ;
+
+ return header;
+
+ }
+
+ public string function generateCFScriptHeader(){
+ var header = 'component';
+
+ if (len(This.getExtends()) gt 0){
+ header = ListAppend(header, 'extends="#This.getExtends()#"', ' ') ;
+ }
+
+ if (len(This.getPersistent())){
+ header = ListAppend(header, 'persistent="#This.getPersistent()#"', ' ') ;
+ }
+
+ if (len(This.getTable()) gt 0){
+ header = ListAppend(header, 'table="#This.getTable()#"', ' ') ;
+ }
+
+ if (len(This.getEntityName()) gt 0){
+ header = ListAppend(header, 'entityName="#This.getEntityName()#"', ' ') ;
+ }
+
+ if (This.getOutput()){
+ header = ListAppend(header, 'output="#This.getOutput()#"', ' ') ;
+ }
+
+ header = ListAppend(header, '{' & variables.lineBreak, ' ') ;
+
+ return header;
+
+ }
+
+ public string function generateCFMLFooter(){
+ var footer = '</cfcomponent>' & variables.lineBreak;
+ return footer;
+ }
+
+ public string function generateCFScriptFooter(){
+ var footer = '}' & variables.lineBreak;
+ return footer;
+ }
+
+ private string function generateCFMLProperties(){
+ if (ArrayLen(variables.propertyArray) eq 0){
+ return "";
+ }
+
+ var props = variables.lineBreak;
+ var i = 0;
+
+ for (i = 1; i lte ArrayLen(variables.propertyArray); i++){
+ props = props & " " & variables.propertyArray[i].getCFML() & variables.lineBreak ;
+ }
+
+ return props;
+ }
+
+ private string function generateCFScriptProperties(){
+ if (ArrayLen(variables.propertyArray) eq 0){
+ return "";
+ }
+
+ var props = variables.lineBreak;
+ var i = 0;
+
+ for (i = 1; i lte ArrayLen(variables.propertyArray); i++){
+ props = props & " " & variables.propertyArray[i].getCFSCript() & variables.lineBreak ;
+ }
+
+ return props;
+ }
+
+ private string function generateCFMLFunctions(){
+ var body = "";
+
+ body = body & variables.lineBreak;
+
+ for (i = 1; i lte ArrayLen(variables.functionArray); i++){
+ body = body & " " & variables.functionArray[i].getCFML();
+ body = body & variables.lineBreak;
+ }
+
+ return body;
+
+ }
+
+ private string function generateCFScriptFunctions(){
+ var body = "";
+
+ for (i = 1; i lte ArrayLen(variables.functionArray); i++){
+ body = body & variables.lineBreak & " " & variables.functionArray[i].getCFScript();
+ }
+
+ body = body & variables.lineBreak;
+ return body;
+
+ }
+
+ private string function generateCFMLConstructor(){
+ return "";
+
+ }
+
+ private string function generateCFScriptConstructor(){
+ return "";
+
+ }
+
+ public string function getCFML(){
+ var results = "";
+
+ results = results & generateCFMLHeader();
+ results = results & generateCFMLProperties() ;
+ results = results & generateCFMLFunctions();
+ results = results & generateCFMLFooter();
+
+ return results;
+ }
+
+ public string function getCFScript(){
+ var results = "";
+
+ results = results & generateCFScriptHeader();
+ results = results & generateCFScriptProperties() ;
+ results = results & generateCFScriptFunctions();
+ results = results & generateCFScriptFooter();
+
+ return results;
+ }
+
+ public void function addFunction(required functionObj){
+ ArrayAppend(variables.functionArray, arguments.functionObj);
+ }
+
+ public void function addProperty(required property property){
+ ArrayAppend(variables.propertyArray, arguments.property);
+ }
+
+
+
+
+}
+
+
64 handlers/cfc/code/customTag.cfc
@@ -0,0 +1,64 @@
+component extends="CFPage" accessors="true"
+{
+ /**
+ * @hint Psuedo constructor, and all around nice function.
+ */
+ public any function init(required string name, required string fileLocation){
+
+ This.setExtension('cfm');
+ This.setName(arguments.Name);
+ This.setFileLocation(arguments.fileLocation);
+
+ variables.NL = createObject("java", "java.lang.System").getProperty("line.separator");
+
+ variables.header = "<!--- #This.getName()#.cfm --->" & NL & '<cfprocessingdirective suppresswhitespace="yes">' & variables.NL;
+ variables.attributes = CreateObject("java","java.lang.StringBuilder").Init();
+ variables.body = CreateObject("java","java.lang.StringBuilder").Init();
+ variables.footer = "</cfprocessingdirective>" & variables.NL & '<cfexit method="exitTag" />' & variables.NL ;
+
+
+ }
+
+ /**
+ * @hint Adds a cfparam'ed attribute to the custom tag.
+ */
+ public void function addAttribute(required string name, string type="", boolean required=false, string defaultvalue=""){
+ var attributeString = CreateObject("java","java.lang.StringBuilder").Init();
+ attributeString.append('<cfparam name="attributes.' & arguments.name & '"');
+
+ if (len(arguments.type gt 1)){
+ attributeString.append(' type="' & arguments.type & '"');
+ }
+
+ if (not arguments.required AND len(arguments.defaultvalue gt 1)){
+ attributeString.append(' default="' & arguments.defaultvalue & '"');
+ }
+
+ attributeString.append(" />" & variables.NL);
+
+ variables.attributes.append(attributeString);
+ }
+
+ /**
+ * @hint Returns the actual cf code.
+ */
+ public string function getCFML(){
+ var i=0;
+ var results = CreateObject("java","java.lang.StringBuilder").Init();
+
+ // Add the header to the custom tag. --->
+ results.append(variables.header);
+ results.append(variables.attributes);
+ results.append(variables.body);
+
+ // Add the footer to the custom tag. --->
+ results.append(variables.footer);
+
+ return results;
+ }
+
+
+
+
+
+}
241 handlers/cfc/code/function.cfc
@@ -0,0 +1,241 @@
+component accessors="true" {
+
+ property name="name";
+ property name="output" type="boolean" default="false";
+ property name="access";
+ property name="hint";
+ property name="returntype";
+ property name="ReturnResult";
+
+
+ public function init(){
+ variables.lineBreak = createObject("java", "java.lang.System").getProperty("line.separator");
+ variables.arguments = ArrayNew(1);
+ variables.localvariables = ArrayNew(1);
+ variables.operation = CreateObject("java","java.lang.StringBuilder").Init();
+ variables.operationScript = CreateObject("java","java.lang.StringBuilder").Init();
+
+ return This;
+ }
+
+ public void function addArgument(required argument argument){
+ ArrayAppend(variables.arguments, arguments.argument);
+ }
+
+ public void function AddLocalVariable(required string LocalVariable, string type="string", string value="", boolean quote=true){
+ ArrayAppend(variables.localVariables, Duplicate(arguments));
+ }
+
+ public void function AddOperation(required string Operation){
+ variables.operation = variables.operation.append(arguments.operation & lineBreak);
+ }
+
+ public void function AddOperationScript(required string Operation){
+ variables.operationScript = variables.operationScript.append(arguments.operation & lineBreak);
+ }
+
+ public string function generateCFMLHeader(){
+ var header = '<cffunction';
+
+ if (len(This.getName()) gt 0){
+ header = ListAppend(header, 'name="#This.getName()#"', ' ');
+ }
+
+ if (len(This.getAccess()) gt 0){
+ header = ListAppend(header, 'access="#This.getAccess()#"', ' ');
+ }
+
+ if (len(This.getOutput())){
+ header = ListAppend(header, 'output="#This.getOutput()#"', ' ');
+ }
+
+ if (len(This.getReturntype()) gt 0){
+ header = ListAppend(header, 'returnType="#This.getReturntype()#"', ' ');
+ }
+
+ header = ListAppend(header, '>' & variables.lineBreak, ' ');
+
+ return header ;
+ }
+
+ public string function generateCFScriptHeader(){
+ var header = '';
+ var IsPreFunction = false;
+
+ if (len(This.getAccess()) gt 0){
+ var IsPreFunction = true;
+ header = '#This.getAccess()#';
+ }
+
+ if (len(This.getReturntype()) gt 0){
+ var IsPreFunction = true;
+ if(IsPreFunction){
+ header = ListAppend(header, '#This.getReturntype()#', ' ');
+ }
+ else{
+ header = '#This.getReturntype()#';
+ }
+
+ }
+
+ if(IsPreFunction){
+ header = ListAppend(header, 'function', ' ');
+ }
+ else{
+ header = ' function';
+ }
+
+ header = ListAppend(header, '#This.getName()#(' & generateCfscriptArguments() & ')', ' ');
+
+ if (len(This.getOutput()) gt 0){
+ header = ListAppend(header, 'output="#getOutput()#"', ' ');
+ }
+
+ header = ListAppend(header, '{' & variables.lineBreak, ' ');
+
+ return header;
+ }
+
+ private string function generateCFMLFooter(){
+ return ' </cffunction>' & variables.lineBreak;
+ }
+
+ private string function generateCFScriptFooter(){
+ return ' }' & variables.lineBreak ;
+ }
+
+ private string function generateCFMLArguments(){
+ var results ="";
+ var i = 0;
+
+ for (i= 1; i lte arraylen(variables.arguments); i++){
+ results = results & " " & variables.arguments[i].getCFML();
+ }
+
+ return results;
+ }
+
+ private string function generateCFScriptArguments(){
+ var results ="";
+ var i = 0;
+
+ for (i= 1; i lte arraylen(variables.arguments); i++){
+ results = ListAppend(results,variables.arguments[i].getCFScript());
+ }
+
+ results = Replace(results, ",", ", ","ALL");
+
+ return results;
+ }
+
+ private string function generateCFMLLocalVariables(){
+ var results ="";
+ var temp="";
+ var i = 0;
+ var localVar=StructNew();
+
+ if (ArrayLen(variables.localVariables) gt 0){
+ results = variables.linebreak;
+ }
+
+ for (i= 1; i lte arraylen(variables.localVariables); i++){
+ localVar = variables.localVariables[i];
+
+ if (len(localVar.value) gt 0){
+ if(localVar.quote){
+ temp = ' <cfset var #localVar.localvariable# = "#localVar.value#" />' & variables.lineBreak;
+ }
+ else{
+ temp = ' <cfset var #localVar.localvariable# = #localVar.value# />' & variables.lineBreak;
+ }
+ }
+ else if (CompareNoCase(localVar.type, "struct") eq 0){
+ temp = " <cfset var #localVar.localvariable# = StructNew() />" & variables.lineBreak;
+ }
+ else{
+ temp = " <cfset var #localVar.localvariable# = """" />" & variables.lineBreak;
+ }
+
+ results = results & temp;
+
+ }
+
+
+ return results;
+ }
+
+ private string function generateCFScriptLocalVariables(){
+ var results ="";
+ var temp="";
+ var i = 0;
+ var localVar=StructNew();
+
+ if (ArrayLen(variables.localVariables) gt 0){
+ results = variables.linebreak;
+ }
+
+ for (i= 1; i lte arraylen(variables.localVariables); i++){
+ localVar = variables.localVariables[i];
+
+ if (len(localVar.value) gt 0){
+ if(localVar.quote){
+ temp = ' var #localVar.localvariable# = "#localVar.value#";' & variables.lineBreak;
+ }
+ else{
+ temp = ' var #localVar.localvariable# = #localVar.value#;' & variables.lineBreak;
+ }
+ }
+ else if (CompareNoCase(localVar.type, "struct") eq 0){
+ temp = " var #localVar.localvariable# = StructNew();" & variables.lineBreak;
+ }
+ else{
+ temp = " var #localVar.localvariable# = """";" & variables.lineBreak;
+ }
+
+ results = results & temp;
+
+ }
+
+
+ return results;
+
+
+
+
+ }
+
+ public string function getCFML(){
+ var results="";
+
+ results = results & generateCFMLHeader();
+ results = results & generateCFMLArguments();
+ results = results & generateCFMLLocalVariables();
+ results = results & operation;
+
+ if (compareNoCase(This.getReturnType(), "void") neq 0){
+ results = results.concat(' <cfreturn #This.getReturnResult()# />' & variables.lineBreak);
+ }
+
+ results = results.concat(generateCFMLFooter()) ;
+
+ return results;
+ }
+
+ public string function getCFScript(){
+ var results="";
+
+ results = results & generateCFScriptHeader();
+ results = results & generateCFScriptLocalVariables();
+ results = results & operationScript;
+
+ if (compareNoCase(This.getReturnType(), "void") neq 0){
+ results = results.concat(' return #This.getReturnResult()#;' & variables.lineBreak);
+ }
+
+ results = results.concat(generateCFScriptFooter()) ;
+
+ return results;
+ }
+
+
+}
146 handlers/cfc/code/property.cfc
@@ -0,0 +1,146 @@
+component accessors="true" {
+
+ property name="name";
+ property name="column";
+ property name="type";
+ property name="ormtype";
+ property name="length";
+ property name="fieldtype";
+ property name="generator";
+ property name="fkcolumn";
+ property name="cfc";
+ property name="missingRowIgnored" type="boolean" default="true";
+ property name="inverse" type="boolean" default="true";
+ property name="cascade";
+ property name="collectiontype";
+ property name="singularName";
+
+
+ public string function getCFML(){
+ var result = "";
+
+ result = result & '<cfproperty';
+
+ if (len(This.getName())){
+ result = ListAppend(result, 'name="#This.getName()#"', " ") ;
+ }
+
+ if (len(This.getColumn())){
+ result = ListAppend(result, 'column="#This.getColumn()#"', " ") ;
+ }
+
+ if (len(This.getormtype())){
+ result = ListAppend(result, 'ormtype="#This.getormtype()#"', " ") ;
+ }
+
+ if (len(This.gettype())){
+ result = ListAppend(result, 'type="#This.gettype()#"', " ") ;
+ }
+
+ if (len(This.getFieldtype())){
+ result = ListAppend(result, 'fieldtype="#This.getFieldtype()#"', " ") ;
+ }
+
+ if (len(This.getGenerator())){
+ result = ListAppend(result, 'generator="#This.getGenerator()#"', " ") ;
+ }
+
+ if (len(This.getCFC())){
+ result = ListAppend(result, 'cfc="#This.getCFC()#"', " ") ;
+ }
+
+ if (len(This.getFkColumn())){
+ result = ListAppend(result, 'fkColumn="#This.getFkColumn()#"', " ") ;
+ }
+
+ if (len(This.getmissingRowIgnored())){
+ result = ListAppend(result, 'missingRowIgnored="#This.getmissingRowIgnored()#"', " ") ;
+ }
+
+ if (len(This.getinverse())){
+ result = ListAppend(result, 'inverse="#This.getinverse()#"', " ") ;
+ }
+
+ if (len(This.getcascade())){
+ result = ListAppend(result, 'cascade="#This.getcascade()#"', " ") ;
+ }
+
+ if (len(This.getcollectiontype())){
+ result = ListAppend(result, 'collectiontype="#This.getcollectiontype()#"', " ") ;
+ }
+
+ if (len(This.getSingularName())){
+ result = ListAppend(result, 'SingularName="#This.getSingularName()#"', " ");
+ }
+
+ result = result & ' />';
+ return result;
+
+ }
+
+
+ public string function getCfScript(){
+ var result = "";
+
+ result = result & 'property';
+
+ if (len(This.getName())){
+ result = ListAppend(result, 'name="#This.getName()#"', " ") ;
+ }
+
+ if (len(This.getColumn())){
+ result = ListAppend(result, 'column="#This.getColumn()#"', " ") ;
+ }
+
+ if (len(This.getormtype())){
+ result = ListAppend(result, 'ormtype="#This.getormtype()#"', " ") ;
+ }
+
+ if (len(This.gettype())){
+ result = ListAppend(result, 'type="#This.gettype()#"', " ") ;
+ }
+
+ if (len(This.getFieldtype())){
+ result = ListAppend(result, 'fieldtype="#This.getFieldtype()#"', " ") ;
+ }
+
+ if (len(This.getGenerator())){
+ result = ListAppend(result, 'generator="#This.getGenerator()#"', " ") ;
+ }
+
+ if (len(This.getCFC())){
+ result = ListAppend(result, 'cfc="#This.getCFC()#"', " ") ;
+ }
+
+ if (len(This.getFkColumn())){
+ result = ListAppend(result, 'fkColumn="#This.getFkColumn()#"', " ") ;
+ }
+
+ if (len(This.getmissingRowIgnored())){
+ result = ListAppend(result, 'missingRowIgnored="#This.getmissingRowIgnored()#"', " ") ;
+ }
+
+ if (len(This.getinverse())){
+ result = ListAppend(result, 'inverse="#This.getinverse()#"', " ") ;
+ }
+
+ if (len(This.getcascade())){
+ result = ListAppend(result, 'cascade="#This.getcascade()#"', " ") ;
+ }
+
+ if (len(This.getcollectiontype())){
+ result = ListAppend(result, 'collectiontype="#This.getcollectiontype()#"', " ") ;
+ }
+
+ if (len(This.getSingularName())){
+ result = ListAppend(result, 'SingularName="#This.getSingularName()#"', " ");
+ }
+
+ result = result & ';';
+
+ return result;
+
+ }
+
+
+}
476 handlers/cfc/db/base.cfc
@@ -0,0 +1,476 @@
+<!---
+***********************************************************************************************************
+*
+* ADOBE CONFIDENTIAL
+* ___________________
+*
+* Copyright 2008 Adobe Systems Incorporated
+* All Rights Reserved.
+*
+* NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
+* terms of the Adobe license agreement accompanying it. If you have received this file from a
+* source other than Adobe, then your use, modification, or distribution of it requires the prior
+* written permission of Adobe.
+*************************************************************************************************************/
+--->
+
+<cfcomponent name="base" displayname="base" output="false" hint="component with generic methods used by all services">
+
+ <cfscript>
+
+ /**
+ * Set the name of the service tag to be invoked
+ * @output false
+ */
+ private void function setTagName(string tagName)
+ {
+ variables.tagName = tagName;
+ }
+
+
+ /**
+ * Get the name of the service tag
+ * @output false
+ */
+ private string function getTagName()
+ {
+ return variables.tagName;
+ }
+
+
+ /**
+ * Set service tag attributes.
+ * @output false
+ */
+ public void function setAttributes()
+ {
+ if(!structisempty(arguments))
+ {
+ structappend(variables,arguments,"yes");
+ }
+ }
+
+
+ /**
+ * Returns a struct with all/some of the service tag attribute values. If no attributes are specified, it returns a coldfusion with all service tag attribute values
+ * @output false
+ */
+ public struct function getAttributes(string attribs="")
+ {
+ var attributesstruct = {};
+ var i = 0;
+ arguments.attribs = trim(arguments.attribs) neq "" ? trim(arguments.attribs) : variables.tagAttributes;
+
+ for(i=1; i lte listlen(attribs); i++)
+ {
+ var attrib = trim(listgetat(attribs,i));
+ if(structkeyexists(variables,attrib))
+ {
+ attributesstruct[attrib] = variables[attrib];
+ }
+ }
+ return attributesstruct;
+ }
+
+
+ /**
+ * Removes a specific service tag attribute from CFC variables scope. Invoked by clearAttributes()
+ * @output false
+ */
+ private void function clearAttribute(struct tagAttributesStruct,string tagAttribute)
+ {
+ if(structkeyexists(tagAttributesStruct,tagAttribute))
+ {
+ structdelete(tagAttributesStruct,tagAttribute);
+ }
+ }
+
+
+ /**
+ * Removes all|some of the service tag attributes from CFC variables scope. Accepts a list of service tag attributes to remove. If no attributes are specified, all attributes are
+ * removed from CFC variables scope
+ * @output false
+ */
+ public void function clearAttributes(string tagAttributesToClear="")
+ {
+ var attributeslist = isdefined("arguments.tagAttributesToClear") and trim(arguments.tagAttributesToClear) neq "" ? arguments.tagAttributesToClear : variables.tagAttributes;
+ var i = 0;
+
+ for(i=1;i lte listlen(attributeslist); i++)
+ {
+ var attrib = trim(listgetat(attributeslist,i));
+ clearAttribute(variables,attrib);
+ }
+ }
+
+
+ /**
+ * Removes service tag attributes
+ * @output false
+ */
+ public void function clear()
+ {
+ clearAttributes();
+ clearParams();
+ }
+
+
+ /**
+ * Resets child tags by resetting the parameters array
+ * @output false
+ */
+ public void function clearParams()
+ {
+ if(isdefined("variables.parameters"))
+ {
+ variables.parameters = [];
+ }
+ }
+
+
+ /**
+ * Returns a struct with attributes set either using implicit setters | init() | setAttributes()
+ * @output false
+ */
+ private struct function getTagAttributes()
+ {
+ var tagAttributes = structnew();
+ var i = 0;
+
+ for(i=1; i lte listlen(variables.tagAttributes); i++)
+ {
+ var attrib = trim(listgetat(variables.tagAttributes,i));
+ if(structkeyexists(variables,attrib))
+ {
+ tagAttributes[attrib] = variables[attrib];
+ }
+ }
+ return tagAttributes;
+ }
+
+
+ /**
+ * Accepts a service tag name and returns the allowed tag attributes. Uses double-checked locking
+ * @output false
+ */
+ private string function getSupportedTagAttributes(string tagName)
+ {
+ //store all service tag attributes in Server scope for faster access.
+ if(not isdefined("server.coldfusion.serviceTagAttributes.#tagName#"))
+ {
+ lock scope="server" timeout="30" throwontimeout="yes" type="exclusive"
+ {
+ if(not isdefined("server.coldfusion.serviceTagAttributes.#tagName#"))
+ {
+ var webinf = getPageContext().getServletContext().getRealPath("/WEB-INF");
+ var sep = server.os.name contains "windows"? "\" : "/";
+ var cftldpath = webinf & sep & "cftags" & sep & "META-INF" & sep & "taglib.cftld";
+ var xpath = "/taglib/tag[name='#lcase(Right(tagName,len(tagName)-2))#']/attribute/name";
+ var cftagsXml = XmlParse(FileRead(cftldpath));
+ var tagAttributes = xmlsearch(cftagsXml,xpath);
+ var attributeslist = "";
+ var i = 0;
+ for(i=1;i lte arraylen(tagAttributes); i++)
+ {
+ attributeslist = listappend(attributeslist,trim(tagAttributes[i].xmltext));
+ }
+ server.coldfusion.serviceTagAttributes[tagName] = listsort(attributeslist,"textnocase","ASC");
+ }
+ }
+ }
+
+ //use a local variable for faster access
+ lock scope="server" timeout="30" throwontimeout="yes" type="readonly"
+ {
+ var attributeslist = server.coldfusion.serviceTagAttributes[tagName];
+ }
+
+ return attributeslist;
+ }
+
+ /**
+ * Add child tags like cfmailparam, cfmailpart etc
+ * @output false
+ */
+ public void function addParam()
+ {
+ if(!structisempty(arguments))
+ {
+ if(isdefined("variables.parameters"))
+ {
+ arrayappend(variables.parameters, arguments);
+ }
+ }
+ }
+
+
+ /**
+ * Validate against any incorrect attributes passed to the child tags. This is done by passing allowExtraAttributes=false
+ * @output false
+ */
+ private array function appendAllowExtraAttributes(array params)
+ {
+ var temp = [];
+ var nbrOfParams = arraylen(arguments.params);
+ var i = 0;
+
+ for(i=1; i lte nbrOfParams; i++)
+ {
+ var param = arguments.params[i];
+ if(isstruct(param))
+ {
+ structappend(param,{allowExtraAttributes=false});
+ arrayappend(temp,param);
+ }
+ }
+ return temp;
+ }
+
+ </cfscript>
+
+
+
+ <!---
+ The corresponding service tag to invoke.
+
+ Supported service tags are
+ cfhttp
+ cfftp
+ cfldap
+ cfpdf
+ cfmail
+ cfquery
+ cfstoredproc
+ --->
+
+ <cffunction name="invokeTag" access="private" output="true" returntype="any" hint="invokes the service tag">
+ <cfargument name="tagName" type="string" hint="Name of the service tag to invoke">
+ <cfargument name="tagAttributes" type="struct" hint="Attributes of the service tag that were set using either init() | implicit setters | setAttributes()">
+ <cfargument name="tagParams" type="struct" required="no" default="#{}#" hint="Struct containing child params/tags">
+
+ <cfset var params = structkeyexists(arguments.tagParams,"params") ? appendAllowExtraAttributes(arguments.tagParams["params"]) : []>
+ <cfset var tagresult = new result()>
+ <cfset arguments.tagAttributes = appendAllowExtraAttributes([arguments.tagAttributes])[1]>
+
+ <cfswitch expression="#tagName#">
+
+ <!--- http service --->
+ <cfcase value="CFHTTP">
+ <cfset var httpparam = "">
+ <cfhttp attributeCollection="#tagAttributes#">
+ <cfloop array="#params#" index="httpparam">
+ <cfhttpparam attributeCollection="#httpparam#">
+ </cfloop>
+ </cfhttp>
+ <!--- set query object and http prefix--->
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagresult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+ <cfset tagresult.setPrefix(cfhttp)>
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- ldap service --->
+ <cfcase value="CFLDAP">
+ <cfset tagAttributes.name ="results" />
+ <cfldap attributeCollection="#tagAttributes#" />
+
+ <!--- set query object and http prefix--->
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagresult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- dbinfo service --->
+ <cfcase value="CFDBINFO">
+ <cfset tagAttributes.name ="results" />
+ <cfdbinfo attributeCollection="#tagAttributes#" />
+
+ <!--- set query object and http prefix--->
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagresult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- imap service --->
+ <cfcase value="CFIMAP">
+ <cfset tagAttributes.name ="results" />
+ <cfimap attributeCollection="#tagAttributes#" />
+
+ <!--- set query object and http prefix--->
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagresult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- imap service --->
+ <cfcase value="CFPOP">
+ <cfset tagAttributes.name ="results" />
+ <cfpop attributeCollection="#tagAttributes#" />
+
+ <!--- set query object and http prefix--->
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagresult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- ftp service --->
+ <cfcase value="CFFTP">
+ <cfftp attributeCollection="#tagAttributes#">
+ <!--- set query object (for listdir action) and cfftp prefix --->
+ <cfif structkeyexists(tagAttributes,"name") and trim(tagAttributes["name"]) neq "">
+ <cfset tagResult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+ <cfset tagResult.setPrefix(cfftp)>
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- pdf service --->
+ <cfcase value="CFPDF">
+ <!--- If the "source" attribute contains any cfdocument or cfpdf variables, we need to pass a variable with that value instead of the value --->
+ <cfset var sourceVar = "">
+ <cfset var pdfparam = "">
+ <cfif structkeyexists(tagAttributes,"source") and not isSimpleValue(tagAttributes["source"])>
+ <cfset sourceVar = tagAttributes["source"]>
+ <cfset structappend(tagAttributes,{source="sourceVar"})>
+ </cfif>
+ <cfpdf attributeCollection="#tagAttributes#">
+ <cfif comparenocase(tagAttributes["action"],"merge") eq 0>
+ <cfif arraylen(params) gt 0>
+ <cfloop array="#params#" index="pdfparam">
+ <cfpdfparam attributeCollection="#pdfparam#">
+ </cfloop>
+ </cfif>
+ </cfif>
+ </cfpdf>
+ <!--- process name attribute for actions other than action="thumbnail | extractimage" --->
+ <cfif not listcontainsnocase("thumbnail,extractimage",tagAttributes["action"])>
+ <cfif structkeyexists(tagAttributes,"name") and tagAttributes["name"] neq "">
+ <cfset tagResult.setResult(StructFind(variables,tagAttributes["name"]))>
+ </cfif>
+ <cfelse>
+ <cfset tagResult.setResult("")>
+ </cfif>
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- mail service --->
+ <cfcase value="CFMAIL">
+ <cfset var mailbody = "">
+ <cfset var mailpartbody = "">
+ <cfset var mailparam = "">
+ <cfset var mailpart = "">
+ <cfset var parts = structkeyexists(tagParams,"parts") ? appendAllowExtraAttributes(tagParams["parts"]) : []>
+ <!--- if query attribute exists, pass a variable with query object instead of the query object --->
+ <cfif structkeyexists(tagAttributes,"query") and isquery(tagAttributes["query"])>
+ <cfset var queryVar = tagAttributes['query']>
+ <cfset structappend(tagAttributes,{query="queryVar"},"yes")>
+ </cfif>
+ <!--- Capture mail content into a local variable and delete body attribute --->
+ <cfif structkeyexists(tagAttributes,"body")>
+ <cfset var mailbody = tagAttributes["body"]>
+ <cfset structdelete(tagAttributes,"body")>
+ </cfif>
+ <!--- invoke the cfmail/cfmailparams/cfmailpart tags --->
+ <cfmail attributeCollection="#tagAttributes#">
+ #mailbody#
+ <cfloop array="#params#" index="mailparam">
+ <cfmailparam attributeCollection="#mailparam#">
+ </cfloop>
+ <cfloop array="#parts#" index="mailpart">
+ <!--- Capture mailpart content into a local variable and delete body attribute --->
+ <cfif structkeyexists(mailpart,"body")>
+ <cfset var mailpartbody = mailpart["body"]>
+ <cfset structdelete(mailpart,"body")>
+ </cfif>
+ <cfmailpart attributeCollection="#mailpart#">
+ #trim(mailpartbody)#
+ </cfmailpart>
+ </cfloop>
+ </cfmail>
+ <cfreturn tagResult>
+ </cfcase>
+
+ <!--- query service --->
+ <cfcase value="CFQUERY">
+ <cfset var sqlparams = structkeyexists(tagParams,"params") ? tagParams["params"] : []>
+ <cfset var sqlArray = structkeyexists(tagParams,"sqlArray") ? tagParams["sqlArray"] : []>
+ <cfset var sqlQuery = structkeyexists(tagParams,"sql") ? tagParams["sql"] : "">
+ <cfset var sqlType = structkeyexists(tagParams,"sqlType") ? tagParams["sqlType"] : "">
+ <cfset var i = 0>
+ <cfquery attributeCollection="#tagAttributes#">
+ <!--- if no queryparams exist, use query directly --->
+ <cfif arraylen(sqlParams) eq 0>
+ #PreserveSingleQuotes(sqlQuery)#
+ <cfelse>
+ #getPreserveSingleQuotes(sqlArray[1])#
+ <cfif sqlType neq "" and arraylen(sqlParams) gt 0>
+ <cfloop index="i" from="2" to="#ArrayLen(sqlArray)#">
+ <cfif (i-1) lte arraylen(sqlParams)>
+ <cfqueryparam attributeCollection="#sqlParams[i-1]#"/>
+ </cfif>
+ #getPreserveSingleQuotes(sqlArray[i])#
+ </cfloop>
+ </cfif>
+ </cfif>
+ </cfquery>
+ <!--- set resultset and query meta info --->
+ <cftry>
+ <cfset tagResult.setResult(StructFind(variables,tagAttributes['name']))>
+ <cfcatch type="any">
+ </cfcatch>
+ </cftry>
+ <cfset tagResult.setPrefix(StructFind(variables,tagAttributes['result']))>
+ <cfreturn tagResult>
+ </cfcase>
+
+
+ <!--- storedproc service --->
+ <cfcase value="CFSTOREDPROC">
+ <cfset var procresults = structkeyexists(tagParams,"procresults") ? appendAllowExtraAttributes(tagParams["procresults"]) : []>
+ <cfset var spResult = new storedprocResult()>
+ <cfset var procparam = "">
+ <cfset var procresult = "">
+ <cfstoredproc attributeCollection="#tagAttributes#">
+ <cfloop array="#params#" index="procparam">
+ <cfprocparam attributeCollection="#procparam#"/>
+ </cfloop>
+ <cfloop array="#procresults#" index="procresult">
+ <cfprocresult attributeCollection="#procresult#"/>
+ </cfloop>
+ </cfstoredproc>
+ <!--- process proc vars --->
+ <cfset var procvars = {}>
+ <cfloop array="#params#" index="procparam">
+ <cfif structkeyexists(procparam,"type") and listcontainsnocase("OUT,INOUT",procparam["type"])>
+ <cfif structkeyexists(procparam,"variable") and procparam["variable"] neq "">
+ <cfset procvars[procparam.variable] = StructFind(variables,procparam["variable"])>
+ </cfif>
+ </cfif>
+ </cfloop>
+ <!--- process proc resultsets --->
+ <cfset var procresultset = {}>
+ <cfloop array="#procresults#" index="procresult">
+ <cfset procresultset[procresult.name] = StructFind(variables,procresult["name"])>
+ </cfloop>
+ <!--- set inout and out variables, proc resultsets and the cfstoredproc prefix --->
+ <cfset spResult.setProcOutVariables(procvars)>
+ <cfset spResult.setProcResultSets(procresultset)>
+ <cfif structkeyexists(tagAttributes,"result") and tagAttributes["result"] neq "">
+ <cfset spResult.setPrefix(StructFind(variables,tagAttributes["result"]))>
+ <cfelse>
+ <cfset spResult.setPrefix(cfstoredproc)>
+ </cfif>
+ <cfreturn spResult>
+ </cfcase>
+ </cfswitch>
+ </cffunction>
+</cfcomponent>
23 handlers/cfc/db/column.cfc
@@ -0,0 +1,23 @@
+component accessors="true" extends="dbItem"
+{
+ property name="name";
+ property name="displayName";
+ property name="column";
+ property name="length";
+ property name="isForeignKey" type="boolean";
+ property name="isPrimaryKey" type="boolean";
+ property name="foreignKey";
+ property name="foreignKeyTable";
+ property name="ormType";
+ property name="dataType";
+ property name="uiType";
+
+ public string function toXML(){
+ return objectToXML("column");
+ }
+
+ public boolean function isColumnSameAsColumnName(){
+ return (CompareNoCase(This.getName(), This.getColumn()) eq 0);
+ }
+
+}
73 handlers/cfc/db/datasource.cfc
@@ -0,0 +1,73 @@
+component accessors="true" extends="dbItem"
+{
+ property name="name";
+ property name="displayName";
+ property name="engine";
+ property name="version";
+ property name="tables" type="table[]";
+ property name="tablesStruct" type="struct";
+
+ public function init(required string datasource){
+ variables.dbinfo = New dbinfo();
+ dbinfo.setDatasource(arguments.datasource);
+
+
+ This.setName(arguments.datasource);
+ This.setDisplayName(arguments.datasource);
+
+ populateTables();
+ populateDatasource();
+
+ return This;
+ }
+
+ private void function populateTables(){
+ var i = 0;
+ var tablesArray = ArrayNew(1);
+ var tablesStruct = StructNew();
+ dbinfo.setType("tables");
+ var tables = dbinfo.send().getResult();
+
+
+ var qoq = new Query();
+ var queryString = " SELECT *
+ FROM resultSet
+ WHERE table_type != 'SYSTEM TABLE'";
+ qoq.setAttributes(resultSet = tables);
+ qoq.SetDBType("query");
+ tables = qoq.execute(sql=queryString).getResult();
+
+
+ for (i=1; i <= tables.recordCount; i++){
+ var table = New table(tables.table_name[i], This.getName());
+
+ if (CompareNoCase(tables.table_type[i], "view") eq 0){
+ table.setIsView(true);
+ }
+ else{
+ table.setIsView(false);
+ }
+ arrayAppend(tablesArray, table);
+ tablesStruct[table.getName()] = table;
+ }
+ This.setTables(tablesArray);
+ This.setTablesStruct(tablesStruct);
+
+ }
+
+ public void function populateDatasource(){
+ dbinfo.setType("version");
+ var version = dbinfo.send().getResult();
+
+ This.setEngine(version.database_productname);
+ This.setVersion(version.database_version);
+
+ }
+
+
+ public string function toXML(){
+ return objectToXML("datasource");
+ }
+
+
+}
169 handlers/cfc/db/dbConfig.cfc
@@ -0,0 +1,169 @@
+component
+{
+ public function init(required string path){
+
+ variables.FS = createObject("java","java.lang.System").getProperty("file.separator");
+
+ if (CompareNoCase(right(arguments.path, 1),variables.FS) neq 0){
+ variables.path = arguments.path & variables.FS & "schema" & variables.FS;
+ }
+ else{
+ variables.path = arguments.path & ".schema" & variables.FS;
+ }
+ }
+
+ public void function writeConfig(required datasource datasource){
+ var tables = arguments.datasource.getTables();
+ var i = 0;
+ var j = 0;
+ var datasourcePath = variables.path & variables.FS & datasource.getName();
+
+ //Write XML to disk
+
+ conditionallyCreateDirectory(datasourcePath);
+ FileWrite(datasourcePath & variables.FS & "_datasource.xml", datasource.serialize());
+
+ for (i=1; i <= arraylen(tables); i++){
+ //Write XML to disk
+ var tableSchemaPath = datasourcePath & variables.FS & tables[i].getName();
+ conditionallyCreateDirectory(tableSchemaPath);
+ FileWrite(tableSchemaPath & variables.FS & "_table.xml", tables[i].serialize());
+
+ var columns = tables[i].getColumns();
+ for (j=1; j <= arraylen(columns); j++){
+ //Write XML to disk
+ FileWrite(tableSchemaPath & variables.FS & columns[j].getName() & ".xml", columns[j].serialize());
+ }
+ }
+
+ }
+
+ public datasource function overwriteConfig(required datasource datasource){
+ if (not directoryExists(variables.path)){
+ return arguments.datasource;
+ }
+
+
+ var i = 0;
+ var j = 0;
+ var checksums = getChecksumInfoFromDisk();
+ var newDataSource = duplicate(arguments.datasource);
+
+
+ //check datasource
+ var datasourceName = newDataSource.getName();
+ var DSCSPath = datasourceName;
+
+ var configCS = checksums[DSCSPath]['checksum'];
+ var dbCS = newDataSource.getChecksum();
+
+ if (CompareNoCase(configCS, dbCS) neq 0 ){
+ newDataSource = reWriteObject(newDataSource, checksums[DSCSPath]['filePath'], "datasource");
+ }
+
+ //check tables
+ var tableArray = ArrayNew(1);
+ var tableStruct = StructNew();
+ var tables = newDataSource.getTables();
+
+ for (i=1; i <= arraylen(tables); i++){
+ var table = tables[i];
+ var tableName = table.getName();
+ var tableCSPath = DSCSPath & "/" & tableName;
+ var configCS = checksums[tableCSPath]['checksum'];
+ var dbCS = table.getChecksum();
+
+ if (CompareNoCase(configCS, dbCS) neq 0 ){
+ var table = reWriteObject(table, checksums[tableCSPath]['filePath'], "table");
+ }
+
+ //check columns
+ var columnsArray = ArrayNew(1);
+ var columnsStruct = StructNew();
+ var columns = table.getColumns();
+
+
+
+ for (j=1; j <= arraylen(columns); j++){
+ var column = columns[j];
+ var columnName = column.getName();
+ var columnCSPath = DSCSPath & "/" & tableName & "/" & columnName;
+ var configCS = checksums[columnCSPath]['checksum'];
+ var dbCS = column.getChecksum();
+
+ if (CompareNoCase(configCS, dbCS) neq 0 ){
+ var column = reWriteObject(column, checksums[columnCSPath]['filePath'], "column");
+ }
+
+ ArrayAppend(columnsArray, column);
+ columnsStruct[columnName] = column;
+
+ }
+ table.setColumns(columnsArray);
+ table.setColumnsStruct(columnsStruct);
+
+ //add edited or unedited tables back to the datsource
+ ArrayAppend(tableArray, table);
+ tableStruct[tableName] = table;
+
+
+ }
+ newDataSource.setTables(tableArray);
+ newDataSource.setTablesStruct(tableStruct);
+
+
+ return newDataSource;
+ }
+
+ private any function reWriteObject(required any object, required string path, required string ObjectType){
+ var newObject = Duplicate(arguments.object);
+ var XML = XMLParse(FileRead(arguments.path));
+ var keys = StructKeyArray(XML[arguments.ObjectType]);
+ var i = 0;
+
+ for (i=1;i <= arraylen(keys); i++){
+ Evaluate("newObject.set#keys[i]#(XML[arguments.ObjectType][keys[i]]['XMLText'])");
+ }
+
+ return newObject;
+ }
+
+ private void function conditionallyCreateDirectory(required string path){
+ if(not directoryExists(path)){
+ DirectoryCreate(path);
+ }
+ }
+
+ private struct function getChecksumInfoFromDisk(){
+ var i = 0;
+ var dirs = directoryList(variables.path, true, "query");
+ var qoq = new Query();
+ var queryString = " SELECT directory, name
+ FROM resultSet
+ WHERE name like '%.xml'";
+ qoq.setAttributes(resultSet = dirs);
+ qoq.SetDBType("query");
+ dirs = qoq.execute(sql=queryString).getResult();
+
+ var returnStruct = StructNew();
+
+ for (i = 1; i <= dirs.recordCount; i++){
+ var checksumArrayPath = ReplaceNoCase(dirs.directory[i], variables.path, "", "all");
+
+
+ if ( compareNoCase(left(dirs.name[i], 1), "_")){
+ checksumArrayPath = checksumArrayPath & variables.FS & getToken(dirs.name[i], 1, ".");
+ }
+ var XMLConfigPath = dirs.directory[i] & variables.FS & dirs.name[i];
+
+ returnStruct[checksumArrayPath] = structNew();
+ returnStruct[checksumArrayPath]['checksum'] = Hash(FileRead(XMLConfigPath));
+ returnStruct[checksumArrayPath]['filePath'] = XMLConfigPath;
+
+ }
+
+ return returnStruct;
+ }
+
+
+}
81 handlers/cfc/db/dbItem.cfc
@@ -0,0 +1,81 @@
+component
+{
+
+ public string function serialize(){
+ var XML = toXML();
+ return XML;
+ }
+
+ public string function getCheckSum(){
+ return Hash(toXML());
+ }
+
+ public string function objectToXML(required string type){
+ var str = createObject("java", "java.lang.StringBuilder").init();
+ var NL = CreateObject("java", "java.lang.System").getProperty("line.separator");
+ var props = Duplicate(variables);
+ var i = 0;
+
+
+ StructDelete(props, "This");
+
+ StructDelete(props, "dbinfo");
+ StructDelete(props, "utils");
+ StructDelete(props, "mappings");
+
+ StructDelete(props, "columns");
+ StructDelete(props, "columnsStruct");
+
+ StructDelete(props, "tables");
+ StructDelete(props, "tablesStruct");
+
+ var keys = StructKeyArray(props);
+ ArraySort(keys, "textnocase");
+
+
+ str.append('<?xml version="1.0" encoding="iso-8859-1"?>');
+ str.append(NL);
+
+ str.append('<#arguments.type#>');
+ str.append(NL);
+
+ for (i=1; i <= ArrayLen(keys); i++){
+ if (not IsCustomFunction(props[keys[i]]) ){
+ str.append(' ');
+ str.append('<#keys[i]#>');
+ str.append('#props[keys[i]]#');
+ str.append('</#keys[i]#>');
+ str.append(NL);
+ }
+ }
+
+ str.append('</#arguments.type#>');
+ str.append(NL);
+
+ return str;
+ }
+
+ public string function capitalize(required string str){
+
+ var newstr = "";
+ var word = "";
+ var separator = "";
+ var wordArray = ListtoArray(arguments.str, " ");
+ var i = 0;
+
+ for (i=1; i <= ArrayLen(wordArray); i++){
+ newstr = newstr & separator & UCase(left(wordArray[i],1)) ;
+ if (len(wordArray[i]) gt 1){
+ newstr = newstr & LCase(right(wordArray[i],len(wordArray[i])-1));
+ }
+ separator = " ";
+ }
+
+
+ return newstr;
+
+
+
+ }
+
+}
80 handlers/cfc/db/dbinfo.cfc
@@ -0,0 +1,80 @@
+/***********************************************************************************************************
+*
+* ADOBE CONFIDENTIAL
+* ___________________
+*
+* Copyright 2008 Adobe Systems Incorporated
+* All Rights Reserved.
+*
+* NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
+* terms of the Adobe license agreement accompanying it. If you have received this file from a
+* source other than Adobe, then your use, modification, or distribution of it requires the prior
+* written permission of Adobe.
+*************************************************************************************************************/
+
+/**
+ * DBInfo Service that returns metadata info about targeted database.
+ * @name dbinfo
+ * @displayname ColdFusion DBInfo Service
+ * @output false
+ * @accessors true
+ */
+component extends="base"
+{
+ property string datasource;
+ property string username;
+ property string password;
+ property string dbname;
+ property string type;
+ property string table;
+ property string pattern;
+
+ //service tag to invoke
+ variables.tagName = "CFDBINFO";
+
+
+ //list of valid cfhttp tag attributes
+ variables.tagAttributes = getSupportedTagAttributes(getTagName());
+
+
+ variables.attributes = "";
+ /**
+ * Initialization routine. Returns an instance of this component
+ * @output false
+ */
+ public dbinfo function init()
+ {
+
+ if(!structisempty(arguments))
+ {
+ structappend(variables,arguments,"yes");
+ }
+ return this;
+ }
+
+ /**
+ * Invoke the dbinfo tag to provide the DBINFO service in cfscript
+ * @output true
+ */
+ public result function send()
+ {
+
+ //store tag attributes to be passed to the service tag in a local variable
+ var tagAttributes = duplicate(getTagAttributes());
+
+ //attributes passed to service tag action like send() override existing attributes and are discarded after the action
+ if(!structisempty(arguments))
+ {
+ structappend(tagAttributes,arguments,"yes");
+ }
+
+ //if a result attribute is specified, we ignore it so that we can always return the result struct
+ if(structkeyexists(tagAttributes,"result"))
+ {
+ structdelete(tagAttributes, "result");
+ }
+
+ //invoke the ldap tag to perform the http service
+ return super.invokeTag(getTagName(),tagAttributes);
+ }
+}
67 handlers/cfc/db/mappings.cfc
@@ -0,0 +1,67 @@
+component
+{
+
+ public function init(){
+ variables.datatypes = {};
+
+ datatypes['int']['ormType'] = "integer";
+ datatypes['integer']['ormType'] = "integer";
+ datatypes['INT UNSIGNED']['ormType'] = "integer";
+ datatypes['smallint']['ormType'] = "short";
+ datatypes['number']['ormType'] = "big_decimal";
+ datatypes['decimal']['ormType'] = "long";
+
+ datatypes['varchar']['ormType'] = "string";
+ datatypes['varchar2']['ormType'] = "string";
+ datatypes['char']['ormType'] = "character";
+
+ datatypes['boolean']['ormType'] = "boolean";
+ datatypes['yes_no']['ormType'] = "yes_no";
+ datatypes['true_false']['ormType'] = "true_false";
+
+ datatypes['date']['ormType'] = "date";
+ datatypes['time']['ormType'] = "time";
+ datatypes['timestamp']['ormType'] = "timestamp";
+ datatypes['datetime']['ormType'] = "timestamp";
+
+ datatypes['clob']['ormType'] = "clob";
+ datatypes['blob']['ormType'] = "blob";
+
+ datatypes['int']['uiType'] = "string";
+ datatypes['integer']['uiType'] = "string";
+ datatypes['INT UNSIGNED']['uiType'] = "string";
+ datatypes['smallint']['uiType'] = "string";
+ datatypes['number']['uiType'] = "string";
+ datatypes['decimal']['uiType'] = "string";
+
+ datatypes['varchar']['uiType'] = "string";
+ datatypes['varchar2']['uiType'] = "string";
+ datatypes['char']['uiType'] = "string";
+
+ datatypes['boolean']['uiType'] = "boolean";
+ datatypes['yes_no']['uiType'] = "boolean";
+ datatypes['true_false']['uiType'] = "boolean";
+
+ datatypes['date']['uiType'] = "date";
+ datatypes['time']['uiType'] = "time";
+ datatypes['timestamp']['uiType'] = "datetime";
+ datatypes['datetime']['uiType'] = "datetime";
+
+ datatypes['clob']['uiType'] = "clob";
+ datatypes['blob']['uiType'] = "blob";
+
+
+
+ return This;
+ }
+
+ public string function getOrmType(required string datatype){
+ return datatypes[arguments.datatype]['ormType'];
+ }
+
+ public string function getUIType(required string datatype){
+ return datatypes[arguments.datatype]['UIType'];
+ }
+
+
+}
89 handlers/cfc/db/table.cfc
@@ -0,0 +1,89 @@
+component accessors="true" extends="dbItem"
+{
+ property name="name";
+ property name="displayName";
+ property name="entityName";
+ property name="identity";
+ property name="isReferencedAsFK" type="boolean";
+ property name="isJoinTable" type="boolean";
+ property name="softDelete" type="boolean";
+ property name="hasJoinTable" type="boolean";
+ property name="hasForeignKeys" type="boolean";
+ property name="isView" type="boolean";
+ property name="columns" type="column[]";
+ property name="columnsStruct" type="struct";
+
+
+ public function init(required string name, required string datasource){
+ variables.mappings = New mappings();
+ variables.dbinfo = New dbinfo();
+ dbinfo.setDatasource(arguments.datasource);
+ dbinfo.setTable(arguments.name);
+
+ setName(arguments.name);
+ setDisplayName(capitalize(arguments.name));
+ setEntityName(Lcase(arguments.name));
+
+ populateTable();
+
+ populateColumns();
+
+
+ return This;
+ }
+
+ public array function getArray(){
+ return columns;
+ }
+
+ private void function populateTable(){
+ dbinfo.setType("foreignkeys");
+ var foreignkeys = dbinfo.send().getResult();
+
+ This.setHasForeignKeys(foreignKeys.recordCount > 0 );
+
+ }
+
+ private void function populateColumns(){
+ dbinfo.setType("columns");
+
+ var columns = dbinfo.send().getResult();
+ var i = 0;
+ var columnArray = arrayNew(1);
+ var columnStruct = structNew();
+
+ for (i=1; i <= columns.recordCount; i++){
+ var column = New column();
+ column.setName(LCase(columns.column_name[i]));
+ column.setDisplayName(capitalize(columns.column_name[i]));
+ column.setColumn(columns.column_name[i]);
+ column.setOrmType(mappings.getOrmType(columns.type_name[i]));
+ column.setUIType(mappings.getUIType(columns.type_name[i]));
+ column.setDataType(columns.type_name[i]);
+ column.setisForeignKey(columns.is_ForeignKey[i]);
+ column.setisPrimaryKey(columns.is_PrimaryKey[i]);
+ column.setForeignKey(columns.referenced_primarykey[i]);
+ column.setForeignKeyTable(columns.referenced_primarykey_table[i]);
+ column.setLength(columns.column_size[i]);
+
+ columnArray[columns.ordinal_position[i]] = column;
+ columnStruct[column.getName()] = column;
+
+ if (column.getisPrimaryKey()){
+ this.setIdentity(column.getName());
+ }
+
+ }
+ This.setColumns(columnArray);
+ This.setColumnsStruct(columnStruct);
+ }
+
+ public string function toXML(){
+ return objectToXML("table");
+ }
+
+ public boolean function isEntitySameAsTableName(){
+ return (CompareNoCase(This.getName(), This.getEntityName()) eq 0);
+ }
+
+}
482 handlers/generators/trorm/generator.cfc
@@ -0,0 +1,482 @@
+component{
+
+ public generator function init(){
+ variables.lineBreak = createObject("java", "java.lang.System").getProperty("line.separator");
+ return This;
+ }
+
+ public any function createORMCFC(required any table, required string path){
+ var i = 0;
+ var fileLocation = path;
+
+ var cfc = New apptacular.handlers.cfc.code.cfc();
+ cfc.setName(table.getEntityName());
+ cfc.setFileLocation(fileLocation);
+ cfc.setPersistent(true);
+
+ if (not table.isEntitySameAsTableName()){
+ cfc.setTable(table.getName());
+ cfc.setEntityname(table.getEntityName());
+ }
+
+ var columns = table.getColumns();
+
+ for (i=1; i <= ArrayLen(columns); i++){
+ column = columns[i];
+
+
+ property = New apptacular.handlers.cfc.code.property();
+ property.setName(column.getName());
+ property.setOrmType(column.getOrmType());
+
+ if (not column.isColumnSameAsColumnName()){
+ property.setColumn(column.getColumn());
+ }
+
+ if (column.getLength() gt 0){
+ property.setLength(column.getLength());
+ }
+
+ if (column.getIsPrimaryKey()){
+ property.setFieldtype('id');
+ property.setGenerator('increment');
+ }
+ /*else if (column.isForeignKey()){
+ property.setName(tableData.columns.referenced_primarykey_table[i]);
+ property.setFieldtype('many-to-one');
+ property.setFkcolumn(tableData.columns.referenced_primarykey[i]);
+ property.setCFC(tableData.columns.referenced_primarykey_table[i]);
+ property.setInverse(true);
+ property.SetmissingRowIgnored(true);
+ }*/
+
+ cfc.AddProperty(property);
+ }
+
+ /*for (i=1; i lte tableData.foreignkeys.recordCount; i++){
+ property = New property();
+ property.setName(tableData.foreignkeys.fktable_name[i]);
+ property.setFieldtype('one-to-many');
+ property.setFkcolumn(tableData.foreignkeys.fkcolumn_name[i]);
+ property.setCFC(tableData.foreignkeys.fktable_name[i]);
+ property.setCascade("all-delete-orphan");
+ cfc.AddProperty(property);
+
+ }*/
+
+ var func= New apptacular.handlers.cfc.code.function();
+ func.setName('nullifyZeroID');
+ func.setAccess("public");
+ func.setReturnType('void');
+ func.AddOperation(' <cfif getIDValue() eq 0>');
+ func.AddOperation(' <cfset variables[getIDName()] = JavaCast("Null", "") />');
+ func.AddOperation(' </cfif>');
+ func.AddOperationScript(' if (getIDValue() eq 0){');
+ func.AddOperationScript(' variables[getIDName()] = JavaCast("Null", "");');
+ func.AddOperationScript(' }');
+ cfc.addFunction(func);
+
+
+ return cfc;
+ }
+
+ public any function createAppCFC(required any datasource, required string path){
+
+ var dbname = arguments.datasource.getName();
+ var fileLocation = arguments.path;
+
+ var appCFC = New apptacular.handlers.cfc.code.applicationCFC();
+ appCFC.setName('Application') ;
+ appCFC.setFileLocation(fileLocation) ;
+ appCFC.addApplicationProperty('name', dbname) ;
+ appCFC.addApplicationProperty('ormenabled', true) ;
+ appCFC.addApplicationProperty('datasource', dbname) ;
+ appCFC.addApplicationProperty("customTagPaths", "ExpandPath('customtags/')", false) ;
+
+
+
+ var func= New apptacular.handlers.cfc.code.function();
+ func.setName('onRequestStart');
+ func.setAccess("public");
+ func.setReturnType("boolean");
+
+ func.AddOperation(' <cfif structKeyExists(url, "reset_app")>');
+ func.AddOperation(' <cfset ApplicationStop() />');
+ func.AddOperation(' <cfset location(cgi.script_name, false) />');
+ func.AddOperation(' </cfif>');
+ func.AddOperationScript(' if (structKeyExists(url, "reset_app")){');
+ func.AddOperationScript(' ApplicationStop();');
+ func.AddOperationScript(' location(cgi.script_name, false);');
+ func.AddOperationScript(' }');
+
+
+ func.setReturnResult('true');
+ appCFC.addFunction(func);
+
+
+
+ return appCFC ;
+ }
+
+ public any function createViewListCustomTag(required any table, required string path){
+ var i = 0;
+ var fileLocation = path;
+ var fileName = table.getEntityName() & "List";
+ var identity = table.getIdentity();
+
+ var ct = New apptacular.handlers.cfc.code.customTag(fileName, fileLocation);
+ ct.addAttribute(table.getEntityName() & "Array", "array", true);
+
+ ct.AppendBody('<cfset message = attributes.message /> ');
+ ct.AppendBody('<cfif CompareNoCase(message, "deleted") eq 0>');
+ ct.AppendBody(' <p class="alert">Record deleted</p>');
+ ct.AppendBody('<cfelse>');
+ ct.AppendBody(' <p></p>');
+ ct.AppendBody('</cfif>');
+ ct.AppendBody(' <p><a href="?method=edit">New</a></p>');
+ ct.AppendBody('<table>');
+ ct.AppendBody(' <thead>');
+ ct.AppendBody(' <tr>');
+
+ var columns = table.getColumns();
+
+ for (i = 1; i <= ArrayLen(columns); i++){
+ if (not columns[i].getIsForeignKey()){
+ ct.AppendBody(' <th>#columns[i].getDisplayName()#</th>');
+ }
+ }
+ ct.AppendBody(' </tr>');
+ ct.AppendBody(' </thead>');
+
+ ct.AppendBody(' <tbody>');
+ ct.AppendBody(' <cfoutput>');
+ ct.AppendBody(' <cfloop array="##attributes.#table.getEntityName()#Array##" index="#table.getEntityName()#">');
+
+ ct.AppendBody(' <tr>');
+
+ for (i = 1; i <= ArrayLen(columns); i++){
+ if (not columns[i].getIsForeignKey()){
+ ct.AppendBody(' <td>###table.getEntityName()#.get#columns[i].getName()#()##</td>');
+ }
+ }
+
+ ct.AppendBody(' <td><a href="?method=read&#identity#=###table.getEntityName()#.get#identity#()##">Read</a></td>');
+ ct.AppendBody(' <td><a href="?method=edit&#identity#=###table.getEntityName()#.get#identity#()##">Edit</a></td>');
+ ct.AppendBody(' <td><a href="?method=delete_process&#identity#=###table.getEntityName()#.get#identity#()##" onclick="if (confirm(''Are you sure?'')) { return true}; return false"">Delete</a></td>');
+ ct.AppendBody(' </tr>');
+ ct.AppendBody(' </cfloop>');
+ ct.AppendBody(' </cfoutput>');
+ ct.AppendBody(' </tbody>');
+
+
+ ct.AppendBody('</table>');
+
+ return ct;
+ }
+
+ public any function createViewReadCustomTag(required any table, required string path){
+ var i = 0;
+ var fileLocation = path;
+ var fileName = table.getEntityName() & "Read";
+
+ var ct = New apptacular.handlers.cfc.code.customTag(fileName, fileLocation);
+ var EntityName = table.getEntityName();
+ var columns = table.getColumns();
+
+ ct.addAttribute(EntityName, 'any', true);
+ ct.AppendBody('<cfset #EntityName# = attributes.#EntityName# /> ');
+ ct.AppendBody('<table>');
+ ct.AppendBody(' <tbody>');
+ ct.AppendBody(' <cfoutput>');
+
+ for (i = 1; i <= ArrayLen(columns); i++){
+ column = columns[i];
+ if (not column.GetIsForeignKey()){
+ ct.AppendBody(' <tr>');
+ ct.AppendBody(' <th>#column.getName()#</th>');
+ ct.AppendBody(' <td>###EntityName#.get#column.getName()#()##</td>');
+ ct.AppendBody(' </tr>');
+ }
+ }
+
+ ct.AppendBody(' </cfoutput>');
+ ct.AppendBody(' </tbody>');
+ ct.AppendBody('</table>');
+
+ return ct;
+ }
+
+ public any function createViewEditCustomTag(required any table, required string path){
+ var i = 0;
+ var fileLocation = path;
+ var fileName = table.getEntityName() & "Edit";
+
+ var ct = New apptacular.handlers.cfc.code.customTag(fileName, fileLocation);
+ var EntityName = table.getEntityName();
+ var columns = table.getColumns();
+ var identity = table.getIdentity();
+
+
+ ct.addAttribute(EntityName, 'any', true);
+ ct.addAttribute('message', 'string', false, "");
+ ct.AppendBody('<cfset #EntityName# = attributes.#EntityName# /> ');
+ ct.AppendBody('<cfset message = attributes.message /> ');
+ ct.AppendBody('<cfif CompareNoCase(message, "updated") eq 0>');
+ ct.AppendBody(' <p class="alert">Records updated</p>');
+ ct.AppendBody('<cfelse>');
+ ct.AppendBody(' <p></p>');
+ ct.AppendBody('</cfif>');
+ ct.AppendBody('<cfform action="?method=edit_process" method="post" format="html">');
+ ct.AppendBody(' <cfoutput>');
+ ct.AppendBody(' <table>');
+ ct.AppendBody(' <tbody>');
+
+
+
+
+ for (i = 1; i <= ArrayLen(columns); i++){
+ column = columns[i];
+ if (not column.GetIsForeignKey()){
+
+ columnName = column.getName();
+
+ if (column.getIsPrimaryKey()){
+ ct.AppendBody(' <input name="#columnName#" type="hidden" value="###EntityName#.get#columnName#()##" />');
+ }
+ else{
+ uitype = column.getUIType();
+
+ ct.AppendBody(' <tr>');
+
+ //Create different UI's depending on data type.
+ if (compareNoCase(uitype, "date") eq 0){
+ ct.AppendBody(' <th><label for="#columnName#">#columnName#:</label></th>');
+ ct.AppendBody(' <td><cfinput name="#columnName#" type="datefield" id="#columnName#" value="##DateFormat(#EntityName#.get#columnName#(),''mm/dd/yyyy'')##" /></td>');
+ }
+ else{
+ ct.AppendBody(' <th><label for="#columnName#">#columnName#:</label></th>');
+ ct.AppendBody(' <td><input name="#columnName#" type="text" id="#columnName#" value="###EntityName#.get#columnName#()##" /></td>');
+ }
+
+ ct.AppendBody(' </tr>');
+ }
+ }
+ }
+ ct.AppendBody(' <tr>');
+ ct.AppendBody(' <th />');
+ ct.AppendBody(' <td><input name="save" type="submit" value="Save" /></td>');
+ ct.AppendBody(' </tr>');
+
+ ct.AppendBody(' </cfoutput>');