Annotation of 2002/css-validator/HOWTO.html, revision 1.2

1.1       plehegar    1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      2:    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      3: <html xmlns="http://www.w3.org/1999/xhtml" lang="en-fr" xml:lang="en-fr">
                      4:   <head>
                      5:     <title>CSS Validator Project</title>
                      6: 
                      7:     <link href="style/page.css" type="text/css" rel="STYLESHEET" />
                      8:     <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
                      9:     <link rel="STYLESHEET" title="default" media="screen" href="style/general.css" type="text/css" />
                     10:     <meta name="Generator" content="*emacs: emacs-css" />
                     11:     <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
                     12: </head>
                     13:   <body>
                     14:     <a class="left" href="http://www.w3.org"><img
                     15:        src="http://www.w3.org/Icons/w3c_home" alt="w3c" border="0" /></a>
                     16:     <a class="right" href="http://www.w3.org/Jigsaw/"><img
                     17:          src="http://jigsaw.w3.org/Icons/jigpower.gif" alt="Jigsaw Powered"
                     18:          border="0" width="94" height="52" /></a>
                     19:     <br />
                     20: 
                     21:     <div class="t1">CSS</div>
                     22:     <div class="t2">Validator</div>
                     23: 
                     24:     <h1 class="center">CSS Validator version 2.0 : 
                     25:       How to add CSS properties in this validator ?</h1>
                     26:     
                     27:     <p>In first, you should create your properties.</p>
                     28:       
                     29:     <p>To do this, You should extend the class CSS.Properties.CssProperty. If you have
                     30:       some macros, see <a href="docs/org.w3c.css.aural.ACssCueBefore.html">CSS.Properties.ACssCueBefore</a> for an example.
                     31:       </p>
                     32:     <p>An example for the name of a property : 
                     33:       <code>CSS2.Printing.CssPageBreakBefore</code>
                     34:       </p>
                     35:     <p>Then, you should implements the interface 
                     36:       <a href="docs/org.w3c.css.parser.CssStyle.html">org.w3c.css.parser.CssStyle</a>. For an example, you can see
                     37:       <a href="docs/org.w3c.css.aural.ACssStyle.html">org.w3c.css.aural.ACssStyle</a>. In this
                     38:       example, I added aural cascading style sheet to cascading style sheet level 1,
                     39:       so I extends the style Css1Style that implements the CssStyle. Be careful, you
                     40:       must have a public constructor with no parameters in your CssStyle !
                     41:       </p>
                     42:     <p>An example for the name of your style :
                     43:       <code>CSS2.Printing.PCssStyle</code>
                     44:       </p>
                     45:     <p>Create two configuration properties file :</p>
                     46:     <ol>
                     47:       <li>Config.properties
                     48:        <pre>
                     49: # My parser config :
                     50: style : CSS2.Printing.PCssStyle
                     51: properties: CSS2Printing.properties
                     52: # Note : the file CSS2Printing.properties should be in your style directory.
                     53: 
                     54: # Activate the CSS2 parser
                     55: extended-parser : true
                     56:        </pre></li>
                     57:       <li>CS2Printing.properties
                     58:        <pre>
                     59: # A property
                     60: # Note : if you want to reuse CSS1 properties, you should add all properties !
                     61: #        For an example, see <a
                     62:            href="org/w3c/css/aural/AuralProperties.properties">AuralProperties.properties</a>
                     63: page-break-before : CSS2.Printing.CssPageBreakBefore
                     64:        </pre></li>
                     65:     </ol>
                     66:     
                     67:     <p>Now you are ready to parse your properties.</p>
                     68:     <p>Finally, You should say where the parser can find your properties. This is
                     69:       a sample code to parse your owns properties :</p>
                     70:       
                     71:     <pre>
                     72: <span class="keyword">import</span> <span class="reference">java</span>.<span class="reference">util</span>.<span class="type">Properties</span>;
                     73: <span class="keyword">import</span> <span class="reference">java</span>.<span class="reference">net</span>.<span class="type">URL</span>;
                     74: 
                     75: <span class="keyword">import</span> <span class="reference">org</span>.<span class="reference">w3c</span>.<span class="reference">css</span>.<span class="reference">parser</span>.<span class="type">CssFouffa</span>;
                     76: <span class="keyword">import</span> <span class="reference">org</span>.<span class="reference">w3c</span>.<span class="reference">css</span>.<span class="reference">css</span>.<span class="type">StyleSheetParser</span>;
                     77: <span class="keyword">import</span> <span class="reference">org</span>.<span class="reference">w3c</span>.<span class="reference">css</span>.<span class="reference">css</span>.<span class="type">StyleSheetOrigin</span>;
                     78: 
                     79: <span class="keyword">import</span> <span class="reference">CSS2</span>.<span class="reference">Printing</span>.<span class="type">PCssStyle</span>;
                     80: 
                     81: <span class="keyword">class</span> <span class="function-name">MyStartUp</span> {
                     82: 
                     83:  <span class="reference">public</span> <span class="type">static</span> <span class="type">void</span> <span class="function-name">main</span>(<span class="type">String</span>[] <span class="variable-name">args</span>) {
                     84: 
                     85:   <span class="type">Properties</span> <span class="variable-name">properties</span> = <span class="keyword">new</span> <span class="type">Properties</span>();
                     86:   <span class="keyword">try</span> {
                     87:    <span class="type">Properties</span> <span class="variable-name">config</span> = <span class="keyword">new</span> <span class="type">Properties</span>();
                     88: 
                     89:    <span class="comment">// try to load the file
                     90: </span>   <span class="type">URL</span> <span class="variable-name">url</span> = PCssStyle.<span class="keyword">class</span>.getResource("<span class="string">CSS2Printing.properties</span>");
                     91: 
                     92:    config.load(url.openStream());
                     93: 
                     94:    <span class="comment">// set the parser
                     95: </span>   CssFouffa.loadConfig(config);
                     96: 
                     97:   } <span class="keyword">catch</span> (<span class="type">Exception</span> <span class="variable-name">e</span>) {
                     98:    System.err.println("<span class="string">MyStartUp: couldn't load properties</span>");
                     99:    System.err.println("<span class="string">  </span>" + e.toString() );
                    100:    System.exit(1);
                    101:   }
                    102: 
                    103:   <span class="comment">// now the parser is ready !
                    104: </span>
                    105:   <span class="comment">// create a parser
                    106: </span>  <span class="type">StyleSheetParser</span> <span class="variable-name">parser</span> = <span class="keyword">new</span> <span class="type">StyleSheetParser</span>();
                    107: 
                    108:   <span class="comment">// parse an URL
                    109: </span>  parser.parseURL(<span class="keyword">new</span> <span class="type">URL</span>("<span class="string">http://www.w3.org/Style</span>"), StyleSheetOrigin.AUTHOR);
                    110: 
                    111:   <span class="comment">// output the result
                    112: </span>  <span class="type">StyleSheetGenerator</span> <span class="variable-name">style</span> = 
                    113:    <span class="keyword">new</span> <span class="type">StyleSheetGenerator</span>("<span class="string">My example</span>",           <span class="comment">// title
                    114: </span>                           parser.getStyleSheet(), <span class="comment">// get the style sheet
                    115: </span>                           "<span class="string">text</span>");                <span class="comment">// output format
                    116: </span>  style.print(System.out);
                    117:  }
                    118: }
                    119: 
                    120:     </pre>
                    121:     
                    122:     <p>There is an example for a new package for CSS2. In this example, I reuse
                    123:       Aural properties.
                    124:     </p>
                    125:     <hr class="large" />
                    126:     <img src="images/mwcss.gif" alt="made with CSS" />
1.2     ! plehegar  127:     <address class="right"><a href="mailto:Email.html">validator-css</a></address>
1.1       plehegar  128:   </body>
                    129: </html>

Webmaster