java类javax.xml.stream.events.ProcessingInstruction的实例源码

TocPIParser.java 文件源码 项目:HTMLtoc 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Parses an {@link ProcessingInstruction XML event} of a
 * processing instruction.
 * @param pi the event to parse
 * @return the data from the processing instruction or <code>null</code>
 * if the event is {@link #isIgnoredPI(ProcessingInstruction) ignored}
 * by this parser
 */
public TocPIData parse(ProcessingInstruction pi) throws JAXBException
{
 if (isIgnoredPI(pi))
  return null;
 String rawData = pi.getData();
 rawData = null == rawData ? "" : rawData.trim();
 boolean closing = rawData.endsWith("/");
 if (closing)
  rawData = rawData.substring(0, rawData.length() - 1).trim();
 TocPIData data;
 if (0 < rawData.length())
  data = parseAttrs(rawData);
 else if (closing)
  data = new TocPIData();
 else
  throw new JAXBException("Processing instruction contains no data");
 data.setClosing(closing);
 return data;
}
StAXEvent2SAX.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
StAXEvent2SAX.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
StAXEvent2SAX.java 文件源码 项目:openjdk9 阅读 24 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
XMLEventStreamReader.java 文件源码 项目:spring4-understanding 阅读 29 收藏 0 点赞 0 评论 0
@Override
public String getPITarget() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getTarget();
    }
    else {
        throw new IllegalStateException();
    }
}
XMLEventStreamReader.java 文件源码 项目:spring4-understanding 阅读 34 收藏 0 点赞 0 评论 0
@Override
public String getPIData() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getData();
    }
    else {
        throw new IllegalStateException();
    }
}
XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 27 收藏 0 点赞 0 评论 0
@Override
public String getPITarget() {
    XMLSecEvent xmlSecEvent = getCurrentEvent();
    if (xmlSecEvent.getEventType() != PROCESSING_INSTRUCTION) {
        throw new IllegalStateException(ERR_STATE_NOT_PI);
    }
    return ((ProcessingInstruction) xmlSecEvent).getTarget();
}
XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 23 收藏 0 点赞 0 评论 0
@Override
public String getPIData() {
    XMLSecEvent xmlSecEvent = getCurrentEvent();
    if (xmlSecEvent.getEventType() != PROCESSING_INSTRUCTION) {
        throw new IllegalStateException(ERR_STATE_NOT_PI);
    }
    return ((ProcessingInstruction) xmlSecEvent).getData();
}
StAXEvent2SAX.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 37 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
XMLEventStreamReader.java 文件源码 项目:spring 阅读 23 收藏 0 点赞 0 评论 0
@Override
public String getPITarget() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getTarget();
    }
    else {
        throw new IllegalStateException();
    }
}
XMLEventStreamReader.java 文件源码 项目:spring 阅读 24 收藏 0 点赞 0 评论 0
@Override
public String getPIData() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getData();
    }
    else {
        throw new IllegalStateException();
    }
}
StAXEvent2SAX.java 文件源码 项目:infobip-open-jdk-8 阅读 21 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
XMLEventStreamReader.java 文件源码 项目:teiid 阅读 23 收藏 0 点赞 0 评论 0
public String getPITarget() {
    if (event.isProcessingInstruction()) {
        return ((ProcessingInstruction) event).getTarget();
    }
    else {
        throw new IllegalStateException();
    }
}
XMLEventStreamReader.java 文件源码 项目:teiid 阅读 24 收藏 0 点赞 0 评论 0
public String getPIData() {
    if (event.isProcessingInstruction()) {
        return ((ProcessingInstruction) event).getData();
    }
    else {
        throw new IllegalStateException();
    }
}
XmlStaxParser.java 文件源码 项目:bagri 阅读 24 收藏 0 点赞 0 评论 0
private void processEvent(XmlParserContext ctx, XMLEvent xmlEvent) throws BagriException {

    if (ctx.getDocRoot() == null) {
        ctx.firstEvents.add(xmlEvent);
        if (xmlEvent.getEventType() == XMLStreamConstants.START_ELEMENT) {
            String root = "/" + xmlEvent.asStartElement().getName();
            ctx.addDocument(root);
            for (XMLEvent event: ctx.firstEvents) {
                processEvent(ctx, event);
            }
        }
    } else {
        switch (xmlEvent.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                startElement(ctx, xmlEvent.asStartElement());
                break;
            case XMLStreamConstants.CHARACTERS:
                if (!xmlEvent.asCharacters().isWhiteSpace()) {
                    ctx.addCharacters(xmlEvent.asCharacters().getData());
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                ctx.endElement();
                break;
            case XMLStreamConstants.ATTRIBUTE:
                ctx.addAttribute(((Attribute) xmlEvent).getName(), ((Attribute) xmlEvent).getValue());
                break;
            case XMLStreamConstants.COMMENT:
                ctx.addComment(((Comment) xmlEvent).getText());
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ctx.addProcessingInstruction(((ProcessingInstruction) xmlEvent).getTarget(), ((ProcessingInstruction) xmlEvent).getData());
                break;
            default:
                break;
        }
    }
}
XMLEventStreamReader.java 文件源码 项目:class-guard 阅读 23 收藏 0 点赞 0 评论 0
public String getPITarget() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getTarget();
    }
    else {
        throw new IllegalStateException();
    }
}
XMLEventStreamReader.java 文件源码 项目:class-guard 阅读 28 收藏 0 点赞 0 评论 0
public String getPIData() {
    if (this.event.isProcessingInstruction()) {
        return ((ProcessingInstruction) this.event).getData();
    }
    else {
        throw new IllegalStateException();
    }
}
StAXEvent2SAX.java 文件源码 项目:OLD-OpenJDK8 阅读 20 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
StAXStreamResultBuilder.java 文件源码 项目:SplitCharater 阅读 23 收藏 0 点赞 0 评论 0
public void processingInstruction(ProcessingInstruction event)
        throws XMLStreamException {
    String data = event.getData();
    if (data != null && data.length() > 0) {
        fStreamWriter.writeProcessingInstruction(event.getTarget(), data);
    }
    else {
        fStreamWriter.writeProcessingInstruction(event.getTarget());
    }
}
StAXEvent2SAX.java 文件源码 项目:openjdk-icedtea7 阅读 21 收藏 0 点赞 0 评论 0
private void handlePI(ProcessingInstruction event)
    throws XMLStreamException {
    try {
        _sax.processingInstruction(
            event.getTarget(),
            event.getData());
    } catch (SAXException e) {
        throw new XMLStreamException(e);
    }
}
Transformer.java 文件源码 项目:HTMLtoc 阅读 27 收藏 0 点赞 0 评论 0
@Override
public void add(XMLEvent event) throws XMLStreamException
{
 if (event instanceof ProcessingInstruction)
 {
  if (null == piData)
   piData = parsePIEvent((ProcessingInstruction)event);
 }
 else
  piData = null;
 if (null != piData)
 {
  if (piData.isOpening())
  {
   formatter = TocFormatter.forPI(piData, event.getLocation());
   formatter.setXMLEventFactory(getXMLEventFactory());
  }
  if (piData.isClosing())
   super.add(getXMLEventFactory().createCharacters("\n"));
 }
 else if (state == State.INDEXED)
  index(event);
 else if (state == State.ROOT)
 {
  addDTD((StartElement)event);
  super.add(event);
  state = State.PASSTHROUGH;
 }
}
Transformer.java 文件源码 项目:HTMLtoc 阅读 21 收藏 0 点赞 0 评论 0
protected void trackContext(XMLEvent event)
{
 switch (event.getEventType())
 {
 case START_ELEMENT:
  context.add(0, (StartElement)event);
  break;
 case END_DOCUMENT:
 case END_ELEMENT:
  if (!context.isEmpty())
  {
   StartElement open = context.remove(0);
   EndElement close = event instanceof EndElement ? (EndElement)event : null;
   if (null == close || !open.getName().equals(close.getName()))
    throw new IllegalStateException("Unclosed " + describeEvent(open) + ' '
     + describeLocation(open.getLocation()));
  }
  else
   throw new IllegalStateException("Unclosed " + describeEvent(origin) + ' '
     + describeLocation(origin.getLocation()));
  break;
 case PROCESSING_INSTRUCTION:
  if (!TocPIParser.isIgnoredPI((ProcessingInstruction)event))
   throw new IllegalStateException("Processing instructions <?" + TocPIParser.PI_TARGET
     + "?> are not allowed within the context of " + describeEvent(origin));
  break;
 }
}
Transformer.java 文件源码 项目:HTMLtoc 阅读 22 收藏 0 点赞 0 评论 0
protected TocPIData parsePIEvent(ProcessingInstruction event)
  throws XMLStreamException
{
 try
 {
  return piParser().parse(event);
 }
 catch (JAXBException pierr)
 {
  throw new XMLStreamException("Error parsing " + describeEvent(event),
    event.getLocation(), pierr);
 }
}
Transformer.java 文件源码 项目:HTMLtoc 阅读 20 收藏 0 点赞 0 评论 0
protected TocPIData filterPIEvent(ProcessingInstruction event)
{
 try
 {
  return piParser().parse(event);
 }
 catch (JAXBException pierr)
 {
  throw new IllegalArgumentException("Error parsing " + describeEvent(event), pierr);
 }
}
LoadProcess.java 文件源码 项目:scaleDOM 阅读 21 收藏 0 点赞 0 评论 0
private void processProcessingInstruction(final ProcessingInstruction processingInstruction,
        final NodeLocation location) {
    // Create and append ProcessingInstruction node
    final org.w3c.dom.ProcessingInstruction processingInstructionNode = doc.createProcessingInstruction(
            processingInstruction.getTarget(), processingInstruction.getData());
    state.getCurrentParentNode().appendChild(processingInstructionNode);
    state.createdNode();
}
StAXSchemaParser.java 文件源码 项目:OpenJSharp 阅读 18 收藏 0 点赞 0 评论 0
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
StAXSchemaParser.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
XMLEventFactoryImpl.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
@Override
public ProcessingInstruction createProcessingInstruction(String target, String data) {
    ProcessingInstructionEvent event =  new ProcessingInstructionEvent(target, data);
    if(location != null)event.setLocation(location);
    return event;
}
Issue41Test.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testEvents() {
    XMLEventFactory f = XMLEventFactory.newInstance();
    final String contents = "test <some> text & more! [[]] --";
    final String prefix = "prefix";
    final String uri = "http://foo";
    final String localName = "elem";

    try {
        StartDocument sd = f.createStartDocument();
        writeAsEncodedUnicode(sd);

        Comment c = f.createComment("some comments");
        writeAsEncodedUnicode(c);

        StartElement se = f.createStartElement(prefix, uri, localName);

        ProcessingInstruction pi = f.createProcessingInstruction("target", "data");
        writeAsEncodedUnicode(pi);

        Namespace ns = f.createNamespace(prefix, uri);
        writeAsEncodedUnicode(ns);

        Characters characters = f.createCharacters(contents);
        writeAsEncodedUnicode(characters);
        // CData
        Characters cdata = f.createCData(contents);
        writeAsEncodedUnicode(cdata);

        // Attribute
        QName attrName = new QName("http://test.com", "attr", "ns");
        Attribute attr = f.createAttribute(attrName, "value");
        writeAsEncodedUnicode(attr);

        // prefix, uri, localName
        EndElement ee = f.createEndElement(prefix, uri, localName);
        writeAsEncodedUnicode(ee);

        EndDocument ed = f.createEndDocument();
        writeAsEncodedUnicode(ed);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }

}
XMLEventFactoryWrapper.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
@Override
public ProcessingInstruction createProcessingInstruction(String target, String data) {
    return defaultImpl.createProcessingInstruction(target, data);
}


问题


面经


文章

微信
公众号

扫码关注公众号