1. Cocoon Introduction According to the official definition of Apache, cocoon is an XML release framework. It allows you to define the conversion of XML documents and documents, and eventually generate the representations you choose, such as HTML, PDF, SVG, VRML, and more. In addition, Cocoon enables you to add processing logic in the XML file, thus a dynamic characteristic of the XML pipe.
2, download and installation
Download the latest version of Cocoon from http://xml.apache.org/, this article is in an example of version 2.1.6. Unzip the deployment package to the application server, this article takes Tomcat as an example. Visit http: // loclahost: 8080 / cocoon / See if the welcome interface appears.
3, Hello, Cocoon
After the CoCoon installation configuration is complete, you can run the routines provided by the system, or you can make an XSP program yourself. This article provides a simple program for reference. 3.1 File Description Program Name: Hello.xsp Conversion File: Hello.xsl3.2 File List 3.2.1 Hello.xsp
Expand the page of XSP ->
tag defines business logic -> string hello = "Hello, XSP!"; < XSP: EXPR> Hello
3.2.2
Hello.xsl
The value in the mark is output ->
The XSL style list can convert the XML document and output the specified style. 3.3 The configuration before the release first can be placed in the {Tomcat_Home} / WebApps / Cocoon / Hello directory. Thereafter, the corresponding configuration is required in SiteMap.xMap. Add to -> below
According to the above configuration, the style is specified in the style of hello / hello.xsl, and as long as you enter http: // localhost: 8080 / cocoon / hello / hello in the URL, send the result to In the browser. Similarly, if there is Hello2.xsp in this directory, you can call via http: // localhost: 8080 / cocoon / hello / hello2. It should be noted that after modifying SiteMap.xmap, you need to restart Tomcat or resin to make the modification take effect, otherwise you can try the check-reload attribute in the SiteMap mark in the Cocoon.xConf file, for example: After SITEMAP.XMAP modification, the system will automatically discover SITEMAP changes and re-load it.
4, from XML to HTML and PDF
4.1, Creating an XML Sample Document We use a simple XML file as a data source. You may use the actual XML or database or the like as a data source. Test.xml content: this is the test.xml example </ title> <s1 title = "section" > <p> this is the text of section one </ p> </ s1> </ page> 4.2, creating XSLT to generate HTML in Cocoon is used to generate HTML in Cocoon is to select and convert input documents using XSLT Suitable elements. Copy the DOC2HTML.XSL below to the HTML-PDF directory to make it together with the above two XML documents. DOC2HTML.XSL content: <? XML Version = "1.0" encoding = "ISO-8859-1"> <xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/xsl/transform" Version = "1.0"> <! - generate HTML SKELETON ON ROOT ELEMENT -> <XSL: Template Match = "/"> <html> <head> <title> <xsl: Apply-Templates Select = "Page / Title "/> <body> <xsl: apply-templates /> </ body> </ html> </ xsl: template> <! - story is buy later by the meerkat eXample - > <XSL: Template Match = "P | Story"> <P> <xsl: Apply-Templates /> </ P> </ xsl: template> <! - convert sections to html headings -> <XSL: Template Match = "s1"> <h1> <xsl: Apply-Templates Select = "@ title" /> </ h1> <xsl: apply-templates /> </ xsl: template> </ xsl: stylesheet> 4.3, creation Site Map Now we already have a document to be published and used to convert it to HTML XSLT. The next thing we have to do is to connect it together in the CoCoon pipe, then the site map can choose the pipeline through a specific request. SiteMap.xmap file content: <? XML version = "1.0" encoding = "UTF-8"?> <map: SiteMap XMLns: map = "http://apache.org/cocoon/sitemap/1.0"></p>
<p><map: components> <map: generators default = "file"> <map: generator name = "file" src = "org.apache.cocoon.generation.filegenerator" /> <map: generators> <map: Transformers Default = "xslt"> <map: transformer name = "xslt" src = "org.apache.cocoon.transformation.traxtransformer" /> </ map: transformers></p>
<p><map: readers default = "resource"> <map: reader name = "resource" src = "org.apache.cocoon.reading.resourceReader" /> </ map: readers></p>
<p><map: serializers default = "html"> <map: serializer name = "xml" mime-type = "text / xml" src = "org.apache.cocoon.serialization.xmlserializer" /> <map: serializer name = " HTML "MIME-TYPE =" text / html "src =" org.apache.cocoon.serialization.htmlserializer "/> <map: serializer name =" svg2png "src =" org.apache.cocoon.serization.svgserializer "mime- TYPE = "image / png" /> <map: serializer name = "fo2pdf" src = "org.apache.cocoon.serialization.fopserializer" mime-type = "Application / PDF" /> </ map: serializers></p>
<p><map: matcher default = "wildcard"> <map: matcher name = "wildcard" src = "org.apache.cocoon.matching.wildcardurimatcher" /> </ map: matchers> <map: pipe default = "caching"> <map: pipe name = "caching" src = "org.apache.cocoon.components.pipeline.impl.cachingprocessingpipeline"> </ map: pipe> </ map: pipes></p>
<p></ map: Components> <map: pipelines> <map: pipeline></p>
<p><map: match pattern = "*. html"> <map: generate src = "{1} .xml" /> <map: transform src = "doc2html.xsl" /> <map: serialize type = "html" / > </ map: match> <! - later, respond to * .pdf requireds with our docs process by doc2pdf.xsl -> <map: match pattern = "*. pdf"> <map: generate src = { 1} .xml "/> <map: transform.xsl" /> <map: serialize type = "fo2pdf" /> </ map: match> </ map: pipeline> </ map: pipes></p>
<p></ map: Sitemap> The above file is a very important thing is that <map: match> element is used to tell Cocoon how to handle the request of .html in the path here. 4.4. Test HTML Posted At this time, we should see the result of the HTML page. Access http: // localhost: 8080 / cocoon / test.html page displays "Section One" of the large font. If there is no normal job, you need to detect the above steps. If you can't find the reason, you can view the Cocoon's log to the $ Tomcat / WebApps / Cocoon / Web-INF / LOGS directory. Cocoon's log has multiple files, you only need to see the log file that is changed when the error occurs, and finds a clue. The above site map has been included in the PDF release. But this feature does not work normally because we have not created the XSLT required to convert to PDF. 4.5, the XSLT PDF document for creating a conversion PDF is generated by the XSL-FO document (including the XML document containing some specific page descriptive words). The actual transformation is completed by the Cocoon's PDF sequencer. Copy the following DOC2PDF.XSL to the HTML-PDF directory: DOC2PDF.XSL <? XML Version = "1.0" Encoding = "ISO-8859-1"> <xsl: stylesheet xmlns: xsl = "http: // www .w3.org / 1999 / xsl / transform "Version =" 1.0 "XMLns: fo =" http://www.w3.org/1999/xsl/format "> <! - generate pdf page structure -> < XSL: Template Match = "/"> <fo: root xmlns: fo = "http://www.w3.org/1999/xsl/format"> <fo: layout-master-set> <fo: Simple-Page -master master-name = "Page" Page-height = "</p>
<p>29.7cm</p>
<p>"Page-width ="</p>
<p>21cm</p>
<p>"margin-top =" 1cm</p>
<p>"margin-bottom ="</p>
<p>2cm</p>
<p>"margin-left ="</p>
<p>2.5cm</p>
<p>"Margin-Right ="</p>
<p>2.5cm</p>
<p>"> <fo: region-before extent ="</p>
<p>3cm</p>
<p>"/> <fo: region-body margin-top ="</p>
<p>3cm</p>
<p>"/> <fo: region-after eXtent ="</p>
<p>1.5cm</p>
<p>"/> </ fo: Simple-page-master> <fo: Page-sequence-master master-name =" all "> <fo: repeatable-page-master-alternatives> <fo: conditional-page-master-reference Master-reference = "Page" page-position = "first" /> </ fo: repeatable-page-master-alternative-master> </ fo: layout-master-set> <fo : Page-sequence master-reference = "all"> <fo: flow flow-name = "xsl-region-body"> <fo: block> <xsl: apply-templates /> </ fo: block> </ fo : flow> </ fo: page-sequence> </ fo: root> </ xsl: template> <! - process paragraphs -> <xsl: template match = "p"> <fo: block> <xsl: Apply-templates /> </ fo: block> </ xsl: template> <! - convert sections to xsl-fo headings -> <xsl: template match = "s1"> <fo: block font-size = "</p>
<p>24pt</p></div><div class="text-center mt-3 text-grey">
转载请注明原文地址:https://www.9cbs.com/read-40148.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>)
</div><div></div></div></div><ul class="postlist list-unstyled">
</ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="40148" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved
</div><div class="col text-right">Processed:
<b>0.043</b>, SQL:
<b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script>
var debug = DEBUG = 0;
var url_rewrite_on = 1;
var url_path = './';
var forumarr = {"1":"Tech"};
var fid = 1;
var uid = 0;
var gid = 0;
xn.options.water_image_url = 'view/img/water-small.png';
</script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script>
var forum_url = 'list-1.html';
var safe_token = 'RUHACDZatdW8N9j8EXtdnQLHvjucctly3SfLqWRZP_2B2Wfcv_2BBkedgey0wt7xbV6dIvdsJwM1E7O2sY75I6a1Uw_3D_3D';
var body = $('body');
body.on('submit', '#form', function() {
var jthis = $(this);
var jsubmit = jthis.find('#submit');
jthis.reset();
jsubmit.button('loading');
var postdata = jthis.serializeObject();
$.xpost(jthis.attr('action'), postdata, function(code, message) {
if(code == 0) {
location.reload();
} else {
$.alert(message);
jsubmit.button('reset');
}
});
return false;
});
function resize_image() {
var jmessagelist = $('div.message');
var first_width = jmessagelist.width();
jmessagelist.each(function() {
var jdiv = $(this);
var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width();
var jmessage_width = Math.min(jdiv.width(), maxwidth);
jdiv.find('img, embed, iframe, video').each(function() {
var jimg = $(this);
var img_width = this.org_width;
var img_height = this.org_height;
if(!img_width) {
var img_width = jimg.attr('width');
var img_height = jimg.attr('height');
this.org_width = img_width;
this.org_height = img_height;
}
if(img_width > jmessage_width) {
if(this.tagName == 'IMG') {
jimg.width(jmessage_width);
jimg.css('height', 'auto');
jimg.css('cursor', 'pointer');
jimg.on('click', function() {
});
} else {
jimg.width(jmessage_width);
var height = (img_height / img_width) * jimg.width();
jimg.height(height);
}
}
});
});
}
function resize_table() {
$('div.message').each(function() {
var jdiv = $(this);
jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>');
});
}
$(function() {
resize_image();
resize_table();
$(window).on('resize', resize_image);
});
var jmessage = $('#message');
jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); });
jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); });
$('#nav li[data-active="fid-1"]').addClass('active');
</script>