![]() |
![]() |
jtidy-r872-jdk1516:38:17.194 INFO jd.cli.Main - Decompiling jtidy-r872-jdk15.jar package org.w3c.tidy.ant; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Properties; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Parameter; import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.FlatFileNameMapper; import org.apache.tools.ant.util.IdentityMapper; import org.w3c.tidy.Tidy; public class JTidyTask extends Task { private List filesets = new ArrayList(); private File destdir; private File destfile; private File srcfile; private boolean failonerror; private boolean flatten; private Tidy tidy; private Properties props; private File properties; public void setDestdir(File destdir) { this.destdir = destdir; } public void setDestfile(File destfile) { this.destfile = destfile; } public void setSrcfile(File srcfile) { this.srcfile = srcfile; } public void setFailonerror(boolean failonerror) { this.failonerror = failonerror; } public void setFlatten(boolean flatten) { this.flatten = flatten; } public void setProperties(File properties) { this.properties = properties; } public void addFileset(FileSet fileSet) { filesets.add(fileSet); } public void addConfiguredParameter(Parameter prop) { props.setProperty(prop.getName(), prop.getValue()); } public void init() { super.init(); tidy = new Tidy(); props = new Properties(); } protected void validateParameters() throws BuildException { if ((srcfile == null) && (filesets.size() == 0)) { throw new BuildException("Specify at least srcfile or a fileset."); } if ((srcfile != null) && (filesets.size() > 0)) { throw new BuildException("You can't specify both srcfile and nested filesets."); } if ((destfile == null) && (destdir == null)) { throw new BuildException("One of destfile or destdir must be set."); } if ((srcfile == null) && (destfile != null)) { throw new BuildException("You only can use destfile with srcfile."); } if ((srcfile != null) && (srcfile.isDirectory())) { throw new BuildException("srcfile can't be a directory."); } if ((properties != null) && (properties.isDirectory())) { throw new BuildException("Invalid properties file specified: " + properties.getPath()); } } public void execute() throws BuildException { validateParameters(); if (properties != null) { try { props.load(new FileInputStream(properties)); } catch (IOException e) { throw new BuildException("Unable to load properties file " + properties, e); } } tidy.setErrout(new PrintWriter(new ByteArrayOutputStream())); tidy.setConfigurationFromProps(props); if (srcfile != null) { executeSingle(); } else { executeSet(); } } protected void executeSingle() { if (!srcfile.exists()) { throw new BuildException("Could not find source file " + srcfile.getAbsolutePath() + "."); } if (destfile == null) { destfile = new File(destdir, srcfile.getName()); } processFile(srcfile, destfile); } protected void executeSet() { FileNameMapper mapper = null; if (flatten) { mapper = new FlatFileNameMapper(); } else { mapper = new IdentityMapper(); } mapper.setTo(destdir.getAbsolutePath()); Iterator iterator = filesets.iterator(); while (iterator.hasNext()) { FileSet fileSet = (FileSet)iterator.next(); DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject()); String[] sourceFiles = directoryScanner.getIncludedFiles(); File inputdir = directoryScanner.getBasedir(); mapper.setFrom(inputdir.getAbsolutePath()); for (int j = 0; j < sourceFiles.length; j++) { String[] mapped = mapper.mapFileName(sourceFiles[j]); processFile(new File(inputdir, sourceFiles[j]), new File(destdir, mapped[0])); } } } protected void processFile(File inputFile, File outputFile) { log("Processing " + inputFile.getAbsolutePath(), 4); InputStream is; try { is = new BufferedInputStream(new FileInputStream(inputFile)); } catch (IOException e) { throw new BuildException("Unable to open file " + inputFile); } OutputStream os; try { outputFile.getParentFile().mkdirs(); outputFile.createNewFile(); os = new BufferedOutputStream(new FileOutputStream(outputFile)); } catch (IOException e) { throw new BuildException("Unable to open destination file " + outputFile, e); } tidy.parse(is, os); try { is.close(); } catch (IOException e1) {} try { os.flush(); os.close(); } catch (IOException e1) {} if ((tidy.getParseErrors() > 0) && (!tidy.getForceOutput())) { outputFile.delete(); } if ((failonerror) && (tidy.getParseErrors() > 0)) { throw new BuildException("Tidy was unable to process file " + inputFile + ", " + tidy.getParseErrors() + " returned."); } } } /* Location: * Qualified Name: org.w3c.tidy.ant.JTidyTask * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public abstract interface AttrCheck { public abstract void check(Lexer paramLexer, Node paramNode, AttVal paramAttVal); } /* Location: * Qualified Name: org.w3c.tidy.AttrCheck * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckAction implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (attval.hasValue()) { AttrCheckImpl.URL.check(lexer, node, attval); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckAction * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckAlign implements AttrCheck { private static final String[] VALID_VALUES = { "left", "right", "center", "justify" }; public void check(Lexer lexer, Node node, AttVal attval) { if ((tag != null) && ((tag.model & 0x10000) != 0)) { AttrCheckImpl.VALIGN.check(lexer, node, attval); return; } if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } attval.checkLowerCaseAttrValue(lexer, node); if (node.is(TagId.CAPTION)) { return; } if (!attval.valueIsAmong(VALID_VALUES)) { if ((!attval.valueIs("char")) || (!node.hasCM(640))) { report.attrError(lexer, node, attval, (short)51); } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckAlign * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckBool implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { return; } attval.checkLowerCaseAttrValue(lexer, node); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckBool * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckClear implements AttrCheck { private static final String[] VALID_VALUES = { "none", "left", "right", "all" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); if (value == null) { value = "none"; } return; } attval.checkLowerCaseAttrValue(lexer, node); if (!attval.valueIsAmong(VALID_VALUES)) { report.attrError(lexer, node, attval, (short)51); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckClear * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; import java.util.HashMap; import java.util.Map; public class AttrCheckImpl$CheckColor implements AttrCheck { private static final Map<String, String> COLORS_BY_NAME = new HashMap(); private static final Map<String, String> COLORS_BY_VALUE = new HashMap(); private static void addColor(String name, String value) { COLORS_BY_NAME.put(name, value); COLORS_BY_VALUE.put(value, name); } static { addColor("black", "#000000"); addColor("green", "#008000"); addColor("silver", "#C0C0C0"); addColor("lime", "#00FF00"); addColor("gray", "#808080"); addColor("olive", "#808000"); addColor("white", "#FFFFFF"); addColor("yellow", "#FFFF00"); addColor("maroon", "#800000"); addColor("navy", "#000080"); addColor("red", "#FF0000"); addColor("blue", "#0000FF"); addColor("purple", "#800080"); addColor("teal", "#008080"); addColor("fuchsia", "#FF00FF"); addColor("aqua", "#00FFFF"); } private static String getColorCode(String name) { return (String)COLORS_BY_NAME.get(name.toLowerCase()); } private static String getColorName(String code) { return (String)COLORS_BY_VALUE.get(code.toUpperCase()); } private static boolean isValidColorCode(String color) { if (color.length() != 6) { return false; } for (int i = 0; i < 6; i++) { if (!TidyUtils.isxdigit(color.charAt(i))) { return false; } } return true; } public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } boolean valid = false; String given = value; if ((given.length() > 0) && (given.charAt(0) != '#') && ((valid = isValidColorCode(given)))) { String s = '#' + given; report.attrError(lexer, node, attval, (short)73); given = value = s; } if ((!valid) && (given.length() > 0) && (given.charAt(0) == '#')) { valid = isValidColorCode(given.substring(1)); } if ((valid) && (given.charAt(0) == '#') && (configuration.isReplaceColor())) { String newName = getColorName(given); if (newName != null) { given = value = newName; } } if (!valid) { valid = getColorCode(given) != null; } if ((valid) && (given.charAt(0) == '#')) { value = value.toUpperCase(); } else { value = value.toLowerCase(); } if (!valid) { report.attrError(lexer, node, attval, (short)51); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckColor * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckFsubmit implements AttrCheck { private static final String[] VALID_VALUES = { "get", "post" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckFsubmit * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckId implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (!TidyUtils.isValidHTMLID(value)) { if ((isvoyager) && (TidyUtils.isValidXMLID(value))) { report.attrError(lexer, node, attval, (short)71); } else { report.attrError(lexer, node, attval, (short)51); } } Node old = configuration.tt.getNodeByAnchor(value); if ((old != null) && (old != node)) { report.attrError(lexer, node, attval, (short)66); } else { configuration.tt.addAnchor(value, node); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckId * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckLang implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if ((!attval.hasValue()) && (!attval.is(AttrId.XML_LANG))) { if (configuration.getAccessibilityCheckLevel() == 0) { report.attrError(lexer, node, attval, (short)50); } return; } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckLang * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckLength implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if ((attval.is(AttrId.WIDTH)) && ((node.is(TagId.COL)) || (node.is(TagId.COLGROUP)))) { return; } String p = value; if ((p.length() == 0) || (!Character.isDigit(p.charAt(0)))) { report.attrError(lexer, node, attval, (short)51); } else { for (int j = 1; j < p.length(); j++) { if ((!Character.isDigit(p.charAt(j))) && (p.charAt(j) != '%')) { report.attrError(lexer, node, attval, (short)51); break; } } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckLength * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckName implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (node.isAnchorElement()) { if ((configuration.isXmlOut()) && (!TidyUtils.isValidNMTOKEN(value))) { report.attrError(lexer, node, attval, (short)51); } Node old = configuration.tt.getNodeByAnchor(value); if ((old != null) && (old != node)) { report.attrError(lexer, node, attval, (short)66); } else { configuration.tt.addAnchor(value, node); } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckName * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckNumber implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if ((node.is(TagId.FRAMESET)) && ((attval.is(AttrId.COLS)) || (attval.is(AttrId.ROWS)))) { return; } String p = value; int j = 0; if ((node.is(TagId.FONT)) && (p.length() > 0) && ((p.charAt(0) == '+') || (p.charAt(0) == '-'))) { j++; } for (; j < p.length(); j++) { if (!Character.isDigit(p.charAt(j))) { report.attrError(lexer, node, attval, (short)51); break; } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckNumber * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckScope implements AttrCheck { private static final String[] VALID_VALUES = { "row", "rowgroup", "col", "colgroup" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckScope * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckScript implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) {} } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckScript * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckScroll implements AttrCheck { private static final String[] VALID_VALUES = { "no", "auto", "yes" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckScroll * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckShape implements AttrCheck { private static final String[] VALID_VALUES = { "rect", "default", "circle", "poly" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckShape * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckTarget implements AttrCheck { private static final String[] VALID_VALUES = { "_blank", "_self", "_parent", "_top" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } String value = value; if ((value.length() > 0) && (Character.isLetter(value.charAt(0)))) { return; } if (!attval.valueIsAmong(VALID_VALUES)) { report.attrError(lexer, node, attval, (short)51); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckTarget * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckTextDir implements AttrCheck { private static final String[] VALID_VALUES = { "rtl", "ltr" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckTextDir * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckType implements AttrCheck { private static final String[] valuesINPUT = { "text", "password", "checkbox", "radio", "submit", "reset", "file", "hidden", "image", "button" }; private static final String[] valuesBUTTON = { "button", "submit", "reset" }; private static final String[] valuesUL = { "disc", "square", "circle" }; private static final String[] valuesOL = { "1", "a", "i" }; public void check(Lexer lexer, Node node, AttVal attval) { if (node.is(TagId.INPUT)) { AttrCheckImpl.access$000(lexer, node, attval, valuesINPUT); } else if (node.is(TagId.BUTTON)) { AttrCheckImpl.access$000(lexer, node, attval, valuesBUTTON); } else if (node.is(TagId.UL)) { AttrCheckImpl.access$000(lexer, node, attval, valuesUL); } else if (node.is(TagId.OL)) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (!attval.valueIsAmong(valuesOL)) { report.attrError(lexer, node, attval, (short)51); } } else if (node.is(TagId.LI)) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (attval.valueIsAmong(valuesUL)) { attval.checkLowerCaseAttrValue(lexer, node); } else if (!attval.valueIsAmong(valuesOL)) { report.attrError(lexer, node, attval, (short)51); } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckType * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckUrl implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { int escapeCount = 0; boolean backslashFound = false; if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } String p = value; boolean isJavascript = value.startsWith("javascript:"); for (int i = 0; i < p.length(); i++) { char c = p.charAt(i); if (c == '\\') { backslashFound = true; } else if ((c > '~') || (c <= ' ') || (c == '<') || (c == '>')) { escapeCount++; } } if ((configuration.isFixBackslash()) && (backslashFound)) { value = (p = p.replace('\\', '/')); } if ((configuration.isFixUri()) && (escapeCount > 0)) { StringBuilder dest = new StringBuilder(p.length() + escapeCount * 2); for (int i = 0; i < p.length(); i++) { char c = p.charAt(i); if ((c > '~') || (c <= ' ') || (c == '<') || (c == '>')) { dest.append(String.format("%%%02X", new Object[] { Character.valueOf(c) })); } else { dest.append(c); } } value = dest.toString(); } if (backslashFound) { if ((configuration.isFixBackslash()) && (!isJavascript)) { report.attrError(lexer, node, attval, (short)62); } else { report.attrError(lexer, node, attval, (short)61); } } if (escapeCount > 0) { if (configuration.isFixUri()) { report.attrError(lexer, node, attval, (short)64); } else { report.attrError(lexer, node, attval, (short)63); } Lexer tmp369_368 = lexer;369368badChars = ((short)(369368badChars | 0x51)); } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckUrl * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckValign implements AttrCheck { private static final String[] VALID_VALUES = { "top", "middle", "bottom", "baseline" }; private static final String[] VALID_VALUES_IMG = { "left", "right" }; private static final String[] VALID_VALUES_PROPRIETARY = { "texttop", "absmiddle", "absbottom", "textbottom" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } attval.checkLowerCaseAttrValue(lexer, node); if (!attval.valueIsAmong(VALID_VALUES)) { if (attval.valueIsAmong(VALID_VALUES_IMG)) { if ((tag == null) || ((tag.model & 0x10000) == 0)) { report.attrError(lexer, node, attval, (short)51); } } else if (attval.valueIsAmong(VALID_VALUES_PROPRIETARY)) { lexer.constrainVersion(57344); report.attrError(lexer, node, attval, (short)54); } else { report.attrError(lexer, node, attval, (short)51); } } } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckValign * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; public class AttrCheckImpl$CheckVType implements AttrCheck { private static final String[] VALID_VALUES = { "data", "object", "ref" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.access$000(lexer, node, attval, VALID_VALUES); } } /* Location: * Qualified Name: org.w3c.tidy.AttrCheckImpl.CheckVType * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.w3c.tidy; import java.util.HashMap; import java.util.Map; public final class AttrCheckImpl { public static final AttrCheck PCDATA = null; public static final AttrCheck CHARSET = null; public static final AttrCheck TYPE = new CheckType(); public static final AttrCheck XTYPE = null; public static final AttrCheck CHARACTER = null; public static final AttrCheck URLS = null; public static final AttrCheck URL = new CheckUrl(); public static final AttrCheck SCRIPT = new CheckScript(); public static final AttrCheck ALIGN = new CheckAlign(); public static final AttrCheck VALIGN = new CheckValign(); public static final AttrCheck COLOR = new CheckColor(); public static final AttrCheck CLEAR = new CheckClear(); public static final AttrCheck BORDER = new CheckBool(); public static final AttrCheck LANG = new CheckLang(); public static final AttrCheck BOOL = new CheckBool(); public static final AttrCheck COLS = null; public static final AttrCheck NUMBER = new CheckNumber(); public static final AttrCheck LENGTH = new CheckLength(); public static final AttrCheck COORDS = null; public static final AttrCheck DATE = null; public static final AttrCheck TEXTDIR = new CheckTextDir(); public static final AttrCheck IDREFS = null; public static final AttrCheck IDREF = null; public static final AttrCheck IDDEF = new CheckId(); public static final AttrCheck NAME = new CheckName(); public static final AttrCheck TFRAME = null; public static final AttrCheck FBORDER = null; public static final AttrCheck MEDIA = null; public static final AttrCheck FSUBMIT = new CheckFsubmit(); public static final AttrCheck LINKTYPES = null; public static final AttrCheck TRULES = null; public static final AttrCheck SCOPE = new CheckScope(); public static final AttrCheck SHAPE = new CheckShape(); public static final AttrCheck SCROLL = new CheckScroll(); public static final AttrCheck TARGET = new CheckTarget(); public static final AttrCheck VTYPE = new CheckVType(); public static final AttrCheck ACTION = new CheckAction(); public static class CheckUrl implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { int escapeCount = 0; boolean backslashFound = false; if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } String p = value; boolean isJavascript = value.startsWith("javascript:"); for (int i = 0; i < p.length(); i++) { char c = p.charAt(i); if (c == '\\') { backslashFound = true; } else if ((c > '~') || (c <= ' ') || (c == '<') || (c == '>')) { escapeCount++; } } if ((configuration.isFixBackslash()) && (backslashFound)) { value = (p = p.replace('\\', '/')); } if ((configuration.isFixUri()) && (escapeCount > 0)) { StringBuilder dest = new StringBuilder(p.length() + escapeCount * 2); for (int i = 0; i < p.length(); i++) { char c = p.charAt(i); if ((c > '~') || (c <= ' ') || (c == '<') || (c == '>')) { dest.append(String.format("%%%02X", new Object[] { Character.valueOf(c) })); } else { dest.append(c); } } value = dest.toString(); } if (backslashFound) { if ((configuration.isFixBackslash()) && (!isJavascript)) { report.attrError(lexer, node, attval, (short)62); } else { report.attrError(lexer, node, attval, (short)61); } } if (escapeCount > 0) { if (configuration.isFixUri()) { report.attrError(lexer, node, attval, (short)64); } else { report.attrError(lexer, node, attval, (short)63); } Lexer tmp369_368 = lexer;369368badChars = ((short)(369368badChars | 0x51)); } } } public static class CheckAction implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (attval.hasValue()) { AttrCheckImpl.URL.check(lexer, node, attval); } } } private static void checkAttrValidity(Lexer lexer, Node node, AttVal attval, String[] list) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } attval.checkLowerCaseAttrValue(lexer, node); if (!attval.valueIsAmong(list)) { report.attrError(lexer, node, attval, (short)51); } } public static class CheckScript implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) {} } public static class CheckName implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (node.isAnchorElement()) { if ((configuration.isXmlOut()) && (!TidyUtils.isValidNMTOKEN(value))) { report.attrError(lexer, node, attval, (short)51); } Node old = configuration.tt.getNodeByAnchor(value); if ((old != null) && (old != node)) { report.attrError(lexer, node, attval, (short)66); } else { configuration.tt.addAnchor(value, node); } } } } public static class CheckId implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if (!TidyUtils.isValidHTMLID(value)) { if ((isvoyager) && (TidyUtils.isValidXMLID(value))) { report.attrError(lexer, node, attval, (short)71); } else { report.attrError(lexer, node, attval, (short)51); } } Node old = configuration.tt.getNodeByAnchor(value); if ((old != null) && (old != node)) { report.attrError(lexer, node, attval, (short)66); } else { configuration.tt.addAnchor(value, node); } } } public static class CheckBool implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { return; } attval.checkLowerCaseAttrValue(lexer, node); } } public static class CheckAlign implements AttrCheck { private static final String[] VALID_VALUES = { "left", "right", "center", "justify" }; public void check(Lexer lexer, Node node, AttVal attval) { if ((tag != null) && ((tag.model & 0x10000) != 0)) { AttrCheckImpl.VALIGN.check(lexer, node, attval); return; } if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } attval.checkLowerCaseAttrValue(lexer, node); if (node.is(TagId.CAPTION)) { return; } if (!attval.valueIsAmong(VALID_VALUES)) { if ((!attval.valueIs("char")) || (!node.hasCM(640))) { report.attrError(lexer, node, attval, (short)51); } } } } public static class CheckValign implements AttrCheck { private static final String[] VALID_VALUES = { "top", "middle", "bottom", "baseline" }; private static final String[] VALID_VALUES_IMG = { "left", "right" }; private static final String[] VALID_VALUES_PROPRIETARY = { "texttop", "absmiddle", "absbottom", "textbottom" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } attval.checkLowerCaseAttrValue(lexer, node); if (!attval.valueIsAmong(VALID_VALUES)) { if (attval.valueIsAmong(VALID_VALUES_IMG)) { if ((tag == null) || ((tag.model & 0x10000) == 0)) { report.attrError(lexer, node, attval, (short)51); } } else if (attval.valueIsAmong(VALID_VALUES_PROPRIETARY)) { lexer.constrainVersion(57344); report.attrError(lexer, node, attval, (short)54); } else { report.attrError(lexer, node, attval, (short)51); } } } } public static class CheckLength implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if ((attval.is(AttrId.WIDTH)) && ((node.is(TagId.COL)) || (node.is(TagId.COLGROUP)))) { return; } String p = value; if ((p.length() == 0) || (!Character.isDigit(p.charAt(0)))) { report.attrError(lexer, node, attval, (short)51); } else { for (int j = 1; j < p.length(); j++) { if ((!Character.isDigit(p.charAt(j))) && (p.charAt(j) != '%')) { report.attrError(lexer, node, attval, (short)51); break; } } } } } public static class CheckTarget implements AttrCheck { private static final String[] VALID_VALUES = { "_blank", "_self", "_parent", "_top" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } String value = value; if ((value.length() > 0) && (Character.isLetter(value.charAt(0)))) { return; } if (!attval.valueIsAmong(VALID_VALUES)) { report.attrError(lexer, node, attval, (short)51); } } } public static class CheckFsubmit implements AttrCheck { private static final String[] VALID_VALUES = { "get", "post" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckClear implements AttrCheck { private static final String[] VALID_VALUES = { "none", "left", "right", "all" }; public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); if (value == null) { value = "none"; } return; } attval.checkLowerCaseAttrValue(lexer, node); if (!attval.valueIsAmong(VALID_VALUES)) { report.attrError(lexer, node, attval, (short)51); } } } public static class CheckShape implements AttrCheck { private static final String[] VALID_VALUES = { "rect", "default", "circle", "poly" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckScope implements AttrCheck { private static final String[] VALID_VALUES = { "row", "rowgroup", "col", "colgroup" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckNumber implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } if ((node.is(TagId.FRAMESET)) && ((attval.is(AttrId.COLS)) || (attval.is(AttrId.ROWS)))) { return; } String p = value; int j = 0; if ((node.is(TagId.FONT)) && (p.length() > 0) && ((p.charAt(0) == '+') || (p.charAt(0) == '-'))) { j++; } for (; j < p.length(); j++) { if (!Character.isDigit(p.charAt(j))) { report.attrError(lexer, node, attval, (short)51); break; } } } } public static class CheckColor implements AttrCheck { private static final Map<String, String> COLORS_BY_NAME = new HashMap(); private static final Map<String, String> COLORS_BY_VALUE = new HashMap(); private static void addColor(String name, String value) { COLORS_BY_NAME.put(name, value); COLORS_BY_VALUE.put(value, name); } static { addColor("black", "#000000"); addColor("green", "#008000"); addColor("silver", "#C0C0C0"); addColor("lime", "#00FF00"); addColor("gray", "#808080"); addColor("olive", "#808000"); addColor("white", "#FFFFFF"); addColor("yellow", "#FFFF00"); addColor("maroon", "#800000"); addColor("navy", "#000080"); addColor("red", "#FF0000"); addColor("blue", "#0000FF"); addColor("purple", "#800080"); addColor("teal", "#008080"); addColor("fuchsia", "#FF00FF"); addColor("aqua", "#00FFFF"); } private static String getColorCode(String name) { return (String)COLORS_BY_NAME.get(name.toLowerCase()); } private static String getColorName(String code) { return (String)COLORS_BY_VALUE.get(code.toUpperCase()); } private static boolean isValidColorCode(String color) { if (color.length() != 6) { return false; } for (int i = 0; i < 6; i++) { if (!TidyUtils.isxdigit(color.charAt(i))) { return false; } } return true; } public void check(Lexer lexer, Node node, AttVal attval) { if (!attval.hasValue()) { report.attrError(lexer, node, attval, (short)50); return; } boolean valid = false; String given = value; if ((given.length() > 0) && (given.charAt(0) != '#') && ((valid = isValidColorCode(given)))) { String s = '#' + given; report.attrError(lexer, node, attval, (short)73); given = value = s; } if ((!valid) && (given.length() > 0) && (given.charAt(0) == '#')) { valid = isValidColorCode(given.substring(1)); } if ((valid) && (given.charAt(0) == '#') && (configuration.isReplaceColor())) { String newName = getColorName(given); if (newName != null) { given = value = newName; } } if (!valid) { valid = getColorCode(given) != null; } if ((valid) && (given.charAt(0) == '#')) { value = value.toUpperCase(); } else { value = value.toLowerCase(); } if (!valid) { report.attrError(lexer, node, attval, (short)51); } } } public static class CheckVType implements AttrCheck { private static final String[] VALID_VALUES = { "data", "object", "ref" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckScroll implements AttrCheck { private static final String[] VALID_VALUES = { "no", "auto", "yes" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckTextDir implements AttrCheck { private static final String[] VALID_VALUES = { "rtl", "ltr" }; public void check(Lexer lexer, Node node, AttVal attval) { AttrCheckImpl.checkAttrValidity(lexer, node, attval, VALID_VALUES); } } public static class CheckLang implements AttrCheck { public void check(Lexer lexer, Node node, AttVal attval) { if ((!attval.hasValue()) && (!attval.is(AttrId.XML_LANG))) { if (configuration.getAccessibilityCheckLevel() == 0) { report.attrError(lexer, node, attval, (short)50); } return; } } } public static class CheckType implements AttrCheck { private static final String[] valuesINPUT = { "text", "password", "checkbox", "radio", "submit", "reset", "file", "hidden", "image", "button" }; private static final String[] valuesBUTTON = { "button", "submit", "reset" }; private static final String[] valuesUL = { "disc", "square", "circle" }; private static final String[] valuesOL = { "1", "a", "i" }; Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|