org.apache.xerces.xni.Augmentations Java Examples

The following examples show how to use org.apache.xerces.xni.Augmentations. 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: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 6 votes vote down vote up
/** Doctype declaration. */
public void doctypeDecl(String rootElementName, String publicId, String systemId,
                        Augmentations augs) throws XNIException {
    fSeenAnything = true;
    if (fReportErrors) {
        if (fSeenRootElement) {
            fErrorReporter.reportError("HTML2010", null);
        }
        else if (fSeenDoctype) {
            fErrorReporter.reportError("HTML2011", null);
        }
    }
    if (!fSeenRootElement && !fSeenDoctype) {
        fSeenDoctype = true;
        if (fDocumentHandler != null) {
            fDocumentHandler.doctypeDecl(rootElementName, publicId, systemId, augs);
        }
    }
}
 
Example #2
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException {
	if (XMLModelConstants.XML_MODEL_PI.equals(target)) {
		XMLModelDeclaration model = XMLModelDeclaration.parse(data);
		XMLModelValidator validator = createValidator(model);
		if (validator != null) {
			validator.reset(configuration);
			validator.setHref(model.getHref());
			if (xmlModelValidators == null) {
				xmlModelValidators = new ArrayList<>();
			}
			xmlModelValidators.add(validator);
		}
	}

	if (documentHandler != null) {
		documentHandler.processingInstruction(target, data, augs);
	}
}
 
Example #3
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 6 votes vote down vote up
/** Text declaration. */
public void textDecl(String version, String encoding, Augmentations augs)
    throws XNIException {
    fSeenAnything = true;
    
    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.textDecl(version, encoding, augs);
    }

}
 
Example #4
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 6 votes vote down vote up
/** Start CDATA section. */
public void startCDATA(Augmentations augs) throws XNIException {
    fSeenAnything = true;
    
    consumeEarlyTextIfNeeded();

    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.startCDATA(augs);
    }

}
 
Example #5
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void ignoredEndElement(final QName element, final Augmentations augs) {
    // if real </form> is reached, don't accept fields anymore as lost children
    if ("form".equals(element.localpart)) {
        formWaitingForLostChildren_ = null;
    }
}
 
Example #6
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Start document. */
public void startDocument(XMLLocator locator, String encoding, 
                          NamespaceContext nscontext, Augmentations augs) 
    throws XNIException {

    // reset state
    fElementStack.top = 0;
    if (fragmentContextStack_ != null) {
    	fragmentContextStackSize_ = fragmentContextStack_.length;
    	for (int i=0; i<fragmentContextStack_.length; ++i) {
    		final QName name = fragmentContextStack_[i];
        	final Element elt = HTMLElements.getElement(name.localpart);
        	fElementStack.push(new Info(elt, name));
    	}
    	
    }
    else {
    	fragmentContextStackSize_ = 0;
    }
    fSeenAnything = false;
    fSeenDoctype = false;
    fSeenRootElement = false;
    fSeenRootElementEnd = false;
    fSeenHeadElement = false;
    fSeenBodyElement = false;
    

    // pass on event
    if (fDocumentHandler != null) {
    	XercesBridge.getInstance().XMLDocumentHandler_startDocument(fDocumentHandler, locator, encoding, nscontext, augs);
    }

}
 
Example #7
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doctypeDecl(String arg0, String arg1, String arg2,
        Augmentations arg3) throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("doctypeDecl");
  }
}
 
Example #8
Source File: HTMLSAXParser.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void startDocument(XMLLocator arg0,
                          String arg1,
                          NamespaceContext arg2,
                          Augmentations arg3) throws XNIException {
    super.startDocument(arg0, arg1, arg2, arg3);
    buffer = new StringBuffer();
}
 
Example #9
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void endGeneralEntity(String arg0, Augmentations arg1)
        throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("endGeneralEntity");
  }
}
 
Example #10
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void ignoredStartElement(final QName elem, final XMLAttributes attrs, final Augmentations augs) {
    // when multiple body elements are encountered, the attributes of the discarded
    // elements are used when not previously defined
    if (body_ != null && "body".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes(body_, attrs);
    }
    if (body_ != null && "html".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes((DomElement) body_.getParentNode(), attrs);
    }
}
 
Example #11
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Processing instruction. */
public void processingInstruction(String target, XMLString data,
                                  Augmentations augs) throws XNIException {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
        fDocumentHandler.processingInstruction(target, data, augs);
    }
}
 
Example #12
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void endElement(final QName element, final Augmentations augs)
    throws XNIException {
    // augs might change so we store only the interesting part
    lastTagWasSynthesized_ = isSynthesized(augs);
    super.endElement(element, augs);
}
 
Example #13
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void startElement(final QName element, final XMLAttributes attributes, final Augmentations augs)
    throws XNIException {
    // augs might change so we store only the interesting part
    lastTagWasSynthesized_ = isSynthesized(augs);
    super.startElement(element, attributes, augs);
}
 
Example #14
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void ignorableWhitespace(XMLString arg0, Augmentations arg1)
        throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("ignorableWhitespace: " + arg0);
  }
}
 
Example #15
Source File: CMDTDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void comment(XMLString text, Augmentations augs) throws XNIException {
	if (text != null) {
		comment = text.toString();
	}
	super.comment(text, augs);
}
 
