<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Curl Global Community - Curl Clues]]></title>
		<link>https://communities.curl.com/</link>
		<description><![CDATA[Curl Global Community - https://communities.curl.com]]></description>
		<pubDate>Sun, 19 Apr 2026 10:08:13 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[XML3:XPATH Expressions]]></title>
			<link>https://communities.curl.com/showthread.php?tid=34</link>
			<pubDate>Thu, 16 Jun 2011 01:09:14 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=34</guid>
			<description><![CDATA[Path expressions allows you to specify objects and object values from the Document Object Model using expressions. The expressions are defined using the W3C XPath's functions and the results are returned within the framework of DOM APIs in a standard, interoperable way. Path expressions conform to the XPath 1.0 standard, and are represented as XDMPath objects. <br />
<br />
<br />
It is often more concise to use reference paths to locate data items in XML structures. This approach allows for a clearer distinction between the document structure, and the processing. The result of a path expression may be a nodeset, or an atomic value (text, number or boolean). In this Curl Cue, we will describe general XPath expressons that will get you started. <br />
<br />
<br />
First, we need to describe general XPath expressions. <br />
<img src="attachment.php?aid=61" /> <br />
Now we can apply the expressions above to the example XML data where <br />
<br />
•inventory is the root node <br />
<br />
•item is a child node of inventory <br />
<br />
•title, part, and price are children of item <br />
<br />
•loc is an attribute <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>ff123 <br />
9.99 <br />
<br />
<br />
<br />
np213 <br />
6.95</code></div></div> <br />
<br />
Let's take a look at the following XPath expressions... <br />
<br />
<br />
1. /inventory/item <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies go to the inventory tag <br />
<br />
•item: find all elements with an item tag <br />
<br />
<br />
<br />
In this case, the result will be all item nodes in the samples root element. <br />
<br />
<br />
2. /inventory/item/title/@loc <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies to go to the inventory tag <br />
<br />
•item/: go to all elements with an item tag <br />
<br />
•title/: go to all elements with a title tag <br />
<br />
•@loc: select loc attributes <br />
<br />
<br />
<br />
In this case, the result will be all loc attributes from title nodes under item. <br />
<br />
<br />
3. //title\[@loc\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•//: search the entire document <br />
<br />
•title\[@loc\]: find all title elements that have a loc attribute <br />
<br />
In this case, the result will be all the item elements that have an attribute named loc. Note that example 2 will return the loc attributes, while this example will return item elements that have a loc attribute. <br />
<br />
<br />
4. //title\[@loc ="us"\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•//: search the entire document <br />
<br />
•title\[@loc\]: find all title elements that have a loc attribute with the value of 'us' <br />
<br />
<br />
<br />
In this case, the result will be the item elements that have a loc attribute equal to 'us'. <br />
<br />
<br />
5. /inventory/item\[1\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies to go to the inventory tag <br />
<br />
•item\[1\]: select the first item element <br />
<br />
<br />
<br />
In this case, the result will be the first item element that is the child of the inventory element. Note that expressions enclosed in \[ \] are predicates. A predicate is used to find a specific node or node that contains a specific value. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XDMPath Display</span> <br />
<br />
<br />
Now that we understand some XPath syntax, the following applet allows us to experiment with the expressions. The XDMPath Display applet has three panes: <br />
<br />
•The top pane allows us to select an XML file from a dropdown list. <br />
<br />
•The left pane displays the entire XML structure includijkng nodes, elements, attributes, and associated values. <br />
<br />
•The right pane allows us to input an XPath query and display the results. <br />
<br />
<br />
<br />
<br />
<br />
Once you have entered the desired XPath expression, click on the 'Select' button. The results of the query will be displayed in the right pane. Selecting the 'Highlight' button will highlight the corresponding nodes withing the XML display on the left pane. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>||| Copyright (C) 1998-2009, Sumisho Computer Systems Corp. All Rights Reserved. <br />
||| <br />
||| An OpenCurl project. <br />
<br />
||| Licensed under the Apache License, Version 2.0 (the "License"); <br />
||| you may not use this file except in compliance with the License. <br />
||| You may obtain a copy of the License at <br />
||| <br />
||| http://www.apache.org/licenses/LICENSE-2.0 <br />
||| <br />
||| Unless required by applicable law or agreed to in writing, software <br />
||| distributed under the License is distributed on an "AS IS" BASIS, <br />
||| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br />
||| See the License for the specific language governing permissions and <br />
||| limitations under the License. <br />
<br />
{curl 6.0, 7.0 applet} <br />
{applet manifest = "../manifest.mcurl"} <br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL} <br />
{import * from COM.CURL.WSDK.XML-DISPLAY} <br />
<br />
|| prefix declarations <br />
{define-proc {dwim-prefix-declarations <br />
subject:XDMElement, <br />
context:XDMNamespaceContext = xml-namespace-context <br />
}:void <br />
{subject.walk-children <br />
|| walk descendants and self <br />
include-self? = true, <br />
include-descendants? = true, <br />
{proc {n:XDMNode}:bool <br />
{type-switch n <br />
case e:XDMElement do <br />
|| check declared prefixes <br />
{if-non-null ps = e.namespace-declarations then <br />
{for p in {ps.get-prefixes} do <br />
{if-non-null ns = {ps.get-uri p} then <br />
{if {context.get-uri p} == null <br />
then <br />
|| extend global declarations accordingly <br />
{context.declare-prefix? p, ns}}}}}} <br />
|| continue walking <br />
{return true}}} <br />
} <br />
<br />
{document-style PlainDocument} <br />
{set-document-properties <br />
hstretch? = true, <br />
vstretch? = true <br />
} <br />
<br />
{persistent-data "Settings"} <br />
{value <br />
|| defaults <br />
let base-url:Url = {{get-the-applet}.url.parent.canonicalize} <br />
let restore-settings?:bool = true <br />
let factory-settings:XDMElement = <br />
{XDMElement "settings", <br />
{XDMElement "filename", "inventory.xml"}, <br />
{XDMElement "path", "*"} <br />
} <br />
let settings:XDMElement = {factory-settings.clone} <br />
|| TODO: list model <br />
|| - recent files <br />
|| - recent paths <br />
{if-non-null settings-xml = <br />
{if restore-settings? then <br />
{get-persistent-data "settings", error-if-missing? = false} <br />
else null} <br />
then <br />
{try <br />
set settings = <br />
{build-xml preserve-whitespace? = false, <br />
settings-xml}.root <br />
catch e:Exception do <br />
{popup-message {message Ignoring faulty settings}}}} <br />
let settings-context:XDMDataBindingContext = <br />
{XDMDataBindingContext model = settings} <br />
{on-applet-suspend do <br />
{set-persistent-data "settings", <br />
{settings.to-XML}} <br />
{commit-persistent-data}} <br />
<br />
|| model <br />
let xmldoc:#XDMDocument = null <br />
let xml:#XDMElement = null <br />
|| model tree <br />
let tm:XDMTreeModel = <br />
{XDMTreeModel null} <br />
let tc:XDMTreeControl = <br />
{XDMTreeControl tm, <br />
tree-connector-color = "silver", <br />
selection-policy = "multiple"} <br />
<br />
|| subset <br />
let xs:XDMNodeSet = {XDMNodeSet} <br />
|| subset tree <br />
let stm:XDMTreeModel = <br />
{XDMTreeModel null} <br />
let stc:XDMTreeControl = <br />
{XDMTreeControl stm, <br />
tree-connector-color = "silver", <br />
xdm-text-breakable? = true, <br />
selection-policy = "multiple"} <br />
<br />
|| actions <br />
let search-status:TextDisplay = {TextDisplay} <br />
let search-command:ComboBox = <br />
{ComboBox <br />
{bind value to "path"}, <br />
width = 4in, <br />
vorigin = 70%, <br />
{on ValueFinished at c:ComboBox do <br />
{with-busy-cursor <br />
|| clear highlighted nodes <br />
{tc.clear-categories category = "highlight"} <br />
{tc.select-nothing} <br />
{if c.value.empty? then <br />
set stm.root = null <br />
else <br />
{try <br />
|| apply specified xpath <br />
let w:StopWatch = {StopWatch} <br />
{w.start} <br />
set xs = {xml.search c.value} <br />
{w.stop} <br />
set search-status.value = <br />
{message Found {value xs.size} nodes in {w.elapsed}} <br />
set stm.root = xs asa XDMTreeNode <br />
{stc.expand-node {non-null stm.root}} <br />
|| note new setting <br />
{c.update-data-binding "value"} <br />
|| remember new query <br />
{if {c.find c.value} &lt; 0 then <br />
{c.append c.value}} <br />
catch e:Exception do <br />
set search-status.value = e.message <br />
{popup-message e}} <br />
}}}} <br />
let load:{proc-type {Url}:void} = <br />
{proc {loc:Url}:void <br />
{try <br />
|| load document <br />
set xmldoc = <br />
{build-xml loc, preserve-whitespace? = false} <br />
set xml = xmldoc.root <br />
|| populate displays <br />
set tm.root = xml asa XDMTreeNode <br />
{tc.expand-node {non-null tm.root}} <br />
|| augment global prefix declarations <br />
{dwim-prefix-declarations {non-null xml}} <br />
|| reset path <br />
||-- {search-command.clear-items} <br />
{search-command.set-value-with-events "*"} <br />
catch e:Exception do <br />
{popup-message e}}} <br />
let load-command:DropdownList = <br />
{DropdownList <br />
"inventory.xml", <br />
"samples.xml", <br />
{bind value to "filename"}, <br />
vorigin = 70%, <br />
{on ValueFinished at c:DropdownList do <br />
{with-busy-cursor <br />
{load {base-url.concat c.value}} <br />
|| note new setting <br />
{c.update-data-binding "value"} <br />
|| remember new query <br />
{if {c.find c.value} &lt; 0 then <br />
{c.append c.value}}}}} <br />
<br />
|| display <br />
let pane-style:Arguments = <br />
{Arguments <br />
border-width = 3px, <br />
border-style = "ridge"} <br />
let display-full:Graphic = <br />
{VBox <br />
margin = 3px, <br />
width = 2in, <br />
tc, <br />
{Fill}} <br />
let display-subset:Graphic = <br />
{VBox <br />
margin = 3px, <br />
{HBox <br />
spacing = 3pt, <br />
margin = 3pt, <br />
{text XPath:}, <br />
search-command, <br />
{CommandButton <br />
label = {message Select}, <br />
{on Action do <br />
|| select corresponding tree nodes <br />
{with-busy-cursor do <br />
{tc.collapse-node {non-null tm.root}, <br />
collapse-descendants? = true} <br />
{for x in xs do <br />
let n:XDMTreeNode = tm[x] <br />
{tc.select-nodes additive? = true, n}}}}}, <br />
{CommandButton <br />
label = {message Highlight}, <br />
{on Action do <br />
|| highlight corresponding tree nodes <br />
{with-busy-cursor do <br />
|| clear this category <br />
{tc.clear-categories category = "highlight"} <br />
{for x in xs do <br />
let n:XDMTreeNode = tm[x] <br />
|| assure node is visible <br />
{if-non-null p = n.parent then <br />
{tc.expand-node p, <br />
expand-ancestors? = true}} <br />
{tc.set-category n, "highlight"} <br />
}}}}, <br />
{Fill}}, <br />
{ScrollBox <br />
hstretch? = true, <br />
hscroll? = false, <br />
stc}, <br />
{Fill}, <br />
search-status} <br />
<br />
|| behavior <br />
let expand-action:EventHandler = <br />
{on Action at c:TreeControl do <br />
{if-non-null node = c.current-node then <br />
{with-busy-cursor <br />
{if {c.expanded-nodes.member? node} then <br />
{c.collapse-node node, <br />
collapse-descendants? = true} <br />
else <br />
{c.expand-node node, <br />
expand-descendants? = true}}}}} <br />
{tc.add-event-handler expand-action} <br />
{stc.add-event-handler expand-action} <br />
<br />
|| arrangement <br />
let main:PanedWindow = <br />
{PanedWindow orientation = "horizontal"} <br />
{main.add-pane <br />
{ScrollBox <br />
margin = 1px, <br />
hstretch? = true, <br />
vstretch? = true, <br />
{splice pane-style}, <br />
display-full}} <br />
{main.add-pane <br />
{Frame <br />
margin = 1px, <br />
hstretch? = true, <br />
vstretch? = true, <br />
{splice pane-style}, <br />
display-subset}} <br />
{main.set-pane-sizes {{Array-of double} 30%, 70%}} <br />
<br />
|| initialize <br />
{after 0s do <br />
{load-command.handle-event {ValueFinished}}} <br />
<br />
|| layout <br />
{VBox <br />
data-binding-context = settings-context, <br />
margin = 3pt, <br />
spacing = 3pt, <br />
{splice pane-style}, <br />
{HBox <br />
spacing = 3pt, <br />
margin = 3pt, <br />
{title XDMPath Display}, <br />
{Fill width = .5in}, <br />
{text File:}, <br />
load-command, <br />
{Fill}, <br />
{CommandButton <br />
label = {message Restore Settings}, <br />
{on Action do <br />
set settings = {factory-settings.clone} <br />
set settings-context.model = settings <br />
{load-command.handle-event {ValueFinished}} <br />
}}}, <br />
{hrule}, <br />
main <br />
} <br />
<br />
}</code></div></div> <br />
Since the above applet allows us to quickly view XPath query results, XDMPath Display is definitely an asset for developers. We have made this available for you to download on your machine to use with other XML files. Please select the following link to download a zip file of the XPath Explorer: XPath Explorer. Once you unzip the files, select xpath-explorer.curl to run the applet. Note that this Curl applet is also included within the WSDK documentation. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XPath in a Nutshell</span> <br />
Just to summarize using XPath expressions, we have put together a list of points worth noting: <br />
<br />
<br />
•Path expressions navigate nodes in an XML document (these resemble filesystem paths). <br />
<br />
•Paths return collections of nodes (nodesets) <br />
<br />
•Absolute paths, starting with '/' begin at the start of the document. Other paths are relative. <br />
<br />
•Paths consist of steps separated by slashes '/'. <br />
<br />
•Each step builds on the nodeset from the previous step. <br />
<br />
•Steps can follow different "axes": child elements (by name), attributes (name prefixed with '@'), descendants (starting wtih '//'). <br />
<br />
•Steps can be filtered using a predicate inside square brackets \[ \]. <br />
<br />
<br />
<br />
<br />
<br />
Of course, this is just a short list. There is a lot more on XPath such as datatypes, functions, axes, shorthand, context-node, and operators. For a complete listing of XPath expressions, please see W3C XML Path Language (XPath). <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=61" target="_blank" title="">Using XPath1.JPG</a> (Size: 33.51 KB / Downloads: 1964)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Path expressions allows you to specify objects and object values from the Document Object Model using expressions. The expressions are defined using the W3C XPath's functions and the results are returned within the framework of DOM APIs in a standard, interoperable way. Path expressions conform to the XPath 1.0 standard, and are represented as XDMPath objects. <br />
<br />
<br />
It is often more concise to use reference paths to locate data items in XML structures. This approach allows for a clearer distinction between the document structure, and the processing. The result of a path expression may be a nodeset, or an atomic value (text, number or boolean). In this Curl Cue, we will describe general XPath expressons that will get you started. <br />
<br />
<br />
First, we need to describe general XPath expressions. <br />
<img src="attachment.php?aid=61" /> <br />
Now we can apply the expressions above to the example XML data where <br />
<br />
•inventory is the root node <br />
<br />
•item is a child node of inventory <br />
<br />
•title, part, and price are children of item <br />
<br />
•loc is an attribute <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>ff123 <br />
9.99 <br />
<br />
<br />
<br />
np213 <br />
6.95</code></div></div> <br />
<br />
Let's take a look at the following XPath expressions... <br />
<br />
<br />
1. /inventory/item <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies go to the inventory tag <br />
<br />
•item: find all elements with an item tag <br />
<br />
<br />
<br />
In this case, the result will be all item nodes in the samples root element. <br />
<br />
<br />
2. /inventory/item/title/@loc <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies to go to the inventory tag <br />
<br />
•item/: go to all elements with an item tag <br />
<br />
•title/: go to all elements with a title tag <br />
<br />
•@loc: select loc attributes <br />
<br />
<br />
<br />
In this case, the result will be all loc attributes from title nodes under item. <br />
<br />
<br />
3. //title\[@loc\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•//: search the entire document <br />
<br />
•title\[@loc\]: find all title elements that have a loc attribute <br />
<br />
In this case, the result will be all the item elements that have an attribute named loc. Note that example 2 will return the loc attributes, while this example will return item elements that have a loc attribute. <br />
<br />
<br />
4. //title\[@loc ="us"\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•//: search the entire document <br />
<br />
•title\[@loc\]: find all title elements that have a loc attribute with the value of 'us' <br />
<br />
<br />
<br />
In this case, the result will be the item elements that have a loc attribute equal to 'us'. <br />
<br />
<br />
5. /inventory/item\[1\] <br />
<br />
<br />
Reading from left to right: <br />
<br />
•/: is the root node of the document <br />
<br />
•inventory/: specifies to go to the inventory tag <br />
<br />
•item\[1\]: select the first item element <br />
<br />
<br />
<br />
In this case, the result will be the first item element that is the child of the inventory element. Note that expressions enclosed in \[ \] are predicates. A predicate is used to find a specific node or node that contains a specific value. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XDMPath Display</span> <br />
<br />
<br />
Now that we understand some XPath syntax, the following applet allows us to experiment with the expressions. The XDMPath Display applet has three panes: <br />
<br />
•The top pane allows us to select an XML file from a dropdown list. <br />
<br />
•The left pane displays the entire XML structure includijkng nodes, elements, attributes, and associated values. <br />
<br />
•The right pane allows us to input an XPath query and display the results. <br />
<br />
<br />
<br />
<br />
<br />
Once you have entered the desired XPath expression, click on the 'Select' button. The results of the query will be displayed in the right pane. Selecting the 'Highlight' button will highlight the corresponding nodes withing the XML display on the left pane. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>||| Copyright (C) 1998-2009, Sumisho Computer Systems Corp. All Rights Reserved. <br />
||| <br />
||| An OpenCurl project. <br />
<br />
||| Licensed under the Apache License, Version 2.0 (the "License"); <br />
||| you may not use this file except in compliance with the License. <br />
||| You may obtain a copy of the License at <br />
||| <br />
||| http://www.apache.org/licenses/LICENSE-2.0 <br />
||| <br />
||| Unless required by applicable law or agreed to in writing, software <br />
||| distributed under the License is distributed on an "AS IS" BASIS, <br />
||| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br />
||| See the License for the specific language governing permissions and <br />
||| limitations under the License. <br />
<br />
{curl 6.0, 7.0 applet} <br />
{applet manifest = "../manifest.mcurl"} <br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL} <br />
{import * from COM.CURL.WSDK.XML-DISPLAY} <br />
<br />
|| prefix declarations <br />
{define-proc {dwim-prefix-declarations <br />
subject:XDMElement, <br />
context:XDMNamespaceContext = xml-namespace-context <br />
}:void <br />
{subject.walk-children <br />
|| walk descendants and self <br />
include-self? = true, <br />
include-descendants? = true, <br />
{proc {n:XDMNode}:bool <br />
{type-switch n <br />
case e:XDMElement do <br />
|| check declared prefixes <br />
{if-non-null ps = e.namespace-declarations then <br />
{for p in {ps.get-prefixes} do <br />
{if-non-null ns = {ps.get-uri p} then <br />
{if {context.get-uri p} == null <br />
then <br />
|| extend global declarations accordingly <br />
{context.declare-prefix? p, ns}}}}}} <br />
|| continue walking <br />
{return true}}} <br />
} <br />
<br />
{document-style PlainDocument} <br />
{set-document-properties <br />
hstretch? = true, <br />
vstretch? = true <br />
} <br />
<br />
{persistent-data "Settings"} <br />
{value <br />
|| defaults <br />
let base-url:Url = {{get-the-applet}.url.parent.canonicalize} <br />
let restore-settings?:bool = true <br />
let factory-settings:XDMElement = <br />
{XDMElement "settings", <br />
{XDMElement "filename", "inventory.xml"}, <br />
{XDMElement "path", "*"} <br />
} <br />
let settings:XDMElement = {factory-settings.clone} <br />
|| TODO: list model <br />
|| - recent files <br />
|| - recent paths <br />
{if-non-null settings-xml = <br />
{if restore-settings? then <br />
{get-persistent-data "settings", error-if-missing? = false} <br />
else null} <br />
then <br />
{try <br />
set settings = <br />
{build-xml preserve-whitespace? = false, <br />
settings-xml}.root <br />
catch e:Exception do <br />
{popup-message {message Ignoring faulty settings}}}} <br />
let settings-context:XDMDataBindingContext = <br />
{XDMDataBindingContext model = settings} <br />
{on-applet-suspend do <br />
{set-persistent-data "settings", <br />
{settings.to-XML}} <br />
{commit-persistent-data}} <br />
<br />
|| model <br />
let xmldoc:#XDMDocument = null <br />
let xml:#XDMElement = null <br />
|| model tree <br />
let tm:XDMTreeModel = <br />
{XDMTreeModel null} <br />
let tc:XDMTreeControl = <br />
{XDMTreeControl tm, <br />
tree-connector-color = "silver", <br />
selection-policy = "multiple"} <br />
<br />
|| subset <br />
let xs:XDMNodeSet = {XDMNodeSet} <br />
|| subset tree <br />
let stm:XDMTreeModel = <br />
{XDMTreeModel null} <br />
let stc:XDMTreeControl = <br />
{XDMTreeControl stm, <br />
tree-connector-color = "silver", <br />
xdm-text-breakable? = true, <br />
selection-policy = "multiple"} <br />
<br />
|| actions <br />
let search-status:TextDisplay = {TextDisplay} <br />
let search-command:ComboBox = <br />
{ComboBox <br />
{bind value to "path"}, <br />
width = 4in, <br />
vorigin = 70%, <br />
{on ValueFinished at c:ComboBox do <br />
{with-busy-cursor <br />
|| clear highlighted nodes <br />
{tc.clear-categories category = "highlight"} <br />
{tc.select-nothing} <br />
{if c.value.empty? then <br />
set stm.root = null <br />
else <br />
{try <br />
|| apply specified xpath <br />
let w:StopWatch = {StopWatch} <br />
{w.start} <br />
set xs = {xml.search c.value} <br />
{w.stop} <br />
set search-status.value = <br />
{message Found {value xs.size} nodes in {w.elapsed}} <br />
set stm.root = xs asa XDMTreeNode <br />
{stc.expand-node {non-null stm.root}} <br />
|| note new setting <br />
{c.update-data-binding "value"} <br />
|| remember new query <br />
{if {c.find c.value} &lt; 0 then <br />
{c.append c.value}} <br />
catch e:Exception do <br />
set search-status.value = e.message <br />
{popup-message e}} <br />
}}}} <br />
let load:{proc-type {Url}:void} = <br />
{proc {loc:Url}:void <br />
{try <br />
|| load document <br />
set xmldoc = <br />
{build-xml loc, preserve-whitespace? = false} <br />
set xml = xmldoc.root <br />
|| populate displays <br />
set tm.root = xml asa XDMTreeNode <br />
{tc.expand-node {non-null tm.root}} <br />
|| augment global prefix declarations <br />
{dwim-prefix-declarations {non-null xml}} <br />
|| reset path <br />
||-- {search-command.clear-items} <br />
{search-command.set-value-with-events "*"} <br />
catch e:Exception do <br />
{popup-message e}}} <br />
let load-command:DropdownList = <br />
{DropdownList <br />
"inventory.xml", <br />
"samples.xml", <br />
{bind value to "filename"}, <br />
vorigin = 70%, <br />
{on ValueFinished at c:DropdownList do <br />
{with-busy-cursor <br />
{load {base-url.concat c.value}} <br />
|| note new setting <br />
{c.update-data-binding "value"} <br />
|| remember new query <br />
{if {c.find c.value} &lt; 0 then <br />
{c.append c.value}}}}} <br />
<br />
|| display <br />
let pane-style:Arguments = <br />
{Arguments <br />
border-width = 3px, <br />
border-style = "ridge"} <br />
let display-full:Graphic = <br />
{VBox <br />
margin = 3px, <br />
width = 2in, <br />
tc, <br />
{Fill}} <br />
let display-subset:Graphic = <br />
{VBox <br />
margin = 3px, <br />
{HBox <br />
spacing = 3pt, <br />
margin = 3pt, <br />
{text XPath:}, <br />
search-command, <br />
{CommandButton <br />
label = {message Select}, <br />
{on Action do <br />
|| select corresponding tree nodes <br />
{with-busy-cursor do <br />
{tc.collapse-node {non-null tm.root}, <br />
collapse-descendants? = true} <br />
{for x in xs do <br />
let n:XDMTreeNode = tm[x] <br />
{tc.select-nodes additive? = true, n}}}}}, <br />
{CommandButton <br />
label = {message Highlight}, <br />
{on Action do <br />
|| highlight corresponding tree nodes <br />
{with-busy-cursor do <br />
|| clear this category <br />
{tc.clear-categories category = "highlight"} <br />
{for x in xs do <br />
let n:XDMTreeNode = tm[x] <br />
|| assure node is visible <br />
{if-non-null p = n.parent then <br />
{tc.expand-node p, <br />
expand-ancestors? = true}} <br />
{tc.set-category n, "highlight"} <br />
}}}}, <br />
{Fill}}, <br />
{ScrollBox <br />
hstretch? = true, <br />
hscroll? = false, <br />
stc}, <br />
{Fill}, <br />
search-status} <br />
<br />
|| behavior <br />
let expand-action:EventHandler = <br />
{on Action at c:TreeControl do <br />
{if-non-null node = c.current-node then <br />
{with-busy-cursor <br />
{if {c.expanded-nodes.member? node} then <br />
{c.collapse-node node, <br />
collapse-descendants? = true} <br />
else <br />
{c.expand-node node, <br />
expand-descendants? = true}}}}} <br />
{tc.add-event-handler expand-action} <br />
{stc.add-event-handler expand-action} <br />
<br />
|| arrangement <br />
let main:PanedWindow = <br />
{PanedWindow orientation = "horizontal"} <br />
{main.add-pane <br />
{ScrollBox <br />
margin = 1px, <br />
hstretch? = true, <br />
vstretch? = true, <br />
{splice pane-style}, <br />
display-full}} <br />
{main.add-pane <br />
{Frame <br />
margin = 1px, <br />
hstretch? = true, <br />
vstretch? = true, <br />
{splice pane-style}, <br />
display-subset}} <br />
{main.set-pane-sizes {{Array-of double} 30%, 70%}} <br />
<br />
|| initialize <br />
{after 0s do <br />
{load-command.handle-event {ValueFinished}}} <br />
<br />
|| layout <br />
{VBox <br />
data-binding-context = settings-context, <br />
margin = 3pt, <br />
spacing = 3pt, <br />
{splice pane-style}, <br />
{HBox <br />
spacing = 3pt, <br />
margin = 3pt, <br />
{title XDMPath Display}, <br />
{Fill width = .5in}, <br />
{text File:}, <br />
load-command, <br />
{Fill}, <br />
{CommandButton <br />
label = {message Restore Settings}, <br />
{on Action do <br />
set settings = {factory-settings.clone} <br />
set settings-context.model = settings <br />
{load-command.handle-event {ValueFinished}} <br />
}}}, <br />
{hrule}, <br />
main <br />
} <br />
<br />
}</code></div></div> <br />
Since the above applet allows us to quickly view XPath query results, XDMPath Display is definitely an asset for developers. We have made this available for you to download on your machine to use with other XML files. Please select the following link to download a zip file of the XPath Explorer: XPath Explorer. Once you unzip the files, select xpath-explorer.curl to run the applet. Note that this Curl applet is also included within the WSDK documentation. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XPath in a Nutshell</span> <br />
Just to summarize using XPath expressions, we have put together a list of points worth noting: <br />
<br />
<br />
•Path expressions navigate nodes in an XML document (these resemble filesystem paths). <br />
<br />
•Paths return collections of nodes (nodesets) <br />
<br />
•Absolute paths, starting with '/' begin at the start of the document. Other paths are relative. <br />
<br />
•Paths consist of steps separated by slashes '/'. <br />
<br />
•Each step builds on the nodeset from the previous step. <br />
<br />
•Steps can follow different "axes": child elements (by name), attributes (name prefixed with '@'), descendants (starting wtih '//'). <br />
<br />
•Steps can be filtered using a predicate inside square brackets \[ \]. <br />
<br />
<br />
<br />
<br />
<br />
Of course, this is just a short list. There is a lot more on XPath such as datatypes, functions, axes, shorthand, context-node, and operators. For a complete listing of XPath expressions, please see W3C XML Path Language (XPath). <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=61" target="_blank" title="">Using XPath1.JPG</a> (Size: 33.51 KB / Downloads: 1964)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[XML2:Transforming XML]]></title>
			<link>https://communities.curl.com/showthread.php?tid=33</link>
			<pubDate>Thu, 16 Jun 2011 00:59:45 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=33</guid>
			<description><![CDATA[The last Curl Cue addressed how to access XML data from a server and store the information as an XML document model (XDMNodes). Now the content must be transformed or processed to meet the application functionality. Since the data has already been internalized, all we need to do is:<br />
<br />
•query the relevant information,<br />
<br />
•perform relevant processesing,<br />
<br />
•and diplay the requested information to the user.<br />
<br />
 <br />
 <br />
 <br />
 <br />
One of the most common types of display is a grid.  In the first example, we query data and dislay it using a standard <font color="purple">Table</font> and in the second example we will display it using a <font color="purple">RecordGrid</font>.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Querying the Data</span><br />
Once the data is contained within the Curl XML DOM structure, the goal is to extract elements and their associated values by traversing the node tree. This includes element types, element values, and element attributes. Using the WSDK, there are three different ways to obtain this information.  Either by using object methods, XPath expressions, or elaboration. In this Curl Cue, we will focus on using XPath expressions to query relevant content.<br />
<br />
 <br />
We will use the same data from the last Curl Cue (XML Data). The following is the <font color="purple">XDMDocument</font> view so that you can recall the structure of the XML.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "services.xml"}<br />
<br />
&nbsp;&nbsp; let xmldoc:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;{XDMTreeControl open?=true, xmldoc}<br />
}</code></div></div><br />
<span style="font-weight: bold;" class="mycode_b">Using XPath to Query Data</span><br />
 <br />
 <br />
All of the nodes in the <font color="purple">XDMDocument</font> can be queried using an XPath expression. Nodes include <font color="purple">XDMElement</font>,<font color="purple">XDMAttribute</font>, <font color="purple">XDMText</font>, and <font color="purple">XDMProcessingInstruction</font>.<br />
<br />
 <br />
XPath expressions are used to traverse the nodes in the XML structure and extract elements and their associated values. XPath queries return an <font color="purple">XPathValue</font> which can be one of the following types:<br />
<br />
•XDMNodeSet<br />
<br />
•String<br />
<br />
•double<br />
<br />
•bool<br />
<br />
 <br />
 <br />
In our example,  a <font color="purple">XDMNodeSet</font> is first created to gather all Sample nodes.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>def items:XDMNodeSet = {model.search Samples/Sample}</code></div></div><br />
 <br />
Then, standard XPATH expressions are used to query relevant data. <br />
<br />
•item.search "@xx" returns an attribute value of xx<br />
<br />
•item.search "xx" returns an element value of xx<br />
<br />
 <br />
 <br />
For more information regarding XPath, please see XPath Curl Cue: About XPath.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Tabular Display</span><br />
In the first example, we will be extracting data from th displaying relevant XML data in a table. This is an example of transforming the data for presentation.<br />
<br />
 <br />
All XPATH queries will return an <font color="purple">XDMNodeSet</font>, therefore we need to convert it to a <font color="purple">String</font> before it is able to be used in the table. For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{item.search title}.as-String</code></div></div> <br />
 <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "samples.xml"}<br />
&nbsp;&nbsp; let model:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; let display:Table =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; columns = 2,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-width = 1px,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-color = "brown",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-style = "flat"}<br />
||--&nbsp;&nbsp;&nbsp;&nbsp;def items:XDMNodeSet = {model.search "Samples/Sample"}<br />
&nbsp;&nbsp; def items:XDMNodeSet = {model.root.search "sample"}<br />
&nbsp;&nbsp; {for item in items do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {row-prototype<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {item.search "@id"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {item.search "title"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {link href = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {url&nbsp;&nbsp;{item.search "doclink"}.as-String},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {value&nbsp;&nbsp;{item.search "title"}.as-String}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }}}<br />
&nbsp;&nbsp; display<br />
}</code></div></div><br />
<span style="font-weight: bold;" class="mycode_b">Record Display</span><br />
 <br />
 <br />
In the next example, we are using the XPath to query the title, description and link. The information is stored in a <font color="purple">RecordSet</font> and displayed to the user with a <font color="purple">RecordDisplay</font>. This is an example of transforming the data into a model for further processing. The model data is then transformed for presentation in to a grid display.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "samples.xml"}<br />
&nbsp;&nbsp; let model:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; let display:Table =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; columns = 2,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-width = 1px,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-color = "brown",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-style = "flat"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; def items:XDMNodeSet = {model.search "samples/sample"}<br />
<br />
&nbsp;&nbsp; let rs-samples:RecordSet =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordSet<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordFields<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Title", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Description", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Link", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {for item in items do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {rs-samples.append<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordData Title =&nbsp;&nbsp;{item.search "title"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description = {item.search "description"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link = {item.search "doclink"}.as-String}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {RecordGrid<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 30cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; record-source = rs-samples<br />
&nbsp;&nbsp; }<br />
}</code></div></div>For more information about <font color="purple">RecordSet</font>s, please see RecordSets.<br />
]]></description>
			<content:encoded><![CDATA[The last Curl Cue addressed how to access XML data from a server and store the information as an XML document model (XDMNodes). Now the content must be transformed or processed to meet the application functionality. Since the data has already been internalized, all we need to do is:<br />
<br />
•query the relevant information,<br />
<br />
•perform relevant processesing,<br />
<br />
•and diplay the requested information to the user.<br />
<br />
 <br />
 <br />
 <br />
 <br />
One of the most common types of display is a grid.  In the first example, we query data and dislay it using a standard <font color="purple">Table</font> and in the second example we will display it using a <font color="purple">RecordGrid</font>.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Querying the Data</span><br />
Once the data is contained within the Curl XML DOM structure, the goal is to extract elements and their associated values by traversing the node tree. This includes element types, element values, and element attributes. Using the WSDK, there are three different ways to obtain this information.  Either by using object methods, XPath expressions, or elaboration. In this Curl Cue, we will focus on using XPath expressions to query relevant content.<br />
<br />
 <br />
We will use the same data from the last Curl Cue (XML Data). The following is the <font color="purple">XDMDocument</font> view so that you can recall the structure of the XML.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "services.xml"}<br />
<br />
&nbsp;&nbsp; let xmldoc:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;{XDMTreeControl open?=true, xmldoc}<br />
}</code></div></div><br />
<span style="font-weight: bold;" class="mycode_b">Using XPath to Query Data</span><br />
 <br />
 <br />
