<%-- 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. --%> <%@ page import=" java.io.UnsupportedEncodingException, java.io.PrintStream, java.io.InputStream, java.io.ByteArrayOutputStream, java.io.File, org.apache.commons.fileupload.servlet.ServletFileUpload, org.apache.commons.fileupload.FileItemIterator, org.apache.commons.fileupload.FileItemStream, org.apache.commons.fileupload.util.Streams, org.odftoolkit.odfvalidator.ODFValidator, org.odftoolkit.odfvalidator.Logger, org.odftoolkit.odfvalidator.Configuration, org.odftoolkit.odfvalidator.OdfValidatorMode, org.odftoolkit.odfvalidator.ValidationMessageCollectorErrorFilter, org.odftoolkit.odfvalidator.OdfVersion" %> <% int loggingSelection = 0; int modeSelection = 0; if(ServletFileUpload.isMultipartContent(request)) { %>

ODF Validator Result Page

<% ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iter = upload.getItemIterator(request); ODFValidator validator = null; boolean result = false; while (iter.hasNext()) { FileItemStream item = iter.next(); InputStream stream = item.openStream(); /* The file item contains a simple name-value pair of a form field */ if(item.isFormField()) { if("loggingSelection".equals(item.getFieldName())) { loggingSelection = Integer.parseInt(Streams.asString(stream)); } else if("modeSelection".equals(item.getFieldName())) { modeSelection = Integer.parseInt(Streams.asString(stream)); } } else { /* The file item contains an uploaded file */ if((stream != null) && (item.getName() != null) && (!item.getName().equals(""))) { Logger.LogLevel aLogLevel = null; switch (loggingSelection) { case 2: aLogLevel = Logger.LogLevel.ERROR; break; case 1: aLogLevel = Logger.LogLevel.WARNING; break; default: aLogLevel = Logger.LogLevel.INFO; break; } OdfVersion aOdfVersion = null; OdfValidatorMode odfValidatorMode = null; switch (modeSelection) { case 6: aOdfVersion = OdfVersion.V1_0; odfValidatorMode = OdfValidatorMode.VALIDATE; break; case 4: aOdfVersion = OdfVersion.V1_1; odfValidatorMode = OdfValidatorMode.VALIDATE; break; case 5: aOdfVersion = OdfVersion.V1_0; odfValidatorMode = OdfValidatorMode.VALIDATE_STRICT; break; case 3: aOdfVersion = OdfVersion.V1_1; odfValidatorMode = OdfValidatorMode.VALIDATE_STRICT; break; case 2: odfValidatorMode = OdfValidatorMode.EXTENDED_CONFORMANCE; aOdfVersion = OdfVersion.V1_2; break; case 1: aOdfVersion = OdfVersion.V1_2; default: odfValidatorMode = OdfValidatorMode.CONFORMANCE; break; } validator = new ODFValidator(null, aLogLevel, true, aOdfVersion, true); ByteArrayOutputStream bout = null; if(validator != null) { out.println("

Result for " + item.getName() + "

"); bout = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(bout, true, "UTF-8"); ValidationMessageCollectorErrorFilter filter = new ValidationMessageCollectorErrorFilter(); try { result = !validator.validateStream(pout, stream, item.getName() , odfValidatorMode, filter); } catch (Exception e) { e.printStackTrace(pout); result = false; } } if(result) { out.println("

The document is " + odfValidatorMode.toString()+ " ODF" + validator.getOdfVersion() + "!"); } else { out.println("

The document is NOT " + odfValidatorMode.toString()+ " ODF" + validator.getOdfVersion() + "!"); } String s = null; try { s = new String(bout.toByteArray(), "UTF-8"); s = s.replaceAll("&", "&"); s = s.replaceAll("<", "<"); s = s.replaceAll(">", ">"); s = s.replaceAll("<span class='info'>", ""); s = s.replaceAll("<span class='warning'>", ""); s = s.replaceAll("<span class='error'>", ""); s = s.replaceAll("<span class='fatalError'>", ""); s = s.replaceAll("<span class='filePath'>", ""); s = s.replaceAll("<span class='messageType'>", ""); s = s.replaceAll("</span></br>", "
"); s = s.replaceAll("</span>", "
"); } catch (UnsupportedEncodingException use) { out.println(use); } if(s != null && (s.length() > 0)) { out.println("

Details:

" + s + "
"); } else { out.println("

"); } } } } %>


<% } else { %>

ODF Validator

This service checks conformance of ODF documents based on their OpenDocument Format specification. It does not cover all conformance criteria, yet (see implementation details).

ODF Version:

Logging:


Choose ODF documents for validation:



<% } %>