Example #16
Source File: CMDTDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endAttlist(Augmentations augs) throws XNIException {
	comment = null;
	attributes = null;
	nodeInfo = null;
	super.endAttlist(augs);
}
 
Example #17
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.emptyElement(element, attributes, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.emptyElement(element, attributes, augs);
	}
}
 
Example #18
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Comment. */
public void comment(XMLString text, Augmentations augs) throws XNIException {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
        fDocumentHandler.comment(text, augs);
    }
}
 
Example #19
Source File: HtmlUnitNekoDOMBuilder.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void endElement(final QName element, final Augmentations augs)
    throws XNIException {
    // augs might change so we store only the interesting part
    lastTagWasSynthesized_ = isSynthesized(augs);
    super.endElement(element, augs);
}
 
Example #20
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/**
 * Forces an element start, taking care to set the information to allow startElement to "see" that's
 * the element has been forced.
 * @return <code>true</code> if creation could be done (TABLE's creation for instance can't be forced)
 */
private boolean forceStartElement(final QName elem, XMLAttributes attrs, final Augmentations augs)
throws XNIException {
	
	forcedStartElement_ = true;
	startElement(elem, attrs, augs);
	
	return fElementStack.top > 0 && elem.equals(fElementStack.peek().qname);
}
 
Example #21
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Empty element. */
public void emptyElement(final QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException {
	startElement(element, attrs, augs);
    // browser ignore the closing indication for non empty tags like <form .../> but not for unknown element
    final HTMLElements.Element elem = getElement(element);
    if (elem.isEmpty() || elem.code == HTMLElements.UNKNOWN) {
    	endElement(element, augs);
    }
}
 
Example #22
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Start entity. */
public void startGeneralEntity(String name, 
                               XMLResourceIdentifier id,
                               String encoding,
                               Augmentations augs) throws XNIException {
    fSeenAnything = true;

    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // insert body, if needed
    if (!fDocumentFragment) {
        boolean insertBody = !fSeenRootElement;
        if (!insertBody) {
            Info info = fElementStack.peek();
            if (info.element.code == HTMLElements.HEAD ||
                info.element.code == HTMLElements.HTML) {
                String hname = modifyName("head", fNamesElems);
                String bname = modifyName("body", fNamesElems);
                if (fReportErrors) {
                    fErrorReporter.reportWarning("HTML2009", new Object[]{hname,bname});
                }
                fQName.setValues(null, hname, hname, null);
                endElement(fQName, synthesizedAugs());
                insertBody = true;
            }
        }
        if (insertBody) {
            forceStartBody();
        }
    }
    
    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.startGeneralEntity(name, id, encoding, augs);
    }

}
 
Example #23
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** End entity. */
public void endGeneralEntity(String name, Augmentations augs) throws XNIException {
    
    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.endGeneralEntity(name, augs);
    }

}
 
Example #24
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** End CDATA section. */
public void endCDATA(Augmentations augs) throws XNIException {

    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.endCDATA(augs);
    }

}
 
Example #25
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Start prefix mapping. */
public void startPrefixMapping(String prefix, String uri, Augmentations augs)
    throws XNIException {
    
    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
    	XercesBridge.getInstance().XMLDocumentHandler_startPrefixMapping(fDocumentHandler, prefix, uri, augs);
    }

}
 
Example #26
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** End prefix mapping. */
public void endPrefixMapping(String prefix, Augmentations augs)
    throws XNIException {
    
    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // call handler
    if (fDocumentHandler != null) {
    	XercesBridge.getInstance().XMLDocumentHandler_endPrefixMapping(fDocumentHandler, prefix, augs);
    }

}
 
Example #27
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoked for a start element. If the element is a <script>, overrides the normal behavior to begin collecting
 * the script text.
 */
public void startElement( QName element, XMLAttributes attrs, Augmentations augs ) throws XNIException {
    if (!isSupportedScript( element, attrs )) {
        super.startElement( element, attrs, augs );
    } else {
        _activeScriptBlock = new StringBuffer();
        _scriptLanguage = getScriptLanguage( attrs );
        String srcAttribute = attrs.getValue( "src" );
        if (srcAttribute != null) _activeScriptBlock.append( _scriptHandler.getIncludedScript( srcAttribute ) );
    }
}
 
Example #28
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void endElement( QName element, Augmentations augs ) throws XNIException {
    if (_activeScriptBlock == null) {
        super.endElement( element, augs );
    } else {
        try {
            final String scriptText = _activeScriptBlock.toString();
            String replacementText = getTranslatedScript( _scriptLanguage, scriptText );
            _configuration.pushInputSource( newInputSource( replacementText ) );
        } catch (IOException e) { // ignore
        } finally {
            _activeScriptBlock = null;
        }
    }
}
 
Example #29
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Returns an augmentations object with a synthesized item added. */
protected final Augmentations synthesizedAugs() {
    HTMLAugmentations augs = null;
    if (fAugmentations) {
        augs = fInfosetAugs;
        augs.removeAllItems();
        augs.putItem(AUGMENTATIONS, SYNTHESIZED_ITEM);
    }
    return augs;
}
 
Example #30
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called to signal an empty element. This simply synthesizes a
 * startElement followed by an endElement event.
 */
@Override
public void emptyElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
  this.startElement(element, attributes, augs);
  this.endElement(element, augs, true);
}