xml-xang-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdier...@locus.apache.org
Subject cvs commit: xml-xang/java/samples/hello/layouts editor.xsl editor_browse.xsl editor_edit.xsl xap.xsl
Date Fri, 24 Mar 2000 22:25:45 GMT
mdierken    00/03/24 14:25:45

  Added:       java/samples/hello editor.script.xml hello.xap
                        system.script.xml
               java/samples/hello/layouts editor.xsl editor_browse.xsl
                        editor_edit.xsl xap.xsl
  Log:
  Initial 'hello world' sample.
  
  Revision  Changes    Path
  1.1                  xml-xang/java/samples/hello/editor.script.xml
  
  Index: editor.script.xml
  ===================================================================
  <script >
  
  <![CDATA[
  
  /** Base browser method. Override to provide object specific functionality.
  */
  function doObjectEdit(context,returnTypes,parameters)
  {
  	parameters.put("layout","editor.xsl");
  	get(context,returnTypes,parameters);
  }
  
  function doObjectBrowser(context,returnTypes,parameters)
  {
  	parameters.put("layout","editor_browse.xsl");
  	get(context,returnTypes,parameters);
  }
  
  /** Base editor method. Override to provide object specific functionality.
  */
  function doObjectEditor(context,returnTypes,parameters)
  {
  	parameters.put("layout","editor_edit.xsl");
  	get(context,returnTypes,parameters);
  }
  
  /** Base update method
  */
  function doObjectUpdate(context,returnTypes,parameters)
  {
  	doc = context.getResponse().getWriter();
  	for (prop in parameters.keys())
  	{
  		if (prop.indexOf('prop_') == 0)
  		{
  			value = parameters.get(prop);
  			attrib = prop.substring(5);
  			if (value == null || value=="")
  			{
  				xml.removeAttribute(attrib);
  			}
  			else
  			{
  				xml.setAttribute(attrib,value);
  			}
  			
  		}
  	}
  
  	context.getResponse().setContentType("text/html");
  	doc.println("<html><body>OK</body></html>");
  }
  
  function doObjectAddProp(context,returnTypes,parameters)
  {
  	name = parameters.get('name');
  	value = parameters.get('value');
  	xml.setAttribute(name,value);
  	
  	context.getResponse().setContentType("text/html");
  	doc = context.getResponse().getWriter();
  	doc.println("<html><body>"+name+"="+value+"</body></html>");
  }
  
  ]]>
  </script>
  
  
  1.1                  xml-xang/java/samples/hello/hello.xap
  
  Index: hello.xap
  ===================================================================
  
  <xap hits='0' onGet="get();" onGetXml="getXML()" onGetScript="getScript();"
  	onGetEditor='doObjectEdit()' onGetBrowse='doObjectBrowser()' onGetEdit='doObjectEditor()'

  	onPostUpdate='doObjectUpdate()' onPostAddprop='doObjectAddProp()'
  	layout='xap.xsl'
  	resources.server='http://localhost/xap/apps/apache/layouts/'>
  
  	<title>Apache Xang</title>
  	<message>Welcome to the Next Web Revolution!<br /></message>
  	
  	<!-- include some common code -->
  	<script xml:link='include' src='system.script.xml' > 	</script>
  	<script xml:link='include' src='editor.script.xml' > 	</script>
  
  <page name='base64' >
  		<title>Do Base64 stuff</title>
  		
  		<script>
  		<![CDATA[
  		var bDecoding=false;
  		function doBase64Form(context,returnTypes,parameters)
  		{
  			doc = context.getResponse().getWriter();
  			context.getResponse().setContentType('text/html');
  			doc.println("<html><body>");
  			doc.println("<font size='+2'>Base64 Encoder/Decoder</font><hr />");
  			
  			drawEncodeForm(doc,context,bDecoding);
  			doc.println("</body></html>");
  		}
  
  		function drawEncodeForm(doc,context,bDecoding)
  		{
  			doc.println("<form method='POST' action='.'>");
  			if (bDecoding)
  				doc.println("<input type='hidden' name='do:method' value='decode' />");
  			else
  				doc.println("<input type='hidden' name='do:method' value='encode' />");
  			doc.println("Text: <input type='text' name='text' value='' />");
  			if (bDecoding)
  				doc.println("<input type='submit' value=' Decode '/>");
  			else
  				doc.println("<input type='submit' value=' Encode '/>");
  		}
  
  		/** Decode base64 text
  		*/
  		function base64Decode(text)
  		{
  			decoder = new Packages.org.apache.xang.util.encoding.BASE64Decoder();
  			text = new Packages.java.lang.String(decoder.decodeBuffer(parameters.get("text")));
  			return text;
  		}				
  		/** Encode base64 text
  		*/
  		function base64Encode(text)
  		{
  			encoder = new Packages.org.apache.xang.util.encoding.BASE64Encoder();
  			
  			text = new Packages.java.lang.String(text);
  			text = encoder.encodeBuffer(text.getBytes());
  			return text;
  		}
  		
  		function doDecode()
  		{
  			doc = context.getResponse().getWriter();
  			
  			text = base64Decode(parameters.get("text"));
  
  			context.getResponse().setContentType('text/html');
  
  			doc.println("<html><body>");
  			doc.println("<font size='+2'>Base64 Decoder</font><hr />");
  			doc.println("<b>base64:</b> "+parameters.get('text'));
  			doc.println("<br />");
  			doc.println("<b>plain:</b> "+text);
  			doc.println("<hr />");
  			drawEncodeForm(doc,context,true);
  			
  			doc.println("</body></html>");
  		}
  		function doEncode()
  		{
  			doc = context.getResponse().getWriter();
  
  			text = base64Encode(parameters.get("text"));
  			context.getResponse().setContentType('text/html');
  
  			doc.println("<html><body>");
  			doc.println("<font size='+2'>Base64 Encoder</font><hr />");
  			doc.println("<b>text:</b> "+parameters.get('text'));
  			doc.println("<br />");
  			doc.println("<b>base64:</b> "+text);
  			doc.println("<hr />");
  			drawEncodeForm(doc,context,false);
  			doc.println("</body></html>");
  		}
  		]]>
  		</script>
  		<page name='encoder' 
  					onGet='doBase64Form()' 
  					onGetEncode='doEncode()'
  					onPostEncode='doEncode()'
  					>
  			<title>Base64 Encoder</title>
  		</page>
  		<page name='decoder' 
  					onGet='bDecoding=true;doBase64Form()' 
  					onPostDecode='doDecode()' 
  					onGetDecode='doDecode()' 
  					>
  			<title>Base64 Decoder</title>
  		</page>
  </page>	
  
  
  </xap>
  
  
  
  1.1                  xml-xang/java/samples/hello/system.script.xml
  
  Index: system.script.xml
  ===================================================================
  <script >
  <![CDATA[
  function debug(s)
  {
  	Packages.java.lang.System.out.println(s);
  }
  
  function getInheritedAttribute(element,name)
  {
  	var value;
  	value=null;
  	
  	while ((element != null) && (element.getNodeType() == 1))
  	{
  		value = element.getAttribute(name);
  		if (value != null && value != "")
  			break;
  
  		element = element.getParentNode();
  	}
  	return value;
  }
  
  function getLayout(element)
  {
  	return getInheritedAttribute(element,'layout');
  }
  
  /**
  * This determines which XSL stylesheet to use and applies the stylesheet to the targeted
  * element.
  */
  function get(context,returnTypes,parameters)
  {
  	var doc;
  	var layout;
  
  	debug('in get()');
  	doc = context.getResponse().getWriter();
  
  	// check for object
  	if (xml == null)
  	{
  		context.getResponse().sendError(404,"Page not found.");
  		return;
  	}
  	
  	// get the url to the XSL to use for the transform.
  	base = getInheritedAttribute(xml,'resources.server');
  
  	layout = parameters.get('layout');
  	if (layout == null)
  	{
  		layout = getLayout(xml);
  	}
  
  	if (base != null && (layout.indexOf(':') <= 1))
  		layout = base + layout;
  
  	if (layout != null)
  	{
  		context.getResponse().setContentType("text/html");
  		// do XSL via Xalan
  		{
  			processor = Packages.org.apache.xalan.xslt.XSLTProcessorFactory.getProcessorUsingLiaisonName("org.apache.xalan.xpath.xdom.XercesLiaison");
  			
  			source = new Packages.org.apache.xalan.xslt.XSLTInputSource();
  			source.setNode(xml);
  			
  			stylesheet = new Packages.org.apache.xalan.xslt.XSLTInputSource();
  			stylesheet.setSystemId(layout);
  			
  			output = new Packages.org.apache.xalan.xslt.XSLTResultTarget();
  			output.setCharacterStream(doc);
  			
  			processor.process(source,stylesheet,output);
  		}
  		
  		doc.flush();
  	}
  }
  
  function getXML(context,returnTypes,parameters)
  {
  	doc = context.getResponse().getWriter();
  	doc.println("<?xml version='1.0' ?>");
  	doc.println("<!-- cool huh? -->");
  	doc.println(xml.getXML());
  }
  
  function getScript(context,returnTypes,parameters)
  {
  	var doc;
  	var s;
  	var util;
  
  	doc = context.getResponse().getWriter();
  
  	util = new Packages.org.apache.xang.util.TextUtil();
  	
  
  	s = "<html><body><pre>";
  	s += util.encodeToHTML(app.loadScript(null));
  	s += "</pre></body></html>";
  	doc.println(s);
  	doc.flush();
  }
  ]]>	
  </script>
  
  
  
  1.1                  xml-xang/java/samples/hello/layouts/editor.xsl
  
  Index: editor.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="*">
  <FRAMESET COLS="200,*" BORDER="TRUE">
  	<FRAME NAME="obj_browser" src="?do:method=browse"  marginwidth="1" marginheight="1"
