org.xml.sax.helpers.AttributesImpl Java Examples
The following examples show how to use
org.xml.sax.helpers.AttributesImpl.
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: DTD.java From jlibs with Apache License 2.0 | 6 votes |
public void addMissingAttributes(String elemName, AttributesImpl attributes){ Map<String, DTDAttribute> attList = this.attributes.get(elemName); if(attList==null) return; for(DTDAttribute dtdAttr: attList.values()){ switch(dtdAttr.valueType){ case DEFAULT: case FIXED: if(attributes.getIndex(dtdAttr.name)==-1 && !dtdAttr.isNamespace()){ AttributeType type = dtdAttr.type==AttributeType.ENUMERATION ? AttributeType.NMTOKEN : dtdAttr.type; String namespaceURI = ""; String localName = dtdAttr.name; String qname = localName; int colon = qname.indexOf(':'); if(colon!=-1){ localName = qname.substring(colon+1); String prefix = qname.substring(0, colon); if(prefix.length()>0) namespaceURI = reader.getNamespaceURI(prefix); } attributes.addAttribute(namespaceURI, localName, qname, type.name(), dtdAttr.value); } } } }
Example #2
Source File: FSEditLogOp.java From hadoop with Apache License 2.0 | 6 votes |
private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException { for (XAttr xAttr: xAttrs) { contentHandler.startElement("", "", "XATTR", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString()); XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName()); if (xAttr.getValue() != null) { try { XMLUtils.addSaxString(contentHandler, "VALUE", XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX)); } catch (IOException e) { throw new SAXException(e); } } contentHandler.endElement("", "", "XATTR"); } }
Example #3
Source File: CacheXmlGenerator.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Generates XML for the client-subscription tag * @param bridge instance of <code>CacheServer</code> * * @since 5.7 */ private void generateClientHaQueue(CacheServer bridge) throws SAXException { AttributesImpl atts = new AttributesImpl(); ClientSubscriptionConfigImpl csc = (ClientSubscriptionConfigImpl)bridge.getClientSubscriptionConfig(); try { atts.addAttribute("", "", CLIENT_SUBSCRIPTION_EVICTION_POLICY, "", csc.getEvictionPolicy()); atts.addAttribute("", "", CLIENT_SUBSCRIPTION_CAPACITY, "", String.valueOf(csc.getCapacity())); if (this.version.compareTo(VERSION_6_5) >= 0) { String dsVal = csc.getDiskStoreName(); if (dsVal != null) { atts.addAttribute("", "", DISK_STORE_NAME, "", dsVal); } } if (csc.getDiskStoreName() == null && csc.hasOverflowDirectory()) { atts.addAttribute("", "", OVERFLOW_DIRECTORY, "", csc.getOverflowDirectory()); } handler.startElement("", CLIENT_SUBSCRIPTION, CLIENT_SUBSCRIPTION, atts); handler.endElement("", CLIENT_SUBSCRIPTION, CLIENT_SUBSCRIPTION); } catch (Exception ex) { ex.printStackTrace(); } }
Example #4
Source File: PositionalXmlHandlerTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testStartElement() throws SAXException { handler.startDocument(); Locator2 locator = Mockito.mock(Locator2.class); handler.setDocumentLocator(locator); Mockito.when(locator.getLineNumber()).thenReturn(1); Mockito.when(locator.getColumnNumber()).thenReturn(7); handler.startElement("", "", "element", new AttributesImpl()); assertEquals(1, handler.getElementStack().size()); Element element = handler.getElementStack().pop(); DocumentLocation location = (DocumentLocation) element.getUserData("location"); assertEquals(1, location.getLineNumber()); assertEquals(7, location.getColumnNumber()); }
Example #5
Source File: XMLTransferManifestWriter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") private void writeCategory (NodeRef nodeRef, ManifestCategory value) throws SAXException { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "path", "path", "String", value.getPath()); writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_CATEGORY, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_CATEGORY, attributes); writeValue(nodeRef); writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_CATEGORY, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_CATEGORY); }
Example #6
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 6 votes |
public void testCategory() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "category", attributes); handler.startElement(null, null, "pattern", attributes); handler.characters(text = toCharArray("HELLO ALICE I AM *"), 0, text.length); handler.endElement(null, null, "pattern"); handler.startElement(null, null, "that", attributes); handler.characters(text = toCharArray("TEST"), 0, text.length); handler.endElement(null, null, "that"); handler.startElement(null, null, "template", attributes); handler.characters(text = toCharArray("Hello "), 0, text.length); handler.startElement(null, null, "star", attributes); handler.characters(text = toCharArray(", nice to meet you."), 0, text.length); handler.endElement(null, null, "template"); handler.endElement(null, null, "category"); Category actual = (Category) stack.peek(); Category expected = new Category(new Pattern("HELLO ALICE I AM *"), new That("TEST"), new Template("Hello ", new Star(1), ", nice to meet you.")); assertEquals(expected, actual); }
Example #7
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 6 votes |
public void testFormal() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "formal", attributes); handler.characters( text = toCharArray("change this input case to title case"), 0, text.length); handler.endElement(null, null, "formal"); Formal expected = new Formal("change this input case to title case"); Formal actual = (Formal) stack.peek(); assertEquals(expected, actual); assertEquals("Change This Input Case To Title Case", actual.process(null)); }
Example #8
Source File: SAXAnnotationAdapter.java From jtransc with Apache License 2.0 | 6 votes |
private void addValueElement(final String element, final String name, final String desc, final String value) { AttributesImpl att = new AttributesImpl(); if (name != null) { att.addAttribute("", "name", "name", "", name); } if (desc != null) { att.addAttribute("", "desc", "desc", "", desc); } if (value != null) { att.addAttribute("", "value", "value", "", SAXClassAdapter.encode(value)); } sa.addElement(element, att); }
Example #9
Source File: XMLTransferManifestWriter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void writePermission(ManifestPermission permission) throws SAXException { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "status", "status", "String", permission.getStatus()); attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "authority", "authority", "String", permission.getAuthority()); attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "permission", "permission", "String", permission.getPermission()); writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION, attributes); writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION); }
Example #10
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 6 votes |
public void testJavascript() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "javascript", attributes); handler.characters(text = toCharArray("Anything can go here"), 0, text.length); handler.endElement(null, null, "javascript"); Javascript expected = new Javascript("Anything can go here"); Javascript actual = (Javascript) stack.peek(); assertEquals(expected, actual); assertFalse(expected .equals(new Javascript("Anything else can go here"))); // assertEquals("", actual.process(null)); }
Example #11
Source File: ViewXMLExporter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void startNode(NodeRef nodeRef) { try { AttributesImpl attrs = new AttributesImpl(); Path path = nodeService.getPath(nodeRef); if (path.size() > 1) { // a child name does not exist for root Path.ChildAssocElement pathElement = (Path.ChildAssocElement)path.last(); QName childQName = pathElement.getRef().getQName(); attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME, CHILDNAME_QNAME.toPrefixString(), null, toPrefixString(childQName)); } QName type = nodeService.getType(nodeRef); contentHandler.startElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs); } catch (SAXException e) { throw new ExporterException("Failed to process start node event - node ref " + nodeRef.toString(), e); } }
Example #12
Source File: CanonicalXTMWriter.java From ontopia with Apache License 2.0 | 6 votes |
private void write(AssociationIF association, int number) { AttributesImpl attributes = reifier(association); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_ASSOCIATION, attributes); attributes.clear(); writeType(association); Object[] roles = association.getRoles().toArray(); Arrays.sort(roles, associationRoleComparator); for (int ix = 0; ix < roles.length; ix++) write((AssociationRoleIF) roles[ix], ix + 1); write(association.getScope()); writeLocators(association.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_ASSOCIATION); }
Example #13
Source File: SAXClassAdapter.java From awacs with Apache License 2.0 | 6 votes |
@Override public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { StringBuilder sb = new StringBuilder(); appendAccess(access | ACCESS_FIELD, sb); AttributesImpl att = new AttributesImpl(); att.addAttribute("", "access", "access", "", sb.toString()); att.addAttribute("", "name", "name", "", name); att.addAttribute("", "desc", "desc", "", desc); if (signature != null) { att.addAttribute("", "signature", "signature", "", encode(signature)); } if (value != null) { att.addAttribute("", "value", "value", "", encode(value.toString())); } return new SAXFieldAdapter(sa, att); }
Example #14
Source File: Filter_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void toXML(ContentHandler aContentHandler, boolean aWriteDefaultNamespaceAttribute) throws SAXException { // write the element's start tag AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "syntax", "syntax", "", getSyntax()); // start element aContentHandler.startElement("", "filter", "filter", attrs); // write content String expr = getExpression(); aContentHandler.characters(expr.toCharArray(), 0, expr.length()); // end element aContentHandler.endElement("", "filter", "filter"); }
Example #15
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Output the supported lock types XML element * * @param xml XMLWriter */ protected void writeLockTypes(XMLWriter xml) { try { AttributesImpl nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK, nullAttr); // Output exclusive lock // Shared locks are not supported, as they cannot be supported by the LockService (relevant to ALF-16449). writeLock(xml, WebDAV.XML_NS_EXCLUSIVE); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK); } catch (Exception ex) { throw new AlfrescoRuntimeException("XML write error", ex); } }
Example #16
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 5 votes |
public void testLearn() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "learn", attributes); handler.characters(text = toCharArray("http://resource1"), 0, text.length); handler.endElement(null, null, "learn"); Learn expected = new Learn("http://resource1"); Learn actual = (Learn) stack.peek(); assertEquals(expected, actual); }
Example #17
Source File: SAXAnnotationAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
private void addValueElement(final String element, final String name, final String desc, final String value) { AttributesImpl att = new AttributesImpl(); if (name != null) { att.addAttribute("", "name", "name", "", name); } if (desc != null) { att.addAttribute("", "desc", "desc", "", desc); } if (value != null) { att.addAttribute("", "value", "value", "", SAXClassAdapter.encode(value)); } sa.addElement(element, att); }
Example #18
Source File: StringHeader.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException { String nsUri = name.getNamespaceURI(); String ln = name.getLocalPart(); h.startPrefixMapping("",nsUri); if(mustUnderstand) { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(soapVersion.nsUri,MUST_UNDERSTAND,"S:"+MUST_UNDERSTAND,"CDATA", getMustUnderstandLiteral(soapVersion)); h.startElement(nsUri,ln,ln,attributes); } else { h.startElement(nsUri,ln,ln,EMPTY_ATTS); } h.characters(value.toCharArray(),0,value.length()); h.endElement(nsUri,ln,ln); }
Example #19
Source File: SAXCodeAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public void visitParameter(String name, int access) { AttributesImpl attrs = new AttributesImpl(); if (name != null) { attrs.addAttribute("", "name", "name", "", name); } StringBuilder sb = new StringBuilder(); SAXClassAdapter.appendAccess(access, sb); attrs.addAttribute("", "access", "access", "", sb.toString()); sa.addElement("parameter", attrs); }
Example #20
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 5 votes |
public void testPattern() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "pattern", attributes); handler.characters(text = toCharArray("HELLO ALICE"), 0, text.length); handler.endElement(null, null, "pattern"); Pattern expected = new Pattern(" HELLO ALICE "); Pattern actual = (Pattern) stack.peek(); assertEquals(expected, actual); assertEquals(expected.hashCode(), actual.hashCode()); }
Example #21
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 5 votes |
public void testAiml() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); AttributesImpl aimlAtts = new AttributesImpl(); aimlAtts.addAttribute(null, "version", null, "String", "1.0.1"); handler.startElement(null, null, "aiml", aimlAtts); handler.startElement(null, null, "category", attributes); handler.startElement(null, null, "pattern", attributes); handler.characters(text = toCharArray("HELLO ALICE I AM *"), 0, text.length); handler.endElement(null, null, "pattern"); handler.startElement(null, null, "template", attributes); handler.characters(text = toCharArray("Hello "), 0, text.length); handler.startElement(null, null, "star", attributes); handler.characters(text = toCharArray(", nice to meet you."), 0, text.length); handler.endElement(null, null, "template"); handler.endElement(null, null, "category"); handler.endElement(null, null, "aiml"); Aiml actual = (Aiml) stack.peek(); Aiml expected = new Aiml(new Category( new Pattern("HELLO ALICE I AM *"), new Template("Hello ", new Star(1), ", nice to meet you."))); assertEquals(expected, actual); assertEquals("1.0.1", actual.getVersion()); }
Example #22
Source File: CpeIncludeImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Overridden to handle "href" attribute. * * @return the XML attributes * @see org.apache.uima.resource.metadata.impl.MetaDataObject_impl#getXMLAttributes() */ @Override protected AttributesImpl getXMLAttributes() { AttributesImpl attrs = super.getXMLAttributes(); attrs.addAttribute("", "href", "href", "CDATA", getHref()); return attrs; }
Example #23
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 5 votes |
public void testSystem() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "system", attributes); handler.characters(text = toCharArray("system = \"Hello System!\""), 0, text.length); handler.endElement(null, null, "system"); System tag = (System) stack.peek(); assertEquals(new System("system = \"Hello System!\""), tag); }
Example #24
Source File: FSEditLogOp.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected void toXml(ContentHandler contentHandler) throws SAXException { XMLUtils.addSaxString(contentHandler, "LENGTH", Integer.toString(length)); XMLUtils.addSaxString(contentHandler, "TRG", trg); XMLUtils.addSaxString(contentHandler, "TIMESTAMP", Long.toString(timestamp)); contentHandler.startElement("", "", "SOURCES", new AttributesImpl()); for (int i = 0; i < srcs.length; ++i) { XMLUtils.addSaxString(contentHandler, "SOURCE" + (i + 1), srcs[i]); } contentHandler.endElement("", "", "SOURCES"); appendRpcIdsToXml(contentHandler, rpcClientId, rpcCallId); }
Example #25
Source File: CanonicalTopicMapWriter.java From ontopia with Apache License 2.0 | 5 votes |
/** * PUBLIC: Exports the topic map to the given ContentHandler. */ public void export(TopicMapIF topicmap, ContentHandler dh) throws IOException, SAXException { dh.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "xmlns", CDATA, "http://www.topicmaps.org/cxtm/1.0/"); dh.startElement("", "", "topicMap", atts); atts.clear(); // topics ContextHolder context = createContext(topicmap); Iterator<TopicIF> it = context.topicsInOrder(topicmap.getTopics()); while (it.hasNext()) writeTopic(it.next(), dh, context); // associations Iterator<AssociationIF> ait = context.assocsInOrder(topicmap.getAssociations()); while (ait.hasNext()) writeAssociation(ait.next(), dh, context); dh.endElement("", "", "topicMap"); dh.endDocument(); }
Example #26
Source File: StAXEvent2SAX.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Get the attributes associated with the given START_ELEMENT StAXevent. * * @return the StAX attributes converted to an org.xml.sax.Attributes */ private Attributes getAttributes(StartElement event) { AttributesImpl attrs = new AttributesImpl(); if ( !event.isStartElement() ) { throw new InternalError( "getAttributes() attempting to process: " + event); } // in SAX, namespace declarations are not part of attributes by default. // (there's a property to control that, but as far as we are concerned // we don't use it.) So don't add xmlns:* to attributes. // gather non-namespace attrs for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute staxAttr = (javax.xml.stream.events.Attribute)i.next(); String uri = staxAttr.getName().getNamespaceURI(); if (uri == null) { uri = ""; } String localName = staxAttr.getName().getLocalPart(); String prefix = staxAttr.getName().getPrefix(); String qName; if (prefix == null || prefix.length() == 0) { qName = localName; } else { qName = prefix + ':' + localName; } String type = staxAttr.getDTDType(); String value = staxAttr.getValue(); attrs.addAttribute(uri, localName, qName, type, value); } return attrs; }
Example #27
Source File: AIMLHandlerTest.java From AliceBot with Apache License 2.0 | 5 votes |
public void testPattern() throws Exception { char[] text; AttributesImpl attributes = new AttributesImpl(); handler.startElement(null, null, "pattern", attributes); handler.characters(text = toCharArray("HELLO ALICE"), 0, text.length); handler.endElement(null, null, "pattern"); Pattern expected = new Pattern(" HELLO ALICE "); Pattern actual = (Pattern) stack.peek(); assertEquals(expected, actual); assertEquals(expected.hashCode(), actual.hashCode()); }
Example #28
Source File: RelationMapping.java From ontopia with Apache License 2.0 | 5 votes |
protected void outputEntities(Relation rel, ContentHandler dh) throws SAXException { AttributesImpl atts = new AttributesImpl(); for (Entity entity : rel.getEntities()) { if (entity.getEntityType() == Entity.TYPE_TOPIC) { // <topic> if (entity.getId() != null) addAttribute(atts, "id", "CDATA", entity.getId()); addAttribute(atts, "type", "CDATA", entity.getAssociationType()); dh.startElement("", "", "topic", atts); atts.clear(); outputFields(entity, dh); // </topic> dh.endElement("", "", "topic"); } else if (entity.getEntityType() == Entity.TYPE_ASSOCIATION) { // <association> if (entity.getId() != null) addAttribute(atts, "id", "CDATA", entity.getId()); addAttribute(atts, "type", "CDATA", entity.getAssociationType()); addAttribute(atts, "scope", "CDATA", entity.getScope()); dh.startElement("", "", "association", atts); atts.clear(); outputFields(entity, dh); // </association> dh.endElement("", "", "association"); } } }
Example #29
Source File: SAAJMessage.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Gets the Attributes that are not namesapce declarations * @param attrs * @return */ private AttributesImpl getAttributes(NamedNodeMap attrs) { AttributesImpl atts = new AttributesImpl(); if(attrs == null) return EMPTY_ATTS; for(int i=0; i < attrs.getLength();i++) { Attr a = (Attr)attrs.item(i); //check if attr is ns declaration if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) { continue; } atts.addAttribute(fixNull(a.getNamespaceURI()),a.getLocalName(),a.getName(),a.getSchemaTypeInfo().getTypeName(),a.getValue()); } return atts; }
Example #30
Source File: SAXClassAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { StringBuilder sb = new StringBuilder(); appendAccess(access | ACCESS_CLASS, sb); AttributesImpl att = new AttributesImpl(); att.addAttribute("", "access", "access", "", sb.toString()); if (name != null) { att.addAttribute("", "name", "name", "", name); } if (signature != null) { att.addAttribute("", "signature", "signature", "", encode(signature)); } if (superName != null) { att.addAttribute("", "parent", "parent", "", superName); } att.addAttribute("", "major", "major", "", Integer.toString(version & 0xFFFF)); att.addAttribute("", "minor", "minor", "", Integer.toString(version >>> 16)); sa.addStart("class", att); sa.addStart("interfaces", new AttributesImpl()); if (interfaces != null && interfaces.length > 0) { for (int i = 0; i < interfaces.length; i++) { AttributesImpl att2 = new AttributesImpl(); att2.addAttribute("", "name", "name", "", interfaces[i]); sa.addElement("interface", att2); } } sa.addEnd("interfaces"); }