Author: maksimkaszynski
Date: 2007-10-10 14:16:22 -0400 (Wed, 10 Oct 2007)
New Revision: 3321
Added:
trunk/docs/highlight/
trunk/docs/highlight/pom.xml
trunk/docs/highlight/src/
trunk/docs/highlight/src/main/
trunk/docs/highlight/src/main/java/
trunk/docs/highlight/src/main/java/org/
trunk/docs/highlight/src/main/java/org/richfaces/
trunk/docs/highlight/src/main/java/org/richfaces/highlight/
trunk/docs/highlight/src/main/java/org/richfaces/highlight/CssXhtmlRenderer.java
trunk/docs/highlight/src/main/java/org/richfaces/highlight/IStyleConstantsCSS.java
trunk/docs/highlight/src/main/java/org/richfaces/highlight/XhtmlRendererFactory.java
trunk/docs/highlight/src/main/resources/
trunk/docs/highlight/src/main/resources/org/
trunk/docs/highlight/src/main/resources/org/richfaces/
trunk/docs/highlight/src/main/resources/org/richfaces/highlight/
trunk/docs/highlight/src/main/resources/org/richfaces/highlight/renderers.properties
Modified:
trunk/docs/pom.xml
trunk/docs/userguide/en/src/main/resources/css/html.css
trunk/docs/xslt/en/pom.xml
trunk/docs/xslt/en/src/main/xslt/code-highlight.xsl
Log:
http://jira.jboss.com/jira/browse/RF-747
Property changes on: trunk/docs/highlight
___________________________________________________________________
Name: svn:ignore
+ target
.classpath
.project
.settings
Added: trunk/docs/highlight/pom.xml
===================================================================
--- trunk/docs/highlight/pom.xml (rev 0)
+++ trunk/docs/highlight/pom.xml 2007-10-10 18:16:22 UTC (rev 3321)
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>docs</artifactId>
+ <groupId>org.richfaces</groupId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.docs</groupId>
+ <artifactId>highlight</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <name>RichFaces Code Highlighting</name>
+
+
+ <dependencies>
+<!-- <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>xerces</artifactId>
+ <version>2.8.0-v200702082200</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>bundle</artifactId>
+ <groupId>system</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency> -->
+ <dependency>
+ <groupId>org.eclipse.wst.sse</groupId>
+ <artifactId>core</artifactId>
+ <version>1.1.201-v200703241528</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>xerces</artifactId>
+ <groupId>org.apache</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>bundle</artifactId>
+ <groupId>system</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>core</artifactId>
+ <groupId>org.eclipse.wst.xml</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>runtime</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>resources</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>filebuffers</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>text</artifactId>
+ <groupId>org.eclipse</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>commands</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>common</artifactId>
+ <groupId>org.eclipse.emf</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>icu</artifactId>
+ <groupId>com.ibm</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.wst.css</groupId>
+ <artifactId>core</artifactId>
+ <version>1.1.101-v200704012321</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>xerces</artifactId>
+ <groupId>org.apache</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>bundle</artifactId>
+ <groupId>system</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>core</artifactId>
+ <groupId>org.eclipse.wst.xml</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>runtime</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>resources</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>filebuffers</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>text</artifactId>
+ <groupId>org.eclipse</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>commands</artifactId>
+ <groupId>org.eclipse.core</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>common</artifactId>
+ <groupId>org.eclipse.emf</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>icu</artifactId>
+ <groupId>com.ibm</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.uwyn</groupId>
+ <artifactId>jhighlight</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
+
Added: trunk/docs/highlight/src/main/java/org/richfaces/highlight/CssXhtmlRenderer.java
===================================================================
--- trunk/docs/highlight/src/main/java/org/richfaces/highlight/CssXhtmlRenderer.java
(rev 0)
+++
trunk/docs/highlight/src/main/java/org/richfaces/highlight/CssXhtmlRenderer.java 2007-10-10
18:16:22 UTC (rev 3321)
@@ -0,0 +1,372 @@
+package org.richfaces.highlight;
+import java.awt.Color;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Formattable;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.wst.css.core.internal.parser.CSSTokenizer;
+import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts;
+
+import com.uwyn.jhighlight.highlighter.ExplicitStateHighlighter;
+import com.uwyn.jhighlight.renderer.XhtmlRenderer;
+import com.uwyn.jhighlight.tools.StringUtils;
+
+
+public class CssXhtmlRenderer extends XhtmlRenderer {
+
+ static class WrapperBean<T> {
+ private T wrapped;
+
+ public WrapperBean(T wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return ((WrapperBean<?>)obj).get() == wrapped;
+ }
+
+ public T get() {
+ return wrapped;
+ }
+
+ @Override
+ public int hashCode() {
+ return wrapped.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return super.toString();
+ }
+ }
+
+ class FormattableToken implements Formattable {
+ private String token;
+
+ public FormattableToken(String token) {
+ this.token = token;
+ }
+
+ public void formatTo(Formatter formatter, int flags, int width,
+ int precision) {
+ try {
+ formatter.out().append(getClassForToken(token));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ class XHTMLString implements Formattable {
+ private String text;
+
+ public XHTMLString(String text) {
+ this.text = text;
+ }
+
+ public void formatTo(Formatter formatter, int flags, int width,
+ int precision) {
+ String s =
+ StringUtils.replace(StringUtils.encodeHtml(text), " ",
" ")
+ .replaceAll("\\r?\\n", "<br />\n");
+ try {
+ formatter.out().append(s);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ class FormattableColor implements Formattable {
+ private Color color;
+
+ public FormattableColor(Color color) {
+ this.color = color;
+ }
+
+ public void formatTo(Formatter formatter, int flags, int width,
+ int precision) {
+ try {
+ formatter.out().append("#").append(
+ Integer.toHexString(color.getRGB()).substring(2)
+ .toUpperCase());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static final Map<String, Color> fContextToStyleMap = new
HashMap<String, Color>();
+
+ private static final String classTemplate = ".css_%s";
+ private static final String colorTemplate = "color:%s;";
+ private static final String tokenTemplate = "<span
class=\"css_%s\">%s</span>";
+
+ private static final Map<String, String> tokenClasses = new HashMap<String,
String>();
+
+ private Map<String, String> defaultCss = null;
+
+ static {
+ //eclipse source code copied
+ fContextToStyleMap.put(CSSRegionContexts.CSS_COMMENT, IStyleConstantsCSS.COMMENT);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_CDO, IStyleConstantsCSS.COMMENT);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_CDC, IStyleConstantsCSS.COMMENT);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_S, IStyleConstantsCSS.NORMAL);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DELIMITER,
IStyleConstantsCSS.SEMI_COLON);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_LBRACE, IStyleConstantsCSS.CURLY_BRACE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_RBRACE, IStyleConstantsCSS.CURLY_BRACE);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_IMPORT, IStyleConstantsCSS.ATMARK_RULE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_PAGE, IStyleConstantsCSS.ATMARK_RULE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_MEDIA, IStyleConstantsCSS.ATMARK_RULE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_FONT_FACE,
IStyleConstantsCSS.ATMARK_RULE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_CHARSET, IStyleConstantsCSS.ATMARK_RULE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_ATKEYWORD,
IStyleConstantsCSS.ATMARK_RULE);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_STRING, IStyleConstantsCSS.STRING);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_URI, IStyleConstantsCSS.URI);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_MEDIUM, IStyleConstantsCSS.MEDIA);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_MEDIA_SEPARATOR,
IStyleConstantsCSS.MEDIA);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_CHARSET_NAME, IStyleConstantsCSS.STRING);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_PAGE_SELECTOR, IStyleConstantsCSS.MEDIA);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ELEMENT_NAME,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_UNIVERSAL,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_PSEUDO,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_CLASS,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ID,
IStyleConstantsCSS.SELECTOR);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_COMBINATOR,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_SEPARATOR,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_START,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_END,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_NAME,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_VALUE,
IStyleConstantsCSS.SELECTOR);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_OPERATOR,
IStyleConstantsCSS.SELECTOR);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_PROPERTY,
IStyleConstantsCSS.PROPERTY_NAME);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_DIMENSION,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_STRING,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_URI,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_HASH,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_UNICODE_RANGE,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_IMPORTANT,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_VALUE_S,
IStyleConstantsCSS.PROPERTY_VALUE);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_SEPARATOR,
IStyleConstantsCSS.COLON);
+ fContextToStyleMap.put(CSSRegionContexts.CSS_DECLARATION_DELIMITER,
IStyleConstantsCSS.SEMI_COLON);
+
+ fContextToStyleMap.put(CSSRegionContexts.CSS_UNKNOWN, IStyleConstantsCSS.ERROR);
+ }
+
+ public static void main(String[] args) throws Exception {
+ //new CssXhtmlRenderer().generateCSSTemplate(new
File("D:\\eclipse\\rf\\rf3\\docs\\userguide\\en\\src\\main\\resources\\css\\css.css"));
+ //new CssXhtmlRenderer().generateClassesForTokens();
+
+ //System.exit(0);
+
+ String path =
"D:\\eclipse\\rf\\rf3\\samples\\richfaces-demo\\src\\main\\webapp\\css\\common.css";
+
+ if (args.length > 0) {
+ path = args[0];
+ }
+
+ FileReader fileReader = new FileReader(path);
+
+
+ try {
+
+ new CssXhtmlRenderer().highlight("aaaa", new FileInputStream(path), new
FileOutputStream("css.html"), null, false);
+
+ } finally {
+ fileReader.close();
+ }
+ }
+
+
+ private void generateClassesForTokens() {
+ Map<WrapperBean<Color>, String> fieldMap = new
HashMap<WrapperBean<Color>, String>();
+
+ try {
+ Field[] fields = IStyleConstantsCSS.class.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+ int modifiers = field.getModifiers();
+
+ if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
+ String name = field.getName().toLowerCase();
+ Object object = field.get(null);
+ if (object instanceof Color) {
+ fieldMap.put(new WrapperBean<Color>((Color) object), name);
+ }
+
+
+ }
+ }
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+
+ Iterator<Entry<String, Color>> iterator =
fContextToStyleMap.entrySet().iterator();
+ while(iterator.hasNext()) {
+ Entry<String, Color> entry = iterator.next();
+ String token = entry.getKey();
+ Color color = entry.getValue();
+ WrapperBean<Color> bean = new WrapperBean<Color>(color);
+
+ String string = fieldMap.get(bean);
+ tokenClasses.put(token, string);
+
+ }
+
+
+ }
+
+ public Map<String, String> generateCSSTemplate() {
+ Map<String, String> m = new HashMap<String, String>();
+ Field[] fields = IStyleConstantsCSS.class.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+ int modifiers = field.getModifiers();
+
+ if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
+ String name = field.getName().toLowerCase();
+ try {
+ Object object = field.get(null);
+ if (object instanceof Color) {
+ FormattableColor color = new FormattableColor((Color) object);
+ m.put(String.format(classTemplate, name), String.format(colorTemplate, color));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return m;
+ }
+
+
+
+ public String getClassForToken(String token) {
+ synchronized (tokenClasses) {
+ if (tokenClasses.isEmpty()) {
+ generateClassesForTokens();
+ }
+ }
+
+ return tokenClasses.get(token);
+ }
+
+ protected String getCssClass(int arg0) {
+ return null;
+ }
+
+ @Override
+ protected synchronized Map<String,String> getDefaultCssStyles() {
+
+ if (defaultCss == null) {
+ defaultCss = generateCSSTemplate();
+ }
+ return defaultCss;
+ }
+
+ protected ExplicitStateHighlighter getHighlighter() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.uwyn.jhighlight.renderer.XhtmlRenderer#highlight(java.lang.String,
java.io.InputStream, java.io.OutputStream, java.lang.String, boolean)
+ */
+ public void highlight(String name, InputStream in, OutputStream out,
+ String encoding, boolean fragment) throws IOException {
+
+ InputStreamReader reader = encoding == null ?
+ new InputStreamReader(in) :
+ new InputStreamReader(in, encoding);
+
+ StringBuffer b = new StringBuffer();
+ char [] buffer = new char[1024];
+ int read;
+
+ while((read = reader.read(buffer)) != -1) {
+ b.append(buffer, 0, read);
+ }
+
+ highlight(name, b.toString(), out, encoding, fragment);
+ }
+
+ private void highlight(String name, String in, OutputStream output,
+ String encoding, boolean fragment) throws IOException{
+
+ String string = StringUtils.convertTabsToSpaces(in, 4);
+ PrintWriter out = new PrintWriter(output);
+
+ if (fragment)
+ {
+ out.write(getXhtmlHeaderFragment(name));
+ }
+ else
+ {
+ out.write(getXhtmlHeader(name));
+ }
+
+ CSSTokenizer tokenizer = new CSSTokenizer(new StringReader(string));
+ while (!tokenizer.isEOF()) {
+ String token = tokenizer.primGetNextToken();
+ if (token != null) {
+ String text = tokenizer.yytext();
+ out.printf(tokenTemplate, new FormattableToken(token), new XHTMLString(text));
+ } else {
+ if (tokenizer.yylength() > 0) {
+ throw new IllegalStateException();
+ }
+ }
+ }
+ if (!fragment) {
+ out.write(getXhtmlFooter());
+ }
+
+ out.flush();
+ out.close();
+ }
+
+ public String highlight(String name, String in, String encoding,
+ boolean fragment) throws IOException {
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ highlight(name, in, s, encoding, fragment);
+
+ s.flush();
+ s.close();
+
+ return (encoding == null) ? s.toString() : s.toString(encoding);
+ }
+
+}
+
Added: trunk/docs/highlight/src/main/java/org/richfaces/highlight/IStyleConstantsCSS.java
===================================================================
--- trunk/docs/highlight/src/main/java/org/richfaces/highlight/IStyleConstantsCSS.java
(rev 0)
+++
trunk/docs/highlight/src/main/java/org/richfaces/highlight/IStyleConstantsCSS.java 2007-10-10
18:16:22 UTC (rev 3321)
@@ -0,0 +1,22 @@
+package org.richfaces.highlight;
+import java.awt.Color;
+
+
+//eclipse source code copied
+public interface IStyleConstantsCSS {
+
+ Color COMMENT = new Color(63, 95, 191);
+ Color NORMAL = new Color(0);
+ Color SEMI_COLON = new Color(0);;
+ Color CURLY_BRACE = new Color(0);;
+ Color ATMARK_RULE = new Color(63, 127, 127);
+ Color SELECTOR = new Color(63, 127, 127);
+ Color MEDIA = new Color(42, 0, 255);
+ Color STRING = new Color(42, 0, 255);
+ Color URI = new Color(42, 0, 255);
+ Color PROPERTY_VALUE = new Color(42, 0, 255);
+ Color COLON = new Color(0);;
+ Color ERROR = new Color(191, 63, 63);
+ Color PROPERTY_NAME = new Color(127, 0, 127);
+
+}
Added:
trunk/docs/highlight/src/main/java/org/richfaces/highlight/XhtmlRendererFactory.java
===================================================================
--- trunk/docs/highlight/src/main/java/org/richfaces/highlight/XhtmlRendererFactory.java
(rev 0)
+++
trunk/docs/highlight/src/main/java/org/richfaces/highlight/XhtmlRendererFactory.java 2007-10-10
18:16:22 UTC (rev 3321)
@@ -0,0 +1,118 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.highlight;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import com.uwyn.jhighlight.renderer.Renderer;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class XhtmlRendererFactory {
+
+ private static XhtmlRendererFactory instance;
+ public static final String fileName = "renderers.properties";
+ private Map<Object, Object> classNames = new HashMap<Object, Object>();
+
+ public static final XhtmlRendererFactory instance() {
+ synchronized(XhtmlRendererFactory.class) {
+ if (instance == null) {
+ instance = new XhtmlRendererFactory();
+ }
+ }
+
+ return instance;
+ }
+
+ public XhtmlRendererFactory() {
+ InputStream resourceAsStream =
+ getClass().getResourceAsStream(fileName);
+ try {
+ Properties props = new Properties();
+ props.load(resourceAsStream);
+ classNames.putAll(props);
+ resourceAsStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public Renderer getRenderer(String type) {
+
+ Renderer renderer =
+ com.uwyn.jhighlight.renderer.XhtmlRendererFactory.getRenderer(type);
+ if (renderer == null) {
+ Object object = classNames.get(type.toLowerCase());
+ if (object != null) {
+ String className = object.toString();
+
+ try {
+ Class<?> class1 = Class.forName(className);
+ Object newInstance = class1.newInstance();
+ if (newInstance instanceof Renderer) {
+ return (Renderer) newInstance;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return renderer;
+ }
+
+ public static void main(String[] args) {
+ Renderer renderer =
+ XhtmlRendererFactory.instance().getRenderer("css");
+ String path =
"D:\\eclipse\\rf\\rf3\\samples\\richfaces-demo\\src\\main\\webapp\\css\\common.css";
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ renderer.highlight("css", new FileInputStream(path),bos, null, true);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ renderer = XhtmlRendererFactory.instance().getRenderer("xhtml");
+ try {
+ renderer.highlight("bbb", new ByteArrayInputStream(bos.toByteArray()),
System.out, null, false);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+}
Added:
trunk/docs/highlight/src/main/resources/org/richfaces/highlight/renderers.properties
===================================================================
--- trunk/docs/highlight/src/main/resources/org/richfaces/highlight/renderers.properties
(rev 0)
+++
trunk/docs/highlight/src/main/resources/org/richfaces/highlight/renderers.properties 2007-10-10
18:16:22 UTC (rev 3321)
@@ -0,0 +1 @@
+css=org.richfaces.highlight.CssXhtmlRenderer
Modified: trunk/docs/pom.xml
===================================================================
--- trunk/docs/pom.xml 2007-10-10 16:28:00 UTC (rev 3320)
+++ trunk/docs/pom.xml 2007-10-10 18:16:22 UTC (rev 3321)
@@ -39,6 +39,10 @@
<
url>http://maven.exadel.com/</url>
<layout>default</layout>
</repository>
+ <repository>
+ <id>eclipse</id>
+ <
url>http://repo1.maven.org/eclipse/</url>
+ </repository>
</repositories>
<pluginRepositories>
<pluginRepository>
@@ -77,6 +81,7 @@
<modules>
+ <module>highlight</module>
<module>xslt</module>
<!--
<module>docbook</module>
Modified: trunk/docs/userguide/en/src/main/resources/css/html.css
===================================================================
--- trunk/docs/userguide/en/src/main/resources/css/html.css 2007-10-10 16:28:00 UTC (rev
3320)
+++ trunk/docs/userguide/en/src/main/resources/css/html.css 2007-10-10 18:16:22 UTC (rev
3321)
@@ -347,3 +347,42 @@
cursor: pointer;
}
+.css_comment {
+color:#3F5FBF;
+}
+.css_normal {
+color:#000000;
+}
+.css_semi_colon {
+color:#000000;
+}
+.css_curly_brace {
+color:#000000;
+}
+.css_atmark_rule {
+color:#3F7F7F;
+}
+.css_selector {
+color:#3F7F7F;
+}
+.css_media {
+color:#2A00FF;
+}
+.css_string {
+color:#2A00FF;
+}
+.css_uri {
+color:#2A00FF;
+}
+.css_property_value {
+color:#2A00FF;
+}
+.css_colon {
+color:#000000;
+}
+.css_error {
+color:#BF3F3F;
+}
+.css_property_name {
+color:#7F007F;
+}
Modified: trunk/docs/xslt/en/pom.xml
===================================================================
--- trunk/docs/xslt/en/pom.xml 2007-10-10 16:28:00 UTC (rev 3320)
+++ trunk/docs/xslt/en/pom.xml 2007-10-10 18:16:22 UTC (rev 3321)
@@ -12,7 +12,14 @@
<name>Documentation stylesheets (English translation)</name>
<description>
Docbook documentation stylesheets for En-Us translation
- </description>
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>org.richfaces.docs</groupId>
+ <artifactId>highlight</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
<build>
<resources>
<resource>
Modified: trunk/docs/xslt/en/src/main/xslt/code-highlight.xsl
===================================================================
--- trunk/docs/xslt/en/src/main/xslt/code-highlight.xsl 2007-10-10 16:28:00 UTC (rev
3320)
+++ trunk/docs/xslt/en/src/main/xslt/code-highlight.xsl 2007-10-10 18:16:22 UTC (rev
3321)
@@ -8,9 +8,10 @@
version="1.0"
xmlns="http://www.w3.org/TR/xhtml1/transitional"
exclude-result-prefixes="#default"
+ xmlns:rf="java:org.richfaces.highlight.XhtmlRendererFactory"
- <xsl:template
match="programlisting[@role='XML']|programlisting[@role='JAVA']|programlisting[@role='XHTML']|programlisting[@role='JSP']">
+ <xsl:template
match="programlisting[@role='XML']|programlisting[@role='JAVA']|programlisting[@role='XHTML']|programlisting[@role='JSP']|programlisting[@role='CSS']">
<xsl:variable name="role">
<xsl:value-of select="s:toUpperCase(string(@role))"
xmlns:s="java:java.lang.String"/>
@@ -18,8 +19,8 @@
<xsl:variable name="child.content">
<xsl:apply-templates/>
</xsl:variable>
-
- <xsl:variable name="hiliter"
select="jhl:getRenderer(string($role))"
xmlns:jhl="java:com.uwyn.jhighlight.renderer.XhtmlRendererFactory"/>
+ <xsl:variable name="factory" select="rf:instance()"/>
+ <xsl:variable name="hiliter" select="rf:getRenderer($factory,
string($role))"/>
<pre class="{$role}">
<xsl:choose>
<xsl:when test="$hiliter">