com.google.common.xml.XmlEscapers Java Examples
The following examples show how to use
com.google.common.xml.XmlEscapers.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CellValueHelper.java From autopoi with Apache License 2.0 | 6 votes |
/** * 03版本复杂数据 * * @param rich * @return */ private String getHSSFRichString(HSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0; sb.append(text.substring(0, rich.getIndexOfFormattingRun(0))); for (int i = 0; i < nums; i++) { sb.append("<span "); sb.append("class='font_" + rich.getFontOfFormattingRun(i)); sb.append("_"); sb.append(cssRandom); sb.append("'>"); currentIndex = rich.getIndexOfFormattingRun(i); if (i < nums - 1) { sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); } else { sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(currentIndex, text.length()))); } sb.append("</span>"); } return sb.toString(); }
Example #2
Source File: CellValueHelper.java From autopoi with Apache License 2.0 | 6 votes |
/** * 07版本复杂数据 * * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i); sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
Example #3
Source File: OauthRawGcsService.java From appengine-gcs-client with Apache License 2.0 | 6 votes |
@Override public void composeObject(Iterable<String> source, GcsFilename dest, long timeoutMillis) throws IOException { StringBuilder xmlContent = new StringBuilder(Iterables.size(source) * 50); Escaper escaper = XmlEscapers.xmlContentEscaper(); xmlContent.append("<ComposeRequest>"); for (String srcFileName : source) { xmlContent.append("<Component><Name>") .append(escaper.escape(srcFileName)) .append("</Name></Component>"); } xmlContent.append("</ComposeRequest>"); HTTPRequest req = makeRequest( dest, COMPOSE_QUERY_STRINGS, PUT, timeoutMillis, xmlContent.toString().getBytes(UTF_8)); HTTPResponse resp; try { resp = urlfetch.fetch(req); } catch (IOException e) { throw createIOException(new HTTPRequestInfo(req), e); } if (resp.getResponseCode() != 200) { throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp); } }
Example #4
Source File: CellValueHelper.java From jeasypoi with Apache License 2.0 | 6 votes |
/** * 03版本复杂数据 * * @param rich * @return */ private String getHSSFRichString(HSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0; sb.append(text.substring(0, rich.getIndexOfFormattingRun(0))); for (int i = 0; i < nums; i++) { sb.append("<span "); sb.append("class='font_" + rich.getFontOfFormattingRun(i)); sb.append("_"); sb.append(cssRandom); sb.append("'>"); currentIndex = rich.getIndexOfFormattingRun(i); if (i < nums - 1) { sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); } else { sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(currentIndex, text.length()))); } sb.append("</span>"); } return sb.toString(); }
Example #5
Source File: CellValueHelper.java From jeasypoi with Apache License 2.0 | 6 votes |
/** * 07版本复杂数据 * * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i); sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
Example #6
Source File: CellValueHelper.java From easypoi with Apache License 2.0 | 6 votes |
public String getHtmlValue(Cell cell) { if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType() || Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { cell.setCellType(Cell.CELL_TYPE_STRING); return cell.getStringCellValue(); } else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { if (cell.getRichStringCellValue().numFormattingRuns() == 0) { return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); } else if (is07) { return getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue()); } else { return getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue()); } } return ""; }
Example #7
Source File: CellValueHelper.java From easypoi with Apache License 2.0 | 6 votes |
/** * 03版本复杂数据 * @param rich * @return */ private String getHSSFRichString(HSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0; sb.append(text.substring(0, rich.getIndexOfFormattingRun(0))); for (int i = 0; i < nums; i++) { sb.append("<span "); sb.append("class='font_" + rich.getFontOfFormattingRun(i)); sb.append("_"); sb.append(cssRandom); sb.append("'>"); currentIndex = rich.getIndexOfFormattingRun(i); if (i < nums - 1) { sb.append(XmlEscapers.xmlContentEscaper().escape( text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); } else { sb.append(XmlEscapers.xmlContentEscaper().escape( text.substring(currentIndex, text.length()))); } sb.append("</span>"); } return sb.toString(); }
Example #8
Source File: CellValueHelper.java From easypoi with Apache License 2.0 | 6 votes |
/** * 07版本复杂数据 * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich .getIndexOfFormattingRun(i); sb.append(XmlEscapers.xmlContentEscaper().escape( text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
Example #9
Source File: PluralXmlResourceValue.java From bazel with Apache License 2.0 | 6 votes |
public static XmlResourceValue from(Value proto, Visibility visibility) { Plural plural = proto.getCompoundValue().getPlural(); Map<String, String> items = new LinkedHashMap<>(); for (Plural.Entry entry : plural.getEntryList()) { String name = entry.getArity().toString().toLowerCase(); String value = XmlEscapers.xmlContentEscaper().escape( entry.getItem() .getStr() .getValue()); items.put(name, value); } return new PluralXmlResourceValue( visibility, plural, ImmutableMap.of(), ImmutableMap.copyOf(items)); }
Example #10
Source File: CellValueHelper.java From autopoi with Apache License 2.0 | 5 votes |
public String getHtmlValue(Cell cell) { if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType() || Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { cell.setCellType(Cell.CELL_TYPE_STRING); return cell.getStringCellValue(); } else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { if (cell.getRichStringCellValue().numFormattingRuns() == 0) { return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); } else if (is07) { return getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue()); } else { return getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue()); } } return ""; }
Example #11
Source File: JApiAnnotationElementValue.java From japicmp with Apache License 2.0 | 5 votes |
@XmlAttribute(name = "value") public String getValueString() { if (type != Type.Array && type != Type.Annotation) { return XmlEscapers.xmlAttributeEscaper().escape(value.toString()); } return "n.a."; }
Example #12
Source File: ProtoApk.java From bazel with Apache License 2.0 | 5 votes |
private void quote(ByteString bytes) throws IOException { QUOTE.writeTo(out); out.write( XmlEscapers.xmlAttributeEscaper() .escape(bytes.toStringUtf8()) .getBytes(StandardCharsets.UTF_8)); QUOTE.writeTo(out); }
Example #13
Source File: SimpleXmlResourceValue.java From bazel with Apache License 2.0 | 5 votes |
public static XmlResourceValue from( Value proto, Visibility visibility, ResourceType resourceType) { Item item = proto.getItem(); String stringValue = null; ImmutableMap.Builder<String, String> attributes = ImmutableMap.builder(); if (item.hasStr()) { stringValue = XmlEscapers.xmlContentEscaper().escape(item.getStr().getValue()); } else if (item.hasRef()) { stringValue = "@" + item.getRef().getName(); attributes.put("format", "reference"); } else if (item.hasStyledStr()) { StyledString styledString = item.getStyledStr(); StringBuilder stringBuilder = new StringBuilder(styledString.getValue()); for (Span span : styledString.getSpanList()) { stringBuilder.append( String.format(";%s,%d,%d", span.getTag(), span.getFirstChar(), span.getLastChar())); } stringValue = stringBuilder.toString(); } else if (item.hasPrim()) { stringValue = convertPrimitiveToString(item.getPrim()); } else { throw new IllegalArgumentException( String.format("'%s' with value %s is not a simple resource type.", resourceType, proto)); } return new SimpleXmlResourceValue( visibility, Type.valueOf(resourceType.toString().toUpperCase(Locale.ENGLISH)), item, attributes.build(), stringValue); }
Example #14
Source File: AbstractXmlHighlightingFragment2.java From sarl with Apache License 2.0 | 5 votes |
/** Open a tag. * * @param tag the tag name. * @param nameValuePairs the properties. */ void internalOpenTag(String tag, String... nameValuePairs) { append("<").append(tag); //$NON-NLS-1$ for (int i = 0; i < nameValuePairs.length; i = i + 2) { append(" "); //$NON-NLS-1$ append(nameValuePairs[i]); append("=\""); //$NON-NLS-1$ append(XmlEscapers.xmlAttributeEscaper().escape(nameValuePairs[i + 1])); append("\""); //$NON-NLS-1$ } }
Example #15
Source File: CellValueHelper.java From jeasypoi with Apache License 2.0 | 5 votes |
public String getHtmlValue(Cell cell) { if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType() || Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { cell.setCellType(Cell.CELL_TYPE_STRING); return cell.getStringCellValue(); } else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { if (cell.getRichStringCellValue().numFormattingRuns() == 0) { return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); } else if (is07) { return getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue()); } else { return getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue()); } } return ""; }
Example #16
Source File: Extractor.java From javaide with GNU General Public License v3.0 | 4 votes |
@NonNull private static String escapeXml(@NonNull String unescaped) { return XmlEscapers.xmlAttributeEscaper().escape(unescaped); }
Example #17
Source File: LdapView.java From cloudbreak with Apache License 2.0 | 4 votes |
public String getBindPasswordEscaped() { return XmlEscapers.xmlAttributeEscaper().escape(bindPassword); }
Example #18
Source File: EscapeXMLAttributes.java From levelup-java-examples with Apache License 2.0 | 4 votes |
@Test public void escape_xml_with_google_guava () { String escapedXML = XmlEscapers.xmlAttributeEscaper().escape(XML_TO_ESCAPE); assertEquals(ESCAPED_XML, escapedXML); }
Example #19
Source File: DiffResult.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
protected String xhtmlEscapeContent(String val) { return XmlEscapers.xmlContentEscaper().escape(val); }
Example #20
Source File: DiffResult.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
protected String xhtmlEscapeAttribute(String val) { return XmlEscapers.xmlAttributeEscaper().escape(val); }
Example #21
Source File: RecurlyObjectSerializer.java From arcusplatform with Apache License 2.0 | 2 votes |
/** * * Calls toString() for all objects passed in except for char arrays for which * this converts to a new string and then clears the char array buffer. * * @param object * @return String */ private String getString(Object object) { if (object == null) { return ""; } return XmlEscapers.xmlContentEscaper().escape(object.toString()); }