All of the nodes in the <font color="purple">XDMDocument</font> can be queried using an XPath expression. Nodes include <font color="purple">XDMElement</font>,<font color="purple">XDMAttribute</font>, <font color="purple">XDMText</font>, and <font color="purple">XDMProcessingInstruction</font>.<br />
<br />
 <br />
XPath expressions are used to traverse the nodes in the XML structure and extract elements and their associated values. XPath queries return an <font color="purple">XPathValue</font> which can be one of the following types:<br />
<br />
•XDMNodeSet<br />
<br />
•String<br />
<br />
•double<br />
<br />
•bool<br />
<br />
 <br />
 <br />
In our example,  a <font color="purple">XDMNodeSet</font> is first created to gather all Sample nodes.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>def items:XDMNodeSet = {model.search Samples/Sample}</code></div></div><br />
 <br />
Then, standard XPATH expressions are used to query relevant data. <br />
<br />
•item.search "@xx" returns an attribute value of xx<br />
<br />
•item.search "xx" returns an element value of xx<br />
<br />
 <br />
 <br />
For more information regarding XPath, please see XPath Curl Cue: About XPath.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Tabular Display</span><br />
In the first example, we will be extracting data from th displaying relevant XML data in a table. This is an example of transforming the data for presentation.<br />
<br />
 <br />
All XPATH queries will return an <font color="purple">XDMNodeSet</font>, therefore we need to convert it to a <font color="purple">String</font> before it is able to be used in the table. For example:<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{item.search title}.as-String</code></div></div> <br />
 <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "samples.xml"}<br />
