⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translationhandler.java

📁 ajax patterns 这是关于ajax设计模式方面的原代码
💻 JAVA
字号:
/*
    Copyright 2006 Christian Gross http://www.devspace.com
    From the book Ajax Patterns and Best Practices

   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 devspace.ajax.restMVC.translation;
import devspace.ajax.permutations.*;
import java.util.*;
import javax.servlet.http.*;
import java.io.*;
import devspace.ajax.restMVC.*;
import javax.servlet.*;

class CookieResolver extends GenericCookieUserResolverImplementation {
    protected String getCookieIdentifier() {
        return "TranslationHandler_";
    }
    
    protected String getCookiePath() {
        return "/restmvc/dotranslation";
    }
}

public class TranslationHandler extends RedirectionHttpHandlerBase {
    static Hashtable _tasks = new Hashtable();
    
    public TranslationHandler() {
        assignUserResolver(new CookieResolver());
    }
    
    protected boolean doPermutations() {
        return true;
    }
    protected boolean isMimeSupported(String mimeType) {
        if (mimeType.compareTo( "text/xml") == 0) {
            return true;
        }
        else if (mimeType.compareTo( "text/html") == 0) {
            return true;
        }
        return false;
    }
    
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        SynchronousParent parent = new SynchronousParent();
        parent.addCommand(new GermanTranslationImplementation());
        parent.addCommand(new FrenchTranslationImplementation());
        String wordToTranslate = req.getParameter("word");
        if (wordToTranslate != null && wordToTranslate.length() > 0) {
            parent.processRequest(new WordToTranslateRequest(wordToTranslate));
            if (_mimeType.compareTo( "text/xml") == 0) {
                resp.setContentType("text/xml");
                PrintWriter output = resp.getWriter();
                output.write("<results>");
                for (TranslatedWordResult result : parent.getResultsCollection()) {
                    output.write("<result>");
                    output.write("<original>" + result.getOriginal() + "</original>");
                    output.write("<translated>" + result.getTranslation() + "</translated>");
                    output.write("<language>" + result.getLanguage() + "</language>");
                    output.write("</result>");
                }
                output.write("</results>");
                resp.setStatus(200);
            }
            else if (_mimeType.compareTo( "text/html") == 0) {
                resp.setContentType("text/html");
                PrintWriter output = resp.getWriter();
                output.write("Results:<br />");
                for (TranslatedWordResult result : parent.getResultsCollection()) {
                    output.write("original :" + result.getOriginal() + "<br />");
                    output.write("translated :" + result.getTranslation() + "<br />");
                    output.write("languge:" + result.getLanguage() + "<br />");
                }
                resp.setStatus(200);
            }
        }
        
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        throw new ServletException("HTTP Post is not supported");
    }
    
    protected String getBaseURL() {
        return "/restmvc/dotranslation";
    }
    
    protected String getURLEnding() {
        return _identifiedUser.getIdentifier();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -