jaroslav@260: /** jaroslav@358: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. jaroslav@260: * jaroslav@551: * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved. jaroslav@260: * jaroslav@358: * Oracle and Java are registered trademarks of Oracle and/or its affiliates. jaroslav@358: * Other names may be trademarks of their respective owners. jaroslav@260: * jaroslav@358: * The contents of this file are subject to the terms of either the GNU jaroslav@358: * General Public License Version 2 only ("GPL") or the Common jaroslav@358: * Development and Distribution License("CDDL") (collectively, the jaroslav@358: * "License"). You may not use this file except in compliance with the jaroslav@358: * License. You can obtain a copy of the License at jaroslav@358: * http://www.netbeans.org/cddl-gplv2.html jaroslav@358: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the jaroslav@358: * specific language governing permissions and limitations under the jaroslav@358: * License. When distributing the software, include this License Header jaroslav@358: * Notice in each file and include the License file at jaroslav@358: * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this jaroslav@358: * particular file as subject to the "Classpath" exception as provided jaroslav@358: * by Oracle in the GPL Version 2 section of the License file that jaroslav@358: * accompanied this code. If applicable, add the following below the jaroslav@358: * License Header, with the fields enclosed by brackets [] replaced by jaroslav@358: * your own identifying information: jaroslav@358: * "Portions Copyrighted [year] [name of copyright owner]" jaroslav@358: * jaroslav@358: * Contributor(s): jaroslav@358: * jaroslav@358: * The Original Software is NetBeans. The Initial Developer of the Original jaroslav@551: * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved. jaroslav@358: * jaroslav@358: * If you wish your version of this file to be governed by only the CDDL jaroslav@358: * or only the GPL Version 2, indicate your decision by adding jaroslav@358: * "[Contributor] elects to include this software in this distribution jaroslav@358: * under the [CDDL or GPL Version 2] license." If you do not indicate a jaroslav@358: * single choice of license, a recipient has the option to distribute jaroslav@358: * your version of this file under either the CDDL, the GPL Version 2 or jaroslav@358: * to extend the choice of license to its licensees as provided above. jaroslav@358: * However, if you add GPL Version 2 code and therefore, elected the GPL jaroslav@358: * Version 2 license, then the option applies only if the new code is jaroslav@358: * made subject to such option by the copyright holder. jaroslav@260: */ jtulach@1057: package org.netbeans.html.xhr4j; jaroslav@260: jaroslav@260: import java.io.IOException; jaroslav@446: import java.io.InputStream; jaroslav@263: import net.java.html.json.OnReceive; jtulach@838: import org.netbeans.html.context.spi.Contexts; jtulach@838: import org.netbeans.html.json.spi.JSONCall; jtulach@838: import org.netbeans.html.json.spi.Transfer; jaroslav@260: import org.openide.util.lookup.ServiceProvider; jaroslav@260: jtulach@1057: /** Implementation module with support for XHR via Java. jtulach@1057: * Handles {@link OnReceive} requests by using Java to connect to given jtulach@1057: * URL and then parsing it via JavaScript. Use this module if you have jtulach@1057: * problems with CORS - as the Java connection isn't restricted by CORS jtulach@1057: * rules. jtulach@1057: * jtulach@1057: * Registers {@link Transfer} technology at position 50. jtulach@1057: * The {@link Contexts.Id} of the technology is xhr4j. jtulach@1057: * jtulach@790: * @author Jaroslav Tulach jtulach@1057: * @since 1.3 jaroslav@260: */ jtulach@1057: @Contexts.Id("xhr4j") jaroslav@260: @ServiceProvider(service = Contexts.Provider.class) jtulach@1057: public final class XmlHttpResourceContext jtulach@1057: implements Contexts.Provider, Transfer { jaroslav@260: @Override jaroslav@260: public void fillContext(Contexts.Builder context, Class requestor) { jtulach@1057: context.register(Transfer.class, this, 50); jaroslav@260: } jaroslav@446: jaroslav@446: @Override jaroslav@446: public void extract(Object obj, String[] props, Object[] values) { jaroslav@446: LoadJSON.extractJSON(obj, props, values); jaroslav@446: } jaroslav@446: jaroslav@446: @Override jaroslav@446: public Object toJSON(InputStream is) throws IOException { jtulach@1057: return LoadJSON.parse(LoadJSON.readStream(is)); jaroslav@446: } jaroslav@446: jaroslav@446: @Override jaroslav@446: public void loadJSON(JSONCall call) { jaroslav@446: LoadJSON.loadJSON(call); jaroslav@446: } jaroslav@260: }