gpt4 book ai didi

org.eclipse.core.runtime.content.XMLContentDescriber类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 09:48:40 27 4
gpt4 key购买 nike

本文整理了Java中org.eclipse.core.runtime.content.XMLContentDescriber类的一些代码示例,展示了XMLContentDescriber类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLContentDescriber类的具体详情如下:
包路径:org.eclipse.core.runtime.content.XMLContentDescriber
类名称:XMLContentDescriber

XMLContentDescriber介绍

[英]A content describer for XML files. This class provides basis for XML-based content describers.

The document is detected by the describer as VALID, if it contains an xml declaration with <?xml prefix and the encoding in the declaration is correct.

Below are sample declarations recognized by the describer as VALID

  • <?xml version="1.0"?>

  • <?xml version="1.0"

  • <?xml version="1.0" encoding="utf-16"?>

  • <?xml version="1.0" encoding="utf-16?>

[中]XML文件的内容描述符。此类为基于XML的内容描述符提供了基础。
如果文档包含带有<?xml前缀的xml声明,且声明中的编码正确,则描述符会将该文档检测为VALID
以下是描述者认可为VALID的声明示例

  • <?xml version=“1.0”>

  • <?xml version=“1.0”

  • <?xml version=“1.0”encoding=“utf-16”>

  • <?xml version=“1.0”encoding=“utf-16”>

代码示例

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.contenttype

