当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamReader.getLocation方法代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamReader.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.getLocation方法的具体用法?Java XMLStreamReader.getLocation怎么用?Java XMLStreamReader.getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.stream.XMLStreamReader的用法示例。


在下文中一共展示了XMLStreamReader.getLocation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFeatureMap

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Processes a GateDocumentFeatures or Annotation element to build a
 * feature map. The element is expected to contain Feature children,
 * each with a Name and Value. The reader will be returned positioned
 * on the closing GateDocumentFeatures or Annotation tag.
 * 
 * @throws XMLStreamException
 */
public static FeatureMap readFeatureMap(XMLStreamReader xsr)
        throws XMLStreamException {
  FeatureMap fm = Factory.newFeatureMap();
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "Feature");
    Object featureName = null;
    Object featureValue = null;
    while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
      if("Name".equals(xsr.getLocalName())) {
        featureName = readFeatureNameOrValue(xsr);
      }
      else if("Value".equals(xsr.getLocalName())) {
        featureValue = readFeatureNameOrValue(xsr);
      }
      else {
        throw new XMLStreamException("Feature element should contain "
                + "only Name and Value children", xsr.getLocation());
      }
    }
    fm.put(featureName, featureValue);
  }
  return fm;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:32,代码来源:DocumentStaxUtils.java

示例2: nextTagSkipDTD

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * A copy of the nextTag algorithm from the XMLStreamReader javadocs,
 * but which also skips over DTD events as well as whitespace,
 * comments and PIs.
 * 
 * @param xsr the reader to advance
 * @return {@link XMLStreamConstants#START_ELEMENT} or
 *         {@link XMLStreamConstants#END_ELEMENT} for the next tag.
 * @throws XMLStreamException
 */
private static int nextTagSkipDTD(XMLStreamReader xsr)
        throws XMLStreamException {
  int eventType = xsr.next();
  while((eventType == XMLStreamConstants.CHARACTERS && xsr.isWhiteSpace())
          || (eventType == XMLStreamConstants.CDATA && xsr.isWhiteSpace())
          || eventType == XMLStreamConstants.SPACE
          || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
          || eventType == XMLStreamConstants.COMMENT
          || eventType == XMLStreamConstants.DTD) {
    eventType = xsr.next();
  }
  if(eventType != XMLStreamConstants.START_ELEMENT
          && eventType != XMLStreamConstants.END_ELEMENT) {
    throw new XMLStreamException("expected start or end tag", xsr
            .getLocation());
  }
  return eventType;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:29,代码来源:DocumentStaxUtils.java

示例3: toLocation

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private static Locator toLocation(XMLStreamReader xsr) {
    LocatorImpl loc = new LocatorImpl();
    Location in = xsr.getLocation();
    loc.setSystemId(in.getSystemId());
    loc.setPublicId(in.getPublicId());
    loc.setLineNumber(in.getLineNumber());
    loc.setColumnNumber(in.getColumnNumber());
    return loc;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:LocatableWebServiceException.java

示例4: getLocator

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private Locator getLocator(XMLStreamReader reader) {
    Location location = reader.getLocation();
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(location.getSystemId());
        loc.setLineNumber(location.getLineNumber());
    return loc;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:WSDLParserExtensionFacade.java

示例5: readRelationSet

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void readRelationSet(XMLStreamReader xsr,
        RelationSet relations, Set<Integer> allAnnotIds)
        throws XMLStreamException {
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "Relation");
    String type = xsr.getAttributeValue(null, "Type");
    String idString = xsr.getAttributeValue(null, "Id");
    String memberString = xsr.getAttributeValue(null, "Members");
    
    if(memberString == null)
      throw new XMLStreamException("A relation must have members");
    if (type == null)
      throw new XMLStreamException("A relation must have a type");
    if (idString == null)
      throw new XMLStreamException("A relation must have an id");
    
    String[] memberStrings = memberString.split(";");
    int[] members = new int[memberStrings.length];
    for(int i = 0; i < members.length; ++i) {
      members[i] = Integer.parseInt(memberStrings[i]);
    }

    xsr.nextTag();
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "UserData");

    // get the string representation of the user data
    StringBuilder stringRep = new StringBuilder(1024);
    int eventType;
    while((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
      switch(eventType) {
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.CDATA:
          stringRep.append(xsr.getTextCharacters(), xsr.getTextStart(),
                  xsr.getTextLength());
          break;

        case XMLStreamConstants.START_ELEMENT:
          throw new XMLStreamException("Elements not allowed within "
                  + "user data.", xsr.getLocation());

        default:
          // do nothing - ignore comments, PIs, etc.
      }
    }

    xsr.require(XMLStreamConstants.END_ELEMENT, null, "UserData");

    FeatureMap features = readFeatureMap(xsr);

    Relation r = new SimpleRelation(Integer.parseInt(idString), type, members);
    r.setFeatures(features);

    if(stringRep.length() > 0) {
      ObjectWrapper wrapper = new ObjectWrapper(stringRep.toString());
      r.setUserData(wrapper.getValue());
    }

    relations.add(r);
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:61,代码来源:DocumentStaxUtils.java

示例6: readTextWithNodes

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
 * Processes the TextWithNodes element from this XMLStreamReader,
 * returning the text content of the document. The supplied map is
 * updated with the offset of each Node element encountered. The
 * reader must be positioned on the starting TextWithNodes tag and
 * will be returned positioned on the corresponding closing tag.
 * 
 * @param xsr
 * @param nodeIdToOffsetMap
 * @return the text content of the document
 */
public static String readTextWithNodes(XMLStreamReader xsr,
        Map<Integer, Long> nodeIdToOffsetMap) throws XMLStreamException {
  StringBuffer textBuf = new StringBuffer(20480);
  int eventType;
  while((eventType = xsr.next()) != XMLStreamConstants.END_ELEMENT) {
    switch(eventType) {
      case XMLStreamConstants.CHARACTERS:
      case XMLStreamConstants.CDATA:
        textBuf.append(xsr.getTextCharacters(), xsr.getTextStart(), xsr
                .getTextLength());
        break;

      case XMLStreamConstants.START_ELEMENT:
        // only Node elements allowed
        xsr.require(XMLStreamConstants.START_ELEMENT, null, "Node");
        String idString = xsr.getAttributeValue(null, "id");
        if(idString == null) {
          throw new XMLStreamException("Node element has no id", xsr
                  .getLocation());
        }
        try {
          Integer id = Integer.valueOf(idString);
          Long offset = Long.valueOf(textBuf.length());
          nodeIdToOffsetMap.put(id, offset);
        }
        catch(NumberFormatException nfe) {
          throw new XMLStreamException("Node element must have "
                  + "integer id", xsr.getLocation());
        }

        // Node element must be empty
        if(xsr.next() != XMLStreamConstants.END_ELEMENT) {
          throw new XMLStreamException("Node element within TextWithNodes "
                  + "must be empty.", xsr.getLocation());
        }
        break;

      default:
        // do nothing - ignore comments, PIs...
    }
  }
  return textBuf.toString();
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:55,代码来源:DocumentStaxUtils.java

示例7: AbstractObjectImpl

import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
AbstractObjectImpl(XMLStreamReader xsr) {
    Location loc = xsr.getLocation();
    this.lineNumber = loc.getLineNumber();
    this.systemId = loc.getSystemId();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:AbstractObjectImpl.java


注:本文中的javax.xml.stream.XMLStreamReader.getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。