Java Code Examples for com.sun.xml.internal.stream.Entity#ScannedEntity

The following examples show how to use com.sun.xml.internal.stream.Entity#ScannedEntity . 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: XMLEntityManager.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the line number where the current document event ends.
 * <p>
 * <strong>Warning:</strong> The return value from the method
 * is intended only as an approximation for the sake of error
 * reporting; it is not intended to provide sufficient information
 * to edit the character content of the original XML document.
 * <p>
 * The return value is an approximation of the line number
 * in the document entity or external parsed entity where the
 * markup triggering the event appears.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.  The first line in the document is line 1.
 *
 * @return The line number, or -1 if none is available.
 */
public int getLineNumber() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.isExternal()) {
            return fCurrentEntity.lineNumber;
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i=size-1; i>0 ; i--) {
                Entity.ScannedEntity firstExternalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (firstExternalEntity.isExternal()) {
                    return firstExternalEntity.lineNumber;
                }
            }
        }
    }

    return -1;

}
 
Example 2
Source File: XMLEntityManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the literal system identifier for the current document event.
 * <p>
 * The return value is the literal system identifier of the document
 * entity or of the external parsed entity in which the markup
 * triggering the event appears.
 * <p>
 * @return A string containing the literal system identifier, or null
 *         if none is available.
 */
public String getLiteralSystemId() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.entityLocation != null &&
                fCurrentEntity.entityLocation.getLiteralSystemId() != null ) {
            return fCurrentEntity.entityLocation.getLiteralSystemId();
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i = size - 1; i >= 0 ; i--) {
                Entity.ScannedEntity externalEntity =
                        (Entity.ScannedEntity)fEntityStack.elementAt(i);

                if (externalEntity.entityLocation != null &&
                        externalEntity.entityLocation.getLiteralSystemId() != null) {
                    return externalEntity.entityLocation.getLiteralSystemId();
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: XMLEntityManager.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the line number where the current document event ends.
 * <p>
 * <strong>Warning:</strong> The return value from the method
 * is intended only as an approximation for the sake of error
 * reporting; it is not intended to provide sufficient information
 * to edit the character content of the original XML document.
 * <p>
 * The return value is an approximation of the line number
 * in the document entity or external parsed entity where the
 * markup triggering the event appears.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.  The first line in the document is line 1.
 *
 * @return The line number, or -1 if none is available.
 */
public int getLineNumber() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.isExternal()) {
            return fCurrentEntity.lineNumber;
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i=size-1; i>0 ; i--) {
                Entity.ScannedEntity firstExternalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (firstExternalEntity.isExternal()) {
                    return firstExternalEntity.lineNumber;
                }
            }
        }
    }

    return -1;

}
 
Example 4
Source File: XMLEntityManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the line number where the current document event ends.
 * <p>
 * <strong>Warning:</strong> The return value from the method
 * is intended only as an approximation for the sake of error
 * reporting; it is not intended to provide sufficient information
 * to edit the character content of the original XML document.
 * <p>
 * The return value is an approximation of the line number
 * in the document entity or external parsed entity where the
 * markup triggering the event appears.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.  The first line in the document is line 1.
 *
 * @return The line number, or -1 if none is available.
 */
public int getLineNumber() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.isExternal()) {
            return fCurrentEntity.lineNumber;
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i=size-1; i>0 ; i--) {
                Entity.ScannedEntity firstExternalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (firstExternalEntity.isExternal()) {
                    return firstExternalEntity.lineNumber;
                }
            }
        }
    }

    return -1;

}
 
Example 5
Source File: XMLEntityManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the line number where the current document event ends.
 * <p>
 * <strong>Warning:</strong> The return value from the method
 * is intended only as an approximation for the sake of error
 * reporting; it is not intended to provide sufficient information
 * to edit the character content of the original XML document.
 * <p>
 * The return value is an approximation of the line number
 * in the document entity or external parsed entity where the
 * markup triggering the event appears.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.  The first line in the document is line 1.
 *
 * @return The line number, or -1 if none is available.
 */
public int getLineNumber() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.isExternal()) {
            return fCurrentEntity.lineNumber;
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i=size-1; i>0 ; i--) {
                Entity.ScannedEntity firstExternalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (firstExternalEntity.isExternal()) {
                    return firstExternalEntity.lineNumber;
                }
            }
        }
    }

    return -1;

}
 
