IPTC data in coldfusion 9 - coldfusion

I am using coldfusion's imageGetIPTCMetadata() function to get the iptc keywords.
I used Photomechanics to insert some keywords in a hierarchical fashion like this
Personnel | Appointments | Assistant Chief of General Staff (ACGS), Personnel | Ranks | Royal Marine | Colour Sergeant (CSgt), Personnel | Ranks | Royal Navy | Chief Petty Officer (CPO), Personnel|Ranks|Army|Field Marshall (Fd Marshall) (FM)
But after I call the method in my CFC I get this -
How can I get the keywords with a delimeter or something so that I can reuse them in my code.

If I understand your question correctly, you can use one of the List functions like ListGetAt to get the keywords with a delimiter. Or if you prefer working with arrays you can use the ListToArray function keywordsArray = ListToArray(data.Keywords,"|")
<cfscript>
data = ImageGetIPTCMetadata(myImage);
for( i=1; i LTE ListLen(data.Keywords,"|"); i++ )
{
WriteOutput( Trim( ListGetAt(data.Keywords, i, "|") ) & "<br />" );
}
</cfscript>

I use CFX_OpenImage to read and write IPTC_ data in .jpg files in CF8 thru CF11. I also use this for image resize and rotation.
More CFX_OPENIMAGE INFO go to http://www.kolumbus.fi/jukka.manner/cfx_openimage/
It GraphicsMagick 1.3.17.
GraphicsMagick (www.graphicsmagick.org) maintains a stable release branch, maintains a detailed Change Log, and maintains a stable source repository with complete version history so that changes are controlled, and changes between releases are accurately described. GraphicsMagick provides continued support for a release branch.
More INSTALLATION INFO:
Note: If you are installing 64bit version of the tag, please download and install Microsoft Visual C++ 2010 Redistributable Package (x64) from Microsoft (http://www.microsoft.com/download/en/details.aspx?id=14632). The x64 version has been compiled and written in Visual Studio 2010.
CFX_OPENIMAGE installation steps common to both versions:
Create an environment variable Since GraphicsMagick needs read configuration files (*.mgk files), we need to tell the tag where those files are located. In order to do that, a system or cold fusion runtime user specific environment variable must be set. The name of this variable is CFX_OPENIMAGE_FULLPATH.
CFX_OPENIMAGE_FULLPATH environment variable should contain full pathname which points to a directory where all mgk-files and cfx_openimage.ini file are kept. A default value for this is “c:\cfx_openimage\”. Notice that the last “\” character is needed too.
You may install the actual dll where ever you like, it’s up to you to register is anyway via CF admin page. For keeping the security settings for all the files equal, it is recommended to keep cfx_openimage.dll in the same directory that the *.mgk and cfx_openimage.ini directory.

I found the solution here:
<cfparam name="URL.source" default="xmp-asset.jpg">
<cffile action="readbinary" file="#ExpandPath(URL.source)#" variable="data">
<!-- encode the binary data to hex -->
<cfset hex_data = BinaryEncode(data,"hex") />
<!-- string indicating beginning of packet '<x:xmpmeta' -->
<cfset xmp_string_begin = "3C783A786D706D657461" />
<!-- string indicating end of packet '</x:xmpmeta>' -->
<cfset xmp_string_end = "3C2F783A786D706D6574613E" />
<!-- find the starting index in the hex string -->
<cfset idx_start = FindNoCase(xmp_string_begin,hex_data) />
<!-- find the ending index in the hex string -->
<cfset idx_end = FindNoCase(xmp_string_end,hex_data,idx_start) + Len(xmp_string_end) />
<!-- using the start and end indices, extract the xmp packet -->
<cfset xmp_hex = Mid(hex_data,idx_start,Evaluate(idx_end-idx_start)) />
<!-- convert the hex to readable characters -->
<cfset xmp_string = ToString(BinaryDecode(xmp_hex,"hex")) />
<!-- parse the xml string to and xml structure -->
<cfset xmp_xml = XmlParse(xmp_string) />
<cfcontent type="text/xml">
<cfoutput>#xmp_string#</cfoutput>
Now I can get the entire XMP xml and do all I want to do with the data there.

Related

VS Code, ColdFusion, comment shortcut produces wrong comment

I write ColdFusion in VS code and have KamasamaK's CF extension installed. When I am inside a .cfc file and when I hit shortcut key - Ctrl-/ - it comments out code in a wrong fassion, like so:
// <cfset cfc = "wrong comment format" />
Now, I already followed instructions in this answer and have this written inside of my
C:\Users\<username>\.vscode\extensions\kamasamak.vscode-cfml-0.5.3\language-configuration.json file:
"comments": {
"lineComment": "<!--- --->",
"blockComment": [ "<!--- ", " --->" ]
}
and when I hit shortcut key inside of my .cfm file it works great:
<!--- <cfset cfm = "it works in cfm file" /> --->
but for some reason it does not work in .cfc file.
Additional information:
My .cfc file is recognized as ColdFusion file (I see CFML written in the bottom right corner of the VS Code).
When I close and reopen VS Code I see notification in the bottom right corner "Caching components". While this caching in progress commenting does work correctly and I was able to comment code out correctly like so:
<!--- // <cfset cfc = "wrong comment format" /> --->
however, after caching is done it is back to commenting out code in the wrong fashion, like so:
// <!--- // <cfset cfc = "wrong comment format" /> --->
I tested it with every single other extension disabled.
Questions:
Anybody knows what could be wrong?
Could this be a bug in the extension itself?
Edit 1.
Yesterday I left this comment:
[...] I created basic component, 3 lines of code, and formatting worked! Thank you. Need to analyze my code now.
However, this morning I tried to create the exact same basic .cfc again but this time it did not work, unlike yesterday:
<component>
// <cfset a = "a" />
</component>
Not sure what is going on, but since it works while "Caching components" pop-up is running I think the answer lies somewhere there.
Edit 2.
I just tried to create basic component for the 3rd time to test comment feature again. Immediately after I finished typing out this code
<component>
<cfset a = "a" />
</component>
I hit comment shortcut key and commenting worked:
<component>
<!--- <cfset a = "a" /> --->
</component>
However, after about 1 second later or less, I hit shortcut key again and it again commented out code wrongly:
<component>
// <!--- <cfset a = "a" /> --->
</component>
I suspect that this new file got cached and correct .cfc commenting stopped working. So, it looks like there might be a bug in extension where cached components comment code in wrong fashion.
Edit 3.
I created this issue in GitHub based on my best understanding of the problem.

Looking for ColdFusion or Java street Address Parser [duplicate]

This question already has answers here:
How to parse freeform street/postal address out of text, and into components
(6 answers)
Closed 6 years ago.
I have found C# & Perl libraries that look good for Street Address parsing.
https://usaddress.codeplex.com/
http://search.cpan.org/~timb/Geo-StreetAddress-US-1.04/US.pm
Is there ColdFusion code -or- something that can be run from CF to do the same job?
If you need to parse & validate, you could use the SmartyStreets.com LiveAddress API. A ColdFusion CFC from 2011 is available that will connect, validate the address and return a JSON struct of a lot more location-based data for that address.
http://smartystreets.riaforge.org/
SmartyStreets also has javascript Address Autocomplete API so you can include it on any web-based form to ensure that incoming addresses are validated before you ever save it to your back-end database (including the identification & full separation of address parts).
Check out the features... it's more robust than any offline library:
https://smartystreets.com/features
The only downside is that is a paid service and you can only process 250 addresses for free each month:
https://smartystreets.com/free-address-verification
In addition to using the CFC, I use separate wrapper for SmartyStreet's "Smartylist" (a command-line tool). It basically uploads a CSV file and returns the same file with additional columns with the original submitted data.
https://smartystreets.com/docs/smartylist/command-line-tool
"Address Cleaner" is a ColdFusion ColdBox plugin that uses JGeoCoder.
https://github.com/angelseye/Address-Cleaner
http://jgeocoder.sourceforge.net/
Once the JAR file is installed, you can call the CFC using the following methods and it will return matches to the following keys CITY, LINE2, NUMBER, PREDIR, STATE, STREET, TYPE, ZIP. (NOTE: You'll need to modify the CFC if you aren't using the Coldbox framework.):
clearAddressString = addressCleaner.cleanAddress(FullAddressString);
addressStruct = addressCleaner.getAddressStruct(FullAddressString);
Another java option could be used with ColdFusion is "International Address Parser". (Multiple country packs are available, but no prices are listed.)
http://www.address-parser.net/product-java.php
http://address-parser.net/documentation/documentation.php#java
I have written a preliminary parser of address and zip. Here is a snippet to get you started (https://bitbucket.org/snippets/mrrobwad/KR9Mg):
<cfset loc.SOURCETEXT = "123 ABC Street, Any Town, MA 12345">
<cfset loc.array_zip_code = REMatchNoCase("[-:.\s][0-9]{5}([-][0-9]{4})?",loc.SOURCETEXT)>
<cfif ArrayLen(loc.array_zip_code) GT 0>
<cfset loc.ZIP = REReplaceNoCase(loc.array_zip_code[1],"[-:.\s]","","All")>
<b>ZIP:</b>
<cfdump var="#loc.ZIP#">
</cfif>
<br><br>
<cfset loc.street_types = "STREET|ST|DRIVE|DR|AVENUE|AVE|ROAD|RD|LOOP|COURT|CT|CIR|CIRCLE|LANE|LN|BOULEVARD|BLVD">
<cfset loc.array_street_type = REMatchNoCase("(\s)+(#loc.street_types#)[^a-zA-Z]",loc.SOURCETEXT)>
<cfif ArrayLen(loc.array_street_type) GT 0>
<cfset loc.street_address_trimmed = Left(loc.SOURCETEXT,FindNoCase(loc.array_street_type[1],loc.SOURCETEXT)+Len(loc.array_street_type[1]))>
<cfset loc.array_street_address = REMatchNoCase("(\d{1,5})+(\s([a-zA-Z])+)+",loc.street_address_trimmed)>
<cfif ArrayLen(loc.array_street_address) GT 0>
<cfset loc.ADDRESS = loc.array_street_address[1]>
<b>ADDRESS:</b>
<cfdump var="#loc.ADDRESS#">
</cfif>
</cfif>

Replace url in all hrefs inside body tags

I am using cfhttp to get a website . I want to replace all the links inside the body tags. Importantly I don't want to mess up the stylesheets etc in the head.
I want to do the following:
In the external web page body we may find a link:
External Link
I want to replace it with the following:
External Link
Its easy enough using Replace() but then I also replace all the linked stylesheets etc. I just want to edit the href's of clickable links.
I've modified an HTML document's DOM to add tracking parameters to links in outbound email messages using the jsoup library. (jsoup is an open source Java HTML Parser and can be download at http://jsoup.org/.) You'll note that it uses jQuery-like select methods, but all manipulations are performed on the server-side (I've also used it for removing ads from CFHTTTP-fetched HTML.)
Here's a quick sample of working ColdFusion code that will do exactly what you want on the server-side:
<CFSET TheHTML = CFHTTP.FileContent>
<CFSET jsoup = CreateObject("java", "org.jsoup.Jsoup")>
<CFSET TempHTML = jsoup.parse(TheHTML)>
<CFLOOP ARRAY="#TempHTML.select('a')#" INDEX="ThisLink">
<CFSET TheLink = thisLink.attr("href").toString()>
<CFSET TheHTML = replace(TheHTML, TheLink, "http://mywebsite.com/?u=" & URLEncodedFormat(TheLink))>
</CFLOOP>

cffile creating blank lines when storing a table

I've got a cfsavecontent tag that saves a table. Later I use cffile to write the saved content to a file. When I look at that file, I see that there many blank lines inserted after <td> tags in the table; and few blank lines inserted after </tr> tags. (Although it doesn't do that where the code says <tr><td> </td></tr> all on one line.)
Presently I have a file which contains two of those tables. The tables are generated in a loop, and the output file is created with cffile append. This file has 915 lines in it of which maybe 30 are non-blank. All my subsequent code works correctly, but this is just test data. In the real world I could have 1000 or more tables, and I am concerned about the file size.
The code:
<cfset head1 = 'from = "moxware" '>
<cfset head2 = 'to = "#hrep.PersonEmail#" '>
<cfset head3 = 'replyto = "#replyto#" '>
<cfset head4 = 'subject = "#subject#" '>
<cfset head5 = 'type = "html" '>
<cfsavecontent variable = "abc">
<cfoutput>
#head1#
#head2#
#head3#
#head4#
#head5# >
#xyz#
</cfoutput>
</cfsavecontent>
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfmail"
mode = "777" >
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "#abc#"
mode = "777">
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "</cfmail>"
mode = "777" >
Re the xyz, I am reading it in from a file:
<cffile action = "read"
file = "/var/www/reports/moxrep/#reportname#.cfm"
variable = "xyz">
and the file looks like this:
<link rel="stylesheet" href="sample.css">
<link rel="stylesheet" type = "text/css" href ="betty.css"/>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font- family:georgia,serif">Dear Customer,</span></span></p>
We were so pleased that you have signed up for one of our programs. Apparently you live in the city of {{1. Additionally we observe that your were referred to us by {{2. Below please find a listing of what you signed up for.</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font- family:georgia,serif">{{r</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">Sincerely Yours,</span></span></p>
<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">John Jones<br />
President<br />
XYZ Corporation</span></span></p>
The file was created by a code generator, not me, so it's a bit cumbersome. Later in the code I replace everything starting with {{ ; in particular {{r gets replaced with a table, and that is where the additional space is coming from.
The append itself is not inserting any extra lines.
Does anyone know what is causing these extra blank lines in the file; and how to get rid of them?
Betty, typically you need to do this carefully if you want to avoid whitespace. In particular the use of cfoutput with a query will generate lines. So this code:
<table>
<cfoutput query="myquery">
<tr><td>#col1#</td><td>#col2#</td></tr>
</cfoutput>
</table>
will produce extra lines... but if you do this:
<cfsetting enablecfoutputonly="yes">
<cfoutput><table></cfoutput>
<cfloop query="myquery"><cfoutput><tr><td>#col1#</td><td>#col2#</td></tr></cfoutput></cfloop>
<cfoutput></table></cfoutput>
You would carefully control exactly what is allowed to be appended to the buffer. enableoutputonly does exactly what it says... it does not allow anything to "go to the buffer" unless it is enclosed in cfoutputs.
Hope this helps. As cameron says you should paste code for questions like this. That's where the answer will typically reside.
(you might also need to experiment with the "addnewline" attribute of cffile - depending on whether your problem is a line at the END of your file).
To answer your question regarding adding cfsetting... in your case you are writing CF code to a file that is then executed later (which by the way is not a great idea usually :). So in your first Append statement:
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfmail"
mode = "777" >
Change the "output" to be:
<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfsetting enablecfoutputonly=""yes""/> <cfmail"
mode = "777" >
But Betty - you will still need to remove the line breaks from your cfsavecontent (if that's where your whitespace is coming from) because they actually ARE inside of a cfoutput. Also, your code that creates the table you are inserting might be at fault - and it is not listed here.
Finally, since this is cfmail take a look at this post regarding line breaks that may or may not have some bearing - but at least gives you one more piece of information :)
http://www.coldfusionmuse.com/index.cfm/2006/4/12/cfmail.linebreak
You may consider using cfprocessingdirective around your cfsavecontent. There is a setting in CF administrator that universally either compresses or retains unnecessary whitespace, "Enable Whitespace Management" - http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html . Using the suppressWhiteSpace attribute of cfprocessingdirective, you can override this setting for a particular page or part of a page. So in your case:
<cfprocessingdirective suppressWhiteSpace="true">
<cfsavecontent variable="myvar">....
...
...
</cfsavecontent>
</cfprocessingdirective>
may help. Likewise, to ensure the retention of whitespace when building text emails, you'd use suppressWhiteSpace="false".
Cheers,

White Space / Coldfusion

What would be the correct way to stop the white space that ColdFusion outputs?
I know there is cfcontent and cfsetting enableCFoutputOnly. What is the correct way to do that?
In addition to <cfsilent>, <cfsetting enablecfoutputonly="yes"> and <cfprocessingdirective suppressWhiteSpace = "true"> is <cfcontent reset="true" />. You can delete whitespaces at the beginning of your document with it.
HTML5 document would then start like this:
<cfcontent type="text/html; charset=utf-8" reset="true" /><!doctype html>
XML document:
<cfcontent reset="yes" type="text/xml; charset=utf-8" /><CFOUTPUT>#VariableHoldingXmlDocAsString#</CFOUTPUT>
This way you won't get the "Content is not allowed in prolog"-error for XML docs.
If you are getting unwanted whitespaces from a function use the output-attribute to suppress any output and return your result as string - for example:
<cffunction name="getMyName" access="public" returntype="string" output="no">
<cfreturn "Seybsen" />
</cffunction>
You can modify the ColdFusion output by getting access to the ColdFusion Outpout Buffer. James Brown recently demo'd this at our user group meeting (Central Florida Web Developers User Group).
<cfscript>
out = getPageContext().getOut().getString();
newOutput = REreplace(out, 'regex', '', 'all');
</cfscript>
A great place to do this would be in Application.cfc onRequestEnd(). Your result could be a single line of HTML which is then sent to the browser. Work with your web server to GZip and you'll cut bandwidth a great deal.
In terms of tags, there is cfsilent
In the administrator there is a setting to 'Enable whitespace management'
Futher reading on cfsilent and cfcontent reset.
If neither <cfsilent> nor <cfsetting enablecfoutputonly="yes"> can satisfy you, then you are probably over-engineering this issue.
When you are asking solely out of aesthetic reasons, my recommendation is: Ignore the whitespace, it does not do any harm.
Alternatively, You can ensure your entire page is stored within a variable and all this processing is done within cfsilent tags. e.g.
<cfsilent>
<!-- some coldfusion -->
<cfsavecontent variable="pageContent">
<html>
<!-- some content -->
</html>
</cfsavecontent>
<!-- reformat pageContent if required -->
</cfsilent><cfoutput>#pageContent#</cfoutput>
Finally, you can perform any additional processing after you've generated the pagecontent but before you output it e.g. a regular expression to remove additional whitespace or some code tidying.
Here's a tip if you use CFC.
If you're not expecting your method to generate any output, use output="false" in <cffunction> and <cfcomponent> (not needed only if you're using CF9 script style). This will eliminate a lot of unwanted whitespaces.
If you have access to the server and want to implement it on every page request search for and install trimflt.jar. It's a Java servlet filter that will remove all whitespace and line breaks before sending it off. Drop the jar in the /WEB-INF/lib dir of CF and edit the web.xml file to add the filter. Its configurable as well to remove comments, exclude files or extensions, and preserve specific strings. Been running it for a few years without a problem. A set it and forget it solution.
I've found that even using every possible way to eliminate whitespace, your code may still have some unwanted spaces or line breaks. If you're still experiencing this you may need to sacrifice well formatted code for desired output.
for example, instead of:
<cfprocessingdirective suppressWhiteSpace = "true">
<cfquery ...>
...
...
...
</cfquery>
<cfoutput>
Welcome to the site #query.userName#
</cfoutput>
</cfprocessingdirective>
You may need to code:
<cfprocessingdirective suppressWhiteSpace = "true"><cfquery ...>
...
...
...
</cfquery><cfoutput>Welcome to the site #query.UserName#</cfoutput></cfprocessingdirective>
This isn't CF adding whitespace, but you adding whitespace when formatting your CF.
HTH