[x3d-public] MFString quoting [was: interesting sample] JSON escaping example

Don Brutzman brutzman at nps.edu
Fri May 5 21:55:06 PDT 2017



On 4/27/2017 3:22 AM, Roy Walmsley wrote:
> Hi,
> 
> The trick when considering translating from XML encoding to JSON encoding is to think of the what is needed in the middle, i.e. what is loaded into memory, or, equivalently, what would be displayed on the screen. So, considering the examples below one at a time:
> 
> 	X3D  "quote mark  \"  is ""
> 
> I presume that the term X3D implies that we looking at an XML  encoding of a string. So, what we want to see on the screen is
> 
> 	quote mark " is "
> 
> The escaping rules for JSON are simple. An easy to understand diagram is at  http://www.json.org/.

| A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

http://www.json.org/string.gif (open source, attached as JsonStringRailroadTrackDiagram.gif)

> So translating this memory representation to the JSON encoding gives:
> 
> 	"quote mark \" is ""
> 
> Notice that the ampersand shall not be escaped in the JSON encoding. In fact, only the quotation mark " and the reverse solidus \ have to be escaped.

agreed

> The escaping of the forward solidus / is optional.

It looks like the figure requires such escaping - unless you are looking at the path through the central box?

	+==============================+
	|Any UNICODE character except |
	| " or \ or control character  |
	+==============================+

Please confirm...

Next part is very helpful:
> Now let's look at the second example.
> 
> 	JSON "empty string \\\\\"\\\\\" skips a line:",
> 
> This is already a JSON encoding. So a parser will load this and display the following string
> 
> 	empty string \\"\\" skips a line:
> 
> Clearly that is not what is desired. What you want to see is:
> 
> 	empty string "" skips a line:
> 
> So, encoded into JSON this becomes
> 
> 	"empty string \"\" skips a line:"
> 
> Similarly, encoded into the XML encoding gives
> 
> 	"empty string \"\" skips a line:"
> 
> So yes, I would conclude that you are far too zealous in adding all those backslashes.
> 
> Remember, you are not trying to write an XML encoded string as a JSON encoding. You are going via computer memory, where loading the XML encoding undoes all the escaping. You then only have to do the new escaping on the unescaped string.
> 
> Hope this helps. Happy to talk if you want. Especially as I haven't involved stylesheets in the discussion above!
> 
> All the best,
> 
> Roy

Paraphrase:  the analysis correctly diagnoses that the X3dToJson.xslt stylesheet is escaping the already-escaped XML version.  Hence too many backslashes.  Instead it should produce escaped JSON that matches the intended display string.

Re-paraphrase: the X3D (.x3d XML) To Json stylesheet should produce JSON corresponding to the expected display text that gets shown.

Collecting and confirming excerpts above:

[show]	empty string "" skips a line:

[.x3d]	"empty string \"\" skips a line:"

[JSON]	"empty string \"\" skips a line:"

Gulp: .x3d and JSON MF/SFString values are identical.  Wow pretty ironic.  Apparently working too hard, much escapism for no reason??!!  :0

Hmm hmmm.. I think that appears correct for MF/SFString values.  Please review!

Meanwhile, though, XML .x3d comments can have unescaped quotation marks, so those still must be escaped in JSON.  So X3D and JSON comment escaping is not identical.

Modified scene and conversion attached, excerpts follow.

================================================================

[show]	☺ = smiley face emoticon, and "" means skip a line

[.x3d]	<!-- ☺ = smiley face emoticon, and "" means skip a line -->

[JSON]

