If I was using Sling in an order management system, I would still model
it as a tree of nodes. Nodes aren't expensive to create (although 50
nodes for an order seems high). If you're going to use JCR, you should
get used to creating nodes :)

When you need to create the XML documents for ingestion by other
systems, that's where Sling scripts can come into play.

To be clear, you can do what you are doing and store XML in String
properties. As I said below, it is probably more "correct" to store XML
documents in nt:file nodes. And if you were storing XHTML or DocBook
files, it would make sense to store the document as-is. But once you
start needing to parse the XML blob in your scripts, that looks like a
problem to me. But you definitely can do it.

Justin

On 5/24/10 5:00 PM, Tony Giaccone wrote:
> Justin, 
> 
> I appreciate your help, really I do, and please understand that I'm new to 
> this whole deal and trying to understand the underlying details. 
> 
> So maybe a little more information would make things clearer.  The XML that 
> I'm creating is also going to be used to drive an external process. 
> 
> I can't give the explain the exact process, because of other issues, but you 
> could imagine this as being analogous to an order and fulfillment system. 
> 
> What I'm capturing in my node, is the state of the "document" as it was 
> created and passed off to another external service.  So in that sense 
> I am in fact creating an XML document, not just an XML representation of a 
> document for the repository.  This XML document is a record of something 
> that happened, a snapshot you might say of a particular point in time. 
> 
> The xml is kind of like an order. We generate this XML document to drive a 
> fulfillment/shipping system.  That system is going to go out and act on that 
> document. Create it's own copy of the data, drive a whole complex system that 
> eventually produces an order from that XML.
> 
> At some point in the future, before the order gets shipped, someone's going 
> to look at the document in the repository. At that point I'm going to take 
> that XML 
> document and render an Order summary  so that we can be sure that the order 
> has been fulfilled and is about to be shipped matches what was requested. 
> 
> Now maybe it makes sense to put the document in the repository as a sequence 
> of resource types, maybe there are reasons it would make more sense to do 
> that.
> 
> 
> I have this sense that a node is an expensive thing to create, and so the 
> idea of taking what is probably 40 or 50 elements and turning them into 40 or 
> 50 nodes seems excessive to me. 
> However, I'm quite aware that my mental model is probably flawed.  When doing 
> development you want to play to the strengths of the system you are using. 
> 
> 
> Tony
> 
> 
> On May 24, 2010, at 3:11 PM, Justin Edelson wrote:
> 
>> On 5/24/10 2:48 PM, Tony Giaccone wrote:
>>> So what would you suggest as the alternative? 
>> Like I said, I would suggest putting your content in the repository
>> using JCR nodes and properties.
>>
>>>
>>> How should I place my xml into the repository?
>>>
>>> I can understand why you wouldn't want to write the code to do this, but 
>>> can you give me a general idea? 
>> If you're going to place XML in the repository, you can either do what
>> you are doing or using a nt:file node. I think both are wrong based on
>> your description. In the general case, however, if you have a "file" you
>> should use nt:file (see
>> http://wiki.apache.org/jackrabbit/DavidsModel#Rule_.236:_Files_are_Files_are_Files.).
>> I just don't think you have a file - you have structured data and
>> structured data should be saved as nodes and properties. Perhaps I'm
>> misunderstanding your situation, but when you talk about "creating an
>> XML representation" that raises big red flags for me.
>>
>> As for parsing an XML document in a JSP, you can obviously do it with
>> inline Java and JAXP. If you were using an ESP, you could probably use
>> the E4X API, but I've not tested that personally.
>>
>>>
>>> If I have a XML Document how do I put that into the repository in the 
>>> "correct" manner? 
>> It doesn't sound to me like you do have an XML document. You have a
>> "document" which you generate an XML representation of. I'm suggesting
>> that you think a mapping between the "document" and JCR nodes instead of
>> creating that XML representation.
>>
>> For example, let's say your "document" is a memo which has a from
>> address, a to address, a date, and a body. Each address is actually
>> composed of a first name and last name. For this, I would create a
>> single JCR node with properties "date" and "body" and child nodes named
>> "from" and "to" each of which having properties named "firstName" and
>> "lastName".
>>
>> You could do this in a single form post:
>>
>>          NameValuePair[] formData = {
>>                  new NameValuePair("from/firstName", "Justin"),
>>                  new NameValuePair("from/lastName", "Edelson"),
>>                    new NameValuePair("from/sling:resourceType",
>> "myco/address"),
>>                  new NameValuePair("to/firstName", "Tony"),
>>                  new NameValuePair("to/lastName", "Giaccone"),
>>                    new NameValuePair("to/sling:resourceType",
>> "myco/address"),
>>                    new NameValuePair("date", "<some date>"),
>>                    new NameValuePair("d...@typehint", "Date"),
>>                    new NameValuePair("body","<some body>"),
>>                    new NameValuePair("sling:resourceType", "myco/memo")
>>                 };
>>
>> By default, Sling will create an XML representation of this node using
>> system or document view. You can provide your own script to customize
>> the XML generated.
>>
>> Justin
>>
>>>
>>> Tony
>>>
>>>
>>>
>>> On May 24, 2010, at 1:08 PM, Justin Edelson wrote:
>>>
>>>> It just doesn't make sense to me to take an object (a "document"),
>>>> create an XML representation of that object, and then store the
>>>> representation in the repository as a single node (or node property).
>>>>
>>>> If you have:
>>>>>   <document>
>>>>>           <name>
>>>>>                   <firstName>Bob</firstName>
>>>>>                   <lastName>Smith</lastname>
>>>>>           </name>
>>>>>   </document>
>>>>
>>>> and currently you're storing the document as /documents/doc1, then
>>>>
>>>> /documents/doc1/n...@firstname = Bob
>>>> /documents/doc1/n...@lastname = Smith
>>>>
>>>> i.e. doc1 has a child node called name which has attributes named
>>>> firstName and lastName.
>>>>
>>>> If you store XML in the repository and then want to access the values
>>>> inside that document in a script, you'll need to parse the document into
>>>> a DOM of some sort.
>>>>
>>>> Justin
>>>>
>>>>
>>>>
>>>>
>>>> On 5/24/10 12:51 PM, Tony Giaccone wrote:
>>>>>
>>>>>
>>>>> Maybe it makes better sense to talk about the general form of the 
>>>>> application and a bit of the code. 
>>>>>
>>>>>
>>>>> Here's the java code that posts a document into the repository.  It takes 
>>>>> the document and creates an XML representation of that document. 
>>>>>
>>>>> Extracts some metadata (these are in general things we will search on). 
>>>>>
>>>>> And then inserts the metadata and the xml using a PUT into the 
>>>>> repository. 
>>>>>
>>>>>           String documentXML = data.toXML();
>>>>>           String repoBin =  
>>>>> repoManager.documentToPath(data,data.SLING_RESOURCE_TYPE);
>>>>>           String postMethodURL = 
>>>>> repoURLPut+repoBin+"/"+data.getDocumentId();
>>>>>           log.debug("url ->" + postMethodURL);
>>>>>       PostMethod post = new PostMethod(postMethodURL);
>>>>>       NameValuePair[] formData = { 
>>>>>               new NameValuePair(RESOURCE_ID, 
>>>>> Warrant.SLING_RESOURCE_TYPE), 
>>>>>               new NameValuePair(DOC_TITLE, data.getWarrantId()),
>>>>>               new NameValuePair(DOCUMENT_ID, data.getCaseId()),
>>>>>               new NameValuePair(DOCUMENT_XML, warrantXML)
>>>>>              };
>>>>>       
>>>>>       post.setRequestBody(formData); 
>>>>>           String response = null;
>>>>>           int status;
>>>>>           try {
>>>>>                   status = client.executeMethod( post );
>>>>>
>>>>>
>>>>> I didn't include all the code for handling the response as I don't think 
>>>>> it's relevant here. 
>>>>>
>>>>>
>>>>> Question #1. Does that seem like a reasonable way to put an XML document 
>>>>> that is probably only going to be a 20 or 30 thousand bytes (maybe 
>>>>> smaller) into the repository?
>>>>>
>>>>> If not, how would you insert it?
>>>>>
>>>>>
>>>>> Question #2  Now I've got data in my repository? How do I reference the 
>>>>> values in that XML in a JSP. Suppose for simplicity sake my document was:
>>>>>   <document> 
>>>>>           <name>
>>>>>                   <firstName>Bob</firstName>
>>>>>                   <lastName>Smith</lastname>
>>>>>           </name>
>>>>>   </document> 
>>>>>
>>>>> How would I go about putting that name on to a JSP?  
>>>>>
>>>>>
>>>>> What if it was:
>>>>>
>>>>>
>>>>>   <document>
>>>>>           <names> 
>>>>>                   <name>
>>>>>                           <firstName>Bob</firstName>
>>>>>                           <lastName>Smith</lastname>
>>>>>                   </name>
>>>>>                   <name>
>>>>>                           <firstName>Bill</firstName>
>>>>>                           <lastName>Jones</lastname>
>>>>>                   </name> 
>>>>>           </names>
>>>>>   </document> 
>>>>>
>>>>>
>>>>> Looking for some basic answers. 
>>>>>
>>>>>
>>>>> Tony Giaccone
>>>>>
>>>>
>>>
>>
> 

Reply via email to