public void printJSONResponse(Writer outWriter) throws IOException { if (isDirty()) { outWriter.write(", \"dd\":"); JsonPaintTarget jsonPaintTarget = new JsonPaintTarget( session.getCommunicationManager(), outWriter, false); jsonPaintTarget.startTag("dd"); jsonPaintTarget.addAttribute("visitId", lastVisitId); if (acceptCriterion != null) { jsonPaintTarget.addAttribute("accepted", lastVisitAccepted); acceptCriterion.paintResponse(jsonPaintTarget); } jsonPaintTarget.endTag("dd"); jsonPaintTarget.close(); lastVisitId = -1; lastVisitAccepted = false; acceptCriterion = null; dragEvent = null; } }
@Override public void addVariable(VariableOwner owner, String name, StreamVariable value) throws PaintException { String url = manager.getStreamVariableTargetUrl((ClientConnector) owner, name, value); if (url != null) { addVariable(owner, name, url); } // else { //NOP this was just a cleanup by component } }
startTag(sectionTagName); if (namespace != null) { addAttribute("xmlns", namespace); tag.addData("\"" + escapeJSON(sectionData) + "\""); endTag(sectionTagName);
/** * Adds a upload stream type variable. * * TODO not converted for JSON * * @param owner * the Listener for variable changes. * @param name * the Variable name. * * @throws PaintException * if the paint operation failed. */ @Override public void addUploadStreamVariable(VariableOwner owner, String name) throws PaintException { startTag("uploadstream"); addAttribute(UIDL_ARG_NAME, name); endTag("uploadstream"); }
@Override public void addAttribute(String name, String value) throws PaintException { // In case of null data output nothing: if ((value == null) || (name == null)) { throw new NullPointerException( "Parameters must be non-null strings"); } tag.addAttribute("\"" + name + "\":\"" + escapeJSON(value) + "\""); if (customLayoutArgumentsOpen && "template".equals(name)) { getUsedResources().add("layouts/" + value + ".html"); } }
@Override public PaintStatus startPaintable(Component connector, String tagName) throws PaintException { boolean topLevelPaintable = openPaintables.isEmpty(); if (getLogger().isLoggable(Level.FINE)) { getLogger().log(Level.FINE, "startPaintable for {0}@{1}", new Object[] { connector.getClass().getName(), Integer.toHexString(connector.hashCode()) }); } startTag(tagName, true); openPaintables.push(connector); openPaintableTags.push(tagName); addAttribute("id", connector.getConnectorId()); // Only paint top level paintables. All sub paintables are marked as // queued and painted separately later. if (!topLevelPaintable) { return PaintStatus.CACHED; } if (connector instanceof CustomLayout) { customLayoutArgumentsOpen = true; } return PaintStatus.PAINTING; }
writer.write("\"changes\" : "); JsonPaintTarget paintTarget = new JsonPaintTarget(manager, writer, !repaintAll); paintTarget.close(); writer.write(", "); // close changes .getUsedClientConnectors(); boolean typeMappingsOpen = false;
/** * Prints XML-escaped text. * * @param str * @throws PaintException * if the paint operation failed. * */ @Override public void addText(String str) throws PaintException { tag.addData("\"" + escapeJSON(str) + "\""); }
@Override public void endPaintable(Component paintable) throws PaintException { if (getLogger().isLoggable(Level.FINE)) { getLogger().log(Level.FINE, "endPaintable for {0}@{1}", new Object[] { paintable.getClass().getName(), Integer.toHexString(paintable.hashCode()) }); } ClientConnector openPaintable = openPaintables.peek(); if (paintable != openPaintable) { throw new PaintException("Invalid UIDL: closing wrong paintable: '" + paintable.getConnectorId() + "' expected: '" + openPaintable.getConnectorId() + "'."); } // remove paintable from the stack openPaintables.pop(); String openTag = openPaintableTags.pop(); endTag(openTag); }
@Override public void addAttribute(String name, Component value) throws PaintException { final String id = value.getConnectorId(); addAttribute(name, id); }
/** * Substitutes the XML sensitive characters with predefined XML entities. * * @param xml * the String to be substituted. * @return A new string instance where all occurrences of XML sensitive * characters are substituted with entities. */ public static String escapeXML(String xml) { if (xml == null || xml.length() <= 0) { return ""; } return escapeXML(new StringBuilder(xml)).toString(); }
/** * Closes the paint target. Paint target must be closed before the * <code>getUIDL</code> can be called. Subsequent attempts to write to paint * target. If the target was already closed, call to this function is * ignored. will generate an exception. * * @throws PaintException * if the paint operation failed. */ public void close() throws PaintException { if (tag != null) { uidlBuffer.write(tag.getJSON()); } flush(); closed = true; }
for (Object o : target.getUsedResources()) { final String resource = (String) o; InputStream is = null; + JsonPaintTarget.escapeJSON(layout.toString()) + "\""); } else {
@Override public String getJsonPresentation() { StringBuilder sb = new StringBuilder(); sb.append("\""); sb.append(name); sb.append("\":["); for (int i = 0; i < value.length;) { sb.append("\""); sb.append(escapeJSON(value[i])); sb.append("\""); i++; if (i < value.length) { sb.append(','); } } sb.append(']'); return sb.toString(); } }
@Override public void addAttribute(String name, Resource value) throws PaintException { if (value == null) { throw new NullPointerException(); } ClientConnector ownerConnector = openPaintables.peek(); ownerConnector.getUI().getSession().getGlobalResourceHandler(true) .register(value, ownerConnector); ResourceReference reference = ResourceReference.create(value, ownerConnector, name); addAttribute(name, reference.getURL()); }
/** * Prints the single text section. * * Prints full text section. The section data is escaped * * @param sectionTagName * the name of the tag. * @param sectionData * the section data to be printed. * @throws PaintException * if the paint operation failed. */ @Override public void addSection(String sectionTagName, String sectionData) throws PaintException { tag.addData("{\"" + sectionTagName + "\":\"" + escapeJSON(sectionData) + "\"}"); }
@Override public void addAttribute(String name, Object[] values) { // In case of null data output nothing: if ((values == null) || (name == null)) { throw new NullPointerException( "Parameters must be non-null strings"); } final StringBuilder buf = new StringBuilder(); buf.append("\"").append(name).append("\":["); for (int i = 0; i < values.length; i++) { if (i > 0) { buf.append(','); } buf.append("\""); buf.append(escapeJSON(values[i].toString())); buf.append("\""); } buf.append(']'); tag.addAttribute(buf.toString()); }
@Override public void addVariable(VariableOwner owner, String name, String value) throws PaintException { tag.addVariable(new StringVariable(owner, name, escapeJSON(value))); }
sb.append(((ClientConnector) key).getConnectorId()); } else { sb.append(escapeJSON(key.toString())); } else { sb.append("\""); sb.append(escapeJSON(mapValue.toString())); sb.append("\"");
/** * Adds XML directly to UIDL. * * @param xml * the Xml to be added. * @throws PaintException * if the paint operation failed. */ @Override public void addUIDL(String xml) throws PaintException { // Ensure that the target is open if (closed) { throw new PaintException( "Attempted to write to a closed PaintTarget."); } // Make sure that the open start tag is closed before // anything is written. // Escape and write what was given if (xml != null) { tag.addData("\"" + escapeJSON(xml) + "\""); } }