You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by to...@apache.org on 2005/12/19 01:33:16 UTC
svn commit: r357583 - in /myfaces/build/trunk/tools/src/java: ./ javax/
javax/faces/ javax/faces/context/ org/ org/apache/ org/apache/myfaces/
org/apache/myfaces/tools/
Author: tomsp
Date: Sun Dec 18 16:32:59 2005
New Revision: 357583
URL: http://svn.apache.org/viewcvs?rev=357583&view=rev
Log: (empty)
Added:
myfaces/build/trunk/tools/src/java/
myfaces/build/trunk/tools/src/java/javax/
myfaces/build/trunk/tools/src/java/javax/faces/
myfaces/build/trunk/tools/src/java/javax/faces/context/
myfaces/build/trunk/tools/src/java/javax/faces/context/FacesContextSingleton.java
myfaces/build/trunk/tools/src/java/org/
myfaces/build/trunk/tools/src/java/org/apache/
myfaces/build/trunk/tools/src/java/org/apache/myfaces/
myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/
myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/FaceletsTaglibTask.java
myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Tag.java
myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Taglib.java
Added: myfaces/build/trunk/tools/src/java/javax/faces/context/FacesContextSingleton.java
URL: http://svn.apache.org/viewcvs/myfaces/build/trunk/tools/src/java/javax/faces/context/FacesContextSingleton.java?rev=357583&view=auto
==============================================================================
--- myfaces/build/trunk/tools/src/java/javax/faces/context/FacesContextSingleton.java (added)
+++ myfaces/build/trunk/tools/src/java/javax/faces/context/FacesContextSingleton.java Sun Dec 18 16:32:59 2005
@@ -0,0 +1,12 @@
+package javax.faces.context;
+
+/**
+ * @author Thomas Spiegl
+ */
+public class FacesContextSingleton
+{
+ public static void setCurrentInstance(FacesContext facesContext)
+ {
+ FacesContext.setCurrentInstance(facesContext);
+ }
+}
Added: myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/FaceletsTaglibTask.java
URL: http://svn.apache.org/viewcvs/myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/FaceletsTaglibTask.java?rev=357583&view=auto
==============================================================================
--- myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/FaceletsTaglibTask.java (added)
+++ myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/FaceletsTaglibTask.java Sun Dec 18 16:32:59 2005
@@ -0,0 +1,443 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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 org.apache.myfaces.tools;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache .commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+import javax.faces.FacesException;
+import javax.faces.application.*;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.*;
+import javax.faces.convert.Converter;
+import javax.faces.el.*;
+import javax.faces.event.ActionListener;
+import javax.faces.render.RenderKit;
+import javax.faces.validator.Validator;
+import javax.faces.webapp.UIComponentTag;
+import javax.faces.webapp.ValidatorTag;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.File;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author Thomas Spiegl
+ */
+public class FaceletsTaglibTask extends Task
+{
+ private static final Log log = LogFactory.getLog(FaceletsTaglibTask.class);
+
+ private String _validatorId;
+ private String _sourceTld;
+ private String _targetFile;
+
+ public void setSourceTld(String sourceTld)
+ {
+ _sourceTld = sourceTld;
+ }
+
+ public void setTargetFile(String targetFile)
+ {
+ _targetFile = targetFile;
+ }
+
+
+ public void execute() throws BuildException
+ {
+ log.info("generating facelets taglib source: "+ _sourceTld + " target: " + _targetFile);
+ File source = new File(_sourceTld);
+ File target = new File(_targetFile);
+ FaceletsTaglibTask faceletSupport = new FaceletsTaglibTask();
+ try
+ {
+ faceletSupport.createFaceletTaglib(source, target);
+ }
+ catch (Exception e)
+ {
+ throw new BuildException(e);
+ }
+ }
+
+ public void createFaceletTaglib(File source, File target) throws Exception
+ {
+ FacesContextSingleton.setCurrentInstance(new FacesContextMock());
+
+ Digester digester = new Digester();
+ digester.addObjectCreate("taglib", Taglib.class);
+ digester.addObjectCreate("taglib/tag", Tag.class);
+ digester.addCallMethod("taglib/tag/name", "setName", 0);
+ digester.addCallMethod("taglib/tag/tag-class", "setTagClass", 0);
+ digester.addSetNext("taglib/tag", "addTag", "org.apache.myfaces.tools.Tag");
+ Taglib taglib = (Taglib) digester.parse(source);
+
+ Document doc = createDocument();
+ Element taglibElem = doc.createElement("facelet-taglib");
+ doc.appendChild(taglibElem);
+ List tags = taglib.getTags();
+ for (int i = 0; i < tags.size(); i++) {
+ Tag tag = (Tag) tags.get(i);
+ Class clazz = Thread.currentThread().getContextClassLoader().loadClass(tag.getTagClass());
+ if (UIComponentTag.class.isAssignableFrom(clazz)) {
+ Element tagEl = createElement(doc, taglibElem, "tag", null);
+ createElement(doc, tagEl, "tag-name", tag.getName());
+ Element componentEl = createElement(doc, tagEl, "component", null);
+ Object obj = clazz.newInstance();
+ createElement(doc, componentEl, "component-type", BeanUtils.getProperty(obj, "componentType"));
+ String rendererType = BeanUtils.getProperty(obj, "rendererType");
+ if (rendererType != null)
+ createElement(doc, componentEl, "renderer-type", rendererType);
+ }
+ else if (ValidatorTag.class.isAssignableFrom(clazz))
+ {
+ Element tagEl = createElement(doc, taglibElem, "tag", null);
+ createElement(doc, tagEl, "tag-name", tag.getName());
+ Element componentEl = createElement(doc, tagEl, "validator", null);
+ Object obj = clazz.newInstance();
+ Method method = obj.getClass().getDeclaredMethod("createValidator", null);
+ method.setAccessible(true);
+ method.invoke(obj, null);
+ createElement(doc, componentEl, "validator-id", _validatorId);
+ }
+ }
+ serialize(doc, new FileOutputStream(target));
+ }
+
+ private Element createElement(Document doc, Element parent, String name, String text)
+ {
+ Element element = doc.createElement(name);
+ parent.appendChild(element);
+ if (text != null) {
+ Text textEl = doc.createTextNode(text);
+ element.appendChild(textEl);
+ }
+ return element;
+ }
+
+ private Document createDocument() throws ParserConfigurationException
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder =docBuilderFactory.newDocumentBuilder();
+ return docBuilder.newDocument();
+ }
+
+ private void serialize(Document target, OutputStream out) throws
+ TransformerConfigurationException, TransformerException {
+ Transformer transformer = createTransformer();
+ transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "facelet-taglib");
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN\" \"facelet-taglib_1_0.dtd");
+ transformer.transform(new DOMSource(target), new StreamResult(out));
+ }
+
+ private Transformer createTransformer() throws TransformerConfigurationException
+ {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ return factory.newTransformer();
+ }
+
+ private class FacesContextMock extends FacesContext
+ {
+ private Application _application = new ApplicationMock();
+
+ public Application getApplication()
+ {
+ return _application;
+ }
+
+ public Iterator getClientIdsWithMessages()
+ {
+ return null;
+ }
+
+ public ExternalContext getExternalContext()
+ {
+ return null;
+ }
+
+ public FacesMessage.Severity getMaximumSeverity()
+ {
+ return null;
+ }
+
+ public Iterator getMessages()
+ {
+ return null;
+ }
+
+ public Iterator getMessages(String string)
+ {
+ return null;
+ }
+
+ public RenderKit getRenderKit()
+ {
+ return null;
+ }
+
+ public boolean getRenderResponse()
+ {
+ return false;
+ }
+
+ public boolean getResponseComplete()
+ {
+ return false;
+ }
+
+ public ResponseStream getResponseStream()
+ {
+ return null;
+ }
+
+ public void setResponseStream(ResponseStream responseStream)
+ {
+ }
+
+ public ResponseWriter getResponseWriter()
+ {
+ return null;
+ }
+
+ public void setResponseWriter(ResponseWriter responseWriter)
+ {
+ }
+
+ public UIViewRoot getViewRoot()
+ {
+ return null;
+ }
+
+ public void setViewRoot(UIViewRoot uiViewRoot)
+ {
+ }
+
+ public void addMessage(String string, FacesMessage facesMessage)
+ {
+ }
+
+ public void release()
+ {
+ }
+
+ public void renderResponse()
+ {
+ }
+
+ public void responseComplete()
+ {
+ }
+ }
+
+ private class ApplicationMock extends Application
+ {
+ public ActionListener getActionListener()
+ {
+ return null;
+ }
+
+ public void setActionListener(ActionListener actionListener)
+ {
+
+ }
+
+ public Locale getDefaultLocale()
+ {
+ return null;
+ }
+
+ public void setDefaultLocale(Locale locale)
+ {
+
+ }
+
+ public String getDefaultRenderKitId()
+ {
+ return null;
+ }
+
+ public void setDefaultRenderKitId(String string)
+ {
+
+ }
+
+ public String getMessageBundle()
+ {
+ return null;
+ }
+
+ public void setMessageBundle(String string)
+ {
+
+ }
+
+ public NavigationHandler getNavigationHandler()
+ {
+ return null;
+ }
+
+ public void setNavigationHandler(NavigationHandler navigationHandler)
+ {
+
+ }
+
+ public PropertyResolver getPropertyResolver()
+ {
+ return null;
+ }
+
+ public void setPropertyResolver(PropertyResolver propertyResolver)
+ {
+
+ }
+
+ public VariableResolver getVariableResolver()
+ {
+ return null;
+ }
+
+ public void setVariableResolver(VariableResolver variableResolver)
+ {
+
+ }
+
+ public ViewHandler getViewHandler()
+ {
+ return null;
+ }
+
+ public void setViewHandler(ViewHandler viewHandler)
+ {
+
+ }
+
+ public StateManager getStateManager()
+ {
+ return null;
+ }
+
+ public void setStateManager(StateManager stateManager)
+ {
+
+ }
+
+ public void addComponent(String string, String string1)
+ {
+
+ }
+
+ public UIComponent createComponent(String string) throws FacesException
+ {
+ return null;
+ }
+
+ public UIComponent createComponent(ValueBinding valueBinding, FacesContext facesContext, String string) throws FacesException
+ {
+ return null;
+ }
+
+ public Iterator getComponentTypes()
+ {
+ return null;
+ }
+
+ public void addConverter(String string, String string1)
+ {
+
+ }
+
+ public void addConverter(Class aClass, String string)
+ {
+
+ }
+
+ public Converter createConverter(String string)
+ {
+ return null;
+ }
+
+ public Converter createConverter(Class aClass)
+ {
+ return null;
+ }
+
+ public Iterator getConverterIds()
+ {
+ return null;
+ }
+
+ public Iterator getConverterTypes()
+ {
+ return null;
+ }
+
+ public MethodBinding createMethodBinding(String string, Class[] classes) throws ReferenceSyntaxException
+ {
+ return null;
+ }
+
+ public Iterator getSupportedLocales()
+ {
+ return null;
+ }
+
+ public void setSupportedLocales(Collection collection)
+ {
+
+ }
+
+ public void addValidator(String string, String string1)
+ {
+
+ }
+
+ public Validator createValidator(String string) throws FacesException
+ {
+ _validatorId = string;
+ return null;
+ }
+
+ public Iterator getValidatorIds()
+ {
+ return null;
+ }
+
+ public ValueBinding createValueBinding(String string) throws ReferenceSyntaxException
+ {
+ return null;
+ }
+
+ }
+}
Added: myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Tag.java
URL: http://svn.apache.org/viewcvs/myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Tag.java?rev=357583&view=auto
==============================================================================
--- myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Tag.java (added)
+++ myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Tag.java Sun Dec 18 16:32:59 2005
@@ -0,0 +1,30 @@
+package org.apache.myfaces.tools;
+
+/**
+ * @author Thomas Spiegl
+ */
+public class Tag
+{
+ private String _tagClass;
+ private String _name;
+
+ public String getTagClass()
+ {
+ return _tagClass;
+ }
+
+ public void setTagClass(String tagClass)
+ {
+ _tagClass = tagClass;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public void setName(String name)
+ {
+ _name = name;
+ }
+}
Added: myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Taglib.java
URL: http://svn.apache.org/viewcvs/myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Taglib.java?rev=357583&view=auto
==============================================================================
--- myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Taglib.java (added)
+++ myfaces/build/trunk/tools/src/java/org/apache/myfaces/tools/Taglib.java Sun Dec 18 16:32:59 2005
@@ -0,0 +1,23 @@
+package org.apache.myfaces.tools;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Thomas Spiegl
+ */
+public class Taglib
+{
+ private List _tags = new ArrayList();
+
+ public void addTag(Tag tag)
+ {
+ _tags.add(tag);
+ }
+
+ public List getTags()
+ {
+ return _tags;
+ }
+
+}