天天看点

ICEfaces抄袭PrimeFaces

ICEfaces涉嫌抄袭PrimeFaces

ICEfaces 3发布后,本来我是很激动的,以为这是一个伟大的版本。但是,PrimeFaces的同行们发现了ICEfaces抄袭了PrimeFaces的部分代码。ICEfaces的行为真令人失望!

由于PrimeFaces和ICEfaces都是开源产品,因此抄袭在法律上没有问题。但是在道德上,则无法过关。抄袭的代码对比如下:

一、PrimeFaces PanelRenderer

"text-align: left;">

import java.io.IOException;  

import java.util.Map;  

import javax.faces.component.UIComponent;  

import javax.faces.context.FacesContext;  

import javax.faces.context.ResponseWriter;  

import org.primefaces.component.menu.Menu;  

import org.primefaces.renderkit.CoreRenderer;  

public class PanelRenderer extends CoreRenderer {  

    @Override  

    public void decode(FacesContext context, UIComponent component) {  

        Panel panel = (Panel) component;  

        String clientId = panel.getClientId(context);  

        Map params = context.getExternalContext().getRequestParameterMap();  

        //Restore toggle state  

        String collapsedParam = params.get(clientId + "_collapsed");  

        if(collapsedParam != null) {  

            panel.setCollapsed(Boolean.valueOf(collapsedParam));  

        }  

        //Restore visibility state  

        String visibleParam = params.get(clientId + "_visible");  

        if(visibleParam != null) {  

            panel.setVisible(Boolean.valueOf(visibleParam));  

        decodeBehaviors(context, component);  

    }  

    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {  

        encodeMarkup(facesContext, panel);  

        encodeScript(facesContext, panel);  

    protected void encodeScript(FacesContext context, Panel panel) throws IOException {  

        ResponseWriter writer = context.getResponseWriter();  

        startScript(writer, clientId);  

        writer.write("PrimeFaces.cw('Panel','" + panel.resolveWidgetVar() + "',{");  

        writer.write("id:'" + clientId + "'");  

        //Toggle configuration  

        if(panel.isToggleable()) {  

            writer.write(",toggleable:true");  

            writer.write(",toggleSpeed:" + panel.getToggleSpeed());  

            writer.write(",collapsed:" + panel.isCollapsed());  

        if(panel.isClosable()) {  

            writer.write(",closable:true");  

            writer.write(",closeSpeed:" + panel.getCloseSpeed());  

        //Options menu configuration  

        if(panel.getOptionsMenu() != null) {  

            writer.write(",hasMenu:true");  

        encodeClientBehaviors(context, panel);  

        writer.write("});");  

        endScript(writer);  

    protected void encodeMarkup(FacesContext context, Panel panel) throws IOException {  

        Menu optionsMenu = panel.getOptionsMenu();  

        writer.startElement("div", null);  

        writer.writeAttribute("id", clientId, null);  

        String styleClass = panel.getStyleClass() != null ? Panel.PANEL_CLASS + " " + panel.getStyleClass() : Panel.PANEL_CLASS;  

        styleClass = panel.isVisible() ? styleClass : styleClass + " ui-helper-hidden";  

        writer.writeAttribute("class", styleClass, "styleClass");  

        if(panel.getStyle() != null) {  

            writer.writeAttribute("style", panel.getStyle(), "style");  

        encodeHeader(context, panel);  

        encodeContent(context, panel);  

        encodeFooter(context, panel);  

            encodeStateHolder(context, panel, clientId + "_collapsed", String.valueOf(panel.isCollapsed()));  

            encodeStateHolder(context, panel, clientId + "_visible", String.valueOf(panel.isVisible()));  

        if (optionsMenu != null) {  

            optionsMenu.setPosition("dynamic");  

            optionsMenu.setTrigger(clientId + "_menu");  

            optionsMenu.setMy("left top");  

            optionsMenu.setAt("left bottom");  

            optionsMenu.encodeAll(context);  

        writer.endElement("div");  

    protected void encodeHeader(FacesContext context, Panel panel) throws IOException {  

        String widgetVar = panel.resolveWidgetVar();  

        UIComponent header = panel.getFacet("header");  

        String headerText = panel.getHeader();  

        if(headerText == null && header == null) {  

            return;  

        writer.writeAttribute("id", panel.getClientId(context) + "_header", null);  

        writer.writeAttribute("class", Panel.PANEL_TITLEBAR_CLASS, null);  

        //Title  

        writer.startElement("span", null);  

        writer.writeAttribute("class", Panel.PANEL_TITLE_CLASS, null);  

        if(header != null) {  

            renderChild(context, header);  

        } else if(headerText != null) {  

            writer.write(headerText);  

        writer.endElement("span");  

        //Options  

            encodeIcon(context, panel, "ui-icon-closethick", clientId + "_closer", panel.getCloseTitle());  

            String icon = panel.isCollapsed() ? "ui-icon-plusthick" : "ui-icon-minusthick";  

            encodeIcon(context, panel, icon, clientId + "_toggler", panel.getToggleTitle());  

            encodeIcon(context, panel, "ui-icon-gear", clientId + "_menu", panel.getMenuTitle());  

    protected void encodeContent(FacesContext facesContext, Panel panel) throws IOException {  

        ResponseWriter writer = facesContext.getResponseWriter();  

        writer.writeAttribute("id", panel.getClientId() + "_content", null);  

        writer.writeAttribute("class", Panel.PANEL_CONTENT_CLASS, null);  

        if (panel.isCollapsed()) {  

            writer.writeAttribute("style", "display:none", null);  

        renderChildren(facesContext, panel);  

    protected void encodeFooter(FacesContext facesContext, Panel panel) throws IOException {  

        UIComponent footer = panel.getFacet("footer");  

        String footerText = panel.getFooter();  

        if (footer != null || footerText != null) {  

            writer.startElement("div", null);  

            writer.writeAttribute("id", panel.getClientId(facesContext) + "_footer", null);  

            writer.writeAttribute("class", Panel.PANEL_FOOTER_CLASS, null);  

            if (footer != null) {  

                renderChild(facesContext, footer);  

            } else if (footerText != null) {  

                writer.write(footerText);  

            }  

            writer.endElement("div");  

    protected void encodeIcon(FacesContext context, Panel panel, String iconClass, String id, String title) throws IOException {  

        writer.startElement("a", null);  

        writer.writeAttribute("href", "javascript:void(0)", null);  

        writer.writeAttribute("class", Panel.PANEL_TITLE_ICON_CLASS, null);  

        if(title != null) {  

            writer.writeAttribute("title", title, null);  

        if(id != null) {  

            writer.writeAttribute("id", id, null);  

        writer.writeAttribute("class", "ui-icon " + iconClass, null);  

        writer.endElement("a");  

    protected void encodeStateHolder(FacesContext context, Panel panel, String name, String value) throws IOException {  

        writer.startElement("input", null);  

        writer.writeAttribute("type", "hidden", null);  

        writer.writeAttribute("id", name, null);  

        writer.writeAttribute("name", name, null);  

        writer.writeAttribute("value", value, null);  

        writer.endElement("input");  

    public void encodeChildren(FacesContext context, UIComponent component) throws IOException {  

        //Do nothing  

    public boolean getRendersChildren() {  

        return true;  

}

二、IceFaces PanelRenderer

package org.icefaces.ace.component.panel;  

import org.icefaces.ace.component.menu.Menu;  

import org.icefaces.ace.renderkit.CoreRenderer;  

import org.icefaces.ace.util.Utils;  

import org.icefaces.ace.util.JSONBuilder;  

import org.icefaces.render.MandatoryResourceComponent;  

@MandatoryResourceComponent(tagName="panel", value="org.icefaces.ace.component.panel.Panel")  

        writer.startElement("script", null);  

        writer.writeAttribute("type", "text/javascript", null);  

        writer.write(this.resolveWidgetVar(panel) + " = new ");  

        JSONBuilder jb = JSONBuilder.create();  

        jb.beginFunction("ice.ace.Panel")  

            .item(clientId)  

            .beginMap()  

            .entry("visible", panel.isVisible());  

            jb.entry("toggleable", true);  

            jb.entry("toggleSpeed", panel.getToggleSpeed());  

            jb.entry("collapsed", panel.isCollapsed());  

            jb.entry("closable", true);  

            jb.entry("closeSpeed", panel.getCloseSpeed());  

            jb.entry("hasMenu", true);  

        encodeClientBehaviors(context, panel, jb);  

        jb.endMap().endFunction();  

        writer.write(jb.toString());  

        writer.endElement("script");  

        String styleClass = panel.getStyleClass() ;  

        Utils.writeConcatenatedStyleClasses(writer, Panel.PANEL_CLASS, styleClass);  

        String style = panel.getStyle();  

        if(style != null) {  

            writer.writeAttribute("style", style, "style");  

        String widgetVar = this.resolveWidgetVar(panel);  

        writer.writeAttribute("id", clientId + "_header", null);  

            encodeIcon(context, panel, "ui-icon-closethick", clientId + "_closer");  

            encodeIcon(context, panel, icon, clientId + "_toggler");  

            encodeIcon(context, panel, "ui-icon-gear", clientId + "_menu");  

    protected void encodeIcon(FacesContext context, Panel panel, String iconClass, String id) throws IOException {  

}  

三、PrimeFaces Panel.js

/** 

 * PrimeFaces Panel Widget 

 */  

PrimeFaces.widget.Panel = function(cfg) {  

    this.cfg = cfg;  

    this.id = this.cfg.id;  

    this.jqId = PrimeFaces.escapeClientId(this.id);  

    if(this.cfg.toggleable) {  

        this.toggler = $(this.jqId + '_toggler');  

        this.toggleStateHolder = $(this.jqId + '_collapsed');  

        this.content = $(this.jqId + '_content');  

        this.setupToggleTrigger();  

    if(this.cfg.closable) {  

        this.visibleStateHolder = $(this.jqId + "_visible");  

        this.setupCloseTrigger();  

    if(this.cfg.hasMenu) {  

        this.setupMenuTrigger();  

    this.postConstruct();  

PrimeFaces.extend(PrimeFaces.widget.Panel, PrimeFaces.widget.BaseWidget);  

PrimeFaces.widget.Panel.prototype.toggle = function() {  

    if(this.cfg.collapsed) {  

        this.toggler.removeClass('ui-icon-plusthick').addClass('ui-icon-minusthick');  

        this.cfg.collapsed = false;  

        this.toggleStateHolder.val(false);  

    else {  

        this.toggler.removeClass('ui-icon-minusthick').addClass('ui-icon-plusthick');  

        this.cfg.collapsed = true;  

        this.toggleStateHolder.val(true);  

    var _self = this;  

    this.content.slideToggle(this.cfg.toggleSpeed,  

        function(e) {  

            if(_self.cfg.behaviors) {  

                var toggleBehavior = _self.cfg.behaviors['toggle'];  

                if(toggleBehavior) {  

                    toggleBehavior.call(_self, e);  

                }  

        });  

PrimeFaces.widget.Panel.prototype.close = function() {  

    this.visibleStateHolder.val(false);  

    $(this.jqId).fadeOut(this.cfg.closeSpeed,  

                var closeBehavior = _self.cfg.behaviors['close'];  

                if(closeBehavior) {  

                    closeBehavior.call(_self, e);  

    );  

PrimeFaces.widget.Panel.prototype.show = function() {  

    $(this.jqId).fadeIn(this.cfg.closeSpeed);  

    this.visibleStateHolder.val(true);  

PrimeFaces.widget.Panel.prototype.setupToggleTrigger = function() {  

    var _self = this,  

    trigger = this.toggler.parent();  

    this.setupTriggerVisuals(trigger);  

    trigger.click(function() {_self.toggle();});  

PrimeFaces.widget.Panel.prototype.setupCloseTrigger = function() {  

    trigger = $(this.jqId + '_closer').parent();  

    trigger.click(function() {_self.close();});  

PrimeFaces.widget.Panel.prototype.setupMenuTrigger = function() {  

    var trigger = $(this.jqId + '_menu').parent();  

PrimeFaces.widget.Panel.prototype.setupTriggerVisuals = function(trigger) {  

    trigger.mouseover(function() {$(this).addClass('ui-state-hover');})  

            .mouseout(function() {$(this).removeClass('ui-state-hover');});  

四、IceFaces Panel.js

 *  Panel Widget 

ice.ace.Panel = function(id, cfg) {  

    this.id = id;  

    this.jqId = ice.ace.escapeClientId(id);  

        this.toggler = ice.ace.jq(this.jqId + '_toggler');  

        this.toggleStateHolder = ice.ace.jq(this.jqId + '_collapsed');  

        this.content = ice.ace.jq(this.jqId + '_content');  

        this.visibleStateHolder = ice.ace.jq(this.jqId + "_visible");  

    if(!this.cfg.visible) {  

        ice.ace.jq(this.jqId).css('display','none');  

ice.ace.Panel.prototype.toggle = function() {  

                    toggleBehavior.call(this, e);  

ice.ace.Panel.prototype.close = function() {  

    ice.ace.jq(this.jqId).fadeOut(this.cfg.closeSpeed,  

                    closeBehavior.call(this, e);  

ice.ace.Panel.prototype.show = function() {  

    ice.ace.jq(this.jqId).fadeIn(this.cfg.closeSpeed);  

ice.ace.Panel.prototype.setupToggleTrigger = function() {  

ice.ace.Panel.prototype.setupCloseTrigger = function() {  

    trigger = ice.ace.jq(this.jqId + '_closer').parent();  

ice.ace.Panel.prototype.setupMenuTrigger = function() {  

    var trigger = ice.ace.jq(this.jqId + '_menu').parent();  

ice.ace.Panel.prototype.setupTriggerVisuals = function(trigger) {  

    trigger.mouseover(function() {ice.ace.jq(this).addClass('ui-state-hover');})  

            .mouseout(function() {ice.ace.jq(this).removeClass('ui-state-hover');});  

ICEsoft公司在开发ACE组件集时,把PrimeFaces的代码直接复制过来,然后修改包名和类名,其它的代码都是照搬。这种行为真丢脸。

结论:ICEfaces的行为让人及其失望,用PrimeFaces的开发者的一句原话作为本文的总结:“您可以复制我们的代码,但您永远也拿不走我们的激情!”。