zack
7 years ago
93 changed files with 49743 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,99 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleSheet; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* @author koch |
||||
* @author rbri |
||||
*/ |
||||
public abstract class AbstractCSSRuleImpl extends CSSOMObjectImpl implements CSSFormatable { |
||||
|
||||
private static final long serialVersionUID = 7829784704712797815L; |
||||
|
||||
private CSSStyleSheetImpl parentStyleSheet_; |
||||
private CSSRule parentRule_; |
||||
|
||||
protected CSSStyleSheetImpl getParentStyleSheetImpl() { |
||||
return parentStyleSheet_; |
||||
} |
||||
|
||||
public void setParentStyleSheet(final CSSStyleSheetImpl parentStyleSheet) { |
||||
parentStyleSheet_ = parentStyleSheet; |
||||
} |
||||
|
||||
public void setParentRule(final CSSRule parentRule) { |
||||
parentRule_ = parentRule; |
||||
} |
||||
|
||||
public AbstractCSSRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final CSSRule parentRule) { |
||||
super(); |
||||
parentStyleSheet_ = parentStyleSheet; |
||||
parentRule_ = parentRule; |
||||
} |
||||
|
||||
public AbstractCSSRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public CSSStyleSheet getParentStyleSheet() { |
||||
return parentStyleSheet_; |
||||
} |
||||
|
||||
public CSSRule getParentRule() { |
||||
return parentRule_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public abstract String getCssText(CSSFormat format); |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSRule)) { |
||||
return false; |
||||
} |
||||
return super.equals(obj); |
||||
// don't use parentRule and parentStyleSheet in equals()
|
||||
// recursive loop -> stack overflow!
|
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
final int hash = super.hashCode(); |
||||
// don't use parentRule and parentStyleSheet in hashCode()
|
||||
// recursive loop -> stack overflow!
|
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,145 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSCharsetRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSCharsetRule}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSCharsetRuleImpl extends AbstractCSSRuleImpl implements CSSCharsetRule { |
||||
|
||||
private static final long serialVersionUID = -2472209213089007127L; |
||||
|
||||
private String encoding_; |
||||
|
||||
public CSSCharsetRuleImpl( |
||||
final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, |
||||
final String encoding) { |
||||
super(parentStyleSheet, parentRule); |
||||
encoding_ = encoding; |
||||
} |
||||
|
||||
public CSSCharsetRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return CHARSET_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
sb.append("@charset \""); |
||||
|
||||
final String enc = getEncoding(); |
||||
if (null != enc) { |
||||
sb.append(enc); |
||||
} |
||||
sb.append("\";"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be a charset rule
|
||||
if (r.getType() == CSSRule.CHARSET_RULE) { |
||||
encoding_ = ((CSSCharsetRuleImpl) r).encoding_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_CHARSET_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public String getEncoding() { |
||||
return encoding_; |
||||
} |
||||
|
||||
public void setEncoding(final String encoding) throws DOMException { |
||||
encoding_ = encoding; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSCharsetRule)) { |
||||
return false; |
||||
} |
||||
final CSSCharsetRule ccr = (CSSCharsetRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getEncoding(), ccr.getEncoding()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, encoding_); |
||||
return hash; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSFontFaceRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleDeclaration; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSFontFaceRule}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSFontFaceRuleImpl extends AbstractCSSRuleImpl implements CSSFontFaceRule { |
||||
|
||||
private static final long serialVersionUID = -3604191834588759088L; |
||||
|
||||
private CSSStyleDeclarationImpl style_; |
||||
|
||||
public CSSFontFaceRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final CSSRule parentRule) { |
||||
super(parentStyleSheet, parentRule); |
||||
} |
||||
|
||||
public CSSFontFaceRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return FONT_FACE_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append("@font-face {"); |
||||
|
||||
final CSSStyleDeclaration style = getStyle(); |
||||
if (null != style) { |
||||
sb.append(style.getCssText()); |
||||
} |
||||
sb.append("}"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be a font face rule
|
||||
if (r.getType() == CSSRule.FONT_FACE_RULE) { |
||||
style_ = ((CSSFontFaceRuleImpl) r).style_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_FONT_FACE_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public CSSStyleDeclaration getStyle() { |
||||
return style_; |
||||
} |
||||
|
||||
public void setStyle(final CSSStyleDeclarationImpl style) { |
||||
style_ = style; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSFontFaceRule)) { |
||||
return false; |
||||
} |
||||
final CSSFontFaceRule cffr = (CSSFontFaceRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getStyle(), cffr.getStyle()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, style_); |
||||
return hash; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,171 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSImportRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleSheet; |
||||
import org.w3c.dom.stylesheets.MediaList; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSImportRule}. |
||||
* |
||||
* TODO: Implement getStyleSheet() |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSImportRuleImpl extends AbstractCSSRuleImpl implements CSSImportRule { |
||||
|
||||
private static final long serialVersionUID = 7807829682009179339L; |
||||
|
||||
private String href_; |
||||
private MediaList media_; |
||||
|
||||
public void setHref(final String href) { |
||||
href_ = href; |
||||
} |
||||
|
||||
public void setMedia(final MediaList media) { |
||||
media_ = media; |
||||
} |
||||
|
||||
public CSSImportRuleImpl( |
||||
final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, |
||||
final String href, |
||||
final MediaList media) { |
||||
super(parentStyleSheet, parentRule); |
||||
href_ = href; |
||||
media_ = media; |
||||
} |
||||
|
||||
public CSSImportRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return IMPORT_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append("@import"); |
||||
|
||||
final String href = getHref(); |
||||
if (null != href) { |
||||
sb.append(" url(").append(href).append(")"); |
||||
} |
||||
|
||||
final MediaList ml = getMedia(); |
||||
if (null != ml && ml.getLength() > 0) { |
||||
sb.append(" ").append(((MediaListImpl) getMedia()).getMediaText(format)); |
||||
} |
||||
sb.append(";"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be an import rule
|
||||
if (r.getType() == CSSRule.IMPORT_RULE) { |
||||
href_ = ((CSSImportRuleImpl) r).href_; |
||||
media_ = ((CSSImportRuleImpl) r).media_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_IMPORT_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public String getHref() { |
||||
return href_; |
||||
} |
||||
|
||||
public MediaList getMedia() { |
||||
return media_; |
||||
} |
||||
|
||||
public CSSStyleSheet getStyleSheet() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSImportRule)) { |
||||
return false; |
||||
} |
||||
final CSSImportRule cir = (CSSImportRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getHref(), cir.getHref()) |
||||
&& LangUtils.equals(getMedia(), cir.getMedia()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, href_); |
||||
hash = LangUtils.hashCode(hash, media_); |
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,250 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.ObjectInputStream; |
||||
import java.io.ObjectOutputStream; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import com.fr.third.steadystate.css.util.ThrowCssExceptionErrorHandler; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSMediaRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSRuleList; |
||||
import org.w3c.dom.stylesheets.MediaList; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSMediaRule}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSMediaRuleImpl extends AbstractCSSRuleImpl implements CSSMediaRule { |
||||
|
||||
private static final long serialVersionUID = 6603734096445214651L; |
||||
|
||||
private MediaList media_; |
||||
private CSSRuleList cssRules_; |
||||
|
||||
public void setMedia(final MediaList media) { |
||||
media_ = media; |
||||
} |
||||
|
||||
public void setCssRules(final CSSRuleList cssRules) { |
||||
cssRules_ = cssRules; |
||||
} |
||||
|
||||
public CSSMediaRuleImpl( |
||||
final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, |
||||
final MediaList media) { |
||||
super(parentStyleSheet, parentRule); |
||||
media_ = media; |
||||
} |
||||
|
||||
public CSSMediaRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return MEDIA_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder("@media "); |
||||
|
||||
sb.append(((MediaListImpl) getMedia()).getMediaText(format)); |
||||
sb.append(" {"); |
||||
for (int i = 0; i < getCssRules().getLength(); i++) { |
||||
final CSSRule rule = getCssRules().item(i); |
||||
sb.append(rule.getCssText()).append(" "); |
||||
} |
||||
sb.append("}"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be a media rule
|
||||
if (r.getType() == CSSRule.MEDIA_RULE) { |
||||
media_ = ((CSSMediaRuleImpl) r).media_; |
||||
cssRules_ = ((CSSMediaRuleImpl) r).cssRules_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_MEDIA_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public MediaList getMedia() { |
||||
return media_; |
||||
} |
||||
|
||||
public CSSRuleList getCssRules() { |
||||
if (cssRules_ == null) { |
||||
cssRules_ = new CSSRuleListImpl(); |
||||
} |
||||
return cssRules_; |
||||
} |
||||
|
||||
public int insertRule(final String rule, final int index) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(rule)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
parser.setParentStyleSheet(parentStyleSheet); |
||||
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE); |
||||
// parser._parentRule is never read
|
||||
// parser.setParentRule(_parentRule);
|
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// Insert the rule into the list of rules
|
||||
((CSSRuleListImpl) getCssRules()).insert(r, index); |
||||
|
||||
} |
||||
catch (final IndexOutOfBoundsException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INDEX_SIZE_ERR, |
||||
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, |
||||
e.getMessage()); |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
return index; |
||||
} |
||||
|
||||
public void deleteRule(final int index) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
try { |
||||
((CSSRuleListImpl) getCssRules()).delete(index); |
||||
} |
||||
catch (final IndexOutOfBoundsException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INDEX_SIZE_ERR, |
||||
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public void setRuleList(final CSSRuleListImpl rules) { |
||||
cssRules_ = rules; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSMediaRule)) { |
||||
return false; |
||||
} |
||||
final CSSMediaRule cmr = (CSSMediaRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getMedia(), cmr.getMedia()) |
||||
&& LangUtils.equals(getCssRules(), cmr.getCssRules()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, media_); |
||||
hash = LangUtils.hashCode(hash, cssRules_); |
||||
return hash; |
||||
} |
||||
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException { |
||||
out.writeObject(cssRules_); |
||||
out.writeObject(media_); |
||||
} |
||||
|
||||
private void readObject(final ObjectInputStream in) |
||||
throws IOException, ClassNotFoundException { |
||||
|
||||
cssRules_ = (CSSRuleList) in.readObject(); |
||||
if (cssRules_ != null) { |
||||
for (int i = 0; i < cssRules_.getLength(); i++) { |
||||
final CSSRule cssRule = cssRules_.item(i); |
||||
if (cssRule instanceof AbstractCSSRuleImpl) { |
||||
((AbstractCSSRuleImpl) cssRule).setParentRule(this); |
||||
((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(getParentStyleSheetImpl()); |
||||
} |
||||
} |
||||
} |
||||
media_ = (MediaList) in.readObject(); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
/** |
||||
* @author koch |
||||
*/ |
||||
public interface CSSOMObject { |
||||
|
||||
Object getUserData(String key); |
||||
|
||||
Object setUserData(String key, Object data); |
||||
} |
@ -0,0 +1,76 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Hashtable; |
||||
import java.util.Map; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSOMObject}. |
||||
* |
||||
* @author koch |
||||
*/ |
||||
public class CSSOMObjectImpl implements CSSOMObject, Serializable { |
||||
|
||||
private static final long serialVersionUID = 0L; |
||||
|
||||
private Map<String, Object> userDataMap_; |
||||
|
||||
public Map<String, Object> getUserDataMap() { |
||||
if (userDataMap_ == null) { |
||||
userDataMap_ = new Hashtable<String, Object>(); |
||||
} |
||||
return userDataMap_; |
||||
} |
||||
|
||||
public void setUserDataMap(final Map<String, Object> userDataMap) { |
||||
userDataMap_ = userDataMap; |
||||
} |
||||
|
||||
public CSSOMObjectImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public Object getUserData(final String key) { |
||||
return getUserDataMap().get(key); |
||||
} |
||||
|
||||
public Object setUserData(final String key, final Object data) { |
||||
return getUserDataMap().put(key, data); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSOMObjectImpl)) { |
||||
return false; |
||||
} |
||||
final CSSOMObjectImpl coi = (CSSOMObjectImpl) obj; |
||||
return LangUtils.equals(userDataMap_, coi.userDataMap_); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = LangUtils.HASH_SEED; |
||||
hash = LangUtils.hashCode(hash, userDataMap_); |
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,172 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSPageRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleDeclaration; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSPageRule}. |
||||
* |
||||
* TODO: Implement setSelectorText() |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSPageRuleImpl extends AbstractCSSRuleImpl implements CSSPageRule { |
||||
|
||||
private static final long serialVersionUID = -6007519872104320812L; |
||||
|
||||
private String pseudoPage_; |
||||
private CSSStyleDeclaration style_; |
||||
|
||||
public CSSPageRuleImpl( |
||||
final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, |
||||
final String pseudoPage) { |
||||
super(parentStyleSheet, parentRule); |
||||
pseudoPage_ = pseudoPage; |
||||
} |
||||
|
||||
public CSSPageRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return PAGE_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
final String sel = getSelectorText(); |
||||
sb.append("@page ").append(sel); |
||||
|
||||
if (sel.length() > 0) { |
||||
sb.append(" "); |
||||
} |
||||
sb.append("{"); |
||||
|
||||
final CSSStyleDeclaration style = getStyle(); |
||||
if (null != style) { |
||||
sb.append(style.getCssText()); |
||||
} |
||||
sb.append("}"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be a page rule
|
||||
if (r.getType() == CSSRule.PAGE_RULE) { |
||||
pseudoPage_ = ((CSSPageRuleImpl) r).pseudoPage_; |
||||
style_ = ((CSSPageRuleImpl) r).style_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_PAGE_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public String getSelectorText() { |
||||
if (null == pseudoPage_) { |
||||
return ""; |
||||
} |
||||
return pseudoPage_; |
||||
} |
||||
|
||||
public void setSelectorText(final String selectorText) throws DOMException { |
||||
} |
||||
|
||||
public CSSStyleDeclaration getStyle() { |
||||
return style_; |
||||
} |
||||
|
||||
public void setPseudoPage(final String pseudoPage) { |
||||
pseudoPage_ = pseudoPage; |
||||
} |
||||
|
||||
public void setStyle(final CSSStyleDeclarationImpl style) { |
||||
style_ = style; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSPageRule)) { |
||||
return false; |
||||
} |
||||
final CSSPageRule cpr = (CSSPageRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getSelectorText(), cpr.getSelectorText()) |
||||
&& LangUtils.equals(getStyle(), cpr.getStyle()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, pseudoPage_); |
||||
hash = LangUtils.hashCode(hash, style_); |
||||
return hash; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSRuleList; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSRuleList}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSRuleListImpl implements CSSRuleList, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -1269068897476453290L; |
||||
|
||||
private List<CSSRule> rules_; |
||||
|
||||
public List<CSSRule> getRules() { |
||||
if (rules_ == null) { |
||||
rules_ = new ArrayList<CSSRule>(); |
||||
} |
||||
return rules_; |
||||
} |
||||
|
||||
public void setRules(final List<CSSRule> rules) { |
||||
rules_ = rules; |
||||
} |
||||
|
||||
public CSSRuleListImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public int getLength() { |
||||
return getRules().size(); |
||||
} |
||||
|
||||
public CSSRule item(final int index) { |
||||
if (index < 0 || null == rules_ || index >= rules_.size()) { |
||||
return null; |
||||
} |
||||
return rules_.get(index); |
||||
} |
||||
|
||||
public void add(final CSSRule rule) { |
||||
getRules().add(rule); |
||||
} |
||||
|
||||
public void insert(final CSSRule rule, final int index) { |
||||
getRules().add(index, rule); |
||||
} |
||||
|
||||
public void delete(final int index) { |
||||
getRules().remove(index); |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < getLength(); i++) { |
||||
if (i > 0) { |
||||
sb.append("\r\n"); |
||||
} |
||||
|
||||
final CSSRule rule = item(i); |
||||
sb.append(((CSSFormatable) rule).getCssText(format)); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSRuleList)) { |
||||
return false; |
||||
} |
||||
final CSSRuleList crl = (CSSRuleList) obj; |
||||
return equalsRules(crl); |
||||
} |
||||
|
||||
private boolean equalsRules(final CSSRuleList crl) { |
||||
if ((crl == null) || (getLength() != crl.getLength())) { |
||||
return false; |
||||
} |
||||
for (int i = 0; i < getLength(); i++) { |
||||
final CSSRule cssRule1 = item(i); |
||||
final CSSRule cssRule2 = crl.item(i); |
||||
if (!LangUtils.equals(cssRule1, cssRule2)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = LangUtils.HASH_SEED; |
||||
hash = LangUtils.hashCode(hash, rules_); |
||||
return hash; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,196 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.SelectorList; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleDeclaration; |
||||
import org.w3c.dom.css.CSSStyleRule; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSStyleRule}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSStyleRuleImpl extends AbstractCSSRuleImpl implements CSSStyleRule { |
||||
|
||||
private static final long serialVersionUID = -697009251364657426L; |
||||
|
||||
private SelectorList selectors_; |
||||
private CSSStyleDeclaration style_; |
||||
|
||||
public SelectorList getSelectors() { |
||||
return selectors_; |
||||
} |
||||
|
||||
public void setSelectors(final SelectorList selectors) { |
||||
selectors_ = selectors; |
||||
} |
||||
|
||||
public CSSStyleRuleImpl(final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, final SelectorList selectors) { |
||||
super(parentStyleSheet, parentRule); |
||||
selectors_ = selectors; |
||||
} |
||||
|
||||
public CSSStyleRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return STYLE_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
final CSSStyleDeclaration style = getStyle(); |
||||
if (null == style) { |
||||
return ""; |
||||
} |
||||
|
||||
final String selectorText = ((CSSFormatable) selectors_).getCssText(format); |
||||
final String styleText = ((CSSFormatable) style).getCssText(format); |
||||
|
||||
if (null == styleText || styleText.length() == 0) { |
||||
return selectorText + " { }"; |
||||
} |
||||
|
||||
if (format != null && format.getPropertiesInSeparateLines()) { |
||||
return selectorText + " {" + styleText + "}"; |
||||
} |
||||
|
||||
return selectorText + " { " + styleText + " }"; |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be a style rule
|
||||
if (r.getType() == CSSRule.STYLE_RULE) { |
||||
selectors_ = ((CSSStyleRuleImpl) r).selectors_; |
||||
style_ = ((CSSStyleRuleImpl) r).style_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_STYLE_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public String getSelectorText() { |
||||
return selectors_.toString(); |
||||
} |
||||
|
||||
public void setSelectorText(final String selectorText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(selectorText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
selectors_ = parser.parseSelectors(is); |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public CSSStyleDeclaration getStyle() { |
||||
return style_; |
||||
} |
||||
|
||||
public void setStyle(final CSSStyleDeclaration style) { |
||||
style_ = style; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSStyleRule)) { |
||||
return false; |
||||
} |
||||
final CSSStyleRule csr = (CSSStyleRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getSelectorText(), csr.getSelectorText()) |
||||
&& LangUtils.equals(getStyle(), csr.getStyle()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, selectors_); |
||||
hash = LangUtils.hashCode(hash, style_); |
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,411 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.ObjectInputStream; |
||||
import java.io.ObjectOutputStream; |
||||
import java.io.Serializable; |
||||
import java.io.StringReader; |
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import com.fr.third.steadystate.css.util.ThrowCssExceptionErrorHandler; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.Node; |
||||
import org.w3c.dom.css.CSSImportRule; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSRuleList; |
||||
import org.w3c.dom.css.CSSStyleSheet; |
||||
import org.w3c.dom.stylesheets.MediaList; |
||||
import org.w3c.dom.stylesheets.StyleSheet; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSStyleSheet}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSStyleSheetImpl implements CSSStyleSheet, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -2300541300646796363L; |
||||
|
||||
private boolean disabled_; |
||||
private Node ownerNode_; |
||||
private StyleSheet parentStyleSheet_; |
||||
private String href_; |
||||
private String title_; |
||||
private MediaList media_; |
||||
private CSSRule ownerRule_; |
||||
private boolean readOnly_; |
||||
private CSSRuleList cssRules_; |
||||
private String baseUri_; |
||||
|
||||
public void setMedia(final MediaList media) { |
||||
media_ = media; |
||||
} |
||||
|
||||
private String getBaseUri() { |
||||
return baseUri_; |
||||
} |
||||
|
||||
public void setBaseUri(final String baseUri) { |
||||
baseUri_ = baseUri; |
||||
} |
||||
|
||||
public CSSStyleSheetImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public String getType() { |
||||
return "text/css"; |
||||
} |
||||
|
||||
public boolean getDisabled() { |
||||
return disabled_; |
||||
} |
||||
|
||||
/** |
||||
* We will need to respond more fully if a stylesheet is disabled, probably |
||||
* by generating an event for the main application. |
||||
*/ |
||||
public void setDisabled(final boolean disabled) { |
||||
disabled_ = disabled; |
||||
} |
||||
|
||||
public Node getOwnerNode() { |
||||
return ownerNode_; |
||||
} |
||||
|
||||
public StyleSheet getParentStyleSheet() { |
||||
return parentStyleSheet_; |
||||
} |
||||
|
||||
public String getHref() { |
||||
return href_; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title_; |
||||
} |
||||
|
||||
public MediaList getMedia() { |
||||
return media_; |
||||
} |
||||
|
||||
public CSSRule getOwnerRule() { |
||||
return ownerRule_; |
||||
} |
||||
|
||||
public CSSRuleList getCssRules() { |
||||
if (cssRules_ == null) { |
||||
cssRules_ = new CSSRuleListImpl(); |
||||
} |
||||
return cssRules_; |
||||
} |
||||
|
||||
public int insertRule(final String rule, final int index) throws DOMException { |
||||
if (readOnly_) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(rule)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
parser.setParentStyleSheet(this); |
||||
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
if (r == null) { |
||||
// this should neven happen because of the ThrowCssExceptionErrorHandler
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
"Parsing rule '" + rule + "' failed."); |
||||
} |
||||
|
||||
if (getCssRules().getLength() > 0) { |
||||
// We need to check that this type of rule can legally go into
|
||||
// the requested position.
|
||||
int msg = -1; |
||||
if (r.getType() == CSSRule.CHARSET_RULE) { |
||||
|
||||
// Index must be 0, and there can be only one charset rule
|
||||
if (index != 0) { |
||||
msg = DOMExceptionImpl.CHARSET_NOT_FIRST; |
||||
} |
||||
else if (getCssRules().item(0).getType() == CSSRule.CHARSET_RULE) { |
||||
msg = DOMExceptionImpl.CHARSET_NOT_UNIQUE; |
||||
} |
||||
} |
||||
else if (r.getType() == CSSRule.IMPORT_RULE) { |
||||
// Import rules must preceed all other rules (except
|
||||
// charset rules)
|
||||
if (index <= getCssRules().getLength()) { |
||||
for (int i = 0; i < index; i++) { |
||||
final int rt = getCssRules().item(i).getType(); |
||||
if ((rt != CSSRule.CHARSET_RULE) && (rt != CSSRule.IMPORT_RULE)) { |
||||
msg = DOMExceptionImpl.IMPORT_NOT_FIRST; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else { |
||||
if (index <= getCssRules().getLength()) { |
||||
for (int i = index; i < getCssRules().getLength(); i++) { |
||||
final int rt = getCssRules().item(i).getType(); |
||||
if ((rt == CSSRule.CHARSET_RULE) || (rt == CSSRule.IMPORT_RULE)) { |
||||
msg = DOMExceptionImpl.INSERT_BEFORE_IMPORT; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (msg > -1) { |
||||
throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, msg); |
||||
} |
||||
} |
||||
|
||||
// Insert the rule into the list of rules
|
||||
((CSSRuleListImpl) getCssRules()).insert(r, index); |
||||
|
||||
} |
||||
catch (final IndexOutOfBoundsException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INDEX_SIZE_ERR, |
||||
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, |
||||
e.getMessage()); |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
return index; |
||||
} |
||||
|
||||
public void deleteRule(final int index) throws DOMException { |
||||
if (readOnly_) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
((CSSRuleListImpl) getCssRules()).delete(index); |
||||
} |
||||
catch (final IndexOutOfBoundsException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INDEX_SIZE_ERR, |
||||
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public boolean isReadOnly() { |
||||
return readOnly_; |
||||
} |
||||
|
||||
public void setReadOnly(final boolean b) { |
||||
readOnly_ = b; |
||||
} |
||||
|
||||
public void setOwnerNode(final Node ownerNode) { |
||||
ownerNode_ = ownerNode; |
||||
} |
||||
|
||||
public void setParentStyleSheet(final StyleSheet parentStyleSheet) { |
||||
parentStyleSheet_ = parentStyleSheet; |
||||
} |
||||
|
||||
public void setHref(final String href) { |
||||
href_ = href; |
||||
} |
||||
|
||||
public void setTitle(final String title) { |
||||
title_ = title; |
||||
} |
||||
|
||||
public void setMediaText(final String mediaText) { |
||||
final InputSource source = new InputSource(new StringReader(mediaText)); |
||||
try { |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final SACMediaList sml = parser.parseMedia(source); |
||||
media_ = new MediaListImpl(sml); |
||||
} |
||||
catch (final IOException e) { |
||||
// TODO handle exception
|
||||
} |
||||
} |
||||
|
||||
public void setOwnerRule(final CSSRule ownerRule) { |
||||
ownerRule_ = ownerRule; |
||||
} |
||||
|
||||
public void setCssRules(final CSSRuleList rules) { |
||||
cssRules_ = rules; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final CSSRuleList rules = getCssRules(); |
||||
if (rules instanceof CSSFormatable) { |
||||
return ((CSSRuleListImpl) rules).getCssText(format); |
||||
} |
||||
return getCssRules().toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSStyleSheet)) { |
||||
return false; |
||||
} |
||||
final CSSStyleSheet css = (CSSStyleSheet) obj; |
||||
boolean eq = LangUtils.equals(getCssRules(), css.getCssRules()); |
||||
eq = eq && (getDisabled() == css.getDisabled()); |
||||
eq = eq && LangUtils.equals(getHref(), css.getHref()); |
||||
eq = eq && LangUtils.equals(getMedia(), css.getMedia()); |
||||
// TODO implement some reasonful equals method for ownerNode
|
||||
// eq = eq && Utils.equals(getOwnerNode(), css.getOwnerNode());
|
||||
// don't use ownerNode and parentStyleSheet in equals()
|
||||
// recursive loop -> stack overflow!
|
||||
eq = eq && LangUtils.equals(getTitle(), css.getTitle()); |
||||
return eq; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = LangUtils.HASH_SEED; |
||||
hash = LangUtils.hashCode(hash, baseUri_); |
||||
hash = LangUtils.hashCode(hash, cssRules_); |
||||
hash = LangUtils.hashCode(hash, disabled_); |
||||
hash = LangUtils.hashCode(hash, href_); |
||||
hash = LangUtils.hashCode(hash, media_); |
||||
hash = LangUtils.hashCode(hash, ownerNode_); |
||||
// don't use ownerNode and parentStyleSheet in hashCode()
|
||||
// recursive loop -> stack overflow!
|
||||
hash = LangUtils.hashCode(hash, readOnly_); |
||||
hash = LangUtils.hashCode(hash, title_); |
||||
return hash; |
||||
} |
||||
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException { |
||||
out.writeObject(baseUri_); |
||||
out.writeObject(cssRules_); |
||||
out.writeBoolean(disabled_); |
||||
out.writeObject(href_); |
||||
out.writeObject(media_); |
||||
// TODO ownerNode may not be serializable!
|
||||
// out.writeObject(ownerNode);
|
||||
out.writeBoolean(readOnly_); |
||||
out.writeObject(title_); |
||||
} |
||||
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { |
||||
baseUri_ = (String) in.readObject(); |
||||
cssRules_ = (CSSRuleList) in.readObject(); |
||||
if (cssRules_ != null) { |
||||
for (int i = 0; i < cssRules_.getLength(); i++) { |
||||
final CSSRule cssRule = cssRules_.item(i); |
||||
if (cssRule instanceof AbstractCSSRuleImpl) { |
||||
((AbstractCSSRuleImpl) cssRule).setParentStyleSheet(this); |
||||
} |
||||
} |
||||
} |
||||
disabled_ = in.readBoolean(); |
||||
href_ = (String) in.readObject(); |
||||
media_ = (MediaList) in.readObject(); |
||||
// TODO ownerNode may not be serializable!
|
||||
// ownerNode = (Node) in.readObject();
|
||||
readOnly_ = in.readBoolean(); |
||||
title_ = (String) in.readObject(); |
||||
} |
||||
|
||||
/** |
||||
* Imports referenced CSSStyleSheets. |
||||
* |
||||
* @param recursive <code>true</code> if the import should be done |
||||
* recursively, <code>false</code> otherwise |
||||
*/ |
||||
public void importImports(final boolean recursive) throws DOMException { |
||||
for (int i = 0; i < getCssRules().getLength(); i++) { |
||||
final CSSRule cssRule = getCssRules().item(i); |
||||
if (cssRule.getType() == CSSRule.IMPORT_RULE) { |
||||
final CSSImportRule cssImportRule = (CSSImportRule) cssRule; |
||||
try { |
||||
final URI importURI = new URI(getBaseUri()).resolve(cssImportRule.getHref()); |
||||
final CSSStyleSheetImpl importedCSS = (CSSStyleSheetImpl) |
||||
new CSSOMParser().parseStyleSheet(new InputSource( |
||||
importURI.toString()), null, importURI.toString()); |
||||
if (recursive) { |
||||
importedCSS.importImports(recursive); |
||||
} |
||||
final MediaList mediaList = cssImportRule.getMedia(); |
||||
if (mediaList.getLength() == 0) { |
||||
mediaList.appendMedium("all"); |
||||
} |
||||
final CSSMediaRuleImpl cssMediaRule = new CSSMediaRuleImpl(this, null, mediaList); |
||||
cssMediaRule.setRuleList((CSSRuleListImpl) importedCSS.getCssRules()); |
||||
deleteRule(i); |
||||
((CSSRuleListImpl) getCssRules()).insert(cssMediaRule, i); |
||||
} |
||||
catch (final URISyntaxException e) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
// TODO handle exception
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,126 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
import org.w3c.dom.css.CSSStyleSheet; |
||||
|
||||
import org.w3c.dom.stylesheets.StyleSheet; |
||||
import org.w3c.dom.stylesheets.StyleSheetList; |
||||
|
||||
/** |
||||
* Implementation of {@link StyleSheetList}. |
||||
* |
||||
* @author <a href="mailto:waldbaer@users.sourceforge.net">Johannes Koch</a> |
||||
*/ |
||||
public class CSSStyleSheetListImpl implements StyleSheetList { |
||||
private List<CSSStyleSheet> cssStyleSheets_; |
||||
|
||||
public List<CSSStyleSheet> getCSSStyleSheets() { |
||||
if (cssStyleSheets_ == null) { |
||||
cssStyleSheets_ = new ArrayList<CSSStyleSheet>(); |
||||
} |
||||
return cssStyleSheets_; |
||||
} |
||||
|
||||
public void setCSSStyleSheets(final List<CSSStyleSheet> cssStyleSheets) { |
||||
cssStyleSheets_ = cssStyleSheets; |
||||
} |
||||
|
||||
/** |
||||
* Creates a new instance of CSSStyleSheetListImpl |
||||
*/ |
||||
public CSSStyleSheetListImpl() { |
||||
super(); |
||||
} |
||||
|
||||
// start StyleSheetList
|
||||
public int getLength() { |
||||
return getCSSStyleSheets().size(); |
||||
} |
||||
|
||||
public StyleSheet item(final int index) { |
||||
return getCSSStyleSheets().get(index); |
||||
} |
||||
|
||||
/** |
||||
* Adds a CSSStyleSheet. |
||||
* |
||||
* @param cssStyleSheet the CSSStyleSheet |
||||
*/ |
||||
public void add(final CSSStyleSheet cssStyleSheet) { |
||||
getCSSStyleSheets().add(cssStyleSheet); |
||||
} |
||||
// end StyleSheetList
|
||||
|
||||
/** |
||||
* Merges all StyleSheets in this list into one. |
||||
* |
||||
* @return the new (merged) StyleSheet |
||||
*/ |
||||
public StyleSheet merge() { |
||||
final CSSStyleSheetImpl merged = new CSSStyleSheetImpl(); |
||||
final CSSRuleListImpl cssRuleList = new CSSRuleListImpl(); |
||||
final Iterator<CSSStyleSheet> it = getCSSStyleSheets().iterator(); |
||||
while (it.hasNext()) { |
||||
final CSSStyleSheetImpl cssStyleSheet = (CSSStyleSheetImpl) it.next(); |
||||
final CSSMediaRuleImpl cssMediaRule = new CSSMediaRuleImpl(merged, null, cssStyleSheet.getMedia()); |
||||
cssMediaRule.setRuleList((CSSRuleListImpl) cssStyleSheet.getCssRules()); |
||||
cssRuleList.add(cssMediaRule); |
||||
} |
||||
merged.setCssRules(cssRuleList); |
||||
merged.setMediaText("all"); |
||||
return merged; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof StyleSheetList)) { |
||||
return false; |
||||
} |
||||
final StyleSheetList ssl = (StyleSheetList) obj; |
||||
return equalsStyleSheets(ssl); |
||||
} |
||||
|
||||
private boolean equalsStyleSheets(final StyleSheetList ssl) { |
||||
if ((ssl == null) || (getLength() != ssl.getLength())) { |
||||
return false; |
||||
} |
||||
for (int i = 0; i < getLength(); i++) { |
||||
final StyleSheet styleSheet1 = item(i); |
||||
final StyleSheet styleSheet2 = ssl.item(i); |
||||
if (!LangUtils.equals(styleSheet1, styleSheet2)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = LangUtils.HASH_SEED; |
||||
hash = LangUtils.hashCode(hash, cssStyleSheets_); |
||||
return hash; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,140 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
|
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSUnknownRule; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link CSSUnknownRule}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSUnknownRuleImpl extends AbstractCSSRuleImpl implements CSSUnknownRule { |
||||
|
||||
private static final long serialVersionUID = -268104019127675990L; |
||||
|
||||
private String text_; |
||||
|
||||
public String getText() { |
||||
return text_; |
||||
} |
||||
|
||||
public void setText(final String text) { |
||||
text_ = text; |
||||
} |
||||
|
||||
public CSSUnknownRuleImpl( |
||||
final CSSStyleSheetImpl parentStyleSheet, |
||||
final CSSRule parentRule, |
||||
final String text) { |
||||
super(parentStyleSheet, parentRule); |
||||
text_ = text; |
||||
} |
||||
|
||||
public CSSUnknownRuleImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public short getType() { |
||||
return UNKNOWN_RULE; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
if (null == text_) { |
||||
return ""; |
||||
} |
||||
return text_; |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); |
||||
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
||||
DOMExceptionImpl.READ_ONLY_STYLE_SHEET); |
||||
} |
||||
|
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSRule r = parser.parseRule(is); |
||||
|
||||
// The rule must be an unknown rule
|
||||
if (r.getType() == CSSRule.UNKNOWN_RULE) { |
||||
text_ = ((CSSUnknownRuleImpl) r).text_; |
||||
} |
||||
else { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_MODIFICATION_ERR, |
||||
DOMExceptionImpl.EXPECTING_FONT_FACE_RULE); |
||||
} |
||||
} |
||||
catch (final CSSException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSUnknownRule)) { |
||||
return false; |
||||
} |
||||
final CSSUnknownRule cur = (CSSUnknownRule) obj; |
||||
return super.equals(obj) |
||||
&& LangUtils.equals(getCssText(), cur.getCssText()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, text_); |
||||
return hash; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,431 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.StringReader; |
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import com.fr.third.steadystate.css.parser.LexicalUnitImpl; |
||||
import com.fr.third.steadystate.css.userdata.UserDataConstants; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSPrimitiveValue; |
||||
import org.w3c.dom.css.CSSValue; |
||||
import org.w3c.dom.css.CSSValueList; |
||||
import org.w3c.dom.css.Counter; |
||||
import org.w3c.dom.css.RGBColor; |
||||
import org.w3c.dom.css.Rect; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* The <code>CSSValueImpl</code> class can represent either a |
||||
* <code>CSSPrimitiveValue</code> or a <code>CSSValueList</code> so that |
||||
* the type can successfully change when using <code>setCssText</code>. |
||||
* |
||||
* TODO: |
||||
* Float unit conversions, |
||||
* A means of checking valid primitive types for properties |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CSSValueImpl extends CSSOMObjectImpl implements CSSPrimitiveValue, CSSValueList, CSSFormatable { |
||||
|
||||
private static final long serialVersionUID = 406281136418322579L; |
||||
|
||||
private Object value_; |
||||
|
||||
public Object getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
public void setValue(final Object value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public CSSValueImpl(final LexicalUnit value, final boolean forcePrimitive) { |
||||
LexicalUnit parameters = null; |
||||
try { |
||||
parameters = value.getParameters(); |
||||
} |
||||
catch (final IllegalStateException e) { |
||||
// Batik SAC parser throws IllegalStateException in some cases
|
||||
} |
||||
|
||||
if (!forcePrimitive && (value.getNextLexicalUnit() != null)) { |
||||
value_ = getValues(value); |
||||
} |
||||
else if (parameters != null) { |
||||
if (value.getLexicalUnitType() == LexicalUnit.SAC_RECT_FUNCTION) { |
||||
// Rect
|
||||
value_ = new RectImpl(value.getParameters()); |
||||
} |
||||
else if (value.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { |
||||
// RGBColor
|
||||
value_ = new RGBColorImpl(value.getParameters()); |
||||
} |
||||
else if (value.getLexicalUnitType() == LexicalUnit.SAC_COUNTER_FUNCTION) { |
||||
// Counter
|
||||
value_ = new CounterImpl(false, value.getParameters()); |
||||
} |
||||
else if (value.getLexicalUnitType() == LexicalUnit.SAC_COUNTERS_FUNCTION) { |
||||
// Counter
|
||||
value_ = new CounterImpl(true, value.getParameters()); |
||||
} |
||||
else { |
||||
value_ = value; |
||||
} |
||||
} |
||||
else { |
||||
// We need to be a CSSPrimitiveValue
|
||||
value_ = value; |
||||
} |
||||
|
||||
if (value instanceof LexicalUnitImpl) { |
||||
final Locator locator = ((LexicalUnitImpl) value).getLocator(); |
||||
if (locator != null) { |
||||
setUserData(UserDataConstants.KEY_LOCATOR, locator); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public CSSValueImpl() { |
||||
super(); |
||||
} |
||||
|
||||
private List<CSSValueImpl> getValues(final LexicalUnit value) { |
||||
final List<CSSValueImpl> values = new ArrayList<CSSValueImpl>(); |
||||
LexicalUnit lu = value; |
||||
while (lu != null) { |
||||
values.add(new CSSValueImpl(lu, true)); |
||||
lu = lu.getNextLexicalUnit(); |
||||
} |
||||
return values; |
||||
} |
||||
|
||||
public CSSValueImpl(final LexicalUnit value) { |
||||
this(value, false); |
||||
} |
||||
|
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
if (getCssValueType() == CSS_VALUE_LIST) { |
||||
|
||||
// Create the string from the LexicalUnits so we include the correct
|
||||
// operators in the string
|
||||
final StringBuilder sb = new StringBuilder(); |
||||
final List<?> list = (List<?>) value_; |
||||
final Iterator<?> it = list.iterator(); |
||||
|
||||
boolean separate = false; |
||||
while (it.hasNext()) { |
||||
final Object o = it.next(); |
||||
|
||||
final CSSValueImpl cssValue = (CSSValueImpl) o; |
||||
if (separate) { |
||||
if (cssValue.value_ instanceof LexicalUnit) { |
||||
final LexicalUnit lu = (LexicalUnit) cssValue.value_; |
||||
if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
sb.append(" "); |
||||
} |
||||
} |
||||
else { |
||||
sb.append(" "); |
||||
} |
||||
} |
||||
|
||||
if (cssValue.value_ instanceof CSSFormatable) { |
||||
sb.append(((CSSFormatable) o).getCssText(format)); |
||||
} |
||||
else { |
||||
sb.append(o.toString()); |
||||
} |
||||
separate = true; |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
if (value_ instanceof CSSFormatable) { |
||||
return ((CSSFormatable) value_).getCssText(format); |
||||
} |
||||
return value_ != null ? value_.toString() : ""; |
||||
} |
||||
|
||||
public void setCssText(final String cssText) throws DOMException { |
||||
try { |
||||
final InputSource is = new InputSource(new StringReader(cssText)); |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
final CSSValueImpl v2 = (CSSValueImpl) parser.parsePropertyValue(is); |
||||
value_ = v2.value_; |
||||
setUserDataMap(v2.getUserDataMap()); |
||||
} |
||||
catch (final Exception e) { |
||||
throw new DOMExceptionImpl( |
||||
DOMException.SYNTAX_ERR, |
||||
DOMExceptionImpl.SYNTAX_ERROR, |
||||
e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public short getCssValueType() { |
||||
if (value_ instanceof List) { |
||||
return CSS_VALUE_LIST; |
||||
} |
||||
if ((value_ instanceof LexicalUnit) |
||||
&& (((LexicalUnit) value_).getLexicalUnitType() == LexicalUnit.SAC_INHERIT)) { |
||||
return CSS_INHERIT; |
||||
} |
||||
return CSS_PRIMITIVE_VALUE; |
||||
} |
||||
|
||||
public short getPrimitiveType() { |
||||
if (value_ instanceof LexicalUnit) { |
||||
final LexicalUnit lu = (LexicalUnit) value_; |
||||
switch (lu.getLexicalUnitType()) { |
||||
case LexicalUnit.SAC_INHERIT: |
||||
return CSS_IDENT; |
||||
case LexicalUnit.SAC_INTEGER: |
||||
case LexicalUnit.SAC_REAL: |
||||
return CSS_NUMBER; |
||||
case LexicalUnit.SAC_EM: |
||||
return CSS_EMS; |
||||
case LexicalUnit.SAC_EX: |
||||
return CSS_EXS; |
||||
case LexicalUnit.SAC_PIXEL: |
||||
return CSS_PX; |
||||
case LexicalUnit.SAC_INCH: |
||||
return CSS_IN; |
||||
case LexicalUnit.SAC_CENTIMETER: |
||||
return CSS_CM; |
||||
case LexicalUnit.SAC_MILLIMETER: |
||||
return CSS_MM; |
||||
case LexicalUnit.SAC_POINT: |
||||
return CSS_PT; |
||||
case LexicalUnit.SAC_PICA: |
||||
return CSS_PC; |
||||
case LexicalUnit.SAC_PERCENTAGE: |
||||
return CSS_PERCENTAGE; |
||||
case LexicalUnit.SAC_URI: |
||||
return CSS_URI; |
||||
case LexicalUnit.SAC_COUNTER_FUNCTION: |
||||
// case LexicalUnit.SAC_COUNTERS_FUNCTION:
|
||||
return CSS_COUNTER; |
||||
// case LexicalUnit.SAC_RGBCOLOR:
|
||||
// return CSS_RGBCOLOR;
|
||||
case LexicalUnit.SAC_DEGREE: |
||||
return CSS_DEG; |
||||
case LexicalUnit.SAC_GRADIAN: |
||||
return CSS_GRAD; |
||||
case LexicalUnit.SAC_RADIAN: |
||||
return CSS_RAD; |
||||
case LexicalUnit.SAC_MILLISECOND: |
||||
return CSS_MS; |
||||
case LexicalUnit.SAC_SECOND: |
||||
return CSS_S; |
||||
case LexicalUnit.SAC_HERTZ: |
||||
return CSS_HZ; |
||||
case LexicalUnit.SAC_KILOHERTZ: |
||||
return CSS_KHZ; |
||||
case LexicalUnit.SAC_IDENT: |
||||
return CSS_IDENT; |
||||
case LexicalUnit.SAC_STRING_VALUE: |
||||
return CSS_STRING; |
||||
case LexicalUnit.SAC_ATTR: |
||||
return CSS_ATTR; |
||||
// case LexicalUnit.SAC_RECT_FUNCTION:
|
||||
// return CSS_RECT;
|
||||
case LexicalUnit.SAC_UNICODERANGE: |
||||
case LexicalUnit.SAC_SUB_EXPRESSION: |
||||
case LexicalUnit.SAC_FUNCTION: |
||||
return CSS_STRING; |
||||
case LexicalUnit.SAC_DIMENSION: |
||||
return CSS_DIMENSION; |
||||
default: |
||||
return CSS_UNKNOWN; |
||||
} |
||||
} |
||||
else if (value_ instanceof RectImpl) { |
||||
return CSS_RECT; |
||||
} |
||||
else if (value_ instanceof RGBColorImpl) { |
||||
return CSS_RGBCOLOR; |
||||
} |
||||
else if (value_ instanceof CounterImpl) { |
||||
return CSS_COUNTER; |
||||
} |
||||
return CSS_UNKNOWN; |
||||
} |
||||
|
||||
public void setFloatValue(final short unitType, final float floatValue) throws DOMException { |
||||
value_ = LexicalUnitImpl.createNumber(null, floatValue); |
||||
} |
||||
|
||||
public float getFloatValue(final short unitType) throws DOMException { |
||||
if (value_ instanceof LexicalUnit) { |
||||
final LexicalUnit lu = (LexicalUnit) value_; |
||||
return lu.getFloatValue(); |
||||
} |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.FLOAT_ERROR); |
||||
|
||||
// We need to attempt a conversion
|
||||
// return 0;
|
||||
} |
||||
|
||||
public void setStringValue(final short stringType, final String stringValue) throws DOMException { |
||||
switch (stringType) { |
||||
case CSS_STRING: |
||||
value_ = LexicalUnitImpl.createString(null, stringValue); |
||||
break; |
||||
case CSS_URI: |
||||
value_ = LexicalUnitImpl.createURI(null, stringValue); |
||||
break; |
||||
case CSS_IDENT: |
||||
value_ = LexicalUnitImpl.createIdent(null, stringValue); |
||||
break; |
||||
case CSS_ATTR: |
||||
// _value = LexicalUnitImpl.createAttr(null, stringValue);
|
||||
// break;
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.NOT_SUPPORTED_ERR, |
||||
DOMExceptionImpl.NOT_IMPLEMENTED); |
||||
default: |
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.STRING_ERROR); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* TODO: return a value for a list type |
||||
*/ |
||||
public String getStringValue() throws DOMException { |
||||
if (value_ instanceof LexicalUnit) { |
||||
final LexicalUnit lu = (LexicalUnit) value_; |
||||
if ((lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) |
||||
|| (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE) |
||||
|| (lu.getLexicalUnitType() == LexicalUnit.SAC_URI) |
||||
|| (lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT) |
||||
|| (lu.getLexicalUnitType() == LexicalUnit.SAC_ATTR)) { |
||||
return lu.getStringValue(); |
||||
} |
||||
|
||||
// for rgba values we are using this type
|
||||
if (lu.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) { |
||||
return lu.toString(); |
||||
} |
||||
} |
||||
else if (value_ instanceof List) { |
||||
return null; |
||||
} |
||||
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.STRING_ERROR); |
||||
} |
||||
|
||||
public Counter getCounterValue() throws DOMException { |
||||
if (value_ instanceof Counter) { |
||||
return (Counter) value_; |
||||
} |
||||
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.COUNTER_ERROR); |
||||
} |
||||
|
||||
public Rect getRectValue() throws DOMException { |
||||
if (value_ instanceof Rect) { |
||||
return (Rect) value_; |
||||
} |
||||
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.RECT_ERROR); |
||||
} |
||||
|
||||
public RGBColor getRGBColorValue() throws DOMException { |
||||
if (value_ instanceof RGBColor) { |
||||
return (RGBColor) value_; |
||||
} |
||||
|
||||
throw new DOMExceptionImpl( |
||||
DOMException.INVALID_ACCESS_ERR, |
||||
DOMExceptionImpl.RGBCOLOR_ERROR); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public int getLength() { |
||||
if (value_ instanceof List) { |
||||
return ((List<CSSValue>) value_).size(); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public CSSValue item(final int index) { |
||||
if (value_ instanceof List) { |
||||
final List<CSSValue> list = (List<CSSValue>) value_; |
||||
return list.get(index); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof CSSValue)) { |
||||
return false; |
||||
} |
||||
final CSSValue cv = (CSSValue) obj; |
||||
// TODO to be improved!
|
||||
return super.equals(obj) |
||||
&& (getCssValueType() == cv.getCssValueType()) |
||||
&& LangUtils.equals(getCssText(), cv.getCssText()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, value_); |
||||
return hash; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,144 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.Counter; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Implementation of {@link Counter}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CounterImpl implements Counter, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 7996279151817598904L; |
||||
|
||||
private String identifier_; |
||||
private String listStyle_; |
||||
private String separator_; |
||||
|
||||
public void setIdentifier(final String identifier) { |
||||
identifier_ = identifier; |
||||
} |
||||
|
||||
public void setListStyle(final String listStyle) { |
||||
listStyle_ = listStyle; |
||||
} |
||||
|
||||
public void setSeparator(final String separator) { |
||||
separator_ = separator; |
||||
} |
||||
|
||||
/** |
||||
* Creates new CounterImpl |
||||
*/ |
||||
public CounterImpl(final boolean separatorSpecified, final LexicalUnit lu) throws DOMException { |
||||
LexicalUnit next = lu; |
||||
identifier_ = next.getStringValue(); |
||||
next = next.getNextLexicalUnit(); // ','
|
||||
if (next != null) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"Counter parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
if (separatorSpecified && (next != null)) { |
||||
separator_ = next.getStringValue(); |
||||
next = next.getNextLexicalUnit(); // ','
|
||||
if (next != null) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"Counter parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
} |
||||
} |
||||
if (next != null) { |
||||
listStyle_ = next.getStringValue(); |
||||
next = next.getNextLexicalUnit(); |
||||
if (next != null) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"Too many parameters for counter function."); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public CounterImpl() { |
||||
super(); |
||||
} |
||||
|
||||
public String getIdentifier() { |
||||
return identifier_; |
||||
} |
||||
|
||||
public String getListStyle() { |
||||
return listStyle_; |
||||
} |
||||
|
||||
public String getSeparator() { |
||||
return separator_; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
if (separator_ == null) { |
||||
// This is a 'counter()' function
|
||||
sb.append("counter("); |
||||
} |
||||
else { |
||||
// This is a 'counters()' function
|
||||
sb.append("counters("); |
||||
} |
||||
sb.append(identifier_); |
||||
if (separator_ != null) { |
||||
sb.append(", \"").append(separator_).append("\""); |
||||
} |
||||
if (listStyle_ != null) { |
||||
sb.append(", ").append(listStyle_); |
||||
} |
||||
sb.append(")"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.util.Locale; |
||||
import java.util.ResourceBundle; |
||||
|
||||
import org.w3c.dom.DOMException; |
||||
|
||||
/** |
||||
* Custom {@link DOMException} extension. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class DOMExceptionImpl extends DOMException { |
||||
|
||||
private static final long serialVersionUID = 7365733663951145145L; |
||||
|
||||
public static final int SYNTAX_ERROR = 0; |
||||
public static final int INDEX_OUT_OF_BOUNDS = 1; |
||||
public static final int READ_ONLY_STYLE_SHEET = 2; |
||||
public static final int EXPECTING_UNKNOWN_RULE = 3; |
||||
public static final int EXPECTING_STYLE_RULE = 4; |
||||
public static final int EXPECTING_CHARSET_RULE = 5; |
||||
public static final int EXPECTING_IMPORT_RULE = 6; |
||||
public static final int EXPECTING_MEDIA_RULE = 7; |
||||
public static final int EXPECTING_FONT_FACE_RULE = 8; |
||||
public static final int EXPECTING_PAGE_RULE = 9; |
||||
public static final int FLOAT_ERROR = 10; |
||||
public static final int STRING_ERROR = 11; |
||||
public static final int COUNTER_ERROR = 12; |
||||
public static final int RECT_ERROR = 13; |
||||
public static final int RGBCOLOR_ERROR = 14; |
||||
public static final int CHARSET_NOT_FIRST = 15; |
||||
public static final int CHARSET_NOT_UNIQUE = 16; |
||||
public static final int IMPORT_NOT_FIRST = 17; |
||||
public static final int NOT_FOUND = 18; |
||||
public static final int NOT_IMPLEMENTED = 19; |
||||
public static final int INSERT_BEFORE_IMPORT = 20; |
||||
|
||||
private static ResourceBundle ExceptionResource_ = |
||||
ResourceBundle.getBundle( |
||||
"com.steadystate.css.parser.ExceptionResource", |
||||
Locale.getDefault()); |
||||
|
||||
public DOMExceptionImpl(final short code, final int messageKey) { |
||||
this(code, messageKey, null); |
||||
} |
||||
|
||||
public DOMExceptionImpl(final int code, final int messageKey) { |
||||
this(code, messageKey, null); |
||||
} |
||||
|
||||
public DOMExceptionImpl(final int code, final int messageKey, final String info) { |
||||
super((short) code, constructMessage(messageKey, info)); |
||||
} |
||||
|
||||
private static String constructMessage(final int key, final String info) { |
||||
final String messageKey = "s" + String.valueOf(key); |
||||
String message = ExceptionResource_.getString(messageKey); |
||||
if (null != info && info.length() > 0) { |
||||
message = message + " (" + info + ")"; |
||||
} |
||||
return message; |
||||
} |
||||
} |
@ -0,0 +1,210 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.StringReader; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.CSSOMParser; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.SACMediaListImpl; |
||||
import com.fr.third.steadystate.css.userdata.UserDataConstants; |
||||
import com.fr.third.steadystate.css.util.ThrowCssExceptionErrorHandler; |
||||
import org.w3c.css.sac.CSSParseException; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.stylesheets.MediaList; |
||||
|
||||
import com.fr.third.steadystate.css.parser.media.MediaQuery; |
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implements {@link MediaList}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class MediaListImpl extends CSSOMObjectImpl implements MediaList { |
||||
private static final long serialVersionUID = 6662784733573034870L; |
||||
|
||||
private List<MediaQuery> mediaQueries_; |
||||
|
||||
/** |
||||
* Creates new MediaList. |
||||
* @param mediaList the media list |
||||
*/ |
||||
public MediaListImpl(final SACMediaList mediaList) { |
||||
this(); |
||||
|
||||
setMediaList(mediaList); |
||||
|
||||
if (mediaList instanceof Locatable) { |
||||
final Locator locator = ((Locatable) mediaList).getLocator(); |
||||
if (locator != null) { |
||||
setUserData(UserDataConstants.KEY_LOCATOR, locator); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
* The attributes are null. |
||||
*/ |
||||
public MediaListImpl() { |
||||
mediaQueries_ = new ArrayList<MediaQuery>(10); |
||||
} |
||||
|
||||
public String getMediaText() { |
||||
return getMediaText(null); |
||||
} |
||||
|
||||
/** |
||||
* Returns a string representation of the rule based on the given format. |
||||
* If provided format is null, the result is the same as getCssText() |
||||
* |
||||
* @param format the formatting rules |
||||
* @return the formated string |
||||
*/ |
||||
public String getMediaText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(""); |
||||
boolean isNotFirst = false; |
||||
for (MediaQuery mediaQuery : mediaQueries_) { |
||||
if (isNotFirst) { |
||||
sb.append(", "); |
||||
} |
||||
else { |
||||
isNotFirst = true; |
||||
} |
||||
sb.append(mediaQuery.getCssText(format)); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public void setMediaText(final String mediaText) throws DOMException { |
||||
final InputSource source = new InputSource(new StringReader(mediaText)); |
||||
try { |
||||
final CSSOMParser parser = new CSSOMParser(); |
||||
parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE); |
||||
final SACMediaList sml = parser.parseMedia(source); |
||||
setMediaList(sml); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage()); |
||||
} |
||||
catch (final IOException e) { |
||||
throw new DOMException(DOMException.NOT_FOUND_ERR, e.getLocalizedMessage()); |
||||
} |
||||
} |
||||
|
||||
public int getLength() { |
||||
return mediaQueries_.size(); |
||||
} |
||||
|
||||
public String item(final int index) { |
||||
final MediaQuery mq = mediaQuery(index); |
||||
if (null == mq) { |
||||
return null; |
||||
} |
||||
|
||||
return mq.getMedia(); |
||||
} |
||||
|
||||
public MediaQuery mediaQuery(final int index) { |
||||
if (index < 0 || (index >= mediaQueries_.size())) { |
||||
return null; |
||||
} |
||||
return mediaQueries_.get(index); |
||||
} |
||||
|
||||
public void deleteMedium(final String oldMedium) throws DOMException { |
||||
for (MediaQuery mediaQuery : mediaQueries_) { |
||||
final String str = mediaQuery.getMedia(); |
||||
if (str.equalsIgnoreCase(oldMedium)) { |
||||
mediaQueries_.remove(mediaQuery); |
||||
return; |
||||
} |
||||
} |
||||
throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, DOMExceptionImpl.NOT_FOUND); |
||||
} |
||||
|
||||
public void appendMedium(final String newMedium) throws DOMException { |
||||
mediaQueries_.add(new MediaQuery(newMedium)); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getMediaText(null); |
||||
} |
||||
|
||||
public void setMedia(final List<String> media) { |
||||
mediaQueries_.clear(); |
||||
for (String medium : media) { |
||||
mediaQueries_.add(new MediaQuery(medium)); |
||||
} |
||||
} |
||||
|
||||
private void setMediaList(final SACMediaList mediaList) { |
||||
if (mediaList instanceof SACMediaListImpl) { |
||||
final SACMediaListImpl impl = (SACMediaListImpl) mediaList; |
||||
for (int i = 0; i < mediaList.getLength(); i++) { |
||||
mediaQueries_.add(impl.mediaQuery(i)); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
for (int i = 0; i < mediaList.getLength(); i++) { |
||||
mediaQueries_.add(new MediaQuery(mediaList.item(i))); |
||||
} |
||||
} |
||||
|
||||
private boolean equalsMedia(final MediaList ml) { |
||||
if ((ml == null) || (getLength() != ml.getLength())) { |
||||
return false; |
||||
} |
||||
for (int i = 0; i < getLength(); i++) { |
||||
final String m1 = item(i); |
||||
final String m2 = ml.item(i); |
||||
if (!LangUtils.equals(m1, m2)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof MediaList)) { |
||||
return false; |
||||
} |
||||
final MediaList ml = (MediaList) obj; |
||||
return super.equals(obj) && equalsMedia(ml); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, mediaQueries_); |
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,165 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.dom.css.CSSValue; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class Property extends CSSOMObjectImpl implements CSSFormatable { |
||||
private static final long serialVersionUID = 8720637891949104989L; |
||||
|
||||
private String name_; |
||||
private CSSValue value_; |
||||
private boolean important_; |
||||
|
||||
/** |
||||
* Creates new Property. |
||||
* @param name the name |
||||
* @param value the value |
||||
* @param important true if the important flag set |
||||
*/ |
||||
public Property(final String name, final CSSValue value, final boolean important) { |
||||
name_ = name; |
||||
value_ = value; |
||||
important_ = important; |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
* The attributes are null. |
||||
*/ |
||||
public Property() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the name. |
||||
* @return the name |
||||
*/ |
||||
public String getName() { |
||||
return name_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the name to a new value. |
||||
* @param name the new name |
||||
*/ |
||||
public void setName(final String name) { |
||||
name_ = name; |
||||
} |
||||
|
||||
/** |
||||
* Returns the value. |
||||
* @return the value |
||||
*/ |
||||
public CSSValue getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* Returns true if the important flag is set. |
||||
* @return true or false |
||||
*/ |
||||
public boolean isImportant() { |
||||
return important_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the value to a new value. |
||||
* @param value the new CSSValue |
||||
*/ |
||||
public void setValue(final CSSValue value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Sets the important flag to a new value. |
||||
* @param important the new flag value |
||||
*/ |
||||
public void setImportant(final boolean important) { |
||||
important_ = important; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(name_); |
||||
if (null != value_) { |
||||
sb.append(": "); |
||||
sb.append(((CSSValueImpl) value_).getCssText(format)); |
||||
} |
||||
if (important_) { |
||||
sb.append(" !important"); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof Property)) { |
||||
return false; |
||||
} |
||||
final Property p = (Property) obj; |
||||
return super.equals(obj) |
||||
&& (important_ == p.important_) |
||||
&& LangUtils.equals(name_, p.name_) |
||||
&& LangUtils.equals(value_, p.value_); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public int hashCode() { |
||||
int hash = super.hashCode(); |
||||
hash = LangUtils.hashCode(hash, important_); |
||||
hash = LangUtils.hashCode(hash, name_); |
||||
hash = LangUtils.hashCode(hash, value_); |
||||
return hash; |
||||
} |
||||
} |
@ -0,0 +1,178 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSPrimitiveValue; |
||||
import org.w3c.dom.css.RGBColor; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Implementation of {@link RGBColor}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class RGBColorImpl implements RGBColor, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 8152675334081993160L; |
||||
private CSSPrimitiveValue red_; |
||||
private CSSPrimitiveValue green_; |
||||
private CSSPrimitiveValue blue_; |
||||
|
||||
/** |
||||
* Constructor that reads the values from the given |
||||
* chain of LexicalUnits. |
||||
* @param lu the values |
||||
* @throws DOMException in case of error |
||||
*/ |
||||
public RGBColorImpl(final LexicalUnit lu) throws DOMException { |
||||
LexicalUnit next = lu; |
||||
red_ = new CSSValueImpl(next, true); |
||||
next = next.getNextLexicalUnit(); // ,
|
||||
if (next != null) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"rgb parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
if (next != null) { |
||||
green_ = new CSSValueImpl(next, true); |
||||
next = next.getNextLexicalUnit(); // ,
|
||||
if (next != null) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"rgb parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
blue_ = new CSSValueImpl(next, true); |
||||
next = next.getNextLexicalUnit(); |
||||
if (next != null) { |
||||
// error
|
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"Too many parameters for rgb function."); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
* The values for the colors are null. |
||||
*/ |
||||
public RGBColorImpl() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the red part. |
||||
*/ |
||||
public CSSPrimitiveValue getRed() { |
||||
return red_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the red part to a new value. |
||||
* @param red the new CSSPrimitiveValue |
||||
*/ |
||||
public void setRed(final CSSPrimitiveValue red) { |
||||
red_ = red; |
||||
} |
||||
|
||||
/** |
||||
* Returns the green part. |
||||
*/ |
||||
public CSSPrimitiveValue getGreen() { |
||||
return green_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the green part to a new value. |
||||
* @param green the new CSSPrimitiveValue |
||||
*/ |
||||
public void setGreen(final CSSPrimitiveValue green) { |
||||
green_ = green; |
||||
} |
||||
|
||||
/** |
||||
* Returns the blue part. |
||||
*/ |
||||
public CSSPrimitiveValue getBlue() { |
||||
return blue_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the blue part to a new value. |
||||
* @param blue the new CSSPrimitiveValue |
||||
*/ |
||||
public void setBlue(final CSSPrimitiveValue blue) { |
||||
blue_ = blue; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
if (null != format && format.isRgbAsHex()) { |
||||
sb |
||||
.append("#") |
||||
.append(getColorAsHex(red_)) |
||||
.append(getColorAsHex(green_)) |
||||
.append(getColorAsHex(blue_)); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
sb |
||||
.append("rgb(") |
||||
.append(red_) |
||||
.append(", ") |
||||
.append(green_) |
||||
.append(", ") |
||||
.append(blue_) |
||||
.append(")"); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
private String getColorAsHex(final CSSPrimitiveValue color) { |
||||
return String.format("%02x", Math.round(color.getFloatValue(LexicalUnit.SAC_INTEGER))); |
||||
} |
||||
} |
@ -0,0 +1,219 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.dom; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.css.CSSPrimitiveValue; |
||||
import org.w3c.dom.css.Rect; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Implementation of {@link Rect}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
*/ |
||||
public class RectImpl implements Rect, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -7031248513917920621L; |
||||
|
||||
private CSSPrimitiveValue top_; |
||||
private CSSPrimitiveValue right_; |
||||
private CSSPrimitiveValue bottom_; |
||||
private CSSPrimitiveValue left_; |
||||
|
||||
/** |
||||
* Constructor that reads the values from the given |
||||
* chain of LexicalUnits. |
||||
* @param lu the values |
||||
* @throws DOMException in case of error |
||||
*/ |
||||
public RectImpl(final LexicalUnit lu) throws DOMException { |
||||
// top
|
||||
if (lu == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses first parameter."); |
||||
} |
||||
top_ = new CSSValueImpl(lu, true); |
||||
|
||||
// right
|
||||
LexicalUnit next = lu.getNextLexicalUnit(); // ,
|
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses second parameter."); |
||||
} |
||||
|
||||
boolean isCommaSeparated = false; |
||||
if (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
isCommaSeparated = true; |
||||
next = next.getNextLexicalUnit(); |
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses second parameter."); |
||||
} |
||||
} |
||||
right_ = new CSSValueImpl(next, true); |
||||
|
||||
// bottom
|
||||
next = next.getNextLexicalUnit(); |
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses third parameter."); |
||||
} |
||||
if (isCommaSeparated) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"All or none rect parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses third parameter."); |
||||
} |
||||
} |
||||
else { |
||||
if (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"All or none rect parameters must be separated by ','."); |
||||
} |
||||
} |
||||
bottom_ = new CSSValueImpl(next, true); |
||||
|
||||
// left
|
||||
next = next.getNextLexicalUnit(); |
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses fourth parameter."); |
||||
} |
||||
if (isCommaSeparated) { |
||||
if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"All or none rect parameters must be separated by ','."); |
||||
} |
||||
next = next.getNextLexicalUnit(); |
||||
if (next == null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Rect misses fourth parameter."); |
||||
} |
||||
} |
||||
else { |
||||
if (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, |
||||
"All or none rect parameters must be separated by ','."); |
||||
} |
||||
} |
||||
left_ = new CSSValueImpl(next, true); |
||||
|
||||
// too many
|
||||
next = next.getNextLexicalUnit(); |
||||
if (next != null) { |
||||
throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for rect function."); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Constructor. |
||||
* The values for the coordinates are null. |
||||
*/ |
||||
public RectImpl() { |
||||
super(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the top part. |
||||
*/ |
||||
public CSSPrimitiveValue getTop() { |
||||
return top_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the top part to a new value. |
||||
* @param top the new CSSPrimitiveValue |
||||
*/ |
||||
public void setTop(final CSSPrimitiveValue top) { |
||||
top_ = top; |
||||
} |
||||
|
||||
/** |
||||
* Returns the right part. |
||||
*/ |
||||
public CSSPrimitiveValue getRight() { |
||||
return right_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the right part to a new value. |
||||
* @param right the new CSSPrimitiveValue |
||||
*/ |
||||
public void setRight(final CSSPrimitiveValue right) { |
||||
right_ = right; |
||||
} |
||||
|
||||
/** |
||||
* Returns the bottom part. |
||||
*/ |
||||
public CSSPrimitiveValue getBottom() { |
||||
return bottom_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the bottom part to a new value. |
||||
* @param bottom the new CSSPrimitiveValue |
||||
*/ |
||||
public void setBottom(final CSSPrimitiveValue bottom) { |
||||
bottom_ = bottom; |
||||
} |
||||
|
||||
/** |
||||
* Returns the left part. |
||||
*/ |
||||
public CSSPrimitiveValue getLeft() { |
||||
return left_; |
||||
} |
||||
|
||||
/** |
||||
* Sets the left part to a new value. |
||||
* @param left the new CSSPrimitiveValue |
||||
*/ |
||||
public void setLeft(final CSSPrimitiveValue left) { |
||||
left_ = left; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
return new StringBuilder("rect(") |
||||
.append(top_).append(", ") |
||||
.append(right_).append(", ") |
||||
.append(bottom_).append(", ") |
||||
.append(left_).append(")").toString(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.format; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* Format object that controls the output produced by toString(CssFormat). |
||||
* |
||||
* @author rbri |
||||
*/ |
||||
public class CSSFormat { |
||||
private static final String NEW_LINE = System.getProperty("line.separator"); |
||||
|
||||
private boolean rgbAsHex_; |
||||
private boolean propertiesInSeparateLines_; |
||||
private boolean useSourceStringValues_; |
||||
private String propertiesIndent_ = ""; |
||||
|
||||
public boolean isRgbAsHex() { |
||||
return rgbAsHex_; |
||||
} |
||||
|
||||
public CSSFormat setRgbAsHex(final boolean rgbAsHex) { |
||||
rgbAsHex_ = rgbAsHex; |
||||
return this; |
||||
} |
||||
|
||||
public boolean useSourceStringValues() { |
||||
return useSourceStringValues_; |
||||
} |
||||
|
||||
public CSSFormat setUseSourceStringValues(final boolean useSourceStringValues) { |
||||
useSourceStringValues_ = useSourceStringValues; |
||||
return this; |
||||
} |
||||
|
||||
public boolean getPropertiesInSeparateLines() { |
||||
return propertiesInSeparateLines_; |
||||
} |
||||
|
||||
public String getPropertiesIndent() { |
||||
return propertiesIndent_; |
||||
} |
||||
|
||||
/** |
||||
* If this value is larger than -1 the individual properties from a rule |
||||
* are rendered in separate lines; the parameter defines the indentation level. |
||||
* Set this to -1 to disable the feature (default) |
||||
* |
||||
* @param anIndent the number of blanks used for indentation |
||||
* @return the format itself |
||||
*/ |
||||
public CSSFormat setPropertiesInSeparateLines(final int anIndent) { |
||||
propertiesInSeparateLines_ = anIndent > -1; |
||||
|
||||
if (anIndent > 0) { |
||||
final char[] chars = new char[anIndent]; |
||||
Arrays.fill(chars, ' '); |
||||
propertiesIndent_ = new String(chars); |
||||
} |
||||
else { |
||||
propertiesIndent_ = ""; |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
public String getNewLine() { |
||||
return NEW_LINE; |
||||
} |
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.format; |
||||
|
||||
/** |
||||
* Common interface for all classes supporting formated output. |
||||
* |
||||
* @author rbri |
||||
*/ |
||||
public interface CSSFormatable { |
||||
|
||||
/** |
||||
* Returns a string representation of the rule based on the given format. |
||||
* If provided format is null, the result is the same as getCssText() |
||||
* |
||||
* @param format the formatting rules |
||||
* @return the formated string |
||||
*/ |
||||
String getCssText(CSSFormat format); |
||||
} |
@ -0,0 +1,800 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStreamReader; |
||||
import java.net.URL; |
||||
import java.nio.charset.Charset; |
||||
import java.text.MessageFormat; |
||||
import java.util.Locale; |
||||
import java.util.MissingResourceException; |
||||
import java.util.ResourceBundle; |
||||
|
||||
import com.fr.third.steadystate.css.sac.SelectorFactoryAdapter; |
||||
import org.w3c.css.sac.CSSParseException; |
||||
import org.w3c.css.sac.ConditionFactory; |
||||
import org.w3c.css.sac.DocumentHandler; |
||||
import org.w3c.css.sac.ErrorHandler; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.Parser; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SelectorFactory; |
||||
import org.w3c.css.sac.SelectorList; |
||||
import org.w3c.dom.DOMException; |
||||
|
||||
import com.fr.third.steadystate.css.parser.selectors.ConditionFactoryImpl; |
||||
import com.fr.third.steadystate.css.parser.selectors.SelectorFactoryImpl; |
||||
import com.fr.third.steadystate.css.sac.ConditionFactoryAdapter; |
||||
import com.fr.third.steadystate.css.sac.ConditionFactoryExt; |
||||
import com.fr.third.steadystate.css.sac.DocumentHandlerAdapter; |
||||
import com.fr.third.steadystate.css.sac.DocumentHandlerExt; |
||||
import com.fr.third.steadystate.css.sac.SelectorFactoryExt; |
||||
|
||||
/** |
||||
* Base implementation of {@link Parser}. |
||||
* |
||||
* @author koch |
||||
* @author RBRi |
||||
*/ |
||||
abstract class AbstractSACParser implements SACParser { |
||||
private DocumentHandlerExt documentHandler_; |
||||
private ErrorHandler errorHandler_; |
||||
private InputSource source_; |
||||
private Locale locale_; |
||||
private SelectorFactoryExt selectorFactory_; |
||||
private ConditionFactoryExt conditionFactory_; |
||||
private ResourceBundle sacParserMessages_; |
||||
|
||||
private boolean ieStarHackAccepted_; |
||||
|
||||
private static final String NUM_CHARS = "0123456789."; |
||||
|
||||
protected DocumentHandlerExt getDocumentHandler() { |
||||
if (documentHandler_ == null) { |
||||
setDocumentHandler(new HandlerBase()); |
||||
} |
||||
return documentHandler_; |
||||
} |
||||
|
||||
public void setDocumentHandler(final DocumentHandler handler) { |
||||
if (handler instanceof DocumentHandlerExt) { |
||||
documentHandler_ = (DocumentHandlerExt) handler; |
||||
} |
||||
else { |
||||
documentHandler_ = new DocumentHandlerAdapter(handler); |
||||
} |
||||
} |
||||
|
||||
protected ErrorHandler getErrorHandler() { |
||||
if (errorHandler_ == null) { |
||||
setErrorHandler(new HandlerBase()); |
||||
} |
||||
return errorHandler_; |
||||
} |
||||
|
||||
public void setErrorHandler(final ErrorHandler eh) { |
||||
errorHandler_ = eh; |
||||
} |
||||
|
||||
protected InputSource getInputSource() { |
||||
return source_; |
||||
} |
||||
|
||||
public void setIeStarHackAccepted(final boolean accepted) { |
||||
ieStarHackAccepted_ = accepted; |
||||
} |
||||
|
||||
public boolean isIeStarHackAccepted() { |
||||
return ieStarHackAccepted_; |
||||
} |
||||
|
||||
public void setLocale(final Locale locale) { |
||||
if (locale_ != locale) { |
||||
sacParserMessages_ = null; |
||||
} |
||||
locale_ = locale; |
||||
} |
||||
|
||||
protected Locale getLocale() { |
||||
if (locale_ == null) { |
||||
setLocale(Locale.getDefault()); |
||||
} |
||||
return locale_; |
||||
} |
||||
|
||||
protected SelectorFactoryExt getSelectorFactory() { |
||||
if (selectorFactory_ == null) { |
||||
selectorFactory_ = new SelectorFactoryImpl(); |
||||
} |
||||
return selectorFactory_; |
||||
} |
||||
|
||||
public void setSelectorFactory(final SelectorFactory selectorFactory) { |
||||
if (selectorFactory instanceof SelectorFactoryExt) { |
||||
selectorFactory_ = (SelectorFactoryExt) selectorFactory; |
||||
} |
||||
else { |
||||
selectorFactory_ = new SelectorFactoryAdapter(selectorFactory); |
||||
} |
||||
} |
||||
|
||||
protected ConditionFactoryExt getConditionFactory() { |
||||
if (conditionFactory_ == null) { |
||||
conditionFactory_ = new ConditionFactoryImpl(); |
||||
} |
||||
return conditionFactory_; |
||||
} |
||||
|
||||
public void setConditionFactory(final ConditionFactory conditionFactory) { |
||||
if (conditionFactory instanceof ConditionFactoryExt) { |
||||
conditionFactory_ = (ConditionFactoryExt) conditionFactory; |
||||
} |
||||
else { |
||||
conditionFactory_ = new ConditionFactoryAdapter(conditionFactory); |
||||
} |
||||
} |
||||
|
||||
protected ResourceBundle getSACParserMessages() { |
||||
if (sacParserMessages_ == null) { |
||||
try { |
||||
sacParserMessages_ = ResourceBundle.getBundle( |
||||
"com.steadystate.css.parser.SACParserMessages", |
||||
getLocale()); |
||||
} |
||||
catch (final MissingResourceException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return sacParserMessages_; |
||||
} |
||||
|
||||
protected Locator createLocator(final Token t) { |
||||
return new LocatorImpl(getInputSource().getURI(), |
||||
t == null ? 0 : t.beginLine, |
||||
t == null ? 0 : t.beginColumn); |
||||
} |
||||
|
||||
protected String add_escapes(final String str) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
char ch; |
||||
for (int i = 0; i < str.length(); i++) { |
||||
ch = str.charAt(i); |
||||
switch (ch) { |
||||
case 0 : |
||||
continue; |
||||
case '\b': |
||||
sb.append("\\b"); |
||||
continue; |
||||
case '\t': |
||||
sb.append("\\t"); |
||||
continue; |
||||
case '\n': |
||||
sb.append("\\n"); |
||||
continue; |
||||
case '\f': |
||||
sb.append("\\f"); |
||||
continue; |
||||
case '\r': |
||||
sb.append("\\r"); |
||||
continue; |
||||
case '\"': |
||||
sb.append("\\\""); |
||||
continue; |
||||
case '\'': |
||||
sb.append("\\\'"); |
||||
continue; |
||||
case '\\': |
||||
sb.append("\\\\"); |
||||
continue; |
||||
default: |
||||
if (ch < 0x20 || ch > 0x7e) { |
||||
final String s = "0000" + Integer.toString(ch, 16); |
||||
sb.append("\\u" + s.substring(s.length() - 4, s.length())); |
||||
} |
||||
else { |
||||
sb.append(ch); |
||||
} |
||||
continue; |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
protected CSSParseException toCSSParseException(final String key, final ParseException e) { |
||||
final String messagePattern1 = getSACParserMessages().getString("invalidExpectingOne"); |
||||
final String messagePattern2 = getSACParserMessages().getString("invalidExpectingMore"); |
||||
int maxSize = 0; |
||||
final StringBuilder expected = new StringBuilder(); |
||||
for (int i = 0; i < e.expectedTokenSequences.length; i++) { |
||||
if (maxSize < e.expectedTokenSequences[i].length) { |
||||
maxSize = e.expectedTokenSequences[i].length; |
||||
} |
||||
for (int j = 0; j < e.expectedTokenSequences[i].length; j++) { |
||||
expected.append(e.tokenImage[e.expectedTokenSequences[i][j]]); |
||||
} |
||||
if (i < e.expectedTokenSequences.length - 1) { |
||||
expected.append(", "); |
||||
} |
||||
} |
||||
final StringBuilder invalid = new StringBuilder(); |
||||
Token tok = e.currentToken.next; |
||||
for (int i = 0; i < maxSize; i++) { |
||||
if (i != 0) { |
||||
invalid.append(" "); |
||||
} |
||||
if (tok.kind == 0) { |
||||
invalid.append(e.tokenImage[0]); |
||||
break; |
||||
} |
||||
invalid.append(add_escapes(tok.image)); |
||||
tok = tok.next; |
||||
} |
||||
String s = null; |
||||
try { |
||||
s = getSACParserMessages().getString(key); |
||||
} |
||||
catch (final MissingResourceException ex) { |
||||
s = key; |
||||
} |
||||
final StringBuilder message = new StringBuilder(s); |
||||
message.append(" ("); |
||||
if (e.expectedTokenSequences.length == 1) { |
||||
message.append(MessageFormat.format(messagePattern1, new Object[] {invalid, expected})); |
||||
} |
||||
else { |
||||
message.append(MessageFormat.format(messagePattern2, new Object[] {invalid, expected})); |
||||
} |
||||
message.append(")"); |
||||
return new CSSParseException(message.toString(), |
||||
getInputSource().getURI(), e.currentToken.next.beginLine, |
||||
e.currentToken.next.beginColumn); |
||||
} |
||||
|
||||
protected CSSParseException toCSSParseException(final DOMException e) { |
||||
final String messagePattern = getSACParserMessages().getString("domException"); |
||||
return new CSSParseException( |
||||
MessageFormat.format(messagePattern, e.getMessage()), getInputSource().getURI(), 1, 1); |
||||
} |
||||
|
||||
protected CSSParseException toCSSParseException(final TokenMgrError e) { |
||||
final String messagePattern = getSACParserMessages().getString("tokenMgrError"); |
||||
return new CSSParseException(messagePattern, getInputSource().getURI(), 1, 1); |
||||
} |
||||
|
||||
protected CSSParseException toCSSParseException(final String messageKey, |
||||
final Object[] msgParams, final Locator locator) { |
||||
final String messagePattern = getSACParserMessages().getString(messageKey); |
||||
return new CSSParseException(MessageFormat.format(messagePattern, msgParams), locator); |
||||
} |
||||
|
||||
protected CSSParseException createSkipWarning(final String key, final CSSParseException e) { |
||||
String s = null; |
||||
try { |
||||
s = getSACParserMessages().getString(key); |
||||
} |
||||
catch (final MissingResourceException ex) { |
||||
s = key; |
||||
} |
||||
return new CSSParseException(s, e.getURI(), e.getLineNumber(), e.getColumnNumber()); |
||||
} |
||||
|
||||
public void parseStyleSheet(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
try { |
||||
styleSheet(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidStyleSheet", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
} |
||||
|
||||
public void parseStyleSheet(final String uri) throws IOException { |
||||
parseStyleSheet(new InputSource(uri)); |
||||
} |
||||
|
||||
public void parseStyleDeclaration(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
try { |
||||
styleDeclaration(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidStyleDeclaration", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
} |
||||
|
||||
public void parseRule(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
try { |
||||
styleSheetRuleSingle(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidRule", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
} |
||||
|
||||
public SelectorList parseSelectors(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
SelectorList sl = null; |
||||
try { |
||||
sl = parseSelectorsInternal(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidSelectorList", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
return sl; |
||||
} |
||||
|
||||
public LexicalUnit parsePropertyValue(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
LexicalUnit lu = null; |
||||
try { |
||||
lu = expr(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidExpr", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
return lu; |
||||
} |
||||
|
||||
public boolean parsePriority(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
boolean b = false; |
||||
try { |
||||
b = prio(); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidPrio", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
return b; |
||||
} |
||||
|
||||
public SACMediaList parseMedia(final InputSource source) throws IOException { |
||||
source_ = source; |
||||
ReInit(getCharStream(source)); |
||||
final SACMediaListImpl ml = new SACMediaListImpl(); |
||||
try { |
||||
mediaList(ml); |
||||
} |
||||
catch (final ParseException e) { |
||||
getErrorHandler().error(toCSSParseException("invalidMediaList", e)); |
||||
} |
||||
catch (final TokenMgrError e) { |
||||
getErrorHandler().error(toCSSParseException(e)); |
||||
} |
||||
catch (final CSSParseException e) { |
||||
getErrorHandler().error(e); |
||||
} |
||||
return ml; |
||||
} |
||||
|
||||
private CharStream getCharStream(final InputSource source) throws IOException { |
||||
if (source.getCharacterStream() != null) { |
||||
return new CssCharStream(source.getCharacterStream(), 1, 1); |
||||
} |
||||
if (source.getByteStream() != null) { |
||||
final InputStreamReader reader; |
||||
final String encoding = source.getEncoding(); |
||||
if (encoding == null || encoding.length() < 1) { |
||||
reader = new InputStreamReader(source.getByteStream(), Charset.defaultCharset()); |
||||
} |
||||
else { |
||||
reader = new InputStreamReader(source.getByteStream(), encoding); |
||||
} |
||||
return new CssCharStream(reader, 1, 1); |
||||
} |
||||
if (source.getURI() != null) { |
||||
final InputStreamReader reader = new InputStreamReader(new URL(source.getURI()).openStream()); |
||||
return new CssCharStream(reader, 1, 1); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public abstract String getParserVersion(); |
||||
protected abstract String getGrammarUri(); |
||||
protected abstract void ReInit(CharStream charStream); |
||||
protected abstract void styleSheet() throws CSSParseException, ParseException; |
||||
protected abstract void styleDeclaration() throws ParseException; |
||||
protected abstract void styleSheetRuleSingle() throws ParseException; |
||||
protected abstract SelectorList parseSelectorsInternal() throws ParseException; |
||||
protected abstract SelectorList selectorList() throws ParseException; |
||||
protected abstract LexicalUnit expr() throws ParseException; |
||||
protected abstract boolean prio() throws ParseException; |
||||
protected abstract void mediaList(SACMediaListImpl ml) throws ParseException; |
||||
|
||||
protected void handleStartDocument() { |
||||
getDocumentHandler().startDocument(getInputSource()); |
||||
} |
||||
|
||||
protected void handleEndDocument() { |
||||
getDocumentHandler().endDocument(getInputSource()); |
||||
} |
||||
|
||||
protected void handleIgnorableAtRule(final String s, final Locator locator) { |
||||
getDocumentHandler().ignorableAtRule(s, locator); |
||||
} |
||||
|
||||
protected void handleCharset(final String characterEncoding, final Locator locator) { |
||||
getDocumentHandler().charset(characterEncoding, locator); |
||||
} |
||||
|
||||
protected void handleImportStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI, final Locator locator) { |
||||
getDocumentHandler().importStyle(uri, media, defaultNamespaceURI, locator); |
||||
} |
||||
|
||||
protected void handleStartMedia(final SACMediaList media, final Locator locator) { |
||||
getDocumentHandler().startMedia(media, locator); |
||||
} |
||||
|
||||
protected void handleMedium(final String medium, final Locator locator) { |
||||
// empty default impl
|
||||
} |
||||
|
||||
protected void handleEndMedia(final SACMediaList media) { |
||||
getDocumentHandler().endMedia(media); |
||||
} |
||||
|
||||
protected void handleStartPage(final String name, final String pseudoPage, final Locator locator) { |
||||
getDocumentHandler().startPage(name, pseudoPage, locator); |
||||
} |
||||
|
||||
protected void handleEndPage(final String name, final String pseudoPage) { |
||||
getDocumentHandler().endPage(name, pseudoPage); |
||||
} |
||||
|
||||
protected void handleStartFontFace(final Locator locator) { |
||||
getDocumentHandler().startFontFace(locator); |
||||
} |
||||
|
||||
protected void handleEndFontFace() { |
||||
getDocumentHandler().endFontFace(); |
||||
} |
||||
|
||||
protected void handleSelector(final Selector selector) { |
||||
// empty default impl
|
||||
} |
||||
|
||||
protected void handleStartSelector(final SelectorList selectors, final Locator locator) { |
||||
getDocumentHandler().startSelector(selectors, locator); |
||||
} |
||||
|
||||
protected void handleEndSelector(final SelectorList selectors) { |
||||
getDocumentHandler().endSelector(selectors); |
||||
} |
||||
|
||||
protected void handleProperty(final String name, final LexicalUnit value, |
||||
final boolean important, final Locator locator) { |
||||
getDocumentHandler().property(name, value, important, locator); |
||||
} |
||||
|
||||
protected LexicalUnit functionInternal(final LexicalUnit prev, final String funct, |
||||
final LexicalUnit params) { |
||||
|
||||
if ("counter(".equalsIgnoreCase(funct)) { |
||||
return LexicalUnitImpl.createCounter(prev, params); |
||||
} |
||||
else if ("counters(".equalsIgnoreCase(funct)) { |
||||
return LexicalUnitImpl.createCounters(prev, params); |
||||
} |
||||
else if ("attr(".equalsIgnoreCase(funct)) { |
||||
return LexicalUnitImpl.createAttr(prev, params.getStringValue()); |
||||
} |
||||
else if ("rect(".equalsIgnoreCase(funct)) { |
||||
return LexicalUnitImpl.createRect(prev, params); |
||||
} |
||||
else if ("rgb(".equalsIgnoreCase(funct)) { |
||||
return LexicalUnitImpl.createRgbColor(prev, params); |
||||
} |
||||
return LexicalUnitImpl.createFunction( |
||||
prev, |
||||
funct.substring(0, funct.length() - 1), |
||||
params); |
||||
} |
||||
|
||||
protected LexicalUnit hexcolorInternal(final LexicalUnit prev, final Token t) { |
||||
// Step past the hash at the beginning
|
||||
final int i = 1; |
||||
int r = 0; |
||||
int g = 0; |
||||
int b = 0; |
||||
final int len = t.image.length() - 1; |
||||
try { |
||||
if (len == 3) { |
||||
r = Integer.parseInt(t.image.substring(i + 0, i + 1), 16); |
||||
g = Integer.parseInt(t.image.substring(i + 1, i + 2), 16); |
||||
b = Integer.parseInt(t.image.substring(i + 2, i + 3), 16); |
||||
r = (r << 4) | r; |
||||
g = (g << 4) | g; |
||||
b = (b << 4) | b; |
||||
} |
||||
else if (len == 6) { |
||||
r = Integer.parseInt(t.image.substring(i + 0, i + 2), 16); |
||||
g = Integer.parseInt(t.image.substring(i + 2, i + 4), 16); |
||||
b = Integer.parseInt(t.image.substring(i + 4, i + 6), 16); |
||||
} |
||||
else { |
||||
final String pattern = getSACParserMessages().getString("invalidColor"); |
||||
throw new CSSParseException(MessageFormat.format( |
||||
pattern, new Object[] {t}), |
||||
getInputSource().getURI(), t.beginLine, |
||||
t.beginColumn); |
||||
} |
||||
|
||||
// Turn into an "rgb()"
|
||||
final LexicalUnit lr = LexicalUnitImpl.createNumber(null, r); |
||||
final LexicalUnit lc1 = LexicalUnitImpl.createComma(lr); |
||||
final LexicalUnit lg = LexicalUnitImpl.createNumber(lc1, g); |
||||
final LexicalUnit lc2 = LexicalUnitImpl.createComma(lg); |
||||
LexicalUnitImpl.createNumber(lc2, b); |
||||
|
||||
return LexicalUnitImpl.createRgbColor(prev, lr); |
||||
} |
||||
catch (final NumberFormatException ex) { |
||||
final String pattern = getSACParserMessages().getString("invalidColor"); |
||||
throw new CSSParseException(MessageFormat.format( |
||||
pattern, new Object[] {t}), |
||||
getInputSource().getURI(), t.beginLine, |
||||
t.beginColumn, ex); |
||||
} |
||||
} |
||||
|
||||
int intValue(final char op, final String s) { |
||||
final int result = Integer.parseInt(s); |
||||
if (op == '-') { |
||||
return -1 * result; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
float floatValue(final char op, final String s) { |
||||
final float result = Float.parseFloat(s); |
||||
if (op == '-') { |
||||
return -1 * result; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
int getLastNumPos(final String s) { |
||||
int i = 0; |
||||
for ( ; i < s.length(); i++) { |
||||
if (NUM_CHARS.indexOf(s.charAt(i)) < 0) { |
||||
break; |
||||
} |
||||
} |
||||
return i - 1; |
||||
} |
||||
|
||||
/** |
||||
* Unescapes escaped characters in the specified string, according to the |
||||
* <a href="http://www.w3.org/TR/CSS21/syndata.html#escaped-characters">CSS specification</a>. |
||||
* |
||||
* This could be done directly in the parser, but portions of the lexer would have to be moved |
||||
* to the parser, meaning that the grammar would no longer match the standard grammar specified |
||||
* by the W3C. This would make the parser and lexer much less maintainable. |
||||
*/ |
||||
public String unescape(final String s, final boolean unescapeDoubleQuotes) { |
||||
if (s == null) { |
||||
return s; |
||||
} |
||||
|
||||
// avoid creation of new string if possible
|
||||
StringBuilder buf = null; |
||||
int index = -1; |
||||
int len = s.length(); |
||||
len--; |
||||
if (unescapeDoubleQuotes) { |
||||
while (index < len) { |
||||
final char c = s.charAt(++index); |
||||
|
||||
if (c == '\\' || (c == '\"')) { |
||||
buf = new StringBuilder(len); |
||||
buf.append(s.substring(0, index)); |
||||
index--; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
else { |
||||
while (index < len) { |
||||
if ('\\' == s.charAt(++index)) { |
||||
buf = new StringBuilder(len); |
||||
buf.append(s.substring(0, index)); |
||||
index--; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (null == buf) { |
||||
return s; |
||||
} |
||||
|
||||
// ok, we have to construct a new string
|
||||
int numValue = -1; |
||||
int hexval; |
||||
int digitCount = 0; |
||||
|
||||
while (index < len) { |
||||
final char c = s.charAt(++index); |
||||
|
||||
if (numValue > -1) { |
||||
hexval = hexval(c); |
||||
if (hexval != -1) { |
||||
numValue = (numValue * 16) + hexval; |
||||
if (++digitCount < 6) { |
||||
continue; |
||||
} |
||||
|
||||
if (numValue > 0xFFFF || numValue == 0) { |
||||
numValue = 0xFFFD; |
||||
} |
||||
buf.append((char) numValue); |
||||
numValue = -1; |
||||
continue; |
||||
} |
||||
|
||||
if (digitCount > 0) { |
||||
if (numValue > 0xFFFF || numValue == 0) { |
||||
numValue = 0xFFFD; |
||||
} |
||||
|
||||
buf.append((char) numValue); |
||||
|
||||
if (c == ' ' || c == '\t') { |
||||
numValue = -1; |
||||
continue; |
||||
} |
||||
} |
||||
|
||||
numValue = -1; |
||||
if (digitCount == 0 && c == '\\') { |
||||
buf.append('\\'); |
||||
continue; |
||||
} |
||||
|
||||
if (c == '\n' || c == '\f') { |
||||
continue; |
||||
} |
||||
if (c == '\r') { |
||||
if (index < len) { |
||||
if (s.charAt(index + 1) == '\n') { |
||||
index++; |
||||
} |
||||
} |
||||
continue; |
||||
} |
||||
} |
||||
|
||||
if (c == '\\') { |
||||
numValue = 0; |
||||
digitCount = 0; |
||||
continue; |
||||
} |
||||
|
||||
if (c == '\"' && !unescapeDoubleQuotes) { |
||||
buf.append('\\'); |
||||
} |
||||
|
||||
buf.append(c); |
||||
} |
||||
|
||||
if (numValue > -1) { |
||||
if (digitCount == 0) { |
||||
buf.append('\\'); |
||||
} |
||||
else { |
||||
if (numValue > 0xFFFF || numValue == 0) { |
||||
numValue = 0xFFFD; |
||||
} |
||||
buf.append((char) numValue); |
||||
} |
||||
} |
||||
|
||||
return buf.toString(); |
||||
} |
||||
|
||||
private static int hexval(final char c) { |
||||
switch (c) { |
||||
case '0' : |
||||
return 0; |
||||
case '1' : |
||||
return 1; |
||||
case '2' : |
||||
return 2; |
||||
case '3' : |
||||
return 3; |
||||
case '4' : |
||||
return 4; |
||||
case '5' : |
||||
return 5; |
||||
case '6' : |
||||
return 6; |
||||
case '7' : |
||||
return 7; |
||||
case '8' : |
||||
return 8; |
||||
case '9' : |
||||
return 9; |
||||
|
||||
case 'a' : |
||||
case 'A' : |
||||
return 10; |
||||
case 'b' : |
||||
case 'B' : |
||||
return 11; |
||||
case 'c' : |
||||
case 'C' : |
||||
return 12; |
||||
case 'd' : |
||||
case 'D' : |
||||
return 13; |
||||
case 'e' : |
||||
case 'E' : |
||||
return 14; |
||||
case 'f' : |
||||
case 'F' : |
||||
return 15; |
||||
default : |
||||
return -1; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,506 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.io.IOException; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.lang.reflect.Method; |
||||
import java.util.Stack; |
||||
import java.util.logging.Logger; |
||||
|
||||
import com.fr.third.steadystate.css.dom.CSSImportRuleImpl; |
||||
import com.fr.third.steadystate.css.sac.DocumentHandlerExt; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.ErrorHandler; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.Parser; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.css.sac.SelectorList; |
||||
import org.w3c.css.sac.helpers.ParserFactory; |
||||
import org.w3c.dom.DOMException; |
||||
import org.w3c.dom.Node; |
||||
import org.w3c.dom.css.CSSRule; |
||||
import org.w3c.dom.css.CSSStyleDeclaration; |
||||
import org.w3c.dom.css.CSSStyleSheet; |
||||
import org.w3c.dom.css.CSSValue; |
||||
|
||||
import com.fr.third.steadystate.css.dom.CSSCharsetRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSFontFaceRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSMediaRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSOMObject; |
||||
import com.fr.third.steadystate.css.dom.CSSPageRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSRuleListImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSStyleDeclarationImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSStyleRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSStyleSheetImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSUnknownRuleImpl; |
||||
import com.fr.third.steadystate.css.dom.CSSValueImpl; |
||||
import com.fr.third.steadystate.css.dom.MediaListImpl; |
||||
import com.fr.third.steadystate.css.dom.Property; |
||||
import com.fr.third.steadystate.css.userdata.UserDataConstants; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
*/ |
||||
public class CSSOMParser { |
||||
|
||||
private static final Object LOCK = new Object(); |
||||
private static final String DEFAULT_PARSER = "com.steadystate.css.parser.SACParserCSS21"; |
||||
|
||||
private static String LastFailed_; |
||||
|
||||
private Parser parser_; |
||||
private CSSStyleSheetImpl parentStyleSheet_; |
||||
|
||||
/** Creates new CSSOMParser */ |
||||
public CSSOMParser() { |
||||
this (null); |
||||
} |
||||
|
||||
/** |
||||
* Creates new CSSOMParser. |
||||
* |
||||
* @param parser the SAC Parser |
||||
*/ |
||||
public CSSOMParser(final Parser parser) { |
||||
synchronized (LOCK) { |
||||
if (null != parser) { |
||||
System.setProperty("org.w3c.css.sac.parser", parser.getClass().getCanonicalName()); |
||||
parser_ = parser; |
||||
return; |
||||
} |
||||
|
||||
// no parser provided, determine the correct one
|
||||
String currentParser = System.getProperty("org.w3c.css.sac.parser"); |
||||
try { |
||||
// use the direct method if we already failed once before
|
||||
if (null != LastFailed_ && LastFailed_.equals(currentParser)) { |
||||
parser_ = new SACParserCSS21(); |
||||
} |
||||
else { |
||||
if (null == currentParser) { |
||||
System.setProperty("org.w3c.css.sac.parser", DEFAULT_PARSER); |
||||
currentParser = DEFAULT_PARSER; |
||||
} |
||||
final ParserFactory factory = new ParserFactory(); |
||||
parser_ = factory.makeParser(); |
||||
} |
||||
} |
||||
catch (final Exception e) { |
||||
final Logger log = Logger.getLogger("com.steadystate.css"); |
||||
log.warning(e.toString()); |
||||
log.warning("using the default 'SACParserCSS21' instead"); |
||||
log.throwing("CSSOMParser", "consturctor", e); |
||||
LastFailed_ = currentParser; |
||||
parser_ = new SACParserCSS21(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void setErrorHandler(final ErrorHandler eh) { |
||||
parser_.setErrorHandler(eh); |
||||
} |
||||
|
||||
/** |
||||
* Parses a SAC input source into a CSSOM style sheet. |
||||
* |
||||
* @param source the SAC input source |
||||
* @param ownerNode the owner node (see the definition of |
||||
* <code>ownerNode</code> in org.w3c.dom.css.StyleSheet) |
||||
* @param href the href (see the definition of <code>href</code> in |
||||
* org.w3c.dom.css.StyleSheet) |
||||
* @return the CSSOM style sheet |
||||
* @throws IOException if the underlying SAC parser throws an IOException |
||||
*/ |
||||
public CSSStyleSheet parseStyleSheet(final InputSource source, |
||||
final Node ownerNode, final String href) throws IOException { |
||||
final CSSOMHandler handler = new CSSOMHandler(); |
||||
handler.setOwnerNode(ownerNode); |
||||
handler.setHref(href); |
||||
parser_.setDocumentHandler(handler); |
||||
parser_.parseStyleSheet(source); |
||||
final Object o = handler.getRoot(); |
||||
if (o instanceof CSSStyleSheet) { |
||||
return (CSSStyleSheet) o; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Parses a SAC input source into a CSSOM style declaration. |
||||
* |
||||
* @param source the SAC input source |
||||
* @return the CSSOM style declaration |
||||
* @throws IOException if the underlying SAC parser throws an IOException |
||||
*/ |
||||
public CSSStyleDeclaration parseStyleDeclaration(final InputSource source) throws IOException { |
||||
final CSSStyleDeclarationImpl sd = new CSSStyleDeclarationImpl(null); |
||||
parseStyleDeclaration(sd, source); |
||||
return sd; |
||||
} |
||||
|
||||
public void parseStyleDeclaration(final CSSStyleDeclaration sd, final InputSource source) throws IOException { |
||||
final Stack<Object> nodeStack = new Stack<Object>(); |
||||
nodeStack.push(sd); |
||||
final CSSOMHandler handler = new CSSOMHandler(nodeStack); |
||||
parser_.setDocumentHandler(handler); |
||||
parser_.parseStyleDeclaration(source); |
||||
} |
||||
|
||||
public CSSValue parsePropertyValue(final InputSource source) throws IOException { |
||||
final CSSOMHandler handler = new CSSOMHandler(); |
||||
parser_.setDocumentHandler(handler); |
||||
final LexicalUnit lu = parser_.parsePropertyValue(source); |
||||
if (null == lu) { |
||||
return null; |
||||
} |
||||
return new CSSValueImpl(lu); |
||||
} |
||||
|
||||
public CSSRule parseRule(final InputSource source) throws IOException { |
||||
final CSSOMHandler handler = new CSSOMHandler(); |
||||
parser_.setDocumentHandler(handler); |
||||
parser_.parseRule(source); |
||||
return (CSSRule) handler.getRoot(); |
||||
} |
||||
|
||||
public SelectorList parseSelectors(final InputSource source) throws IOException { |
||||
final HandlerBase handler = new HandlerBase(); |
||||
parser_.setDocumentHandler(handler); |
||||
return parser_.parseSelectors(source); |
||||
} |
||||
|
||||
public SACMediaList parseMedia(final InputSource source) throws IOException { |
||||
final HandlerBase handler = new HandlerBase(); |
||||
parser_.setDocumentHandler(handler); |
||||
if (parser_ instanceof AbstractSACParser) { |
||||
return ((AbstractSACParser) parser_).parseMedia(source); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void setParentStyleSheet(final CSSStyleSheetImpl parentStyleSheet) { |
||||
parentStyleSheet_ = parentStyleSheet; |
||||
} |
||||
|
||||
protected CSSStyleSheetImpl getParentStyleSheet() { |
||||
return parentStyleSheet_; |
||||
} |
||||
|
||||
class CSSOMHandler implements DocumentHandlerExt { |
||||
private Stack<Object> nodeStack_; |
||||
private Object root_; |
||||
private Node ownerNode_; |
||||
private String href_; |
||||
|
||||
private Node getOwnerNode() { |
||||
return ownerNode_; |
||||
} |
||||
|
||||
private void setOwnerNode(final Node ownerNode) { |
||||
ownerNode_ = ownerNode; |
||||
} |
||||
|
||||
private String getHref() { |
||||
return href_; |
||||
} |
||||
|
||||
private void setHref(final String href) { |
||||
href_ = href; |
||||
} |
||||
|
||||
CSSOMHandler(final Stack<Object> nodeStack) { |
||||
nodeStack_ = nodeStack; |
||||
} |
||||
|
||||
CSSOMHandler() { |
||||
nodeStack_ = new Stack<Object>(); |
||||
} |
||||
|
||||
Object getRoot() { |
||||
return root_; |
||||
} |
||||
|
||||
public void startDocument(final InputSource source) throws CSSException { |
||||
if (nodeStack_.empty()) { |
||||
final CSSStyleSheetImpl ss = new CSSStyleSheetImpl(); |
||||
CSSOMParser.this.setParentStyleSheet(ss); |
||||
ss.setOwnerNode(getOwnerNode()); |
||||
ss.setBaseUri(source.getURI()); |
||||
ss.setHref(getHref()); |
||||
ss.setMediaText(source.getMedia()); |
||||
ss.setTitle(source.getTitle()); |
||||
// Create the rule list
|
||||
final CSSRuleListImpl rules = new CSSRuleListImpl(); |
||||
ss.setCssRules(rules); |
||||
nodeStack_.push(ss); |
||||
nodeStack_.push(rules); |
||||
} |
||||
else { |
||||
// Error
|
||||
} |
||||
} |
||||
|
||||
public void endDocument(final InputSource source) throws CSSException { |
||||
// Pop the rule list and style sheet nodes
|
||||
nodeStack_.pop(); |
||||
root_ = nodeStack_.pop(); |
||||
} |
||||
|
||||
public void comment(final String text) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule) throws CSSException { |
||||
ignorableAtRule(atRule, null); |
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule, final Locator locator) throws CSSException { |
||||
// Create the unknown rule and add it to the rule list
|
||||
final CSSUnknownRuleImpl ir = new CSSUnknownRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), |
||||
atRule); |
||||
addLocator(locator, ir); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(ir); |
||||
} |
||||
else { |
||||
root_ = ir; |
||||
} |
||||
} |
||||
|
||||
public void namespaceDeclaration(final String prefix, final String uri) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void charset(final String characterEncoding, final Locator locator) |
||||
throws CSSException { |
||||
final CSSCharsetRuleImpl cr = new CSSCharsetRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), |
||||
characterEncoding); |
||||
addLocator(locator, cr); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(cr); |
||||
} |
||||
else { |
||||
root_ = cr; |
||||
} |
||||
} |
||||
|
||||
public void importStyle( |
||||
final String uri, |
||||
final SACMediaList media, |
||||
final String defaultNamespaceURI) throws CSSException { |
||||
importStyle(uri, media, defaultNamespaceURI, null); |
||||
} |
||||
|
||||
public void importStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI, final Locator locator) throws CSSException { |
||||
// Create the import rule and add it to the rule list
|
||||
final CSSImportRuleImpl ir = new CSSImportRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), |
||||
uri, |
||||
new MediaListImpl(media)); |
||||
addLocator(locator, ir); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(ir); |
||||
} |
||||
else { |
||||
root_ = ir; |
||||
} |
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media) throws CSSException { |
||||
startMedia(media, null); |
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media, final Locator locator) throws CSSException { |
||||
final MediaListImpl ml = new MediaListImpl(media); |
||||
// Create the media rule and add it to the rule list
|
||||
final CSSMediaRuleImpl mr = new CSSMediaRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), |
||||
ml); |
||||
addLocator(locator, mr); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(mr); |
||||
} |
||||
|
||||
// Create the rule list
|
||||
final CSSRuleListImpl rules = new CSSRuleListImpl(); |
||||
mr.setRuleList(rules); |
||||
nodeStack_.push(mr); |
||||
nodeStack_.push(rules); |
||||
} |
||||
|
||||
public void endMedia(final SACMediaList media) throws CSSException { |
||||
// Pop the rule list and media rule nodes
|
||||
nodeStack_.pop(); |
||||
root_ = nodeStack_.pop(); |
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage) throws CSSException { |
||||
startPage(name, pseudoPage, null); |
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage, final Locator locator) |
||||
throws CSSException { |
||||
// Create the page rule and add it to the rule list
|
||||
final CSSPageRuleImpl pr = new CSSPageRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), pseudoPage); |
||||
addLocator(locator, pr); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(pr); |
||||
} |
||||
|
||||
// Create the style declaration
|
||||
final CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(pr); |
||||
pr.setStyle(decl); |
||||
nodeStack_.push(pr); |
||||
nodeStack_.push(decl); |
||||
} |
||||
|
||||
public void endPage(final String name, final String pseudoPage) throws CSSException { |
||||
// Pop both the style declaration and the page rule nodes
|
||||
nodeStack_.pop(); |
||||
root_ = nodeStack_.pop(); |
||||
} |
||||
|
||||
public void startFontFace() throws CSSException { |
||||
startFontFace(null); |
||||
} |
||||
|
||||
public void startFontFace(final Locator locator) throws CSSException { |
||||
// Create the font face rule and add it to the rule list
|
||||
final CSSFontFaceRuleImpl ffr = new CSSFontFaceRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule()); |
||||
addLocator(locator, ffr); |
||||
if (!nodeStack_.empty()) { |
||||
((CSSRuleListImpl) nodeStack_.peek()).add(ffr); |
||||
} |
||||
|
||||
// Create the style declaration
|
||||
final CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(ffr); |
||||
ffr.setStyle(decl); |
||||
nodeStack_.push(ffr); |
||||
nodeStack_.push(decl); |
||||
} |
||||
|
||||
public void endFontFace() throws CSSException { |
||||
// Pop both the style declaration and the font face rule nodes
|
||||
nodeStack_.pop(); |
||||
root_ = nodeStack_.pop(); |
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors) throws CSSException { |
||||
startSelector(selectors, null); |
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors, final Locator locator) throws CSSException { |
||||
// Create the style rule and add it to the rule list
|
||||
final CSSStyleRuleImpl sr = new CSSStyleRuleImpl( |
||||
CSSOMParser.this.getParentStyleSheet(), |
||||
getParentRule(), selectors); |
||||
addLocator(locator, sr); |
||||
if (!nodeStack_.empty()) { |
||||
final Object o = nodeStack_.peek(); |
||||
((CSSRuleListImpl) o).add(sr); |
||||
} |
||||
|
||||
// Create the style declaration
|
||||
final CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(sr); |
||||
sr.setStyle(decl); |
||||
nodeStack_.push(sr); |
||||
nodeStack_.push(decl); |
||||
} |
||||
|
||||
public void endSelector(final SelectorList selectors) throws CSSException { |
||||
// Pop both the style declaration and the style rule nodes
|
||||
nodeStack_.pop(); |
||||
root_ = nodeStack_.pop(); |
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important) throws CSSException { |
||||
property(name, value, important, null); |
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important, |
||||
final Locator locator) { |
||||
final CSSStyleDeclarationImpl decl = (CSSStyleDeclarationImpl) nodeStack_.peek(); |
||||
try { |
||||
final Property property = new Property(name, new CSSValueImpl(value), important); |
||||
addLocator(locator, property); |
||||
decl.addProperty(property); |
||||
} |
||||
catch (final DOMException e) { |
||||
if (parser_ instanceof AbstractSACParser) { |
||||
final AbstractSACParser parser = (AbstractSACParser) parser_; |
||||
parser.getErrorHandler().error(parser.toCSSParseException(e)); |
||||
|
||||
} |
||||
// call ErrorHandler?
|
||||
} |
||||
} |
||||
|
||||
private CSSRule getParentRule() { |
||||
if (!nodeStack_.empty() && nodeStack_.size() > 1) { |
||||
final Object node = nodeStack_.get(nodeStack_.size() - 2); |
||||
if (node instanceof CSSRule) { |
||||
return (CSSRule) node; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private void addLocator(Locator locator, final CSSOMObject cssomObject) { |
||||
if (locator == null) { |
||||
final Parser parser = CSSOMParser.this.parser_; |
||||
try { |
||||
final Method getLocatorMethod = parser.getClass().getMethod( |
||||
"getLocator", (Class[]) null); |
||||
locator = (Locator) getLocatorMethod.invoke( |
||||
parser, (Object[]) null); |
||||
} |
||||
catch (final SecurityException e) { |
||||
// TODO
|
||||
} |
||||
catch (final NoSuchMethodException e) { |
||||
// TODO
|
||||
} |
||||
catch (final IllegalArgumentException e) { |
||||
// TODO
|
||||
} |
||||
catch (final IllegalAccessException e) { |
||||
// TODO
|
||||
} |
||||
catch (final InvocationTargetException e) { |
||||
// TODO
|
||||
} |
||||
} |
||||
if (locator != null) { |
||||
cssomObject.setUserData(UserDataConstants.KEY_LOCATOR, locator); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,120 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. CharStream.java Version 7.0 */ |
||||
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** |
||||
* This interface describes a character stream that maintains line and |
||||
* column number positions of the characters. It also has the capability |
||||
* to backup the stream to some extent. An implementation of this |
||||
* interface is used in the TokenManager implementation generated by |
||||
* JavaCCParser. |
||||
* |
||||
* All the methods except backup can be implemented in any fashion. backup |
||||
* needs to be implemented correctly for the correct operation of the lexer. |
||||
* Rest of the methods are all used to get information like line number, |
||||
* column number and the String that constitutes a token and are not used |
||||
* by the lexer. Hence their implementation won't affect the generated lexer's |
||||
* operation. |
||||
*/ |
||||
|
||||
public |
||||
interface CharStream { |
||||
|
||||
/** |
||||
* Returns the next character from the selected input. The method |
||||
* of selecting the input is the responsibility of the class
|
||||
* implementing this interface. Can throw any java.io.IOException. |
||||
*/ |
||||
char readChar() throws java.io.IOException; |
||||
|
||||
@Deprecated |
||||
/** |
||||
* Returns the column position of the character last read. |
||||
* @deprecated |
||||
* @see #getEndColumn |
||||
*/ |
||||
int getColumn(); |
||||
|
||||
@Deprecated |
||||
/** |
||||
* Returns the line number of the character last read. |
||||
* @deprecated |
||||
* @see #getEndLine |
||||
*/ |
||||
int getLine(); |
||||
|
||||
/** |
||||
* Returns the column number of the last character for current token (being |
||||
* matched after the last call to BeginTOken). |
||||
*/ |
||||
int getEndColumn(); |
||||
|
||||
/** |
||||
* Returns the line number of the last character for current token (being |
||||
* matched after the last call to BeginTOken). |
||||
*/ |
||||
int getEndLine(); |
||||
|
||||
/** |
||||
* Returns the column number of the first character for current token (being |
||||
* matched after the last call to BeginTOken). |
||||
*/ |
||||
int getBeginColumn(); |
||||
|
||||
/** |
||||
* Returns the line number of the first character for current token (being |
||||
* matched after the last call to BeginTOken). |
||||
*/ |
||||
int getBeginLine(); |
||||
|
||||
/** |
||||
* Backs up the input stream by amount steps. Lexer calls this method if it |
||||
* had already read some characters, but could not use them to match a |
||||
* (longer) token. So, they will be used again as the prefix of the next |
||||
* token and it is the implemetation's responsibility to do this right. |
||||
*/ |
||||
void backup(int amount); |
||||
|
||||
/** |
||||
* Returns the next character that marks the beginning of the next token. |
||||
* All characters must remain in the buffer between two successive calls |
||||
* to this method to implement backup correctly. |
||||
*/ |
||||
char BeginToken() throws java.io.IOException; |
||||
|
||||
/** |
||||
* Returns a string made up of characters from the marked token beginning |
||||
* to the current buffer position. Implementations have the choice of returning |
||||
* anything that they want to. For example, for efficiency, one might decide |
||||
* to just return null, which is a valid implementation. |
||||
*/ |
||||
String GetImage(); |
||||
|
||||
/** |
||||
* Returns an array of characters that make up the suffix of length 'len' for |
||||
* the currently matched token. This is used to build up the matched string |
||||
* for use in actions in the case of MORE. A simple and inefficient |
||||
* implementation of this is as follows : |
||||
* |
||||
* { |
||||
* String t = GetImage(); |
||||
* return t.substring(t.length() - len, t.length()).toCharArray(); |
||||
* } |
||||
*/ |
||||
char[] GetSuffix(int len); |
||||
|
||||
/** |
||||
* The lexer calls this function to indicate that it is done with the stream |
||||
* and hence implementations can free any resources held by this class. |
||||
* Again, the body of this function can be just empty and it will not |
||||
* affect the lexer's operation. |
||||
*/ |
||||
void Done(); |
||||
|
||||
|
||||
void setTabSize(int i); |
||||
int getTabSize(); |
||||
boolean getTrackLineColumn(); |
||||
void setTrackLineColumn(boolean trackLineColumn); |
||||
} |
||||
/* JavaCC - OriginalChecksum=5226f2ae40a0ca5a5d5c722f00281ba2 (do not edit this line) */ |
@ -0,0 +1,365 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ |
||||
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** |
||||
* An implementation of interface CharStream. |
||||
* There is no processing of escaping in this class because the escaping is |
||||
* part of the parser. CSS has some strange rules about that, so processing |
||||
* unicode escapes in this class is too early. |
||||
*/ |
||||
|
||||
public final class CssCharStream implements CharStream |
||||
{ |
||||
/** Whether parser is static. */ |
||||
public static final boolean staticFlag = false; |
||||
|
||||
private static final int BUFFER_SIZE = 2048; |
||||
|
||||
int bufsize; |
||||
int available; |
||||
int tokenBegin; |
||||
/** Position in buffer. */ |
||||
public int bufpos = -1; |
||||
private int bufline[]; |
||||
private int bufcolumn[]; |
||||
|
||||
private int column = 0; |
||||
private int line = 1; |
||||
|
||||
private boolean prevCharIsCR = false; |
||||
private boolean prevCharIsLF = false; |
||||
|
||||
private java.io.Reader inputStream; |
||||
|
||||
private char[] buffer; |
||||
private int maxNextCharInd = 0; |
||||
private int inBuf = 0; |
||||
|
||||
private int tabSize = 1; |
||||
private boolean trackLineColumn = true; |
||||
|
||||
private void ExpandBuff(boolean wrapAround) |
||||
{ |
||||
char[] newbuffer = new char[bufsize + BUFFER_SIZE]; |
||||
int newbufline[] = new int[bufsize + BUFFER_SIZE]; |
||||
int newbufcolumn[] = new int[bufsize + BUFFER_SIZE]; |
||||
|
||||
try |
||||
{ |
||||
if (wrapAround) |
||||
{ |
||||
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); |
||||
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); |
||||
buffer = newbuffer; |
||||
|
||||
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); |
||||
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); |
||||
bufline = newbufline; |
||||
|
||||
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); |
||||
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); |
||||
bufcolumn = newbufcolumn; |
||||
|
||||
maxNextCharInd = (bufpos += (bufsize - tokenBegin)); |
||||
} |
||||
else |
||||
{ |
||||
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); |
||||
buffer = newbuffer; |
||||
|
||||
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); |
||||
bufline = newbufline; |
||||
|
||||
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); |
||||
bufcolumn = newbufcolumn; |
||||
|
||||
maxNextCharInd = (bufpos -= tokenBegin); |
||||
} |
||||
} |
||||
catch (Throwable t) |
||||
{ |
||||
throw new Error(t.getMessage()); |
||||
} |
||||
|
||||
bufsize += BUFFER_SIZE; |
||||
available = bufsize; |
||||
tokenBegin = 0; |
||||
} |
||||
|
||||
private final void FillBuff() throws java.io.IOException |
||||
{ |
||||
if (maxNextCharInd == available) |
||||
{ |
||||
if (available == bufsize) |
||||
{ |
||||
if (tokenBegin > BUFFER_SIZE) |
||||
{ |
||||
bufpos = maxNextCharInd = 0; |
||||
available = tokenBegin; |
||||
} |
||||
else if (tokenBegin < 0) |
||||
bufpos = maxNextCharInd = 0; |
||||
else |
||||
ExpandBuff(false); |
||||
} |
||||
else if (available > tokenBegin) |
||||
available = bufsize; |
||||
else if ((tokenBegin - available) < BUFFER_SIZE) |
||||
ExpandBuff(true); |
||||
else |
||||
available = tokenBegin; |
||||
} |
||||
|
||||
int i; |
||||
try { |
||||
if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) |
||||
{ |
||||
inputStream.close(); |
||||
throw new java.io.IOException(); |
||||
} |
||||
|
||||
maxNextCharInd += i; |
||||
return; |
||||
} |
||||
catch(java.io.IOException e) { |
||||
--bufpos; |
||||
backup(0); |
||||
if (tokenBegin == -1) |
||||
tokenBegin = bufpos; |
||||
throw e; |
||||
} |
||||
} |
||||
|
||||
/** Start. */ |
||||
public final char BeginToken() throws java.io.IOException |
||||
{ |
||||
tokenBegin = -1; |
||||
char c = readChar(); |
||||
tokenBegin = bufpos; |
||||
|
||||
return c; |
||||
} |
||||
|
||||
private final void UpdateLineColumn(char c) |
||||
{ |
||||
column++; |
||||
|
||||
if (prevCharIsLF) |
||||
{ |
||||
prevCharIsLF = false; |
||||
line += (column = 1); |
||||
} |
||||
else if (prevCharIsCR) |
||||
{ |
||||
prevCharIsCR = false; |
||||
if (c == '\n') |
||||
{ |
||||
prevCharIsLF = true; |
||||
} |
||||
else |
||||
line += (column = 1); |
||||
} |
||||
|
||||
switch (c) |
||||
{ |
||||
case '\r' : |
||||
prevCharIsCR = true; |
||||
break; |
||||
case '\n' : |
||||
prevCharIsLF = true; |
||||
break; |
||||
// case '\t' :
|
||||
// column--;
|
||||
// column += (8 - (column & 07));
|
||||
// break;
|
||||
default : |
||||
break; |
||||
} |
||||
|
||||
bufline[bufpos] = line; |
||||
bufcolumn[bufpos] = column; |
||||
} |
||||
|
||||
/** Read a character. */ |
||||
public final char readChar() throws java.io.IOException |
||||
{ |
||||
if (inBuf > 0) |
||||
{ |
||||
--inBuf; |
||||
|
||||
if (++bufpos == bufsize) |
||||
bufpos = 0; |
||||
|
||||
return buffer[bufpos]; |
||||
} |
||||
|
||||
if (++bufpos >= maxNextCharInd) |
||||
FillBuff(); |
||||
|
||||
char c = buffer[bufpos]; |
||||
|
||||
UpdateLineColumn(c); |
||||
return c; |
||||
} |
||||
|
||||
@Deprecated |
||||
/** |
||||
* @deprecated |
||||
* @see #getEndColumn |
||||
*/ |
||||
public final int getColumn() { |
||||
return bufcolumn[bufpos]; |
||||
} |
||||
|
||||
@Deprecated |
||||
/** |
||||
* @deprecated |
||||
* @see #getEndLine |
||||
*/ |
||||
public final int getLine() { |
||||
return bufline[bufpos]; |
||||
} |
||||
|
||||
/** Get token end column number. */ |
||||
public final int getEndColumn() { |
||||
return bufcolumn[bufpos]; |
||||
} |
||||
|
||||
/** Get token end line number. */ |
||||
public final int getEndLine() { |
||||
return bufline[bufpos]; |
||||
} |
||||
|
||||
/** Get token beginning column number. */ |
||||
public final int getBeginColumn() { |
||||
return bufcolumn[tokenBegin]; |
||||
} |
||||
|
||||
/** Get token beginning line number. */ |
||||
public final int getBeginLine() { |
||||
return bufline[tokenBegin]; |
||||
} |
||||
|
||||
/** Backup a number of characters. */ |
||||
public final void backup(int amount) { |
||||
inBuf += amount; |
||||
if ((bufpos -= amount) < 0) |
||||
bufpos += bufsize; |
||||
} |
||||
|
||||
/** Constructor. */ |
||||
public CssCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) |
||||
{ |
||||
inputStream = dstream; |
||||
line = startline; |
||||
column = startcolumn - 1; |
||||
|
||||
available = bufsize = buffersize; |
||||
buffer = new char[buffersize]; |
||||
bufline = new int[buffersize]; |
||||
bufcolumn = new int[buffersize]; |
||||
} |
||||
|
||||
/** Constructor. */ |
||||
public CssCharStream(java.io.Reader dstream, int startline, |
||||
int startcolumn) |
||||
{ |
||||
this(dstream, startline, startcolumn, 4096); |
||||
} |
||||
|
||||
/** Get token literal value. */ |
||||
public final String GetImage() |
||||
{ |
||||
if (bufpos >= tokenBegin) |
||||
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); |
||||
return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1); |
||||
} |
||||
|
||||
/** Get the suffix. */ |
||||
public final char[] GetSuffix(int len) |
||||
{ |
||||
char[] ret = new char[len]; |
||||
|
||||
if ((bufpos + 1) >= len) |
||||
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); |
||||
else |
||||
{ |
||||
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1); |
||||
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
/** Reset buffer when finished. */ |
||||
public void Done() |
||||
{ |
||||
buffer = null; |
||||
bufline = null; |
||||
bufcolumn = null; |
||||
} |
||||
|
||||
/** |
||||
* Method to adjust line and column numbers for the start of a token. |
||||
*/ |
||||
public void adjustBeginLineColumn(int newLine, int newCol) |
||||
{ |
||||
int start = tokenBegin; |
||||
int len; |
||||
|
||||
if (bufpos >= tokenBegin) |
||||
{ |
||||
len = bufpos - tokenBegin + inBuf + 1; |
||||
} |
||||
else |
||||
{ |
||||
len = bufsize - tokenBegin + bufpos + 1 + inBuf; |
||||
} |
||||
|
||||
int i = 0, j = 0, k = 0; |
||||
int nextColDiff = 0, columnDiff = 0; |
||||
|
||||
while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) |
||||
{ |
||||
bufline[j] = newLine; |
||||
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; |
||||
bufcolumn[j] = newCol + columnDiff; |
||||
columnDiff = nextColDiff; |
||||
i++; |
||||
} |
||||
|
||||
if (i < len) |
||||
{ |
||||
bufline[j] = newLine++; |
||||
bufcolumn[j] = newCol + columnDiff; |
||||
|
||||
while (i++ < len) |
||||
{ |
||||
if (bufline[j = start % bufsize] != bufline[++start % bufsize]) |
||||
bufline[j] = newLine++; |
||||
else |
||||
bufline[j] = newLine; |
||||
} |
||||
} |
||||
|
||||
line = bufline[j]; |
||||
column = bufcolumn[j]; |
||||
} |
||||
|
||||
public void setTabSize(int i) { |
||||
tabSize = i; |
||||
} |
||||
|
||||
public int getTabSize() { |
||||
return tabSize; |
||||
} |
||||
|
||||
public boolean getTrackLineColumn() { |
||||
return trackLineColumn; |
||||
} |
||||
|
||||
public void setTrackLineColumn(boolean tlc) { |
||||
trackLineColumn = tlc; |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.util.ListResourceBundle; |
||||
|
||||
/** |
||||
* ExceptionResource. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class ExceptionResource extends ListResourceBundle { |
||||
|
||||
@Override |
||||
public Object[][] getContents() { |
||||
return contents; |
||||
} |
||||
|
||||
static final Object[][] contents = { |
||||
{"s0", "Syntax error"}, |
||||
{"s1", "Index out of bounds error"}, |
||||
{"s2", "This style sheet is read only"}, |
||||
{"s3", "The text does not represent an unknown rule"}, |
||||
{"s4", "The text does not represent a style rule"}, |
||||
{"s5", "The text does not represent a charset rule"}, |
||||
{"s6", "The text does not represent an import rule"}, |
||||
{"s7", "The text does not represent a media rule"}, |
||||
{"s8", "The text does not represent a font face rule"}, |
||||
{"s9", "The text does not represent a page rule"}, |
||||
{"s10", "This isn't a Float type"}, |
||||
{"s11", "This isn't a String type"}, |
||||
{"s12", "This isn't a Counter type"}, |
||||
{"s13", "This isn't a Rect type"}, |
||||
{"s14", "This isn't an RGBColor type"}, |
||||
{"s15", "A charset rule must be the first rule"}, |
||||
{"s16", "A charset rule already exists"}, |
||||
{"s17", "An import rule must preceed all other rules"}, |
||||
{"s18", "The specified type was not found"}, |
||||
{"s20", "Can't insert a rule before the last charset or import rule"} |
||||
}; |
||||
} |
@ -0,0 +1,162 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import com.fr.third.steadystate.css.sac.DocumentHandlerExt; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CSSParseException; |
||||
import org.w3c.css.sac.ErrorHandler; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.css.sac.SelectorList; |
||||
|
||||
/** |
||||
* Empty implementation of the DocumentHandlerExt interface. |
||||
*/ |
||||
public class HandlerBase implements DocumentHandlerExt, ErrorHandler { |
||||
|
||||
public void startDocument(final InputSource source) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void endDocument(final InputSource source) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void comment(final String text) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void namespaceDeclaration(final String prefix, final String uri) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void importStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void importStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void endMedia(final SACMediaList media) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void endPage(final String name, final String pseudoPage) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startFontFace() throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startFontFace(final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void endFontFace() throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void endSelector(final SelectorList selectors) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important, final Locator locator) { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void charset(final String characterEncoding, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void warning(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
|
||||
public void error(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
|
||||
public void fatalError(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
} |
@ -0,0 +1,780 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Implementation of {@link LexicalUnit}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class LexicalUnitImpl extends LocatableImpl implements LexicalUnit, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -7260032046960116891L; |
||||
|
||||
private short lexicalUnitType_; |
||||
private LexicalUnit nextLexicalUnit_; |
||||
private LexicalUnit previousLexicalUnit_; |
||||
private float floatValue_; |
||||
private String dimension_; |
||||
private String functionName_; |
||||
private LexicalUnit parameters_; |
||||
private String stringValue_; |
||||
private String sourceStringValue_; |
||||
|
||||
/** cache */ |
||||
private transient String toString_; |
||||
|
||||
public void setLexicalUnitType(final short type) { |
||||
lexicalUnitType_ = type; |
||||
toString_ = null; |
||||
} |
||||
|
||||
public void setNextLexicalUnit(final LexicalUnit next) { |
||||
nextLexicalUnit_ = next; |
||||
} |
||||
|
||||
public void setPreviousLexicalUnit(final LexicalUnit prev) { |
||||
previousLexicalUnit_ = prev; |
||||
} |
||||
|
||||
public void setFloatValue(final float floatVal) { |
||||
floatValue_ = floatVal; |
||||
toString_ = null; |
||||
} |
||||
|
||||
public String getDimension() { |
||||
return dimension_; |
||||
} |
||||
|
||||
public void setDimension(final String dimension) { |
||||
dimension_ = dimension; |
||||
toString_ = null; |
||||
} |
||||
|
||||
public void setFunctionName(final String function) { |
||||
functionName_ = function; |
||||
toString_ = null; |
||||
} |
||||
|
||||
public void setParameters(final LexicalUnit params) { |
||||
parameters_ = params; |
||||
toString_ = null; |
||||
} |
||||
|
||||
public void setStringValue(final String stringVal) { |
||||
stringValue_ = stringVal; |
||||
toString_ = null; |
||||
} |
||||
|
||||
protected LexicalUnitImpl(final LexicalUnit previous, final short type) { |
||||
this(); |
||||
lexicalUnitType_ = type; |
||||
previousLexicalUnit_ = previous; |
||||
if (previousLexicalUnit_ != null) { |
||||
((LexicalUnitImpl) previousLexicalUnit_).nextLexicalUnit_ = this; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Integer |
||||
*/ |
||||
protected LexicalUnitImpl(final LexicalUnit previous, final int value) { |
||||
this(previous, SAC_INTEGER); |
||||
floatValue_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Dimension |
||||
*/ |
||||
protected LexicalUnitImpl(final LexicalUnit previous, final short type, final float value) { |
||||
this(previous, type); |
||||
floatValue_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Unknown dimension |
||||
*/ |
||||
protected LexicalUnitImpl( |
||||
final LexicalUnit previous, |
||||
final short type, |
||||
final String dimension, |
||||
final float value) { |
||||
this(previous, type); |
||||
dimension_ = dimension; |
||||
floatValue_ = value; |
||||
} |
||||
|
||||
/** |
||||
* String |
||||
*/ |
||||
protected LexicalUnitImpl(final LexicalUnit previous, final short type, final String value) { |
||||
this(previous, type); |
||||
stringValue_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Function |
||||
*/ |
||||
protected LexicalUnitImpl( |
||||
final LexicalUnit previous, |
||||
final short type, |
||||
final String name, |
||||
final LexicalUnit params) { |
||||
this(previous, type); |
||||
functionName_ = name; |
||||
parameters_ = params; |
||||
} |
||||
|
||||
protected LexicalUnitImpl(final LexicalUnit previous, final short type, final String name, |
||||
final String stringValue) { |
||||
this(previous, type); |
||||
functionName_ = name; |
||||
stringValue_ = stringValue; |
||||
} |
||||
|
||||
/** |
||||
* Default constructor. |
||||
*/ |
||||
protected LexicalUnitImpl() { |
||||
} |
||||
|
||||
public short getLexicalUnitType() { |
||||
return lexicalUnitType_; |
||||
} |
||||
|
||||
public LexicalUnit getNextLexicalUnit() { |
||||
return nextLexicalUnit_; |
||||
} |
||||
|
||||
public LexicalUnit getPreviousLexicalUnit() { |
||||
return previousLexicalUnit_; |
||||
} |
||||
|
||||
public int getIntegerValue() { |
||||
return (int) floatValue_; |
||||
} |
||||
|
||||
public float getFloatValue() { |
||||
return floatValue_; |
||||
} |
||||
|
||||
public String getDimensionUnitText() { |
||||
switch (lexicalUnitType_) { |
||||
case SAC_EM: |
||||
return "em"; |
||||
case SAC_EX: |
||||
return "ex"; |
||||
case SAC_PIXEL: |
||||
return "px"; |
||||
case SAC_INCH: |
||||
return "in"; |
||||
case SAC_CENTIMETER: |
||||
return "cm"; |
||||
case SAC_MILLIMETER: |
||||
return "mm"; |
||||
case SAC_POINT: |
||||
return "pt"; |
||||
case SAC_PICA: |
||||
return "pc"; |
||||
case SAC_PERCENTAGE: |
||||
return "%"; |
||||
case SAC_DEGREE: |
||||
return "deg"; |
||||
case SAC_GRADIAN: |
||||
return "grad"; |
||||
case SAC_RADIAN: |
||||
return "rad"; |
||||
case SAC_MILLISECOND: |
||||
return "ms"; |
||||
case SAC_SECOND: |
||||
return "s"; |
||||
case SAC_HERTZ: |
||||
return "Hz"; |
||||
case SAC_KILOHERTZ: |
||||
return "kHz"; |
||||
case SAC_DIMENSION: |
||||
return dimension_; |
||||
default: |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
public String getFunctionName() { |
||||
return functionName_; |
||||
} |
||||
|
||||
public LexicalUnit getParameters() { |
||||
return parameters_; |
||||
} |
||||
|
||||
public String getStringValue() { |
||||
return stringValue_; |
||||
} |
||||
|
||||
public String getSourceStringValue() { |
||||
return sourceStringValue_; |
||||
} |
||||
|
||||
public LexicalUnit getSubValues() { |
||||
return parameters_; |
||||
} |
||||
|
||||
/** |
||||
* Same as {@link #getCssText(CSSFormat)} but using the default format. |
||||
* |
||||
* @return the formated string |
||||
*/ |
||||
public String getCssText() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
if (null != toString_ && (format == null || !format.useSourceStringValues())) { |
||||
return toString_; |
||||
} |
||||
|
||||
final StringBuilder sb = new StringBuilder(); |
||||
switch (lexicalUnitType_) { |
||||
case SAC_OPERATOR_COMMA: |
||||
sb.append(","); |
||||
break; |
||||
case SAC_OPERATOR_PLUS: |
||||
sb.append("+"); |
||||
break; |
||||
case SAC_OPERATOR_MINUS: |
||||
sb.append("-"); |
||||
break; |
||||
case SAC_OPERATOR_MULTIPLY: |
||||
sb.append("*"); |
||||
break; |
||||
case SAC_OPERATOR_SLASH: |
||||
sb.append("/"); |
||||
break; |
||||
case SAC_OPERATOR_MOD: |
||||
sb.append("%"); |
||||
break; |
||||
case SAC_OPERATOR_EXP: |
||||
sb.append("^"); |
||||
break; |
||||
case SAC_OPERATOR_LT: |
||||
sb.append("<"); |
||||
break; |
||||
case SAC_OPERATOR_GT: |
||||
sb.append(">"); |
||||
break; |
||||
case SAC_OPERATOR_LE: |
||||
sb.append("<="); |
||||
break; |
||||
case SAC_OPERATOR_GE: |
||||
sb.append(">="); |
||||
break; |
||||
case SAC_OPERATOR_TILDE: |
||||
sb.append("~"); |
||||
break; |
||||
case SAC_INHERIT: |
||||
sb.append("inherit"); |
||||
break; |
||||
case SAC_INTEGER: |
||||
sb.append(String.valueOf(getIntegerValue())); |
||||
break; |
||||
case SAC_REAL: |
||||
sb.append(getTrimedFloatValue()); |
||||
break; |
||||
case SAC_EM: |
||||
case SAC_EX: |
||||
case SAC_PIXEL: |
||||
case SAC_INCH: |
||||
case SAC_CENTIMETER: |
||||
case SAC_MILLIMETER: |
||||
case SAC_POINT: |
||||
case SAC_PICA: |
||||
case SAC_PERCENTAGE: |
||||
case SAC_DEGREE: |
||||
case SAC_GRADIAN: |
||||
case SAC_RADIAN: |
||||
case SAC_MILLISECOND: |
||||
case SAC_SECOND: |
||||
case SAC_HERTZ: |
||||
case SAC_KILOHERTZ: |
||||
case SAC_DIMENSION: |
||||
sb.append(getTrimedFloatValue()); |
||||
final String dimUnitText = getDimensionUnitText(); |
||||
if (null != dimUnitText) { |
||||
sb.append(dimUnitText); |
||||
} |
||||
break; |
||||
case SAC_URI: |
||||
sb.append("url(").append(getStringValue()).append(")"); |
||||
break; |
||||
case SAC_COUNTER_FUNCTION: |
||||
sb.append("counter("); |
||||
appendParams(sb); |
||||
sb.append(")"); |
||||
break; |
||||
case SAC_COUNTERS_FUNCTION: |
||||
sb.append("counters("); |
||||
appendParams(sb); |
||||
sb.append(")"); |
||||
break; |
||||
case SAC_RGBCOLOR: |
||||
sb.append("rgb("); |
||||
appendParams(sb); |
||||
sb.append(")"); |
||||
break; |
||||
case SAC_IDENT: |
||||
sb.append(getStringValue()); |
||||
break; |
||||
case SAC_STRING_VALUE: |
||||
sb.append("\""); |
||||
|
||||
String value = getStringValue(); |
||||
if (null != format && format.useSourceStringValues() |
||||
&& sourceStringValue_ != null |
||||
&& value != sourceStringValue_) { |
||||
value = sourceStringValue_; |
||||
} |
||||
else { |
||||
// replace line breaks
|
||||
value = value.replace("\n", "\\A ").replace("\r", "\\D "); |
||||
} |
||||
sb.append(value); |
||||
|
||||
sb.append("\""); |
||||
break; |
||||
case SAC_ATTR: |
||||
sb.append("attr(") |
||||
.append(getStringValue()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_RECT_FUNCTION: |
||||
sb.append("rect("); |
||||
appendParams(sb); |
||||
sb.append(")"); |
||||
break; |
||||
case SAC_UNICODERANGE: |
||||
final String range = getStringValue(); |
||||
if (null != range) { |
||||
sb.append(range); |
||||
} |
||||
break; |
||||
case SAC_SUB_EXPRESSION: |
||||
final String subExpression = getStringValue(); |
||||
if (null != subExpression) { |
||||
sb.append(subExpression); |
||||
} |
||||
break; |
||||
case SAC_FUNCTION: |
||||
final String functName = getFunctionName(); |
||||
if (null != functName) { |
||||
sb.append(functName); |
||||
} |
||||
sb.append('('); |
||||
appendParams(sb); |
||||
sb.append(")"); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
toString_ = sb.toString(); |
||||
return toString_; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
|
||||
public String toDebugString() { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
switch (lexicalUnitType_) { |
||||
case SAC_OPERATOR_COMMA: |
||||
sb.append("SAC_OPERATOR_COMMA"); |
||||
break; |
||||
case SAC_OPERATOR_PLUS: |
||||
sb.append("SAC_OPERATOR_PLUS"); |
||||
break; |
||||
case SAC_OPERATOR_MINUS: |
||||
sb.append("SAC_OPERATOR_MINUS"); |
||||
break; |
||||
case SAC_OPERATOR_MULTIPLY: |
||||
sb.append("SAC_OPERATOR_MULTIPLY"); |
||||
break; |
||||
case SAC_OPERATOR_SLASH: |
||||
sb.append("SAC_OPERATOR_SLASH"); |
||||
break; |
||||
case SAC_OPERATOR_MOD: |
||||
sb.append("SAC_OPERATOR_MOD"); |
||||
break; |
||||
case SAC_OPERATOR_EXP: |
||||
sb.append("SAC_OPERATOR_EXP"); |
||||
break; |
||||
case SAC_OPERATOR_LT: |
||||
sb.append("SAC_OPERATOR_LT"); |
||||
break; |
||||
case SAC_OPERATOR_GT: |
||||
sb.append("SAC_OPERATOR_GT"); |
||||
break; |
||||
case SAC_OPERATOR_LE: |
||||
sb.append("SAC_OPERATOR_LE"); |
||||
break; |
||||
case SAC_OPERATOR_GE: |
||||
sb.append("SAC_OPERATOR_GE"); |
||||
break; |
||||
case SAC_OPERATOR_TILDE: |
||||
sb.append("SAC_OPERATOR_TILDE"); |
||||
break; |
||||
case SAC_INHERIT: |
||||
sb.append("SAC_INHERIT"); |
||||
break; |
||||
case SAC_INTEGER: |
||||
sb.append("SAC_INTEGER(") |
||||
.append(String.valueOf(getIntegerValue())) |
||||
.append(")"); |
||||
break; |
||||
case SAC_REAL: |
||||
sb.append("SAC_REAL(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_EM: |
||||
sb.append("SAC_EM(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_EX: |
||||
sb.append("SAC_EX(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_PIXEL: |
||||
sb.append("SAC_PIXEL(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_INCH: |
||||
sb.append("SAC_INCH(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_CENTIMETER: |
||||
sb.append("SAC_CENTIMETER(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_MILLIMETER: |
||||
sb.append("SAC_MILLIMETER(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_POINT: |
||||
sb.append("SAC_POINT(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_PICA: |
||||
sb.append("SAC_PICA(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_PERCENTAGE: |
||||
sb.append("SAC_PERCENTAGE(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_DEGREE: |
||||
sb.append("SAC_DEGREE(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_GRADIAN: |
||||
sb.append("SAC_GRADIAN(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_RADIAN: |
||||
sb.append("SAC_RADIAN(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_MILLISECOND: |
||||
sb.append("SAC_MILLISECOND(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_SECOND: |
||||
sb.append("SAC_SECOND(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_HERTZ: |
||||
sb.append("SAC_HERTZ(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_KILOHERTZ: |
||||
sb.append("SAC_KILOHERTZ(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_DIMENSION: |
||||
sb.append("SAC_DIMENSION(") |
||||
.append(getTrimedFloatValue()) |
||||
.append(getDimensionUnitText()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_URI: |
||||
sb.append("SAC_URI(url(") |
||||
.append(getStringValue()) |
||||
.append("))"); |
||||
break; |
||||
case SAC_COUNTER_FUNCTION: |
||||
sb.append("SAC_COUNTER_FUNCTION(counter("); |
||||
appendParams(sb); |
||||
sb.append("))"); |
||||
break; |
||||
case SAC_COUNTERS_FUNCTION: |
||||
sb.append("SAC_COUNTERS_FUNCTION(counters("); |
||||
appendParams(sb); |
||||
sb.append("))"); |
||||
break; |
||||
case SAC_RGBCOLOR: |
||||
sb.append("SAC_RGBCOLOR(rgb("); |
||||
appendParams(sb); |
||||
sb.append("))"); |
||||
break; |
||||
case SAC_IDENT: |
||||
sb.append("SAC_IDENT(") |
||||
.append(getStringValue()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_STRING_VALUE: |
||||
sb.append("SAC_STRING_VALUE(\"") |
||||
.append(getStringValue()) |
||||
.append("\")"); |
||||
break; |
||||
case SAC_ATTR: |
||||
sb.append("SAC_ATTR(attr(") |
||||
.append(getStringValue()) |
||||
.append("))"); |
||||
break; |
||||
case SAC_RECT_FUNCTION: |
||||
sb.append("SAC_RECT_FUNCTION(rect("); |
||||
appendParams(sb); |
||||
sb.append("))"); |
||||
break; |
||||
case SAC_UNICODERANGE: |
||||
sb.append("SAC_UNICODERANGE(") |
||||
.append(getStringValue()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_SUB_EXPRESSION: |
||||
sb.append("SAC_SUB_EXPRESSION(") |
||||
.append(getStringValue()) |
||||
.append(")"); |
||||
break; |
||||
case SAC_FUNCTION: |
||||
sb.append("SAC_FUNCTION(") |
||||
.append(getFunctionName()) |
||||
.append("("); |
||||
LexicalUnit l = parameters_; |
||||
while (l != null) { |
||||
sb.append(l.toString()); |
||||
l = l.getNextLexicalUnit(); |
||||
} |
||||
sb.append("))"); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
private void appendParams(final StringBuilder sb) { |
||||
LexicalUnit l = parameters_; |
||||
if (l != null) { |
||||
sb.append(l.toString()); |
||||
l = l.getNextLexicalUnit(); |
||||
while (l != null) { |
||||
if (l.getLexicalUnitType() != SAC_OPERATOR_COMMA) { |
||||
sb.append(" "); |
||||
} |
||||
sb.append(l.toString()); |
||||
l = l.getNextLexicalUnit(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private String getTrimedFloatValue() { |
||||
final float f = getFloatValue(); |
||||
final int i = (int) f; |
||||
|
||||
if (f - i == 0) { |
||||
return Integer.toString((int) f); |
||||
} |
||||
return Float.toString(f); |
||||
} |
||||
|
||||
public static LexicalUnit createNumber(final LexicalUnit prev, final int i) { |
||||
return new LexicalUnitImpl(prev, i); |
||||
} |
||||
|
||||
public static LexicalUnit createNumber(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_REAL, f); |
||||
} |
||||
|
||||
public static LexicalUnit createPercentage(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_PERCENTAGE, f); |
||||
} |
||||
|
||||
public static LexicalUnit createPixel(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_PIXEL, f); |
||||
} |
||||
|
||||
public static LexicalUnit createCentimeter(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_CENTIMETER, f); |
||||
} |
||||
|
||||
public static LexicalUnit createMillimeter(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_MILLIMETER, f); |
||||
} |
||||
|
||||
public static LexicalUnit createInch(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_INCH, f); |
||||
} |
||||
|
||||
public static LexicalUnit createPoint(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_POINT, f); |
||||
} |
||||
|
||||
public static LexicalUnit createPica(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_PICA, f); |
||||
} |
||||
|
||||
public static LexicalUnit createEm(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_EM, f); |
||||
} |
||||
|
||||
public static LexicalUnit createEx(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_EX, f); |
||||
} |
||||
|
||||
public static LexicalUnit createDegree(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_DEGREE, f); |
||||
} |
||||
|
||||
public static LexicalUnit createRadian(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_RADIAN, f); |
||||
} |
||||
|
||||
public static LexicalUnit createGradian(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_GRADIAN, f); |
||||
} |
||||
|
||||
public static LexicalUnit createMillisecond(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_MILLISECOND, f); |
||||
} |
||||
|
||||
public static LexicalUnit createSecond(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_SECOND, f); |
||||
} |
||||
|
||||
public static LexicalUnit createHertz(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_HERTZ, f); |
||||
} |
||||
|
||||
public static LexicalUnit createDimension(final LexicalUnit prev, final float f, final String dim) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_DIMENSION, dim, f); |
||||
} |
||||
|
||||
public static LexicalUnit createKiloHertz(final LexicalUnit prev, final float f) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_KILOHERTZ, f); |
||||
} |
||||
|
||||
public static LexicalUnit createCounter(final LexicalUnit prev, final LexicalUnit params) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_COUNTER_FUNCTION, "counter", params); |
||||
} |
||||
|
||||
public static LexicalUnit createCounters(final LexicalUnit prev, final LexicalUnit params) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_COUNTERS_FUNCTION, "counters", params); |
||||
} |
||||
|
||||
public static LexicalUnit createAttr(final LexicalUnit prev, final String value) { |
||||
// according to LexicalUnit.SAC_ATTR, LexicalUnit.getStringValue(), not
|
||||
// LexicalUnit.getParameters() is applicable
|
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_ATTR, "name", value); |
||||
} |
||||
|
||||
public static LexicalUnit createRect(final LexicalUnit prev, final LexicalUnit params) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_RECT_FUNCTION, "rect", params); |
||||
} |
||||
|
||||
public static LexicalUnit createRgbColor(final LexicalUnit prev, final LexicalUnit params) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_RGBCOLOR, "rgb", params); |
||||
} |
||||
|
||||
public static LexicalUnit createFunction(final LexicalUnit prev, final String name, final LexicalUnit params) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_FUNCTION, name, params); |
||||
} |
||||
|
||||
public static LexicalUnit createString(final LexicalUnit prev, final String value) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, value); |
||||
} |
||||
|
||||
public static LexicalUnit createString(final LexicalUnit prev, final String value, final String sourceStringValue) { |
||||
final LexicalUnitImpl unit = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, value); |
||||
unit.sourceStringValue_ = sourceStringValue; |
||||
return unit; |
||||
} |
||||
|
||||
public static LexicalUnit createIdent(final LexicalUnit prev, final String value) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, value); |
||||
} |
||||
|
||||
public static LexicalUnit createURI(final LexicalUnit prev, final String value) { |
||||
return new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, value); |
||||
} |
||||
|
||||
public static LexicalUnit createComma(final LexicalUnit prev) { |
||||
return new LexicalUnitImpl(prev, SAC_OPERATOR_COMMA); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import org.w3c.css.sac.Locator; |
||||
|
||||
/** |
||||
* An object that provides a SAC locator |
||||
* |
||||
* @author <a href="mailto:waldbaer@users.sourceforge.net">Johannes Koch</a> |
||||
*/ |
||||
public interface Locatable { |
||||
|
||||
Locator getLocator(); |
||||
|
||||
void setLocator(Locator locator); |
||||
} |
@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import org.w3c.css.sac.Locator; |
||||
|
||||
/** |
||||
* Implementation of {@link Locatable} |
||||
* |
||||
* @author <a href="mailto:waldbaer@users.sourceforge.net">Johannes Koch</a> |
||||
*/ |
||||
public class LocatableImpl implements Locatable { |
||||
|
||||
private Locator locator_; |
||||
|
||||
public Locator getLocator() { |
||||
return locator_; |
||||
} |
||||
|
||||
public void setLocator(final Locator locator) { |
||||
locator_ = locator; |
||||
} |
||||
} |
@ -0,0 +1,146 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.w3c.css.sac.Locator; |
||||
|
||||
import com.fr.third.steadystate.css.util.LangUtils; |
||||
|
||||
/** |
||||
* Implementation of {@link Locator}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
*/ |
||||
public class LocatorImpl implements Locator, Serializable { |
||||
|
||||
private static final long serialVersionUID = 2240824537064705530L; |
||||
|
||||
private String uri_; |
||||
private int lineNumber_; |
||||
private int columnNumber_; |
||||
|
||||
/** |
||||
* Creates new LocatorImpl |
||||
* @param uri the uri |
||||
* @param line the lineNumber |
||||
* @param column the columnNumber |
||||
*/ |
||||
public LocatorImpl(final String uri, final int line, final int column) { |
||||
uri_ = uri; |
||||
lineNumber_ = line; |
||||
columnNumber_ = column; |
||||
} |
||||
|
||||
/** |
||||
* Return the URI for the current document event. |
||||
* |
||||
* <p>The parser must resolve the URI fully before passing it to the |
||||
* application.</p> |
||||
* |
||||
* @return A string containing the URI, or null |
||||
* if none is available. |
||||
*/ |
||||
public String getURI() { |
||||
return uri_; |
||||
} |
||||
|
||||
/** |
||||
* @return @see #getURI() |
||||
*/ |
||||
public String getUri() { |
||||
return uri_; |
||||
} |
||||
|
||||
/** |
||||
* Set the uri to a new value. |
||||
* @see #getURI() |
||||
* @param uri the new uri |
||||
*/ |
||||
public void setUri(final String uri) { |
||||
uri_ = uri; |
||||
} |
||||
|
||||
/** |
||||
* Return the column number where the current document event ends. |
||||
* Note that this is the column number of the first |
||||
* character after the text associated with the document |
||||
* event. The first column in a line is position 1. |
||||
* @return The column number, or -1 if none is available. |
||||
* @see #getLineNumber |
||||
*/ |
||||
public int getColumnNumber() { |
||||
return columnNumber_; |
||||
} |
||||
|
||||
/** |
||||
* Set the columnNumber to a new value. |
||||
* @param column the new columnNumber |
||||
*/ |
||||
public void setColumnNumber(final int column) { |
||||
columnNumber_ = column; |
||||
} |
||||
|
||||
/** |
||||
* Return the line number where the current document event ends. |
||||
* Note that this is the line position of the first character |
||||
* after the text associated with the document event. |
||||
* @return The line number, or -1 if none is available. |
||||
* @see #getColumnNumber |
||||
*/ |
||||
public int getLineNumber() { |
||||
return lineNumber_; |
||||
} |
||||
|
||||
/** |
||||
* Set the lineNumber to a new value. |
||||
* @param line the new lineNumber |
||||
*/ |
||||
public void setLineNumber(final int line) { |
||||
lineNumber_ = line; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object obj) { |
||||
if (this == obj) { |
||||
return true; |
||||
} |
||||
if (!(obj instanceof Locator)) { |
||||
return false; |
||||
} |
||||
final Locator l = (Locator) obj; |
||||
return (getColumnNumber() == l.getColumnNumber()) |
||||
&& (getLineNumber() == l.getLineNumber()) |
||||
&& LangUtils.equals(getURI(), l.getURI()); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int hash = LangUtils.HASH_SEED; |
||||
hash = LangUtils.hashCode(hash, columnNumber_); |
||||
hash = LangUtils.hashCode(hash, lineNumber_); |
||||
hash = LangUtils.hashCode(hash, uri_); |
||||
return hash; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return new StringBuilder().append(getUri()).append(" (") |
||||
.append(getLineNumber()).append(':') |
||||
.append(getColumnNumber()).append(')').toString(); |
||||
} |
||||
} |
@ -0,0 +1,193 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 7.0 */ |
||||
/* JavaCCOptions:KEEP_LINE_COLUMN=true */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** |
||||
* This exception is thrown when parse errors are encountered. |
||||
* You can explicitly create objects of this exception type by |
||||
* calling the method generateParseException in the generated |
||||
* parser. |
||||
* |
||||
* You can modify this class to customize your error reporting |
||||
* mechanisms so long as you retain the public fields. |
||||
*/ |
||||
public class ParseException extends Exception { |
||||
|
||||
/** |
||||
* The version identifier for this Serializable class. |
||||
* Increment only if the <i>serialized</i> form of the |
||||
* class changes. |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* The end of line string for this machine. |
||||
*/ |
||||
protected static String EOL = System.getProperty("line.separator", "\n"); |
||||
|
||||
/** |
||||
* This constructor is used by the method "generateParseException" |
||||
* in the generated parser. Calling this constructor generates |
||||
* a new object of this type with the fields "currentToken", |
||||
* "expectedTokenSequences", and "tokenImage" set. |
||||
*/ |
||||
public ParseException(Token currentTokenVal, |
||||
int[][] expectedTokenSequencesVal, |
||||
String[] tokenImageVal |
||||
) |
||||
{ |
||||
super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); |
||||
currentToken = currentTokenVal; |
||||
expectedTokenSequences = expectedTokenSequencesVal; |
||||
tokenImage = tokenImageVal; |
||||
} |
||||
|
||||
/** |
||||
* The following constructors are for use by you for whatever |
||||
* purpose you can think of. Constructing the exception in this |
||||
* manner makes the exception behave in the normal way - i.e., as |
||||
* documented in the class "Throwable". The fields "errorToken", |
||||
* "expectedTokenSequences", and "tokenImage" do not contain |
||||
* relevant information. The JavaCC generated code does not use |
||||
* these constructors. |
||||
*/ |
||||
|
||||
public ParseException() { |
||||
super(); |
||||
} |
||||
|
||||
/** Constructor with message. */ |
||||
public ParseException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* This is the last token that has been consumed successfully. If |
||||
* this object has been created due to a parse error, the token |
||||
* followng this token will (therefore) be the first error token. |
||||
*/ |
||||
public Token currentToken; |
||||
|
||||
/** |
||||
* Each entry in this array is an array of integers. Each array |
||||
* of integers represents a sequence of tokens (by their ordinal |
||||
* values) that is expected at this point of the parse. |
||||
*/ |
||||
public int[][] expectedTokenSequences; |
||||
|
||||
/** |
||||
* This is a reference to the "tokenImage" array of the generated |
||||
* parser within which the parse error occurred. This array is |
||||
* defined in the generated ...Constants interface. |
||||
*/ |
||||
public String[] tokenImage; |
||||
|
||||
/** |
||||
* It uses "currentToken" and "expectedTokenSequences" to generate a parse |
||||
* error message and returns it. If this object has been created |
||||
* due to a parse error, and you do not catch it (it gets thrown |
||||
* from the parser) the correct error message |
||||
* gets displayed. |
||||
*/ |
||||
private static String initialise(Token currentToken, |
||||
int[][] expectedTokenSequences, |
||||
String[] tokenImage) { |
||||
|
||||
StringBuffer expected = new StringBuffer(); |
||||
int maxSize = 0; |
||||
for (int i = 0; i < expectedTokenSequences.length; i++) { |
||||
if (maxSize < expectedTokenSequences[i].length) { |
||||
maxSize = expectedTokenSequences[i].length; |
||||
} |
||||
for (int j = 0; j < expectedTokenSequences[i].length; j++) { |
||||
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); |
||||
} |
||||
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { |
||||
expected.append("..."); |
||||
} |
||||
expected.append(EOL).append(" "); |
||||
} |
||||
String retval = "Encountered \""; |
||||
Token tok = currentToken.next; |
||||
for (int i = 0; i < maxSize; i++) { |
||||
if (i != 0) retval += " "; |
||||
if (tok.kind == 0) { |
||||
retval += tokenImage[0]; |
||||
break; |
||||
} |
||||
retval += " " + tokenImage[tok.kind]; |
||||
retval += " \""; |
||||
retval += add_escapes(tok.image); |
||||
retval += " \""; |
||||
tok = tok.next; |
||||
} |
||||
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; |
||||
retval += "." + EOL; |
||||
|
||||
|
||||
if (expectedTokenSequences.length == 0) { |
||||
// Nothing to add here
|
||||
} else { |
||||
if (expectedTokenSequences.length == 1) { |
||||
retval += "Was expecting:" + EOL + " "; |
||||
} else { |
||||
retval += "Was expecting one of:" + EOL + " "; |
||||
} |
||||
retval += expected.toString(); |
||||
} |
||||
|
||||
return retval; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Used to convert raw characters to their escaped version |
||||
* when these raw version cannot be used as part of an ASCII |
||||
* string literal. |
||||
*/ |
||||
static String add_escapes(String str) { |
||||
StringBuffer retval = new StringBuffer(); |
||||
char ch; |
||||
for (int i = 0; i < str.length(); i++) { |
||||
switch (str.charAt(i)) |
||||
{ |
||||
case '\b': |
||||
retval.append("\\b"); |
||||
continue; |
||||
case '\t': |
||||
retval.append("\\t"); |
||||
continue; |
||||
case '\n': |
||||
retval.append("\\n"); |
||||
continue; |
||||
case '\f': |
||||
retval.append("\\f"); |
||||
continue; |
||||
case '\r': |
||||
retval.append("\\r"); |
||||
continue; |
||||
case '\"': |
||||
retval.append("\\\""); |
||||
continue; |
||||
case '\'': |
||||
retval.append("\\\'"); |
||||
continue; |
||||
case '\\': |
||||
retval.append("\\\\"); |
||||
continue; |
||||
default: |
||||
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
||||
String s = "0000" + Integer.toString(ch, 16); |
||||
retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
||||
} else { |
||||
retval.append(ch); |
||||
} |
||||
continue; |
||||
} |
||||
} |
||||
return retval.toString(); |
||||
} |
||||
|
||||
} |
||||
/* JavaCC - OriginalChecksum=a8a58654a5ee2b5eb919333733c9ca09 (do not edit this line) */ |
@ -0,0 +1,63 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** |
||||
* Util methods used by the parser and lexer. |
||||
* |
||||
* @author RBRi |
||||
*/ |
||||
public final class ParserUtils { |
||||
|
||||
private ParserUtils() { |
||||
} |
||||
|
||||
/** |
||||
* Remove the given number of chars from start and end. |
||||
* There is no parameter checking, the caller has to take care of this. |
||||
* |
||||
* @param s the StringBuilder |
||||
* @param left no of chars to be removed from start |
||||
* @param right no of chars to be removed from end |
||||
* @return the trimmed string |
||||
*/ |
||||
public static String trimBy(final StringBuilder s, final int left, final int right) { |
||||
return s.substring(left, s.length() - right); |
||||
} |
||||
|
||||
/** |
||||
* Helper that removes the leading "url(", the trailing ")" |
||||
* and surrounding quotes from the given string builder. |
||||
* @param s the StringBuilder |
||||
* @return |
||||
*/ |
||||
public static String trimUrl(final StringBuilder s) { |
||||
final String s1 = trimBy(s, 4, 1).trim(); |
||||
if (s1.length() == 0) { |
||||
return s1; |
||||
} |
||||
|
||||
final int end = s1.length() - 1; |
||||
final char c0 = s1.charAt(0); |
||||
if ((c0 == '"' && s1.charAt(end) == '"') |
||||
|| (c0 == '\'' && s1.charAt(end) == '\'')) { |
||||
return s1.substring(1, end); |
||||
} |
||||
|
||||
return s1; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,71 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.w3c.css.sac.SACMediaList; |
||||
|
||||
import com.fr.third.steadystate.css.parser.media.MediaQuery; |
||||
|
||||
/** |
||||
* Implementation of {@link SACMediaList}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class SACMediaListImpl extends LocatableImpl implements SACMediaList { |
||||
|
||||
private final List<MediaQuery> mediaQueries_; |
||||
|
||||
public SACMediaListImpl() { |
||||
mediaQueries_ = new ArrayList<MediaQuery>(); |
||||
} |
||||
|
||||
public int getLength() { |
||||
return mediaQueries_.size(); |
||||
} |
||||
|
||||
public String item(final int index) { |
||||
return mediaQuery(index).getMedia(); |
||||
} |
||||
|
||||
public MediaQuery mediaQuery(final int index) { |
||||
return mediaQueries_.get(index); |
||||
} |
||||
|
||||
public void add(final String s) { |
||||
add(new MediaQuery(s)); |
||||
} |
||||
|
||||
public void add(final MediaQuery mediaQuery) { |
||||
mediaQueries_.add(mediaQuery); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
final int len = getLength(); |
||||
for (int i = 0; i < len; i++) { |
||||
sb.append(item(i)); |
||||
if (i < len - 1) { |
||||
sb.append(", "); |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import org.w3c.css.sac.Parser; |
||||
|
||||
/** |
||||
* Our extension of the {@link Parser} interface. |
||||
* |
||||
* @author RBRi |
||||
*/ |
||||
public interface SACParser extends Parser { |
||||
|
||||
void setIeStarHackAccepted(boolean accepted); |
||||
|
||||
boolean isIeStarHackAccepted(); |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,216 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SACParserCSS1Constants.java */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
|
||||
/** |
||||
* Token literal values and constants. |
||||
* Generated by org.javacc.parser.OtherFilesGen#start() |
||||
*/ |
||||
public interface SACParserCSS1Constants { |
||||
|
||||
/** End of File. */ |
||||
int EOF = 0; |
||||
/** RegularExpression Id. */ |
||||
int S = 1; |
||||
/** RegularExpression Id. */ |
||||
int IDENT = 3; |
||||
/** RegularExpression Id. */ |
||||
int LINK_PSCLASS = 4; |
||||
/** RegularExpression Id. */ |
||||
int VISITED_PSCLASS = 5; |
||||
/** RegularExpression Id. */ |
||||
int ACTIVE_PSCLASS = 6; |
||||
/** RegularExpression Id. */ |
||||
int FIRST_LINE = 7; |
||||
/** RegularExpression Id. */ |
||||
int FIRST_LETTER = 8; |
||||
/** RegularExpression Id. */ |
||||
int HASH = 9; |
||||
/** RegularExpression Id. */ |
||||
int LBRACE = 10; |
||||
/** RegularExpression Id. */ |
||||
int RBRACE = 11; |
||||
/** RegularExpression Id. */ |
||||
int COMMA = 12; |
||||
/** RegularExpression Id. */ |
||||
int DOT = 13; |
||||
/** RegularExpression Id. */ |
||||
int SEMICOLON = 14; |
||||
/** RegularExpression Id. */ |
||||
int COLON = 15; |
||||
/** RegularExpression Id. */ |
||||
int SLASH = 16; |
||||
/** RegularExpression Id. */ |
||||
int PLUS = 17; |
||||
/** RegularExpression Id. */ |
||||
int MINUS = 18; |
||||
/** RegularExpression Id. */ |
||||
int EQUALS = 19; |
||||
/** RegularExpression Id. */ |
||||
int GT = 20; |
||||
/** RegularExpression Id. */ |
||||
int LSQUARE = 21; |
||||
/** RegularExpression Id. */ |
||||
int RSQUARE = 22; |
||||
/** RegularExpression Id. */ |
||||
int STRING = 23; |
||||
/** RegularExpression Id. */ |
||||
int RROUND = 24; |
||||
/** RegularExpression Id. */ |
||||
int URL = 25; |
||||
/** RegularExpression Id. */ |
||||
int CDO = 26; |
||||
/** RegularExpression Id. */ |
||||
int CDC = 27; |
||||
/** RegularExpression Id. */ |
||||
int IMPORT_SYM = 28; |
||||
/** RegularExpression Id. */ |
||||
int IMPORTANT_SYM = 29; |
||||
/** RegularExpression Id. */ |
||||
int ATKEYWORD = 30; |
||||
/** RegularExpression Id. */ |
||||
int EMS = 31; |
||||
/** RegularExpression Id. */ |
||||
int EXS = 32; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PX = 33; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_CM = 34; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_MM = 35; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_IN = 36; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PT = 37; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PC = 38; |
||||
/** RegularExpression Id. */ |
||||
int PERCENTAGE = 39; |
||||
/** RegularExpression Id. */ |
||||
int NUMBER = 40; |
||||
/** RegularExpression Id. */ |
||||
int RGB = 41; |
||||
/** RegularExpression Id. */ |
||||
int NAME = 42; |
||||
/** RegularExpression Id. */ |
||||
int D = 43; |
||||
/** RegularExpression Id. */ |
||||
int NUM = 44; |
||||
/** RegularExpression Id. */ |
||||
int UNICODERANGE = 45; |
||||
/** RegularExpression Id. */ |
||||
int RANGE = 46; |
||||
/** RegularExpression Id. */ |
||||
int Q16 = 47; |
||||
/** RegularExpression Id. */ |
||||
int Q15 = 48; |
||||
/** RegularExpression Id. */ |
||||
int Q14 = 49; |
||||
/** RegularExpression Id. */ |
||||
int Q13 = 50; |
||||
/** RegularExpression Id. */ |
||||
int Q12 = 51; |
||||
/** RegularExpression Id. */ |
||||
int Q11 = 52; |
||||
/** RegularExpression Id. */ |
||||
int LATIN1 = 53; |
||||
/** RegularExpression Id. */ |
||||
int NMCHAR = 54; |
||||
/** RegularExpression Id. */ |
||||
int NMSTART = 55; |
||||
/** RegularExpression Id. */ |
||||
int STRING1 = 56; |
||||
/** RegularExpression Id. */ |
||||
int STRING2 = 57; |
||||
/** RegularExpression Id. */ |
||||
int NONASCII = 58; |
||||
/** RegularExpression Id. */ |
||||
int ESCAPE = 59; |
||||
/** RegularExpression Id. */ |
||||
int NL = 60; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE = 61; |
||||
/** RegularExpression Id. */ |
||||
int HNUM = 62; |
||||
/** RegularExpression Id. */ |
||||
int H = 63; |
||||
/** RegularExpression Id. */ |
||||
int UNKNOWN = 66; |
||||
|
||||
/** Lexical state. */ |
||||
int DEFAULT = 0; |
||||
/** Lexical state. */ |
||||
int COMMENT = 1; |
||||
|
||||
/** Literal token values. */ |
||||
String[] tokenImage = { |
||||
"<EOF>", |
||||
"<S>", |
||||
"\"/*\"", |
||||
"<IDENT>", |
||||
"\":link\"", |
||||
"\":visited\"", |
||||
"\":active\"", |
||||
"\":first-line\"", |
||||
"\":first-letter\"", |
||||
"<HASH>", |
||||
"\"{\"", |
||||
"\"}\"", |
||||
"\",\"", |
||||
"\".\"", |
||||
"\";\"", |
||||
"\":\"", |
||||
"\"/\"", |
||||
"\"+\"", |
||||
"\"-\"", |
||||
"\"=\"", |
||||
"\">\"", |
||||
"\"[\"", |
||||
"\"]\"", |
||||
"<STRING>", |
||||
"\")\"", |
||||
"<URL>", |
||||
"\"<!--\"", |
||||
"\"-->\"", |
||||
"\"@import\"", |
||||
"<IMPORTANT_SYM>", |
||||
"<ATKEYWORD>", |
||||
"<EMS>", |
||||
"<EXS>", |
||||
"<LENGTH_PX>", |
||||
"<LENGTH_CM>", |
||||
"<LENGTH_MM>", |
||||
"<LENGTH_IN>", |
||||
"<LENGTH_PT>", |
||||
"<LENGTH_PC>", |
||||
"<PERCENTAGE>", |
||||
"<NUMBER>", |
||||
"\"rgb(\"", |
||||
"<NAME>", |
||||
"<D>", |
||||
"<NUM>", |
||||
"<UNICODERANGE>", |
||||
"<RANGE>", |
||||
"<Q16>", |
||||
"<Q15>", |
||||
"<Q14>", |
||||
"<Q13>", |
||||
"<Q12>", |
||||
"\"?\"", |
||||
"<LATIN1>", |
||||
"<NMCHAR>", |
||||
"<NMSTART>", |
||||
"<STRING1>", |
||||
"<STRING2>", |
||||
"<NONASCII>", |
||||
"<ESCAPE>", |
||||
"<NL>", |
||||
"<UNICODE>", |
||||
"<HNUM>", |
||||
"<H>", |
||||
"\"*/\"", |
||||
"<token of kind 65>", |
||||
"<UNKNOWN>", |
||||
}; |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,286 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SACParserCSS21Constants.java */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
|
||||
/** |
||||
* Token literal values and constants. |
||||
* Generated by org.javacc.parser.OtherFilesGen#start() |
||||
*/ |
||||
public interface SACParserCSS21Constants { |
||||
|
||||
/** End of File. */ |
||||
int EOF = 0; |
||||
/** RegularExpression Id. */ |
||||
int S = 1; |
||||
/** RegularExpression Id. */ |
||||
int W = 2; |
||||
/** RegularExpression Id. */ |
||||
int H = 6; |
||||
/** RegularExpression Id. */ |
||||
int HNUM = 7; |
||||
/** RegularExpression Id. */ |
||||
int NONASCII = 8; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE = 9; |
||||
/** RegularExpression Id. */ |
||||
int ESCAPE = 10; |
||||
/** RegularExpression Id. */ |
||||
int NMSTART = 11; |
||||
/** RegularExpression Id. */ |
||||
int NMCHAR = 12; |
||||
/** RegularExpression Id. */ |
||||
int NL = 13; |
||||
/** RegularExpression Id. */ |
||||
int STRING1 = 14; |
||||
/** RegularExpression Id. */ |
||||
int STRING2 = 15; |
||||
/** RegularExpression Id. */ |
||||
int COMMENT_ = 16; |
||||
/** RegularExpression Id. */ |
||||
int NUMBER = 17; |
||||
/** RegularExpression Id. */ |
||||
int INHERIT = 18; |
||||
/** RegularExpression Id. */ |
||||
int IDENT = 19; |
||||
/** RegularExpression Id. */ |
||||
int NAME = 20; |
||||
/** RegularExpression Id. */ |
||||
int NUM = 21; |
||||
/** RegularExpression Id. */ |
||||
int STRING = 22; |
||||
/** RegularExpression Id. */ |
||||
int URL = 23; |
||||
/** RegularExpression Id. */ |
||||
int A_LETTER = 24; |
||||
/** RegularExpression Id. */ |
||||
int C_LETTER = 25; |
||||
/** RegularExpression Id. */ |
||||
int D_LETTER = 26; |
||||
/** RegularExpression Id. */ |
||||
int E_LETTER = 27; |
||||
/** RegularExpression Id. */ |
||||
int G_LETTER = 28; |
||||
/** RegularExpression Id. */ |
||||
int H_LETTER = 29; |
||||
/** RegularExpression Id. */ |
||||
int I_LETTER = 30; |
||||
/** RegularExpression Id. */ |
||||
int K_LETTER = 31; |
||||
/** RegularExpression Id. */ |
||||
int L_LETTER = 32; |
||||
/** RegularExpression Id. */ |
||||
int M_LETTER = 33; |
||||
/** RegularExpression Id. */ |
||||
int N_LETTER = 34; |
||||
/** RegularExpression Id. */ |
||||
int O_LETTER = 35; |
||||
/** RegularExpression Id. */ |
||||
int P_LETTER = 36; |
||||
/** RegularExpression Id. */ |
||||
int R_LETTER = 37; |
||||
/** RegularExpression Id. */ |
||||
int S_LETTER = 38; |
||||
/** RegularExpression Id. */ |
||||
int T_LETTER = 39; |
||||
/** RegularExpression Id. */ |
||||
int X_LETTER = 40; |
||||
/** RegularExpression Id. */ |
||||
int Z_LETTER = 41; |
||||
/** RegularExpression Id. */ |
||||
int CDO = 42; |
||||
/** RegularExpression Id. */ |
||||
int CDC = 43; |
||||
/** RegularExpression Id. */ |
||||
int INCLUDES = 44; |
||||
/** RegularExpression Id. */ |
||||
int DASHMATCH = 45; |
||||
/** RegularExpression Id. */ |
||||
int LBRACE = 46; |
||||
/** RegularExpression Id. */ |
||||
int RBRACE = 47; |
||||
/** RegularExpression Id. */ |
||||
int LROUND = 48; |
||||
/** RegularExpression Id. */ |
||||
int RROUND = 49; |
||||
/** RegularExpression Id. */ |
||||
int DOT = 50; |
||||
/** RegularExpression Id. */ |
||||
int SEMICOLON = 51; |
||||
/** RegularExpression Id. */ |
||||
int COLON = 52; |
||||
/** RegularExpression Id. */ |
||||
int ASTERISK = 53; |
||||
/** RegularExpression Id. */ |
||||
int SLASH = 54; |
||||
/** RegularExpression Id. */ |
||||
int MINUS = 55; |
||||
/** RegularExpression Id. */ |
||||
int EQUALS = 56; |
||||
/** RegularExpression Id. */ |
||||
int LSQUARE = 57; |
||||
/** RegularExpression Id. */ |
||||
int RSQUARE = 58; |
||||
/** RegularExpression Id. */ |
||||
int PLUS = 59; |
||||
/** RegularExpression Id. */ |
||||
int GREATER = 60; |
||||
/** RegularExpression Id. */ |
||||
int COMMA = 61; |
||||
/** RegularExpression Id. */ |
||||
int HASH = 62; |
||||
/** RegularExpression Id. */ |
||||
int IMPORT_SYM = 63; |
||||
/** RegularExpression Id. */ |
||||
int PAGE_SYM = 64; |
||||
/** RegularExpression Id. */ |
||||
int MEDIA_SYM = 65; |
||||
/** RegularExpression Id. */ |
||||
int CHARSET_SYM = 66; |
||||
/** RegularExpression Id. */ |
||||
int IMPORTANT_SYM = 67; |
||||
/** RegularExpression Id. */ |
||||
int EMS = 68; |
||||
/** RegularExpression Id. */ |
||||
int EXS = 69; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PX = 70; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_CM = 71; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_MM = 72; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_IN = 73; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PT = 74; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PC = 75; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_DEG = 76; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_RAD = 77; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_GRAD = 78; |
||||
/** RegularExpression Id. */ |
||||
int TIME_MS = 79; |
||||
/** RegularExpression Id. */ |
||||
int TIME_S = 80; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_HZ = 81; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_KHZ = 82; |
||||
/** RegularExpression Id. */ |
||||
int PERCENTAGE = 83; |
||||
/** RegularExpression Id. */ |
||||
int DIMENSION = 84; |
||||
/** RegularExpression Id. */ |
||||
int URI = 85; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION_LANG = 86; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION = 87; |
||||
/** RegularExpression Id. */ |
||||
int ATKEYWORD = 88; |
||||
/** RegularExpression Id. */ |
||||
int UNKNOWN = 89; |
||||
|
||||
/** Lexical state. */ |
||||
int DEFAULT = 0; |
||||
/** Lexical state. */ |
||||
int COMMENT = 1; |
||||
|
||||
/** Literal token values. */ |
||||
String[] tokenImage = { |
||||
"<EOF>", |
||||
"<S>", |
||||
"<W>", |
||||
"\"/*\"", |
||||
"\"*/\"", |
||||
"<token of kind 5>", |
||||
"<H>", |
||||
"<HNUM>", |
||||
"<NONASCII>", |
||||
"<UNICODE>", |
||||
"<ESCAPE>", |
||||
"<NMSTART>", |
||||
"<NMCHAR>", |
||||
"<NL>", |
||||
"<STRING1>", |
||||
"<STRING2>", |
||||
"<COMMENT_>", |
||||
"<NUMBER>", |
||||
"\"inherit\"", |
||||
"<IDENT>", |
||||
"<NAME>", |
||||
"<NUM>", |
||||
"<STRING>", |
||||
"<URL>", |
||||
"<A_LETTER>", |
||||
"<C_LETTER>", |
||||
"<D_LETTER>", |
||||
"<E_LETTER>", |
||||
"<G_LETTER>", |
||||
"<H_LETTER>", |
||||
"<I_LETTER>", |
||||
"<K_LETTER>", |
||||
"<L_LETTER>", |
||||
"<M_LETTER>", |
||||
"<N_LETTER>", |
||||
"<O_LETTER>", |
||||
"<P_LETTER>", |
||||
"<R_LETTER>", |
||||
"<S_LETTER>", |
||||
"<T_LETTER>", |
||||
"<X_LETTER>", |
||||
"<Z_LETTER>", |
||||
"\"<!--\"", |
||||
"\"-->\"", |
||||
"\"~=\"", |
||||
"\"|=\"", |
||||
"<LBRACE>", |
||||
"\"}\"", |
||||
"\"(\"", |
||||
"\")\"", |
||||
"\".\"", |
||||
"\";\"", |
||||
"\":\"", |
||||
"\"*\"", |
||||
"\"/\"", |
||||
"\"-\"", |
||||
"\"=\"", |
||||
"\"[\"", |
||||
"\"]\"", |
||||
"<PLUS>", |
||||
"<GREATER>", |
||||
"<COMMA>", |
||||
"<HASH>", |
||||
"<IMPORT_SYM>", |
||||
"<PAGE_SYM>", |
||||
"<MEDIA_SYM>", |
||||
"<CHARSET_SYM>", |
||||
"<IMPORTANT_SYM>", |
||||
"<EMS>", |
||||
"<EXS>", |
||||
"<LENGTH_PX>", |
||||
"<LENGTH_CM>", |
||||
"<LENGTH_MM>", |
||||
"<LENGTH_IN>", |
||||
"<LENGTH_PT>", |
||||
"<LENGTH_PC>", |
||||
"<ANGLE_DEG>", |
||||
"<ANGLE_RAD>", |
||||
"<ANGLE_GRAD>", |
||||
"<TIME_MS>", |
||||
"<TIME_S>", |
||||
"<FREQ_HZ>", |
||||
"<FREQ_KHZ>", |
||||
"<PERCENTAGE>", |
||||
"<DIMENSION>", |
||||
"<URI>", |
||||
"<FUNCTION_LANG>", |
||||
"<FUNCTION>", |
||||
"<ATKEYWORD>", |
||||
"<UNKNOWN>", |
||||
"\"progid:\"", |
||||
}; |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,255 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SACParserCSS2Constants.java */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
|
||||
/** |
||||
* Token literal values and constants. |
||||
* Generated by org.javacc.parser.OtherFilesGen#start() |
||||
*/ |
||||
public interface SACParserCSS2Constants { |
||||
|
||||
/** End of File. */ |
||||
int EOF = 0; |
||||
/** RegularExpression Id. */ |
||||
int S = 1; |
||||
/** RegularExpression Id. */ |
||||
int W = 2; |
||||
/** RegularExpression Id. */ |
||||
int LBRACE = 6; |
||||
/** RegularExpression Id. */ |
||||
int RBRACE = 7; |
||||
/** RegularExpression Id. */ |
||||
int COMMA = 8; |
||||
/** RegularExpression Id. */ |
||||
int DOT = 9; |
||||
/** RegularExpression Id. */ |
||||
int SEMICOLON = 10; |
||||
/** RegularExpression Id. */ |
||||
int COLON = 11; |
||||
/** RegularExpression Id. */ |
||||
int ASTERISK = 12; |
||||
/** RegularExpression Id. */ |
||||
int SLASH = 13; |
||||
/** RegularExpression Id. */ |
||||
int PLUS = 14; |
||||
/** RegularExpression Id. */ |
||||
int MINUS = 15; |
||||
/** RegularExpression Id. */ |
||||
int EQUALS = 16; |
||||
/** RegularExpression Id. */ |
||||
int GT = 17; |
||||
/** RegularExpression Id. */ |
||||
int LSQUARE = 18; |
||||
/** RegularExpression Id. */ |
||||
int RSQUARE = 19; |
||||
/** RegularExpression Id. */ |
||||
int HASH = 20; |
||||
/** RegularExpression Id. */ |
||||
int STRING = 21; |
||||
/** RegularExpression Id. */ |
||||
int RROUND = 22; |
||||
/** RegularExpression Id. */ |
||||
int URL = 23; |
||||
/** RegularExpression Id. */ |
||||
int URI = 24; |
||||
/** RegularExpression Id. */ |
||||
int CDO = 25; |
||||
/** RegularExpression Id. */ |
||||
int CDC = 26; |
||||
/** RegularExpression Id. */ |
||||
int INCLUDES = 27; |
||||
/** RegularExpression Id. */ |
||||
int DASHMATCH = 28; |
||||
/** RegularExpression Id. */ |
||||
int IMPORT_SYM = 29; |
||||
/** RegularExpression Id. */ |
||||
int PAGE_SYM = 30; |
||||
/** RegularExpression Id. */ |
||||
int MEDIA_SYM = 31; |
||||
/** RegularExpression Id. */ |
||||
int FONT_FACE_SYM = 32; |
||||
/** RegularExpression Id. */ |
||||
int CHARSET_SYM = 33; |
||||
/** RegularExpression Id. */ |
||||
int ATKEYWORD = 34; |
||||
/** RegularExpression Id. */ |
||||
int IMPORTANT_SYM = 35; |
||||
/** RegularExpression Id. */ |
||||
int INHERIT = 36; |
||||
/** RegularExpression Id. */ |
||||
int EMS = 37; |
||||
/** RegularExpression Id. */ |
||||
int EXS = 38; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PX = 39; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_CM = 40; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_MM = 41; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_IN = 42; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PT = 43; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PC = 44; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_DEG = 45; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_RAD = 46; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_GRAD = 47; |
||||
/** RegularExpression Id. */ |
||||
int TIME_MS = 48; |
||||
/** RegularExpression Id. */ |
||||
int TIME_S = 49; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_HZ = 50; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_KHZ = 51; |
||||
/** RegularExpression Id. */ |
||||
int PERCENTAGE = 52; |
||||
/** RegularExpression Id. */ |
||||
int DIMEN = 53; |
||||
/** RegularExpression Id. */ |
||||
int NUMBER = 54; |
||||
/** RegularExpression Id. */ |
||||
int RGB = 55; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION_LANG = 56; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION = 57; |
||||
/** RegularExpression Id. */ |
||||
int IDENT = 58; |
||||
/** RegularExpression Id. */ |
||||
int NAME = 59; |
||||
/** RegularExpression Id. */ |
||||
int NUM = 60; |
||||
/** RegularExpression Id. */ |
||||
int UNICODERANGE = 61; |
||||
/** RegularExpression Id. */ |
||||
int RANGE = 62; |
||||
/** RegularExpression Id. */ |
||||
int Q16 = 63; |
||||
/** RegularExpression Id. */ |
||||
int Q15 = 64; |
||||
/** RegularExpression Id. */ |
||||
int Q14 = 65; |
||||
/** RegularExpression Id. */ |
||||
int Q13 = 66; |
||||
/** RegularExpression Id. */ |
||||
int Q12 = 67; |
||||
/** RegularExpression Id. */ |
||||
int Q11 = 68; |
||||
/** RegularExpression Id. */ |
||||
int NMSTART = 69; |
||||
/** RegularExpression Id. */ |
||||
int NMCHAR = 70; |
||||
/** RegularExpression Id. */ |
||||
int STRING1 = 71; |
||||
/** RegularExpression Id. */ |
||||
int STRING2 = 72; |
||||
/** RegularExpression Id. */ |
||||
int NONASCII = 73; |
||||
/** RegularExpression Id. */ |
||||
int ESCAPE = 74; |
||||
/** RegularExpression Id. */ |
||||
int NL = 75; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE = 76; |
||||
/** RegularExpression Id. */ |
||||
int HNUM = 77; |
||||
/** RegularExpression Id. */ |
||||
int H = 78; |
||||
/** RegularExpression Id. */ |
||||
int UNKNOWN = 79; |
||||
|
||||
/** Lexical state. */ |
||||
int DEFAULT = 0; |
||||
/** Lexical state. */ |
||||
int COMMENT = 1; |
||||
|
||||
/** Literal token values. */ |
||||
String[] tokenImage = { |
||||
"<EOF>", |
||||
"<S>", |
||||
"<W>", |
||||
"\"/*\"", |
||||
"\"*/\"", |
||||
"<token of kind 5>", |
||||
"\"{\"", |
||||
"\"}\"", |
||||
"\",\"", |
||||
"\".\"", |
||||
"\";\"", |
||||
"\":\"", |
||||
"\"*\"", |
||||
"\"/\"", |
||||
"\"+\"", |
||||
"\"-\"", |
||||
"\"=\"", |
||||
"\">\"", |
||||
"\"[\"", |
||||
"\"]\"", |
||||
"<HASH>", |
||||
"<STRING>", |
||||
"\")\"", |
||||
"<URL>", |
||||
"<URI>", |
||||
"\"<!--\"", |
||||
"\"-->\"", |
||||
"\"~=\"", |
||||
"\"|=\"", |
||||
"\"@import\"", |
||||
"\"@page\"", |
||||
"\"@media\"", |
||||
"\"@font-face\"", |
||||
"\"@charset\"", |
||||
"<ATKEYWORD>", |
||||
"<IMPORTANT_SYM>", |
||||
"\"inherit\"", |
||||
"<EMS>", |
||||
"<EXS>", |
||||
"<LENGTH_PX>", |
||||
"<LENGTH_CM>", |
||||
"<LENGTH_MM>", |
||||
"<LENGTH_IN>", |
||||
"<LENGTH_PT>", |
||||
"<LENGTH_PC>", |
||||
"<ANGLE_DEG>", |
||||
"<ANGLE_RAD>", |
||||
"<ANGLE_GRAD>", |
||||
"<TIME_MS>", |
||||
"<TIME_S>", |
||||
"<FREQ_HZ>", |
||||
"<FREQ_KHZ>", |
||||
"<PERCENTAGE>", |
||||
"<DIMEN>", |
||||
"<NUMBER>", |
||||
"\"rgb(\"", |
||||
"\"lang(\"", |
||||
"<FUNCTION>", |
||||
"<IDENT>", |
||||
"<NAME>", |
||||
"<NUM>", |
||||
"<UNICODERANGE>", |
||||
"<RANGE>", |
||||
"<Q16>", |
||||
"<Q15>", |
||||
"<Q14>", |
||||
"<Q13>", |
||||
"<Q12>", |
||||
"\"?\"", |
||||
"<NMSTART>", |
||||
"<NMCHAR>", |
||||
"<STRING1>", |
||||
"<STRING2>", |
||||
"<NONASCII>", |
||||
"<ESCAPE>", |
||||
"<NL>", |
||||
"<UNICODE>", |
||||
"<HNUM>", |
||||
"<H>", |
||||
"<UNKNOWN>", |
||||
}; |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,334 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SACParserCSS3Constants.java */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
|
||||
/** |
||||
* Token literal values and constants. |
||||
* Generated by org.javacc.parser.OtherFilesGen#start() |
||||
*/ |
||||
public interface SACParserCSS3Constants { |
||||
|
||||
/** End of File. */ |
||||
int EOF = 0; |
||||
/** RegularExpression Id. */ |
||||
int S = 1; |
||||
/** RegularExpression Id. */ |
||||
int W = 2; |
||||
/** RegularExpression Id. */ |
||||
int H = 6; |
||||
/** RegularExpression Id. */ |
||||
int HNUM = 7; |
||||
/** RegularExpression Id. */ |
||||
int NONASCII = 8; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE = 9; |
||||
/** RegularExpression Id. */ |
||||
int ESCAPE = 10; |
||||
/** RegularExpression Id. */ |
||||
int NMSTART = 11; |
||||
/** RegularExpression Id. */ |
||||
int NMCHAR = 12; |
||||
/** RegularExpression Id. */ |
||||
int NL = 13; |
||||
/** RegularExpression Id. */ |
||||
int STRING1 = 14; |
||||
/** RegularExpression Id. */ |
||||
int STRING2 = 15; |
||||
/** RegularExpression Id. */ |
||||
int COMMENT_ = 16; |
||||
/** RegularExpression Id. */ |
||||
int AND = 17; |
||||
/** RegularExpression Id. */ |
||||
int NOT = 18; |
||||
/** RegularExpression Id. */ |
||||
int ONLY = 19; |
||||
/** RegularExpression Id. */ |
||||
int NUMBER = 20; |
||||
/** RegularExpression Id. */ |
||||
int INHERIT = 21; |
||||
/** RegularExpression Id. */ |
||||
int IDENT = 22; |
||||
/** RegularExpression Id. */ |
||||
int NAME = 23; |
||||
/** RegularExpression Id. */ |
||||
int NUM = 24; |
||||
/** RegularExpression Id. */ |
||||
int STRING = 25; |
||||
/** RegularExpression Id. */ |
||||
int URL = 26; |
||||
/** RegularExpression Id. */ |
||||
int A_LETTER = 27; |
||||
/** RegularExpression Id. */ |
||||
int C_LETTER = 28; |
||||
/** RegularExpression Id. */ |
||||
int D_LETTER = 29; |
||||
/** RegularExpression Id. */ |
||||
int E_LETTER = 30; |
||||
/** RegularExpression Id. */ |
||||
int F_LETTER = 31; |
||||
/** RegularExpression Id. */ |
||||
int G_LETTER = 32; |
||||
/** RegularExpression Id. */ |
||||
int H_LETTER = 33; |
||||
/** RegularExpression Id. */ |
||||
int I_LETTER = 34; |
||||
/** RegularExpression Id. */ |
||||
int K_LETTER = 35; |
||||
/** RegularExpression Id. */ |
||||
int L_LETTER = 36; |
||||
/** RegularExpression Id. */ |
||||
int M_LETTER = 37; |
||||
/** RegularExpression Id. */ |
||||
int N_LETTER = 38; |
||||
/** RegularExpression Id. */ |
||||
int O_LETTER = 39; |
||||
/** RegularExpression Id. */ |
||||
int P_LETTER = 40; |
||||
/** RegularExpression Id. */ |
||||
int R_LETTER = 41; |
||||
/** RegularExpression Id. */ |
||||
int S_LETTER = 42; |
||||
/** RegularExpression Id. */ |
||||
int T_LETTER = 43; |
||||
/** RegularExpression Id. */ |
||||
int U_LETTER = 44; |
||||
/** RegularExpression Id. */ |
||||
int V_LETTER = 45; |
||||
/** RegularExpression Id. */ |
||||
int X_LETTER = 46; |
||||
/** RegularExpression Id. */ |
||||
int Z_LETTER = 47; |
||||
/** RegularExpression Id. */ |
||||
int CDO = 48; |
||||
/** RegularExpression Id. */ |
||||
int CDC = 49; |
||||
/** RegularExpression Id. */ |
||||
int INCLUDES = 50; |
||||
/** RegularExpression Id. */ |
||||
int DASHMATCH = 51; |
||||
/** RegularExpression Id. */ |
||||
int PREFIXMATCH = 52; |
||||
/** RegularExpression Id. */ |
||||
int SUFFIXMATCH = 53; |
||||
/** RegularExpression Id. */ |
||||
int SUBSTRINGMATCH = 54; |
||||
/** RegularExpression Id. */ |
||||
int LBRACE = 55; |
||||
/** RegularExpression Id. */ |
||||
int RBRACE = 56; |
||||
/** RegularExpression Id. */ |
||||
int LROUND = 57; |
||||
/** RegularExpression Id. */ |
||||
int RROUND = 58; |
||||
/** RegularExpression Id. */ |
||||
int DOT = 59; |
||||
/** RegularExpression Id. */ |
||||
int SEMICOLON = 60; |
||||
/** RegularExpression Id. */ |
||||
int COLON = 61; |
||||
/** RegularExpression Id. */ |
||||
int ASTERISK = 62; |
||||
/** RegularExpression Id. */ |
||||
int SLASH = 63; |
||||
/** RegularExpression Id. */ |
||||
int MINUS = 64; |
||||
/** RegularExpression Id. */ |
||||
int EQUALS = 65; |
||||
/** RegularExpression Id. */ |
||||
int LSQUARE = 66; |
||||
/** RegularExpression Id. */ |
||||
int RSQUARE = 67; |
||||
/** RegularExpression Id. */ |
||||
int PLUS = 68; |
||||
/** RegularExpression Id. */ |
||||
int GREATER = 69; |
||||
/** RegularExpression Id. */ |
||||
int TILDE = 70; |
||||
/** RegularExpression Id. */ |
||||
int COMMA = 71; |
||||
/** RegularExpression Id. */ |
||||
int HASH = 72; |
||||
/** RegularExpression Id. */ |
||||
int IMPORT_SYM = 73; |
||||
/** RegularExpression Id. */ |
||||
int PAGE_SYM = 74; |
||||
/** RegularExpression Id. */ |
||||
int MEDIA_SYM = 75; |
||||
/** RegularExpression Id. */ |
||||
int FONT_FACE_SYM = 76; |
||||
/** RegularExpression Id. */ |
||||
int CHARSET_SYM = 77; |
||||
/** RegularExpression Id. */ |
||||
int IMPORTANT_SYM = 78; |
||||
/** RegularExpression Id. */ |
||||
int EMS = 79; |
||||
/** RegularExpression Id. */ |
||||
int EXS = 80; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PX = 81; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_CM = 82; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_MM = 83; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_IN = 84; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PT = 85; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PC = 86; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_DEG = 87; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_RAD = 88; |
||||
/** RegularExpression Id. */ |
||||
int ANGLE_GRAD = 89; |
||||
/** RegularExpression Id. */ |
||||
int TIME_MS = 90; |
||||
/** RegularExpression Id. */ |
||||
int TIME_S = 91; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_HZ = 92; |
||||
/** RegularExpression Id. */ |
||||
int FREQ_KHZ = 93; |
||||
/** RegularExpression Id. */ |
||||
int RESOLUTION_DPI = 94; |
||||
/** RegularExpression Id. */ |
||||
int RESOLUTION_DPCM = 95; |
||||
/** RegularExpression Id. */ |
||||
int PERCENTAGE = 96; |
||||
/** RegularExpression Id. */ |
||||
int DIMENSION = 97; |
||||
/** RegularExpression Id. */ |
||||
int H_PLACEHOLDER = 98; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE_RANGE = 99; |
||||
/** RegularExpression Id. */ |
||||
int URI = 100; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION_NOT = 101; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION_LANG = 102; |
||||
/** RegularExpression Id. */ |
||||
int FUNCTION = 103; |
||||
/** RegularExpression Id. */ |
||||
int ATKEYWORD = 104; |
||||
/** RegularExpression Id. */ |
||||
int UNKNOWN = 105; |
||||
|
||||
/** Lexical state. */ |
||||
int DEFAULT = 0; |
||||
/** Lexical state. */ |
||||
int COMMENT = 1; |
||||
|
||||
/** Literal token values. */ |
||||
String[] tokenImage = { |
||||
"<EOF>", |
||||
"<S>", |
||||
"<W>", |
||||
"\"/*\"", |
||||
"\"*/\"", |
||||
"<token of kind 5>", |
||||
"<H>", |
||||
"<HNUM>", |
||||
"<NONASCII>", |
||||
"<UNICODE>", |
||||
"<ESCAPE>", |
||||
"<NMSTART>", |
||||
"<NMCHAR>", |
||||
"<NL>", |
||||
"<STRING1>", |
||||
"<STRING2>", |
||||
"<COMMENT_>", |
||||
"\"and\"", |
||||
"\"not\"", |
||||
"\"only\"", |
||||
"<NUMBER>", |
||||
"\"inherit\"", |
||||
"<IDENT>", |
||||
"<NAME>", |
||||
"<NUM>", |
||||
"<STRING>", |
||||
"<URL>", |
||||
"<A_LETTER>", |
||||
"<C_LETTER>", |
||||
"<D_LETTER>", |
||||
"<E_LETTER>", |
||||
"<F_LETTER>", |
||||
"<G_LETTER>", |
||||
"<H_LETTER>", |
||||
"<I_LETTER>", |
||||
"<K_LETTER>", |
||||
"<L_LETTER>", |
||||
"<M_LETTER>", |
||||
"<N_LETTER>", |
||||
"<O_LETTER>", |
||||
"<P_LETTER>", |
||||
"<R_LETTER>", |
||||
"<S_LETTER>", |
||||
"<T_LETTER>", |
||||
"<U_LETTER>", |
||||
"<V_LETTER>", |
||||
"<X_LETTER>", |
||||
"<Z_LETTER>", |
||||
"\"<!--\"", |
||||
"\"-->\"", |
||||
"\"~=\"", |
||||
"\"|=\"", |
||||
"\"^=\"", |
||||
"\"$=\"", |
||||
"\"*=\"", |
||||
"<LBRACE>", |
||||
"\"}\"", |
||||
"\"(\"", |
||||
"\")\"", |
||||
"\".\"", |
||||
"\";\"", |
||||
"\":\"", |
||||
"\"*\"", |
||||
"\"/\"", |
||||
"\"-\"", |
||||
"\"=\"", |
||||
"\"[\"", |
||||
"\"]\"", |
||||
"<PLUS>", |
||||
"<GREATER>", |
||||
"\"~\"", |
||||
"<COMMA>", |
||||
"<HASH>", |
||||
"<IMPORT_SYM>", |
||||
"<PAGE_SYM>", |
||||
"<MEDIA_SYM>", |
||||
"<FONT_FACE_SYM>", |
||||
"<CHARSET_SYM>", |
||||
"<IMPORTANT_SYM>", |
||||
"<EMS>", |
||||
"<EXS>", |
||||
"<LENGTH_PX>", |
||||
"<LENGTH_CM>", |
||||
"<LENGTH_MM>", |
||||
"<LENGTH_IN>", |
||||
"<LENGTH_PT>", |
||||
"<LENGTH_PC>", |
||||
"<ANGLE_DEG>", |
||||
"<ANGLE_RAD>", |
||||
"<ANGLE_GRAD>", |
||||
"<TIME_MS>", |
||||
"<TIME_S>", |
||||
"<FREQ_HZ>", |
||||
"<FREQ_KHZ>", |
||||
"<RESOLUTION_DPI>", |
||||
"<RESOLUTION_DPCM>", |
||||
"<PERCENTAGE>", |
||||
"<DIMENSION>", |
||||
"<H_PLACEHOLDER>", |
||||
"<UNICODE_RANGE>", |
||||
"<URI>", |
||||
"<FUNCTION_NOT>", |
||||
"<FUNCTION_LANG>", |
||||
"<FUNCTION>", |
||||
"<ATKEYWORD>", |
||||
"<UNKNOWN>", |
||||
"\"progid:\"", |
||||
}; |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,219 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. SACParserCSSmobileOKBasic1Constants.java */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
|
||||
/** |
||||
* Token literal values and constants. |
||||
* Generated by org.javacc.parser.OtherFilesGen#start() |
||||
*/ |
||||
public interface SACParserCSSmobileOKBasic1Constants { |
||||
|
||||
/** End of File. */ |
||||
int EOF = 0; |
||||
/** RegularExpression Id. */ |
||||
int S = 1; |
||||
/** RegularExpression Id. */ |
||||
int IDENT = 3; |
||||
/** RegularExpression Id. */ |
||||
int LINK_PSCLASS = 4; |
||||
/** RegularExpression Id. */ |
||||
int VISITED_PSCLASS = 5; |
||||
/** RegularExpression Id. */ |
||||
int ACTIVE_PSCLASS = 6; |
||||
/** RegularExpression Id. */ |
||||
int FIRST_LINE = 7; |
||||
/** RegularExpression Id. */ |
||||
int FIRST_LETTER = 8; |
||||
/** RegularExpression Id. */ |
||||
int HASH = 9; |
||||
/** RegularExpression Id. */ |
||||
int LBRACE = 10; |
||||
/** RegularExpression Id. */ |
||||
int RBRACE = 11; |
||||
/** RegularExpression Id. */ |
||||
int COMMA = 12; |
||||
/** RegularExpression Id. */ |
||||
int DOT = 13; |
||||
/** RegularExpression Id. */ |
||||
int SEMICOLON = 14; |
||||
/** RegularExpression Id. */ |
||||
int COLON = 15; |
||||
/** RegularExpression Id. */ |
||||
int ASTERISK = 16; |
||||
/** RegularExpression Id. */ |
||||
int SLASH = 17; |
||||
/** RegularExpression Id. */ |
||||
int PLUS = 18; |
||||
/** RegularExpression Id. */ |
||||
int MINUS = 19; |
||||
/** RegularExpression Id. */ |
||||
int EQUALS = 20; |
||||
/** RegularExpression Id. */ |
||||
int GT = 21; |
||||
/** RegularExpression Id. */ |
||||
int LSQUARE = 22; |
||||
/** RegularExpression Id. */ |
||||
int RSQUARE = 23; |
||||
/** RegularExpression Id. */ |
||||
int STRING = 24; |
||||
/** RegularExpression Id. */ |
||||
int RROUND = 25; |
||||
/** RegularExpression Id. */ |
||||
int URL = 26; |
||||
/** RegularExpression Id. */ |
||||
int CDO = 27; |
||||
/** RegularExpression Id. */ |
||||
int CDC = 28; |
||||
/** RegularExpression Id. */ |
||||
int IMPORT_SYM = 29; |
||||
/** RegularExpression Id. */ |
||||
int MEDIA_SYM = 30; |
||||
/** RegularExpression Id. */ |
||||
int IMPORTANT_SYM = 31; |
||||
/** RegularExpression Id. */ |
||||
int ATKEYWORD = 32; |
||||
/** RegularExpression Id. */ |
||||
int EMS = 33; |
||||
/** RegularExpression Id. */ |
||||
int EXS = 34; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PX = 35; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_CM = 36; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_MM = 37; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_IN = 38; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PT = 39; |
||||
/** RegularExpression Id. */ |
||||
int LENGTH_PC = 40; |
||||
/** RegularExpression Id. */ |
||||
int PERCENTAGE = 41; |
||||
/** RegularExpression Id. */ |
||||
int NUMBER = 42; |
||||
/** RegularExpression Id. */ |
||||
int RGB = 43; |
||||
/** RegularExpression Id. */ |
||||
int NAME = 44; |
||||
/** RegularExpression Id. */ |
||||
int D = 45; |
||||
/** RegularExpression Id. */ |
||||
int NUM = 46; |
||||
/** RegularExpression Id. */ |
||||
int UNICODERANGE = 47; |
||||
/** RegularExpression Id. */ |
||||
int RANGE = 48; |
||||
/** RegularExpression Id. */ |
||||
int Q16 = 49; |
||||
/** RegularExpression Id. */ |
||||
int Q15 = 50; |
||||
/** RegularExpression Id. */ |
||||
int Q14 = 51; |
||||
/** RegularExpression Id. */ |
||||
int Q13 = 52; |
||||
/** RegularExpression Id. */ |
||||
int Q12 = 53; |
||||
/** RegularExpression Id. */ |
||||
int Q11 = 54; |
||||
/** RegularExpression Id. */ |
||||
int NMSTART = 55; |
||||
/** RegularExpression Id. */ |
||||
int NMCHAR = 56; |
||||
/** RegularExpression Id. */ |
||||
int STRING1 = 57; |
||||
/** RegularExpression Id. */ |
||||
int STRING2 = 58; |
||||
/** RegularExpression Id. */ |
||||
int NONASCII = 59; |
||||
/** RegularExpression Id. */ |
||||
int ESCAPE = 60; |
||||
/** RegularExpression Id. */ |
||||
int NL = 61; |
||||
/** RegularExpression Id. */ |
||||
int UNICODE = 62; |
||||
/** RegularExpression Id. */ |
||||
int HNUM = 63; |
||||
/** RegularExpression Id. */ |
||||
int H = 64; |
||||
/** RegularExpression Id. */ |
||||
int UNKNOWN = 67; |
||||
|
||||
/** Lexical state. */ |
||||
int DEFAULT = 0; |
||||
/** Lexical state. */ |
||||
int COMMENT = 1; |
||||
|
||||
/** Literal token values. */ |
||||
String[] tokenImage = { |
||||
"<EOF>", |
||||
"<S>", |
||||
"\"/*\"", |
||||
"<IDENT>", |
||||
"\":link\"", |
||||
"\":visited\"", |
||||
"\":active\"", |
||||
"\":first-line\"", |
||||
"\":first-letter\"", |
||||
"<HASH>", |
||||
"\"{\"", |
||||
"\"}\"", |
||||
"\",\"", |
||||
"\".\"", |
||||
"\";\"", |
||||
"\":\"", |
||||
"\"*\"", |
||||
"\"/\"", |
||||
"\"+\"", |
||||
"\"-\"", |
||||
"\"=\"", |
||||
"\">\"", |
||||
"\"[\"", |
||||
"\"]\"", |
||||
"<STRING>", |
||||
"\")\"", |
||||
"<URL>", |
||||
"\"<!--\"", |
||||
"\"-->\"", |
||||
"\"@import\"", |
||||
"\"@media\"", |
||||
"<IMPORTANT_SYM>", |
||||
"<ATKEYWORD>", |
||||
"<EMS>", |
||||
"<EXS>", |
||||
"<LENGTH_PX>", |
||||
"<LENGTH_CM>", |
||||
"<LENGTH_MM>", |
||||
"<LENGTH_IN>", |
||||
"<LENGTH_PT>", |
||||
"<LENGTH_PC>", |
||||
"<PERCENTAGE>", |
||||
"<NUMBER>", |
||||
"\"rgb(\"", |
||||
"<NAME>", |
||||
"<D>", |
||||
"<NUM>", |
||||
"<UNICODERANGE>", |
||||
"<RANGE>", |
||||
"<Q16>", |
||||
"<Q15>", |
||||
"<Q14>", |
||||
"<Q13>", |
||||
"<Q12>", |
||||
"\"?\"", |
||||
"<NMSTART>", |
||||
"<NMCHAR>", |
||||
"<STRING1>", |
||||
"<STRING2>", |
||||
"<NONASCII>", |
||||
"<ESCAPE>", |
||||
"<NL>", |
||||
"<UNICODE>", |
||||
"<HNUM>", |
||||
"<H>", |
||||
"\"*/\"", |
||||
"<token of kind 66>", |
||||
"<UNKNOWN>", |
||||
}; |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,39 @@
|
||||
# resource bundle for SACParser messages - default |
||||
invalidExpectingOne=Invalid token \"{0}\". Was expecting: {1}. |
||||
invalidExpectingMore=Invalid token \"{0}\". Was expecting one of: {1}. |
||||
invalidColor=Invalid color \"{0}\". |
||||
invalidStyleSheet=Error in style sheet. |
||||
invalidRule=Error in rule. |
||||
invalidUnknownRule=Error in unknown at-rule. |
||||
invalidCharsetRule=Error in @charset rule. |
||||
misplacedCharsetRule=The @charset must be the first element in the style sheet. |
||||
invalidImportRule=Error in @import rule. |
||||
invalidImportRuleIgnored=@import rule must occur before all other rules. |
||||
invalidImportRuleIgnored2=@import rule must occur before all other rules, except the @charset rule. |
||||
invalidPageRule=Error in @page rule. |
||||
invalidFontFaceRule=Error in @font-face rule. |
||||
invalidMediaList=Error in media list. |
||||
invalidMediaRule=Error in @media rule. |
||||
invalidStyleRule=Error in style rule. |
||||
invalidStyleDeclaration=Error in style declaration. |
||||
invalidDeclaration=Error in declaration. |
||||
invalidDeclarationInvalidChar=Error in declaration; invalid character \"{0}\" found. |
||||
invalidDeclarationStarHack=Error in declaration. ''*'' is not allowed as first char of a property. |
||||
invalidSelectorList=Error in selector list. |
||||
invalidSelector=Error in selector. |
||||
invalidSimpleSelector=Error in simple selector. |
||||
invalidClassSelector=Error in class selector. |
||||
invalidElementName=Error in element name. |
||||
invalidAttrib=Error in attribute selector. |
||||
invalidPseudo=Error in pseudo class or element. |
||||
duplicatePseudo=Duplicate pseudo class \":{0}\" or pseudo class \":{0}\" not at end. |
||||
invalidHash=Error in hash. |
||||
invalidExpr=Error in expression. |
||||
invalidExprColon=Error in expression; '':'' found after identifier \"{0}\". |
||||
invalidPrio=Error in priority. |
||||
|
||||
ignoringRule=Ignoring the whole rule. |
||||
ignoringFollowingDeclarations=Ignoring the following declarations in this rule. |
||||
|
||||
tokenMgrError=Lexical error. |
||||
domException=DOM exception: ''{0}'' |
@ -0,0 +1,39 @@
|
||||
# resource bundle for SACParser messages - german |
||||
invalidExpectingOne=Ung\u00fcltiger Token \"{0}\". Erwartet wurde: {1}. |
||||
invalidExpectingMore=Ung\u00fcltiger Token \"{0}\". Erwartet wurde einer von: {1}. |
||||
invalidColor=Ung\u00fcltige Farbe \"{0}\". |
||||
invalidStyleSheet=Fehler im Stylesheet. |
||||
invalidRule=Fehler in Regel. |
||||
invalidUnknownRule=Fehler in unbekannter At-Regel. |
||||
invalidCharsetRule=Fehler in @charset-Regel. |
||||
misplacedCharsetRule=Die @charset Regel muss das erste Element im Stylesheet sein. |
||||
invalidImportRule=Fehler in @import-Regel. |
||||
invalidImportRuleIgnored=@import-Regel muss vor allen anderen Regeln erscheinen. |
||||
invalidImportRuleIgnored2=@import-Regel muss vor allen anderen Regeln erscheinen, au\u00dfer der @charset-Regel. |
||||
invalidPageRule=Fehler in @page-Regel. |
||||
invalidFontFaceRule=Fehler in @font-face-Regel. |
||||
invalidMediaList=Fehler in Medienliste. |
||||
invalidMediaRule=Fehler in @media-Regel. |
||||
invalidStyleRule=Fehler in Style-Regel. |
||||
invalidStyleDeclaration=Fehler in Styledeklaration. |
||||
invalidDeclaration=Fehler in Deklaration. |
||||
invalidDeclarationInvalidChar=Fehler in Deklaration. Es wurde das ung\u00fcltige Zeichen \"{0}\" gefunden. |
||||
invalidDeclarationStarHack=Error in declaration. ''*'' ist als erstes Zeichen einer Property nicht erlaubt. |
||||
invalidSelectorList=Fehler in Selektorliste. |
||||
invalidSelector=Fehler in Selektor. |
||||
invalidSimpleSelector=Fehler in einfachem Selektor. |
||||
invalidClassSelector=Fehler in Klassen-Selektor. |
||||
invalidElementName=Fehler in Elementname. |
||||
invalidAttrib=Fehler in Attribut-Selektor. |
||||
invalidPseudo=Fehler in Pseudo-Klasse oder Pseudo-Element. |
||||
duplicatePseudo=Doppelte Pseudo-Klasse \":{0}\" oder die Pseudo-Klasse \":{0}\" ist nicht das letzte Element. |
||||
invalidHash=Fehler in Hash. |
||||
invalidExpr=Fehler in Ausdruck. |
||||
invalidExprColon=Fehler in Ausdruck; '':'' nach dem identifier \"{0}\" gefunden. |
||||
invalidPrio=Fehler in Priorit\u00e4t. |
||||
|
||||
ignoringRule=Ignoriere die gesamte Regel. |
||||
ignoringFollowingDeclarations=Ignoriere die folgenden Deklarationen in dieser Regel. |
||||
|
||||
tokenMgrError=Lexikalischer Fehler. |
||||
domException=DOM Fehler: ''{0}'' |
@ -0,0 +1,40 @@
|
||||
# resource bundle for SACParser messages - default |
||||
invalidExpectingOne=Invalid token \"{0}\". Was expecting: {1}. |
||||
invalidExpectingMore=Invalid token \"{0}\". Was expecting one of: {1}. |
||||
invalidColor=Invalid color \"{0}\". |
||||
invalidStyleSheet=Error in style sheet. |
||||
invalidRule=Error in rule. |
||||
invalidUnknownRule=Error in unknown at-rule. |
||||
invalidCharsetRule=Error in @charset rule. |
||||
misplacedCharsetRule=The @charset must be the first element in the style sheet. |
||||
invalidImportRule=Error in @import rule. |
||||
invalidImportRuleIgnored=@import rule must occur before all other rules. |
||||
invalidImportRuleIgnored2=@import rule must occur before all other rules, except the @charset rule. |
||||
invalidPageRule=Error in @page rule. |
||||
invalidFontFaceRule=Error in @font-face rule. |
||||
invalidMediaList=Error in media list. |
||||
invalidMediaRule=Error in @media rule. |
||||
invalidStyleRule=Error in style rule. |
||||
invalidStyleDeclaration=Error in style declaration. |
||||
invalidDeclaration=Error in declaration. |
||||
invalidDeclarationInvalidChar=Error in declaration; invalid character \"{0}\" found. |
||||
invalidDeclarationStarHack=Error in declaration. ''*'' is not allowed as first char of a property. |
||||
invalidSelectorList=Error in selector list. |
||||
invalidSelector=Error in selector. |
||||
invalidSimpleSelector=Error in simple selector. |
||||
invalidClassSelector=Error in class selector. |
||||
invalidElementName=Error in element name. |
||||
invalidAttrib=Error in attribute selector. |
||||
invalidPseudo=Error in pseudo class or element. |
||||
duplicatePseudo=Duplicate pseudo class \":{0}\" or pseudo class \":{0}\" not at end. |
||||
invalidHash=Error in hash. |
||||
invalidExpr=Error in expression. |
||||
invalidExprColon=Error in expression; '':'' found after identifier \"{0}\". |
||||
invalidPrio=Error in priority. |
||||
|
||||
ignoringRule=Ignoring the whole rule. |
||||
ignoringFollowingDeclarations=Ignoring the following declarations in this rule. |
||||
|
||||
tokenMgrError=Lexical error. |
||||
domException=DOM exception: ''{0}'' |
||||
|
@ -0,0 +1,81 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SelectorList; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Implementation of {@link SelectorList}. |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class SelectorListImpl extends LocatableImpl implements SelectorList, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 7313376916207026333L; |
||||
|
||||
private List<Selector> selectors_ = new ArrayList<Selector>(10); |
||||
|
||||
public List<Selector> getSelectors() { |
||||
return selectors_; |
||||
} |
||||
|
||||
public void setSelectors(final List<Selector> selectors) { |
||||
selectors_ = selectors; |
||||
} |
||||
|
||||
public int getLength() { |
||||
return selectors_.size(); |
||||
} |
||||
|
||||
public Selector item(final int index) { |
||||
return selectors_.get(index); |
||||
} |
||||
|
||||
public void add(final Selector sel) { |
||||
selectors_.add(sel); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final int len = getLength(); |
||||
|
||||
final StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < len; i++) { |
||||
final CSSFormatable sel = (CSSFormatable) item(i); |
||||
sb.append(sel.getCssText(format)); |
||||
if (i < len - 1) { |
||||
sb.append(", "); |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,132 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. Token.java Version 7.0 */ |
||||
/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** |
||||
* Describes the input token stream. |
||||
*/ |
||||
|
||||
@SuppressWarnings("all") public class Token implements java.io.Serializable { |
||||
|
||||
/** |
||||
* The version identifier for this Serializable class. |
||||
* Increment only if the <i>serialized</i> form of the |
||||
* class changes. |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* An integer that describes the kind of this token. This numbering |
||||
* system is determined by JavaCCParser, and a table of these numbers is |
||||
* stored in the file ...Constants.java. |
||||
*/ |
||||
public int kind; |
||||
|
||||
/** The line number of the first character of this Token. */ |
||||
public int beginLine; |
||||
/** The column number of the first character of this Token. */ |
||||
public int beginColumn; |
||||
/** The line number of the last character of this Token. */ |
||||
public int endLine; |
||||
/** The column number of the last character of this Token. */ |
||||
public int endColumn; |
||||
|
||||
/** |
||||
* The string image of the token. |
||||
*/ |
||||
public String image; |
||||
|
||||
/** |
||||
* A reference to the next regular (non-special) token from the input |
||||
* stream. If this is the last token from the input stream, or if the |
||||
* token manager has not read tokens beyond this one, this field is |
||||
* set to null. This is true only if this token is also a regular |
||||
* token. Otherwise, see below for a description of the contents of |
||||
* this field. |
||||
*/ |
||||
public Token next; |
||||
|
||||
/** |
||||
* This field is used to access special tokens that occur prior to this |
||||
* token, but after the immediately preceding regular (non-special) token. |
||||
* If there are no such special tokens, this field is set to null. |
||||
* When there are more than one such special token, this field refers |
||||
* to the last of these special tokens, which in turn refers to the next |
||||
* previous special token through its specialToken field, and so on |
||||
* until the first special token (whose specialToken field is null). |
||||
* The next fields of special tokens refer to other special tokens that |
||||
* immediately follow it (without an intervening regular token). If there |
||||
* is no such token, this field is null. |
||||
*/ |
||||
public Token specialToken; |
||||
|
||||
/** |
||||
* An optional attribute value of the Token. |
||||
* Tokens which are not used as syntactic sugar will often contain |
||||
* meaningful values that will be used later on by the compiler or |
||||
* interpreter. This attribute value is often different from the image. |
||||
* Any subclass of Token that actually wants to return a non-null value can |
||||
* override this method as appropriate. |
||||
*/ |
||||
public Object getValue() { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* No-argument constructor |
||||
*/ |
||||
public Token() {} |
||||
|
||||
/** |
||||
* Constructs a new token for the specified Image. |
||||
*/ |
||||
public Token(int kind) |
||||
{ |
||||
this(kind, null); |
||||
} |
||||
|
||||
/** |
||||
* Constructs a new token for the specified Image and Kind. |
||||
*/ |
||||
public Token(int kind, String image) |
||||
{ |
||||
this.kind = kind; |
||||
this.image = image; |
||||
} |
||||
|
||||
/** |
||||
* Returns the image. |
||||
*/ |
||||
@Override |
||||
public String toString() |
||||
{ |
||||
return image; |
||||
} |
||||
|
||||
/** |
||||
* Returns a new Token object, by default. However, if you want, you |
||||
* can create and return subclass objects based on the value of ofKind. |
||||
* Simply add the cases to the switch for all those special cases. |
||||
* For example, if you have a subclass of Token called IDToken that |
||||
* you want to create if ofKind is ID, simply add something like : |
||||
* |
||||
* case MyParserConstants.ID : return new IDToken(ofKind, image); |
||||
* |
||||
* to the following switch statement. Then you can cast matchedToken |
||||
* variable to the appropriate type and use sit in your lexical actions. |
||||
*/ |
||||
public static Token newToken(int ofKind, String image) |
||||
{ |
||||
switch(ofKind) |
||||
{ |
||||
default : return new Token(ofKind, image); |
||||
} |
||||
} |
||||
|
||||
public static Token newToken(int ofKind) |
||||
{ |
||||
return newToken(ofKind, null); |
||||
} |
||||
|
||||
} |
||||
/* JavaCC - OriginalChecksum=42fb99eba8a3a8a58b2bdee94f557744 (do not edit this line) */ |
@ -0,0 +1,147 @@
|
||||
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 7.0 */ |
||||
/* JavaCCOptions: */ |
||||
package com.fr.third.steadystate.css.parser; |
||||
|
||||
/** Token Manager Error. */ |
||||
@SuppressWarnings("all") public class TokenMgrError extends Error |
||||
{ |
||||
|
||||
/** |
||||
* The version identifier for this Serializable class. |
||||
* Increment only if the <i>serialized</i> form of the |
||||
* class changes. |
||||
*/ |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/* |
||||
* Ordinals for various reasons why an Error of this type can be thrown. |
||||
*/ |
||||
|
||||
/** |
||||
* Lexical error occurred. |
||||
*/ |
||||
public static final int LEXICAL_ERROR = 0; |
||||
|
||||
/** |
||||
* An attempt was made to create a second instance of a static token manager. |
||||
*/ |
||||
public static final int STATIC_LEXER_ERROR = 1; |
||||
|
||||
/** |
||||
* Tried to change to an invalid lexical state. |
||||
*/ |
||||
public static final int INVALID_LEXICAL_STATE = 2; |
||||
|
||||
/** |
||||
* Detected (and bailed out of) an infinite loop in the token manager. |
||||
*/ |
||||
public static final int LOOP_DETECTED = 3; |
||||
|
||||
/** |
||||
* Indicates the reason why the exception is thrown. It will have |
||||
* one of the above 4 values. |
||||
*/ |
||||
int errorCode; |
||||
|
||||
/** |
||||
* Replaces unprintable characters by their escaped (or unicode escaped) |
||||
* equivalents in the given string |
||||
*/ |
||||
protected static final String addEscapes(String str) { |
||||
StringBuffer retval = new StringBuffer(); |
||||
char ch; |
||||
for (int i = 0; i < str.length(); i++) { |
||||
switch (str.charAt(i)) |
||||
{ |
||||
case '\b': |
||||
retval.append("\\b"); |
||||
continue; |
||||
case '\t': |
||||
retval.append("\\t"); |
||||
continue; |
||||
case '\n': |
||||
retval.append("\\n"); |
||||
continue; |
||||
case '\f': |
||||
retval.append("\\f"); |
||||
continue; |
||||
case '\r': |
||||
retval.append("\\r"); |
||||
continue; |
||||
case '\"': |
||||
retval.append("\\\""); |
||||
continue; |
||||
case '\'': |
||||
retval.append("\\\'"); |
||||
continue; |
||||
case '\\': |
||||
retval.append("\\\\"); |
||||
continue; |
||||
default: |
||||
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
||||
String s = "0000" + Integer.toString(ch, 16); |
||||
retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
||||
} else { |
||||
retval.append(ch); |
||||
} |
||||
continue; |
||||
} |
||||
} |
||||
return retval.toString(); |
||||
} |
||||
|
||||
/** |
||||
* Returns a detailed message for the Error when it is thrown by the |
||||
* token manager to indicate a lexical error. |
||||
* Parameters : |
||||
* EOFSeen : indicates if EOF caused the lexical error |
||||
* curLexState : lexical state in which this error occurred |
||||
* errorLine : line number when the error occurred |
||||
* errorColumn : column number when the error occurred |
||||
* errorAfter : prefix that was seen before this error occurred |
||||
* curchar : the offending character |
||||
* Note: You can customize the lexical error message by modifying this method. |
||||
*/ |
||||
protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { |
||||
char curChar1 = (char)curChar; |
||||
return("Lexical error at line " + |
||||
errorLine + ", column " + |
||||
errorColumn + ". Encountered: " + |
||||
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + |
||||
"after : \"" + addEscapes(errorAfter) + "\""); |
||||
} |
||||
|
||||
/** |
||||
* You can also modify the body of this method to customize your error messages. |
||||
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not |
||||
* of end-users concern, so you can return something like : |
||||
* |
||||
* "Internal Error : Please file a bug report .... " |
||||
* |
||||
* from this method for such cases in the release version of your parser. |
||||
*/ |
||||
@Override |
||||
public String getMessage() { |
||||
return super.getMessage(); |
||||
} |
||||
|
||||
/* |
||||
* Constructors of various flavors follow. |
||||
*/ |
||||
|
||||
/** No arg constructor. */ |
||||
public TokenMgrError() { |
||||
} |
||||
|
||||
/** Constructor with message and reason. */ |
||||
public TokenMgrError(String message, int reason) { |
||||
super(message); |
||||
errorCode = reason; |
||||
} |
||||
|
||||
/** Full Constructor. */ |
||||
public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { |
||||
this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); |
||||
} |
||||
} |
||||
/* JavaCC - OriginalChecksum=79a7770cdb8d32ef3bb22077e08dbe6a (do not edit this line) */ |
@ -0,0 +1,101 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.media; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.steadystate.css.dom.Property; |
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* @author rbri |
||||
*/ |
||||
public class MediaQuery extends LocatableImpl implements CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 456776383828897471L; |
||||
|
||||
private String media_; |
||||
private List<Property> properties_; |
||||
private boolean isOnly_; |
||||
private boolean isNot_; |
||||
|
||||
public MediaQuery(final String media) { |
||||
this(media, false, false); |
||||
} |
||||
|
||||
public MediaQuery(final String media, final boolean isOnly, final boolean isNot) { |
||||
setMedia(media); |
||||
properties_ = new ArrayList<Property>(10); |
||||
isOnly_ = isOnly; |
||||
isNot_ = isNot; |
||||
} |
||||
|
||||
public String getMedia() { |
||||
return media_; |
||||
} |
||||
|
||||
public void setMedia(final String media) { |
||||
media_ = media; |
||||
} |
||||
|
||||
public List<Property> getProperties() { |
||||
return properties_; |
||||
} |
||||
|
||||
public void addMediaProperty(final Property mp) { |
||||
properties_.add(mp); |
||||
} |
||||
|
||||
public boolean isOnly() { |
||||
return isOnly_; |
||||
} |
||||
|
||||
public boolean isNot() { |
||||
return isNot_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (isOnly_) { |
||||
sb.append("only "); |
||||
} |
||||
if (isNot_) { |
||||
sb.append("not "); |
||||
} |
||||
|
||||
sb.append(getMedia()); |
||||
|
||||
for (Property prop : properties_) { |
||||
sb.append(" and (") |
||||
.append(prop.getCssText(format)) |
||||
.append(')'); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.CombinatorCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class AndConditionImpl extends LocatableImpl implements CombinatorCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -3180583860092672742L; |
||||
|
||||
private Condition firstCondition_; |
||||
private Condition secondCondition_; |
||||
|
||||
public void setFirstCondition(final Condition c1) { |
||||
firstCondition_ = c1; |
||||
if (c1 instanceof Locatable) { |
||||
setLocator(((Locatable) c1).getLocator()); |
||||
} |
||||
else if (c1 == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setSecondCondition(final Condition c2) { |
||||
secondCondition_ = c2; |
||||
} |
||||
|
||||
public AndConditionImpl(final Condition c1, final Condition c2) { |
||||
setFirstCondition(c1); |
||||
setSecondCondition(c2); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_AND_CONDITION; |
||||
} |
||||
|
||||
public Condition getFirstCondition() { |
||||
return firstCondition_; |
||||
} |
||||
|
||||
public Condition getSecondCondition() { |
||||
return secondCondition_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
Condition cond = getFirstCondition(); |
||||
if (null != cond) { |
||||
sb.append(((CSSFormatable) cond).getCssText(format)); |
||||
} |
||||
|
||||
cond = getSecondCondition(); |
||||
if (null != cond) { |
||||
sb.append(((CSSFormatable) cond).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class AttributeConditionImpl extends LocatableImpl implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 9035418830958954213L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocaleName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public AttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocaleName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ATTRIBUTE_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class BeginHyphenAttributeConditionImpl extends LocatableImpl |
||||
implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 6552118983276681650L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocaleName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public BeginHyphenAttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocaleName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "|=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,69 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.CharacterDataSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class CharacterDataSelectorImpl extends LocatableImpl |
||||
implements CharacterDataSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 4635511567927852889L; |
||||
|
||||
private String data_; |
||||
|
||||
public void setData(final String data) { |
||||
data_ = data; |
||||
} |
||||
|
||||
public CharacterDataSelectorImpl(final String data) { |
||||
setData(data); |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_CDATA_SECTION_NODE_SELECTOR; |
||||
} |
||||
|
||||
public String getData() { |
||||
return data_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String data = getData(); |
||||
if (data == null) { |
||||
return ""; |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import org.w3c.css.sac.DescendantSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class ChildSelectorImpl extends LocatableImpl implements DescendantSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -5843289529637921083L; |
||||
|
||||
private Selector ancestorSelector_; |
||||
private SimpleSelector simpleSelector_; |
||||
|
||||
public void setAncestorSelector(final Selector ancestorSelector) { |
||||
ancestorSelector_ = ancestorSelector; |
||||
if (ancestorSelector instanceof Locatable) { |
||||
setLocator(((Locatable) ancestorSelector).getLocator()); |
||||
} |
||||
else if (ancestorSelector == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setSimpleSelector(final SimpleSelector simpleSelector) { |
||||
simpleSelector_ = simpleSelector; |
||||
} |
||||
|
||||
public ChildSelectorImpl(final Selector parent, final SimpleSelector simpleSelector) { |
||||
setAncestorSelector(parent); |
||||
setSimpleSelector(simpleSelector); |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_CHILD_SELECTOR; |
||||
} |
||||
|
||||
public Selector getAncestorSelector() { |
||||
return ancestorSelector_; |
||||
} |
||||
|
||||
public SimpleSelector getSimpleSelector() { |
||||
return simpleSelector_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (null != ancestorSelector_) { |
||||
sb.append(((CSSFormatable) ancestorSelector_).getCssText(format)); |
||||
} |
||||
|
||||
sb.append(" > "); |
||||
|
||||
if (null != simpleSelector_) { |
||||
sb.append(((CSSFormatable) simpleSelector_).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class ClassConditionImpl extends LocatableImpl implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -2216489300949054242L; |
||||
|
||||
private String value_; |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public ClassConditionImpl(final String value) { |
||||
setValue(value); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_CLASS_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return null; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return true; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "." + value; |
||||
} |
||||
return "."; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,164 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CombinatorCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.ContentCondition; |
||||
import org.w3c.css.sac.LangCondition; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.NegativeCondition; |
||||
import org.w3c.css.sac.PositionalCondition; |
||||
|
||||
import com.fr.third.steadystate.css.sac.ConditionFactoryExt; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author Ronald Brill |
||||
*/ |
||||
public class ConditionFactoryImpl implements ConditionFactoryExt { |
||||
|
||||
public CombinatorCondition createAndCondition(final Condition first, final Condition second) throws CSSException { |
||||
return new AndConditionImpl(first, second); |
||||
} |
||||
|
||||
public CombinatorCondition createOrCondition(final Condition first, final Condition second) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public NegativeCondition createNegativeCondition(final Condition condition) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public PositionalCondition createPositionalCondition( |
||||
final int position, |
||||
final boolean typeNode, |
||||
final boolean type) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public AttributeCondition createAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new AttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createIdCondition(final String value) throws CSSException { |
||||
return createIdCondition(value, null); |
||||
} |
||||
|
||||
public AttributeCondition createIdCondition(final String value, final Locator locator) throws CSSException { |
||||
final IdConditionImpl cond = new IdConditionImpl(value); |
||||
cond.setLocator(locator); |
||||
return cond; |
||||
} |
||||
|
||||
public LangCondition createLangCondition(final String lang) throws CSSException { |
||||
return createLangCondition(lang, null); |
||||
} |
||||
public LangCondition createLangCondition(final String lang, final Locator locator) throws CSSException { |
||||
final LangConditionImpl cond = new LangConditionImpl(lang); |
||||
cond.setLocator(locator); |
||||
return cond; |
||||
} |
||||
|
||||
public AttributeCondition createOneOfAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new OneOfAttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createBeginHyphenAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new BeginHyphenAttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createPrefixAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new PrefixAttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createSuffixAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new SuffixAttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createSubstringAttributeCondition( |
||||
final String localName, |
||||
final String namespaceURI, |
||||
final boolean specified, |
||||
final String value) throws CSSException { |
||||
return new SubstringAttributeConditionImpl(localName, value, specified); |
||||
} |
||||
|
||||
public AttributeCondition createClassCondition( |
||||
final String namespaceURI, |
||||
final String value) throws CSSException { |
||||
return createClassCondition(namespaceURI, value, null); |
||||
} |
||||
|
||||
public AttributeCondition createClassCondition(final String namespaceURI, final String value, |
||||
final Locator locator) throws CSSException { |
||||
final ClassConditionImpl cond = new ClassConditionImpl(value); |
||||
cond.setLocator(locator); |
||||
return cond; |
||||
} |
||||
|
||||
public AttributeCondition createPseudoClassCondition( |
||||
final String namespaceURI, |
||||
final String value) throws CSSException { |
||||
return createPseudoClassCondition(namespaceURI, value, null, false); |
||||
} |
||||
|
||||
public AttributeCondition createPseudoClassCondition(final String namespaceURI, final String value, |
||||
final Locator locator, final boolean doubleColon) throws CSSException { |
||||
final PseudoClassConditionImpl cond = new PseudoClassConditionImpl(value); |
||||
cond.setLocator(locator); |
||||
if (doubleColon) { |
||||
cond.prefixedWithDoubleColon(); |
||||
} |
||||
return cond; |
||||
} |
||||
|
||||
public Condition createOnlyChildCondition() throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public Condition createOnlyTypeCondition() throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public ContentCondition createContentCondition(final String data) |
||||
throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
} |
@ -0,0 +1,102 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.ConditionalSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class ConditionalSelectorImpl extends LocatableImpl implements ConditionalSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 7217145899707580586L; |
||||
|
||||
private SimpleSelector simpleSelector_; |
||||
private Condition condition_; |
||||
|
||||
public void setSimpleSelector(final SimpleSelector simpleSelector) { |
||||
simpleSelector_ = simpleSelector; |
||||
if (simpleSelector instanceof Locatable) { |
||||
setLocator(((Locatable) simpleSelector).getLocator()); |
||||
} |
||||
else if (simpleSelector == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setCondition(final Condition condition) { |
||||
condition_ = condition; |
||||
if (getLocator() == null) { |
||||
if (condition instanceof Locatable) { |
||||
setLocator(((Locatable) condition).getLocator()); |
||||
} |
||||
else if (condition == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public ConditionalSelectorImpl(final SimpleSelector simpleSelector, final Condition condition) { |
||||
setSimpleSelector(simpleSelector); |
||||
setCondition(condition); |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_CONDITIONAL_SELECTOR; |
||||
} |
||||
|
||||
public SimpleSelector getSimpleSelector() { |
||||
return simpleSelector_; |
||||
} |
||||
|
||||
public Condition getCondition() { |
||||
return condition_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (null != simpleSelector_) { |
||||
sb.append(((CSSFormatable) simpleSelector_).getCssText(format)); |
||||
} |
||||
|
||||
if (null != condition_) { |
||||
sb.append(((CSSFormatable) condition_).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.DescendantSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class DescendantSelectorImpl extends LocatableImpl implements DescendantSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -3620467847449531232L; |
||||
|
||||
private Selector ancestorSelector_; |
||||
private SimpleSelector simpleSelector_; |
||||
|
||||
public void setAncestorSelector(final Selector ancestorSelector) { |
||||
ancestorSelector_ = ancestorSelector; |
||||
if (ancestorSelector instanceof Locatable) { |
||||
setLocator(((Locatable) ancestorSelector).getLocator()); |
||||
} |
||||
else if (ancestorSelector == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setSimpleSelector(final SimpleSelector simpleSelector) { |
||||
simpleSelector_ = simpleSelector; |
||||
} |
||||
|
||||
public DescendantSelectorImpl(final Selector parent, final SimpleSelector simpleSelector) { |
||||
setAncestorSelector(parent); |
||||
setSimpleSelector(simpleSelector); |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_DESCENDANT_SELECTOR; |
||||
} |
||||
|
||||
public Selector getAncestorSelector() { |
||||
return ancestorSelector_; |
||||
} |
||||
|
||||
public SimpleSelector getSimpleSelector() { |
||||
return simpleSelector_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (null != ancestorSelector_) { |
||||
sb.append(((CSSFormatable) ancestorSelector_).getCssText(format)); |
||||
} |
||||
|
||||
if (Selector.SAC_PSEUDO_ELEMENT_SELECTOR != getSimpleSelector().getSelectorType()) { |
||||
sb.append(' '); |
||||
} |
||||
|
||||
if (null != simpleSelector_) { |
||||
sb.append(((CSSFormatable) simpleSelector_).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,104 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SiblingSelector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class DirectAdjacentSelectorImpl extends LocatableImpl implements SiblingSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -7328602345833826516L; |
||||
|
||||
private short nodeType_; |
||||
private Selector selector_; // child
|
||||
private SimpleSelector siblingSelector_; // direct adjacent
|
||||
|
||||
public void setNodeType(final short nodeType) { |
||||
nodeType_ = nodeType; |
||||
} |
||||
|
||||
public void setSelector(final Selector child) { |
||||
selector_ = child; |
||||
if (child instanceof Locatable) { |
||||
setLocator(((Locatable) child).getLocator()); |
||||
} |
||||
else if (child == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setSiblingSelector(final SimpleSelector directAdjacent) { |
||||
siblingSelector_ = directAdjacent; |
||||
} |
||||
|
||||
public DirectAdjacentSelectorImpl(final short nodeType, |
||||
final Selector child, final SimpleSelector directAdjacent) { |
||||
setNodeType(nodeType); |
||||
setSelector(child); |
||||
setSiblingSelector(directAdjacent); |
||||
} |
||||
|
||||
public short getNodeType() { |
||||
return nodeType_; |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_DIRECT_ADJACENT_SELECTOR; |
||||
} |
||||
|
||||
public Selector getSelector() { |
||||
return selector_; |
||||
} |
||||
|
||||
public SimpleSelector getSiblingSelector() { |
||||
return siblingSelector_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (null != selector_) { |
||||
sb.append(((CSSFormatable) selector_).getCssText(format)); |
||||
} |
||||
|
||||
sb.append(" + "); |
||||
|
||||
if (null != siblingSelector_) { |
||||
sb.append(((CSSFormatable) siblingSelector_).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.ElementSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class ElementSelectorImpl extends LocatableImpl implements ElementSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 7507121069969409061L; |
||||
|
||||
private String localName_; |
||||
|
||||
public void setLocalName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public ElementSelectorImpl(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_ELEMENT_NODE_SELECTOR; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String localeName = getLocalName(); |
||||
if (localeName == null) { |
||||
return "*"; |
||||
} |
||||
return localeName; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,106 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.Locatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SiblingSelector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* @author Ahmed Ashour |
||||
* @author rbri |
||||
*/ |
||||
public class GeneralAdjacentSelectorImpl extends LocatableImpl implements SiblingSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 1292704016876205605L; |
||||
|
||||
private short nodeType_; |
||||
private Selector selector_; |
||||
private SimpleSelector siblingSelector_; |
||||
|
||||
public void setNodeType(final short nodeType) { |
||||
nodeType_ = nodeType; |
||||
} |
||||
|
||||
public void setSelector(final Selector child) { |
||||
selector_ = child; |
||||
if (child instanceof Locatable) { |
||||
setLocator(((Locatable) child).getLocator()); |
||||
} |
||||
else if (child == null) { |
||||
setLocator(null); |
||||
} |
||||
} |
||||
|
||||
public void setSiblingSelector(final SimpleSelector directAdjacent) { |
||||
siblingSelector_ = directAdjacent; |
||||
} |
||||
|
||||
public GeneralAdjacentSelectorImpl(final short nodeType, |
||||
final Selector child, final SimpleSelector directAdjacent) { |
||||
setNodeType(nodeType); |
||||
setSelector(child); |
||||
setSiblingSelector(directAdjacent); |
||||
} |
||||
|
||||
public short getNodeType() { |
||||
return nodeType_; |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
// not correct but the best choice from the old sac
|
||||
return Selector.SAC_DIRECT_ADJACENT_SELECTOR; |
||||
} |
||||
|
||||
public Selector getSelector() { |
||||
return selector_; |
||||
} |
||||
|
||||
public SimpleSelector getSiblingSelector() { |
||||
return siblingSelector_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
|
||||
if (null != selector_) { |
||||
sb.append(((CSSFormatable) selector_).getCssText(format)); |
||||
} |
||||
|
||||
sb.append(" ~ "); |
||||
|
||||
if (null != siblingSelector_) { |
||||
sb.append(((CSSFormatable) siblingSelector_).getCssText(format)); |
||||
} |
||||
|
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class IdConditionImpl extends LocatableImpl implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 5955662524656167683L; |
||||
|
||||
private String value_; |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public IdConditionImpl(final String value) { |
||||
setValue(value); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ID_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return null; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return true; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "#" + value; |
||||
} |
||||
return "#"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,74 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.LangCondition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class LangConditionImpl extends LocatableImpl implements LangCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 1701599531953055387L; |
||||
|
||||
private String lang_; |
||||
|
||||
public void setLang(final String lang) { |
||||
lang_ = lang; |
||||
} |
||||
|
||||
public LangConditionImpl(final String lang) { |
||||
setLang(lang); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_LANG_CONDITION; |
||||
} |
||||
|
||||
public String getLang() { |
||||
return lang_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final StringBuilder result = new StringBuilder(); |
||||
result.append(":lang("); |
||||
|
||||
final String lang = getLang(); |
||||
if (null != lang) { |
||||
result.append(lang); |
||||
} |
||||
|
||||
result.append(")"); |
||||
return result.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,93 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class OneOfAttributeConditionImpl extends LocatableImpl |
||||
implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -1371164446179830634L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocalName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public OneOfAttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocalName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ONE_OF_ATTRIBUTE_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "~=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
/** |
||||
* @author Ahmed Ashour |
||||
*/ |
||||
public class PrefixAttributeConditionImpl extends LocatableImpl |
||||
implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -6899059242714875011L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocalName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public PrefixAttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocalName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ATTRIBUTE_CONDITION; //for now
|
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "^=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,86 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class PseudoClassConditionImpl extends LocatableImpl implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 1798016773089155610L; |
||||
|
||||
private String value_; |
||||
private boolean doubleColon_; |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public PseudoClassConditionImpl(final String value) { |
||||
setValue(value); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_PSEUDO_CLASS_CONDITION; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return null; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return true; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
public void prefixedWithDoubleColon() { |
||||
doubleColon_ = true; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value == null) { |
||||
return value; |
||||
} |
||||
return (doubleColon_ ? "::" : ":") + value; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.ElementSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author rbri |
||||
*/ |
||||
public class PseudoElementSelectorImpl extends LocatableImpl implements ElementSelector, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 2913936296006875268L; |
||||
|
||||
private String localName_; |
||||
private boolean doubleColon_; |
||||
|
||||
public void setLocaleName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public PseudoElementSelectorImpl(final String localName) { |
||||
setLocaleName(localName); |
||||
} |
||||
|
||||
public short getSelectorType() { |
||||
return Selector.SAC_PSEUDO_ELEMENT_SELECTOR; |
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public void prefixedWithDoubleColon() { |
||||
doubleColon_ = true; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
if (localName_ == null) { |
||||
return localName_; |
||||
} |
||||
return (doubleColon_ ? "::" : ":") + localName_; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,139 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import com.fr.third.steadystate.css.sac.SelectorFactoryExt; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CharacterDataSelector; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.ConditionalSelector; |
||||
import org.w3c.css.sac.DescendantSelector; |
||||
import org.w3c.css.sac.ElementSelector; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.NegativeSelector; |
||||
import org.w3c.css.sac.ProcessingInstructionSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SiblingSelector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
/** |
||||
* |
||||
* @author <a href="mailto:davidsch@users.sourceforge.net">David Schweinsberg</a> |
||||
* @author Ronald Brill |
||||
*/ |
||||
public class SelectorFactoryImpl implements SelectorFactoryExt { |
||||
|
||||
public ConditionalSelector createConditionalSelector( |
||||
final SimpleSelector selector, |
||||
final Condition condition) throws CSSException { |
||||
return new ConditionalSelectorImpl(selector, condition); |
||||
} |
||||
|
||||
public SimpleSelector createAnyNodeSelector() throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public SimpleSelector createRootNodeSelector() throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public NegativeSelector createNegativeSelector(final SimpleSelector selector) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public ElementSelector createElementSelector(final String namespaceURI, final String localName) |
||||
throws CSSException { |
||||
return createElementSelector(namespaceURI, localName, null); |
||||
} |
||||
|
||||
public ElementSelector createElementSelector(final String namespaceURI, final String localName, |
||||
final Locator locator) throws CSSException { |
||||
if (namespaceURI != null) { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
final ElementSelectorImpl sel = new ElementSelectorImpl(localName); |
||||
sel.setLocator(locator); |
||||
return sel; |
||||
} |
||||
|
||||
public ElementSelector createSyntheticElementSelector() throws CSSException { |
||||
return new SyntheticElementSelectorImpl(); |
||||
} |
||||
|
||||
public CharacterDataSelector createTextNodeSelector(final String data) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public CharacterDataSelector createCDataSectionSelector(final String data) |
||||
throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public ProcessingInstructionSelector createProcessingInstructionSelector( |
||||
final String target, |
||||
final String data) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public CharacterDataSelector createCommentSelector(final String data) throws CSSException { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
public ElementSelector createPseudoElementSelector(final String namespaceURI, final String pseudoName) |
||||
throws CSSException { |
||||
return createPseudoElementSelector(namespaceURI, pseudoName, null, false); |
||||
} |
||||
|
||||
public ElementSelector createPseudoElementSelector(final String namespaceURI, final String pseudoName, |
||||
final Locator locator, final boolean doubleColon) throws CSSException { |
||||
if (namespaceURI != null) { |
||||
throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); |
||||
} |
||||
|
||||
final PseudoElementSelectorImpl sel = new PseudoElementSelectorImpl(pseudoName); |
||||
sel.setLocator(locator); |
||||
if (doubleColon) { |
||||
sel.prefixedWithDoubleColon(); |
||||
} |
||||
return sel; |
||||
} |
||||
|
||||
public DescendantSelector createDescendantSelector( |
||||
final Selector parent, |
||||
final SimpleSelector descendant) throws CSSException { |
||||
return new DescendantSelectorImpl(parent, descendant); |
||||
} |
||||
|
||||
public DescendantSelector createChildSelector( |
||||
final Selector parent, |
||||
final SimpleSelector child) throws CSSException { |
||||
return new ChildSelectorImpl(parent, child); |
||||
} |
||||
|
||||
public SiblingSelector createDirectAdjacentSelector( |
||||
final short nodeType, |
||||
final Selector child, |
||||
final SimpleSelector directAdjacent) throws CSSException { |
||||
return new DirectAdjacentSelectorImpl(nodeType, child, directAdjacent); |
||||
} |
||||
|
||||
public SiblingSelector createGeneralAdjacentSelector( |
||||
final short nodeType, |
||||
final Selector child, |
||||
final SimpleSelector directAdjacent) throws CSSException { |
||||
return new GeneralAdjacentSelectorImpl(nodeType, child, directAdjacent); |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
/** |
||||
* @author Ahmed Ashour |
||||
*/ |
||||
public class SubstringAttributeConditionImpl extends LocatableImpl |
||||
implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = 7628763646156568710L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocalName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public SubstringAttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocalName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ATTRIBUTE_CONDITION; //for now
|
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "*=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
import com.fr.third.steadystate.css.format.CSSFormatable; |
||||
import com.fr.third.steadystate.css.parser.LocatableImpl; |
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
|
||||
/** |
||||
* @author Ahmed Ashour |
||||
*/ |
||||
public class SuffixAttributeConditionImpl extends LocatableImpl |
||||
implements AttributeCondition, CSSFormatable, Serializable { |
||||
|
||||
private static final long serialVersionUID = -957389472252773926L; |
||||
|
||||
private String localName_; |
||||
private String value_; |
||||
private boolean specified_; |
||||
|
||||
public void setLocalName(final String localName) { |
||||
localName_ = localName; |
||||
} |
||||
|
||||
public void setValue(final String value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
public void setSpecified(final boolean specified) { |
||||
specified_ = specified; |
||||
} |
||||
|
||||
public SuffixAttributeConditionImpl(final String localName, final String value, final boolean specified) { |
||||
setLocalName(localName); |
||||
setValue(value); |
||||
setSpecified(specified); |
||||
} |
||||
|
||||
public short getConditionType() { |
||||
return Condition.SAC_ATTRIBUTE_CONDITION; //for now
|
||||
} |
||||
|
||||
public String getNamespaceURI() { |
||||
return null; |
||||
} |
||||
|
||||
public String getLocalName() { |
||||
return localName_; |
||||
} |
||||
|
||||
public boolean getSpecified() { |
||||
return specified_; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public String getCssText(final CSSFormat format) { |
||||
final String value = getValue(); |
||||
if (value != null) { |
||||
return "[" + getLocalName() + "$=\"" + value + "\"]"; |
||||
} |
||||
return "[" + getLocalName() + "]"; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return getCssText(null); |
||||
} |
||||
} |
@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.parser.selectors; |
||||
|
||||
import com.fr.third.steadystate.css.format.CSSFormat; |
||||
|
||||
/** |
||||
* Special ElementSelectorImpl used by the parser at all the places where |
||||
* the parser inserts a '*' selector. The selector will be ignored when |
||||
* generating output. |
||||
* This is done to be backward compatible. |
||||
* |
||||
* @author rbri |
||||
*/ |
||||
public class SyntheticElementSelectorImpl extends ElementSelectorImpl { |
||||
|
||||
private static final long serialVersionUID = 3426191759125755798L; |
||||
|
||||
public SyntheticElementSelectorImpl() { |
||||
super(null); |
||||
} |
||||
|
||||
@Override |
||||
public void setLocalName(final String localName) { |
||||
throw new RuntimeException("Method setLocalName is not supported for SyntheticElementSelectorImpl."); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public String getCssText(final CSSFormat format) { |
||||
return ""; |
||||
} |
||||
} |
@ -0,0 +1,119 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CombinatorCondition; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.ConditionFactory; |
||||
import org.w3c.css.sac.ContentCondition; |
||||
import org.w3c.css.sac.LangCondition; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.NegativeCondition; |
||||
import org.w3c.css.sac.PositionalCondition; |
||||
|
||||
/** |
||||
* Implementation of the ConditionFactoryExt interface that maps calls back to a |
||||
* native sac ConditionFactory. |
||||
*/ |
||||
public class ConditionFactoryAdapter implements ConditionFactoryExt { |
||||
|
||||
private final ConditionFactory conditionFactory_; |
||||
|
||||
public ConditionFactoryAdapter(final ConditionFactory selectorFactory) { |
||||
conditionFactory_ = selectorFactory; |
||||
} |
||||
|
||||
public CombinatorCondition createAndCondition(final Condition first, final Condition second) throws CSSException { |
||||
return conditionFactory_.createAndCondition(first, second); |
||||
} |
||||
|
||||
public CombinatorCondition createOrCondition(final Condition first, final Condition second) throws CSSException { |
||||
return conditionFactory_.createOrCondition(first, second); |
||||
} |
||||
|
||||
public NegativeCondition createNegativeCondition(final Condition condition) throws CSSException { |
||||
return conditionFactory_.createNegativeCondition(condition); |
||||
} |
||||
|
||||
public PositionalCondition createPositionalCondition(final int position, final boolean typeNode, final boolean type) |
||||
throws CSSException { |
||||
return conditionFactory_.createPositionalCondition(position, typeNode, type); |
||||
} |
||||
|
||||
public AttributeCondition createAttributeCondition(final String localName, final String namespaceURI, |
||||
final boolean specified, final String value) throws CSSException { |
||||
return conditionFactory_.createAttributeCondition(localName, namespaceURI, specified, value); |
||||
} |
||||
|
||||
public AttributeCondition createIdCondition(final String value) throws CSSException { |
||||
return conditionFactory_.createIdCondition(value); |
||||
} |
||||
|
||||
public AttributeCondition createIdCondition(final String value, final Locator locator) throws CSSException { |
||||
return conditionFactory_.createIdCondition(value); |
||||
} |
||||
|
||||
public LangCondition createLangCondition(final String lang) throws CSSException { |
||||
return conditionFactory_.createLangCondition(lang); |
||||
} |
||||
|
||||
public LangCondition createLangCondition(final String lang, final Locator locator) throws CSSException { |
||||
return conditionFactory_.createLangCondition(lang); |
||||
} |
||||
|
||||
public AttributeCondition createOneOfAttributeCondition(final String localName, final String namespaceURI, |
||||
final boolean specified, final String value) throws CSSException { |
||||
return conditionFactory_.createOneOfAttributeCondition(localName, namespaceURI, specified, value); |
||||
} |
||||
|
||||
public AttributeCondition createBeginHyphenAttributeCondition(final String localName, final String namespaceURI, |
||||
final boolean specified, final String value) throws CSSException { |
||||
return conditionFactory_.createBeginHyphenAttributeCondition(localName, namespaceURI, specified, value); |
||||
} |
||||
|
||||
public AttributeCondition createClassCondition(final String namespaceURI, final String value) throws CSSException { |
||||
return conditionFactory_.createClassCondition(namespaceURI, value); |
||||
} |
||||
|
||||
public AttributeCondition createClassCondition(final String namespaceURI, final String value, final Locator locator) |
||||
throws CSSException { |
||||
return conditionFactory_.createClassCondition(namespaceURI, value); |
||||
} |
||||
|
||||
public AttributeCondition createPseudoClassCondition(final String namespaceURI, final String value) |
||||
throws CSSException { |
||||
return conditionFactory_.createPseudoClassCondition(namespaceURI, value); |
||||
} |
||||
|
||||
public AttributeCondition createPseudoClassCondition(final String namespaceURI, final String value, |
||||
final Locator locator, final boolean doubleColon) throws CSSException { |
||||
return conditionFactory_.createPseudoClassCondition(namespaceURI, value); |
||||
} |
||||
|
||||
public Condition createOnlyChildCondition() throws CSSException { |
||||
return conditionFactory_.createOnlyChildCondition(); |
||||
} |
||||
|
||||
public Condition createOnlyTypeCondition() throws CSSException { |
||||
return conditionFactory_.createOnlyTypeCondition(); |
||||
} |
||||
|
||||
public ContentCondition createContentCondition(final String data) throws CSSException { |
||||
return conditionFactory_.createContentCondition(data); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.AttributeCondition; |
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.ConditionFactory; |
||||
import org.w3c.css.sac.LangCondition; |
||||
import org.w3c.css.sac.Locator; |
||||
|
||||
/** |
||||
* Extension of the ConditionFactory interface. |
||||
* This was added to support the locator parameter to |
||||
* inform about the code position. |
||||
*/ |
||||
public interface ConditionFactoryExt extends ConditionFactory { |
||||
|
||||
AttributeCondition createClassCondition(String namespaceURI, String value, Locator locator) throws CSSException; |
||||
|
||||
AttributeCondition createIdCondition(String value, Locator locator) throws CSSException; |
||||
|
||||
AttributeCondition createPseudoClassCondition(String namespaceURI, String value, |
||||
Locator locator, boolean doubleColon) |
||||
throws CSSException; |
||||
|
||||
LangCondition createLangCondition(String lang, Locator locator) throws CSSException; |
||||
} |
@ -0,0 +1,169 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CSSParseException; |
||||
import org.w3c.css.sac.DocumentHandler; |
||||
import org.w3c.css.sac.ErrorHandler; |
||||
import org.w3c.css.sac.InputSource; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.css.sac.SelectorList; |
||||
|
||||
/** |
||||
* Implementation of the DocumentHandlerExt interface that maps calls back to a |
||||
* native sac DocumentHandler. |
||||
*/ |
||||
public class DocumentHandlerAdapter implements DocumentHandlerExt, ErrorHandler { |
||||
|
||||
private final DocumentHandler documentHanlder_; |
||||
|
||||
public DocumentHandlerAdapter(final DocumentHandler documentHanlder) { |
||||
documentHanlder_ = documentHanlder; |
||||
} |
||||
|
||||
public void startDocument(final InputSource source) throws CSSException { |
||||
documentHanlder_.startDocument(source); |
||||
} |
||||
|
||||
public void endDocument(final InputSource source) throws CSSException { |
||||
documentHanlder_.endDocument(source); |
||||
} |
||||
|
||||
public void comment(final String text) throws CSSException { |
||||
documentHanlder_.comment(text); |
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule) throws CSSException { |
||||
documentHanlder_.ignorableAtRule(atRule); |
||||
} |
||||
|
||||
public void ignorableAtRule(final String atRule, final Locator locator) throws CSSException { |
||||
documentHanlder_.ignorableAtRule(atRule); |
||||
} |
||||
|
||||
public void namespaceDeclaration(final String prefix, final String uri) throws CSSException { |
||||
documentHanlder_.namespaceDeclaration(prefix, uri); |
||||
} |
||||
|
||||
public void importStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI) throws CSSException { |
||||
documentHanlder_.importStyle(uri, media, defaultNamespaceURI); |
||||
} |
||||
|
||||
public void importStyle(final String uri, final SACMediaList media, |
||||
final String defaultNamespaceURI, final Locator locator) throws CSSException { |
||||
documentHanlder_.importStyle(uri, media, defaultNamespaceURI); |
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media) throws CSSException { |
||||
documentHanlder_.startMedia(media); |
||||
} |
||||
|
||||
public void startMedia(final SACMediaList media, final Locator locator) throws CSSException { |
||||
documentHanlder_.startMedia(media); |
||||
} |
||||
|
||||
public void endMedia(final SACMediaList media) throws CSSException { |
||||
documentHanlder_.endMedia(media); |
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage) throws CSSException { |
||||
documentHanlder_.startPage(name, pseudoPage); |
||||
} |
||||
|
||||
public void startPage(final String name, final String pseudoPage, final Locator locator) throws CSSException { |
||||
documentHanlder_.startPage(name, pseudoPage); |
||||
} |
||||
|
||||
public void endPage(final String name, final String pseudoPage) throws CSSException { |
||||
documentHanlder_.endPage(name, pseudoPage); |
||||
} |
||||
|
||||
public void startFontFace() throws CSSException { |
||||
documentHanlder_.startFontFace(); |
||||
} |
||||
|
||||
public void startFontFace(final Locator locator) throws CSSException { |
||||
documentHanlder_.startFontFace(); |
||||
} |
||||
|
||||
public void endFontFace() throws CSSException { |
||||
documentHanlder_.endFontFace(); |
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors) throws CSSException { |
||||
documentHanlder_.startSelector(selectors); |
||||
} |
||||
|
||||
public void startSelector(final SelectorList selectors, final Locator locator) throws CSSException { |
||||
documentHanlder_.startSelector(selectors); |
||||
} |
||||
|
||||
public void endSelector(final SelectorList selectors) throws CSSException { |
||||
documentHanlder_.endSelector(selectors); |
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important) throws CSSException { |
||||
documentHanlder_.property(name, value, important); |
||||
} |
||||
|
||||
public void property(final String name, final LexicalUnit value, final boolean important, final Locator locator) { |
||||
documentHanlder_.property(name, value, important); |
||||
} |
||||
|
||||
public void charset(final String characterEncoding, final Locator locator) throws CSSException { |
||||
// empty default impl
|
||||
} |
||||
|
||||
public void warning(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
|
||||
public void error(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
|
||||
public void fatalError(final CSSParseException exception) throws CSSException { |
||||
final StringBuilder sb = new StringBuilder(); |
||||
sb.append(exception.getURI()) |
||||
.append(" [") |
||||
.append(exception.getLineNumber()) |
||||
.append(":") |
||||
.append(exception.getColumnNumber()) |
||||
.append("] ") |
||||
.append(exception.getMessage()); |
||||
System.err.println(sb.toString()); |
||||
} |
||||
} |
@ -0,0 +1,128 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.DocumentHandler; |
||||
import org.w3c.css.sac.LexicalUnit; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.SACMediaList; |
||||
import org.w3c.css.sac.SelectorList; |
||||
|
||||
/** |
||||
* Extension of the DocumentHanlder interface. |
||||
* This was added to support the locator parameter to |
||||
* inform about the code position. |
||||
*/ |
||||
public interface DocumentHandlerExt extends DocumentHandler { |
||||
|
||||
/** |
||||
* Receive notification of a charset at-rule. |
||||
* |
||||
* @param characterEncoding the character encoding |
||||
* @param locator the SAC locator |
||||
* @throws CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void charset(String characterEncoding, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of a import statement in the style sheet. |
||||
* |
||||
* @param uri The URI of the imported style sheet. |
||||
* @param media The intended destination media for style information. |
||||
* @param defaultNamespaceURI The default namespace URI for the imported |
||||
* style sheet. |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void importStyle(String uri, SACMediaList media, |
||||
String defaultNamespaceURI, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of an unknown rule t-rule not supported by this |
||||
* parser. |
||||
* |
||||
* @param atRule The complete ignored at-rule. |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void ignorableAtRule(String atRule, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of the beginning of a font face statement. |
||||
* |
||||
* The Parser will invoke this method at the beginning of every font face |
||||
* statement in the style sheet. there will be a corresponding endFontFace() |
||||
* event for every startFontFace() event. |
||||
* |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void startFontFace(Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of the beginning of a page statement. |
||||
* |
||||
* The Parser will invoke this method at the beginning of every page |
||||
* statement in the style sheet. there will be a corresponding endPage() |
||||
* event for every startPage() event. |
||||
* |
||||
* @param name the name of the page (if any, null otherwise) |
||||
* @param pseudoPage the pseudo page (if any, null otherwise) |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void startPage(String name, String pseudoPage, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of the beginning of a media statement. |
||||
* |
||||
* The Parser will invoke this method at the beginning of every media |
||||
* statement in the style sheet. there will be a corresponding endMedia() |
||||
* event for every startElement() event. |
||||
* |
||||
* @param media The intended destination media for style information. |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void startMedia(SACMediaList media, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of the beginning of a rule statement. |
||||
* |
||||
* @param selectors All intended selectors for all declarations. |
||||
* @param locator the SAC locator |
||||
* @exception CSSException Any CSS exception, possibly wrapping another |
||||
* exception. |
||||
*/ |
||||
void startSelector(SelectorList selectors, Locator locator) throws CSSException; |
||||
|
||||
/** |
||||
* Receive notification of a declaration. |
||||
* |
||||
* @param name the name of the property. |
||||
* @param value the value of the property. All whitespace are stripped. |
||||
* @param important is this property important ? |
||||
* @param locator the SAC locator |
||||
*/ |
||||
void property(String name, LexicalUnit value, boolean important, Locator locator); |
||||
} |
@ -0,0 +1,124 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.CharacterDataSelector; |
||||
import org.w3c.css.sac.Condition; |
||||
import org.w3c.css.sac.ConditionalSelector; |
||||
import org.w3c.css.sac.DescendantSelector; |
||||
import org.w3c.css.sac.ElementSelector; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.NegativeSelector; |
||||
import org.w3c.css.sac.ProcessingInstructionSelector; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SelectorFactory; |
||||
import org.w3c.css.sac.SiblingSelector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
/** |
||||
* Implementation of the SelectorFactoryExt interface that maps calls back to a |
||||
* native sac SelectorFactory. |
||||
*/ |
||||
public class SelectorFactoryAdapter implements SelectorFactoryExt { |
||||
|
||||
private final SelectorFactory selectorFactory_; |
||||
|
||||
public SelectorFactoryAdapter(final SelectorFactory selectorFactory) { |
||||
selectorFactory_ = selectorFactory; |
||||
} |
||||
|
||||
public ConditionalSelector createConditionalSelector(final SimpleSelector selector, final Condition condition) |
||||
throws CSSException { |
||||
return selectorFactory_.createConditionalSelector(selector, condition); |
||||
} |
||||
|
||||
public SimpleSelector createAnyNodeSelector() throws CSSException { |
||||
return selectorFactory_.createAnyNodeSelector(); |
||||
} |
||||
|
||||
public SimpleSelector createRootNodeSelector() throws CSSException { |
||||
return selectorFactory_.createRootNodeSelector(); |
||||
} |
||||
|
||||
public NegativeSelector createNegativeSelector(final SimpleSelector selector) |
||||
throws CSSException { |
||||
return selectorFactory_.createNegativeSelector(selector); |
||||
} |
||||
|
||||
public ElementSelector createElementSelector(final String namespaceURI, final String tagName) |
||||
throws CSSException { |
||||
return selectorFactory_.createElementSelector(namespaceURI, tagName); |
||||
} |
||||
|
||||
public CharacterDataSelector createTextNodeSelector(final String data) throws CSSException { |
||||
return selectorFactory_.createTextNodeSelector(data); |
||||
} |
||||
|
||||
public CharacterDataSelector createCDataSectionSelector(final String data) throws CSSException { |
||||
return selectorFactory_.createCDataSectionSelector(data); |
||||
} |
||||
|
||||
public ProcessingInstructionSelector createProcessingInstructionSelector(final String target, final String data) |
||||
throws CSSException { |
||||
return selectorFactory_.createProcessingInstructionSelector(target, data); |
||||
} |
||||
|
||||
public CharacterDataSelector createCommentSelector(final String data) throws CSSException { |
||||
return selectorFactory_.createCommentSelector(data); |
||||
} |
||||
|
||||
public ElementSelector createPseudoElementSelector(final String namespaceURI, final String pseudoName) |
||||
throws CSSException { |
||||
return selectorFactory_.createPseudoElementSelector(namespaceURI, pseudoName); |
||||
} |
||||
|
||||
public DescendantSelector createDescendantSelector(final Selector parent, final SimpleSelector descendant) |
||||
throws CSSException { |
||||
return selectorFactory_.createDescendantSelector(parent, descendant); |
||||
} |
||||
|
||||
public DescendantSelector createChildSelector(final Selector parent, final SimpleSelector child) |
||||
throws CSSException { |
||||
return selectorFactory_.createChildSelector(parent, child); |
||||
} |
||||
|
||||
public SiblingSelector createDirectAdjacentSelector(final short nodeType, final Selector child, |
||||
final SimpleSelector directAdjacent) throws CSSException { |
||||
return selectorFactory_.createDirectAdjacentSelector(nodeType, child, directAdjacent); |
||||
} |
||||
|
||||
public ElementSelector createElementSelector(final String namespaceURI, final String tagName, |
||||
final Locator locator) throws CSSException { |
||||
return selectorFactory_.createElementSelector(namespaceURI, tagName); |
||||
} |
||||
|
||||
public ElementSelector createPseudoElementSelector(final String namespaceURI, final String pseudoName, |
||||
final Locator locator, final boolean doubleColon) throws CSSException { |
||||
return selectorFactory_.createPseudoElementSelector(namespaceURI, pseudoName); |
||||
} |
||||
|
||||
public ElementSelector createSyntheticElementSelector() throws CSSException { |
||||
return null; |
||||
} |
||||
|
||||
public SiblingSelector createGeneralAdjacentSelector( |
||||
final short nodeType, |
||||
final Selector child, |
||||
final SimpleSelector directAdjacent) throws CSSException { |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.sac; |
||||
|
||||
import org.w3c.css.sac.CSSException; |
||||
import org.w3c.css.sac.ElementSelector; |
||||
import org.w3c.css.sac.Locator; |
||||
import org.w3c.css.sac.Selector; |
||||
import org.w3c.css.sac.SelectorFactory; |
||||
import org.w3c.css.sac.SiblingSelector; |
||||
import org.w3c.css.sac.SimpleSelector; |
||||
|
||||
/** |
||||
* Extension of the SelectorFactory interface. |
||||
* This was added to support the locator parameter to |
||||
* inform about the code position. |
||||
*/ |
||||
public interface SelectorFactoryExt extends SelectorFactory { |
||||
|
||||
ElementSelector createElementSelector(String namespaceURI, String tagName, Locator locator) |
||||
throws CSSException; |
||||
|
||||
ElementSelector createPseudoElementSelector(String namespaceURI, String pseudoName, |
||||
Locator locator, boolean doubleColon) |
||||
throws CSSException; |
||||
|
||||
ElementSelector createSyntheticElementSelector() throws CSSException; |
||||
|
||||
SiblingSelector createGeneralAdjacentSelector(short nodeType, Selector child, SimpleSelector directAdjacent) |
||||
throws CSSException; |
||||
} |
@ -0,0 +1,25 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.userdata; |
||||
|
||||
public final class UserDataConstants { |
||||
|
||||
private static final String KEY_PREFIX = UserDataConstants.class.getPackage().getName(); |
||||
public static final String KEY_LOCATOR = KEY_PREFIX + ".locator"; |
||||
|
||||
private UserDataConstants() { |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.util; |
||||
|
||||
import java.util.List; |
||||
|
||||
public final class LangUtils { |
||||
public static final int HASH_SEED = 17; |
||||
public static final int HASH_OFFSET = 37; |
||||
|
||||
private LangUtils() { |
||||
} |
||||
|
||||
public static int hashCode(final int seed, final int hashcode) { |
||||
return seed * HASH_OFFSET + hashcode; |
||||
} |
||||
|
||||
public static int hashCode(final int seed, final boolean b) { |
||||
return hashCode(seed, b ? 1 : 0); |
||||
} |
||||
|
||||
public static int hashCode(final int seed, final Object obj) { |
||||
return hashCode(seed, obj != null ? obj.hashCode() : 0); |
||||
} |
||||
|
||||
public static String join(final List<String> values, String separator) { |
||||
if (values == null) { |
||||
return null; |
||||
} |
||||
if (separator == null) { |
||||
separator = ""; |
||||
} |
||||
|
||||
boolean isFirst = true; |
||||
final StringBuilder result = new StringBuilder(); |
||||
for (String part : values) { |
||||
if (part != null && part.length() > 0) { |
||||
if (isFirst) { |
||||
isFirst = false; |
||||
} |
||||
else { |
||||
result.append(separator); |
||||
} |
||||
result.append(part); |
||||
} |
||||
} |
||||
return result.toString(); |
||||
} |
||||
|
||||
public static boolean equals(final Object obj1, final Object obj2) { |
||||
return obj1 == null ? obj2 == null : obj1.equals(obj2); |
||||
} |
||||
} |
@ -0,0 +1,145 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.util; |
||||
|
||||
import java.io.BufferedWriter; |
||||
import java.io.IOException; |
||||
import java.io.Writer; |
||||
|
||||
/** |
||||
* A simple helper to write formated to a writer. |
||||
* |
||||
* @author rbri |
||||
*/ |
||||
public final class Output { |
||||
private static final String NEW_LINE = System.getProperty("line.separator"); |
||||
|
||||
private Writer writer_; |
||||
private StringBuffer currentIndent_; |
||||
private boolean afterNewLine_; |
||||
private final String indent_; |
||||
|
||||
/** |
||||
* Constructor. |
||||
* |
||||
* @param aWriter the writer to write to |
||||
* @param anIndent String to be used for indenting (e.g. "", " ", " ", "\t") |
||||
*/ |
||||
public Output(final Writer aWriter, final String anIndent) { |
||||
writer_ = new BufferedWriter(aWriter); |
||||
indent_ = anIndent; |
||||
currentIndent_ = new StringBuffer(); |
||||
} |
||||
|
||||
/** |
||||
* Write the char. |
||||
* |
||||
* @param aChar the char to be written |
||||
* @return this (for convenience) |
||||
* @throws IOException in case of problems |
||||
*/ |
||||
public Output print(final char aChar) throws IOException { |
||||
writeIndentIfNeeded(); |
||||
writer_.write(aChar); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Write the String. |
||||
* |
||||
* @param aString the string to be written |
||||
* @return this (for convenience) |
||||
* @throws IOException in case of problems |
||||
*/ |
||||
public Output print(final String aString) throws IOException { |
||||
if (null != aString) { |
||||
writeIndentIfNeeded(); |
||||
writer_.write(aString); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Write the string on a new line. |
||||
* |
||||
* @param aString the string to be written |
||||
* @return this (for convenience) |
||||
* @throws IOException in case of problems |
||||
*/ |
||||
public Output println(final String aString) throws IOException { |
||||
writeIndentIfNeeded(); |
||||
writer_.write(aString); |
||||
writer_.write(NEW_LINE); |
||||
afterNewLine_ = true; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Start a newline. |
||||
* |
||||
* @return this (for convenience) |
||||
* @throws IOException in case of problems |
||||
*/ |
||||
public Output println() throws IOException { |
||||
writer_.write(NEW_LINE); |
||||
afterNewLine_ = true; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Flushes the output. |
||||
* |
||||
* @return this (for convenience) |
||||
* @throws IOException in case of error |
||||
*/ |
||||
public Output flush() throws IOException { |
||||
writer_.flush(); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Indent the following. |
||||
* |
||||
* @return this (for convenience) |
||||
*/ |
||||
public Output indent() { |
||||
currentIndent_.append(indent_); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Clear the indent. |
||||
* |
||||
* @return this (for convenience) |
||||
*/ |
||||
public Output unindent() { |
||||
currentIndent_.setLength(Math.max(0, currentIndent_.length() - indent_.length())); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Helper to write a newline. |
||||
* |
||||
* @throws IOException |
||||
* in case of problems |
||||
*/ |
||||
private void writeIndentIfNeeded() throws IOException { |
||||
if (afterNewLine_) { |
||||
writer_.write(currentIndent_.toString()); |
||||
afterNewLine_ = false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
/* |
||||
* Copyright (C) 1999-2018 David Schweinsberg. |
||||
* |
||||
* Licensed 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. |
||||
*/ |
||||
|
||||
package com.fr.third.steadystate.css.util; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.w3c.css.sac.CSSParseException; |
||||
import org.w3c.css.sac.ErrorHandler; |
||||
|
||||
/** |
||||
* Helper implementation of {@link ErrorHandler}, which throws CssException in case of problems. |
||||
* |
||||
* @author rbri |
||||
* @see ErrorHandler |
||||
*/ |
||||
public class ThrowCssExceptionErrorHandler implements ErrorHandler, Serializable { |
||||
private static final long serialVersionUID = -3933638774901855095L; |
||||
|
||||
/** |
||||
* Singleton. |
||||
*/ |
||||
public static final ThrowCssExceptionErrorHandler INSTANCE = new ThrowCssExceptionErrorHandler(); |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public void error(final CSSParseException exception) { |
||||
throw exception; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public void fatalError(final CSSParseException exception) { |
||||
throw exception; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public void warning(final CSSParseException exception) { |
||||
// ignore warnings
|
||||
} |
||||
} |
Loading…
Reference in new issue