{ "Shape":
   {
	"-children":[
	  {
		"#comment":"☺ = smiley face emoticon, and \"\" means skip a line"
	  }
	],

================================================================

[show]	Have a " quote character
[show]	with X3D!
[show]	
[show]	:)   ☺

[.x3d]	<Text solid='false' string='"Have a \" quote character" "with X3D!" "" ":)   ☺"'>

[JSON]	"-geometry":
	  { "Text":
		{
		  "@string":["Have a \" quote character","with X3D!","",":) ☺"],

================================================================

meanwhile, on the other other other hand, .java escapes both \ and " characters as \\ and \" within a quoted String, and the comment/MFString example above looks like

[Java]
.addChild(new ShapeObject()
   .addComments(" ☺ = smiley face emoticon, and \"\" means skip a line ")
   .setGeometry(new TextObject().setString(new MFStringObject("\"Have a \\\" quote character\" \"with X3D!\" \"\" \":)   ☺\""))

which compiles and (based on other examples) converts OK, apparently.  thank goodness.

================================================================

are we having fun yet?!!

am hoping we have finally cornered this one.  added another path to X3dToJson.xslt for MF/SFString, seems to work.  will run a full set of json conversions tonight and we will see what else pops up.

q. "what do you like most about computer science?"
a. "you only have to get something right once, and it stays that way."


> -----Original Message-----
> From: x3d-public [mailto:x3d-public-bounces at web3d.org] On Behalf Of Don Brutzman
> Sent: 27 April 2017 03:30
> To: John Carlson <yottzumm at gmail.com>
> Cc: x3d-public at web3d.org
> Subject: Re: [x3d-public] MFString quoting [was: interesting sample] JSON escaping example
> 
> On 4/26/2017 4:02 PM, yottzumm at gmail.com wrote:
>> I do have a problem with the JSON encoding for the attached file (translated by X3dToJson.xslt).  Let me know if you think otherwise.  Look at all the \\\\\.
> 
> i suspect the issue is illustrated by the following SFString within an MFString
> 
> 	X3D  "quote mark  \"  is &quot;"
> 	JSON "empty string \\\\\"\\\\\" skips a line:",
> 
> will try to break it down.
> 
> double-backslash escaping going on here for JSON; so internal content-only correspondences should likely be
> 
> 	[X3D ]	\
> 	[JSON]	\\
> 
> 	[X3D ]	"
> 	[JSON]	\"
> 
> 	[X3D ]	\"
> 	[JSON]	\\\"
> 
> 	[X3D ]	quote mark  \"  is &quot;
> 	[JSON]	quote mark \\\" is "
> 
> please count.  does that look right?
> 
> if so, then it looks like the X3dToJson.xslt is overzealously prepending 2 extra backslashes in this particular case (one of several).
> 
> if not, then please advise what the right answer is.
> 
> also please re-advise, where are the JSON backslash-related rules?
> 
> if we can agree on what the right answer looks like, then i will dive back into the independently XML/XSLT/XPath escaped (and obtw recursive) stylesheet template that consumes/produces this stuff to try doing the job correctly.  (gulp!)
> 
> p.s. if anyone out there isn't dizzy yet, congrats!
> 
> 
>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>>
>> *From: *Andreas Plesch <mailto:andreasplesch at gmail.com>
>> *Sent: *Wednesday, April 26, 2017 5:21 PM
>> *To: *John Carlson <mailto:yottzumm at gmail.com>
>> *Cc: *Don Brutzman <mailto:brutzman at nps.edu>; X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
>> *Subject: *Re: [x3d-public] MFString quoting [was: interesting sample]
>>
>> On Wed, Apr 26, 2017 at 3:55 PM, <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>>
>>      It’s
>>
>>      http://x3dgraphics.com/slidesets/X3dForWebAuthors/Chapter02GeometryPrimitives.pdf
>>
>>      Got caught in the grand renaming.  Also the parent page is wrong.
>>
>> Thanks.
all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JsonStringRailroadTrackDiagram.gif
Type: image/gif
Size: 17041 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170505/94cfed6d/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TextHaveFunWithX3D.x3d
Type: model/x3d+xml
Size: 2559 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170505/94cfed6d/attachment-0001.x3d>
-------------- next part --------------
{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"TextHaveFunWithX3D.x3d"
          },
          {
            "@name":"description",
            "@content":"Simple smiley-face example illustrating an emoticon character entity, used in an MFString Text."
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"26 April 2017"
          },
          {
            "@name":"modified",
            "@content":"26 April 2017"
          },
          {
            "@name":"Image",
            "@content":"TextHaveFunWithX3D.png"
          },
          {
            "@name":"reference",
            "@content":"http://unicode.org/emoji/charts/full-emoji-list.html"
          },
          {
            "@name":"reference",
            "@content":"https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)"
          },
          {
            "@name":"reference",
            "@content":"https://en.wikipedia.org/wiki/Universal_Character_Set_characters"
          },
          {
            "@name":"reference",
            "@content":"https://www.w3.org/TR/html4/sgml/entities.html"
          },
          {
            "@name":"reference",
            "@content":"https://dev.w3.org/html5/html-author/charref"
          },
          {
            "@name":"reference",
            "@content":"https://www.w3.org/wiki/Common_HTML_entities_used_for_typography"
          },
          {
            "@name":"reference",
            "@content":"http://X3dGraphics.com"
          },
          {
            "@name":"reference",
            "@content":"http://www.web3d.org/x3d/content/examples/X3dResources.html"
          },
          {
            "@name":"rights",
            "@content":"Copyright Don Brutzman and Leonard Daly 2007"
          },
          {
            "@name":"subject",
            "@content":"emoji emoticon, X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com"
          },
          {
            "@name":"identifier",
            "@content":"http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter02GeometryPrimitives/TextHaveFunWithX3D.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"05 May 2017"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"reference",
            "@content":"X3D JSON encoding: http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "Background":
            {
              "@skyColor":[0.819608,0.984314,1]
            }
          },
          { "Shape":
            {
              "-children":[
                {
                  "#comment":"☺ = smiley face emoticon, and \"\" means skip a line"
                }
              ],
              "-geometry":
                { "Text":
                  {
                    "@string":["Have a \" quote character","with X3D!","",":) ☺"],
                    "-fontStyle":
                      { "FontStyle":
                        {
                          "@family":["SANS"],
                          "@justify":["MIDDLE","MIDDLE"],
                          "@style":"BOLD"
                        }
                      }
                  }
                },
              "-appearance":
                { "Appearance":
                  {
                    "-material":
                      { "Material":
                        {
                          "@ambientIntensity":0.25,
                          "@diffuseColor":[0,0.251004,0.239248],
                          "@shininess":0.06,
                          "@specularColor":[0.177935,0.249369,0.229278],
                          "-children":[
                            {
                              "#comment":"Universal Media Library: ArtDeco 19"
                            }
                          ]
                        }
                      }
                  }
                }
            }
          }
        ]
    }
  }
}
-------------- next part --------------
package X3dForWebAuthors.Chapter02GeometryPrimitives;

/*
Copyright (c) 1995-2017 held by the author(s).  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer
      in the documentation and/or other materials provided with the
      distribution.
    * Neither the name of the Web3D Consortium (http://www.web3D.org)
      nor the names of its contributors may be used to endorse or
      promote products derived from this software without specific
      prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

import java.util.*;
import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Text.*;

// Javadoc annotations follow, see below for source.
/**
 * <p> Simple smiley-face example illustrating an emoticon character entity, used in an MFString Text. </p>
 <p> Related links: <a href="../../../Chapter02GeometryPrimitives/TextHaveFunWithX3D.java">TextHaveFunWithX3D.java</a> source, <a href="../../../Chapter02GeometryPrimitives/TextHaveFunWithX3DIndex.html" target="_top">TextHaveFunWithX3D catalog page</a>, <a href="http://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a> and <a href="http://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;" summary="Scene Metadata">
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">  Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../Chapter02GeometryPrimitives/TextHaveFunWithX3D.x3d">TextHaveFunWithX3D.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> Simple smiley-face example illustrating an emoticon character entity, used in an MFString Text. </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Don Brutzman </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 26 April 2017 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 26 April 2017 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> Image </i> </td>
			<td> <a href="../../../Chapter02GeometryPrimitives/TextHaveFunWithX3D.png">TextHaveFunWithX3D.png</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="http://unicode.org/emoji/charts/full-emoji-list.html" target="_blank">http://unicode.org/emoji/charts/full-emoji-list.html</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)" target="_blank">https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://en.wikipedia.org/wiki/Universal_Character_Set_characters" target="_blank">https://en.wikipedia.org/wiki/Universal_Character_Set_characters</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://www.w3.org/TR/html4/sgml/entities.html" target="_blank">https://www.w3.org/TR/html4/sgml/entities.html</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://dev.w3.org/html5/html-author/charref" target="_blank">https://dev.w3.org/html5/html-author/charref</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="https://www.w3.org/wiki/Common_HTML_entities_used_for_typography" target="_blank">https://www.w3.org/wiki/Common_HTML_entities_used_for_typography</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="http://X3dGraphics.com" target="_blank">http://X3dGraphics.com</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> reference </i> </td>
			<td> <a href="http://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">http://www.web3d.org/x3d/content/examples/X3dResources.html</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> rights </i> </td>
			<td> Copyright Don Brutzman and Leonard Daly 2007 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> subject </i> </td>
			<td> emoji emoticon, X3D book, X3D graphics, X3D-Edit, <a href="http://www.x3dGraphics.com" target="_blank">http://www.x3dGraphics.com</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter02GeometryPrimitives/TextHaveFunWithX3D.x3d" target="_blank">http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter02GeometryPrimitives/TextHaveFunWithX3D.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 3.3, <a href="https://savage.nps.edu/X3D-Edit" target="_blank">https://savage.nps.edu/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../Chapter02GeometryPrimitives/../license.html">../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">    </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="http://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="http://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet to create Java source code from an <code>.x3d</code> scene.
	</p>

	* @author Don Brutzman
 */

public class TextHaveFunWithX3D
{
  /** Default constructor to create this object. */
  public TextHaveFunWithX3D ()
  {
    initialize();
  }
	
  /** Create and initialize the X3D model. */
  public final void initialize()
  {
  x3dModel = new X3DObject().setProfile("Immersive").setVersion("3.3")
  .setHead(new headObject()
    .addMeta(new metaObject().setName("title").setContent("TextHaveFunWithX3D.x3d"))
    .addMeta(new metaObject().setName("description").setContent("Simple smiley-face example illustrating an emoticon character entity, used in an MFString Text."))
    .addMeta(new metaObject().setName("creator").setContent("Don Brutzman"))
    .addMeta(new metaObject().setName("created").setContent("26 April 2017"))
    .addMeta(new metaObject().setName("modified").setContent("26 April 2017"))
    .addMeta(new metaObject().setName("Image").setContent("TextHaveFunWithX3D.png"))
    .addMeta(new metaObject().setName("reference").setContent("http://unicode.org/emoji/charts/full-emoji-list.html"))
    .addMeta(new metaObject().setName("reference").setContent("https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)"))
    .addMeta(new metaObject().setName("reference").setContent("https://en.wikipedia.org/wiki/Universal_Character_Set_characters"))
    .addMeta(new metaObject().setName("reference").setContent("https://www.w3.org/TR/html4/sgml/entities.html"))
    .addMeta(new metaObject().setName("reference").setContent("https://dev.w3.org/html5/html-author/charref"))
    .addMeta(new metaObject().setName("reference").setContent("https://www.w3.org/wiki/Common_HTML_entities_used_for_typography"))
    .addMeta(new metaObject().setName("reference").setContent("http://X3dGraphics.com"))
    .addMeta(new metaObject().setName("reference").setContent("http://www.web3d.org/x3d/content/examples/X3dResources.html"))
    .addMeta(new metaObject().setName("rights").setContent("Copyright Don Brutzman and Leonard Daly 2007"))
    .addMeta(new metaObject().setName("subject").setContent("emoji emoticon, X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com"))
    .addMeta(new metaObject().setName("identifier").setContent("http://X3dGraphics.com/examples/X3dForWebAuthors/Chapter02GeometryPrimitives/TextHaveFunWithX3D.x3d"))
    .addMeta(new metaObject().setName("generator").setContent("X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"))
    .addMeta(new metaObject().setName("license").setContent("../license.html")))
  .setScene(new SceneObject()
    .addChild(new BackgroundObject().setSkyColor(new MFColorObject(new float[] {0.819608f,0.984314f,1.0f})))
    .addChild(new ShapeObject()
      .addComments(" ☺ = smiley face emoticon, and \"\" means skip a line ")
      .setGeometry(new TextObject().setString(new MFStringObject("\"Have a \\\" quote character\" \"with X3D!\" \"\" \":)   ☺\""))
        .setFontStyle(new FontStyleObject().setJustify(new MFStringObject("\"MIDDLE\" \"MIDDLE\"")).setFamily(new MFStringObject("\"SANS\"")).setStyle("BOLD")))
      .setAppearance(new AppearanceObject()
        .setMaterial(new MaterialObject().setDiffuseColor(0.0f,0.251004f,0.239248f).setShininess(0.06f).setSpecularColor(0.177935f,0.249369f,0.229278f).setAmbientIntensity(0.25f)
          .addComments(" Universal Media Library: ArtDeco 19 ")))));
  }
  // end of initialize() method

  /** The initialized model object, created within initialize() method. */
  private X3DObject x3dModel;
  
  /** Provide a shallow copy of the X3D model.
   * @return TextHaveFunWithX3D model
   */
  public X3DObject getX3dModel()
  {	  
	  return x3dModel;
  }
  
  /** Indicate X3DJSAIL validation results for this X3D model.
   * @return validation results plus exception information, if any
   */
  public String validateSelf()
  {
	String       metaResult = new String();
	String validationResult = new String();
	String  exceptionResult = new String();
	try
	{
		initialize();
		
		if ((getX3dModel() == null) || (getX3dModel().getHead() == null))
		{
			validationResult = "empty scene, nothing to validate. " + x3dModel.validate();
			return validationResult;
		}
		// first list informational meta elements of interest
		for (metaObject meta : getX3dModel().getHead().getMetaList())
		{
			if (meta.getName().equals(metaObject.NAME_ERROR) ||
				meta.getName().equals(metaObject.NAME_WARNING) ||
				meta.getName().equals(metaObject.NAME_HINT) ||
				meta.getName().equals(metaObject.NAME_INFO) ||
				meta.getName().equals(metaObject.NAME_TODO))
			{
				metaResult += meta.toStringX3D();
			}
		}
		validationResult += x3dModel.validate(); // walk entire tree to validate correctness
	}
	catch (Exception e)
	{
		exceptionResult = e.getMessage(); // report exception failures, if any
	}
	if  (metaResult.isEmpty() && exceptionResult.isEmpty() && validationResult.isEmpty())
	     return "success";
	else
	{
		String returnMessage = metaResult;
		if  (!exceptionResult.isEmpty() && !validationResult.isEmpty())
			returnMessage += "\n*** ";
		returnMessage += exceptionResult;
		if  (exceptionResult.isEmpty() && !validationResult.isEmpty())
			returnMessage = "\n" + returnMessage; // skip line before meta tags, etc.
		returnMessage += validationResult;
		return returnMessage;
	}
  }
    /** Default main() method provided for test purposes.
     * @param argv input parameters
     */
    public static void main(String argv[])
    {
		TextHaveFunWithX3D testObject = new TextHaveFunWithX3D();
		System.out.println ("TextHaveFunWithX3D execution self-validation test results: " + testObject.validateSelf());
	}
}


More information about the x3d-public mailing list