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/fs2http/layouts editor.xsl editor_browse.xsl editor_edit.xsl fs2http.xsl
Date Wed, 21 Jun 2000 21:21:52 GMT
mdierken    00/06/21 14:21:51

  Added:       java/samples/fs2http editor.script.xml fs2http.xap
                        system.script.xml
               java/samples/fs2http/layouts editor.xsl editor_browse.xsl
                        editor_edit.xsl fs2http.xsl
  Log:
  New sample. File System browser - very rough.
  
  Revision  Changes    Path
  1.1                  xml-xang/java/samples/fs2http/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/fs2http/fs2http.xap
  
  Index: fs2http.xap
  ===================================================================
  
  <fs2http hits='0' onGet="pre_get();" onGetXml="getXML()" 
  	onLoad="loadSystem();" onGetLoad="doLoadSystem();"
  	layout='fs2http.xsl'
  	resources.server='../layouts/'>
  
  	<title>File System Browser</title>
  	<message>Welcome <br /></message>
  
  	<root src="d:/apache/htdocs/" depth='2' />
  	
  	<!-- include some common code -->
  	<script xml:link='include' src='system.script.xml' > 	</script>
  
  	<script>
  	<![CDATA[
  	var	fs_root_path = "d:/apache/htdocs/";
  
  	function getURI(node)
  	{
  		uri="";
  		
  		while ((node != null) && 
  			   (node.getNodeType() != Packages.org.w3c.dom.Node.DOCUMENT_NODE))
  		{
  			uri = node.getAttribute("name") + "/" + uri;
  			node = node.getParentNode();			
  		}
  		return uri;
  	}
  	
  	function pre_get(context,returnTypes,parameters)
  	{
  		if (!xml.hasChildNodes())
  		{
  			loadChildren(xml,"d:/apache/htdocs/"+getURI(xml)+"/");
  		}
  		
  		// call base method
  		get(context,returnTypes,parameters);
  	}
  	
  	function loadChildren(parent,path)
  	{
  		var i;
  		var child;
  		
  		xmldoc = parent.getOwnerDocument();
  		fs_folder = new Packages.java.io.File(path);
  
  		// remove 'folder' children
  		children = parent.getChildNodes();
  		if (children != null)
  		{
  			for (i=children.getLength()-1; i >= 0 ; --i)
  			{
  				child = children.item(i);
  				if ((child.getNodeName() == "FOLDER") ||
  					(child.getNodeName() == "CONTENT"))
  					{
  						parent.removeChild(children.item(i));
  					}
  			}
  		}
  		
  		// get list of files
  		list = fs_folder.list();
  		if (list != null)
  		{
  			// create children
  			for (i=0; i < list.length; i++)
  			{
  			    f = new Packages.java.io.File(path+list[i]);
  			    
  			    dir = f.isDirectory();
  			    
  			    if (dir > 0)
  			    {
  					child = xmldoc.createElement("FOLDER");
  			    }
  			    else
  			    {
  					child = xmldoc.createElement("CONTENT");
  			    }
  			    child.setAttribute("title",list[i]);
  			    child.setAttribute("name",list[i]);
  			    
  			    parent.appendChild(child);
  			}
          }
  	}
  	
  	function doLoadSystem(context,returnTypes,parameters)
  	{
  		doc = context.getResponse().getWriter();
  		context.getResponse().setContentType("text/html");
  		
  		doc.println("<HTML><BODY>");
  		
  		// add children
  		loadChildren(xml,"d:/apache/htdocs/"+getURI(xml)+"/");
  		
  		doc.println("</BODY></HTML>");
      }
  		
  	]]>
  	</script>
  
  </fs2http>
  
  
  
  1.1                  xml-xang/java/samples/fs2http/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))
  	{
  		media_root = Packages.org.apache.xang.util.ServletUtil.getRealPath(context);
  		layout = media_root + "/" + 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();
  	}
  }
  
  /*
      public static final short ELEMENT_NODE              = 1;
      public static final short ATTRIBUTE_NODE            = 2;
      public static final short TEXT_NODE                 = 3;
      public static final short CDATA_SECTION_NODE        = 4;
      public static final short ENTITY_REFERENCE_NODE     = 5;
      public static final short ENTITY_NODE               = 6;
      public static final short PROCESSING_INSTRUCTION_NODE = 7;
      public static final short COMMENT_NODE              = 8;
      public static final short DOCUMENT_NODE             = 9;
      public static final short DOCUMENT_TYPE_NODE        = 10;
      public static final short DOCUMENT_FRAGMENT_NODE    = 11;
      public static final short NOTATION_NODE             = 12;
  
  */
  function printNode(node,doc)
  {
  	type = node.getNodeType();
  
  	if (type == Packages.org.w3c.dom.Node.ELEMENT_NODE)
  	{
  		printElement(node,doc);
  	}
  	else
  	if (type == Packages.org.w3c.dom.Node.TEXT_NODE)
  	{
  		v = node.getNodeValue();
  		if (v != null)
  		{
  			doc.print(v);
  		}
  	}
  	else
  	if (type == Packages.org.w3c.dom.Node.CDATA_SECTION_NODE)
  	{
  		v = node.getNodeValue();
  		if (v != null)
  		{
  			doc.print("<!"+"[CDATA[");
  			doc.print(v);
  			doc.print("]"+"]>");
  		}
  	}
  }
  
  function printElement(node,doc)
  {
  	doc.print("<");
  	doc.print(node.getNodeName());
  	doc.print(" ");
  	attributes = node.getAttributes();
  	var i;
  	var j;
  	var list;
  	
  	for (i=0; i < attributes.getLength(); i++)
  	{
  		a = attributes.item(i);
  		doc.print(a.getNodeName());
  		doc.print('="');
  		doc.print(a.getNodeValue());
  		doc.print('" ');
  	}
  
  	if (!node.hasChildNodes())
  		doc.print("/>");
  	else
  	{
  		doc.print(">");
  		
  		list = node.getChildNodes();
  		for (j=0; j < list.getLength(); j++)
  		{
  			printNode(list.item(j),doc);
  		}
  		
  		doc.print("</");
  		doc.print(node.getNodeName());
  		doc.print(">");
  	}
  }
  
  function getXML(context,returnTypes,parameters)
  {
  	doc = context.getResponse().getWriter();
  	context.getResponse().setContentType("text/xml");
  	doc.println("<?xml version='1.0' ?>");
  	doc.println("<!-- cool huh? -->");
  	
  	printElement(xml);
  }
  
  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/fs2http/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/fs2http/layouts/editor_browse.xsl
  
  Index: editor_browse.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE riolayout [
   <!ENTITY baseResourcePath "/xap/apps/apache/" >
   <!ENTITY baseURL "/xap/apps/apache/hello/hello.xap/" >
   <!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/fs2http/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/fs2http/layouts/fs2http.xsl
  
  Index: fs2http.xsl
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE layout [
   <!ENTITY system.title "" >
   <!ENTITY nbsp "&#32; " >
  ]>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0' xml:space='preserve'>
  <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>
  <a href='./?do:method=load'>Refresh</a>
  <hr />
  <xsl:apply-templates mode="outer" select='*[@name]' />
  
  </BODY>
  </HTML>
  </xsl:template>
  
  <!-- Template for FOLDER -->
  <xsl:template match="FOLDER">
  <HTML>
  <BODY>
  <font face="Arial" size="+2">
  	<B><xsl:value-of select='@title' /></B>
  </font>
  <br />
  <font face="Arial" size="+1">
  	<xsl:value-of select='@message' />
  </font>
  
  <!-- do all parents -->
  <xsl:for-each select='..' >
  	<a>
  	<xsl:attribute name='href'>
  		..
  	</xsl:attribute>
  	<xsl:value-of select='@title' />
  	</a>
  	
  </xsl:for-each>
  |
  <a href='./?do:method=load'>Refresh</a> 
  
  <hr />
  <xsl:apply-templates mode="outer" select='FOLDER[@name]' />
  <xsl:apply-templates mode="outer" select='CONTENT[@name]' />
  
  </BODY>
  </HTML>
  </xsl:template>
  
  <!-- Template for FOLDER in a list -->
  <xsl:template match='FOLDER' mode="outer">
  	<img src='/xap/images/folder.gif' />&nbsp;
  	<a>
  	<xsl:attribute name='href'>
  		<xsl:value-of select='@name' />/
  	</xsl:attribute>
  	<xsl:value-of select='@title' />
  	</a>
  	<br />
  </xsl:template>
  
  <xsl:template match='CONTENT' mode="outer">
  	<img src='/xap/images/file.gif' />&nbsp;
  	<a>
  	<xsl:attribute name='href'>
  		<xsl:value-of select='@name' />/
  	</xsl:attribute>
  	<xsl:value-of select='@title' />
  	</a>
  	<br />
  </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