int describe2(Reader input, IContentDescription description, Map<String, Object> properties) throws IOException {
  if (!isProcessed(properties))
    fillContentProperties(readXMLDecl(input), description, properties);
  return internalDescribe(description, properties);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.core.contenttype

@Override
public int describe(Reader input, IContentDescription description) throws IOException {
  return describe2(input, description, new HashMap<String, Object>());
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.core.contenttype

int describe2(InputStream input, IContentDescription description, Map<String, Object> properties) throws IOException {
  if (!isProcessed(properties))
    fillContentProperties(input, description, properties);
  return internalDescribe(description, properties);
}

代码示例来源:origin: org.eclipse/core-contenttype

public int describe(Reader input, IContentDescription description) throws IOException {
  return internalDescribe(readXMLDecl(input), description);
}

代码示例来源:origin: org.eclipse.core/contenttype

private void fillContentProperties(InputStream input, IContentDescription description, Map properties) throws IOException {
  byte[] bom = Util.getByteOrderMark(input);
  String xmlDeclEncoding = "UTF-8"; //$NON-NLS-1$
  input.reset();
  if (bom != null) {
    if (bom == IContentDescription.BOM_UTF_16BE)
      xmlDeclEncoding = "UTF-16BE"; //$NON-NLS-1$
    else if (bom == IContentDescription.BOM_UTF_16LE)
      xmlDeclEncoding = "UTF-16LE"; //$NON-NLS-1$
    // skip BOM to make comparison simpler
    input.skip(bom.length);
    properties.put(BOM, bom);
  }
  fillContentProperties(readXMLDecl(input, xmlDeclEncoding), description, properties);
}

代码示例来源:origin: org.eclipse.core/contenttype

private int internalDescribe(IContentDescription description, Map properties) {
  if (description != null) {
    byte[] bom = (byte[]) properties.get(BOM);
    if (bom != null && description.isRequested(IContentDescription.BYTE_ORDER_MARK))
      description.setProperty(IContentDescription.BYTE_ORDER_MARK, bom);
  }
  Boolean fullXMLDecl = (Boolean) properties.get(FULL_XML_DECL);
  if (fullXMLDecl == null || !fullXMLDecl.booleanValue())
    return INDETERMINATE;
  if (description == null)
    return VALID;
  String charset = (String) properties.get(CHARSET);
  if (description.isRequested(IContentDescription.CHARSET)) {
    if (charset != null && !isCharsetValid(charset))
      return INVALID;
    if (isNonDefaultCharset(charset))
      description.setProperty(IContentDescription.CHARSET, charset);
  }
  return VALID;
}

代码示例来源:origin: org.eclipse.core/contenttype

private String getCharset(String firstLine) {
  int encodingPos = findEncodingPosition(firstLine);
  if (encodingPos == -1)
    return null;
  char quoteChar = '"';
  int firstQuote = firstLine.indexOf('"', encodingPos);
  int firstApostrophe = firstLine.indexOf('\'', encodingPos);
  //use apostrophe if there is no quote, or an apostrophe comes first
  if (firstQuote == -1 || (firstApostrophe != -1 && firstApostrophe < firstQuote)) {
    quoteChar = '\'';
    firstQuote = firstApostrophe;
  }
  if (firstQuote == -1 || firstLine.length() == firstQuote + 1)
    return null;
  int secondQuote = firstLine.indexOf(quoteChar, firstQuote + 1);
  if (secondQuote == -1)
    return isFullXMLDecl(firstLine) ? firstLine.substring(firstQuote + 1, firstLine.lastIndexOf(XML_DECL_END)).trim() : null;
  return firstLine.substring(firstQuote + 1, secondQuote);
}

代码示例来源:origin: org.eclipse/core-contenttype

private int internalDescribe(String line, IContentDescription description) throws IOException {
  // end of stream
  if (line == null)
    return INDETERMINATE;
  // XMLDecl should be the first string (no blanks allowed)
  if (!line.startsWith(XML_PREFIX))
    return INDETERMINATE;
  if (description == null)
    return VALID;
  // describe charset if requested
  if ((description.isRequested(IContentDescription.CHARSET))) {
    String charset = getCharset(line);
    if (charset != null && !isCharsetValid(charset))
      return INVALID;
    if (charset != null && !charset.equalsIgnoreCase("utf8") && !charset.equalsIgnoreCase("utf-8")) //$NON-NLS-1$ //$NON-NLS-2$
      // only set property if value is not default (avoid using a non-default content description)
      description.setProperty(IContentDescription.CHARSET, charset);
  }
  return VALID;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.contenttype

private void fillContentProperties(String line, IContentDescription description, Map<String, Object> properties) throws IOException {
  // XMLDecl should be the first string (no blanks allowed)
  if (line != null && line.startsWith(XML_PREFIX))
    properties.put(FULL_XML_DECL, Boolean.TRUE);
  String charset = getCharset(line);
  if (charset != null)
    properties.put(CHARSET, charset);
  properties.put(RESULT, Boolean.TRUE);
}

代码示例来源:origin: org.eclipse/core-contenttype

private String getCharset(String firstLine) {
  int encodingPos = firstLine.indexOf(ENCODING);
  if (encodingPos == -1)
    return null;
  char quoteChar = '"';
  int firstQuote = firstLine.indexOf(quoteChar, encodingPos);
  if (firstQuote == -1) {
    quoteChar = '\'';
    firstQuote = firstLine.indexOf(quoteChar, encodingPos);
  }
  if (firstQuote == -1 || firstLine.length() == firstQuote - 1)
    return null;
  int secondQuote = firstLine.indexOf(quoteChar, firstQuote + 1);
  if (secondQuote == -1)
    return isFullXMLDecl(firstLine) ? firstLine.substring(firstQuote + 1, firstLine.lastIndexOf(XML_DECL_END)).trim() : null;
  return firstLine.substring(firstQuote + 1, secondQuote);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.contenttype

int describe2(InputStream input, IContentDescription description, Map<String, Object> properties) throws IOException {
  if (!isProcessed(properties))
    fillContentProperties(input, description, properties);
  return internalDescribe(description, properties);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.core.contenttype

private void fillContentProperties(InputStream input, IContentDescription description, Map<String, Object> properties) throws IOException {
  byte[] bom = Util.getByteOrderMark(input);
  String xmlDeclEncoding = "UTF-8"; //$NON-NLS-1$
  input.reset();
  if (bom != null) {
    if (bom == IContentDescription.BOM_UTF_16BE)
      xmlDeclEncoding = "UTF-16BE"; //$NON-NLS-1$
    else if (bom == IContentDescription.BOM_UTF_16LE)
      xmlDeclEncoding = "UTF-16LE"; //$NON-NLS-1$
    // skip BOM to make comparison simpler
    input.skip(bom.length);
    properties.put(BOM, bom);
  }
  fillContentProperties(readXMLDecl(input, xmlDeclEncoding), description, properties);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.contenttype

private int internalDescribe(IContentDescription description, Map<String, Object> properties) {
  if (description != null) {
    byte[] bom = (byte[]) properties.get(BOM);
    if (bom != null && description.isRequested(IContentDescription.BYTE_ORDER_MARK))
      description.setProperty(IContentDescription.BYTE_ORDER_MARK, bom);
  }
  Boolean fullXMLDecl = (Boolean) properties.get(FULL_XML_DECL);
  if (fullXMLDecl == null || !fullXMLDecl.booleanValue())
    return INDETERMINATE;
  if (description == null)
    return VALID;
  String charset = (String) properties.get(CHARSET);
  if (description.isRequested(IContentDescription.CHARSET)) {
    if (charset != null && !isCharsetValid(charset))
      return INVALID;
    if (isNonDefaultCharset(charset))
      description.setProperty(IContentDescription.CHARSET, charset);
  }
  return VALID;
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.contenttype

private String getCharset(String firstLine) {
  int encodingPos = findEncodingPosition(firstLine);
  if (encodingPos == -1)
    return null;
  char quoteChar = '"';
  int firstQuote = firstLine.indexOf('"', encodingPos);
  int firstApostrophe = firstLine.indexOf('\'', encodingPos);
  //use apostrophe if there is no quote, or an apostrophe comes first
  if (firstQuote == -1 || (firstApostrophe != -1 && firstApostrophe < firstQuote)) {
    quoteChar = '\'';
    firstQuote = firstApostrophe;
  }
  if (firstQuote == -1 || firstLine.length() == firstQuote + 1)
    return null;
  int secondQuote = firstLine.indexOf(quoteChar, firstQuote + 1);
  if (secondQuote == -1)
    return isFullXMLDecl(firstLine) ? firstLine.substring(firstQuote + 1, firstLine.lastIndexOf(XML_DECL_END)).trim() : null;
  return firstLine.substring(firstQuote + 1, secondQuote);
}

代码示例来源:origin: org.eclipse/core-contenttype

public int describe(InputStream input, IContentDescription description) throws IOException {
  byte[] bom = Util.getByteOrderMark(input);
  String xmlDeclEncoding = "UTF-8"; //$NON-NLS-1$
  input.reset();
  if (bom != null) {
    if (bom == IContentDescription.BOM_UTF_16BE)
      xmlDeclEncoding = "UTF-16BE"; //$NON-NLS-1$
    else if (bom == IContentDescription.BOM_UTF_16LE)
      xmlDeclEncoding = "UTF-16LE"; //$NON-NLS-1$
    // skip BOM to make comparison simpler
    input.skip(bom.length);
    // set the BOM in the description if requested
    if (description != null && description.isRequested(IContentDescription.BYTE_ORDER_MARK))
      description.setProperty(IContentDescription.BYTE_ORDER_MARK, bom);
  }
  return internalDescribe(readXMLDecl(input, xmlDeclEncoding), description);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.core.contenttype

private void fillContentProperties(String line, IContentDescription description, Map<String, Object> properties) throws IOException {
  // XMLDecl should be the first string (no blanks allowed)
  if (line != null && line.startsWith(XML_PREFIX))
    properties.put(FULL_XML_DECL, Boolean.TRUE);
  String charset = getCharset(line);
  if (charset != null)
    properties.put(CHARSET, charset);
  properties.put(RESULT, Boolean.TRUE);
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.contenttype

int describe2(Reader input, IContentDescription description, Map properties) throws IOException {
  if (!isProcessed(properties))
    fillContentProperties(readXMLDecl(input), description, properties);
  return internalDescribe(description, properties);
}

代码示例来源:origin: org.eclipse.core/contenttype

int describe2(InputStream input, IContentDescription description, Map properties) throws IOException {
  if (!isProcessed(properties))
    fillContentProperties(input, description, properties);
  return internalDescribe(description, properties);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.core.contenttype

@Override
public int describe(InputStream input, IContentDescription description) throws IOException {
  return describe2(input, description, new HashMap<String, Object>());
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.contenttype

private void fillContentProperties(InputStream input, IContentDescription description, Map<String, Object> properties) throws IOException {
  byte[] bom = Util.getByteOrderMark(input);
  String xmlDeclEncoding = "UTF-8"; //$NON-NLS-1$
  input.reset();
  if (bom != null) {
    if (bom == IContentDescription.BOM_UTF_16BE)
      xmlDeclEncoding = "UTF-16BE"; //$NON-NLS-1$
    else if (bom == IContentDescription.BOM_UTF_16LE)
      xmlDeclEncoding = "UTF-16LE"; //$NON-NLS-1$
    // skip BOM to make comparison simpler
    input.skip(bom.length);
    properties.put(BOM, bom);
  }
  fillContentProperties(readXMLDecl(input, xmlDeclEncoding), description, properties);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com