&nbsp;&nbsp; let model:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; let display:Table =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; columns = 2,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-width = 1px,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-color = "brown",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-style = "flat"}<br />
||--&nbsp;&nbsp;&nbsp;&nbsp;def items:XDMNodeSet = {model.search "Samples/Sample"}<br />
&nbsp;&nbsp; def items:XDMNodeSet = {model.root.search "sample"}<br />
&nbsp;&nbsp; {for item in items do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {row-prototype<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {item.search "@id"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {item.search "title"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {link href = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {url&nbsp;&nbsp;{item.search "doclink"}.as-String},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {value&nbsp;&nbsp;{item.search "title"}.as-String}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }}}<br />
&nbsp;&nbsp; display<br />
}</code></div></div><br />
<span style="font-weight: bold;" class="mycode_b">Record Display</span><br />
 <br />
 <br />
In the next example, we are using the XPath to query the title, description and link. The information is stored in a <font color="purple">RecordSet</font> and displayed to the user with a <font color="purple">RecordDisplay</font>. This is an example of transforming the data into a model for further processing. The model data is then transformed for presentation in to a grid display.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{applet manifest = "manifest.mcurl"}<br />
{import * from COM.CURL.WSDK.XML-DOCUMENT-MODEL}<br />
{import * from COM.CURL.WSDK.XML-DISPLAY}<br />
<br />
<br />
{value <br />
&nbsp;&nbsp; let xml-data:Url ={url "samples.xml"}<br />
&nbsp;&nbsp; let model:XDMDocument =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {build-xml preserve-whitespace? = false, xml-data}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; let display:Table =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; columns = 2,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-width = 1px,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-color = "brown",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cell-border-style = "flat"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; def items:XDMNodeSet = {model.search "samples/sample"}<br />
<br />
&nbsp;&nbsp; let rs-samples:RecordSet =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordSet<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordFields<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Title", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Description", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordField <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Link", domain = String<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {for item in items do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {rs-samples.append<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {RecordData Title =&nbsp;&nbsp;{item.search "title"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description = {item.search "description"}.as-String,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link = {item.search "doclink"}.as-String}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {RecordGrid<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 30cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; record-source = rs-samples<br />
&nbsp;&nbsp; }<br />
}</code></div></div>For more information about <font color="purple">RecordSet</font>s, please see RecordSets.<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[XML1:XML Data]]></title>
			<link>https://communities.curl.com/showthread.php?tid=32</link>
			<pubDate>Thu, 16 Jun 2011 00:56:17 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=32</guid>
			<description><![CDATA[Most data can be transformed into XML content. This provides a drive to use XML as a medium for structuring information the Web for the purpose of data exchange between applications. XML structures data using a text-based markup language similar to HTML and is non-proprietary and platform independent. Open standards and the focus on communication and collaboration among people and applications have created and environmnet where XML Web services are becoming a standard platform for application integration in the move to distributed computing on the Internet. From a Curl client perspective, XML information can be obtained from communicating with a Web service over HTTP or using XML over HTTP. <br />
<img src="attachment.php?aid=55" /> <br />
<br />
<br />
In either case, the data that is queried and obtained is XML. Therefore it is necessary to first concentrate on handling XML data in the Curl client over HTTP. Once these fundamental principles are understood, then we will access XML data via a Web service in a subsequent Curl Cue. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Curl's XML Document Model</span> <br />
<br />
<br />
Curl's XML Document Model (XDM) provides functionality for processing XML data in Curl: reading, creating, modifying and writing XML documents. XML document contents are represented as a hierarchy of Curl objects which can be accessed using Curl methods and XPath expressions. Once accessed, the contrent can be displayed, transformed, and processed to meet the application functionality <br />
<br />
<br />
Curl's XDM is accessible through the Curl Web Services Development Kit (WSDK). The WSDK library must be installed and accessed in order to use access its functionality which include SOAP/WSDL support, and an XML document model. If you plan on displaying and manipulating the examples contained within this Curl Cue, there is no need to download the WSDK. However, once you download and run the examples on your local machine, you will need to download the libraray. <br />
<br />
<br />
You can download the WSDK library from the official WSDK download page by selecting the following link: WSDK Download. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XDM Nodes</span> <br />
<br />
<br />
The XDM views XML documents as a tree structure of elements embedded within other elements. All elements, their containing text and their attributes can be accessed through the XDM structure. Their contents can be modified, deleted, and new elements can be created. The elements, associated text and attributes are modeled as nodes. <br />
<br />
<br />
In the WSDK, XDMNodes are represented by XDMElements, XDMAttributes, XDMText, XDMProcessingIstructions. <br />
<br />
<img src="attachment.php?aid=56" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Displaying the XML DOM Structure</span> <br />
<br />
<br />
In the first example, we read the XML, store the data as an XDM document, and then display the data using a tree control structure that allows you to visually expand and compress the XML nodes. This method is very useful during development, but not as common in production applications. <br />
<br />
<br />
Steps: the quickest way to read and view the XML data is to: <br />
<br />
1.Import necessary WSDK packages <br />
<br />
2.Create an XML Document model (<span style="color: purple;" class="mycode_color">XDMDocument</span>) using the <span style="color: purple;" class="mycode_color">build-xml procedure.</span> <br />
<br />
3.Display the stored XML data using <span style="color: purple;" class="mycode_color">XDMTreeControl</span> <br />
<br />
In this example we use XML data created directly in the code using the xml-string variable for simplicity. <br />
<br />
<br />
width='100%' height='550' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata.curl' <br />
<br />
<br />
<br />
Note that 2 packages need to be imported from the WSDK: <br />
<br />
•COM.CURL.WSDK.XML-DOCUMENT-MODEL: this allows us to access <span style="color: purple;" class="mycode_color">XDMDocument</span> <br />
<br />
•COM.CURL.WSDK.XML-DISPLAY: this allows us to access <span style="color: purple;" class="mycode_color">XDMTreeControl</span> <br />
<br />
<br />
<br />
<br />
<br />
In the second example, we query the XML data from a known <span style="color: purple;" class="mycode_color">Url</span>. This scenario is typical of what you would expect from a deployed application where the xml data resides on a company server. <br />
<br />
<br />
For this example, the XML data is stored in the file sample.xml. It represents an inventory or resources from the Widgets/Gadgets/Curlets section on Curl's Developer Community (<a href="http://www.developers.curl.com" target="_blank" rel="noopener" class="mycode_url">www.developers.curl.com</a>). <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>curl <br />
Hardware-accelerated rendering is used to show a 3D view of chemical molecules. <br />
http://developers.curl.com/docs/DOC-1060 <br />
http://developers.curl.com/demos/molecules/start.curl <br />
<br />
<br />
<br />
curl <br />
This example displays flames by simulating them mathematically, not just by showing a series of precomputed images. <br />
http://developers.curl.com/docs/DOC-1057 <br />
http://developers.curl.com/demos/fire/start.curl <br />
<br />
<br />
<br />
curl <br />
The teapot is a classic example of 3D rendering. <br />
http://developers.curl.com/docs/DOC-1059 <br />
http://developers.curl.com/demos/teapot/start.curl</code></div></div> <br />
Note: the full list code samples can be found here: Widgets/Gadgets/Curlets. <br />
<br />
<br />
width='100%' height='390' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata2.curl' <br />
<br />
<br />
<br />
<br />
<br />
About build-xml: The build-xml function uses the standard Curl SAX parser and has corresponding keyword arguments. The input source can be specified as a <span style="color: purple;" class="mycode_color">Url</span> or a <span style="color: purple;" class="mycode_color">String</span>, as well as text and byte streams. <br />
<br />
<br />
The <span style="color: purple;" class="mycode_color">XDMTreeControl</span> displays and exact representation of the XML using a tree structure of elements embedded within other elements. If the XML data had multiple levels, the tree control nodes would expand to view all children. <br />
<br />
<br />
Since the XDM presents stores XML data as a tree structure, it gives us access to the information through a set of objects. This allows us to query relevant information, transform and process the data, and display the requested information to the user. Thus, we can state the the XDM model is needs to be obtained first before any processing can occur. The following Curl Cues will discuss methods of transformation and display. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=55" target="_blank" title="">CurlClientXML.png</a> (Size: 21.34 KB / Downloads: 3135)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=56" target="_blank" title="">XDMNodes.png</a> (Size: 18.02 KB / Downloads: 2541)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Most data can be transformed into XML content. This provides a drive to use XML as a medium for structuring information the Web for the purpose of data exchange between applications. XML structures data using a text-based markup language similar to HTML and is non-proprietary and platform independent. Open standards and the focus on communication and collaboration among people and applications have created and environmnet where XML Web services are becoming a standard platform for application integration in the move to distributed computing on the Internet. From a Curl client perspective, XML information can be obtained from communicating with a Web service over HTTP or using XML over HTTP. <br />
<img src="attachment.php?aid=55" /> <br />
<br />
<br />
In either case, the data that is queried and obtained is XML. Therefore it is necessary to first concentrate on handling XML data in the Curl client over HTTP. Once these fundamental principles are understood, then we will access XML data via a Web service in a subsequent Curl Cue. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Curl's XML Document Model</span> <br />
<br />
<br />
Curl's XML Document Model (XDM) provides functionality for processing XML data in Curl: reading, creating, modifying and writing XML documents. XML document contents are represented as a hierarchy of Curl objects which can be accessed using Curl methods and XPath expressions. Once accessed, the contrent can be displayed, transformed, and processed to meet the application functionality <br />
<br />
<br />
Curl's XDM is accessible through the Curl Web Services Development Kit (WSDK). The WSDK library must be installed and accessed in order to use access its functionality which include SOAP/WSDL support, and an XML document model. If you plan on displaying and manipulating the examples contained within this Curl Cue, there is no need to download the WSDK. However, once you download and run the examples on your local machine, you will need to download the libraray. <br />
<br />
<br />
You can download the WSDK library from the official WSDK download page by selecting the following link: WSDK Download. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">XDM Nodes</span> <br />
<br />
<br />
The XDM views XML documents as a tree structure of elements embedded within other elements. All elements, their containing text and their attributes can be accessed through the XDM structure. Their contents can be modified, deleted, and new elements can be created. The elements, associated text and attributes are modeled as nodes. <br />
<br />
<br />
In the WSDK, XDMNodes are represented by XDMElements, XDMAttributes, XDMText, XDMProcessingIstructions. <br />
<br />
<img src="attachment.php?aid=56" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Displaying the XML DOM Structure</span> <br />
<br />
<br />
In the first example, we read the XML, store the data as an XDM document, and then display the data using a tree control structure that allows you to visually expand and compress the XML nodes. This method is very useful during development, but not as common in production applications. <br />
<br />
<br />
Steps: the quickest way to read and view the XML data is to: <br />
<br />
1.Import necessary WSDK packages <br />
<br />
2.Create an XML Document model (<span style="color: purple;" class="mycode_color">XDMDocument</span>) using the <span style="color: purple;" class="mycode_color">build-xml procedure.</span> <br />
<br />
3.Display the stored XML data using <span style="color: purple;" class="mycode_color">XDMTreeControl</span> <br />
<br />
In this example we use XML data created directly in the code using the xml-string variable for simplicity. <br />
<br />
<br />
width='100%' height='550' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata.curl' <br />
<br />
<br />
<br />
Note that 2 packages need to be imported from the WSDK: <br />
<br />
•COM.CURL.WSDK.XML-DOCUMENT-MODEL: this allows us to access <span style="color: purple;" class="mycode_color">XDMDocument</span> <br />
<br />
•COM.CURL.WSDK.XML-DISPLAY: this allows us to access <span style="color: purple;" class="mycode_color">XDMTreeControl</span> <br />
<br />
<br />
<br />
<br />
<br />
In the second example, we query the XML data from a known <span style="color: purple;" class="mycode_color">Url</span>. This scenario is typical of what you would expect from a deployed application where the xml data resides on a company server. <br />
<br />
<br />
For this example, the XML data is stored in the file sample.xml. It represents an inventory or resources from the Widgets/Gadgets/Curlets section on Curl's Developer Community (<a href="http://www.developers.curl.com" target="_blank" rel="noopener" class="mycode_url">www.developers.curl.com</a>). <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>curl <br />
Hardware-accelerated rendering is used to show a 3D view of chemical molecules. <br />
http://developers.curl.com/docs/DOC-1060 <br />
http://developers.curl.com/demos/molecules/start.curl <br />
<br />
<br />
<br />
curl <br />
This example displays flames by simulating them mathematically, not just by showing a series of precomputed images. <br />
http://developers.curl.com/docs/DOC-1057 <br />
http://developers.curl.com/demos/fire/start.curl <br />
<br />
<br />
<br />
curl <br />
The teapot is a classic example of 3D rendering. <br />
http://developers.curl.com/docs/DOC-1059 <br />
http://developers.curl.com/demos/teapot/start.curl</code></div></div> <br />
Note: the full list code samples can be found here: Widgets/Gadgets/Curlets. <br />
<br />
<br />
width='100%' height='390' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata2.curl' <br />
<br />
<br />
<br />
<br />
<br />
About build-xml: The build-xml function uses the standard Curl SAX parser and has corresponding keyword arguments. The input source can be specified as a <span style="color: purple;" class="mycode_color">Url</span> or a <span style="color: purple;" class="mycode_color">String</span>, as well as text and byte streams. <br />
<br />
<br />
The <span style="color: purple;" class="mycode_color">XDMTreeControl</span> displays and exact representation of the XML using a tree structure of elements embedded within other elements. If the XML data had multiple levels, the tree control nodes would expand to view all children. <br />
<br />
<br />
Since the XDM presents stores XML data as a tree structure, it gives us access to the information through a set of objects. This allows us to query relevant information, transform and process the data, and display the requested information to the user. Thus, we can state the the XDM model is needs to be obtained first before any processing can occur. The following Curl Cues will discuss methods of transformation and display. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=55" target="_blank" title="">CurlClientXML.png</a> (Size: 21.34 KB / Downloads: 3135)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=56" target="_blank" title="">XDMNodes.png</a> (Size: 18.02 KB / Downloads: 2541)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Styling3:Creating Styles with the Style Designer]]></title>
			<link>https://communities.curl.com/showthread.php?tid=31</link>
			<pubDate>Thu, 16 Jun 2011 00:52:37 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=31</guid>
			<description><![CDATA[<span style="font-weight: bold;" class="mycode_b">Overview</span> <br />
<br />
<br />
The Style Designer is a Curl application that allows you to define styling preferences that can be written out as a Curl style sheet. This application allows you to easily create your own control styles without coding. You can... <br />
<br />
•visually modify control styles including buttons, tabs, group boxes, text fields, and more <br />
<br />
•create style templates for use with different applets <br />
<br />
•share styles with other developers <br />
<br />
•write out style sheets for use in Curl applets <br />
<img src="attachment.php?aid=52" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching the Style Designer</span> <br />
The Style Designer is designed to run as a Curl detached applet, meaning that it can run from the web but without a web browser. You can run the Style Designer two different ways: directly from our website or from a downloaded copy. <br />
<br />
<br />
1.To launch the Style Designer as a detached applet, by copy and paste this link into your browser: curl://launch/http://developers.curl.com/demos/style-designer/style-designer.dcurl <br />
<br />
2.Download and unzip the source code from the bottom of the following page: Style Designer. Once you have unzipped the contents, navigate to the style-designer folder and double-click on style-designer.dcurl. <br />
<br />
<br />
<br />
In the case of the downloaded version, you will also need to grant privilege to the style-designer directory. You can do this by selecting the Curl RTE icon on the Windows task bar to bring up the Curl control panel (when the Curl RTE is running). Select the Security tab, then click This Computer heading to open the security settings for your computer. Click the Add Privileged Directory... link and enter the directory where you unzipped the Style Designer (or a parent directory). Click OK. From now on, any Curl applet launched from this directory will have full access to the local machine. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using the Style Designer</span> <br />
<br />
<br />
Once you have launched the Style Designer applet, use this graphical interface to create your own unique look for the Curl styled controls. The left side of the applet is a collection of properties for individual Curl controls as well as general color preferences. <br />
<img src="attachment.php?aid=53" /> <br />
Each style created has an associated Name that is specified in the General Information section. When you initially launch the Style Designer, the default name is S-001. <br />
<br />
<br />
Adjust the colors, highlighting, and other attributes to design custom look. Each section displays attributes that can be changed until you are satisfied with the desired look. When an attribute is modified, for example Dialog Color, the sample controls on the right hand side of the window will automatically refresh to display the updated value. <br />
<br />
<br />
The control groupings in this pane include the following: <br />
<br />
•General Information: includes the style name, a place for you to record your personal rating of this style, and any notes. Error messages will also appear here if selection values are invalid. <br />
<br />
•Global Colors, Gradient Angle: sets general colors for all controls. <br />
<br />
•Controls Options: grouped in a set of tabs, allows you to specify specific attributes for buttons, tabs, group labels, fields, and other controls. Each control has control-specific attributes that can be set. <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Changing Attribute Values</span> <br />
All field selections can be modified by either typing in a value or selecting a check box. If a selection is not valid, an error message will be displayed in the General Information section. <br />
[img]attachment.php?aid=54[/timg] <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating a Style Sheet</span> <br />
<br />
When you are happy with a style you've created you can write out a style sheet file that you can use in any Curl 6.0 applets you develop. Choose File > Write Style Sheet... to write out a Curl style sheet. <br />
<br />
<br />
Note that style sheets use the styled controls library that was introduced with Version 6.0 of the Curl RTE. Therefore, in order to use the style sheet and associated skinned controls in your applets, you must first download the library from the the Curl web site and integrate it into your development environment. If you have not downloaded the library, please select the following link: STYLED-CONTROLS Library. <br />
<br />
<br />
<br />
For more information regarding style sheets, please refer to the Curl Styled Controls Library User's Guide that you installed in the Curl Documentation <br />
<br />
<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=52" target="_blank" title="">styledesigner_verylight_scaled.png</a> (Size: 162.2 KB / Downloads: 1859)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=53" target="_blank" title="">style_properties.png</a> (Size: 17.36 KB / Downloads: 1750)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=54" target="_blank" title="">Creating Styles with the Style Designer1.JPG</a> (Size: 229.72 KB / Downloads: 1313)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<span style="font-weight: bold;" class="mycode_b">Overview</span> <br />
<br />
<br />
The Style Designer is a Curl application that allows you to define styling preferences that can be written out as a Curl style sheet. This application allows you to easily create your own control styles without coding. You can... <br />
<br />
•visually modify control styles including buttons, tabs, group boxes, text fields, and more <br />
<br />
•create style templates for use with different applets <br />
<br />
•share styles with other developers <br />
<br />
•write out style sheets for use in Curl applets <br />
<img src="attachment.php?aid=52" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching the Style Designer</span> <br />
The Style Designer is designed to run as a Curl detached applet, meaning that it can run from the web but without a web browser. You can run the Style Designer two different ways: directly from our website or from a downloaded copy. <br />
<br />
<br />
1.To launch the Style Designer as a detached applet, by copy and paste this link into your browser: curl://launch/http://developers.curl.com/demos/style-designer/style-designer.dcurl <br />
<br />
2.Download and unzip the source code from the bottom of the following page: Style Designer. Once you have unzipped the contents, navigate to the style-designer folder and double-click on style-designer.dcurl. <br />
<br />
<br />
<br />
In the case of the downloaded version, you will also need to grant privilege to the style-designer directory. You can do this by selecting the Curl RTE icon on the Windows task bar to bring up the Curl control panel (when the Curl RTE is running). Select the Security tab, then click This Computer heading to open the security settings for your computer. Click the Add Privileged Directory... link and enter the directory where you unzipped the Style Designer (or a parent directory). Click OK. From now on, any Curl applet launched from this directory will have full access to the local machine. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using the Style Designer</span> <br />
<br />
<br />
Once you have launched the Style Designer applet, use this graphical interface to create your own unique look for the Curl styled controls. The left side of the applet is a collection of properties for individual Curl controls as well as general color preferences. <br />
<img src="attachment.php?aid=53" /> <br />
Each style created has an associated Name that is specified in the General Information section. When you initially launch the Style Designer, the default name is S-001. <br />
<br />
<br />
Adjust the colors, highlighting, and other attributes to design custom look. Each section displays attributes that can be changed until you are satisfied with the desired look. When an attribute is modified, for example Dialog Color, the sample controls on the right hand side of the window will automatically refresh to display the updated value. <br />
<br />
<br />
The control groupings in this pane include the following: <br />
<br />
•General Information: includes the style name, a place for you to record your personal rating of this style, and any notes. Error messages will also appear here if selection values are invalid. <br />
<br />
•Global Colors, Gradient Angle: sets general colors for all controls. <br />
<br />
•Controls Options: grouped in a set of tabs, allows you to specify specific attributes for buttons, tabs, group labels, fields, and other controls. Each control has control-specific attributes that can be set. <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Changing Attribute Values</span> <br />
All field selections can be modified by either typing in a value or selecting a check box. If a selection is not valid, an error message will be displayed in the General Information section. <br />
[img]attachment.php?aid=54[/timg] <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating a Style Sheet</span> <br />
<br />
When you are happy with a style you've created you can write out a style sheet file that you can use in any Curl 6.0 applets you develop. Choose File > Write Style Sheet... to write out a Curl style sheet. <br />
<br />
<br />
Note that style sheets use the styled controls library that was introduced with Version 6.0 of the Curl RTE. Therefore, in order to use the style sheet and associated skinned controls in your applets, you must first download the library from the the Curl web site and integrate it into your development environment. If you have not downloaded the library, please select the following link: STYLED-CONTROLS Library. <br />
<br />
<br />
<br />
For more information regarding style sheets, please refer to the Curl Styled Controls Library User's Guide that you installed in the Curl Documentation <br />
<br />
<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=52" target="_blank" title="">styledesigner_verylight_scaled.png</a> (Size: 162.2 KB / Downloads: 1859)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=53" target="_blank" title="">style_properties.png</a> (Size: 17.36 KB / Downloads: 1750)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=54" target="_blank" title="">Creating Styles with the Style Designer1.JPG</a> (Size: 229.72 KB / Downloads: 1313)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Styling2:Style Sheets]]></title>
			<link>https://communities.curl.com/showthread.php?tid=30</link>
			<pubDate>Thu, 16 Jun 2011 00:36:45 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=30</guid>
			<description><![CDATA[Style sheets are now supported in the Curl GUI Toolkit. (In version 6.0 they were available as an external library. This older note describes how to use styled sheets in version 6.0: Using Style Sheets - Curl 6.0 .) <br />
<br />
<br />
<br />
<br />
You can create and use one or more style sheet files in a Curl application. You can also create your StyleSheet objects directly in the Curl code. In general, follow these basic rules: <br />
<br />
" Each style sheet consists style rules and nested style sheets. <br />
<br />
" A nested style sheet can be defined in a curl file and imported by giving the url for the file. <br />
<br />
" Any nested style sheets must appear before the style rules. <br />
<br />
" A style rule consists of a selector string followed by any number of option settings. <br />
<br />
" If two rules specify the same option, the rule that comes later overrides the earlier rule. <br />
<br />
" If you set an option directly on an object, it cannot be overridden by a style rule. <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Style Sheet Syntax</span> <br />
In Curl, a <span style="color: purple;" class="mycode_color">StyleSheet</span> contains a set of rules that affect the look of the GUI objects the rules apply to. Each <span style="color: purple;" class="mycode_color">StyleRule</span> uses a pattern, or "selector", to identify the controls or GUI components that are affected by the rule. <br />
<br />
<br />
Let's examine a example style sheet definition. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let ss:StyleSheet <br />
{StyleSheet <br />
{StyleRule VBox.panel-vbox <br />
background = blue, <br />
margin = 2px, <br />
spacing = 4px <br />
} <br />
}</code></div></div> <br />
<br />
where: <br />
<br />
" ss a variable that defines the StyleSheet <br />
<br />
" VBox.panel-vbox is the selector <br />
<br />
" VBox is the <span style="color: purple;" class="mycode_color">style-element</span> <br />
<br />
" panel-vbox is the <span style="color: purple;" class="mycode_color">style-class</span> <br />
<br />
<br />
<br />
<br />
<br />
This selector has two components. For the rule to apply, the first component must match the <span style="color: purple;" class="mycode_color">style-element</span> property of an object and the second component must match the <span style="color: purple;" class="mycode_color">style-class</span> property. If either component is omitted, then it doesn't apply. (So ".panel-vbox" would apply to any object with a <span style="color: purple;" class="mycode_color">style-class</span> that includes the string "panel-vbox".) <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using the Style Sheet</span> <br />
<br />
<br />
Once you have a <span style="color: purple;" class="mycode_color">StyleSheet</span> defined, you can use the definitions after it has been installed. For example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{install-style-sheet ss}</code></div></div> <br />
<br />
In our example code, each time we call <span style="color: purple;" class="mycode_color">VBox</span>, we have the option of specifiying the <span style="color: purple;" class="mycode_color">style-class</span> of panel-vbox. For example: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value <br />
let my-panel:VBox = <br />
{VBox <br />
style-class = panel-vbox, <br />
{Frame Top content}, <br />
{Frame Bottom content} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a StyleSheet in the Login Example</span> <br />
Let's pull together these concepts and apply them to our login example. We created a style sheet common-style-sheet that contains definitions for common properties (widths) specified in the login screen. We can use these styles by specifying the style-class. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
|| Identify a StyleSheet <br />
|| The common StyleSheet sets up some rules (primarily widths) common to the <br />
|| different versions of the login form. <br />
{let common-style-sheet:StyleSheet = <br />
{StyleSheet <br />
{StyleRule "CommandButton.ok", <br />
width = 1.75cm <br />
}, <br />
{StyleRule "TextField.login", <br />
width = 2cm <br />
}, <br />
{StyleRule "PasswordField.login", <br />
width = 2cm <br />
}, <br />
{StyleRule "GroupBox.dialog", <br />
width = 4.5cm <br />
} <br />
} <br />
<br />
} <br />
<br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
style-class="dialog", <br />
label = "", <br />
{Dialog <br />
use-look-and-feel? = false, <br />
{Table <br />
{row <br />
{cell {Label"Username:"}} <br />
{cell {value tf}} <br />
}, <br />
{row <br />
{cell {Label "Password: "}} <br />
{cell {value pf}} <br />
}, <br />
{row <br />
{cell <br />
colspan = 2, <br />
halign = "center", <br />
{value cb} <br />
} <br />
} <br />
}, <br />
{validate-with {DialogValidator}} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{TextField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let pf:PasswordField = <br />
{PasswordField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with {StringValidator}, required? = true} <br />
} <br />
<br />
let cb:CommandButton = <br />
{CommandButton <br />
style-class = "ok", <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{Dialog <br />
{GroupBox <br />
width = 4.5cm, <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
spacing = 0.1cm, <br />
{Label "Submitted"}, <br />
{ok-button} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validated"} <br />
} <br />
} <br />
} <br />
} <br />
<br />
|| NOTE: In this case it is a composite of the styled controls StyleSheet, <br />
|| another StyleSheet, and an additional StyleRule. <br />
let ss:StyleSheet = <br />
{StyleSheet <br />
common-style-sheet, <br />
{get-default-style-sheet} <br />
} <br />
<br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{login-dialog tf, pf, cb} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating the Style Sheet File</span> <br />
Defining style sheet rules directly in your source code is a good approach for testing your rules. Once you are satisfied with the <span style="color: purple;" class="mycode_color">StyleRule</span>s, you can place them in one or more style sheet files. The default style sheet is a prime example of this implementation in which it has rules that implement a new look for all of the Curl GUI Toolkit controls. Let's first examine the the contents of the files that define the default style sheet. They are contained within two files: default-style.scurl and dss-defs.scurl (dss-defs.scurl is included in default-style.scurl). These files are located in the Curl install directory. For example, on Windows it is C:\Program Files\Curl Corporation\Surge\8\ide\gui\controls\styled-controls. <br />
<br />
<br />
One thing to recognize is that a style sheet in Curl is simply a file containing Curl code. The file extension is *.scurl and the last expression in this file must return a StyleSheet object. Aside from that, the file can include any Curl code that is needed to implement the style. In particular, you may need to import packages such as CURL.GUI.STANDARD in order to implement your style. <br />
<br />
<br />
Our style sheet file resembles the following: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>|| StyleSheet <br />
{import * from CURL.GUI.STANDARD} <br />
{StyleSheet <br />
{StyleRule CommandButton.ok, <br />
width = 1.75cm <br />
}, <br />
{StyleRule TextField.login, <br />
width = 2cm <br />
}, <br />
{StyleRule PasswordField.login, <br />
width = 2cm <br />
}, <br />
{StyleRule GroupBox.dialog, <br />
width = 4.5cm <br />
} <br />
}</code></div></div> <br />
In our login example, reference the <span style="color: purple;" class="mycode_color">StyleSheet</span> file using the <span style="color: purple;" class="mycode_color">url</span>. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{let common-style-sheet:StyleSheet = <br />
{url styles/my-styles/common-style-b.scurl} <br />
}</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
{let common-style-sheet:StyleSheet = <br />
{url "styles/my-styles/common-style-b.scurl"} <br />
} <br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
style-class="dialog", <br />
label = "", <br />
{Dialog <br />
use-look-and-feel? = false, <br />
{Table <br />
{row <br />
{cell {Label"Username:"}} <br />
{cell {value tf}} <br />
}, <br />
{row <br />
{cell {Label "Password: "}} <br />
{cell {value pf}} <br />
}, <br />
{row <br />
{cell <br />
colspan = 2, <br />
halign = "center", <br />
{value cb} <br />
} <br />
} <br />
}, <br />
{validate-with {DialogValidator}} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{TextField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let pf:PasswordField = <br />
{PasswordField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with {StringValidator}, required? = true} <br />
} <br />
<br />
let cb:CommandButton = <br />
{CommandButton <br />
style-class = "ok", <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{Dialog <br />
{GroupBox <br />
width = 4.5cm, <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
spacing = 0.1cm, <br />
{Label "Submitted"}, <br />
{ok-button} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validated"} <br />
} <br />
} <br />
} <br />
} <br />
<br />
|| NOTE: In this case it is a composite of the styled controls StyleSheet, <br />
|| another StyleSheet, and an additional StyleRule. <br />
let ss:StyleSheet = <br />
{StyleSheet <br />
common-style-sheet, <br />
{get-default-style-sheet} <br />
} <br />
<br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{login-dialog tf, pf, cb} <br />
} <br />
}</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Customization of Login Screen</code></div></div> <br />
The following code defines the customization of controls displayed in the "Custom" selection of our example applet. In the following applet we have customized the look and feel using a style sheet defined in the custom-style-sheet.scurl file. used in this applet can be viewed by selecting this link:<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".scurl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=51" target="_blank" title="">custom-style.scurl</a> (Size: 11.93 KB / Downloads: 1435)
<!-- end: postbit_attachments_attachment --> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
|| Identify the StyleSheets. <br />
|| The common StyleSheet sets up some rules (primarily widths) common to the <br />
|| different versions of the login form. <br />
{let common-style-sheet:StyleSheet = <br />
{url "styles/my-styles/common-style.scurl"} <br />
} <br />
|| The "custom" StyleSheet sets up rules for an appearance that is different <br />
|| from the "default" StyleSheet. <br />
{let custom-style-sheet:StyleSheet = <br />
{url "styles/my-styles/custom-style.scurl"} <br />
} <br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
label = "", <br />
{Dialog <br />
{Table <br />
{row-prototype <br />
{cell-prototype <br />
{TextDisplay <br />
|| Specify the style-class you want applied. <br />
style-class = "login", <br />
value = "Username: " <br />
} <br />
}, <br />
{cell-prototype tf} <br />
}, <br />
{row-prototype <br />
{cell-prototype <br />
{TextDisplay <br />
|| Specify the style-class you want applied. <br />
style-class = "login", <br />
value = "Password: " <br />
} <br />
}, <br />
{cell-prototype pf} <br />
}, <br />
{row-prototype <br />
{cell-prototype <br />
colspan = 2, <br />
halign = "center", <br />
cb <br />
} <br />
} <br />
} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{new TextField, <br />
style-class = "login", <br />
{on v:Validate at tf:TextField do <br />
{if not v.partial? then <br />
{if tf.value != "CurlUser" then <br />
let dlg:Dialog = <br />
{new Dialog, <br />
{GroupBox <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
{Fill height = 0.1cm}, <br />
{TextFlowBox <br />
paragraph-justify = <br />
"center", <br />
"The correct " &amp; <br />
"username is " &amp; <br />
"'CurlUser'." <br />
}, <br />
{Fill height = 0.1cm}, <br />
{CommandButton <br />
label = "OK", <br />
style-class = "ok", <br />
{on Action at cb:CommandButton <br />
do <br />
{cb.dialog.close <br />
"ok" <br />
} <br />
} <br />
}, <br />
{Fill height = 0.1cm} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validate"} <br />
{tf.mark-invalid} <br />
set tf.style-class = "validation-error" <br />
else <br />
set tf.style-class = "TextField" <br />
} <br />
} <br />
} <br />
} <br />
let pf:PasswordField = {new PasswordField} <br />
let cb:CommandButton = <br />
{CommandButton <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{new Dialog, <br />
{GroupBox <br />
label = "", <br />
{VBox <br />
halign = "center", <br />
{Fill height = 0.1cm}, <br />
{TextFlowBox <br />
text-breakable? = false, <br />
"Submitted" <br />
}, <br />
{Fill height = 0.1cm}, <br />
{CommandButton <br />
label = "OK", <br />
style-class = "ok", <br />
{on Action at <br />
cb:CommandButton <br />
do <br />
{cb.dialog.close <br />
"ok" <br />
} <br />
} <br />
}, <br />
{Fill height = 0.1cm} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validate"} <br />
} <br />
} <br />
} <br />
} <br />
|| Create a StyleSheet <br />
|| NOTE: In this case it is a composite of the common StyleSheet, and the <br />
|| custom StyleSheet. <br />
let ss:StyleSheet = <br />
{new StyleSheet, <br />
common-style-sheet, <br />
custom-style-sheet <br />
} <br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{StandardActiveTraversalContainer <br />
halign = "center", <br />
margin = 1cm, <br />
{login-dialog tf, pf, cb} <br />
} <br />
} <br />
}</code></div></div> <br />
For more information regarding paragraph formats, please refer to the Curl Styled Controls Library User's Guide that you installed in the Curl Documentation <br />
<br />
<br />
<br />
]]></description>
			<content:encoded><![CDATA[Style sheets are now supported in the Curl GUI Toolkit. (In version 6.0 they were available as an external library. This older note describes how to use styled sheets in version 6.0: Using Style Sheets - Curl 6.0 .) <br />
<br />
<br />
<br />
<br />
You can create and use one or more style sheet files in a Curl application. You can also create your StyleSheet objects directly in the Curl code. In general, follow these basic rules: <br />
<br />
" Each style sheet consists style rules and nested style sheets. <br />
<br />
" A nested style sheet can be defined in a curl file and imported by giving the url for the file. <br />
<br />
" Any nested style sheets must appear before the style rules. <br />
<br />
" A style rule consists of a selector string followed by any number of option settings. <br />
<br />
" If two rules specify the same option, the rule that comes later overrides the earlier rule. <br />
<br />
" If you set an option directly on an object, it cannot be overridden by a style rule. <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Style Sheet Syntax</span> <br />
In Curl, a <span style="color: purple;" class="mycode_color">StyleSheet</span> contains a set of rules that affect the look of the GUI objects the rules apply to. Each <span style="color: purple;" class="mycode_color">StyleRule</span> uses a pattern, or "selector", to identify the controls or GUI components that are affected by the rule. <br />
<br />
<br />
Let's examine a example style sheet definition. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let ss:StyleSheet <br />
{StyleSheet <br />
{StyleRule VBox.panel-vbox <br />
background = blue, <br />
margin = 2px, <br />
spacing = 4px <br />
} <br />
}</code></div></div> <br />
<br />
where: <br />
<br />
" ss a variable that defines the StyleSheet <br />
<br />
" VBox.panel-vbox is the selector <br />
<br />
" VBox is the <span style="color: purple;" class="mycode_color">style-element</span> <br />
<br />
" panel-vbox is the <span style="color: purple;" class="mycode_color">style-class</span> <br />
<br />
<br />
<br />
<br />
<br />
This selector has two components. For the rule to apply, the first component must match the <span style="color: purple;" class="mycode_color">style-element</span> property of an object and the second component must match the <span style="color: purple;" class="mycode_color">style-class</span> property. If either component is omitted, then it doesn't apply. (So ".panel-vbox" would apply to any object with a <span style="color: purple;" class="mycode_color">style-class</span> that includes the string "panel-vbox".) <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using the Style Sheet</span> <br />
<br />
<br />
Once you have a <span style="color: purple;" class="mycode_color">StyleSheet</span> defined, you can use the definitions after it has been installed. For example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{install-style-sheet ss}</code></div></div> <br />
<br />
In our example code, each time we call <span style="color: purple;" class="mycode_color">VBox</span>, we have the option of specifiying the <span style="color: purple;" class="mycode_color">style-class</span> of panel-vbox. For example: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value <br />
let my-panel:VBox = <br />
{VBox <br />
style-class = panel-vbox, <br />
{Frame Top content}, <br />
{Frame Bottom content} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a StyleSheet in the Login Example</span> <br />
Let's pull together these concepts and apply them to our login example. We created a style sheet common-style-sheet that contains definitions for common properties (widths) specified in the login screen. We can use these styles by specifying the style-class. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
|| Identify a StyleSheet <br />
|| The common StyleSheet sets up some rules (primarily widths) common to the <br />
|| different versions of the login form. <br />
{let common-style-sheet:StyleSheet = <br />
{StyleSheet <br />
{StyleRule "CommandButton.ok", <br />
width = 1.75cm <br />
}, <br />
{StyleRule "TextField.login", <br />
width = 2cm <br />
}, <br />
{StyleRule "PasswordField.login", <br />
width = 2cm <br />
}, <br />
{StyleRule "GroupBox.dialog", <br />
width = 4.5cm <br />
} <br />
} <br />
<br />
} <br />
<br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
style-class="dialog", <br />
label = "", <br />
{Dialog <br />
use-look-and-feel? = false, <br />
{Table <br />
{row <br />
{cell {Label"Username:"}} <br />
{cell {value tf}} <br />
}, <br />
{row <br />
{cell {Label "Password: "}} <br />
{cell {value pf}} <br />
}, <br />
{row <br />
{cell <br />
colspan = 2, <br />
halign = "center", <br />
{value cb} <br />
} <br />
} <br />
}, <br />
{validate-with {DialogValidator}} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{TextField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let pf:PasswordField = <br />
{PasswordField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with {StringValidator}, required? = true} <br />
} <br />
<br />
let cb:CommandButton = <br />
{CommandButton <br />
style-class = "ok", <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{Dialog <br />
{GroupBox <br />
width = 4.5cm, <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
spacing = 0.1cm, <br />
{Label "Submitted"}, <br />
{ok-button} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validated"} <br />
} <br />
} <br />
} <br />
} <br />
<br />
|| NOTE: In this case it is a composite of the styled controls StyleSheet, <br />
|| another StyleSheet, and an additional StyleRule. <br />
let ss:StyleSheet = <br />
{StyleSheet <br />
common-style-sheet, <br />
{get-default-style-sheet} <br />
} <br />
<br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{login-dialog tf, pf, cb} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating the Style Sheet File</span> <br />
Defining style sheet rules directly in your source code is a good approach for testing your rules. Once you are satisfied with the <span style="color: purple;" class="mycode_color">StyleRule</span>s, you can place them in one or more style sheet files. The default style sheet is a prime example of this implementation in which it has rules that implement a new look for all of the Curl GUI Toolkit controls. Let's first examine the the contents of the files that define the default style sheet. They are contained within two files: default-style.scurl and dss-defs.scurl (dss-defs.scurl is included in default-style.scurl). These files are located in the Curl install directory. For example, on Windows it is C:\Program Files\Curl Corporation\Surge\8\ide\gui\controls\styled-controls. <br />
<br />
<br />
One thing to recognize is that a style sheet in Curl is simply a file containing Curl code. The file extension is *.scurl and the last expression in this file must return a StyleSheet object. Aside from that, the file can include any Curl code that is needed to implement the style. In particular, you may need to import packages such as CURL.GUI.STANDARD in order to implement your style. <br />
<br />
<br />
Our style sheet file resembles the following: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>|| StyleSheet <br />
{import * from CURL.GUI.STANDARD} <br />
{StyleSheet <br />
{StyleRule CommandButton.ok, <br />
width = 1.75cm <br />
}, <br />
{StyleRule TextField.login, <br />
width = 2cm <br />
}, <br />
{StyleRule PasswordField.login, <br />
width = 2cm <br />
}, <br />
{StyleRule GroupBox.dialog, <br />
width = 4.5cm <br />
} <br />
}</code></div></div> <br />
In our login example, reference the <span style="color: purple;" class="mycode_color">StyleSheet</span> file using the <span style="color: purple;" class="mycode_color">url</span>. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{let common-style-sheet:StyleSheet = <br />
{url styles/my-styles/common-style-b.scurl} <br />
}</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
{let common-style-sheet:StyleSheet = <br />
{url "styles/my-styles/common-style-b.scurl"} <br />
} <br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
style-class="dialog", <br />
label = "", <br />
{Dialog <br />
use-look-and-feel? = false, <br />
{Table <br />
{row <br />
{cell {Label"Username:"}} <br />
{cell {value tf}} <br />
}, <br />
{row <br />
{cell {Label "Password: "}} <br />
{cell {value pf}} <br />
}, <br />
{row <br />
{cell <br />
colspan = 2, <br />
halign = "center", <br />
{value cb} <br />
} <br />
} <br />
}, <br />
{validate-with {DialogValidator}} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{TextField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let pf:PasswordField = <br />
{PasswordField <br />
style-class="login", <br />
width = 2cm, <br />
{validate-with {StringValidator}, required? = true} <br />
} <br />
<br />
let cb:CommandButton = <br />
{CommandButton <br />
style-class = "ok", <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{Dialog <br />
{GroupBox <br />
width = 4.5cm, <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
spacing = 0.1cm, <br />
{Label "Submitted"}, <br />
{ok-button} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validated"} <br />
} <br />
} <br />
} <br />
} <br />
<br />
|| NOTE: In this case it is a composite of the styled controls StyleSheet, <br />
|| another StyleSheet, and an additional StyleRule. <br />
let ss:StyleSheet = <br />
{StyleSheet <br />
common-style-sheet, <br />
{get-default-style-sheet} <br />
} <br />
<br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{login-dialog tf, pf, cb} <br />
} <br />
}</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Customization of Login Screen</code></div></div> <br />
The following code defines the customization of controls displayed in the "Custom" selection of our example applet. In the following applet we have customized the look and feel using a style sheet defined in the custom-style-sheet.scurl file. used in this applet can be viewed by selecting this link:<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".scurl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=51" target="_blank" title="">custom-style.scurl</a> (Size: 11.93 KB / Downloads: 1435)
<!-- end: postbit_attachments_attachment --> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet} <br />
<br />
|| Identify the StyleSheets. <br />
|| The common StyleSheet sets up some rules (primarily widths) common to the <br />
|| different versions of the login form. <br />
{let common-style-sheet:StyleSheet = <br />
{url "styles/my-styles/common-style.scurl"} <br />
} <br />
|| The "custom" StyleSheet sets up rules for an appearance that is different <br />
|| from the "default" StyleSheet. <br />
{let custom-style-sheet:StyleSheet = <br />
{url "styles/my-styles/custom-style.scurl"} <br />
} <br />
<br />
|| Form creation procs <br />
{define-proc {login-dialog <br />
tf:TextField, pf:PasswordField, cb:CommandButton <br />
}:Graphic <br />
{return <br />
{GroupBox <br />
label = "", <br />
{Dialog <br />
{Table <br />
{row-prototype <br />
{cell-prototype <br />
{TextDisplay <br />
|| Specify the style-class you want applied. <br />
style-class = "login", <br />
value = "Username: " <br />
} <br />
}, <br />
{cell-prototype tf} <br />
}, <br />
{row-prototype <br />
{cell-prototype <br />
{TextDisplay <br />
|| Specify the style-class you want applied. <br />
style-class = "login", <br />
value = "Password: " <br />
} <br />
}, <br />
{cell-prototype pf} <br />
}, <br />
{row-prototype <br />
{cell-prototype <br />
colspan = 2, <br />
halign = "center", <br />
cb <br />
} <br />
} <br />
} <br />
} <br />
} <br />
} <br />
} <br />
<br />
{value <br />
let tf:TextField = <br />
{new TextField, <br />
style-class = "login", <br />
{on v:Validate at tf:TextField do <br />
{if not v.partial? then <br />
{if tf.value != "CurlUser" then <br />
let dlg:Dialog = <br />
{new Dialog, <br />
{GroupBox <br />
label = "", <br />
{hcenter <br />
{VBox <br />
halign = "center", <br />
{Fill height = 0.1cm}, <br />
{TextFlowBox <br />
paragraph-justify = <br />
"center", <br />
"The correct " &amp; <br />
"username is " &amp; <br />
"'CurlUser'." <br />
}, <br />
{Fill height = 0.1cm}, <br />
{CommandButton <br />
label = "OK", <br />
style-class = "ok", <br />
{on Action at cb:CommandButton <br />
do <br />
{cb.dialog.close <br />
"ok" <br />
} <br />
} <br />
}, <br />
{Fill height = 0.1cm} <br />
} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validate"} <br />
{tf.mark-invalid} <br />
set tf.style-class = "validation-error" <br />
else <br />
set tf.style-class = "TextField" <br />
} <br />
} <br />
} <br />
} <br />
let pf:PasswordField = {new PasswordField} <br />
let cb:CommandButton = <br />
{CommandButton <br />
label = "Submit", <br />
{on Action at cb:CommandButton do <br />
{if-non-null dlg = cb.dialog then <br />
{if {validate-dialog dlg} then <br />
let dlg:Dialog = <br />
{new Dialog, <br />
{GroupBox <br />
label = "", <br />
{VBox <br />
halign = "center", <br />
{Fill height = 0.1cm}, <br />
{TextFlowBox <br />
text-breakable? = false, <br />
"Submitted" <br />
}, <br />
{Fill height = 0.1cm}, <br />
{CommandButton <br />
label = "OK", <br />
style-class = "ok", <br />
{on Action at <br />
cb:CommandButton <br />
do <br />
{cb.dialog.close <br />
"ok" <br />
} <br />
} <br />
}, <br />
{Fill height = 0.1cm} <br />
} <br />
} <br />
} <br />
{dlg.show title = "Validate"} <br />
} <br />
} <br />
} <br />
} <br />
|| Create a StyleSheet <br />
|| NOTE: In this case it is a composite of the common StyleSheet, and the <br />
|| custom StyleSheet. <br />
let ss:StyleSheet = <br />
{new StyleSheet, <br />
common-style-sheet, <br />
custom-style-sheet <br />
} <br />
|| Install the StyleSheet. <br />
{install-style-sheet ss} <br />
<br />
|| Create the UI. <br />
{Frame <br />
{StandardActiveTraversalContainer <br />
halign = "center", <br />
margin = 1cm, <br />
{login-dialog tf, pf, cb} <br />
} <br />
} <br />
}</code></div></div> <br />
For more information regarding paragraph formats, please refer to the Curl Styled Controls Library User's Guide that you installed in the Curl Documentation <br />
<br />
<br />
<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Styling1:Curl Styles]]></title>
			<link>https://communities.curl.com/showthread.php?tid=28</link>
			<pubDate>Thu, 16 Jun 2011 00:14:08 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=28</guid>
			<description><![CDATA[Curl supports custom style sheets that are similar in functionality to Cascading Style Sheets (CSS). It allows developers to control the style and layout of displayed Curl elements all at once.<br />
<br />
 <br />
A Curl style sheet is used to help authors of web pages to define colors, fonts, layout, and other aspects of document presentation. It is designed primarily to enable the separation of document content from document presentation. This separation can provide more flexibility and control in the specification of presentational characteristics and can reduce unnecessary complexity and repetition caused by intertwining the structural content with presentation styles.<br />
<br />
 <br />
In referring to the following applet, select the dropdown list to display three different login views.<br />
<br />
•The first item in the dropdown list displays controls created with Curl by removing the default style options.<br />
<br />
•The second item on the dropdown list displays controls using our default styles.<br />
<br />
•The third item on the dropdown list displays formatted controls using a custom style sheet.<br />
<br />
<br />
Note that the login screen does not implement a login procedure, rather it displays the controls for example purposes. We have, however, included validation on the text fields.<br />
<br />
 <br />
In this Curl Cue, we will be addressing the first two items: creating controls with Curl and using a default style sheet.  Creating custom style sheets will be discussed in a subsequent Curl Cue.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Default Style</span><br />
 <br />
Before we style controls, let's first create the login interface using Curl's default styling. From working with Curl containers and controls, you should be familiar with creating the following login screens. The following code displays standard look and feel of Curl graphical objects created to display a standard login screen.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet}<br />
<br />
|| Form creation procs<br />
{define-proc {login-dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tf:TextField, pf:PasswordField, cb:CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}:Graphic<br />
&nbsp;&nbsp; {return<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {GroupBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {row<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
}<br />
<br />
{value<br />
&nbsp;&nbsp; let tf:TextField =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with ValidationPattern.email-address, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let pf:PasswordField = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {PasswordField width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {StringValidator}, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let cb:CommandButton =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "Submit",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {on Action at cb:CommandButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if-non-null dlg = cb.dialog then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {dlg.show title = "Validated"}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {login-dialog tf, pf, cb}<br />
}</code></div></div><br />
[b]Removing Default Styling[.b]<br />
 <br />
 <br />
We can remove all default styling by using install-standard-look-and-feel.  This will remove all styling from the controls. Place this procedure at the top of your applet.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet}<br />
<br />
{install-standard-look-and-feel}<br />
<br />
|| Form creation procs<br />
{define-proc {login-dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tf:TextField, pf:PasswordField, cb:CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {value cb}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {DialogValidator}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
}<br />
<br />
{value<br />
&nbsp;&nbsp; let tf:TextField =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with ValidationPattern.email-address, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let pf:PasswordField = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {PasswordField width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {StringValidator}, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let cb:CommandButton =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "Submit",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {on Action at cb:CommandButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if-non-null dlg = cb.dialog then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if {validate-dialog dlg} then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let dlg:Dialog =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {login-dialog tf, pf, cb}<br />
}</code></div></div><br />
For more information please refer to the User Interface Basics section of the Curl Cues or in the Curl documentation:<br />
<br />
Curl Developer's Guide > Graphical User Interface > Dialogs and Controls..<br />
<br />
 <br />
 <br />
<br />
 For more information regarding style sheets, please refer to the Curl Styled Controls in the Curl Documentation<br />
 <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".curl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=49" target="_blank" title="">loginform.curl</a> (Size: 7.36 KB / Downloads: 1344)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Curl supports custom style sheets that are similar in functionality to Cascading Style Sheets (CSS). It allows developers to control the style and layout of displayed Curl elements all at once.<br />
<br />
 <br />
A Curl style sheet is used to help authors of web pages to define colors, fonts, layout, and other aspects of document presentation. It is designed primarily to enable the separation of document content from document presentation. This separation can provide more flexibility and control in the specification of presentational characteristics and can reduce unnecessary complexity and repetition caused by intertwining the structural content with presentation styles.<br />
<br />
 <br />
In referring to the following applet, select the dropdown list to display three different login views.<br />
<br />
•The first item in the dropdown list displays controls created with Curl by removing the default style options.<br />
<br />
•The second item on the dropdown list displays controls using our default styles.<br />
<br />
•The third item on the dropdown list displays formatted controls using a custom style sheet.<br />
<br />
<br />
Note that the login screen does not implement a login procedure, rather it displays the controls for example purposes. We have, however, included validation on the text fields.<br />
<br />
 <br />
In this Curl Cue, we will be addressing the first two items: creating controls with Curl and using a default style sheet.  Creating custom style sheets will be discussed in a subsequent Curl Cue.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Default Style</span><br />
 <br />
Before we style controls, let's first create the login interface using Curl's default styling. From working with Curl containers and controls, you should be familiar with creating the following login screens. The following code displays standard look and feel of Curl graphical objects created to display a standard login screen.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet}<br />
<br />
|| Form creation procs<br />
{define-proc {login-dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tf:TextField, pf:PasswordField, cb:CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}:Graphic<br />
&nbsp;&nbsp; {return<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {GroupBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Table<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {row<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {cell {Label"Username:"}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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sp;&nbsp; let tf:TextField =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with ValidationPattern.email-address, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let pf:PasswordField = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {PasswordField width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {StringValidator}, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let cb:CommandButton =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "Submit",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {on Action at cb:CommandButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if-non-null dlg = cb.dialog then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if {validate-dialog dlg} then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {dlg.show title = "Validated"}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {login-dialog tf, pf, cb}<br />
}</code></div></div><br />
[b]Removing Default Styling[.b]<br />
 <br />
 <br />
We can remove all default styling by using install-standard-look-and-feel.  This will remove all styling from the controls. Place this procedure at the top of your applet.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 7.0 applet}<br />
<br />
{install-standard-look-and-feel}<br />
<br />
|| Form creation procs<br />
{define-proc {login-dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tf:TextField, pf:PasswordField, cb:CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}:Graphic<br />
&nbsp;&nbsp; {return<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {GroupBox<br />
&nbsp;&n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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {DialogValidator}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
}<br />
<br />
{value<br />
&nbsp;&nbsp; let tf:TextField =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with ValidationPattern.email-address, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let pf:PasswordField = <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {PasswordField width = 2cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {validate-with {StringValidator}, required? = true}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; let cb:CommandButton =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = "Submit",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {on Action at cb:CommandButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if-non-null dlg = cb.dialog then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if {validate-dialog dlg} then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let dlg:Dialog =<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {Dialog<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {GroupBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; {login-dialog tf, pf, cb}<br />
}</code></div></div><br />
For more information please refer to the User Interface Basics section of the Curl Cues or in the Curl documentation:<br />
<br />
Curl Developer's Guide > Graphical User Interface > Dialogs and Controls..<br />
<br />
 <br />
 <br />
<br />
 For more information regarding style sheets, please refer to the Curl Styled Controls in the Curl Documentation<br />
 <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".curl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=49" target="_blank" title="">loginform.curl</a> (Size: 7.36 KB / Downloads: 1344)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Persistent Data2:HTTP Cookies]]></title>
			<link>https://communities.curl.com/showthread.php?tid=27</link>
			<pubDate>Wed, 15 Jun 2011 08:27:27 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=27</guid>
			<description><![CDATA[HTTP Cookies are a standard Web mechanism for state management that allows a server to communicate with a client for purposes of: <br />
<br />
•Authentication <br />
<br />
•Security <br />
<br />
•End user identification <br />
<br />
•Preserving application state <br />
<br />
<br />
<br />
<br />
<br />
Cookies are a way for a server to send information to a client to store, and for the server to later retrieve its data from that client. Servers send cookies to clients by adding fields to HTTP response headers. Clients return cookies to the server by adding fields to HTTP request headers. The information is stored in text files on the client's machine. <br />
<br />
<br />
In the previous Curl Cue, we discussed the power of storing data on the client machine using Curl's Client-side persistent data. So... Why Would a Curl Applet Need to Use HTTP Cookies? HTTP Cookies are mainly used for storing session information when a Curl applet interacts with a server-side application that requires a cookie. An HTTP cookie contains a session identifier as well as other relevant information about the user -- therefore cookies are necessary when a Curl applet interacts with servers that require a session. Each session has a beginning and an end, can be relatively short-lived, and can be terminated by either the client or the server <br />
<br />
<br />
For example, if a user logs into a Curl application, you may need get session information from a server. A cookie is sent to the Curl applet upon start up. Once the Curl applet has the cookie data stored, the information is sent to the associated URI with each request. <br />
<br />
<img src="attachment.php?aid=48" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Working with HTTP Cookies</span> <br />
<br />
<br />
HTTP Cookies can either be secure or insecure. If you have a secure connection, you can use the HTTPS protocol for communication with the server. For our examples, we will use insecure cookies. <br />
<br />
<br />
In general, HTTP Cookies are: <br />
<br />
•Stored on a client machine as text <br />
<br />
•Grouped by URI <br />
<br />
•Sent to the server when the specific URI is requested <br />
<br />
<br />
<br />
<br />
<br />
This <span style="color: purple;" class="mycode_color">HttpCookie</span> class holds all data associated with an HTTP cookie. The associated <span style="color: purple;" class="mycode_color">HttpCookie</span> fields that store the HTTP cookie information are: <br />
<br />
<br />
•comment: A comment about the cookie variable. <br />
<br />
•domain: Domain that the hostname in the URL must match for the cookie to be sent along with requests for that URL. <br />
<br />
•expires: When the cookie should expire. <br />
<br />
•max-age: How long the cookie should last. <br />
<br />
•name: Name of the cookie variable. <br />
<br />
•path: Path that the URL must start with for the cookie to be sent along with requests for that URL. <br />
<br />
•secure?: Indicates whether this HttpCookie should be sent across "secure" channels such as that provided by HTTPS. <br />
<br />
•value: Value of the cookie variable. <br />
<br />
•version: Version of the cookie protocol being used; currently 1 is the only known legal value. <br />
<br />
<br />
<br />
<br />
<br />
Note that When the cookie should expire if expires is null, the cookie is kept only until the current host process exits. Once expires is in the past, the cookie may be deleted. If expires is in the future, the cookie is saved, possibly on disk, until the expiration date. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Setting and Getting HTTP Cookies</span> <br />
Use <span style="color: purple;" class="mycode_color">set-insecure-http-cookie</span> to create the cookie on the local machine. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>|| Let the cookie expire 1 year from now <br />
let expire-date:DateTime = {new DateTime} + (1day *365) <br />
|| Set the cookie <br />
{set-insecure-http-cookie <br />
{get-the-applet}.url, <br />
{HttpCookie <br />
session-id, <br />
My session, <br />
expires = expire-date <br />
} <br />
}</code></div></div> <br />
<br />
Once this information is set, then the cookie data is set with future HTTP requests to the given URI. Also note that <span style="color: purple;" class="mycode_color">get-the-applet</span> returns the <span style="color: purple;" class="mycode_color">Url</span> of the running applet. <br />
<br />
<br />
Use <span style="color: purple;" class="mycode_color">get-http-cookies</span> to retrieve cookie data. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let jar:{Array-of HttpCookie} = {get-http-cookies <br />
{get-the-applet}.url <br />
}</code></div></div> <br />
<br />
You can also use <span style="color: purple;" class="mycode_color">clear-insecure-http-cookie</span> to clear any cookies. In most cases, you will use <span style="color: purple;" class="mycode_color">clear-insecure-http-cookie</span> to remove cookies before the session ends (unless you want the information stored on the local machine for future use). <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Putting it all together...</span> <br />
<br />
Ok, let's put everything together. In the following appley we will create a cookie that stores the value of My session that is set to expire 1 year from the creation date. Since cookies require the a browser, the applet must be run over HTTP. Therefore the code has been enclosed in a <span style="color: purple;" class="mycode_color">try</span> expression so that we can <span style="color: purple;" class="mycode_color">catch</span> any <span style="color: purple;" class="mycode_color">HttpException</span>s. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes <br />
character-encoding = "utf8" <br />
} <br />
{value <br />
<br />
|| Create a cookie value to set <br />
let session-id:String = "My session" <br />
<br />
|| Let the cookie expire 1 year from now <br />
let expire-date:DateTime = {new DateTime} + (1day *365) <br />
{try <br />
|| Clear previous cookies <br />
{clear-insecure-http-cookie <br />
{get-the-applet}.url, <br />
"session-id" <br />
} <br />
<br />
|| Set the cookie with the session-id value <br />
{set-insecure-http-cookie <br />
{get-the-applet}.url, <br />
{HttpCookie <br />
"session-id", <br />
session-id , <br />
expires = expire-date <br />
} <br />
} <br />
<br />
|| Get cookie information <br />
let jar:{Array-of HttpCookie} = <br />
{get-http-cookies <br />
{get-the-applet}.url <br />
} <br />
<br />
|| Loop through the cookie data to find the session-id <br />
{for cookie:HttpCookie in jar do <br />
{if cookie.name == "sessionid" then <br />
set session-id = cookie.value <br />
else <br />
|| Do nothing <br />
} <br />
} <br />
catch e:HttpException do <br />
set session-id = "You must run this applet over HTTP" <br />
<br />
} <br />
<br />
<br />
<br />
|| Create a graphic to hold the information <br />
let display:VBox = {VBox <br />
background = "yellow", <br />
|| Dispaly the cookie value <br />
session-id <br />
} <br />
<br />
|| Return the display <br />
display <br />
}</code></div></div> <br />
Cookies and Security The only cookies an unprivileged applet can set or clear are those that would be sent with the applet's URL or with the applet's URL's parent directory. Keep in mind that unless the cookie has secure?=true and is used with https URLs, it could be seen by third party applications (snooping) on the network. In addition, unless expires=null, the cookie may be stored on disk. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=48" target="_blank" title="">communication.png</a> (Size: 37.44 KB / Downloads: 5410)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[HTTP Cookies are a standard Web mechanism for state management that allows a server to communicate with a client for purposes of: <br />
<br />
•Authentication <br />
<br />
•Security <br />
<br />
•End user identification <br />
<br />
•Preserving application state <br />
<br />
<br />
<br />
<br />
<br />
Cookies are a way for a server to send information to a client to store, and for the server to later retrieve its data from that client. Servers send cookies to clients by adding fields to HTTP response headers. Clients return cookies to the server by adding fields to HTTP request headers. The information is stored in text files on the client's machine. <br />
<br />
<br />
In the previous Curl Cue, we discussed the power of storing data on the client machine using Curl's Client-side persistent data. So... Why Would a Curl Applet Need to Use HTTP Cookies? HTTP Cookies are mainly used for storing session information when a Curl applet interacts with a server-side application that requires a cookie. An HTTP cookie contains a session identifier as well as other relevant information about the user -- therefore cookies are necessary when a Curl applet interacts with servers that require a session. Each session has a beginning and an end, can be relatively short-lived, and can be terminated by either the client or the server <br />
<br />
<br />
For example, if a user logs into a Curl application, you may need get session information from a server. A cookie is sent to the Curl applet upon start up. Once the Curl applet has the cookie data stored, the information is sent to the associated URI with each request. <br />
<br />
<img src="attachment.php?aid=48" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Working with HTTP Cookies</span> <br />
<br />
<br />
HTTP Cookies can either be secure or insecure. If you have a secure connection, you can use the HTTPS protocol for communication with the server. For our examples, we will use insecure cookies. <br />
<br />
<br />
In general, HTTP Cookies are: <br />
<br />
•Stored on a client machine as text <br />
<br />
•Grouped by URI <br />
<br />
•Sent to the server when the specific URI is requested <br />
<br />
<br />
<br />
<br />
<br />
This <span style="color: purple;" class="mycode_color">HttpCookie</span> class holds all data associated with an HTTP cookie. The associated <span style="color: purple;" class="mycode_color">HttpCookie</span> fields that store the HTTP cookie information are: <br />
<br />
<br />
•comment: A comment about the cookie variable. <br />
<br />
•domain: Domain that the hostname in the URL must match for the cookie to be sent along with requests for that URL. <br />
<br />
•expires: When the cookie should expire. <br />
<br />
•max-age: How long the cookie should last. <br />
<br />
•name: Name of the cookie variable. <br />
<br />
•path: Path that the URL must start with for the cookie to be sent along with requests for that URL. <br />
<br />
•secure?: Indicates whether this HttpCookie should be sent across "secure" channels such as that provided by HTTPS. <br />
<br />
•value: Value of the cookie variable. <br />
<br />
•version: Version of the cookie protocol being used; currently 1 is the only known legal value. <br />
<br />
<br />
<br />
<br />
<br />
Note that When the cookie should expire if expires is null, the cookie is kept only until the current host process exits. Once expires is in the past, the cookie may be deleted. If expires is in the future, the cookie is saved, possibly on disk, until the expiration date. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Setting and Getting HTTP Cookies</span> <br />
Use <span style="color: purple;" class="mycode_color">set-insecure-http-cookie</span> to create the cookie on the local machine. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>|| Let the cookie expire 1 year from now <br />
let expire-date:DateTime = {new DateTime} + (1day *365) <br />
|| Set the cookie <br />
{set-insecure-http-cookie <br />
{get-the-applet}.url, <br />
{HttpCookie <br />
session-id, <br />
My session, <br />
expires = expire-date <br />
} <br />
}</code></div></div> <br />
<br />
Once this information is set, then the cookie data is set with future HTTP requests to the given URI. Also note that <span style="color: purple;" class="mycode_color">get-the-applet</span> returns the <span style="color: purple;" class="mycode_color">Url</span> of the running applet. <br />
<br />
<br />
Use <span style="color: purple;" class="mycode_color">get-http-cookies</span> to retrieve cookie data. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let jar:{Array-of HttpCookie} = {get-http-cookies <br />
{get-the-applet}.url <br />
}</code></div></div> <br />
<br />
You can also use <span style="color: purple;" class="mycode_color">clear-insecure-http-cookie</span> to clear any cookies. In most cases, you will use <span style="color: purple;" class="mycode_color">clear-insecure-http-cookie</span> to remove cookies before the session ends (unless you want the information stored on the local machine for future use). <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Putting it all together...</span> <br />
<br />
Ok, let's put everything together. In the following appley we will create a cookie that stores the value of My session that is set to expire 1 year from the creation date. Since cookies require the a browser, the applet must be run over HTTP. Therefore the code has been enclosed in a <span style="color: purple;" class="mycode_color">try</span> expression so that we can <span style="color: purple;" class="mycode_color">catch</span> any <span style="color: purple;" class="mycode_color">HttpException</span>s. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes <br />
character-encoding = "utf8" <br />
} <br />
{value <br />
<br />
|| Create a cookie value to set <br />
let session-id:String = "My session" <br />
<br />
|| Let the cookie expire 1 year from now <br />
let expire-date:DateTime = {new DateTime} + (1day *365) <br />
{try <br />
|| Clear previous cookies <br />
{clear-insecure-http-cookie <br />
{get-the-applet}.url, <br />
"session-id" <br />
} <br />
<br />
|| Set the cookie with the session-id value <br />
{set-insecure-http-cookie <br />
{get-the-applet}.url, <br />
{HttpCookie <br />
"session-id", <br />
session-id , <br />
expires = expire-date <br />
} <br />
} <br />
<br />
|| Get cookie information <br />
let jar:{Array-of HttpCookie} = <br />
{get-http-cookies <br />
{get-the-applet}.url <br />
} <br />
<br />
|| Loop through the cookie data to find the session-id <br />
{for cookie:HttpCookie in jar do <br />
{if cookie.name == "sessionid" then <br />
set session-id = cookie.value <br />
else <br />
|| Do nothing <br />
} <br />
} <br />
catch e:HttpException do <br />
set session-id = "You must run this applet over HTTP" <br />
<br />
} <br />
<br />
<br />
<br />
|| Create a graphic to hold the information <br />
let display:VBox = {VBox <br />
background = "yellow", <br />
|| Dispaly the cookie value <br />
session-id <br />
} <br />
<br />
|| Return the display <br />
display <br />
}</code></div></div> <br />
Cookies and Security The only cookies an unprivileged applet can set or clear are those that would be sent with the applet's URL or with the applet's URL's parent directory. Keep in mind that unless the cookie has secure?=true and is used with https URLs, it could be seen by third party applications (snooping) on the network. In addition, unless expires=null, the cookie may be stored on disk. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=48" target="_blank" title="">communication.png</a> (Size: 37.44 KB / Downloads: 5410)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Persistent Data1:Client-side Persistent Data]]></title>
			<link>https://communities.curl.com/showthread.php?tid=26</link>
			<pubDate>Wed, 15 Jun 2011 08:24:10 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=26</guid>
			<description><![CDATA[How do we keep data around to access it later? Or perhaps keep data for another invocation of the same program? To maximize usability and effectiveness, an application must be able to store relevant client data to disk. Depending on the type of application, client data can contain information such as: <br />
<br />
•User preferences <br />
<br />
•Visual displays <br />
<br />
•Game scores <br />
<br />
•Application settings <br />
<br />
<br />
<br />
<br />
<br />
This data can be retrieved at a later time and further processed. Depending on the application, the data can be stored either locally or remotely. In either case, when the application exits, information regarding the state is written. When the user accesses the application at a later time, that same information is read to return the user to the previous state. <br />
<br />
<br />
Persistent data is data that a Web application should 'remember' as the user moves between pages. There are different approaches to storing information. The approaches depend on the architecture of the system, i.e. whether the program needs to communicate with the server or not. <br />
<br />
<br />
Instead of explicitly writing to a file, small amounts of data can be stored on a client machine using: <br />
<br />
•Client-side persistent data (CSPD) <br />
<br />
•HTTP Cookies <br />
<br />
<br />
<br />
<br />
<br />
In this Curl Cue, we will concentrate on CSPD in which data is stored in a separate repository on the local machine. The Curl runtime environment handles that process of data storage and retrieval automatically. Thus, this provides a consistent method of data storage and retrieval. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Client-side Persistent Data</span> <br />
<br />
<br />
Curl's Client-side Persistent Data system allows you to store small amounts of data on the client without explicitly writing to a file. Data is stored in a Curl-specific repository in which the data can: <br />
<br />
•Handle multiple formats of data <br />
<br />
•Be set to expire <br />
<br />
•Limit the amount of data stored <br />
<br />
•Share data between two or more related applets <br />
<img src="attachment.php?aid=46" /> <br />
Why should you use CSPD? <br />
<br />
<br />
Applets written in the Curl language cannot read from or write to the file system unless they are privileged. This restriction poses problems if your application needs to store applet data. Applets that have been run from a Web site could transmit data back to the host system, but this can be slow and could put a strain on the server. In addition, the data involved may be specific to the user or the client machine, such as the user name. Instead, you can use the persistent data system to store small amounts of data on the client. <br />
<br />
<br />
CSPD stores and retrieves data using key/value pairs. The steps are as follows: <br />
<br />
1.Define a private persistent data repository <br />
<br />
2.Write key/value pairs to the repository <br />
<br />
3.Commit the repository <br />
<br />
4.At a later time, use the key name to retrieve data from the repository <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating the Repository</span> <br />
<br />
<br />
Create the private persistent data repository using the <span style="color: purple;" class="mycode_color">persistent-data</span> procedure. This procedure call needs to occur at the top-level of your file (outside of any code block). It must appear before any attempt to read or store data in the repository. <br />
<br />
<br />
In the following code, we are defining a repository that will store values for up to 180 days (if not accessed) and that has a maximum size of 1024 bytes. The "Date storage" argument is a required comment that describes what is stored in the repository. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{persistent-data <br />
Date storage, <br />
duration = 180days, <br />
max-size = 1024 <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Setting and Committing Persistent Data</span> <br />
<br />
<br />
Each item stored in a repository is identified by a key (or name). Each key has a datatype of <span style="color: purple;" class="mycode_color">String</span> in which it cannot contain slashes (/) (otherwise there are no restrictions). To store data in the repository, call the <span style="color: purple;" class="mycode_color">set-persistent-data</span> procedure, passing it a key and the associated data. <br />
<br />
<br />
In the following example, the key is visit data and the data will be the current time (stored as a string). <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{set-persistent-data visit date, {String {DateTime}}}</code></div></div> <br />
<br />
<br />
After you have added all of the data you want to store in the repository, you need to call <span style="color: purple;" class="mycode_color">commit-persistent-data</span> to store the data to disk. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{commit-persistent-data}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Retrieving CSPD Values</span> <br />
<br />
<br />
Use the <span style="color: purple;" class="mycode_color">get-persistent-data</span> procedure to get data from the repository. You specify the key, and the procedure returns the value associated with the key. Returned values have the same data type as the stored data. <br />
<br />
<br />
If the key does not match an entry in the repository, a <span style="color: purple;" class="mycode_color">KeyNotFoundException</span> is thrown. Therefore, it is wise to use a <span style="color: purple;" class="mycode_color">try</span> expression with a <span style="color: purple;" class="mycode_color">catch</span> clause to handle any exceptions. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{try <br />
set x = {get-persistent-data visit date} <br />
catch not-found:KeyNotFoundException do <br />
set x = You have not been here before <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Putting it all together</span> <br />
<br />
<br />
Let's put the entire example together. Note that since CSPD is stored on each client machine, you will get a different time stamp than your neighbor! <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes <br />
character-encoding = "utf8" <br />
} <br />
<br />
|| Defining the repository <br />
{persistent-data <br />
"Date storage", <br />
duration = 180days, <br />
max-size = 1024 <br />
} <br />
<br />
{value <br />
<br />
|| Retrieving persistent data <br />
let x:#String <br />
{try <br />
set x = {get-persistent-data "visit date"} <br />
catch not-found:KeyNotFoundException do <br />
set x = "You have not been here before" <br />
} <br />
<br />
<br />
|| Setting and committing persistent data <br />
{set-persistent-data "visit date",{String {DateTime}}} <br />
{commit-persistent-data} <br />
<br />
<br />
|| Returning the value of x <br />
{text The last time you visited this site was: {value x}} <br />
<br />
}</code></div></div> <br />
For more information regarding Curl's Client-side persistent data system, please refer to the Curl Developer's Guide under Interacting with External Resources/Client-side Persistent Data. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=46" target="_blank" title="">cspd.png</a> (Size: 58.81 KB / Downloads: 2693)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[How do we keep data around to access it later? Or perhaps keep data for another invocation of the same program? To maximize usability and effectiveness, an application must be able to store relevant client data to disk. Depending on the type of application, client data can contain information such as: <br />
<br />
•User preferences <br />
<br />
•Visual displays <br />
<br />
•Game scores <br />
<br />
•Application settings <br />
<br />
<br />
<br />
<br />
<br />
This data can be retrieved at a later time and further processed. Depending on the application, the data can be stored either locally or remotely. In either case, when the application exits, information regarding the state is written. When the user accesses the application at a later time, that same information is read to return the user to the previous state. <br />
<br />
<br />
Persistent data is data that a Web application should 'remember' as the user moves between pages. There are different approaches to storing information. The approaches depend on the architecture of the system, i.e. whether the program needs to communicate with the server or not. <br />
<br />
<br />
Instead of explicitly writing to a file, small amounts of data can be stored on a client machine using: <br />
<br />
•Client-side persistent data (CSPD) <br />
<br />
•HTTP Cookies <br />
<br />
<br />
<br />
<br />
<br />
In this Curl Cue, we will concentrate on CSPD in which data is stored in a separate repository on the local machine. The Curl runtime environment handles that process of data storage and retrieval automatically. Thus, this provides a consistent method of data storage and retrieval. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Client-side Persistent Data</span> <br />
<br />
<br />
Curl's Client-side Persistent Data system allows you to store small amounts of data on the client without explicitly writing to a file. Data is stored in a Curl-specific repository in which the data can: <br />
<br />
•Handle multiple formats of data <br />
<br />
•Be set to expire <br />
<br />
•Limit the amount of data stored <br />
<br />
•Share data between two or more related applets <br />
<img src="attachment.php?aid=46" /> <br />
Why should you use CSPD? <br />
<br />
<br />
Applets written in the Curl language cannot read from or write to the file system unless they are privileged. This restriction poses problems if your application needs to store applet data. Applets that have been run from a Web site could transmit data back to the host system, but this can be slow and could put a strain on the server. In addition, the data involved may be specific to the user or the client machine, such as the user name. Instead, you can use the persistent data system to store small amounts of data on the client. <br />
<br />
<br />
CSPD stores and retrieves data using key/value pairs. The steps are as follows: <br />
<br />
1.Define a private persistent data repository <br />
<br />
2.Write key/value pairs to the repository <br />
<br />
3.Commit the repository <br />
<br />
4.At a later time, use the key name to retrieve data from the repository <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating the Repository</span> <br />
<br />
<br />
Create the private persistent data repository using the <span style="color: purple;" class="mycode_color">persistent-data</span> procedure. This procedure call needs to occur at the top-level of your file (outside of any code block). It must appear before any attempt to read or store data in the repository. <br />
<br />
<br />
In the following code, we are defining a repository that will store values for up to 180 days (if not accessed) and that has a maximum size of 1024 bytes. The "Date storage" argument is a required comment that describes what is stored in the repository. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{persistent-data <br />
Date storage, <br />
duration = 180days, <br />
max-size = 1024 <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Setting and Committing Persistent Data</span> <br />
<br />
<br />
Each item stored in a repository is identified by a key (or name). Each key has a datatype of <span style="color: purple;" class="mycode_color">String</span> in which it cannot contain slashes (/) (otherwise there are no restrictions). To store data in the repository, call the <span style="color: purple;" class="mycode_color">set-persistent-data</span> procedure, passing it a key and the associated data. <br />
<br />
<br />
In the following example, the key is visit data and the data will be the current time (stored as a string). <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{set-persistent-data visit date, {String {DateTime}}}</code></div></div> <br />
<br />
<br />
After you have added all of the data you want to store in the repository, you need to call <span style="color: purple;" class="mycode_color">commit-persistent-data</span> to store the data to disk. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{commit-persistent-data}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Retrieving CSPD Values</span> <br />
<br />
<br />
Use the <span style="color: purple;" class="mycode_color">get-persistent-data</span> procedure to get data from the repository. You specify the key, and the procedure returns the value associated with the key. Returned values have the same data type as the stored data. <br />
<br />
<br />
If the key does not match an entry in the repository, a <span style="color: purple;" class="mycode_color">KeyNotFoundException</span> is thrown. Therefore, it is wise to use a <span style="color: purple;" class="mycode_color">try</span> expression with a <span style="color: purple;" class="mycode_color">catch</span> clause to handle any exceptions. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{try <br />
set x = {get-persistent-data visit date} <br />
catch not-found:KeyNotFoundException do <br />
set x = You have not been here before <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Putting it all together</span> <br />
<br />
<br />
Let's put the entire example together. Note that since CSPD is stored on each client machine, you will get a different time stamp than your neighbor! <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes <br />
character-encoding = "utf8" <br />
} <br />
<br />
|| Defining the repository <br />
{persistent-data <br />
"Date storage", <br />
duration = 180days, <br />
max-size = 1024 <br />
} <br />
<br />
{value <br />
<br />
|| Retrieving persistent data <br />
let x:#String <br />
{try <br />
set x = {get-persistent-data "visit date"} <br />
catch not-found:KeyNotFoundException do <br />
set x = "You have not been here before" <br />
} <br />
<br />
<br />
|| Setting and committing persistent data <br />
{set-persistent-data "visit date",{String {DateTime}}} <br />
{commit-persistent-data} <br />
<br />
<br />
|| Returning the value of x <br />
{text The last time you visited this site was: {value x}} <br />
<br />
}</code></div></div> <br />
For more information regarding Curl's Client-side persistent data system, please refer to the Curl Developer's Guide under Interacting with External Resources/Client-side Persistent Data. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=46" target="_blank" title="">cspd.png</a> (Size: 58.81 KB / Downloads: 2693)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Serving Content3:Dynamically Generating Curl Content]]></title>
			<link>https://communities.curl.com/showthread.php?tid=25</link>
			<pubDate>Wed, 15 Jun 2011 08:19:57 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=25</guid>
			<description><![CDATA[With server-side technologies such as ASP and PHP, you can use Curl applets that are generated on the fly. Dynamic data can be placed into a Curl applet that is sent from a server to the user's browser. <br />
<br />
<br />
Curl works with server languages such as ASP, JSP, PHP, and CGI. Scripts in these languages can generate Curl applets to be launched on the client machine, after which all Curl processing happens on the client machine. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Generating Curl from a Script </span> <br />
In the following examples, we are using ASP or PHP to dynamically generate Curl content. If you are familiar with scripting languages, you will notice that what would otherwise be HTML has been replaced with Curl code. <br />
<br />
<br />
In either case, you will have to: <br />
<br />
<br />
1.Identify the server scripting language, for example: ?php <br />
<br />
2.State the MIME type declaration for Curl content, for example: text/vnd.curl <br />
<br />
3.Embed correctly formed Curl applet code <br />
<br />
<br />
The following examples both generate similar Curl code. They produce a display like this when run. <br />
<br />
<img src="attachment.php?aid=41" /> <br />
PHP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/** <br />
* <br />
* PHP example <br />
* <br />
*/ <br />
header('Content-type: text/vnd.curl'); <br />
// All of the above code is PHP. <br />
// What follows the next line (i.e., after "echo &lt;{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"A PHP script on the server generated this applet." <br />
} <br />
} <br />
} <br />
} <br />
<br />
END; <br />
// The Curl code ended before the previous line (i.e., before "END;"). <br />
?&gt;</code></div></div> <br />
<br />
ASP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"An ASP script on the server generated this applet." <br />
} <br />
} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Passing Variables from a Script </span> <br />
The previous examples demonstrate how to generate Curl content directly from a server script. Now we are adding in the use of variables. It is common that you may have script variables that store relevant information about the session such as: <br />
<br />
<br />
•Session ID <br />
<br />
•Cookie information <br />
<br />
•Username <br />
<br />
•Other user identification information <br />
<br />
<br />
The following is an example of Curl being generated by a PHP script. It includes the use of a variable (&#36;variable) which is set by calling a function in a separate PHP file to obtain a username for display in the Curl applet. <br />
<br />
<br />
The resulting content displayed is: <br />
<img src="attachment.php?aid=43" /> <br />
PHP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// Include any supporting PHP code. <br />
include("supporting-php-code.php"); <br />
<br />
// Set the Curl MIME type <br />
header('Content-type: text/vnd.curl'); <br />
<br />
// Set a variable using your PHP code. <br />
&#36;variable = getUsername(); <br />
<br />
// All of the above code is PHP. <br />
// What follows the next line (i.e., after "echo &lt;{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"Hello " &amp; "&#36;variable" &amp; "!" <br />
} <br />
} <br />
} <br />
} <br />
<br />
END; <br />
// The Curl code ended before the previous line (i.e., before "END;"). <br />
?&gt;</code></div></div> <br />
<br />
Notice on the code displayed above that we are including supporting PHP code. In this case, the file supporting-php-code.php contains the following content: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>function getUsername() { <br />
return "Curl User"; <br />
} <br />
?&gt;</code></div></div> <br />
In an actual application, the getUsername function retrieves information from one of the data sources mentioned above. <br />
<br />
<br />
ASP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"Hello " &amp; "" &amp; "!" <br />
} <br />
} <br />
} <br />
}</code></div></div> <br />
<br />
Other ways to run Curl applets include the following: <br />
<br />
•Launching a Curl applet from another Curl applet. Please see Launching a Curl Applet. <br />
<br />
•Embedding Curl in HTML. Please see Launching and Embedding Curl in HTML. <br />
<br />
<br />
<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=41" target="_blank" title="">phpscript.jpg</a> (Size: 7.48 KB / Downloads: 1821)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=43" target="_blank" title="">phpvariable.jpg</a> (Size: 4.96 KB / Downloads: 1886)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[With server-side technologies such as ASP and PHP, you can use Curl applets that are generated on the fly. Dynamic data can be placed into a Curl applet that is sent from a server to the user's browser. <br />
<br />
<br />
Curl works with server languages such as ASP, JSP, PHP, and CGI. Scripts in these languages can generate Curl applets to be launched on the client machine, after which all Curl processing happens on the client machine. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Generating Curl from a Script </span> <br />
In the following examples, we are using ASP or PHP to dynamically generate Curl content. If you are familiar with scripting languages, you will notice that what would otherwise be HTML has been replaced with Curl code. <br />
<br />
<br />
In either case, you will have to: <br />
<br />
<br />
1.Identify the server scripting language, for example: ?php <br />
<br />
2.State the MIME type declaration for Curl content, for example: text/vnd.curl <br />
<br />
3.Embed correctly formed Curl applet code <br />
<br />
<br />
The following examples both generate similar Curl code. They produce a display like this when run. <br />
<br />
<img src="attachment.php?aid=41" /> <br />
PHP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/** <br />
* <br />
* PHP example <br />
* <br />
*/ <br />
header('Content-type: text/vnd.curl'); <br />
// All of the above code is PHP. <br />
// What follows the next line (i.e., after "echo &lt;{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"A PHP script on the server generated this applet." <br />
} <br />
} <br />
} <br />
} <br />
<br />
END; <br />
// The Curl code ended before the previous line (i.e., before "END;"). <br />
?&gt;</code></div></div> <br />
<br />
ASP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"An ASP script on the server generated this applet." <br />
} <br />
} <br />
} <br />
}</code></div></div> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Passing Variables from a Script </span> <br />
The previous examples demonstrate how to generate Curl content directly from a server script. Now we are adding in the use of variables. It is common that you may have script variables that store relevant information about the session such as: <br />
<br />
<br />
•Session ID <br />
<br />
•Cookie information <br />
<br />
•Username <br />
<br />
•Other user identification information <br />
<br />
<br />
The following is an example of Curl being generated by a PHP script. It includes the use of a variable (&#36;variable) which is set by calling a function in a separate PHP file to obtain a username for display in the Curl applet. <br />
<br />
<br />
The resulting content displayed is: <br />
<img src="attachment.php?aid=43" /> <br />
PHP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>// Include any supporting PHP code. <br />
include("supporting-php-code.php"); <br />
<br />
// Set the Curl MIME type <br />
header('Content-type: text/vnd.curl'); <br />
<br />
// Set a variable using your PHP code. <br />
&#36;variable = getUsername(); <br />
<br />
// All of the above code is PHP. <br />
// What follows the next line (i.e., after "echo &lt;{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"Hello " &amp; "&#36;variable" &amp; "!" <br />
} <br />
} <br />
} <br />
} <br />
<br />
END; <br />
// The Curl code ended before the previous line (i.e., before "END;"). <br />
?&gt;</code></div></div> <br />
<br />
Notice on the code displayed above that we are including supporting PHP code. In this case, the file supporting-php-code.php contains the following content: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>function getUsername() { <br />
return "Curl User"; <br />
} <br />
?&gt;</code></div></div> <br />
In an actual application, the getUsername function retrieves information from one of the data sources mentioned above. <br />
<br />
<br />
ASP Example <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 5.0 applet} <br />
<br />
{value <br />
{Frame <br />
width = 5cm, <br />
height = 5cm, <br />
border-color = "gray", <br />
border-width = 0.1cm, <br />
border-style = "raised", <br />
background = "#4578ef", <br />
{hcenter <br />
{vcenter <br />
"Hello " &amp; "" &amp; "!" <br />
} <br />
} <br />
} <br />
}</code></div></div> <br />
<br />
Other ways to run Curl applets include the following: <br />
<br />
•Launching a Curl applet from another Curl applet. Please see Launching a Curl Applet. <br />
<br />
•Embedding Curl in HTML. Please see Launching and Embedding Curl in HTML. <br />
<br />
<br />
<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=41" target="_blank" title="">phpscript.jpg</a> (Size: 7.48 KB / Downloads: 1821)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=43" target="_blank" title="">phpvariable.jpg</a> (Size: 4.96 KB / Downloads: 1886)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Serving Content2:Launching and Embedding Curl in HTML]]></title>
			<link>https://communities.curl.com/showthread.php?tid=24</link>
			<pubDate>Wed, 15 Jun 2011 08:15:40 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=24</guid>
			<description><![CDATA[<span style="font-weight: bold;" class="mycode_b">Working with HTML </span> <br />
As you have already seen, the browser can directly load an applet, allowing the applet to take over the entire display area of the browser. A Curl applet can also be launched or embedded in an HTML page that the browser loads. Embedding a Curl applet allows the applet to share the browser's display area with HTML content. <br />
<br />
<br />
For Web pages that contain both HTML and Curl content, the following scenario occurs: <br />
<br />
<br />
1.The browser sends a request to the server <br />
<br />
2.The browser interprets the information sent from the server in which HTML is rendered and Curl content is recognized by the browser <br />
<br />
3.The browser starts the Curl runtime environment to handle the Curl content <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Let's examine each of these scenarios. </span> <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching a Curl applet from an HTML file</span> <br />
From an HTML file, users can launch a Curl applet by selecting a link that targets Curl content using the Anchor tag <A>. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Embedding a Curl applet in an HTML file</span> <br />
A Curl applet can be embedded in an HTML page using HTML's EMBED tag. Because of the way EMBED works, you will need to specify the MIME type for the Curl file explicitly in the HTML page. <br />
<br />
<br />
Your Curl applet will appear within a rectangular area in the HTML page, similar to the way other embedded content appears. <br />
<br />
<br />
In HTML, use the EMBED tag to specify information about Curl content <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>SRC=embed-applet.curl <br />
TYPE = text/vnd.curl <br />
PLUGINURL = http://www.curl.com/download/rte/ <br />
width = 300 <br />
height = 300 &gt;</code></div></div> <br />
Where: <br />
<br />
•SRC: Identifies the Curl applet that will be launched <br />
<br />
•TYPE: Identifies the MIME type <br />
<br />
•PLUGINURL: Identifies the Curl runtime environment location (if not previously installed on system) <br />
<br />
<br />
For example: <br />
<img src="attachment.php?aid=39" /> <br />
Select this link to view the running HTML page: <br />
<br />
<br />
Embedded Applet <br />
<br />
<br />
The EMBED tag contains the MIME type for the Curl content as well as the URL information about where to direct the user in the case the Curl runtime is not available on the user's browser. The attributes used in the example do not constitute a full list of what is available for the EMBED tag. However, they are sufficient for creating a working embedded applet. <br />
<br />
<br />
The HTML code is as follows: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>This is an example of embedding Curl content into HTML. <br />
<br />
<br />
This is a standard HTML page, with a Curl applet embedded into it. <br />
<br />
<br />
<br />
Beginning of the embedded Curl applet <br />
<br />
 SRC="../samples/ServingContent/launch-1.curl" <br />
TYPE = "text/vnd.curl" <br />
PLUGINURL = "http://www.curl.com/html/products/surge.jsp" <br />
width = "300" <br />
height = "300" &gt; <br />
<br />
<br />
<br />
End of the embedded Curl applet.</code></div></div> <br />
If you want your applet to take over the entire browser display area, you can just link to its source file directly, rather than an HTML file that embeds it. <br />
<br />
<br />
<br />
For more information regarding Embedding HTML, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > File Systems and Networking > Interacting with the Browser</span> <br />
<br />
<br />
<br />
<br />
Other ways to run Curl applets... <br />
<br />
•Launching a Curl applet from another Curl applet. Please see Launching a Curl Applet. <br />
<br />
•Generating Curl using PHP or similar scripts. Please see Dynamically Generating Curl Content. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=39" target="_blank" title="">embeddedapplet.jpg</a> (Size: 30.84 KB / Downloads: 3125)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<span style="font-weight: bold;" class="mycode_b">Working with HTML </span> <br />
As you have already seen, the browser can directly load an applet, allowing the applet to take over the entire display area of the browser. A Curl applet can also be launched or embedded in an HTML page that the browser loads. Embedding a Curl applet allows the applet to share the browser's display area with HTML content. <br />
<br />
<br />
For Web pages that contain both HTML and Curl content, the following scenario occurs: <br />
<br />
<br />
1.The browser sends a request to the server <br />
<br />
2.The browser interprets the information sent from the server in which HTML is rendered and Curl content is recognized by the browser <br />
<br />
3.The browser starts the Curl runtime environment to handle the Curl content <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Let's examine each of these scenarios. </span> <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching a Curl applet from an HTML file</span> <br />
From an HTML file, users can launch a Curl applet by selecting a link that targets Curl content using the Anchor tag <A>. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Embedding a Curl applet in an HTML file</span> <br />
A Curl applet can be embedded in an HTML page using HTML's EMBED tag. Because of the way EMBED works, you will need to specify the MIME type for the Curl file explicitly in the HTML page. <br />
<br />
<br />
Your Curl applet will appear within a rectangular area in the HTML page, similar to the way other embedded content appears. <br />
<br />
<br />
In HTML, use the EMBED tag to specify information about Curl content <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>SRC=embed-applet.curl <br />
TYPE = text/vnd.curl <br />
PLUGINURL = http://www.curl.com/download/rte/ <br />
width = 300 <br />
height = 300 &gt;</code></div></div> <br />
Where: <br />
<br />
•SRC: Identifies the Curl applet that will be launched <br />
<br />
•TYPE: Identifies the MIME type <br />
<br />
•PLUGINURL: Identifies the Curl runtime environment location (if not previously installed on system) <br />
<br />
<br />
For example: <br />
<img src="attachment.php?aid=39" /> <br />
Select this link to view the running HTML page: <br />
<br />
<br />
Embedded Applet <br />
<br />
<br />
The EMBED tag contains the MIME type for the Curl content as well as the URL information about where to direct the user in the case the Curl runtime is not available on the user's browser. The attributes used in the example do not constitute a full list of what is available for the EMBED tag. However, they are sufficient for creating a working embedded applet. <br />
<br />
<br />
The HTML code is as follows: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>This is an example of embedding Curl content into HTML. <br />
<br />
<br />
This is a standard HTML page, with a Curl applet embedded into it. <br />
<br />
<br />
<br />
Beginning of the embedded Curl applet <br />
<br />
 SRC="../samples/ServingContent/launch-1.curl" <br />
TYPE = "text/vnd.curl" <br />
PLUGINURL = "http://www.curl.com/html/products/surge.jsp" <br />
width = "300" <br />
height = "300" &gt; <br />
<br />
<br />
<br />
End of the embedded Curl applet.</code></div></div> <br />
If you want your applet to take over the entire browser display area, you can just link to its source file directly, rather than an HTML file that embeds it. <br />
<br />
<br />
<br />
For more information regarding Embedding HTML, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > File Systems and Networking > Interacting with the Browser</span> <br />
<br />
<br />
<br />
<br />
Other ways to run Curl applets... <br />
<br />
•Launching a Curl applet from another Curl applet. Please see Launching a Curl Applet. <br />
<br />
•Generating Curl using PHP or similar scripts. Please see Dynamically Generating Curl Content. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=39" target="_blank" title="">embeddedapplet.jpg</a> (Size: 30.84 KB / Downloads: 3125)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Serving Content1:Launching a Curl Applet]]></title>
			<link>https://communities.curl.com/showthread.php?tid=23</link>
			<pubDate>Wed, 15 Jun 2011 08:12:26 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=23</guid>
			<description><![CDATA[The design and development is complete and now you are ready to deploy your Curl application on a server. Storing the files on your local machine allows you to easily build and test the application and now all the Curl and supporting files must be moved to the server. The first item is to identify the server and move the files over. Next, you must configure your server to accept Curl application requests. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Server Requests </span> <br />
Each time a user selects a link to navigate to a new Web page, the browser sends request to the server. The server receives the request and sends the requested information back to the browser. The browser then interprets and displays the information to the user. <br />
<br />
<br />
When the requested information contains Curl content, the browser receives the information and launches the Curl runtime environment if it is not previously loaded. The processing of the applet is performed on the client and the content is presented to the user in the browser window. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Server Configuration </span> <br />
How does the server know about Curl? When you are ready to deploy a Curl application, you will need to configure your server to work with Curl files. <br />
<br />
•The first step is to take the application files and place them on your server <br />
<br />
•Next, allow access to files <br />
<br />
•Finally, configure the MIME type <br />
<br />
<br />
We'll go through all the steps in more detail. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Placing Files on your Server</span> <br />
In addition to your application and data files, you will need to put a server license file on your server. The Curl RTE will not execute a curl applet from an http:// or https:// location unless there is a valid license file on the server. <br />
<br />
<br />
There are two kinds of server licenses, the free personal license and a paid license for commercial use. <br />
<br />
<br />
•A Curl/Personal Server License unlocks most features of the Curl platform, excepting several features whose primary value is for enterprise applications. You can get a Curl/Personal Server License at no charge for your Web site if you are a noncommercial user. <br />
<br />
•A Curl/Pro Server License unlocks the full capabilities of the Curl platform. If you are an enterprise, you need to use a Curl/Pro license. <br />
<br />
<br />
Each kind of server license takes the form of a file called curl-license-5.dat that you obtain from Curl and place on your Web server to indicate that you are licensed to deploy Curl applications on the Web. In the simplest case, you put this file in the root directory of your Web server. Other options are also available such as placing the server license in the same directory as your Curl applet files. <br />
<br />
<br />
<br />
For more information regarding server licenses, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > License Keys</span> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Allowing Applets to Access Files </span> <br />
The curl-access.txt file contains directives that define which Curl applets can access the Web site's files. Applets are restricted based on their home site, which is the Web site from which they were downloaded. Using curl-access.txt, a server administrator can allow all Curl applets to access files on that server, or can restrict access so that, for example, only Curl applets hosted on other servers in the same domain, or only Curl applets from that server, can access the files. Generally, a Curl applet will access at least some files on the same server where the applet is deployed, so it is usually necessary to have some form of curl-access.txt file on that server. <br />
<br />
<br />
The directives in the curl-access.txt file declare which Curl applets are authorized to access its files. The following curl-access.txt file grants access to applets from all servers: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#Allow applets free access <br />
version: 2.0 <br />
allow-all:</code></div></div> <br />
<br />
The next curl-access.txt file grants access to Curl applets from specific sites and can selectively filter access to the server from publicly deployed applets: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#Allow applets free access <br />
version: 2.0 <br />
allow: *.mydomain.com, test.mysupplier.com <br />
except: public-ftp.mydomain.com</code></div></div> <br />
<br />
<br />
The curl-access.txt mechanism does not override any other protections that your Web site has in place to restrict access to files. If the user could not access a file directly using a browser, then an applet on his or her system will not be able to access the file either. This is true even with a curl-access.txt file that grants the applet access to files on that server. <br />
<br />
<br />
<br />
You can either place this file in the root directory of your Web server or in the same directory as the data files whose accessibility you want to control. When placed at the root of the Web site, the curl-access.txt directives will override all other directives found in the subdirectories of that Web site. Consequently, this method will subject all the files on your Web site to the same rules. When the curl-access.txt file is placed at the local directory level, it controls the access to just the files contained in that directory. <br />
<br />
<br />
<br />
For more information regarding Curl access, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > Allowing Applets to Access Files</span> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Configure Mime Type </span> <br />
In order to serve Curl applets from your Web site, you also need to add MIME type definitions for Curl source files and package files to your Web server's configuration. The MIME type is how the server tells the browser that a file should be handled by the Curl runtime environment. <br />
<br />
<img src="attachment.php?aid=37" /> <br />
<br />
The .dcurl and .car file types are used for specialized purposes. .dcurl files are used for detached applets, which run outside of a browser window as standalone applications. .car files are used when deploying an applet that can be used offline as well as online. <br />
<br />
<br />
<br />
<br />
For more information regarding MIME Types, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > Source MIME Types for Curl files</span> <br />
<br />
<br />
<br />
Launching a Curl applet <br />
Now you are all ready to serve Curl content. The easiest way to launch a Curl applet from a server is to type the url location of the start file (start.curl) of the application. The following Curl applet can be accessed by directly selecting the link. (Select the back button in the browser window to return to Curl Cues.) <br />
<br />
<br />
Select this link to launch a Curl applet <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching a Curl applet from a Curl applet </span> <br />
It is common to have one Curl applet launch another Curl applet. One example is login capability in which the "login applet" launches another Curl applet based on the required authentication. <br />
<br />
<br />
The browse-url method in the Applet class allows you to load a given url; it has the same effect as selecting a link. The browser's history will be updated appropriately. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{applet {compiler-directives careful? = true}} <br />
<br />
{value <br />
let my-applet:Applet = {get-the-applet} <br />
<br />
let browse-button:CommandButton = <br />
{CommandButton <br />
label = "Launch Applet", <br />
{on Action do <br />
{my-applet.browse-url <br />
{url "./launch-1.curl"}, <br />
target = "_blank" <br />
} <br />
} <br />
} <br />
<br />
{VBox <br />
{bold The following button launches another Curl applet}, <br />
browse-button <br />
} <br />
}</code></div></div> <br />
The above example launches a Curl applet when the CommandButton is pressed. The browse-url method is associated with the action of the CommandButton. The target specified in browse-url ("_blank") will open a new browser window. The default behavior is to use the same window as the running applet ("_self"). <br />
<br />
<br />
<br />
Other ways to run Curl applets... <br />
<br />
•Embedding Curl applets in HTML. Please see <a href="http://developers.curl.com/docs/DOC-1127" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1127</a>. <br />
<br />
•Generating Curl using PHP or similar scripts. Please see <a href="http://developers.curl.com/docs/DOC-1128" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1128</a>. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=37" target="_blank" title="">Launching a Curl Applet1.JPG</a> (Size: 19.91 KB / Downloads: 1934)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[The design and development is complete and now you are ready to deploy your Curl application on a server. Storing the files on your local machine allows you to easily build and test the application and now all the Curl and supporting files must be moved to the server. The first item is to identify the server and move the files over. Next, you must configure your server to accept Curl application requests. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Server Requests </span> <br />
Each time a user selects a link to navigate to a new Web page, the browser sends request to the server. The server receives the request and sends the requested information back to the browser. The browser then interprets and displays the information to the user. <br />
<br />
<br />
When the requested information contains Curl content, the browser receives the information and launches the Curl runtime environment if it is not previously loaded. The processing of the applet is performed on the client and the content is presented to the user in the browser window. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Server Configuration </span> <br />
How does the server know about Curl? When you are ready to deploy a Curl application, you will need to configure your server to work with Curl files. <br />
<br />
•The first step is to take the application files and place them on your server <br />
<br />
•Next, allow access to files <br />
<br />
•Finally, configure the MIME type <br />
<br />
<br />
We'll go through all the steps in more detail. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Placing Files on your Server</span> <br />
In addition to your application and data files, you will need to put a server license file on your server. The Curl RTE will not execute a curl applet from an http:// or https:// location unless there is a valid license file on the server. <br />
<br />
<br />
There are two kinds of server licenses, the free personal license and a paid license for commercial use. <br />
<br />
<br />
•A Curl/Personal Server License unlocks most features of the Curl platform, excepting several features whose primary value is for enterprise applications. You can get a Curl/Personal Server License at no charge for your Web site if you are a noncommercial user. <br />
<br />
•A Curl/Pro Server License unlocks the full capabilities of the Curl platform. If you are an enterprise, you need to use a Curl/Pro license. <br />
<br />
<br />
Each kind of server license takes the form of a file called curl-license-5.dat that you obtain from Curl and place on your Web server to indicate that you are licensed to deploy Curl applications on the Web. In the simplest case, you put this file in the root directory of your Web server. Other options are also available such as placing the server license in the same directory as your Curl applet files. <br />
<br />
<br />
<br />
For more information regarding server licenses, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > License Keys</span> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Allowing Applets to Access Files </span> <br />
The curl-access.txt file contains directives that define which Curl applets can access the Web site's files. Applets are restricted based on their home site, which is the Web site from which they were downloaded. Using curl-access.txt, a server administrator can allow all Curl applets to access files on that server, or can restrict access so that, for example, only Curl applets hosted on other servers in the same domain, or only Curl applets from that server, can access the files. Generally, a Curl applet will access at least some files on the same server where the applet is deployed, so it is usually necessary to have some form of curl-access.txt file on that server. <br />
<br />
<br />
The directives in the curl-access.txt file declare which Curl applets are authorized to access its files. The following curl-access.txt file grants access to applets from all servers: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#Allow applets free access <br />
version: 2.0 <br />
allow-all:</code></div></div> <br />
<br />
The next curl-access.txt file grants access to Curl applets from specific sites and can selectively filter access to the server from publicly deployed applets: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>#Allow applets free access <br />
version: 2.0 <br />
allow: *.mydomain.com, test.mysupplier.com <br />
except: public-ftp.mydomain.com</code></div></div> <br />
<br />
<br />
The curl-access.txt mechanism does not override any other protections that your Web site has in place to restrict access to files. If the user could not access a file directly using a browser, then an applet on his or her system will not be able to access the file either. This is true even with a curl-access.txt file that grants the applet access to files on that server. <br />
<br />
<br />
<br />
You can either place this file in the root directory of your Web server or in the same directory as the data files whose accessibility you want to control. When placed at the root of the Web site, the curl-access.txt directives will override all other directives found in the subdirectories of that Web site. Consequently, this method will subject all the files on your Web site to the same rules. When the curl-access.txt file is placed at the local directory level, it controls the access to just the files contained in that directory. <br />
<br />
<br />
<br />
For more information regarding Curl access, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > Allowing Applets to Access Files</span> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Configure Mime Type </span> <br />
In order to serve Curl applets from your Web site, you also need to add MIME type definitions for Curl source files and package files to your Web server's configuration. The MIME type is how the server tells the browser that a file should be handled by the Curl runtime environment. <br />
<br />
<img src="attachment.php?aid=37" /> <br />
<br />
The .dcurl and .car file types are used for specialized purposes. .dcurl files are used for detached applets, which run outside of a browser window as standalone applications. .car files are used when deploying an applet that can be used offline as well as online. <br />
<br />
<br />
<br />
<br />
For more information regarding MIME Types, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Configuring Your Web Server > Source MIME Types for Curl files</span> <br />
<br />
<br />
<br />
Launching a Curl applet <br />
Now you are all ready to serve Curl content. The easiest way to launch a Curl applet from a server is to type the url location of the start file (start.curl) of the application. The following Curl applet can be accessed by directly selecting the link. (Select the back button in the browser window to return to Curl Cues.) <br />
<br />
<br />
Select this link to launch a Curl applet <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Launching a Curl applet from a Curl applet </span> <br />
It is common to have one Curl applet launch another Curl applet. One example is login capability in which the "login applet" launches another Curl applet based on the required authentication. <br />
<br />
<br />
The browse-url method in the Applet class allows you to load a given url; it has the same effect as selecting a link. The browser's history will be updated appropriately. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{applet {compiler-directives careful? = true}} <br />
<br />
{value <br />
let my-applet:Applet = {get-the-applet} <br />
<br />
let browse-button:CommandButton = <br />
{CommandButton <br />
label = "Launch Applet", <br />
{on Action do <br />
{my-applet.browse-url <br />
{url "./launch-1.curl"}, <br />
target = "_blank" <br />
} <br />
} <br />
} <br />
<br />
{VBox <br />
{bold The following button launches another Curl applet}, <br />
browse-button <br />
} <br />
}</code></div></div> <br />
The above example launches a Curl applet when the CommandButton is pressed. The browse-url method is associated with the action of the CommandButton. The target specified in browse-url ("_blank") will open a new browser window. The default behavior is to use the same window as the running applet ("_self"). <br />
<br />
<br />
<br />
Other ways to run Curl applets... <br />
<br />
•Embedding Curl applets in HTML. Please see <a href="http://developers.curl.com/docs/DOC-1127" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1127</a>. <br />
<br />
•Generating Curl using PHP or similar scripts. Please see <a href="http://developers.curl.com/docs/DOC-1128" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1128</a>. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=37" target="_blank" title="">Launching a Curl Applet1.JPG</a> (Size: 19.91 KB / Downloads: 1934)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Forms3:HTTP Forms]]></title>
			<link>https://communities.curl.com/showthread.php?tid=22</link>
			<pubDate>Wed, 15 Jun 2011 08:02:00 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=22</guid>
			<description><![CDATA[One of the most common ways to communicate with a server is over HTTP. Curl's <font color="purple">HttForm</font> class acts as a container for controls that will be part of the web form. Users complete the form by modifying its controls before submitting hte form to an agent for processing. The function of <font color="purple">HttpForm</font> is similar to the FORM tag in HTML.<br />
<br />
 <br />
Lets look at the following simple example.  In this case, we are creating a Google query that also specifies the language and the interface. Enter text that you would like to query in Google, e.g. "Baseball".  Then hit thie "Submit" button.  A new browser window will be launched to display the results.<br />
<br />
 <br />
width='100%' height='60' src='../../wiki/samples/Forms/http2.curl' <br />
<br />
 <br />
 <br />
In this case, <font color="purple">HttpForm</font> is used to create the Web form<br />
<br />
•A <font color="purple">Dialog</font> is created to contain the controls<br />
<br />
•The user fills out the form and clicks the Submit button<br />
<br />
•Key/value pairs are sent to the server script using GET or POST<br />
<br />
•Returned information is sent to the user<br />
<br />
 <br />
 <br />
When instantiating an <font color="purple">HttpForm</font> object, you provide the URL of the CGI program or script on the Web site that will receive the request, as well as the HTTP request method of GET or POST.<br />
<br />
 <br />
Let's break down this example.  First we will create an form that only submits the query.  Afterwards, we can add the additional query elements and expand the example.<br />
<br />
 <br />
width='100%' height='450' src='/wiki/samples/generic-example.curl?Forms/http.curl' <br />
<br />
 <br />
 <br />
In this example, we will be sending the following HTTP request using GET: <a href="http://www.google.com/search?q=Baseball" target="_blank" rel="noopener" class="mycode_url">http://www.google.com/search?q=Baseball</a>   (where "Baseball" represents the text typed in by the user). In order to accomplish this, we need to first specify the url of the server.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{url http://www.google.com/search},</code></div></div>The target specifies the browser window in which the action will be displayed.  Values are as follows:<br />
<br />
 <br />
•_self: Returns results in the current browser window (default)<br />
<br />
•_blank: Returns results in a new browser window<br />
<br />
•_parent: Returns results in the parent frameset of the current frame.<br />
<br />
•_top: Returns the results in the top-level window (full browser window)<br />
<br />
 <br />
 <br />
Since the <font color="purple">HttpForm</font> is a <font color="purple">Dialog</font>, we must create one child object that can contain multiple children.  In our example, we are using a <font color="purple">VBox</font>. Control values that are passed to the HTTP request must include the name attribute.  The <font color="purple">TextField</font> has name = "q" defined.<br />
<br />
 <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 2in,<br />
&nbsp;&nbsp;&nbsp;&nbsp;name = q<br />
}</code></div></div> <br />
 <br />
The submit-button is a Curl procedure that creates a <font color="purple">CommandBuitton</font> with at "Submit" label.  When the user clicks on the button, it automatically passes the form information to the specified <font color="purple">Url</font>.<br />
<br />
  <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{submit-button}</code></div></div> <br />
We have created this proc as a convenience procedure. For custom submit functionality, you can always create your own procedure or method. Another convenience procedure that we have created for you is <font color="purple">reset-button</font>. In this case, it creates and returns a standard "Reset" button for use in the <font color="purple">HttpForm</font>. Let's add this functionality to our example.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{curl-file-attributes character-encoding = "utf8"}<br />
{applet manifest = "manifest.mcurl",<br />
&nbsp;&nbsp; {compiler-directives careful? = true}<br />
}<br />
<br />
{HttpForm<br />
&nbsp;&nbsp; {url "http://www.google.com/search"},<br />
&nbsp;&nbsp; target = "_blank",<br />
&nbsp;&nbsp; {HBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin = 5pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spacing = 3.5pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {text Query:&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2in,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = "q",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value = "Pizza"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {submit-button},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reset-button}<br />
&nbsp;&nbsp; }<br />
}</code></div></div><br />
 <br />
Note that the reset button will 'reset' all controls to their default state.  In the above example the initial value has been set to "Pizza". If no initial value is specified, the "Reset" button will leave the <font color="purple">TextField</font> blank.<br />
]]></description>
			<content:encoded><![CDATA[One of the most common ways to communicate with a server is over HTTP. Curl's <font color="purple">HttForm</font> class acts as a container for controls that will be part of the web form. Users complete the form by modifying its controls before submitting hte form to an agent for processing. The function of <font color="purple">HttpForm</font> is similar to the FORM tag in HTML.<br />
<br />
 <br />
Lets look at the following simple example.  In this case, we are creating a Google query that also specifies the language and the interface. Enter text that you would like to query in Google, e.g. "Baseball".  Then hit thie "Submit" button.  A new browser window will be launched to display the results.<br />
<br />
 <br />
width='100%' height='60' src='../../wiki/samples/Forms/http2.curl' <br />
<br />
 <br />
 <br />
In this case, <font color="purple">HttpForm</font> is used to create the Web form<br />
<br />
•A <font color="purple">Dialog</font> is created to contain the controls<br />
<br />
•The user fills out the form and clicks the Submit button<br />
<br />
•Key/value pairs are sent to the server script using GET or POST<br />
<br />
•Returned information is sent to the user<br />
<br />
 <br />
 <br />
When instantiating an <font color="purple">HttpForm</font> object, you provide the URL of the CGI program or script on the Web site that will receive the request, as well as the HTTP request method of GET or POST.<br />
<br />
 <br />
Let's break down this example.  First we will create an form that only submits the query.  Afterwards, we can add the additional query elements and expand the example.<br />
<br />
 <br />
width='100%' height='450' src='/wiki/samples/generic-example.curl?Forms/http.curl' <br />
<br />
 <br />
 <br />
In this example, we will be sending the following HTTP request using GET: <a href="http://www.google.com/search?q=Baseball" target="_blank" rel="noopener" class="mycode_url">http://www.google.com/search?q=Baseball</a>   (where "Baseball" represents the text typed in by the user). In order to accomplish this, we need to first specify the url of the server.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{url http://www.google.com/search},</code></div></div>The target specifies the browser window in which the action will be displayed.  Values are as follows:<br />
<br />
 <br />
•_self: Returns results in the current browser window (default)<br />
<br />
•_blank: Returns results in a new browser window<br />
<br />
•_parent: Returns results in the parent frameset of the current frame.<br />
<br />
•_top: Returns the results in the top-level window (full browser window)<br />
<br />
 <br />
 <br />
Since the <font color="purple">HttpForm</font> is a <font color="purple">Dialog</font>, we must create one child object that can contain multiple children.  In our example, we are using a <font color="purple">VBox</font>. Control values that are passed to the HTTP request must include the name attribute.  The <font color="purple">TextField</font> has name = "q" defined.<br />
<br />
 <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 2in,<br />
&nbsp;&nbsp;&nbsp;&nbsp;name = q<br />
}</code></div></div> <br />
 <br />
The submit-button is a Curl procedure that creates a <font color="purple">CommandBuitton</font> with at "Submit" label.  When the user clicks on the button, it automatically passes the form information to the specified <font color="purple">Url</font>.<br />
<br />
  <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{submit-button}</code></div></div> <br />
We have created this proc as a convenience procedure. For custom submit functionality, you can always create your own procedure or method. Another convenience procedure that we have created for you is <font color="purple">reset-button</font>. In this case, it creates and returns a standard "Reset" button for use in the <font color="purple">HttpForm</font>. Let's add this functionality to our example.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
{curl-file-attributes character-encoding = "utf8"}<br />
{applet manifest = "manifest.mcurl",<br />
&nbsp;&nbsp; {compiler-directives careful? = true}<br />
}<br />
<br />
{HttpForm<br />
&nbsp;&nbsp; {url "http://www.google.com/search"},<br />
&nbsp;&nbsp; target = "_blank",<br />
&nbsp;&nbsp; {HBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin = 5pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; spacing = 3.5pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {text Query:&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {TextField<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = 2in,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = "q",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value = "Pizza"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {submit-button},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reset-button}<br />
&nbsp;&nbsp; }<br />
}</code></div></div><br />
 <br />
Note that the reset button will 'reset' all controls to their default state.  In the above example the initial value has been set to "Pizza". If no initial value is specified, the "Reset" button will leave the <font color="purple">TextField</font> blank.<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Forms2:Form Validation]]></title>
			<link>https://communities.curl.com/showthread.php?tid=21</link>
			<pubDate>Wed, 15 Jun 2011 07:59:58 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=21</guid>
			<description><![CDATA[One of the most important aspects of building and processing a form is how you validate the input data. You want to assist users by providing them with information to help them make choices as they fill out the form and to understand what's required and optional before selecting the submit button. <br />
<br />
<br />
In classic server-based Web applications, once the enter or submit button is clicked, form data is passed to CGI script, or some other technology. If the data contains an error, there will be a delay before the information travels over the Internet to the server, is examined on the server, and then returns to the user along with an error message. <br />
<br />
We will incrementally build the registration page. Let's first start with a simple example using a <span style="color: purple;" class="mycode_color">TextField</span> in order to discuss the syntax. The idea is to create a validation requirement that is associated with the control. The validate-with procedure is placed on each control that uses validation. The validator is the only required argument. This specifies the type of validation for the control to be valid, in our case a <span style="color: purple;" class="mycode_color">StringValidator</span>. <br />
<br />
<br />
A <span style="color: purple;" class="mycode_color">StringValidator</span> ensures that a input value is not blank. We have also added keyword arguements to enforce size limits (min-chars and max-chars). <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let full-name:TextField = <br />
{TextField <br />
width = 3cm, <br />
{validate-with <br />
{StringValidator min-chars = 3, max-chars = 25}, <br />
required?=true <br />
} <br />
} <br />
<br />
{HBox "Name:", full-name} <br />
}</code></div></div> <br />
The procedure <span style="color: purple;" class="mycode_color">validate-with</span> requests validation on the control. In our case, a <span style="color: purple;" class="mycode_color">TextField</span>. A <span style="color: purple;" class="mycode_color">ValueChanged</span> or <span style="color: purple;" class="mycode_color">ValueFinished</span> event on the control triggers the validation cycle. Note that if you do not specify min-chars and min-chars, then any length <span style="color: purple;" class="mycode_color">String</span> is acceptable. <br />
<br />
<br />
Let's add a <span style="color: purple;" class="mycode_color">MessageDisplay</span> to the validation. A <span style="color: purple;" class="mycode_color">MessageDisplay</span> is graphical object used to display validation messages to the user. In the following example, the first control uses the default message created by Curl. We have also added a user-age input that validates using a <span style="color: purple;" class="mycode_color">NumericValidator</span> that displays a custom message. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let name-feedback:MessageDisplay = {MessageDisplay} <br />
let age-feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = name-feedback, <br />
{validate-with <br />
{StringValidator min-chars = 3, max-chars = 25}, <br />
required? = true <br />
} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = age-feedback, <br />
{validate-with <br />
{NumericValidator min-allowable = 18, max-allowable = 40}, <br />
required? = true, <br />
message = "Users must be between 18 and 40" <br />
} <br />
} <br />
<br />
{Table <br />
columns = 3, <br />
"Name:", full-name,name-feedback, <br />
"Age: ", user-age, age-feedback <br />
} <br />
}</code></div></div> <br />
The <span style="color: purple;" class="mycode_color">MessageDisplay</span> object needs to be created in order to hold the message. The <span style="color: purple;" class="mycode_color">MessageDisplay</span> is referenced in each control, for example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>message-display = neme-feedback</code></div></div> <br />
<br />
Since each control object has its own <span style="color: purple;" class="mycode_color">MessageDisplay</span>, if the user inputs an invalid value, then the associated message will display to the right of the control until the input becomes valid. A message will also appear if the user does not input a value for the user-age since required? = true is specified. <br />
<br />
<br />
Now, let's place additional controls that target common types of entries such as phone number, email, and zip code. In these cases, we can specify a <span style="color: purple;" class="mycode_color">ValidationPattern</span>. For example {validate-with ValidationPattern.us-zip-code} is used to validate a us zip code. Other patterns include credit cards, http-urls, social security numbers, as well as patterns for French, German, Japanese, and Chinese entries. Please see <span style="color: purple;" class="mycode_color">ValidationPattern</span> for more information. <br />
<br />
<br />
<br />
If you run a validation of the user’s form input before the form is submitted, there will be no wait time and redundant load on the server. Invalid inputs are already filtered out when input is passed to the server-based program. It also allows to simplify server-based program. In Curl, data can be validated in real-time, as the user enters information into the form. <br />
<br />
<br />
Our example is a simple registration page that will validate the entries on the client machine (without the need to query the server). If an entry requires a specific input that has not been entered, a validation message will be displayed to the user. Once all valid information has been input into the dialog, the Enter button will be enabled. When the user clicks the Enter button, it will display the input information in a popup dialog. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3, max-chars = 25}, required?=true} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 1cm, <br />
message-display = feedback, <br />
{validate-with {NumericValidator min-allowable = 18, max-allowable = 40}, required? = true, message = "Users must be between 18 and 40"} <br />
} <br />
<br />
let address1:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
let address2:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
<br />
let zip-code:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.us-zip-code} <br />
} <br />
<br />
let home-phone:TextField = <br />
{TextField <br />
width = 5cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.us-phone-number, required?=true} <br />
} <br />
<br />
let email-address:TextField = <br />
{TextField <br />
width = 5cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let enter-button:CommandButton = <br />
{CommandButton <br />
label = "Enter", <br />
{on Action do <br />
{popup-message <br />
{VBox <br />
"You entered:", <br />
full-name.value, <br />
address1.value, <br />
address2.value, <br />
zip-code.value, <br />
home-phone.value, <br />
email-address.value, <br />
user-age.value <br />
} <br />
} <br />
} <br />
} <br />
<br />
<br />
{Table <br />
columns = 2, <br />
"Name:", full-name, <br />
"Address: ", address1, <br />
"City, State: ", address2, <br />
"Zipcode: ", zip-code, <br />
"Phone: ", home-phone, <br />
"Email: ", email-address, <br />
"Age: ", user-age, <br />
enter-button, feedback <br />
} <br />
}</code></div></div> <br />
<br />
In the previous example, we also: <br />
<br />
•Created an Enter button to display the input values. <br />
<br />
•Used the same <span style="color: purple;" class="mycode_color">MessageDisplay</span> for each control. The feedback will be displayed to the right of the Enter button. <br />
<br />
<br />
<br />
While it is possible to use validation on individual controls, the system is most often used to validate controls grouped in a <span style="color: purple;" class="mycode_color">Dialog</span> (including subclasses such as <span style="color: purple;" class="mycode_color">RecordForm</span> or <span style="color: purple;" class="mycode_color">HttpForm</span>). The validation cycle starts when an entry is changed and ends when all necessary feedback has been shown. This also allows us to enable the Enter button when the <span style="color: purple;" class="mycode_color">Dialog</span> is valid. <br />
<br />
<br />
Note that the <span style="color: purple;" class="mycode_color">Dialog</span> has the following validation entries: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>message-display = feedback, <br />
{validate-with {DialogValidator}},</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3, max-chars = 25}, required?=true} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 1cm, <br />
<br />
{validate-with {NumericValidator min-allowable = 18, max-allowable = 40}, required? = true, message = "Users must be between 18 and 40"} <br />
} <br />
<br />
let address1:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
let address2:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
<br />
let zip-code:TextField = <br />
{TextField <br />
width = 3cm, <br />
<br />
{validate-with ValidationPattern.us-zip-code} <br />
} <br />
<br />
let home-phone:TextField = <br />
{TextField <br />
width = 5cm, <br />
<br />
{validate-with ValidationPattern.us-phone-number, required?=true} <br />
} <br />
<br />
let email-address:TextField = <br />
{TextField <br />
width = 5cm, <br />
<br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let enter-button:CommandButton = <br />
{CommandButton <br />
label = "Enter", <br />
name = "e-button", <br />
{on Action do <br />
{popup-message <br />
{VBox <br />
"You entered:", <br />
full-name.value, <br />
address1.value, <br />
address2.value, <br />
zip-code.value, <br />
home-phone.value, <br />
email-address.value, <br />
user-age.value <br />
} <br />
} <br />
} <br />
} <br />
<br />
{Dialog <br />
{Table <br />
columns = 2, <br />
"Name:", full-name, <br />
"Address: ", address1, <br />
"City, State: ", address2, <br />
"Zipcode: ", zip-code, <br />
"Phone: ", home-phone, <br />
"Email: ", email-address, <br />
"Age: ", user-age, <br />
enter-button, feedback <br />
}, <br />
message-display = feedback, <br />
{validate-with {DialogValidator}}, <br />
{on vc:ValidationComplete at d:Dialog do <br />
set {d.get-by-name "e-button"}.enabled? = d.valid? <br />
} <br />
} <br />
}</code></div></div> <br />
In summary, form validation is the first step for allowing users to easily input form values. In our example, we presented the input values using a <span style="color: purple;" class="mycode_color">popup-message</span>. If you wish to submit the valid information to a server for processing, please see the Curl Developer's Guide for more information. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".curl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=34" target="_blank" title="">formvalid.curl</a> (Size: 2.66 KB / Downloads: 1230)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[One of the most important aspects of building and processing a form is how you validate the input data. You want to assist users by providing them with information to help them make choices as they fill out the form and to understand what's required and optional before selecting the submit button. <br />
<br />
<br />
In classic server-based Web applications, once the enter or submit button is clicked, form data is passed to CGI script, or some other technology. If the data contains an error, there will be a delay before the information travels over the Internet to the server, is examined on the server, and then returns to the user along with an error message. <br />
<br />
We will incrementally build the registration page. Let's first start with a simple example using a <span style="color: purple;" class="mycode_color">TextField</span> in order to discuss the syntax. The idea is to create a validation requirement that is associated with the control. The validate-with procedure is placed on each control that uses validation. The validator is the only required argument. This specifies the type of validation for the control to be valid, in our case a <span style="color: purple;" class="mycode_color">StringValidator</span>. <br />
<br />
<br />
A <span style="color: purple;" class="mycode_color">StringValidator</span> ensures that a input value is not blank. We have also added keyword arguements to enforce size limits (min-chars and max-chars). <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let full-name:TextField = <br />
{TextField <br />
width = 3cm, <br />
{validate-with <br />
{StringValidator min-chars = 3, max-chars = 25}, <br />
required?=true <br />
} <br />
} <br />
<br />
{HBox "Name:", full-name} <br />
}</code></div></div> <br />
The procedure <span style="color: purple;" class="mycode_color">validate-with</span> requests validation on the control. In our case, a <span style="color: purple;" class="mycode_color">TextField</span>. A <span style="color: purple;" class="mycode_color">ValueChanged</span> or <span style="color: purple;" class="mycode_color">ValueFinished</span> event on the control triggers the validation cycle. Note that if you do not specify min-chars and min-chars, then any length <span style="color: purple;" class="mycode_color">String</span> is acceptable. <br />
<br />
<br />
Let's add a <span style="color: purple;" class="mycode_color">MessageDisplay</span> to the validation. A <span style="color: purple;" class="mycode_color">MessageDisplay</span> is graphical object used to display validation messages to the user. In the following example, the first control uses the default message created by Curl. We have also added a user-age input that validates using a <span style="color: purple;" class="mycode_color">NumericValidator</span> that displays a custom message. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let name-feedback:MessageDisplay = {MessageDisplay} <br />
let age-feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = name-feedback, <br />
{validate-with <br />
{StringValidator min-chars = 3, max-chars = 25}, <br />
required? = true <br />
} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = age-feedback, <br />
{validate-with <br />
{NumericValidator min-allowable = 18, max-allowable = 40}, <br />
required? = true, <br />
message = "Users must be between 18 and 40" <br />
} <br />
} <br />
<br />
{Table <br />
columns = 3, <br />
"Name:", full-name,name-feedback, <br />
"Age: ", user-age, age-feedback <br />
} <br />
}</code></div></div> <br />
The <span style="color: purple;" class="mycode_color">MessageDisplay</span> object needs to be created in order to hold the message. The <span style="color: purple;" class="mycode_color">MessageDisplay</span> is referenced in each control, for example: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>message-display = neme-feedback</code></div></div> <br />
<br />
Since each control object has its own <span style="color: purple;" class="mycode_color">MessageDisplay</span>, if the user inputs an invalid value, then the associated message will display to the right of the control until the input becomes valid. A message will also appear if the user does not input a value for the user-age since required? = true is specified. <br />
<br />
<br />
Now, let's place additional controls that target common types of entries such as phone number, email, and zip code. In these cases, we can specify a <span style="color: purple;" class="mycode_color">ValidationPattern</span>. For example {validate-with ValidationPattern.us-zip-code} is used to validate a us zip code. Other patterns include credit cards, http-urls, social security numbers, as well as patterns for French, German, Japanese, and Chinese entries. Please see <span style="color: purple;" class="mycode_color">ValidationPattern</span> for more information. <br />
<br />
<br />
<br />
If you run a validation of the user’s form input before the form is submitted, there will be no wait time and redundant load on the server. Invalid inputs are already filtered out when input is passed to the server-based program. It also allows to simplify server-based program. In Curl, data can be validated in real-time, as the user enters information into the form. <br />
<br />
<br />
Our example is a simple registration page that will validate the entries on the client machine (without the need to query the server). If an entry requires a specific input that has not been entered, a validation message will be displayed to the user. Once all valid information has been input into the dialog, the Enter button will be enabled. When the user clicks the Enter button, it will display the input information in a popup dialog. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3, max-chars = 25}, required?=true} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 1cm, <br />
message-display = feedback, <br />
{validate-with {NumericValidator min-allowable = 18, max-allowable = 40}, required? = true, message = "Users must be between 18 and 40"} <br />
} <br />
<br />
let address1:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
let address2:TextField = <br />
{TextField <br />
width = 8cm, <br />
message-display = feedback, <br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
<br />
let zip-code:TextField = <br />
{TextField <br />
width = 3cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.us-zip-code} <br />
} <br />
<br />
let home-phone:TextField = <br />
{TextField <br />
width = 5cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.us-phone-number, required?=true} <br />
} <br />
<br />
let email-address:TextField = <br />
{TextField <br />
width = 5cm, <br />
message-display = feedback, <br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let enter-button:CommandButton = <br />
{CommandButton <br />
label = "Enter", <br />
{on Action do <br />
{popup-message <br />
{VBox <br />
"You entered:", <br />
full-name.value, <br />
address1.value, <br />
address2.value, <br />
zip-code.value, <br />
home-phone.value, <br />
email-address.value, <br />
user-age.value <br />
} <br />
} <br />
} <br />
} <br />
<br />
<br />
{Table <br />
columns = 2, <br />
"Name:", full-name, <br />
"Address: ", address1, <br />
"City, State: ", address2, <br />
"Zipcode: ", zip-code, <br />
"Phone: ", home-phone, <br />
"Email: ", email-address, <br />
"Age: ", user-age, <br />
enter-button, feedback <br />
} <br />
}</code></div></div> <br />
<br />
In the previous example, we also: <br />
<br />
•Created an Enter button to display the input values. <br />
<br />
•Used the same <span style="color: purple;" class="mycode_color">MessageDisplay</span> for each control. The feedback will be displayed to the right of the Enter button. <br />
<br />
<br />
<br />
While it is possible to use validation on individual controls, the system is most often used to validate controls grouped in a <span style="color: purple;" class="mycode_color">Dialog</span> (including subclasses such as <span style="color: purple;" class="mycode_color">RecordForm</span> or <span style="color: purple;" class="mycode_color">HttpForm</span>). The validation cycle starts when an entry is changed and ends when all necessary feedback has been shown. This also allows us to enable the Enter button when the <span style="color: purple;" class="mycode_color">Dialog</span> is valid. <br />
<br />
<br />
Note that the <span style="color: purple;" class="mycode_color">Dialog</span> has the following validation entries: <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>message-display = feedback, <br />
{validate-with {DialogValidator}},</code></div></div> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
{applet manifest = "manifest.mcurl", <br />
{compiler-directives careful? = true} <br />
} <br />
<br />
{value <br />
let feedback:MessageDisplay = {MessageDisplay} <br />
let full-name:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3, max-chars = 25}, required?=true} <br />
} <br />
<br />
let user-age:TextField = <br />
{TextField <br />
width = 1cm, <br />
<br />
{validate-with {NumericValidator min-allowable = 18, max-allowable = 40}, required? = true, message = "Users must be between 18 and 40"} <br />
} <br />
<br />
let address1:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
let address2:TextField = <br />
{TextField <br />
width = 8cm, <br />
<br />
{validate-with {StringValidator min-chars = 3}} <br />
} <br />
<br />
let zip-code:TextField = <br />
{TextField <br />
width = 3cm, <br />
<br />
{validate-with ValidationPattern.us-zip-code} <br />
} <br />
<br />
let home-phone:TextField = <br />
{TextField <br />
width = 5cm, <br />
<br />
{validate-with ValidationPattern.us-phone-number, required?=true} <br />
} <br />
<br />
let email-address:TextField = <br />
{TextField <br />
width = 5cm, <br />
<br />
{validate-with ValidationPattern.email-address, required? = true} <br />
} <br />
<br />
let enter-button:CommandButton = <br />
{CommandButton <br />
label = "Enter", <br />
name = "e-button", <br />
{on Action do <br />
{popup-message <br />
{VBox <br />
"You entered:", <br />
full-name.value, <br />
address1.value, <br />
address2.value, <br />
zip-code.value, <br />
home-phone.value, <br />
email-address.value, <br />
user-age.value <br />
} <br />
} <br />
} <br />
} <br />
<br />
{Dialog <br />
{Table <br />
columns = 2, <br />
"Name:", full-name, <br />
"Address: ", address1, <br />
"City, State: ", address2, <br />
"Zipcode: ", zip-code, <br />
"Phone: ", home-phone, <br />
"Email: ", email-address, <br />
"Age: ", user-age, <br />
enter-button, feedback <br />
}, <br />
message-display = feedback, <br />
{validate-with {DialogValidator}}, <br />
{on vc:ValidationComplete at d:Dialog do <br />
set {d.get-by-name "e-button"}.enabled? = d.valid? <br />
} <br />
} <br />
}</code></div></div> <br />
In summary, form validation is the first step for allowing users to easily input form values. In our example, we presented the input values using a <span style="color: purple;" class="mycode_color">popup-message</span>. If you wish to submit the valid information to a server for processing, please see the Curl Developer's Guide for more information. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/curl.gif" title="" border="0" alt=".curl" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=34" target="_blank" title="">formvalid.curl</a> (Size: 2.66 KB / Downloads: 1230)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Forms1:Creating Forms]]></title>
			<link>https://communities.curl.com/showthread.php?tid=20</link>
			<pubDate>Wed, 15 Jun 2011 07:55:38 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=20</guid>
			<description><![CDATA[Forms-based transactions and data entry are a key part of most enterprise workflows. Well-designed forms streamline users' work through attractive, usable visual design; by providing well-chosen, relevant predefined options for user input; and by interactively providing help and validating information entered by users. Most of all, a high-functioning form never requires its users to pause to wait for processing. These principles apply whether a form is used for sales orders, feedback surveys, product requests, or expense reporting. <br />
<br />
<br />
A classic server-based Web application is structured as a series of one or more forms. A user using a client machine enters information into a form and clicks a Submit or Go button. The information is sent to a server, where it is processed and a new page or form is created that is sent back to the user. This architecture makes few demands on the client machine. <br />
<br />
<br />
Unfortunately, this architecture also brings about the “World-Wide Wait” – that phenomenon where users around the world see an unresponsive screen after clicking the submit button. As a result, the usability and responsiveness of server-based Web applications represent a big step backward from the client/server or locally installed applications that they replaced. <br />
<br />
<img src="attachment.php?aid=32" /> <br />
Curl applications do the presentation work and, where appropriate, run application logic on the client side. Curl’s client-side processing capabilities offload a major computational burden from server machines and greatly reduce the amount of data transmitted from servers to clients. <br />
<img src="attachment.php?aid=33" /> <br />
This architecture allows Curl applications to provide “Active Forms” where validation and computations can be performed on the client without needing to continually submit information to the server. Certain selections by a user, such as indicating multiple beneficiaries on an insurance application, can even dynamically open out new panels required by the user's specific situation. <br />
<br />
<br />
One of the easiest examples is a form where the user inputs information which is then sent to a server. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=32" target="_blank" title="">FormProcessing.jpg</a> (Size: 22.92 KB / Downloads: 1833)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=33" target="_blank" title="">FormProcessingCurl.jpg</a> (Size: 18.5 KB / Downloads: 1782)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Forms-based transactions and data entry are a key part of most enterprise workflows. Well-designed forms streamline users' work through attractive, usable visual design; by providing well-chosen, relevant predefined options for user input; and by interactively providing help and validating information entered by users. Most of all, a high-functioning form never requires its users to pause to wait for processing. These principles apply whether a form is used for sales orders, feedback surveys, product requests, or expense reporting. <br />
<br />
<br />
A classic server-based Web application is structured as a series of one or more forms. A user using a client machine enters information into a form and clicks a Submit or Go button. The information is sent to a server, where it is processed and a new page or form is created that is sent back to the user. This architecture makes few demands on the client machine. <br />
<br />
<br />
Unfortunately, this architecture also brings about the “World-Wide Wait” – that phenomenon where users around the world see an unresponsive screen after clicking the submit button. As a result, the usability and responsiveness of server-based Web applications represent a big step backward from the client/server or locally installed applications that they replaced. <br />
<br />
<img src="attachment.php?aid=32" /> <br />
Curl applications do the presentation work and, where appropriate, run application logic on the client side. Curl’s client-side processing capabilities offload a major computational burden from server machines and greatly reduce the amount of data transmitted from servers to clients. <br />
<img src="attachment.php?aid=33" /> <br />
This architecture allows Curl applications to provide “Active Forms” where validation and computations can be performed on the client without needing to continually submit information to the server. Certain selections by a user, such as indicating multiple beneficiaries on an insurance application, can even dynamically open out new panels required by the user's specific situation. <br />
<br />
<br />
One of the easiest examples is a form where the user inputs information which is then sent to a server. <br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=32" target="_blank" title="">FormProcessing.jpg</a> (Size: 22.92 KB / Downloads: 1833)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=33" target="_blank" title="">FormProcessingCurl.jpg</a> (Size: 18.5 KB / Downloads: 1782)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Files over HTTP4:Viewing RecordSet Data]]></title>
			<link>https://communities.curl.com/showthread.php?tid=19</link>
			<pubDate>Wed, 15 Jun 2011 07:46:07 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=19</guid>
			<description><![CDATA[The primary class for the display of RecordSet data in a tabular format is RecordGrid. This provides a row and column display with built-in functionality for managing the display. The display can easily be modified, allowing you to add your own colors and preferences. <br />
<br />
<br />
An included navigation bar enables you to move to the first or last record, or up or down by one record. It also indicates the total number of records currently displayed, and the position of the current record in the display. By default, a RecordGrid includes the following functionality: <br />
<br />
<br />
•Move columns <br />
<br />
•Resize columns <br />
<br />
•Sort records <br />
<br />
•Filter records <br />
<br />
•Select and edit a field <br />
<br />
•Select one or more records <br />
<br />
<br />
Modeling data in a RecordSet provides access to many convenience features and functions. This Curl Cue concentrates on displaying RecordSet data in a grid fomat. RecordSet data can also be transformed into other display types such as bar, pie, line, scatter, and bubble charts. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating a RecordGrid</span> <br />
Use the RecordGrid class to create the tabular display. The only input needed is the record-source which specifies the RecordSet data. <br />
<br />
Notice that the rows and columns correspond to records and fields from the source RecordSet. The navigation panel at the bottom of the display enables you to move to the first or last record, or up or down by one record. It also indicates the total number of records currently displayed, and the position of the current record in the display. <br />
<br />
<br />
Context sensitive menus are available by right-clicking on the column header. Options include sorting and filtering the displayed data. <br />
<br />
<img src="attachment.php?aid=31" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Changing the RecordGrid Appearance</span> <br />
In the next example, we will change the appearance of the table using formatting options on the RecordGrid. <br />
<br />
width='100%' height='740' src='/wiki/samples/generic-example.curl?Data/recordset-2.curl' <br />
<br />
<br />
There are many options that can be used to specify the formatting. The following is a list of possibilities: <br />
<br />
•alternate-row-background <br />
<br />
•background <br />
<br />
•color <br />
<br />
•header-spec <br />
<br />
•display-column-headers? <br />
<br />
•display-filler-column? <br />
<br />
•grid-line-color <br />
<br />
•horizontal-grid-line-width <br />
<br />
•vertical-grid-line-width <br />
<br />
<br />
You can also turn off the standard grid features, such as the column headings (at the top of the display) and navigation panel (at the bottom of the display): <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28} <br />
} <br />
<br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items, <br />
display-navigation-panel? = false, <br />
display-column-headers? = false, <br />
height = 2.5cm, <br />
width = 9.9cm, <br />
display-filler-column? = true, <br />
alternate-row-background = "#ccccff", <br />
grid-line-color = "gray", <br />
horizontal-grid-line-width = 2px, <br />
vertical-grid-line-width = 4px <br />
} <br />
record-display <br />
}</code></div></div> <br />
<span style="font-weight: bold;" class="mycode_b">Specifying Columns and Display Formats</span> <br />
The default display for a RecordGrid is to sequentially present the defined Record data. In some cases, you may only want to display a portion of the data. In other cases you may want to rearrange the column order or provide special formatting. <br />
<br />
<br />
You can create columns explicitly with RecordGridColumn, which enables you to set properties that control column appearance and function. Columns can also be created automatically and you only need to add a column yourself it you want to customize the column. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int}, <br />
{RecordField "Price", domain = double} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12, Price = 4.75}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100, Price = 12.25}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6, Price = 8.50}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28, Price = 3.45} <br />
} <br />
<br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items, <br />
display-filler-column? = true, <br />
alternate-row-background = "#ccccff", <br />
grid-line-color = "gray", <br />
horizontal-grid-line-width = 2px, <br />
vertical-grid-line-width = 4px, <br />
width = 9.9cm, <br />
height = 3.5cm, <br />
automatic-columns? = false, <br />
{RecordGridColumn "Description"}, <br />
{RecordGridColumn "Item", font-weight = "bold"}, <br />
{RecordGridColumn "Price", halign = "right", format-spec = "&#36;%.2f"} <br />
} <br />
record-display <br />
}</code></div></div> <br />
<br />
<br />
We implemented this functionality by setting automatic-columns? = false and then specifying each RecordGridColumn. In the above example, we display three out of four record columns. <br />
<br />
<br />
Modeling data in a RecordSet provides access to many convenience features and functions. We have already demonstrated the ease of displaying RecordSet data in a grid fomat. RecordSet data can also drive other display types such as bar, pie, line, scatter, and bubble charts <br />
<br />
<br />
<br />
For more information regarding file connections, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Data Records and Grids</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=31" target="_blank" title="">recordgrid.jpg</a> (Size: 13.15 KB / Downloads: 1643)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[The primary class for the display of RecordSet data in a tabular format is RecordGrid. This provides a row and column display with built-in functionality for managing the display. The display can easily be modified, allowing you to add your own colors and preferences. <br />
<br />
<br />
An included navigation bar enables you to move to the first or last record, or up or down by one record. It also indicates the total number of records currently displayed, and the position of the current record in the display. By default, a RecordGrid includes the following functionality: <br />
<br />
<br />
•Move columns <br />
<br />
•Resize columns <br />
<br />
•Sort records <br />
<br />
•Filter records <br />
<br />
•Select and edit a field <br />
<br />
•Select one or more records <br />
<br />
<br />
Modeling data in a RecordSet provides access to many convenience features and functions. This Curl Cue concentrates on displaying RecordSet data in a grid fomat. RecordSet data can also be transformed into other display types such as bar, pie, line, scatter, and bubble charts. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Creating a RecordGrid</span> <br />
Use the RecordGrid class to create the tabular display. The only input needed is the record-source which specifies the RecordSet data. <br />
<br />
Notice that the rows and columns correspond to records and fields from the source RecordSet. The navigation panel at the bottom of the display enables you to move to the first or last record, or up or down by one record. It also indicates the total number of records currently displayed, and the position of the current record in the display. <br />
<br />
<br />
Context sensitive menus are available by right-clicking on the column header. Options include sorting and filtering the displayed data. <br />
<br />
<img src="attachment.php?aid=31" /> <br />
<br />
<span style="font-weight: bold;" class="mycode_b">Changing the RecordGrid Appearance</span> <br />
In the next example, we will change the appearance of the table using formatting options on the RecordGrid. <br />
<br />
width='100%' height='740' src='/wiki/samples/generic-example.curl?Data/recordset-2.curl' <br />
<br />
<br />
There are many options that can be used to specify the formatting. The following is a list of possibilities: <br />
<br />
•alternate-row-background <br />
<br />
•background <br />
<br />
•color <br />
<br />
•header-spec <br />
<br />
•display-column-headers? <br />
<br />
•display-filler-column? <br />
<br />
•grid-line-color <br />
<br />
•horizontal-grid-line-width <br />
<br />
•vertical-grid-line-width <br />
<br />
<br />
You can also turn off the standard grid features, such as the column headings (at the top of the display) and navigation panel (at the bottom of the display): <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28} <br />
} <br />
<br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items, <br />
display-navigation-panel? = false, <br />
display-column-headers? = false, <br />
height = 2.5cm, <br />
width = 9.9cm, <br />
display-filler-column? = true, <br />
alternate-row-background = "#ccccff", <br />
grid-line-color = "gray", <br />
horizontal-grid-line-width = 2px, <br />
vertical-grid-line-width = 4px <br />
} <br />
record-display <br />
}</code></div></div> <br />
<span style="font-weight: bold;" class="mycode_b">Specifying Columns and Display Formats</span> <br />
The default display for a RecordGrid is to sequentially present the defined Record data. In some cases, you may only want to display a portion of the data. In other cases you may want to rearrange the column order or provide special formatting. <br />
<br />
<br />
You can create columns explicitly with RecordGridColumn, which enables you to set properties that control column appearance and function. Columns can also be created automatically and you only need to add a column yourself it you want to customize the column. <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int}, <br />
{RecordField "Price", domain = double} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12, Price = 4.75}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100, Price = 12.25}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6, Price = 8.50}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28, Price = 3.45} <br />
} <br />
<br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items, <br />
display-filler-column? = true, <br />
alternate-row-background = "#ccccff", <br />
grid-line-color = "gray", <br />
horizontal-grid-line-width = 2px, <br />
vertical-grid-line-width = 4px, <br />
width = 9.9cm, <br />
height = 3.5cm, <br />
automatic-columns? = false, <br />
{RecordGridColumn "Description"}, <br />
{RecordGridColumn "Item", font-weight = "bold"}, <br />
{RecordGridColumn "Price", halign = "right", format-spec = "&#36;%.2f"} <br />
} <br />
record-display <br />
}</code></div></div> <br />
<br />
<br />
We implemented this functionality by setting automatic-columns? = false and then specifying each RecordGridColumn. In the above example, we display three out of four record columns. <br />
<br />
<br />
Modeling data in a RecordSet provides access to many convenience features and functions. We have already demonstrated the ease of displaying RecordSet data in a grid fomat. RecordSet data can also drive other display types such as bar, pie, line, scatter, and bubble charts <br />
<br />
<br />
<br />
For more information regarding file connections, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Data Records and Grids</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=31" target="_blank" title="">recordgrid.jpg</a> (Size: 13.15 KB / Downloads: 1643)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Files over HTTP3:Connected Data]]></title>
			<link>https://communities.curl.com/showthread.php?tid=18</link>
			<pubDate>Wed, 15 Jun 2011 07:42:00 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=18</guid>
			<description><![CDATA[Using the Curl API, you can connect directly to a database server or a set of files extracted from a database. You access data through a BasicConnection or a FileConnection. A FileConnection creates a connection to a set of files in comma separated value (CSV) format. A BasicConnection creates a connection to a server-side database management system via a servlet and a simple XML protocol over HTTP. We'll discuss each of these scenarios in this Curl Cue. <br />
<br />
<br />
Both BasicConnection and FileConnection are subsets of a Connection class that provide access to relational data organized as a collection of databases, each of which contains a collection of tables. Each table, in turn, can be accessed as a Curl RecordSet object. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a File Connection</span> <br />
The FileConnection class is easiest for simple applications. You can have a single table or a group of related tables in which specific data can be queried for use within the Curl application. In this scenario, CSV-formatted descriptor files are used to describe the data location and structure. Since this metadata is described in files, is easy to modify and does not need to be embedded in the Curl code. <br />
<br />
<br />
A FileConnection accesses data structured as a collection of files that play the following roles: <br />
<br />
•A database descriptor file <br />
<br />
•Table descriptor files <br />
<br />
•One or more CSV data files <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Database Descriptor File</span> <br />
A database descriptor file describes the databases available on the connection, and the tables in each database. You provide the Url of this file to the constructor when you create the FileConnection. This file is used to locate other descriptor files that describe the databases and tables available through the connection. The database descriptor file contains an initial header line, in which you can put labels that help you remember the meaning of the fields in the following lines. For this example, we created the file connection.csv which contains the following information: <br />
<img src="attachment.php?aid=28" /> <br />
connection.csv <br />
<br />
<br />
•Database: the name of a database. <br />
<br />
•Table: the name of a table in the database. <br />
<br />
•Location: the name of the file that contains data stored in this table. <br />
<br />
•FieldsLocation: the location and name of the table descriptor file for the table named in the Table field. <br />
<br />
•HeaderLines: the number of header lines in the data storage file named in the Location field. <br />
<br />
•Encoding: The character encoding for the data storage file. <br />
<br />
<br />
This file can have multiple records. Each record in the database descriptor file represents a table and specifies the location of the data and the table descriptor files. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Table Descriptor File </span> <br />
The table descriptor file is named in the ''FieldsLocation'' of the database descriptor file and describes the fields of the corresponding table. Here is an example of a table descriptor file: <br />
<img src="attachment.php?aid=29" /> <br />
inventory_fields.csv <br />
<br />
<br />
•name: the name of a field in the table. <br />
<br />
•caption: a caption for the field. <br />
<br />
•domain: a string that describes the domain for the field. <br />
<br />
•default: the default value for this field. <br />
<br />
•modifiable?: specifies whether this field is modifiable. <br />
<br />
•nullable?: specifies whether the value of this field can be null. <br />
<br />
<br />
For example, this table descriptor file specifies the data fields of our example CSV data file. Like the database descriptor file, a table descriptor file begins with a header line that contains labels for the fields in the file. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">CSV Data Files</span> <br />
And finally, let's discuss our data. The CSV file stores all the data we will be converting to a RecordSet. Remember that you can access more than one CSV data file, as long as each one is described in the database descriptor file <br />
inventory_fields.csv <br />
<img src="attachment.php?aid=30" /> <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{import * from CURL.DATA-ACCESS.CONNECTED} <br />
{value <br />
let con:FileConnection = {FileConnection {url "connection.csv"}} <br />
let rs:RecordSet = {con.create-record-set "sample", "inventory"} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
It is important to note that FileConnection is defined in the CURL.DATA-ACCESS.CONNECTED package. Therefore, we need to explicitly import this package. <br />
<br />
<br />
<br />
<br />
For more information regarding file connections, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Managing Data from External Sources > Using RecordSets with Data Files</span> <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a Basic Connection </span> <br />
The BasicConnection class allows you to directly connect to a database server and create RecordSets that are used in a Curl application. To use the BasicConnection object you need to create a servlet on the server that implements the server side of the BasicConnection protocol. <br />
<br />
<br />
Once this infrastructure is set up, you create a connected record set in two steps. <br />
<br />
1.Create a BasicConnection object, <br />
<br />
2.Call the method Connection.create-record-set <br />
<br />
<br />
The url provided to the BasicConnection constructor identifies the servlet that implements the server side of the protocol. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{import * from CURL.DATA-ACCESS.BASE} <br />
{import * from CURL.DATA-ACCESS.CONNECTED} <br />
{let connection:BasicConnection = <br />
{BasicConnection {url http://localhost:8080/test-server/TestServlet}} <br />
}</code></div></div> <br />
In this case, TestServlet is the servlet located on the data server. Once the connection is established, the create-record-set method will directly create a RecordSet using data from the server. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{RecordGrid <br />
record-source = {connection.create-record-set sample, inventory} <br />
}</code></div></div> <br />
Once the RecordSet is created, the API for accessing the data is the same as with a FileConnection. <br />
<br />
<br />
<br />
Use a ConnectedRecordSet just as you use any other RecordSet. If it is modifiable, and if the database server allows it, committing changes to the ConnectedRecordSet updates the data on the database server. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=28" target="_blank" title="">databasedescriptor.jpg</a> (Size: 12.53 KB / Downloads: 2583)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=29" target="_blank" title="">datadescriptor.jpg</a> (Size: 16.28 KB / Downloads: 2431)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=30" target="_blank" title="">conncsvdata.jpg</a> (Size: 9.81 KB / Downloads: 2565)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Using the Curl API, you can connect directly to a database server or a set of files extracted from a database. You access data through a BasicConnection or a FileConnection. A FileConnection creates a connection to a set of files in comma separated value (CSV) format. A BasicConnection creates a connection to a server-side database management system via a servlet and a simple XML protocol over HTTP. We'll discuss each of these scenarios in this Curl Cue. <br />
<br />
<br />
Both BasicConnection and FileConnection are subsets of a Connection class that provide access to relational data organized as a collection of databases, each of which contains a collection of tables. Each table, in turn, can be accessed as a Curl RecordSet object. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a File Connection</span> <br />
The FileConnection class is easiest for simple applications. You can have a single table or a group of related tables in which specific data can be queried for use within the Curl application. In this scenario, CSV-formatted descriptor files are used to describe the data location and structure. Since this metadata is described in files, is easy to modify and does not need to be embedded in the Curl code. <br />
<br />
<br />
A FileConnection accesses data structured as a collection of files that play the following roles: <br />
<br />
•A database descriptor file <br />
<br />
•Table descriptor files <br />
<br />
•One or more CSV data files <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Database Descriptor File</span> <br />
A database descriptor file describes the databases available on the connection, and the tables in each database. You provide the Url of this file to the constructor when you create the FileConnection. This file is used to locate other descriptor files that describe the databases and tables available through the connection. The database descriptor file contains an initial header line, in which you can put labels that help you remember the meaning of the fields in the following lines. For this example, we created the file connection.csv which contains the following information: <br />
<img src="attachment.php?aid=28" /> <br />
connection.csv <br />
<br />
<br />
•Database: the name of a database. <br />
<br />
•Table: the name of a table in the database. <br />
<br />
•Location: the name of the file that contains data stored in this table. <br />
<br />
•FieldsLocation: the location and name of the table descriptor file for the table named in the Table field. <br />
<br />
•HeaderLines: the number of header lines in the data storage file named in the Location field. <br />
<br />
•Encoding: The character encoding for the data storage file. <br />
<br />
<br />
This file can have multiple records. Each record in the database descriptor file represents a table and specifies the location of the data and the table descriptor files. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Table Descriptor File </span> <br />
The table descriptor file is named in the ''FieldsLocation'' of the database descriptor file and describes the fields of the corresponding table. Here is an example of a table descriptor file: <br />
<img src="attachment.php?aid=29" /> <br />
inventory_fields.csv <br />
<br />
<br />
•name: the name of a field in the table. <br />
<br />
•caption: a caption for the field. <br />
<br />
•domain: a string that describes the domain for the field. <br />
<br />
•default: the default value for this field. <br />
<br />
•modifiable?: specifies whether this field is modifiable. <br />
<br />
•nullable?: specifies whether the value of this field can be null. <br />
<br />
<br />
For example, this table descriptor file specifies the data fields of our example CSV data file. Like the database descriptor file, a table descriptor file begins with a header line that contains labels for the fields in the file. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">CSV Data Files</span> <br />
And finally, let's discuss our data. The CSV file stores all the data we will be converting to a RecordSet. Remember that you can access more than one CSV data file, as long as each one is described in the database descriptor file <br />
inventory_fields.csv <br />
<img src="attachment.php?aid=30" /> <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{import * from CURL.DATA-ACCESS.CONNECTED} <br />
{value <br />
let con:FileConnection = {FileConnection {url "connection.csv"}} <br />
let rs:RecordSet = {con.create-record-set "sample", "inventory"} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
It is important to note that FileConnection is defined in the CURL.DATA-ACCESS.CONNECTED package. Therefore, we need to explicitly import this package. <br />
<br />
<br />
<br />
<br />
For more information regarding file connections, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Managing Data from External Sources > Using RecordSets with Data Files</span> <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Using a Basic Connection </span> <br />
The BasicConnection class allows you to directly connect to a database server and create RecordSets that are used in a Curl application. To use the BasicConnection object you need to create a servlet on the server that implements the server side of the BasicConnection protocol. <br />
<br />
<br />
Once this infrastructure is set up, you create a connected record set in two steps. <br />
<br />
1.Create a BasicConnection object, <br />
<br />
2.Call the method Connection.create-record-set <br />
<br />
<br />
The url provided to the BasicConnection constructor identifies the servlet that implements the server side of the protocol. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{import * from CURL.DATA-ACCESS.BASE} <br />
{import * from CURL.DATA-ACCESS.CONNECTED} <br />
{let connection:BasicConnection = <br />
{BasicConnection {url http://localhost:8080/test-server/TestServlet}} <br />
}</code></div></div> <br />
In this case, TestServlet is the servlet located on the data server. Once the connection is established, the create-record-set method will directly create a RecordSet using data from the server. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{RecordGrid <br />
record-source = {connection.create-record-set sample, inventory} <br />
}</code></div></div> <br />
Once the RecordSet is created, the API for accessing the data is the same as with a FileConnection. <br />
<br />
<br />
<br />
Use a ConnectedRecordSet just as you use any other RecordSet. If it is modifiable, and if the database server allows it, committing changes to the ConnectedRecordSet updates the data on the database server. <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=28" target="_blank" title="">databasedescriptor.jpg</a> (Size: 12.53 KB / Downloads: 2583)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=29" target="_blank" title="">datadescriptor.jpg</a> (Size: 16.28 KB / Downloads: 2431)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=30" target="_blank" title="">conncsvdata.jpg</a> (Size: 9.81 KB / Downloads: 2565)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Files over HTTP2:Organizing Data using RecordSets]]></title>
			<link>https://communities.curl.com/showthread.php?tid=17</link>
			<pubDate>Wed, 15 Jun 2011 07:35:57 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=17</guid>
			<description><![CDATA[Handling the management of structured data can take on many different forms in the Curl language. Our goal is to obtain content into a form we can easily represent internally for manipulation and display. A primary class for data management is RecordSet, which organizes data in terms of records and fields, and manages events having to do with changes in the data. RecordSets are especially useful for dealing with data derived from one or more databases on a server, or data that is intended to be written to a database. It enables the end user to perform many database-like operations on the data, such as filtering and sorting, directly on the client machine without needing to invoke database functions on the server. <br />
<br />
<br />
The standard Curl API provides a foundation for representing relationally structured data. RecordSet and related classes provide support for representation, manipulation, display and coordination of such data, thoroughly integrated with Curl graphics. Thus, a RecordSet is the obvious choice for model representation for 'data centric' applications which consume structured datasets from some external (server) provider. Furthermore, because of the breadth of standard functionality, RecordSets should also be considered as the basis for internal structures. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">RecordSet Data</span> <br />
A RecordSet holds a collection of Records, each of which contains values for a predefined set of keys (columns). The column structure is specified by field descriptors (using RecordField and RecordFields), which name and characterize the allowable values. <br />
<img src="attachment.php?aid=26" /> <br />
In Curl, there are two ways to easily create a RecordSet: <br />
<br />
1.Build the RecordSet programmatically directly in the source code <br />
<br />
2.Import data that is structured using comma separated values <br />
<br />
<br />
Both methods allow you to quickly create data structured in record format. The methods above should be used for small amounts of data, or data that does not change rapidly. You can easily adapt these concepts to your own data, allowing you quickly create a RecordSet structure that can be used as input into grid, charts, and forms. <br />
<br />
<br />
The Curl API also includes features for creating a RecordSet that is directly connected to a database or remote data file. This is discussed in the <a href="http://developers.curl.com/docs/DOC-1109" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1109</a> Curl Cue. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Programmatically Create a RecordSet </span> <br />
As with most Curl objects, a RecordSet can be specified completely declaratively, using the rest arguments of its constructor. <br />
<br />
•The RecordFields object is used to define the collection of RecordField objects, each of which describes the data format and type of one column in the RecordSet. <br />
<br />
•The RecordData object is used to organize value tuples which produce successive member Records. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28} <br />
} <br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items <br />
} <br />
record-display <br />
}</code></div></div> <br />
In the example above, we are specifying the item name and type using a RecordField. For example, the first RecordField is defined as {RecordField "Item", domain = String} . This specifies the name of the field to be "Item" and the type of the data in the field to be a String. Each record is specified by a RecordData expression where the value of each field is specified as a keyword argument using the name of the field as the keyword. A RecordGrid is used to automatically provide a tabular display of the RecordSet data. <br />
<br />
<br />
<br />
Standard Domains are defined for the following basic Curl types: char, String, int, int64, float, double, bool, DateTime, Time, or any <br />
<br />
<br />
<br />
<br />
For more information regarding RecordSets, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Data Records and Grids</span> <br />
<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Creating a CsvRecordSet</code></div></div> <br />
CSV stands for Comma Separated Values, sometimes also called Comma Delimited. A CSV file is a specially formatted plain text file which stores spreadsheet or basic database-style information in a very simple format, with one record on each line, and each field within that record separated by a comma. <br />
<br />
<br />
CSV files are often used as a simple way to transfer a large volume of spreadsheet or database information between programs, without worrying about special file types. For example, transferring a home-made address book from Microsoft® Excel into a database program such as Filemaker® Pro could be done by exporting the file as a CSV from Excel, then importing that CSV into Filemaker. <br />
<br />
<br />
Curl also has APIs for working directly with data files in CSV format. CsvRecordSet is a subclass of RecordSet and it allows you to automatically create one or more Records in a RecordSet. <br />
<br />
<br />
Let's begin our example with a CSV file. This example uses a data file created using Microsoft ® Excel and saved in CSV format. Each line in the file is a record. Each field in the file is separated from its neighbor by a comma. <br />
<img src="attachment.php?aid=27" /> <br />
We'll use a CsvRecordSet to import the contents of our file into Curl. CsvRecordSet does the following: <br />
<br />
•Creates a Record from each line of the CSV data <br />
<br />
•Parses each field of the data <br />
<br />
•Converts each field into a Curl datatype <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let rs:CsvRecordSet = <br />
{CsvRecordSet <br />
{url "inventory_items.csv"} <br />
} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
The above example shows how you can quickly bring your data into Curl. CsvRecordSet automatically attempts to map the CSV content into an equivalent datatype using DomainDetector. This automatically detects the type of data in each column of a CSV file. <br />
<br />
<br />
Alternatively, we can provide a RecordFields object that defines the expected structure and domain of the data. In this case, CsvRecordSet attempts to parse each field of the data file in terms of the Domain specified in the corresponding RecordField. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let rs:CsvRecordSet = <br />
{CsvRecordSet <br />
{url "inventory_items.csv"}, <br />
fields = <br />
{RecordFields <br />
{RecordField "Item", <br />
domain = String, <br />
index-type = RecordFieldIndexType.unique <br />
}, <br />
{RecordField "Description", <br />
domain = String <br />
}, <br />
{RecordField "Quantity", <br />
domain = int <br />
}, <br />
{RecordField "Price", <br />
domain = double <br />
} <br />
} <br />
} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
In this case, CsvRecordSet parses each field of the data file in terms of the Domain specified in the corresponding RecordField. In our example, we are specifying the following data types: <br />
<br />
•Item --> String <br />
<br />
•Description --> String <br />
<br />
•Quantity --> int <br />
<br />
•Price --> double <br />
<br />
<br />
Also note that the column headings for each Record are specified by the RecordFields object. A caption can also be set for each column, allowing you to keep the internal name and specify a different name for display. <br />
<br />
<br />
<br />
If the string data in the file cannot be converted to an object of the appropriate type, the code throws an error. <br />
<br />
<br />
<br />
In summary, a RecordSet enables you to write applications that manage data organized in records and fields. <br />
<br />
•Manage events corresponding to data changes <br />
<br />
•Perform many database-like operations on the local data, such as filtering and sorting <br />
<br />
<br />
Two easy ways to create Record data in Curl are to programmatically create a RecordSet or use CsvRecordSet to import CSV data. <br />
<br />
<br />
<br />
For more information regarding CsvRecordSets, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Managing Data from External Sources > Using CSV Data Files</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=26" target="_blank" title="">Organizing Data using RecordSets1.JPG</a> (Size: 22.02 KB / Downloads: 1834)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=27" target="_blank" title="">csvdata.jpg</a> (Size: 9.81 KB / Downloads: 1874)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Handling the management of structured data can take on many different forms in the Curl language. Our goal is to obtain content into a form we can easily represent internally for manipulation and display. A primary class for data management is RecordSet, which organizes data in terms of records and fields, and manages events having to do with changes in the data. RecordSets are especially useful for dealing with data derived from one or more databases on a server, or data that is intended to be written to a database. It enables the end user to perform many database-like operations on the data, such as filtering and sorting, directly on the client machine without needing to invoke database functions on the server. <br />
<br />
<br />
The standard Curl API provides a foundation for representing relationally structured data. RecordSet and related classes provide support for representation, manipulation, display and coordination of such data, thoroughly integrated with Curl graphics. Thus, a RecordSet is the obvious choice for model representation for 'data centric' applications which consume structured datasets from some external (server) provider. Furthermore, because of the breadth of standard functionality, RecordSets should also be considered as the basis for internal structures. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">RecordSet Data</span> <br />
A RecordSet holds a collection of Records, each of which contains values for a predefined set of keys (columns). The column structure is specified by field descriptors (using RecordField and RecordFields), which name and characterize the allowable values. <br />
<img src="attachment.php?aid=26" /> <br />
In Curl, there are two ways to easily create a RecordSet: <br />
<br />
1.Build the RecordSet programmatically directly in the source code <br />
<br />
2.Import data that is structured using comma separated values <br />
<br />
<br />
Both methods allow you to quickly create data structured in record format. The methods above should be used for small amounts of data, or data that does not change rapidly. You can easily adapt these concepts to your own data, allowing you quickly create a RecordSet structure that can be used as input into grid, charts, and forms. <br />
<br />
<br />
The Curl API also includes features for creating a RecordSet that is directly connected to a database or remote data file. This is discussed in the <a href="http://developers.curl.com/docs/DOC-1109" target="_blank" rel="noopener" class="mycode_url">http://developers.curl.com/docs/DOC-1109</a> Curl Cue. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Programmatically Create a RecordSet </span> <br />
As with most Curl objects, a RecordSet can be specified completely declaratively, using the rest arguments of its constructor. <br />
<br />
•The RecordFields object is used to define the collection of RecordField objects, each of which describes the data format and type of one column in the RecordSet. <br />
<br />
•The RecordData object is used to organize value tuples which produce successive member Records. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let items:RecordSet = <br />
{RecordSet <br />
{RecordFields <br />
{RecordField "Item", domain = String}, <br />
{RecordField "Description", domain = String}, <br />
{RecordField "Quantity", domain = int} <br />
}, <br />
{RecordData Item = "PR1400", Description = "Blue pens", Quantity = 12}, <br />
{RecordData Item = "LG4597", Description = "Envelopes", Quantity = 100}, <br />
{RecordData Item = "NP3400", Description = "Notepads", Quantity = 6}, <br />
{RecordData Item = "PN5601", Description = "Pencils", Quantity = 28} <br />
} <br />
let record-display:RecordGrid = <br />
{RecordGrid <br />
record-source = items <br />
} <br />
record-display <br />
}</code></div></div> <br />
In the example above, we are specifying the item name and type using a RecordField. For example, the first RecordField is defined as {RecordField "Item", domain = String} . This specifies the name of the field to be "Item" and the type of the data in the field to be a String. Each record is specified by a RecordData expression where the value of each field is specified as a keyword argument using the name of the field as the keyword. A RecordGrid is used to automatically provide a tabular display of the RecordSet data. <br />
<br />
<br />
<br />
Standard Domains are defined for the following basic Curl types: char, String, int, int64, float, double, bool, DateTime, Time, or any <br />
<br />
<br />
<br />
<br />
For more information regarding RecordSets, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Data Records and Grids</span> <br />
<br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>Creating a CsvRecordSet</code></div></div> <br />
CSV stands for Comma Separated Values, sometimes also called Comma Delimited. A CSV file is a specially formatted plain text file which stores spreadsheet or basic database-style information in a very simple format, with one record on each line, and each field within that record separated by a comma. <br />
<br />
<br />
CSV files are often used as a simple way to transfer a large volume of spreadsheet or database information between programs, without worrying about special file types. For example, transferring a home-made address book from Microsoft® Excel into a database program such as Filemaker® Pro could be done by exporting the file as a CSV from Excel, then importing that CSV into Filemaker. <br />
<br />
<br />
Curl also has APIs for working directly with data files in CSV format. CsvRecordSet is a subclass of RecordSet and it allows you to automatically create one or more Records in a RecordSet. <br />
<br />
<br />
Let's begin our example with a CSV file. This example uses a data file created using Microsoft ® Excel and saved in CSV format. Each line in the file is a record. Each field in the file is separated from its neighbor by a comma. <br />
<img src="attachment.php?aid=27" /> <br />
We'll use a CsvRecordSet to import the contents of our file into Curl. CsvRecordSet does the following: <br />
<br />
•Creates a Record from each line of the CSV data <br />
<br />
•Parses each field of the data <br />
<br />
•Converts each field into a Curl datatype <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let rs:CsvRecordSet = <br />
{CsvRecordSet <br />
{url "inventory_items.csv"} <br />
} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
The above example shows how you can quickly bring your data into Curl. CsvRecordSet automatically attempts to map the CSV content into an equivalent datatype using DomainDetector. This automatically detects the type of data in each column of a CSV file. <br />
<br />
<br />
Alternatively, we can provide a RecordFields object that defines the expected structure and domain of the data. In this case, CsvRecordSet attempts to parse each field of the data file in terms of the Domain specified in the corresponding RecordField. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
<br />
{value <br />
let rs:CsvRecordSet = <br />
{CsvRecordSet <br />
{url "inventory_items.csv"}, <br />
fields = <br />
{RecordFields <br />
{RecordField "Item", <br />
domain = String, <br />
index-type = RecordFieldIndexType.unique <br />
}, <br />
{RecordField "Description", <br />
domain = String <br />
}, <br />
{RecordField "Quantity", <br />
domain = int <br />
}, <br />
{RecordField "Price", <br />
domain = double <br />
} <br />
} <br />
} <br />
{RecordGrid record-source = rs, <br />
width = 6in, <br />
height = 2in <br />
} <br />
}</code></div></div> <br />
In this case, CsvRecordSet parses each field of the data file in terms of the Domain specified in the corresponding RecordField. In our example, we are specifying the following data types: <br />
<br />
•Item --> String <br />
<br />
•Description --> String <br />
<br />
•Quantity --> int <br />
<br />
•Price --> double <br />
<br />
<br />
Also note that the column headings for each Record are specified by the RecordFields object. A caption can also be set for each column, allowing you to keep the internal name and specify a different name for display. <br />
<br />
<br />
<br />
If the string data in the file cannot be converted to an object of the appropriate type, the code throws an error. <br />
<br />
<br />
<br />
In summary, a RecordSet enables you to write applications that manage data organized in records and fields. <br />
<br />
•Manage events corresponding to data changes <br />
<br />
•Perform many database-like operations on the local data, such as filtering and sorting <br />
<br />
<br />
Two easy ways to create Record data in Curl are to programmatically create a RecordSet or use CsvRecordSet to import CSV data. <br />
<br />
<br />
<br />
For more information regarding CsvRecordSets, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Data Management and Display > Managing Data from External Sources > Using CSV Data Files</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=26" target="_blank" title="">Organizing Data using RecordSets1.JPG</a> (Size: 22.02 KB / Downloads: 1834)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=27" target="_blank" title="">csvdata.jpg</a> (Size: 9.81 KB / Downloads: 1874)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Files over HTTP1:Files over HTTP]]></title>
			<link>https://communities.curl.com/showthread.php?tid=16</link>
			<pubDate>Wed, 15 Jun 2011 07:30:36 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=16</guid>
			<description><![CDATA[<span style="font-weight: bold;" class="mycode_b">File Access</span><br />
It is common for programs to read text from and write text to local or remote data files. An applet may need to read data from a Web page, or write data to the local machine for use the next time the program is run.<br />
<br />
 <br />
Reading from and writing to resources are generally accomplished the same way. A resource is identified, a stream is opened to it, the data is transferred, and the resource is closed. The resource is typically identified using a Url object. This Curl Cue will demonstrate how to read file resources. The examples will use text files obtained via HTTP, but it is worth noting that file access is the same whether the file is local or obtained over HTTP.<br />
<br />
 <br />
An input stream object provides the methods necessary to transfer the data. There are general classes and methods that provide the essential means for reading and writing data, but there are also high-level, convenience procedures that simplify many tasks.<br />
<br />
 <br />
The easiest way to read data from a resource is to treat the resource as a text file. Many resources, such as configuration files and Web pages, are commonly handled this way. In all textual cases, you will have to:<br />
<br />
1.Identify the Url<br />
<br />
2.Create a TextInputStream to read the data<br />
<br />
3.Read and store the data<br />
<br />
4.Close the TextInputStream<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Reading File Contents</span><br />
So, how do you read the contents of a file? For our example, we will access the business.txt file that has the following content:<br />
<br />
 <br />
Local Businesses<br />
<br />
Bakery<br />
<br />
Convenience Store<br />
<br />
Coffee Shop<br />
<br />
Print Shop<br />
<br />
Chiropractor<br />
<br />
Fitness Center<br />
<br />
Acupuncture<br />
<br />
Photo Shop<br />
<br />
Optician<br />
<br />
Shoe Store<br />
<br />
 <br />
The easiest way to read the entire contents of a file is to use the read-from procedure. This procedure is actually a utility procedure that combines several operations:<br />
<br />
1.It automatically opens the given url as a TextInputStream<br />
<br />
2.It reads all the characters out of it into a StringBuf<br />
<br />
3.It returns the StringBuf.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
<br />
{pre {read-from {url "business.txt"}}}</code></div></div><br />
The pre text format displays the paragraph contents in a monospace font, preserving whitespace and newlines.<br />
 <br />
<br />
 <br />
Once the file is read, the program can manipulate the StringBuf, or in the case above, we just displayed the content using pre. You may need to convert the content to a String for further processing, for example: {{read-from {url "business.txt"}}.to-String}.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Reading Line by Line</span><br />
One of the most common ways to read text from a file is line by line. Most text files will have multiple lines to read, so this approach makes sense, especially if a line needs to be processed by the applet before the next line is read.<br />
<br />
 <br />
The next example demonstrates a simple way to read a text file line by line.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
<br />
{value<br />
&nbsp;&nbsp; || Create a StringBuf to hold the data<br />
&nbsp;&nbsp; let lines:StringArray = {StringArray}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; || Identify the url<br />
&nbsp;&nbsp; let location:Url = {url "business.txt"}<br />
<br />
&nbsp;&nbsp; {with-open-streams in = {read-open location} do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {until in.end-of-stream? do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {lines.append {{in.read-one-line}.to-String}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; || Display the stored information<br />
&nbsp;&nbsp; let display:VBox =&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background = "beige",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-style = "sunken",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-width = 2pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-color = "navy",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin = 4pt<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; {for line key k in lines do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if k==0 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add {bold {underline {value line}}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add line}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; display<br />
}</code></div></div>We use with-open-streams to read each line of a given file and store it in a StringArray. Notice that we detect the end of the file using the end-of-stream? accessor.<br />
<br />
 <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{with-open-streams in = {read-open location} do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {until in.end-of-stream? do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {lines.append {{in.read-one-line}.to-String{font}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;}</code></div></div>For the display VBox content, we looped through the lines StringArray. The loop is organized so that the first line will be displayed underlined and bolded.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{for line key k in lines do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if k==0 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add {bold {underline{value line{font}{font}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add line}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;}</code></div></div>In this Curl Cue, we identified two main ways to read file content. The Curl language has many stream classes that can be used based on your application needs. These include:<br />
<br />
 <br />
•Text and binary streams<br />
<br />
•Buffered and unbuffered streams<br />
<br />
•Seekable and nonseekable streams<br />
<br />
 <br />
<br />
 For more information regarding reading file content, please refer to the following section in the Curl Documentation:<font color="#000080">Curl Developer's Guide &gt; File Systems and Networking &gt; Accessing Files and Other Resources</font><br />
 <br />
<br />
<br />
]]></description>
			<content:encoded><![CDATA[<span style="font-weight: bold;" class="mycode_b">File Access</span><br />
It is common for programs to read text from and write text to local or remote data files. An applet may need to read data from a Web page, or write data to the local machine for use the next time the program is run.<br />
<br />
 <br />
Reading from and writing to resources are generally accomplished the same way. A resource is identified, a stream is opened to it, the data is transferred, and the resource is closed. The resource is typically identified using a Url object. This Curl Cue will demonstrate how to read file resources. The examples will use text files obtained via HTTP, but it is worth noting that file access is the same whether the file is local or obtained over HTTP.<br />
<br />
 <br />
An input stream object provides the methods necessary to transfer the data. There are general classes and methods that provide the essential means for reading and writing data, but there are also high-level, convenience procedures that simplify many tasks.<br />
<br />
 <br />
The easiest way to read data from a resource is to treat the resource as a text file. Many resources, such as configuration files and Web pages, are commonly handled this way. In all textual cases, you will have to:<br />
<br />
1.Identify the Url<br />
<br />
2.Create a TextInputStream to read the data<br />
<br />
3.Read and store the data<br />
<br />
4.Close the TextInputStream<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Reading File Contents</span><br />
So, how do you read the contents of a file? For our example, we will access the business.txt file that has the following content:<br />
<br />
 <br />
Local Businesses<br />
<br />
Bakery<br />
<br />
Convenience Store<br />
<br />
Coffee Shop<br />
<br />
Print Shop<br />
<br />
Chiropractor<br />
<br />
Fitness Center<br />
<br />
Acupuncture<br />
<br />
Photo Shop<br />
<br />
Optician<br />
<br />
Shoe Store<br />
<br />
 <br />
The easiest way to read the entire contents of a file is to use the read-from procedure. This procedure is actually a utility procedure that combines several operations:<br />
<br />
1.It automatically opens the given url as a TextInputStream<br />
<br />
2.It reads all the characters out of it into a StringBuf<br />
<br />
3.It returns the StringBuf.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
<br />
{pre {read-from {url "business.txt"}}}</code></div></div><br />
The pre text format displays the paragraph contents in a monospace font, preserving whitespace and newlines.<br />
 <br />
<br />
 <br />
Once the file is read, the program can manipulate the StringBuf, or in the case above, we just displayed the content using pre. You may need to convert the content to a String for further processing, for example: {{read-from {url "business.txt"}}.to-String}.<br />
<br />
 <br />
<span style="font-weight: bold;" class="mycode_b">Reading Line by Line</span><br />
One of the most common ways to read text from a file is line by line. Most text files will have multiple lines to read, so this approach makes sense, especially if a line needs to be processed by the applet before the next line is read.<br />
<br />
 <br />
The next example demonstrates a simple way to read a text file line by line.<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet}<br />
<br />
{value<br />
&nbsp;&nbsp; || Create a StringBuf to hold the data<br />
&nbsp;&nbsp; let lines:StringArray = {StringArray}<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; || Identify the url<br />
&nbsp;&nbsp; let location:Url = {url "business.txt"}<br />
<br />
&nbsp;&nbsp; {with-open-streams in = {read-open location} do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {until in.end-of-stream? do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {lines.append {{in.read-one-line}.to-String}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp; || Display the stored information<br />
&nbsp;&nbsp; let display:VBox =&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background = "beige",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-style = "sunken",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-width = 2pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-color = "navy",<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin = 4pt<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; {for line key k in lines do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if k==0 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add {bold {underline {value line}}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add line}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp; }<br />
&nbsp;&nbsp; <br />
&nbsp;&nbsp; display<br />
}</code></div></div>We use with-open-streams to read each line of a given file and store it in a StringArray. Notice that we detect the end of the file using the end-of-stream? accessor.<br />
<br />
 <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{with-open-streams in = {read-open location} do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {until in.end-of-stream? do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {lines.append {{in.read-one-line}.to-String{font}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;}</code></div></div>For the display VBox content, we looped through the lines StringArray. The loop is organized so that the first line will be displayed underlined and bolded.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{for line key k in lines do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {if k==0 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add {bold {underline{value line{font}{font}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {display.add line}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;}</code></div></div>In this Curl Cue, we identified two main ways to read file content. The Curl language has many stream classes that can be used based on your application needs. These include:<br />
<br />
 <br />
•Text and binary streams<br />
<br />
•Buffered and unbuffered streams<br />
<br />
•Seekable and nonseekable streams<br />
<br />
 <br />
<br />
 For more information regarding reading file content, please refer to the following section in the Curl Documentation:<font color="#000080">Curl Developer's Guide &gt; File Systems and Networking &gt; Accessing Files and Other Resources</font><br />
 <br />
<br />
<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[User Interface Basics7:Stretching Graphical Objects]]></title>
			<link>https://communities.curl.com/showthread.php?tid=15</link>
			<pubDate>Wed, 15 Jun 2011 07:12:52 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=15</guid>
			<description><![CDATA[Wouldn't it be easy if everyone had the same size monitor and same resolution? Fortunately, Curl makes it easy to build applications that stretch and compress. It is common to have fixed graphical elements in your applet, as well as elements that stretch and compress with the browser window. <br />
<br />
<br />
When Curl displays a page, it negotiates the layout of each element to determine the final size of each graphic. For graphics that do not have a height or width specified, Curl will look to the dimensions of the child objects. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Common Applet Scenario</span> <br />
It is common in Web design to have the following scenario: <br />
<br />
<br />
•One area of the page set as the navigation portion. This layout object will have a static width. <br />
<br />
•Another area of the page able to expand and compress in order to display the selected content <br />
<br />
<img src="attachment.php?aid=24" /> <br />
In Curl Cues up until now, we have always specified a fixed width or height, e.g. height = 1in. Extra stretchiness can be added to specific objects in your graphical hierarchy using the add-stretch procedure. This example demonstrates how a child object can specify its stretchiness using {add-stretch} for the value of either the width or height option of the object. Select the Show View button to view the example. Try resizing the window that pops up, to compare how the stretchy and non-stretchy objects behave. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
<br />
{value <br />
let stretch-box:HBox = {HBox <br />
height = {add-stretch}, <br />
{VBox <br />
background="teal", <br />
width=1in, <br />
{bold This is a fixed-width column of text}, <br />
{Fill} <br />
}, <br />
{VBox background="silver", <br />
width = {add-stretch}, <br />
{bold This is the stretchable content area. Using the mouse, resize the window making it larger and smaller}, <br />
{Fill} <br />
} <br />
} <br />
<br />
{CommandButton <br />
label = "Show View", <br />
{on Action do <br />
let v:View = {View stretch-box} <br />
{v.show} <br />
} <br />
} <br />
}</code></div></div> <br />
So what is actually happening? When the View is initially displayed: <br />
<br />
<br />
•The left VBox initializes with a width of 1in <br />
<br />
•The right VBox initializes using the preferred width of the text that it contains. The preferred width is automatically calculated by the TextFlowBox that is implicitly created to hold the text in the VBox. When sized according to this preferred width, the TextFlowBox will be able to display its contained text on one line. <br />
<br />
<br />
Notice that when you expand and compress the View, the left VBox maintains a constant width of 1in. Curl will adjust the width accordingly as long as the minimum size of each object can be obtained. The minimum sizes in our example are: <br />
<br />
<br />
•1in for the left VBox <br />
<br />
•The longest word contained within the TextFlowBox for the right VBox. In our example, this word (amusingly!) is the word "stretchable". <br />
<br />
<br />
Now, if you resize the window so its width is smaller than the sum of the minimum sizes, both VBoxes will compress proportionately. This is demonstrated in the picture below. <br />
<img src="attachment.php?aid=25" /> <br />
Of course, there are many scenarios that we can think of for stretching and compressing Curl graphics. For common cases, it is easiest to add elasticity using add-stretch. Alternatively, there are other ways to control stretchiness in Curl. Some containers have vstretch? and/or hstretch? options, and comprehensive control over the stretchiness, compressibility, and size properties of objects is available through the make-elastic procedure. (These features are beyond the scope of this Curl Cue.) <br />
<br />
<br />
<br />
<br />
For more information regarding elastics, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Elastics and Page Layout</span> <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Filling Space</span> <br />
You can use the Fill object to provide a form of stretchy spacing in your applications. A Fill object provides padding to fill empty spaces in graphical displays. These objects are intended to stretch easily to fill excess space, avoiding the stretching of other objects next to which the Fill may be placed. In other words, a Fill object creates highly stretchy Graphic that is typically used for setting the spacing between less stretchy objects. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
width = 5in, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "green", <br />
{bold Green} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "blue", <br />
{bold Blue} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "red", <br />
{bold Red} <br />
} <br />
}</code></div></div> <br />
Each Fill object in a container represents one unit of fill space. That is, if object A and object B are separated by one Fill, and object B and object C are separated by two Fills, then the space between B and C is twice as large as the space between A and B. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
width = 5in, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "green", <br />
{bold Green {br} (Object A)} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "blue", <br />
{bold Blue {br} (Object B)} <br />
}, <br />
{Fill}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "red", <br />
{bold Red {br} (Object C)} <br />
} <br />
}</code></div></div> <br />
For more information regarding Fills, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Graphical Shapes> Rule and Fill > Fill</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=24" target="_blank" title="">Stretching Graphical Objects1.JPG</a> (Size: 21.5 KB / Downloads: 1790)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=25" target="_blank" title="">Stretching Graphical Objects2.JPG</a> (Size: 7.18 KB / Downloads: 1736)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Wouldn't it be easy if everyone had the same size monitor and same resolution? Fortunately, Curl makes it easy to build applications that stretch and compress. It is common to have fixed graphical elements in your applet, as well as elements that stretch and compress with the browser window. <br />
<br />
<br />
When Curl displays a page, it negotiates the layout of each element to determine the final size of each graphic. For graphics that do not have a height or width specified, Curl will look to the dimensions of the child objects. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Common Applet Scenario</span> <br />
It is common in Web design to have the following scenario: <br />
<br />
<br />
•One area of the page set as the navigation portion. This layout object will have a static width. <br />
<br />
•Another area of the page able to expand and compress in order to display the selected content <br />
<br />
<img src="attachment.php?aid=24" /> <br />
In Curl Cues up until now, we have always specified a fixed width or height, e.g. height = 1in. Extra stretchiness can be added to specific objects in your graphical hierarchy using the add-stretch procedure. This example demonstrates how a child object can specify its stretchiness using {add-stretch} for the value of either the width or height option of the object. Select the Show View button to view the example. Try resizing the window that pops up, to compare how the stretchy and non-stretchy objects behave. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
<br />
{value <br />
let stretch-box:HBox = {HBox <br />
height = {add-stretch}, <br />
{VBox <br />
background="teal", <br />
width=1in, <br />
{bold This is a fixed-width column of text}, <br />
{Fill} <br />
}, <br />
{VBox background="silver", <br />
width = {add-stretch}, <br />
{bold This is the stretchable content area. Using the mouse, resize the window making it larger and smaller}, <br />
{Fill} <br />
} <br />
} <br />
<br />
{CommandButton <br />
label = "Show View", <br />
{on Action do <br />
let v:View = {View stretch-box} <br />
{v.show} <br />
} <br />
} <br />
}</code></div></div> <br />
So what is actually happening? When the View is initially displayed: <br />
<br />
<br />
•The left VBox initializes with a width of 1in <br />
<br />
•The right VBox initializes using the preferred width of the text that it contains. The preferred width is automatically calculated by the TextFlowBox that is implicitly created to hold the text in the VBox. When sized according to this preferred width, the TextFlowBox will be able to display its contained text on one line. <br />
<br />
<br />
Notice that when you expand and compress the View, the left VBox maintains a constant width of 1in. Curl will adjust the width accordingly as long as the minimum size of each object can be obtained. The minimum sizes in our example are: <br />
<br />
<br />
•1in for the left VBox <br />
<br />
•The longest word contained within the TextFlowBox for the right VBox. In our example, this word (amusingly!) is the word "stretchable". <br />
<br />
<br />
Now, if you resize the window so its width is smaller than the sum of the minimum sizes, both VBoxes will compress proportionately. This is demonstrated in the picture below. <br />
<img src="attachment.php?aid=25" /> <br />
Of course, there are many scenarios that we can think of for stretching and compressing Curl graphics. For common cases, it is easiest to add elasticity using add-stretch. Alternatively, there are other ways to control stretchiness in Curl. Some containers have vstretch? and/or hstretch? options, and comprehensive control over the stretchiness, compressibility, and size properties of objects is available through the make-elastic procedure. (These features are beyond the scope of this Curl Cue.) <br />
<br />
<br />
<br />
<br />
For more information regarding elastics, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Elastics and Page Layout</span> <br />
<br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Filling Space</span> <br />
You can use the Fill object to provide a form of stretchy spacing in your applications. A Fill object provides padding to fill empty spaces in graphical displays. These objects are intended to stretch easily to fill excess space, avoiding the stretching of other objects next to which the Fill may be placed. In other words, a Fill object creates highly stretchy Graphic that is typically used for setting the spacing between less stretchy objects. <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
width = 5in, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "green", <br />
{bold Green} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "blue", <br />
{bold Blue} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "red", <br />
{bold Red} <br />
} <br />
}</code></div></div> <br />
Each Fill object in a container represents one unit of fill space. That is, if object A and object B are separated by one Fill, and object B and object C are separated by two Fills, then the space between B and C is twice as large as the space between A and B. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
width = 5in, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "green", <br />
{bold Green {br} (Object A)} <br />
}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "blue", <br />
{bold Blue {br} (Object B)} <br />
}, <br />
{Fill}, <br />
{Fill}, <br />
{Frame <br />
width = 1in, <br />
height = 1in, <br />
background = "red", <br />
{bold Red {br} (Object C)} <br />
} <br />
}</code></div></div> <br />
For more information regarding Fills, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Graphical Shapes> Rule and Fill > Fill</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=24" target="_blank" title="">Stretching Graphical Objects1.JPG</a> (Size: 21.5 KB / Downloads: 1790)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=25" target="_blank" title="">Stretching Graphical Objects2.JPG</a> (Size: 7.18 KB / Downloads: 1736)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[User Interface Basics6:Object Layout]]></title>
			<link>https://communities.curl.com/showthread.php?tid=14</link>
			<pubDate>Wed, 15 Jun 2011 07:08:46 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=14</guid>
			<description><![CDATA[Because the Curl language relies on nested graphical containers to place objects, it is helpful to understand the relationship between objects and their containers as well as the relationship between sibling objects within the same container. <br />
<br />
<br />
Graphical objects can be sized, aligned, and formatted according to their object property types. Each type of graphical container will have specific defaults used for alignment. <br />
<br />
<br />
You may think of aligning graphical objects from two perspectives: <br />
<br />
<br />
•Alignment is specified by the parent container. All child objects are aligned in the same manner. <br />
<br />
•Alignment is individually specified by each child object. This allows each child object to individually specify its alignment. In this case, the parent container can override the child specifications. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Alignment Defaults</span> <br />
Before we get into alignment details, let's back up and discuss the default behavior. Each graphical container will align its children using its own particular default behavior. The default alignment behaviors of HBox and VBox, two of the most common containers, are as follows: <br />
<img src="attachment.php?aid=23" /> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow" <br />
}, <br />
{image source = {url "image.jpg"}} <br />
<br />
}</code></div></div> <br />
<span style="font-weight: bold;" class="mycode_b">Specifying Alignment on Child Objects</span> <br />
Many containers, such as HBox, use the outside origins of child objects to align the child objects relative to one another. The outside origin is a certain defined point on each graphical object that is available for use by its graphical parent for aligning graphics within the parent. <br />
<br />
<br />
You can change an object's outside origin location by setting its vorigin or horigin option to one of the following string values: <br />
<br />
<br />
•Possible values for vorigin are: "top", "center", "bottom" <br />
<br />
•Possible values for horigin are: "left", "center", "right" <br />
<br />
<br />
You can also specify an object's origin using a numerical value between 0 and 1. The following example shows several possible locations of an object's origin, at the corners and midpoints of the object's bounding box. <br />
<br />
<br />
Move your pointer over the shaded area for numerical values you could use to specify outside origin locations. (You may need to click on the shaded area first, to activate this behavior.) <br />
Tip: Notice that the numerical origin values in the top-left corner are 0,0 and the bottom-right corner are 1,1. <br />
<br />
<br />
<br />
In the next example, we set the vertical origin to a value of "center" for each child object. Note that vorigin = 0.5 is equivalent to vorigin = "center". <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon", <br />
vorigin = "center" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green", <br />
vorigin = "center" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue", <br />
vorigin = "center" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
vorigin = "center", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me", <br />
vorigin = "center" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow", <br />
vorigin = "center" <br />
}, <br />
{image source = {url "image.jpg"}, <br />
vorigin = "center" <br />
} <br />
}</code></div></div> <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Aligning Objects Specified by the Parent</span> <br />
Instead of specifying the alignment using each child object, we can often change the parent container's alignment behavior. Many containers have valign or halign options that change their alignment behavior. If these options are set to values other than "origin", they will also override any outside origins specified by a child object. <br />
<br />
<br />
•Possible values for valign are: "top", "center", "bottom", "origin" (default) <br />
<br />
•Possible values for halign are: "left", "center", right", "origin" (default) <br />
<br />
<br />
In the next example, we add valign = "center" to the parent container. This aligns all children at the center of the HBox. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
valign = "center", <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow" <br />
}, <br />
{image source = {url "image.jpg"}} <br />
<br />
}</code></div></div> <br />
In conclusion, you may think of aligning graphical objects from two perspectives. <br />
<br />
<br />
•By placing the responsibility on the children. Each parent container has its own way of displaying its children, often using the children's outside origins. You can change the children's outside origins to accommodate the parent's display algorithm. <br />
<br />
•By placing the responsibility on the parent. Most container objects use the halign and/or valign options to provide an additional way to control alignment. <br />
<br />
<br />
<br />
For more information regarding object alignment, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Elastics and Page Layout > Aligning Graphical Objects</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=23" target="_blank" title="">Object Layout1.JPG</a> (Size: 41.72 KB / Downloads: 1640)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[Because the Curl language relies on nested graphical containers to place objects, it is helpful to understand the relationship between objects and their containers as well as the relationship between sibling objects within the same container. <br />
<br />
<br />
Graphical objects can be sized, aligned, and formatted according to their object property types. Each type of graphical container will have specific defaults used for alignment. <br />
<br />
<br />
You may think of aligning graphical objects from two perspectives: <br />
<br />
<br />
•Alignment is specified by the parent container. All child objects are aligned in the same manner. <br />
<br />
•Alignment is individually specified by each child object. This allows each child object to individually specify its alignment. In this case, the parent container can override the child specifications. <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Alignment Defaults</span> <br />
Before we get into alignment details, let's back up and discuss the default behavior. Each graphical container will align its children using its own particular default behavior. The default alignment behaviors of HBox and VBox, two of the most common containers, are as follows: <br />
<img src="attachment.php?aid=23" /> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow" <br />
}, <br />
{image source = {url "image.jpg"}} <br />
<br />
}</code></div></div> <br />
<span style="font-weight: bold;" class="mycode_b">Specifying Alignment on Child Objects</span> <br />
Many containers, such as HBox, use the outside origins of child objects to align the child objects relative to one another. The outside origin is a certain defined point on each graphical object that is available for use by its graphical parent for aligning graphics within the parent. <br />
<br />
<br />
You can change an object's outside origin location by setting its vorigin or horigin option to one of the following string values: <br />
<br />
<br />
•Possible values for vorigin are: "top", "center", "bottom" <br />
<br />
•Possible values for horigin are: "left", "center", "right" <br />
<br />
<br />
You can also specify an object's origin using a numerical value between 0 and 1. The following example shows several possible locations of an object's origin, at the corners and midpoints of the object's bounding box. <br />
<br />
<br />
Move your pointer over the shaded area for numerical values you could use to specify outside origin locations. (You may need to click on the shaded area first, to activate this behavior.) <br />
Tip: Notice that the numerical origin values in the top-left corner are 0,0 and the bottom-right corner are 1,1. <br />
<br />
<br />
<br />
In the next example, we set the vertical origin to a value of "center" for each child object. Note that vorigin = 0.5 is equivalent to vorigin = "center". <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon", <br />
vorigin = "center" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green", <br />
vorigin = "center" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue", <br />
vorigin = "center" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
vorigin = "center", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me", <br />
vorigin = "center" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow", <br />
vorigin = "center" <br />
}, <br />
{image source = {url "image.jpg"}, <br />
vorigin = "center" <br />
} <br />
}</code></div></div> <br />
<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Aligning Objects Specified by the Parent</span> <br />
Instead of specifying the alignment using each child object, we can often change the parent container's alignment behavior. Many containers have valign or halign options that change their alignment behavior. If these options are set to values other than "origin", they will also override any outside origins specified by a child object. <br />
<br />
<br />
•Possible values for valign are: "top", "center", "bottom", "origin" (default) <br />
<br />
•Possible values for halign are: "left", "center", right", "origin" (default) <br />
<br />
<br />
In the next example, we add valign = "center" to the parent container. This aligns all children at the center of the HBox. <br />
<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{curl 6.0, 7.0 applet} <br />
{curl-file-attributes character-encoding = "utf8"} <br />
<br />
{HBox <br />
valign = "center", <br />
height = 2in, <br />
spacing = 2pt, <br />
border-style="raised", <br />
border-width = 2pt, <br />
border-color = "teal", <br />
{Fill <br />
width = .5in, <br />
height = .5in, <br />
background = "maroon" <br />
}, <br />
{Frame <br />
width = .5in, <br />
height = .5in, <br />
background = "green" <br />
}, <br />
{EllipseGraphic <br />
width = .5in, <br />
height = .5in, <br />
fill-color = "blue" <br />
}, <br />
{TextFlowBox <br />
border-style="raised", <br />
border-width = 2pt, <br />
margin=3pt, <br />
border-color = "red", <br />
{text Align Me} <br />
}, <br />
<br />
{CommandButton <br />
label = "Press Me" <br />
}, <br />
<br />
{DropdownList <br />
"Red", "Yellow", "Blue", <br />
value="Yellow" <br />
}, <br />
{image source = {url "image.jpg"}} <br />
<br />
}</code></div></div> <br />
In conclusion, you may think of aligning graphical objects from two perspectives. <br />
<br />
<br />
•By placing the responsibility on the children. Each parent container has its own way of displaying its children, often using the children's outside origins. You can change the children's outside origins to accommodate the parent's display algorithm. <br />
<br />
•By placing the responsibility on the parent. Most container objects use the halign and/or valign options to provide an additional way to control alignment. <br />
<br />
<br />
<br />
For more information regarding object alignment, please refer to the following section in the Curl Documentation:<span style="color: #000080;" class="mycode_color">Curl Developer's Guide > Graphical User Interface > Elastics and Page Layout > Aligning Graphical Objects</span> <br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=23" target="_blank" title="">Object Layout1.JPG</a> (Size: 41.72 KB / Downloads: 1640)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
	</channel>
</rss>