Git, Beginner to Advanced Survey
View more presentations from Rafal Rusin.
This blog covers topics around programming in various languages, for the industry. It includes my insights based on commercial experience from various projects I worked on. I hope it will provide a simple way of doing complex tasks related to programming, as well as an overview of what's going on in software nowadays.
<a:article xmlns='http://www.w3.org/1999/xhtml' xmlns:a="urn:article"> <a:l>Some text</a:l> <a:code lang="xml"><![CDATA[ <someXml/> ]]></a:code> </a:article>
./run <input.xml >output.xhtml
declare namespace a="urn:article"; declare default element namespace "http://www.w3.org/1999/xhtml"; declare function a:processLine($l) { for $i in $l/node() return typeswitch ($i) case element(a:link, xs:untyped) return <a href="{$i/text()}">{$i/text()}</a> default return $i }; declare function a:articleItem($i) { typeswitch ($i) case element(a:l, xs:untyped) return (a:processLine($i), <br/>) case element(a:code, xs:untyped) return ( a:highlight($i/text(), $i/@lang)/body/* , <br/>) default return "error;" }; <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>a.xml</title> <link rel="stylesheet" type="text/css" href="highlight.css"/> </head> <body> { for $i in a:article/* return a:articleItem($i) } </body> </html>
public static class Mod { public static Node highlight(final String code, String lang) throws Exception { Validate.notNull(lang); final Process p = new ProcessBuilder("highlight", "-X", "--syntax", lang).start(); Thread t = new Thread(new Runnable() { public void run() { try { OutputStream out = p.getOutputStream(); IOUtils.write(code, out); out.flush(); out.close(); } catch (IOException e) { throw new RuntimeException(e); } } }); t.start(); String result = IOUtils.toString(p.getInputStream()); t.join(); return DOMUtils.parse(result).getDocumentElement(); } }
<employees> <employee> <name>Fred Jones</name> <address location="home"> <street>900 Aurora Ave.</street> <city>Seattle</city> <state>WA</state> <zip>98115</zip> </address> <address location="work"> <street>2011 152nd Avenue NE</street> <city>Redmond</city> <state>WA</state> <zip>98052</zip> </address> <phone location="work">(425)555-5665</phone> <phone location="home">(206)555-5555</phone> <phone location="mobile">(206)555-4321</phone> </employee> </employees>
<names> <name>Fred Jones</name> </names>
<names> {for $name in employees/employee/name/text() return <name>{$name}</name>} </names>
XQueryEvaluator evaluator = new XQueryEvaluator(); Long result = (Long) evaluator.evaluateExpression("5+5", null).get(0); Assert.assertEquals(new Long(10), result);
evaluator.bindVariable(QName.valueOf("myVar"), 123);
public static class MyFunctions { public static String myHello(String arg) { TestEvaluator te = (TestEvaluator) XQueryEvaluator.contextObjectTL.get(); te.id++; return "hello(" + arg + te.id + ")"; } } XQueryEvaluator evaluator = new XQueryEvaluator(); evaluator.setContextObject(this); evaluator.declareJavaClass("http://my.org/employees", MyFunctions.class); }
declare namespace my = 'http://my.org/employees'; my:myHello("hello")
mvn package