Package dk.brics.xact

Examples of dk.brics.xact.XML


    /**
     * Returns the XML value.
     */
    public XML getXML() {
        XML xml1 = xml.get();
        if (xml1 == null) {
            xml1 = XML.parseTemplate(serializedXML);
            xml = new SoftReference<XML>(xml1);
        }
        return xml1;
View Full Code Here


            }
        }
        response.setContentType(contenttype);
        response.setCharacterEncoding(CHARSET);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        XML xml = getXML();
        ByteArrayOutputStream w = new ByteArrayOutputStream();
        boolean hack = status != HttpServletResponse.SC_OK; // hack to disable IE "friendly error messages" :-(
        xml.toDocument(w, CHARSET);
        int length = w.size();
        if (hack) {
            length += blank.length;
        }
        response.setContentLength(length);
View Full Code Here

   * Generates a ConstStm.
   */
  private void putConst(String template, Origin origin) {
    hardcodeResult = makevar();
    TemplateConstant cnst = new TemplateConstant(template, context.getNamespaces(), origin);
    XML x = parseXML(cnst.getTemplate(), origin);
    if (x != null) {
        cnst.setXML(x);
        cfg.addStatement(new ConstStm(hardcodeResult,
            cnst,
            origin));
View Full Code Here

        if (matcher.find()) {
            host = matcher.group(1);
        }
        error.setStatus(status_code);

        XML xml;
        if (standalone)
            xml = msg;
        else {
            xml = error_template
                    .plug("CODE", status_code)
                    .plug("MSG", msg)
                    .plug("SERVER", host)
                    .plug("TIME",
                            new SimpleDateFormat("d MMM yyyy HH:mm:ss Z",
                                    Locale.US).format(new Date()))
                    .plug("LOGOURL",
                            ThreadContext.getBaseURL(request.isSecure())
                                    + request.getContextPath()
                                    + "/jwiglogo.gif");
            if (status_code == HttpServletResponse.SC_NOT_FOUND) {
                xml = xml.plug("BADNESS", "NOT FOUND");
            } else {
                xml = xml.plug("BADNESS", "ERROR");
            }
        }

        log.info("Sending error " + status_code + " to client");
        WebContext.punish(Dispatcher.getClient(request));
View Full Code Here

        return producer;
    }

    private XML getXMLValue(Session ses) {
        Map<Integer, XML> map = getMap(ses);
        XML def = XML.parseTemplate("");
    XML xml = map.get(this.hashCode());
    if (xml == null) {
        xml = def;
    }
    return xml;
    }
View Full Code Here

     */
    public void setLatestReturnValue(XML val) {
        if (ses == null || producer == null) {
            return;
        }
        XML latest = getXMLValue(ses);
        if (!latest.equals(val)) {
            if (val == null) {
                getMap(ses).remove(this.hashCode());
            } else {
                getMap(ses).put(this.hashCode(),val);
            }
View Full Code Here

     * Returns an XML value obtained by invoking <code>run</code>, together with
     * a JavaScript instruction for automatic updating.
     */
    @Override
  public XML toXML() {
        XML xml = invokeRun();
        Response p = makeResponse(xml); //Make a cached response that stores the value of the XML generated by the producer (and tag it with an ETAG)
        String handlerCacheIdentifier = getCacheAugmentedString(getHandlerIdentifier());

        ThreadContext.getCache().put(handlerCacheIdentifier, p); //Manually store the value in the cache for later requests
        String id = "s" + RandomString.get(12);
View Full Code Here

            ThreadContext c = ThreadContext.get();
            Method m = getClass().getDeclaredMethod("run");
            XMLProducer previous = c.getProducer();
            c.setProducer(this);
            m.setAccessible(true);
            XML xml = (XML) m.invoke(this);
            c.setProducer(previous);
            return xml;
        } catch (NoSuchMethodException e) {
            throw new JWIGException(e);
        } catch (IllegalArgumentException e) {
View Full Code Here

    /**
     * Invokes the <code>run</code> method of the handler, caches the result, and sends it to the client.
     */
    @Override
    Object process(String referer) {
        XML xml = wrap(invokeRun());
        getResponse().setContentType("text/plain");
        return xml;
    }
View Full Code Here

        ThreadContext c = ThreadContext.get();
        RequestManager manager = c.getRequestManager();
        Response r = getResponse();
        if (o instanceof XML) {
            // log.debug("Augmenting: " + r.getETag());
            XML xml = (XML) o;
            String home = manager.getWebSiteURL(c.getServletRequest()
                    .isSecure());
            xml = xml
                    .prependContent(
                            "//xhtml:head",
                            XML.parseTemplate(
                                    "<script type=\"text/javascript\" src=[JWIG]></script>")
                                    .plug("JWIG", manager.makeURL("jwigJS")));
            xml = xml
                    .prependContent(
                            "//xhtml:body", //It is safe to set a constant id given that only one body may exist
                            XML.parseTemplate("<div id=\"noscript\" style=\"color:red\">" +
                                    "[ This web application uses JavaScript, which is not enabled in your browser - "
                                    + "for full functionality, use a browser that supports JavaScript ]</div>" +
                                    "<script type=\"text/javascript\"> " +
                                    "document.getElementById(\"noscript\").style.display = \"none\";" +
                                    "</script>"));
            xml = xml.appendContent("//xhtml:body",
                    XML.parseTemplate(
                            "<script type=\"text/javascript\">"
                                    + "jwig.run('<[HOME]>');" + "</script>")
                            .plug("HOME", home));
            xml = xml.appendContent("//xhtml:body",
                                    XML.parseTemplate("<script type=\"text/javascript\">"
                                    + "jwig.submitHandlerData = <[SUB]> ;" + "</script>").plug("SUB",
                                                                                               generateSubmitHandlerData(r)));
            if (auto_refresh_sessions) {
                Set<Session> sessions = r.getSessions();
                if (sessions != null && sessions.size() > 0) {
                    int minutes = 0;
                    for (Session s : sessions) {
                        int min = s.getMinutes();
                        if (minutes < min || minutes == 0) {
                            minutes = min;
                        }
                    }
                    Object[] ss = { sessions.toArray() };
                    xml = xml
                            .appendContent(
                                    "//xhtml:head",
                                    XML.parseTemplate(
                                            "<script type=\"text/javascript\">"
                                                    + "jwig.startRefreshSessions('<[REFRESH_URL]>',<[MINUTES]>);"
                                                    + "</script>")
                                            .plug("REFRESH_URL",
                                                    manager.makeURL(
                                                            "touchSessions", ss)
                                                            .toString())
                                            .plug("MINUTES", minutes - 1));
                }
            }
            if (Config.get("jwig.logo", true)) {
                xml = xml
                        .appendContent(
                                "//xhtml:body",
                                XML.parseTemplate(
                                        "<table width=\"100%\"><tr>"
                                                + "<td align=\"right\"><a href=\"http://www.brics.dk/JWIG/\">"
View Full Code Here

TOP

Related Classes of dk.brics.xact.XML

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.