scrolling="auto" >
  	</FRAME>
  	<FRAME NAME="obj_editor" src="?do:method=edit" FRAMESPACING="1" marginwidth="2" marginheight="2"
scrolling="auto">
  	</FRAME>
  </FRAMESET>
  
  
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-xang/java/samples/hello/layouts/editor_browse.xsl
  
  Index: editor_browse.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE riolayout [
   <!ENTITY baseResourcePath "/rio4/layouts/filemanager2/" >
   <!ENTITY baseURL "/xsp/data/default.xsp/" >
   <!ENTITY nbsp "<![CDATA[ ]]>" >
   <!ENTITY tag-start "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>"
>
   <!ENTITY tag-end "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>"
>
  ]>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  <xsl:output method="html" indent="no"/>
  
  <xsl:template match="/" >
  <HTML>	
  	<BODY bgcolor='#f0f0f0'>
  	<a href="javascript:window.location=window.location" >Refresh</a>
  	<hr />
  
  	<!-- Parent folder -->
  	<xsl:apply-templates select='..' />
  
  	&tag-start;DIV style="position:relative;top:0;left:8; display: ;"&tag-end;
  	
  	<!-- This folder -->
  	<a target='_parent'>
  		<xsl:attribute name='href'>
  			&baseURL;
  			<xsl:apply-templates mode='up' select='.' />
  			?do:method=editor
  		</xsl:attribute>
  	<img border='0' src="&baseResourcePath;images/folder.gif" /> 
  	&nbsp;
  	<b>
  	<xsl:choose>
  		<xsl:when test='@name'>
  			<xsl:value-of select='@name' />
  		</xsl:when>
  		<xsl:otherwise>
  			root
  		</xsl:otherwise>
  	</xsl:choose>
  	
  	</b>
  	</a>
  
  	<!-- The child folders -->
  	&tag-start;DIV style="position:relative;top:0;left:8; display: ;"&tag-end;
  
  	<xsl:for-each select='*[@name]' >
  		<a target='_parent'>
  			<xsl:attribute name='href'>
  				&baseURL;<xsl:apply-templates mode='up' select='.' />?do:method=editor
  			</xsl:attribute>
  		<img border='0' src="&baseResourcePath;images/folder.gif" /> 
  		&nbsp;
  		<xsl:choose>
  			<xsl:when test='@name'>
  				<xsl:value-of select='@name' />
  			</xsl:when>
  			<xsl:otherwise>
  				root
  			</xsl:otherwise>
  		</xsl:choose>
  		</a>
  		<br />
  			
  	</xsl:for-each>
  
  	</BODY>
  </HTML>
  
  </xsl:template>
  
  <xsl:template mode='up' match="*">
  </xsl:template>
  
  <xsl:template match="*">
  	<!-- Parent folder -->
  	<xsl:apply-templates select='..' />
  	
  		&tag-start;DIV style="position:relative;top:0;left:8; display: ;"&tag-end;
  	
  	<!-- This folder -->
  	<a target='_parent'>
  		<xsl:attribute name='href'>
  			&baseURL;<xsl:apply-templates mode='up' select='.' />?do:method=editor
  		</xsl:attribute>
  	<img border='0' src="&baseResourcePath;images/folder.gif" /> 
  	&nbsp;
  	<xsl:choose>
  		<xsl:when test='@name'>
  			<xsl:value-of select='@name' />
  		</xsl:when>
  		<xsl:otherwise>
  			root
  		</xsl:otherwise>
  	</xsl:choose>
  	</a>
  	
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-xang/java/samples/hello/layouts/editor_edit.xsl
  
  Index: editor_edit.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE riolayout [
   <!ENTITY baseResourcePath "/rio4/layouts/filemanager2/" >
   <!ENTITY baseURL "/xsp/data/default.xsp/" >
   <!ENTITY nbsp "<![CDATA[ ]]>" >
  ]>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="*" >
  <HTML>	
  <BODY bgcolor='#f0f0f0' >
  
  <!-- banner -->
  <table width='100%' bgcolor='#a0a0ff'>
  <tr ><td><font size='+2'>
  &lt;<xsl:value-of select='name()' />&gt;&nbsp; :&nbsp; <xsl:value-of
