Getting a pdf for an Alfresco Java Webscript Controller - java

I'm trying to build a simple Webscript Endpoint in Alfresco that gets a pdf using a Java Webscript controller. We eventually want to expand this endpoint to take multiple pdfs and do some manipulation, but for right now we are just trying to read in and save 1 pdf.
The problem is the resulting InputStream is empty. This is despite it working just fine for xml files.
This is our uploadpdf.get.desc
<webscript>
<shortname>Upload PDFs</shortname>
<description>Upload PDFs</description>
<url>/uploadpdf</url>
<authentication>user</authentication>
<format default="html"></format>
</webscript>
This is our uploadpdf.get.html.ftl
<html>
<body>
<form action="${url.service}" method="post" enctype="multipart/form-data">
PDF1: <input type="file" name="pdf1"><br>
XML1: <input type="file" name="xml1"><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
This is our uploadpdf.post.dec
<webscript>
<shortname>Upload PDFs</shortname>
<description>Upload PDFs</description>
<url>/uploadpdf</url>
<authentication>user</authentication>
<format default="json"></format>
</webscript>
This is our uploadpdf.post.json.ftl (currently just returning a test string)
${newFile}
This is our Webscript-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="webscript.alfresco.tutorials.helloworld.get"
class="com.test.platformsample.HelloWorldWebScript"
parent="webscript">
</bean>
<bean id="webscript.uploadpdf.get"
class="com.test.UploadPdfWebScript"
parent="webscript">
</bean>
<bean id="webscript.uploadpdf.post"
class="com.test.UploadPdfWebScript"
parent="webscript">
</bean>
</beans>
And this is our UploadPdfWebscript.java (notice for testing purposes we are using org.springframework.extensions.webscripts.servlet.FormData;
This is to easily get the file. The code then saves the file to the local docker container. The problem is that file and by extention the InputStream is empty.
package com.test;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.servlet.FormData;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;
public class UploadPdfWebScript extends DeclarativeWebScript {
private static Log logger = LogFactory.getLog(UploadPdfWebScript.class);
protected Map<String, Object> executeImpl(
WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("fromJava", "HelloFromJava");
logger.debug("Your 'UploadPdf' Web Script was called!");
final FormData form = (FormData)req.parseContent();
InputStream file1 = null;
if(form == null || form.getFields() == null) {
return model;
}
for (FormData.FormField field : form.getFields())
{
if (field.getName().equals("pdf1"))
{
file1 = field.getInputStream();
}
}
String result = "this should be overwritten";
try{
result = processFile(file1);
} catch(Exception e) {
logger.error(e.getMessage());
}
if(result == null || result.equals("")) {
result = "No result";
}
model.put("newFile", result);
return model;
}
public String processFile(InputStream file) {
String ret = "{\”Result\": Success}”;
try {
byte[] buffer = new byte[file.available()];
file.read(buffer);
File targetFile = new File("targetFile.pdf");
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(buffer2);
} catch (Exception e) {
ret = "{\”Result\": Failure}”;
logger.error(e.getMessage(), e);
}
return ret;
}
How can I get a pdf or other arbitrary file type from the InputStream? Again the InputStream that is returned from the form is empty whenever I try to upload a pdf and as a result so is the saved pdf.
Note: If I try to read the pdf from the local file system rather than sending it via a post request, this works fine. The pdf I'm uploading is definitely valid and not empty. I also know the webscript is being properly called as it is posting a log message, returning Success, and creating the targetFile.pdf which is empty.

Change this line:
outStream.write(buffer2);
To:
outStream.write(buffer);
Here's what shows up in the tomcat dir on my Docker container:
-rw-r----- 1 root root 117249 Aug 7 19:28 targetFile.pdf
Looks like it works!

Related

Impossible to load image in jsp?

I am having this little problem, I see that it is impossible to load picture in my console, I don't know how to solve the problem.
I am getting my image name from database as a String in my controller, just the name, something like that ' image.jpg' and it is stored in my folder 'images'.
Here is my jsp file :
<c:if test="${ !(post.cover == 'empty')}">
<div class="imgPub">
<img src="Assets/images/${post.cover }">
</div>
</c:if>
In my inspector i can see the whole src written exactly, but a message next to it saying impossible to load image.
Any help would be much appreciated.
HttpServlet will do the job.
use:
youraddress.xxx/images/filename.png
this is important #WebServlet("/images/*")
It will automatically leads to folder defined in PATH and retrieve the image based on the name.
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
#WebServlet("/images/*")
public class ImageServlet extends HttpServlet {
public static final String PATH = "C:/"
/*
linux
public static final String PATH = "/home/images/"
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filename = request.getPathInfo().substring(1);
File file = new File(PATH,filename);
response.setHeader("Content-Type", getServletContext().getMimeType(filename));
response.setHeader("Content-Length",String.valueOf(file.length()));
response.setHeader("Content-Disposition","inline; filename=\""+filename +"\"");
Files.copy(file.toPath(),response.getOutputStream());
}
}

Need to put style-tag in head section in XPages, output goes to Excel

I have an XPage that allows the selection of a query-document. The full-text query that's inside it searches documents from the database, does some calculations and displays them as a view on the screen. There is also a button on the screen that sets requestScope.showExcel=true and does a full reload, in order to download the data directly into Excel (using .setHeader("Content-disposition", "inline; myfile.xls"). It is no more than a simple table with its tr and td tags. So far so good.
Column properties (height, width, colour) can be set per column, these are stored inside the query-document (which is a separate document, not part of the search results). Those properties are put into a style-tag element created using an xp:text control set to create html output.
It all works, except for one thing: Excel and OpenOffice or LibreOffice Calc don't like the style section in the body. When I save the output and move the styles to the head section the file loads okay in Excel.
So I went out to put our computed styling in the head section. I found the styleSheet resource, with its computed content parameter. It does generate some of the CSS I put in, but not all. As it turns out, the content is computed on load, and not dynamically. The button mentioned above does a full refresh of the page, which made me assume that styles would also be updated.
Alas, no. The stylesheet content seems to be fixed.
My questions:
Is there a way that inline CSS can be put in a style section in the head section in a dynamic way, so that it is recomputed when the page is reloaded (full update)?
Is there maybe some control somewhere that lets me add arbitrary content to the head section?
Or is there a way in Java to dynamically adapt the head section??
Thanks for your help!
Just create your own renderer for your header resource:
package ch.hasselba.xpages.renderkit;
import com.ibm.commons.util.StringUtil;
import com.ibm.xsp.complex.Parameter;
import com.ibm.xsp.render.ResourceRenderer;
import com.ibm.xsp.resource.GenericHeadResource;
import com.ibm.xsp.resource.Resource;
import com.ibm.xsp.util.JSUtil;
import java.io.IOException;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
public class GenericHeadResourceRenderer extends ResourceRenderer {
public void encodeResource(FacesContext fc, UIComponent uiComponent,
Resource res) throws IOException {
GenericHeadResource headRes = (GenericHeadResource) res;
ResponseWriter rw = fc.getResponseWriter();
String tagName = headRes.getTagName();
if (StringUtil.isNotEmpty(tagName)) {
rw.startElement(tagName, uiComponent);
List<Parameter> params = headRes.getAttributes();
if (params != null) {
for (Parameter param : params) {
String name = param.getName();
if (StringUtil.isNotEmpty(name)) {
String value = param.getValue();
if (value == null) {
value = "";
}
if( "content".equals( name ) ){
rw.write( value );
}else{
rw.writeAttribute(name, value, name);
}
}
}
}
rw.endElement(tagName);
JSUtil.writeln(rw);
}
}
}
To activate the renderer, you have to overwrite the existing one in the faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<render-kit>
<renderer>
<component-family>com.ibm.xsp.resource.Resource</component-family>
<renderer-type>com.ibm.xsp.resource.GenericHead</renderer-type>
<renderer-class>ch.hasselba.xpages.renderkit.GenericHeadResourceRenderer</renderer-class>
</renderer>
</render-kit>
</faces-config>
Then, add the dynamic content you want in a parameter with the name "content":
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:headTag tagName="style">
<xp:this.attributes>
<xp:parameter name="type" value="text/css" />
<xp:parameter name="content"
value="#{javascript:java.lang.System.currentTimeMillis()}" />
</xp:this.attributes>
</xp:headTag>
</xp:this.resources>
</xp:view>

File Image to Servlet Fails

I am trying to upload an image to a servlet, but every once and a while during automated testing, it silently fails.
Do you guys know what would cause this?
Here is the code on the server:
#ResponseBody
#RequestMapping(method = RequestMethod.POST)
public String upload(HttpServletRequest request) throws Exception {
BufferedImage image = null;
#SuppressWarnings("unchecked")
List<FileItem> items = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
Logger.log(LogLevel.INFO, "Upload contains " + items.size()
+ " items.");
int i = 0;
for (FileItem item : items) {
Logger.log(LogLevel.INFO, "\tItem " + (i++) + ". Name:\t"
+ item.getName() + ", Type:\t" + item.getContentType());
// File is of type "file"
if (!item.isFormField()) {
InputStream inputStream = null;
try {
inputStream = item.getInputStream();
if (inputStream.available() == 0) {
Logger.log(LogLevel.WARN,
"Item shows file type, but no bytes are available");
}
image = ImageIO.read(inputStream);
if (image != null) {
break;
}
} catch (Exception e) {
Logger.log(LogLevel.ERROR,
"There was an error reading the image. "
+ ExceptionUtils.getFullStackTrace(e));
throw new Exception("image provided is not a valid image");
} finally {
if (inputStream != null) {
IOUtils.closeQuietly(inputStream);
}
}
}
}
if (image == null) {
Logger.log(LogLevel.ERROR, "Image was supposedly read correctly, but was null afterwards");
throw new Exception("Image provided could not be read");
}
//do stuff with image
...
}
Here is the test:
public void testImageUpload throws Exception {
HttpPost httppost = new HttpPost("path/to/endpoint");
File file=new File(imgLoc);
FileBody bin = new FileBody(file);
StringBody comment = new StringBody("Filename: " + file);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("upload-file", bin);
reqEntity.addPart("comment", comment);
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Connection","Keep-Alive");
httppost.setEntity(reqEntity);
HttpResponse response =testClient.getClient().execute(httppost);
imgResponse=response.getStatusLine().toString();
System.out.println(imgResponse);
BufferedReader reader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = reader.readLine()) != null){
output = output + " " +line;}
System.out.println("Image Response: "+output);
}
Here is the output from the server when it fails:
2013/10/02 05-53-32,287::LOG:INFO[com.example#upload:L130 -- Upload contains 2 items.]
2013/10/02 05-53-32,288::LOG:INFO[com.example#upload:L133 -- Item 0. Name: Dog.jpg, Type: application/octet-stream]
2013/10/02 05-53-32,288::LOG:WARN[com.example#upload:L140 -- Item shows file type, but no bytes are available]
2013/10/02 05-53-32,289::LOG:INFO[com.example#upload:L133 -- Item 1. Name: null, Type: text/plain; charset=ISO-8859-1]
2013/10/02 05-53-32,290::LOG:ERROR[com.example#upload:L159 -- Image was supposedly read correctly, but was null afterwards]
We catch the exception from the image upload and send back a response code of 422 back to the client, so on the test, we get imgResponse==422 which is a failure case.
Note: this only happens sometimes you run the test.
Here is step by step configuration for file uploading by using Apache Commons FileUpload:
1. Add dependency jars for the following component. Here is the maven dependencies:
pom.xml
<dependencies>
<!-- Spring 3 MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<!-- Apache Commons file upload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- JSTL for c: tag -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
If you are not using maven then download respective jar from the maven repository online.
2. Create a FileUploadForm model
FileUploadForm.java
import java.util.List;
import org.springframework.web.multipart.MultipartFile;
public class FileUploadForm {
private List<MultipartFile> files;
//Getter and setter methods
}
3. Add resolver to MVC config file
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
</bean>
4. Write FileUploadController
FileUploadController.java
#Controller
public class FileUploadController {
     
    #RequestMapping(value = "/show", method = RequestMethod.GET)
    public String displayForm() {
        return "file_upload_form";
    }
     
    #RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(
            #ModelAttribute("uploadForm") FileUploadForm uploadForm,
                    Model map) {
         
        List<MultipartFile> files = uploadForm.getFiles();
 
        List<String> fileNames = new ArrayList<String>();
         
        if(null != files && files.size() > 0) {
            for (MultipartFile multipartFile : files) {
 
                String fileName = multipartFile.getOriginalFilename();
                fileNames.add(fileName);
                //Handle file content - multipartFile.getInputStream()
 
            }
        }
         
        map.addAttribute("files", fileNames);
        return "file_upload_success";
    }
}
5. Write jsp views
file_upload_form.jsp
<html>
<head>
<title>Spring MVC Multiple File Upload</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
//add more file components if Add is clicked
$('#addFile').click(function() {
var fileIndex = $('#fileTable tr').children().length - 1;
$('#fileTable').append(
'<tr><td>'+
' <input type="file" name="files['+ fileIndex +']" />'+
'</td></tr>');
});
});
</script>
</head>
<body>
<h1>Spring Multiple File Upload example</h1>
<form method="post" action="save.html"
**enctype="multipart/form-data"**>
<p>Select files to upload. Press Add button to add more file inputs.</p>
<input id="addFile" type="button" value="Add File" />
<table id="fileTable">
<tr>
<td><input name="files[0]" type="file" /></td>
</tr>
<tr>
<td><input name="files[1]" type="file" /></td>
</tr>
</table>
<br/><input type="submit" value="Upload" />
</form>
</body>
</html>
Reference: http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/mvc.html#mvc-multipart
It seems your content type is application/octet-stream. Please add the below Header in your request and give a try
("Content-Type", "multipart/form-data");
You are using InputStream#available. As the documentation states this is the number of bytes that can be read from the stream without blocking. Now, how many bytes are available from the TCP input stream depends on the size of the the packets and how your request is sliced amongst them (and a lot more other factors).
If your intention is to always read the stream in full, forget the available() method, just read it out until the end of stream and you should be fine.
I've come across this before under two conditions. Once was when I ran low on disk space and the other was when I was doing a bit of load test.
If you take a look at the How it works page, you can make the tool dump items to disk or keep them in memory. Under one case I filled up the drive during testing and the other I was keeping items in memory but the load blew my memory limit.
How do you have it set up? How big is the image you are using to test? How many times do yo upload it during your tests? With this info, I should be able to help a bit more.
This code is used on my site currently, works like a charm:
package com.example;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
#Controller
#RequestMapping("/api/media")
public class ImageRestService {
private static final Logger LOG = LoggerFactory.getLogger(ImageRestService.class);
#RequestMapping(value = "/uploadtemp", method = RequestMethod.POST)
public String upload(#RequestParam(value = "image") MultipartFile image) {
try {
BufferedImage bufferedImage = ImageIO.read(image.getInputStream());
// process image here
} catch (IOException e) {
LOG.error("failed to process image", e);
return "failure/view/name";
}
return "success/view/name";
}
}
Maybe the order of the items list is not fixed (timing dependent?). Your code
if (image != null) {
break;
}
quits the loop instead of trying the next parts. In the comments you state we iterate through the files until we can parse one, which should read
if (image != null) {
continue;
}
then.

XOM and Canonical XML

I'm making a java application that checks if a XML file is already Canonical or not using XOM.
In my tests I have the following file which is already Canonical.
<doc xmlns="http://example.com/default" xmlns:x="http://example.com/x">
<a a1="1" a2="2">123</a>
<b xmlns:y="http://example.com/y" a3=""3"" y:a1="1" y:a2="2"></b>
</doc>
Here it is the code when I load it again with XOM.
<?xml version="1.0"?>
<doc xmlns="http://example.com/default" xmlns:x="http://example.com/x">
<a a1="1" a2="2">123</a>
<b xmlns:y="http://example.com/y" a3=""3"" y:a1="1" y:a2="2" />
</doc>
As you can see it adds again xml tag and delete the closing tag </b> because the value of tag b is empty.
I haven't got any problem with xml version tag but I don't know what to do to keep the closing tag </b> when I load the canonical document from file.
It looks like you are outputting the document with a XOM Serializer you need to use a XOM Canonicalizer to output your xml document and keep it Canonical
This gives the output:
<?xml version="1.0" encoding="UTF-8"?>
<doc xmlns="http://example.com/default" xmlns:x="http://example.com/x">
<a a1="1" a2="2">123</a>
<b a3=""3"" y:a1="1" y:a2="2" xmlns:y="http://example.com/y"/>
</doc>
The following example program will output your XML Cannonically to System.out using a XOM Canonicalizer
package com.foo.bar.xom;
import java.io.IOException;
import nu.xom.Builder;
import nu.xom.canonical.Canonicalizer;
import nu.xom.Document;
import nu.xom.ParsingException;
import nu.xom.Serializer;
import nu.xom.ValidityException;
public class App
{
public static void main(String[] args) throws ValidityException, ParsingException, IOException
{
Builder builder = new Builder();
//Serializer serializer = new Serializer(System.out);
Canonicalizer canonicalizer = new Canonicalizer(System.out, Canonicalizer.EXCLUSIVE_XML_CANONICALIZATION);
//this assumes to your xml document is on the classpath in this package as my.xml
Document input = builder.build(App.class.getResourceAsStream("my.xml"), null);
//serializer.write(input);
canonicalizer.write(input);
}
}

<cms:include without <p> tag

Is there any solution to have something like <cms:include type="OpenCmsString" element="text1" /> ? Because the output from my <cms:include element="text1"> always give me data with <p> tag.
Any kind help is appreciated.
I've once created my own tag for that (StripPTag). You would compile that class and wrap it in a jar file, then deploy that to your opencms webapp lib folder.
package com.opencmsserver.taglib;
import org.opencms.flex.CmsFlexController;
import org.opencms.jsp.Messages;
import org.opencms.main.CmsLog;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.commons.logging.Log;
/**
* Removes the <p> tag from the surrounded content,
* because FCKEditor always add <p> tag to content at
* the beginning and end when using the html editor component
*
* #author Mathias Lin
*
* #version $Revision: 0.1 $
*
* #since 0.4
*/
public class StripPTag extends BodyTagSupport {
/** Serial version UID required for safe serialization. */
private static final long serialVersionUID = -2361021288258405388L;
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(StripPTag.class);
/**
* #see javax.servlet.jsp.tagext.Tag#doEndTag()
* #return EVAL_PAGE
* #throws JspException in case soemthing goes wrong
*/
public int doEndTag() throws JspException {
ServletRequest req = pageContext.getRequest();
// This will always be true if the page is called through OpenCms
if (CmsFlexController.isCmsRequest(req)) {
try {
// Get link-string from the body and reset body
String content = getBodyContent().getString();
content = content.replaceAll("<p>", "");
content = content.replaceAll("</p>", "");
getBodyContent().clear();
getBodyContent().print(content);
getBodyContent().writeOut(pageContext.getOut());
} catch (Exception ex) {
if (LOG.isErrorEnabled()) {
LOG.error("Failed using StripPTag. ", ex);
}
throw new JspException(ex);
}
}
return EVAL_PAGE;
}
}
and my own opencmsserver.tld:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>0.1</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>opencmsserver</short-name>
<uri>http://www.opencmsserver.com/taglib/cms</uri>
<display-name>OpenCms JSP standard taglib</display-name>
<description>
Additional OpenCms Tags
Developed by SYSVISION Ltd. / Mathias Lin (info#opencmsserver.com)
</description>
<tag>
<name>stripPTag</name>
<tag-class>com.opencmsserver.taglib.StripPTag</tag-class>
<body-content>JSP</body-content>
<description>
This tag stripts the p-tag from the surrounded content.
</description>
</tag>
</taglib>
which I then reference in my web.xml:
<!-- Begin: Custom SYSVISION OpenCmsServer lib -->
<taglib>
<taglib-uri>http://www.opencmsserver.com/taglib/opencmsserver</taglib-uri>
<taglib-location>/WEB-INF/opencmsserver.tld</taglib-location>
</taglib>
In your jsp, you just surround it then with:
<opencmsserver:stripPTag>Some content<p>with a paragraph</opencmsserver:stripPTag>
(and don't forget to reference to this tag lib in the jsp header section).

Categories