gpt4 book ai didi

java - 如何验证内部网页上的 CSS?

转载 作者:IT王子 更新时间:2023-10-29 00:21:54 26 4
gpt4 key购买 nike

我想查看内部网页,所以我不能使用 W3C validation直接服务。我设法在本地运行 XHTML validator ,但是,我在使用 css-validator 时遇到了一些问题。我真的不想设置 TomcatJigsaw为了能够运行 Java servlet,命令行选项给了我一条错误消息

Exception in thread "main" java.lang.NoClassDefFoundError: 
org.w3c.tools.resources.ProtocolException at
org.w3c.css.css.CssValidator.main(CssValidator.java:164)

如何在 Linux 机器上验证本地 CSS?

最佳答案

That jar是可运行的,但它需要一些额外的库。

检查 MANIFEST.MF文件:

$ unzip -p css-validator.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.0
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Main-Class: org.w3c.css.css.CssValidator
Class-Path: . lib/commons-collections-3.2.1.jar lib/commons-lang-2.6.j
ar lib/jigsaw.jar lib/tagsoup-1.2.jar lib/velocity-1.7.jar lib/xerces
Impl.jar lib/xml-apis.jar lib/htmlparser-1.3.1.jar

您需要 Class-Path 中提到的所有 jar。您可以从 maven repository 下载它们使用这个脚本:

#!/bin/bash

set -e

mkdir -p lib
curl -LO http://www.w3.org/QA/Tools/css-validator/css-validator.jar
echo "\
http://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
http://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
http://repo1.maven.org/maven2/org/w3c/jigsaw/jigsaw/2.2.6/jigsaw-2.2.6.jar jigsaw.jar
http://repo1.maven.org/maven2/org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.jar
http://repo1.maven.org/maven2/org/apache/velocity/velocity/1.7/velocity-1.7.jar
http://repo1.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar xercesImpl.jar
http://repo1.maven.org/maven2/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1.jar\
" | while read url shortname; do
if [ -z "$shortname" ]; then
shortname="${url##*/}"
fi
curl -L -o "lib/${shortname}" "${url}"
done

这样做之后,它起作用了:

$ java -jar css-validator.jar --output=soap12 file:badcss.html
{vextwarning=false, output=soap12, lang=en, warning=2, medium=all, profile=css3}
<?xml version='1.0' encoding="utf-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<m:cssvalidationresponse
env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:m="http://www.w3.org/2005/07/css-validator">
<m:uri>file:badcss.html</m:uri>
<m:checkedby>http://jigsaw.w3.org/css-validator/</m:checkedby>
<m:csslevel>css3</m:csslevel>
<m:date>2013-03-12T06:40:09Z</m:date>
<m:validity>false</m:validity>
<m:result>
<m:errors xml:lang="en">
<m:errorcount>1</m:errorcount>

<m:errorlist>
<m:uri>file:badcss.html</m:uri>

<m:error>
<m:line>8</m:line>
<m:errortype>parse-error</m:errortype>
<m:context> h1 </m:context>
<m:errorsubtype>
exp
</m:errorsubtype>
<m:skippedstring>
100%
</m:skippedstring>

<m:message>

Property fnt-size doesn&#39;t exist :
</m:message>
</m:error>

</m:errorlist>

</m:errors>
<m:warnings xml:lang="en">
<m:warningcount>1</m:warningcount>

<m:warninglist>
<m:uri>file:badcss.html</m:uri>

<m:warning>
<m:line>5</m:line>
<m:level>0</m:level>
<m:message>You should add a &#39;type&#39; attribute with a value of &#39;text/css&#39; to the &#39;style&#39; element</m:message>
</m:warning>

</m:warninglist>
</m:warnings>
</m:result>
</m:cssvalidationresponse>
</env:Body>
</env:Envelope>

关于java - 如何验证内部网页上的 CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1137884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com