select='@name' />
  </font></td>
  <td align='right'>
  <a href="javascript:window.location=window.location" ><b>Refresh</b></a>
  </td>
  </tr>
  </table>
  
  
  <!-- banner -->
  <table width='100%' bgcolor='#c0c0ff'>
  <tr ><td><font size='+1'>
  Modify attributes
  </font></td></tr>
  </table>
  
  <form method='post' action='?do:method=update'>
  <TABLE>
  	<!-- Attributes -->
  	<xsl:for-each select="@*[((name() &lt; 'onGet') or (name() &gt;= 'onGeu')) and
(name() &lt; 'onPost' or name() &gt;= 'onPosu') ]">
  	<tr>
  		<td>
  			<b><xsl:value-of select='name()' /></b>
  		</td>
  		<td>
  			<input type='text' size='50' id='text' name='text'>
  			<xsl:attribute name='name'>
  				prop_<xsl:value-of select='name()' />
  			</xsl:attribute>
  			<xsl:attribute name='value'>
  				<xsl:value-of select='name()'/>
  			</xsl:attribute>
  			</input>
  		</td>
  	</tr>
  	</xsl:for-each>
  
  	<tr align='right'>
  		<td>
  		</td>
  		<td>
  			<input name='submit' id='submit' type='submit' value='  Update  '/>
  		</td>
  	</tr>
  </TABLE>
  </form>
  
  <!-- banner -->
  <table width='100%' bgcolor='#c0c0ff'>
  <tr ><td><font size='+1'>
  Add new attribute
  </font></td></tr>
  </table>
  <form method='post' action='?do:method=addprop' id='form1' name='form1'>
  <TABLE>
  	<tr>
  		<td>
  			<input type='text' size='10' name='name' />
  		</td>
  		<td>
  			<input type='text' size='40' name='value' />
  			&nbsp;
  			<input name='submit2' id='submit2' type='submit' value='  Add  '/>
  		</td>
  	</tr>
  </TABLE>
  </form>
  
  <!-- banner -->
  <table width='100%' bgcolor='#c0c0ff'>
  <tr ><td><font size='+1'>
  Modify methods
  </font></td></tr>
  </table>
  
  <form method='post' action='?do:method=update' id='form1' name='dialog'>
  <TABLE>
  
  	<!-- Methods -->
  	<xsl:for-each select="@*[(name() &gt;= 'onGet' and name() &lt;= 'onGeu') or