Example 6
Source File: XMLEntityManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds an external entity declaration.
 * <p>
 * <strong>Note:</strong> This method ignores subsequent entity
 * declarations.
 * <p>
 * <strong>Note:</strong> The name should be a unique symbol. The
 * SymbolTable can be used for this purpose.
 *
 * @param name         The name of the entity.
 * @param publicId     The public identifier of the entity.
 * @param literalSystemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the entity
 *                     where <em>the entity being added</em> and
 *                     is used to expand the system identifier when
 *                     the system identifier is a relative URI.
 *                     When null the system identifier of the first
 *                     external entity on the stack is used instead.
 *
 * @see SymbolTable
 */
public void addExternalEntity(String name,
        String publicId, String literalSystemId,
        String baseSystemId) throws IOException {
    if (!fEntities.containsKey(name)) {
        if (baseSystemId == null) {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            if (size == 0 && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
                baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
            }
            for (int i = size - 1; i >= 0 ; i--) {
                Entity.ScannedEntity externalEntity =
                        (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (externalEntity.entityLocation != null && externalEntity.entityLocation.getExpandedSystemId() != null) {
                    baseSystemId = externalEntity.entityLocation.getExpandedSystemId();
                    break;
                }
            }
        }
        Entity entity = new Entity.ExternalEntity(name,
                new XMLEntityDescriptionImpl(name, publicId, literalSystemId, baseSystemId,
                expandSystemId(literalSystemId, baseSystemId, false)), null, fInExternalSubset);
        fEntities.put(name, entity);
    } else{
        if(fWarnDuplicateEntityDef){
            fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                    "MSG_DUPLICATE_ENTITY_DEFINITION",
                    new Object[]{ name },
                    XMLErrorReporter.SEVERITY_WARNING );
        }
    }

}
 
Example 7
Source File: XMLEntityScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example 8
Source File: XMLEntityScanner.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}
 
Example 9
Source File: XMLEntityScanner.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example 10
Source File: XMLDocumentScannerImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * receives callbacks from {@link XMLEntityReader } when buffer
 * is being changed.
 * @param refreshPosition
 */
public void refresh(int refreshPosition){
    super.refresh(refreshPosition);
    if(fReadingDTD){
        Entity entity = fEntityScanner.getCurrentEntity();
        if(entity instanceof Entity.ScannedEntity){
            fEndPos=((Entity.ScannedEntity)entity).position;
        }
        fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
        fStartPos = refreshPosition;
    }
}
 
Example 11
Source File: XMLDocumentScannerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * receives callbacks from {@link XMLEntityReader } when buffer
 * is being changed.
 * @param refreshPosition
 */
public void refresh(int refreshPosition){
    super.refresh(refreshPosition);
    if(fReadingDTD){
        Entity entity = fEntityScanner.getCurrentEntity();
        if(entity instanceof Entity.ScannedEntity){
            fEndPos=((Entity.ScannedEntity)entity).position;
        }
        fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
        fStartPos = refreshPosition;
    }
}
 
Example 12
Source File: XMLEntityScanner.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}
 
Example 13
Source File: XMLEntityScanner.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example 14
Source File: XMLEntityManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the column number where the current document event ends.
 * <p>
 * <strong>Warning:</strong> The return value from the method
 * is intended only as an approximation for the sake of error
 * reporting; it is not intended to provide sufficient information
 * to edit the character content of the original XML document.
 * <p>
 * The return value is an approximation of the column number
 * in the document entity or external parsed entity where the
 * markup triggering the event appears.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.
 * <p>
 * If possible, the SAX driver should provide the line position
 * of the first character after the text associated with the document
 * event.  The first column in each line is column 1.
 *
 * @return The column number, or -1 if none is available.
 */
public int getColumnNumber() {
    if (fCurrentEntity != null) {
        if (fCurrentEntity.isExternal()) {
            return fCurrentEntity.columnNumber;
        } else {
            // search for the first external entity on the stack
            int size = fEntityStack.size();
            for (int i=size-1; i>0 ; i--) {
                Entity.ScannedEntity firstExternalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i);
                if (firstExternalEntity.isExternal()) {
                    return firstExternalEntity.columnNumber;
                }
            }
        }
    }

    return -1;
}
 
