本文整理匯總了Java中javax.xml.stream.events.Namespace類的典型用法代碼示例。如果您正苦於以下問題:Java Namespace類的具體用法?Java Namespace怎麽用?Java Namespace使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Namespace類屬於javax.xml.stream.events包,在下文中一共展示了Namespace類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleEndElement
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private void handleEndElement(EndElement event) throws SAXException {
if(!seenText && predictor.expectText()) {
visitor.text("");
}
// fire endElement
QName qName = event.getName();
tagName.uri = fixNull(qName.getNamespaceURI());
tagName.local = qName.getLocalPart();
visitor.endElement(tagName);
// end namespace bindings
for( Iterator<Namespace> i = event.getNamespaces(); i.hasNext();) {
String prefix = fixNull(i.next().getPrefix()); // be defensive
visitor.endPrefixMapping(prefix);
}
seenText = false;
}
示例2: handleStartElement
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private void handleStartElement(StartElement event) throws SAXException {
// start namespace bindings
for (Iterator i = event.getNamespaces(); i.hasNext();) {
Namespace ns = (Namespace)i.next();
visitor.startPrefixMapping(
fixNull(ns.getPrefix()),
fixNull(ns.getNamespaceURI()));
}
// fire startElement
QName qName = event.getName();
tagName.uri = fixNull(qName.getNamespaceURI());
String localName = qName.getLocalPart();
tagName.uri = fixNull(qName.getNamespaceURI());
tagName.local = localName;
tagName.atts = getAttributes(event);
visitor.startElement(tagName);
seenText = false;
}
示例3: handleStartElement
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private void handleStartElement(StartElement startElement) throws SAXException {
if (getContentHandler() != null) {
QName qName = startElement.getName();
if (hasNamespacesFeature()) {
for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
Namespace namespace = (Namespace) i.next();
startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
}
for (Iterator i = startElement.getAttributes(); i.hasNext();){
Attribute attribute = (Attribute) i.next();
QName attributeName = attribute.getName();
startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
}
getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
getAttributes(startElement));
}
else {
getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
}
}
}
示例4: handleEndElement
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private void handleEndElement(EndElement endElement) throws SAXException {
if (getContentHandler() != null) {
QName qName = endElement.getName();
if (hasNamespacesFeature()) {
getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName));
for (Iterator i = endElement.getNamespaces(); i.hasNext();) {
Namespace namespace = (Namespace) i.next();
endPrefixMapping(namespace.getPrefix());
}
}
else {
getContentHandler().endElement("", "", toQualifiedName(qName));
}
}
}
示例5: getNamespace
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private Namespace getNamespace(int index) {
Iterator namespaces;
if (this.event.isStartElement()) {
namespaces = this.event.asStartElement().getNamespaces();
}
else if (this.event.isEndElement()) {
namespaces = this.event.asEndElement().getNamespaces();
}
else {
throw new IllegalStateException();
}
int count = 0;
while (namespaces.hasNext()) {
Namespace namespace = (Namespace) namespaces.next();
if (count == index) {
return namespace;
}
else {
count++;
}
}
throw new IllegalArgumentException();
}
示例6: getNamespaceCount
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public int getNamespaceCount() {
XMLSecEvent xmlSecEvent = getCurrentEvent();
switch (xmlSecEvent.getEventType()) {
case START_ELEMENT:
return xmlSecEvent.asStartElement().getOnElementDeclaredNamespaces().size();
case END_ELEMENT:
int count = 0;
Iterator<Namespace> namespaceIterator = xmlSecEvent.asEndElement().getNamespaces();
while (namespaceIterator.hasNext()) {
namespaceIterator.next();
count++;
}
return count;
default:
throw new IllegalStateException(ERR_STATE_NOT_ELEM);
}
}
示例7: getNamespacePrefix
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public String getNamespacePrefix(int index) {
XMLSecEvent xmlSecEvent = getCurrentEvent();
switch (xmlSecEvent.getEventType()) {
case START_ELEMENT:
return xmlSecEvent.asStartElement().getOnElementDeclaredNamespaces().get(index).getPrefix();
case END_ELEMENT:
int count = 0;
Iterator<Namespace> namespaceIterator = xmlSecEvent.asEndElement().getNamespaces();
while (namespaceIterator.hasNext()) {
Namespace namespace = namespaceIterator.next();
if (count == index) {
return namespace.getPrefix();
}
count++;
}
throw new ArrayIndexOutOfBoundsException(index);
default:
throw new IllegalStateException(ERR_STATE_NOT_ELEM);
}
}
示例8: getNamespace
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private Namespace getNamespace(int index) {
Iterator namespaces;
if (event.isStartElement()) {
namespaces = event.asStartElement().getNamespaces();
}
else if (event.isEndElement()) {
namespaces = event.asEndElement().getNamespaces();
}
else {
throw new IllegalStateException();
}
int count = 0;
while (namespaces.hasNext()) {
Namespace namespace = (Namespace) namespaces.next();
if (count == index) {
return namespace;
}
else {
count++;
}
}
throw new IllegalArgumentException();
}
示例9: startElement
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void startElement(XmlParserContext ctx, StartElement element) throws BagriException {
ctx.appendCharacters();
ctx.addData(element.getName().toString()); // getLocalPart());
ctx.addElement();
for (Iterator<Namespace> itr = element.getNamespaces(); itr.hasNext();) {
Namespace ns = itr.next();
// TODO: process default namespace properly
String namespace = ns.getValue();
if (namespace != null) {
String prefix = ns.getName().getLocalPart();
ctx.addNamespace(prefix, namespace);
}
}
for (Iterator<Attribute> itr = element.getAttributes(); itr.hasNext();) {
Attribute a = itr.next();
//if (!a.getName().getPrefix().isEmpty()) {
// String prefix = model.translateNamespace(a.getName().getNamespaceURI(), a.getName().getPrefix());
// ctx.addNamespace(prefix, a.getName().getNamespaceURI());
//}
ctx.addAttribute(a.getName(), a.getValue());
}
}
示例10: createNamespaces
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
/**
* Create and return a list of {@code NameSpace} objects from the {@code NamespaceContext}.
*/
private List<Namespace> createNamespaces(SimpleNamespaceContext namespaceContext) {
if (namespaceContext == null) {
return null;
}
List<Namespace> namespaces = new ArrayList<Namespace>();
String defaultNamespaceUri = namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX);
if (StringUtils.hasLength(defaultNamespaceUri)) {
namespaces.add(this.eventFactory.createNamespace(defaultNamespaceUri));
}
for (Iterator<String> iterator = namespaceContext.getBoundPrefixes(); iterator.hasNext(); ) {
String prefix = iterator.next();
String namespaceUri = namespaceContext.getNamespaceURI(prefix);
namespaces.add(this.eventFactory.createNamespace(prefix, namespaceUri));
}
return namespaces;
}
示例11: createNamespaces
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
/**
* Create and return a list of {@code NameSpace} objects from the {@code NamespaceContext}.
*/
private List<Namespace> createNamespaces(SimpleNamespaceContext namespaceContext) {
if (namespaceContext == null) {
return null;
}
List<Namespace> namespaces = new ArrayList<Namespace>();
String defaultNamespaceUri = namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX);
if (StringUtils.hasLength(defaultNamespaceUri)) {
namespaces.add(this.eventFactory.createNamespace(defaultNamespaceUri));
}
for (Iterator iterator = namespaceContext.getBoundPrefixes(); iterator.hasNext();) {
String prefix = (String) iterator.next();
String namespaceUri = namespaceContext.getNamespaceURI(prefix);
namespaces.add(this.eventFactory.createNamespace(prefix, namespaceUri));
}
return namespaces;
}
示例12: getNamespaces
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@Override
public Iterator<Namespace> getNamespaces()
{
if (mNsList == null) {
int firstLocal = mFirstLocalNs;
int len = mNsLength - firstLocal;
if (len == 0) { // can this happen?
return DataUtil.emptyIterator();
}
if (len == 2) { // only one NS
return DataUtil.<Namespace>singletonIterator(NamespaceEventImpl.constructNamespace
(mLocation,
mNamespaces[firstLocal],
mNamespaces[firstLocal+1]));
}
ArrayList<Namespace> l = new ArrayList<Namespace>(len >> 1);
String[] ns = mNamespaces;
for (len = mNsLength; firstLocal < len;
firstLocal += 2) {
l.add(NamespaceEventImpl.constructNamespace(mLocation, ns[firstLocal],
ns[firstLocal+1]));
}
mNsList = l;
}
return mNsList.iterator();
}
示例13: outputNamespaceDeclarations
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
@Override
public void outputNamespaceDeclarations(Writer w) throws IOException
{
for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
Namespace ns = mNamespaces.get(i);
w.write(' ');
w.write(XMLConstants.XMLNS_ATTRIBUTE);
if (!ns.isDefaultNamespaceDeclaration()) {
w.write(':');
w.write(ns.getPrefix());
}
w.write("=\"");
w.write(ns.getNamespaceURI());
w.write('"');
}
}
示例14: buildByPrefixMap
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private Map<String,Namespace> buildByPrefixMap()
{
int len = mNamespaces.size();
if (len == 0) {
return Collections.emptyMap();
}
LinkedHashMap<String,Namespace> m = new LinkedHashMap<String,Namespace>(1 + len + (len>>1));
for (int i = 0; i < len; ++i) {
Namespace ns = mNamespaces.get(i);
String prefix = ns.getPrefix();
if (prefix == null) { // shouldn't happen but...
prefix = "";
}
m.put(prefix, ns);
}
return m;
}
示例15: buildByNsURIMap
import javax.xml.stream.events.Namespace; //導入依賴的package包/類
private Map<String,Namespace> buildByNsURIMap()
{
int len = mNamespaces.size();
if (len == 0) {
return Collections.emptyMap();
}
LinkedHashMap<String,Namespace> m = new LinkedHashMap<String,Namespace>(1 + len + (len>>1));
for (int i = 0; i < len; ++i) {
Namespace ns = mNamespaces.get(i);
String uri = ns.getNamespaceURI();
if (uri == null) { // shouldn't happen but...
uri = "";
}
m.put(uri, ns);
}
return m;
}