1.1 --- a/htmlpage/pom.xml Mon Sep 24 12:39:21 2012 +0200
1.2 +++ b/htmlpage/pom.xml Mon Sep 24 15:06:43 2012 +0200
1.3 @@ -12,7 +12,7 @@
1.4 <version>1.0-SNAPSHOT</version>
1.5 <name>htmlpage</name>
1.6 <url>http://maven.apache.org</url>
1.7 - <properties>
1.8 + <properties>
1.9 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1.10 </properties>
1.11 <dependencies>
1.12 @@ -27,5 +27,21 @@
1.13 </exclusion>
1.14 </exclusions>
1.15 </dependency>
1.16 + <dependency>
1.17 + <groupId>org.netbeans.api</groupId>
1.18 + <artifactId>org-openide-util-lookup</artifactId>
1.19 + </dependency>
1.20 </dependencies>
1.21 + <build>
1.22 + <plugins>
1.23 + <plugin>
1.24 + <groupId>com.mycila.maven-license-plugin</groupId>
1.25 + <artifactId>maven-license-plugin</artifactId>
1.26 + <version>1.9.0</version>
1.27 + <configuration>
1.28 + <header>../vm/src/header.txt</header>
1.29 + </configuration>
1.30 + </plugin>
1.31 + </plugins>
1.32 + </build>
1.33 </project>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Mon Sep 24 15:06:43 2012 +0200
2.3 @@ -0,0 +1,113 @@
2.4 +/**
2.5 + * Java 4 Browser Bytecode Translator
2.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
2.7 + *
2.8 + * This program is free software: you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation, version 2 of the License.
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program. Look for COPYING file in the top folder.
2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
2.20 + */
2.21 +package org.apidesign.bck2brwsr.htmlpage;
2.22 +
2.23 +import java.io.IOException;
2.24 +import java.io.InputStream;
2.25 +import java.io.OutputStreamWriter;
2.26 +import java.io.Writer;
2.27 +import java.util.Locale;
2.28 +import java.util.Set;
2.29 +import javax.annotation.processing.AbstractProcessor;
2.30 +import javax.annotation.processing.Processor;
2.31 +import javax.annotation.processing.RoundEnvironment;
2.32 +import javax.annotation.processing.SupportedAnnotationTypes;
2.33 +import javax.lang.model.element.Element;
2.34 +import javax.lang.model.element.PackageElement;
2.35 +import javax.lang.model.element.TypeElement;
2.36 +import javax.tools.Diagnostic;
2.37 +import javax.tools.FileObject;
2.38 +import javax.tools.StandardLocation;
2.39 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
2.40 +import org.openide.util.lookup.ServiceProvider;
2.41 +
2.42 +/** Annotation processor to process an XHTML page and generate appropriate
2.43 + * "id" file.
2.44 + *
2.45 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.46 + */
2.47 +@ServiceProvider(service=Processor.class)
2.48 +@SupportedAnnotationTypes("org.apidesign.bck2brwsr.htmlpage.api.Page")
2.49 +public final class PageProcessor extends AbstractProcessor {
2.50 + @Override
2.51 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
2.52 + for (Element e : roundEnv.getElementsAnnotatedWith(Page.class)) {
2.53 + Page p = e.getAnnotation(Page.class);
2.54 + PackageElement pe = (PackageElement)e;
2.55 + String pkg = pe.getQualifiedName().toString();
2.56 +
2.57 + ProcessPage pp;
2.58 + try {
2.59 + InputStream is = openStream(pkg, p.xhtml());
2.60 + pp = ProcessPage.readPage(is);
2.61 + is.close();
2.62 + } catch (IOException iOException) {
2.63 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't read " + p.xhtml(), e);
2.64 + return false;
2.65 + }
2.66 + Writer w;
2.67 + try {
2.68 + FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + p.name(), e);
2.69 + w = new OutputStreamWriter(java.openOutputStream());
2.70 + w.append("package " + pkg + ";\n");
2.71 + w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
2.72 + w.append("class ").append(p.name()).append(" {\n");
2.73 + for (String id : pp.ids()) {
2.74 + String tag = pp.tagNameForId(id);
2.75 + String type = type(tag);
2.76 + w.append(" ").append("public static final ").
2.77 + append(type).append(' ').append(cnstnt(id)).append(" = new ").
2.78 + append(type).append("(\"").append(id).append("\");\n");
2.79 + }
2.80 + w.append("}");
2.81 + w.close();
2.82 + } catch (IOException ex) {
2.83 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + p.name() + ".java", e);
2.84 + return false;
2.85 + }
2.86 + }
2.87 + return true;
2.88 + }
2.89 +
2.90 + private InputStream openStream(String pkg, String name) throws IOException {
2.91 + FileObject fo = processingEnv.getFiler().getResource(
2.92 + StandardLocation.SOURCE_PATH, pkg, name);
2.93 + try {
2.94 + return fo.openInputStream();
2.95 + } catch (IOException ex) {
2.96 + return processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, name).openInputStream();
2.97 + }
2.98 + }
2.99 +
2.100 + private static String type(String tag) {
2.101 + if (tag.equals("title")) {
2.102 + return "Title";
2.103 + }
2.104 + if (tag.equals("button")) {
2.105 + return "Button";
2.106 + }
2.107 + if (tag.equals("input")) {
2.108 + return "Input";
2.109 + }
2.110 + return "Element";
2.111 + }
2.112 +
2.113 + private static String cnstnt(String id) {
2.114 + return id.toUpperCase(Locale.ENGLISH).replace('.', '_');
2.115 + }
2.116 +}
3.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/ProcessPage.java Mon Sep 24 12:39:21 2012 +0200
3.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/ProcessPage.java Mon Sep 24 15:06:43 2012 +0200
3.3 @@ -1,3 +1,20 @@
3.4 +/**
3.5 + * Java 4 Browser Bytecode Translator
3.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 + *
3.8 + * This program is free software: you can redistribute it and/or modify
3.9 + * it under the terms of the GNU General Public License as published by
3.10 + * the Free Software Foundation, version 2 of the License.
3.11 + *
3.12 + * This program is distributed in the hope that it will be useful,
3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 + * GNU General Public License for more details.
3.16 + *
3.17 + * You should have received a copy of the GNU General Public License
3.18 + * along with this program. Look for COPYING file in the top folder.
3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 + */
3.21 package org.apidesign.bck2brwsr.htmlpage;
3.22
3.23 import java.io.IOException;
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java Mon Sep 24 15:06:43 2012 +0200
4.3 @@ -0,0 +1,32 @@
4.4 +/**
4.5 + * Java 4 Browser Bytecode Translator
4.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 + *
4.8 + * This program is free software: you can redistribute it and/or modify
4.9 + * it under the terms of the GNU General Public License as published by
4.10 + * the Free Software Foundation, version 2 of the License.
4.11 + *
4.12 + * This program is distributed in the hope that it will be useful,
4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 + * GNU General Public License for more details.
4.16 + *
4.17 + * You should have received a copy of the GNU General Public License
4.18 + * along with this program. Look for COPYING file in the top folder.
4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 + */
4.21 +package org.apidesign.bck2brwsr.htmlpage.api;
4.22 +
4.23 +/**
4.24 + *
4.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
4.26 + */
4.27 +public class Button extends Element {
4.28 + public Button(String id) {
4.29 + super(id);
4.30 + }
4.31 +
4.32 + @Override
4.33 + void dontSubclass() {
4.34 + }
4.35 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Mon Sep 24 15:06:43 2012 +0200
5.3 @@ -0,0 +1,32 @@
5.4 +/**
5.5 + * Java 4 Browser Bytecode Translator
5.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 + *
5.8 + * This program is free software: you can redistribute it and/or modify
5.9 + * it under the terms of the GNU General Public License as published by
5.10 + * the Free Software Foundation, version 2 of the License.
5.11 + *
5.12 + * This program is distributed in the hope that it will be useful,
5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 + * GNU General Public License for more details.
5.16 + *
5.17 + * You should have received a copy of the GNU General Public License
5.18 + * along with this program. Look for COPYING file in the top folder.
5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 + */
5.21 +package org.apidesign.bck2brwsr.htmlpage.api;
5.22 +
5.23 +/** Represents a generic HTML element.
5.24 + *
5.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
5.26 + */
5.27 +public abstract class Element {
5.28 + private final String id;
5.29 +
5.30 + public Element(String id) {
5.31 + this.id = id;
5.32 + }
5.33 +
5.34 + abstract void dontSubclass();
5.35 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java Mon Sep 24 15:06:43 2012 +0200
6.3 @@ -0,0 +1,32 @@
6.4 +/**
6.5 + * Java 4 Browser Bytecode Translator
6.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.7 + *
6.8 + * This program is free software: you can redistribute it and/or modify
6.9 + * it under the terms of the GNU General Public License as published by
6.10 + * the Free Software Foundation, version 2 of the License.
6.11 + *
6.12 + * This program is distributed in the hope that it will be useful,
6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.15 + * GNU General Public License for more details.
6.16 + *
6.17 + * You should have received a copy of the GNU General Public License
6.18 + * along with this program. Look for COPYING file in the top folder.
6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
6.20 + */
6.21 +package org.apidesign.bck2brwsr.htmlpage.api;
6.22 +
6.23 +/**
6.24 + *
6.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
6.26 + */
6.27 +public class Input extends Element {
6.28 + public Input(String id) {
6.29 + super(id);
6.30 + }
6.31 +
6.32 + @Override
6.33 + void dontSubclass() {
6.34 + }
6.35 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Page.java Mon Sep 24 15:06:43 2012 +0200
7.3 @@ -0,0 +1,43 @@
7.4 +/**
7.5 + * Java 4 Browser Bytecode Translator
7.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 + *
7.8 + * This program is free software: you can redistribute it and/or modify
7.9 + * it under the terms of the GNU General Public License as published by
7.10 + * the Free Software Foundation, version 2 of the License.
7.11 + *
7.12 + * This program is distributed in the hope that it will be useful,
7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 + * GNU General Public License for more details.
7.16 + *
7.17 + * You should have received a copy of the GNU General Public License
7.18 + * along with this program. Look for COPYING file in the top folder.
7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 + */
7.21 +/*
7.22 + * To change this template, choose Tools | Templates
7.23 + * and open the template in the editor.
7.24 + */
7.25 +package org.apidesign.bck2brwsr.htmlpage.api;
7.26 +
7.27 +import java.lang.annotation.ElementType;
7.28 +import java.lang.annotation.Retention;
7.29 +import java.lang.annotation.RetentionPolicy;
7.30 +import java.lang.annotation.Target;
7.31 +
7.32 +/** Converts an XHTML page into a Java class that contains
7.33 + * references to all IDs.
7.34 + *
7.35 + * @author Jaroslav Tulach <jtulach@netbeans.org>
7.36 + */
7.37 +@Retention(RetentionPolicy.SOURCE)
7.38 +@Target(ElementType.PACKAGE)
7.39 +public @interface Page {
7.40 + /** Path to the XHTML page to read in */
7.41 + String xhtml();
7.42 + /** Name of a Java class to generate. It will contain constants for all
7.43 + * found elements with IDs.
7.44 + */
7.45 + String name();
7.46 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java Mon Sep 24 15:06:43 2012 +0200
8.3 @@ -0,0 +1,32 @@
8.4 +/**
8.5 + * Java 4 Browser Bytecode Translator
8.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 + *
8.8 + * This program is free software: you can redistribute it and/or modify
8.9 + * it under the terms of the GNU General Public License as published by
8.10 + * the Free Software Foundation, version 2 of the License.
8.11 + *
8.12 + * This program is distributed in the hope that it will be useful,
8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 + * GNU General Public License for more details.
8.16 + *
8.17 + * You should have received a copy of the GNU General Public License
8.18 + * along with this program. Look for COPYING file in the top folder.
8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 + */
8.21 +package org.apidesign.bck2brwsr.htmlpage.api;
8.22 +
8.23 +/**
8.24 + *
8.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
8.26 + */
8.27 +public class Title extends Element {
8.28 + public Title(String id) {
8.29 + super(id);
8.30 + }
8.31 +
8.32 + @Override
8.33 + void dontSubclass() {
8.34 + }
8.35 +}
9.1 --- a/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Mon Sep 24 12:39:21 2012 +0200
9.2 +++ b/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/ProcessPageTest.java Mon Sep 24 15:06:43 2012 +0200
9.3 @@ -1,3 +1,20 @@
9.4 +/**
9.5 + * Java 4 Browser Bytecode Translator
9.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
9.7 + *
9.8 + * This program is free software: you can redistribute it and/or modify
9.9 + * it under the terms of the GNU General Public License as published by
9.10 + * the Free Software Foundation, version 2 of the License.
9.11 + *
9.12 + * This program is distributed in the hope that it will be useful,
9.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.15 + * GNU General Public License for more details.
9.16 + *
9.17 + * You should have received a copy of the GNU General Public License
9.18 + * along with this program. Look for COPYING file in the top folder.
9.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
9.20 + */
9.21 package org.apidesign.bck2brwsr.htmlpage;
9.22
9.23 import java.io.IOException;
9.24 @@ -6,6 +23,8 @@
9.25 import org.testng.annotations.Test;
9.26 import static org.testng.Assert.*;
9.27
9.28 +import org.apidesign.bck2brwsr.htmlpage.api.*;
9.29 +
9.30 public class ProcessPageTest {
9.31
9.32
9.33 @@ -20,4 +39,8 @@
9.34 assertEquals(res.tagNameForId("pg.button"), "button");
9.35 assertEquals(res.tagNameForId("pg.text"), "input");
9.36 }
9.37 +
9.38 + void testWhetherWeCanCallTheGeneratedIdFields() {
9.39 + Title t = TestPage.PG_TITLE;
9.40 + }
9.41 }
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/package-info.java Mon Sep 24 15:06:43 2012 +0200
10.3 @@ -0,0 +1,22 @@
10.4 +/**
10.5 + * Java 4 Browser Bytecode Translator
10.6 + * Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10.7 + *
10.8 + * This program is free software: you can redistribute it and/or modify
10.9 + * it under the terms of the GNU General Public License as published by
10.10 + * the Free Software Foundation, version 2 of the License.
10.11 + *
10.12 + * This program is distributed in the hope that it will be useful,
10.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.15 + * GNU General Public License for more details.
10.16 + *
10.17 + * You should have received a copy of the GNU General Public License
10.18 + * along with this program. Look for COPYING file in the top folder.
10.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
10.20 + */
10.21 +@Page(xhtml="TestPage.xhtml", name="TestPage")
10.22 +package org.apidesign.bck2brwsr.htmlpage;
10.23 +
10.24 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
10.25 +
11.1 --- a/htmlpage/src/test/resources/org/apidesign/bck2brwsr/htmlpage/TestPage.xhtml Mon Sep 24 12:39:21 2012 +0200
11.2 +++ b/htmlpage/src/test/resources/org/apidesign/bck2brwsr/htmlpage/TestPage.xhtml Mon Sep 24 15:06:43 2012 +0200
11.3 @@ -1,4 +1,23 @@
11.4 <?xml version="1.0" encoding="UTF-8"?>
11.5 +<!--
11.6 +
11.7 + Java 4 Browser Bytecode Translator
11.8 + Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
11.9 +
11.10 + This program is free software: you can redistribute it and/or modify
11.11 + it under the terms of the GNU General Public License as published by
11.12 + the Free Software Foundation, version 2 of the License.
11.13 +
11.14 + This program is distributed in the hope that it will be useful,
11.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.17 + GNU General Public License for more details.
11.18 +
11.19 + You should have received a copy of the GNU General Public License
11.20 + along with this program. Look for COPYING file in the top folder.
11.21 + If not, see http://opensource.org/licenses/GPL-2.0.
11.22 +
11.23 +-->
11.24 <!DOCTYPE html>
11.25 <html xmlns="http://www.w3.org/1999/xhtml">
11.26 <head>
12.1 --- a/pom.xml Mon Sep 24 12:39:21 2012 +0200
12.2 +++ b/pom.xml Mon Sep 24 15:06:43 2012 +0200
12.3 @@ -61,6 +61,13 @@
12.4 <version>RELEASE72</version>
12.5 <type>jar</type>
12.6 </dependency>
12.7 + <dependency>
12.8 + <groupId>org.netbeans.api</groupId>
12.9 + <artifactId>org-openide-util-lookup</artifactId>
12.10 + <version>RELEASE72</version>
12.11 + <scope>compile</scope>
12.12 + <type>jar</type>
12.13 + </dependency>
12.14 </dependencies>
12.15 </dependencyManagement>
12.16 <properties>