Example 15
Source File: XMLEntityManager.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void endEntity() throws IOException, XNIException {

        // call handler
        if (DEBUG_BUFFER) {
            System.out.print("(endEntity: ");
            print();
            System.out.println();
        }
        //pop the entity from the stack
        Entity.ScannedEntity entity = fEntityStack.size() > 0 ? (Entity.ScannedEntity)fEntityStack.pop() : null ;

        /** need to close the reader first since the program can end
         *  prematurely (e.g. fEntityHandler.endEntity may throw exception)
         *  leaving the reader open
         */
        //close the reader
        if(fCurrentEntity != null){
            //close the reader
            try{
                if (fLimitAnalyzer != null) {
                    fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT, fCurrentEntity.name);
                    if (fCurrentEntity.name.equals("[xml]")) {
                        fSecurityManager.debugPrint(fLimitAnalyzer);
                    }
                }
                fCurrentEntity.close();
            }catch(IOException ex){
                throw new XNIException(ex);
            }
        }

        // REVISIT: We should never encounter underflow if the calls
        // to startEntity and endEntity are balanced, but guard
        // against the EmptyStackException for now. -- mrglavas
        if (!fReaderStack.isEmpty()) {
            fReaderStack.pop();
        }

        if (fEntityHandler != null) {
            //so this is the last opened entity, signal it to current fEntityHandler using Augmentation
            if(entity == null){
                fEntityAugs.removeAllItems();
                fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);
                fEntityHandler.endEntity(fCurrentEntity.name, fEntityAugs);
                fEntityAugs.removeAllItems();
            }else{
                fEntityHandler.endEntity(fCurrentEntity.name, null);
            }
        }
        //check if it is a document entity
        boolean documentEntity = fCurrentEntity.name == XMLEntity;

        //set popped entity as current entity
        fCurrentEntity = entity;
        fEntityScanner.setCurrentEntity(fCurrentEntity);

        //check if there are any entity left in the stack -- if there are
        //no entries EOF has been reached.
        // throw exception when it is the last entity but it is not a document entity

        if(fCurrentEntity == null & !documentEntity){
            throw new EOFException() ;
        }

        if (DEBUG_BUFFER) {
            System.out.print(")endEntity: ");
            print();
            System.out.println();
        }

    }
 
Example 16
Source File: XMLEntityManager.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void endEntity() throws IOException, XNIException {

        // call handler
        if (DEBUG_BUFFER) {
            System.out.print("(endEntity: ");
            print();
            System.out.println();
        }
        //pop the entity from the stack
        Entity.ScannedEntity entity = fEntityStack.size() > 0 ? (Entity.ScannedEntity)fEntityStack.pop() : null ;

        /** need to close the reader first since the program can end
         *  prematurely (e.g. fEntityHandler.endEntity may throw exception)
         *  leaving the reader open
         */
        //close the reader
        if(fCurrentEntity != null){
            //close the reader
            try{
                if (fLimitAnalyzer != null) {
                    fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT, fCurrentEntity.name);
                    if (fCurrentEntity.name.equals("[xml]")) {
                        fSecurityManager.debugPrint(fLimitAnalyzer);
                    }
                }
                fCurrentEntity.close();
            }catch(IOException ex){
                throw new XNIException(ex);
            }
        }

        if (fEntityHandler != null) {
            //so this is the last opened entity, signal it to current fEntityHandler using Augmentation
            if(entity == null){
                fEntityAugs.removeAllItems();
                fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);
                fEntityHandler.endEntity(fCurrentEntity.name, fEntityAugs);
                fEntityAugs.removeAllItems();
            }else{
                fEntityHandler.endEntity(fCurrentEntity.name, null);
            }
        }
        //check if it is a document entity
        boolean documentEntity = fCurrentEntity.name == XMLEntity;

        //set popped entity as current entity
        fCurrentEntity = entity;
        fEntityScanner.setCurrentEntity(fCurrentEntity);

        //check if there are any entity left in the stack -- if there are
        //no entries EOF has been reached.
        // throw exception when it is the last entity but it is not a document entity

        if(fCurrentEntity == null & !documentEntity){
            throw new EOFException() ;
        }

        if (DEBUG_BUFFER) {
            System.out.print(")endEntity: ");
            print();
            System.out.println();
        }

    }
 
Example 17
Source File: XMLEntityManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the top level entity handled by this manager, or null
 * if no entity was added.
 */
public Entity.ScannedEntity getTopLevelEntity() {
    return (Entity.ScannedEntity)
        (fEntityStack.empty() ? null : fEntityStack.elementAt(0));
}
 
Example 18
Source File: XMLEntityScanner.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public  Entity.ScannedEntity getCurrentEntity(){
    return fCurrentEntity ;
}
 
Example 19
Source File: XMLEntityManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the top level entity handled by this manager, or null
 * if no entity was added.
 */
public Entity.ScannedEntity getTopLevelEntity() {
    return (Entity.ScannedEntity)
        (fEntityStack.empty() ? null : fEntityStack.elementAt(0));
}
 
Example 20
Source File: XMLEntityManager.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the current entity being scanned. Current entity is SET using startEntity function.
 * @return Entity.ScannedEntity
 */

public Entity.ScannedEntity getCurrentEntity(){
    return fCurrentEntity ;
}