(name() &gt;= 'onPost' and name() &lt;= 'onPosu') ]">
  	<tr>
  		<td>
  			<b><xsl:value-of select='name()' /></b>
  		</td>
  		<td>
  			<input type='text' size='50' id='text' name='text'>
  			<xsl:attribute name='name'>
  				prop_<xsl:value-of select='name()' />
  			</xsl:attribute>
  			<xsl:attribute name='value'>
  				<xsl:value-of select='name()'/>
  			</xsl:attribute>
  			</input>
  		</td>
  	</tr>
  	</xsl:for-each>
  
  	<tr align='right'>
  		<td>
  		</td>
  		<td>
  			<input name='submit' id='submit' type='submit' value='  Update  '/>
  		</td>
  	</tr>
  </TABLE>
  </form>
  
  
  <!-- banner -->
  <table width='100%' bgcolor='#c0c0ff'>
  <tr ><td><font size='+1'>
  Add new method
  </font></td></tr>
  </table>
  <form method='post' action='?do:method=addprop' id='form1' name='form1'>
  <TABLE>
  	<tr>
  		<td>
  			<input type='text' size='10' name='name' />
  		</td>
  		<td>
  			<input type='text' size='40' name='value' />
  			&nbsp;
  			<input name='submit2' id='submit2' type='submit' value='  Add  '/>
  		</td>
  	</tr>
  </TABLE>
  </form>
  
  
  </BODY>
  </HTML>
  
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-xang/java/samples/hello/layouts/xap.xsl
  
  Index: xap.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE layout [
   <!ENTITY system.title "" >
  ]>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  <xsl:output method="html" indent="yes"/>
  
  <xsl:template match="*">
  <HTML>
  <BODY>
  <font face="Arial" size="+2">
  	<xsl:value-of select='title' />
  </font>
  <br />
  <font face="Arial" size="+1">
  	<xsl:value-of select='message' />
  </font>
  <hr />
  <xsl:apply-templates mode="outer" select='*[@name]' />
  
  <a href='./?do:method=script'>view script</a>
  
  </BODY>
  </HTML>
  </xsl:template>
  
  <xsl:template match='*' mode="outer">
  	<a>
  	<xsl:attribute name='href'>
  		<xsl:value-of select='@name' />/
  	</xsl:attribute>
  	<xsl:value-of select='title' />
  	</a>
  	<br />
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  

Mime
View raw message