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

发布于 2024-07-27 15:04:18 字数 577 浏览 6 评论 0原文

我想检查内部网页,因此无法直接使用 W3C 验证 服务。 我设法在本地运行 XHTML 验证器,但是,我在使用 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?

I want to check internal web pages, so I cannot use the W3C validation service directly. I managed to run the XHTML validator locally, however, I have some problems with the css-validator. I do not really want to setup Tomcat or Jigsaw in order to be able to run Java servlet, and the commandline option gives me an error message

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

How can I validate local CSS on a Linux box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜点 2024-08-03 15:04:19

您可以从命令行调用 W3C 验证器

命令行使用

任何安装了Java的计算机都可以
还可以从以下位置运行验证器
终端/控制台作为命令行
工具。 下载 css-validator.jar
jar 存档(或使用 ant jar 构建它)
并将其运行为:

java -jar css-validator.jar http://www.w3.org/

注意:css-validator.jar 文件必须
位于完全相同的水平
lib/ 文件夹才能正常工作。

更新:为了使其正常工作,我从 CVS 中查看了完整的发行版,并使用包含的 build.xml 运行 ant。 它下载了除 servlet.jar 之外的所有依赖项。 为了解决这个问题,我下载了 Tomcat 6 的二进制发行版并提取它。 然后,我编辑了 css-validatorbuild.xml 以反映 servlet.lib 的位置:

<property name="servlet.lib" 
 value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>

然后运行 ​​ant 再次。 这会在从 CVS 检出的目录顶层生成 css-validator.jar 文件,其中 lib 子目录包含其他 jar这取决于。 然后,我能够成功运行验证器:

C:\Temp\validator\2002\css-validator> java -jar css-validator.jar http://www.unur.com/

You can invoke the W3C validator from the command line:

Command-Line use

Any computer with Java installed can
also run the validator from the
terminal/console as a commandline
tool. Download the css-validator.jar
jar archive (or build it with ant jar)
and run it as :

java -jar css-validator.jar http://www.w3.org/

Note : the css-validator.jar file must
be located at the exact same level as
the lib/ folder to work properly.

Update: To get it to work, I checked out the full distribution from CVS and ran ant using the included build.xml. It downloaded all dependencies except for servlet.jar. To deal with that, I downloaded the binary distribution of Tomcat 6 and extracted it. Then, I edited the build.xml for css-validator to reflect the location of servlet.lib:

<property name="servlet.lib" 
 value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>

Then ran ant again. This produced the css-validator.jar file in the top level of the directory checked out from CVS with the lib subdirectory containing the other jars it depends on. Then, I was able to run the validator successfully:

C:\Temp\validator\2002\css-validator> java -jar css-validator.jar http://www.unur.com/

濫情▎り 2024-08-03 15:04:19

对于懒惰的人来说,这是我编写的一个脚本,用于执行 Sinan 建议的操作:

#!/bin/sh
# W3C CSS Validator Install Script --------------
# installs W3C CSS Validator
# requires: ant, wget, javac
# see: http://jigsaw.w3.org/css-validator/DOWNLOAD.html
# see: http://esw.w3.org/CssValidator
# see: http://thecodetrain.co.uk/2009/02/running-the-w3c-css-validator-locally-from-the-command-line/
# see: http://stackoverflow.com/a/3303298/357774
##wget "http://www.w3.org/QA/Tools/css-validator/css-validator.jar"
#sudo aptitude install -y ant # uncomment if you don't have ant
CVSROOT=:pserver:anonymous:[email protected]:/sources/public cvs checkout 2002/css-validator 
mkdir 2002/css-validator/lib
TOMCAT6_VERSION='6.0.45'
wget "http://www.apache.org/dist/tomcat/tomcat-6/v$TOMCAT6_VERSION/bin/apache-tomcat-$TOMCAT6_VERSION.tar.gz"
tar xvf apache-tomcat-$TOMCAT6_VERSION.tar.gz
mv apache-tomcat-$TOMCAT6_VERSION/lib/servlet-api.jar 2002/css-validator/lib/servlet.jar
rm -rf apache-tomcat-$TOMCAT6_VERSION apache-tomcat-$TOMCAT6_VERSION.tar.gz
cd 2002/css-validator
ant jar
# usage example: java -jar css-validator.jar "http://csszengarden.com/"

这应该有效,至少直到下一个软件依赖项更新破坏 ant 构建脚本为止(随意参数化版本)。

希望这可以帮助!

For the lazy, here's a script I wrote to do what Sinan suggests:

#!/bin/sh
# W3C CSS Validator Install Script --------------
# installs W3C CSS Validator
# requires: ant, wget, javac
# see: http://jigsaw.w3.org/css-validator/DOWNLOAD.html
# see: http://esw.w3.org/CssValidator
# see: http://thecodetrain.co.uk/2009/02/running-the-w3c-css-validator-locally-from-the-command-line/
# see: http://stackoverflow.com/a/3303298/357774
##wget "http://www.w3.org/QA/Tools/css-validator/css-validator.jar"
#sudo aptitude install -y ant # uncomment if you don't have ant
CVSROOT=:pserver:anonymous:[email protected]:/sources/public cvs checkout 2002/css-validator 
mkdir 2002/css-validator/lib
TOMCAT6_VERSION='6.0.45'
wget "http://www.apache.org/dist/tomcat/tomcat-6/v$TOMCAT6_VERSION/bin/apache-tomcat-$TOMCAT6_VERSION.tar.gz"
tar xvf apache-tomcat-$TOMCAT6_VERSION.tar.gz
mv apache-tomcat-$TOMCAT6_VERSION/lib/servlet-api.jar 2002/css-validator/lib/servlet.jar
rm -rf apache-tomcat-$TOMCAT6_VERSION apache-tomcat-$TOMCAT6_VERSION.tar.gz
cd 2002/css-validator
ant jar
# usage example: java -jar css-validator.jar "http://csszengarden.com/"

That should work, at least until the next software dependency update breaks the ant build script (feel free to parameterize versions).

Hope this helps!

橘虞初梦 2024-08-03 15:04:19

您现在可以使用新的 Linux 命令行工具 htmlval 来检查 HTML 和 CSS。 它肯定适用于在 Linux 机器上验证本地 CSS。

注意:我是开发者。

You can now use the new Linux command line tool htmlval for checking HTML and CSS. It should definitely work for validating local CSS on a Linux box.

Note: I'm the developer.

迷你仙 2024-08-03 15:04:18

该 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 存储库 下载它们:

#!/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'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 'type' attribute with a value of 'text/css' to the 'style' element</m:message>
                        </m:warning>

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

That jar is runnable, but it needs some extra libraries.

Examine the MANIFEST.MF file:

$ 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

You need all the jars mentioned in Class-Path. You can download them from the maven repository using this script:

#!/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

After doing that, it works:

$ 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'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 'type' attribute with a value of 'text/css' to the 'style' element</m:message>
                        </m:warning>

                    </m:warninglist>
                    </m:warnings>
            </m:result>
        </m:cssvalidationresponse>
    </env:Body>
</env:Envelope>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文