org.xml.sax.SAXException Java Examples
The following examples show how to use
org.xml.sax.SAXException.
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: BaseConfigureationServiceTest.java From sakai with Educational Community License v2.0 | 6 votes |
public void testParseXml() throws ParserConfigurationException, IOException, SAXException { // This is a small test of the configuration parsing developed when upgrading the xstream library. BaseConfigurationService configurationService = new BaseConfigurationService(); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document document = builder.parse(getClass().getResourceAsStream("config-example.xml")); configurationService.saveServletClientMappings(document); Map<String, List<Map<String, String>>> saveciteClients = configurationService.getSaveciteClients(); assertEquals(1, saveciteClients.size()); List<Map<String, String>> en = saveciteClients.get("en"); assertNotNull(en); Map<String, String> first = en.get(0); assertNotNull(first); assertEquals("Test", first.get("test")); assertEquals("saveciteClients", first.get("id")); }
Example #2
Source File: XML10IOTest.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 6 votes |
public void testLoadXML10Model() throws ParserConfigurationException, SAXException, IOException, TransformerException { XMLUtils theUtils = XMLUtils.getInstance(); DocumentBuilderFactory theFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder theBuilder = theFactory.newDocumentBuilder(); Document theDoc = theBuilder.parse(getClass().getResourceAsStream("examplemodel.mxm")); AbstractXMLModelSerializer theSerializer = new XMLModel10Serializer(theUtils); Model theModel = theSerializer.deserializeModelFromXML(theDoc); StringWriter theStringWriter = new StringWriter(); theSerializer.serializeModelToXML(theModel, theStringWriter); String theOriginalFile = readResourceFile("examplemodel.mxm"); String theNewFile = theStringWriter.toString(); assertTrue(compareStrings(theOriginalFile, theNewFile)); }
Example #3
Source File: AbstractMessageImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Writes the whole envelope as SAX events. */ @Override public void writeTo( ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException { String soapNsUri = soapVersion.nsUri; contentHandler.setDocumentLocator(NULL_LOCATOR); contentHandler.startDocument(); contentHandler.startPrefixMapping("S",soapNsUri); contentHandler.startElement(soapNsUri,"Envelope","S:Envelope",EMPTY_ATTS); if(hasHeaders()) { contentHandler.startElement(soapNsUri,"Header","S:Header",EMPTY_ATTS); MessageHeaders headers = getHeaders(); for (Header h : headers.asList()) { h.writeTo(contentHandler,errorHandler); } contentHandler.endElement(soapNsUri,"Header","S:Header"); } // write the body contentHandler.startElement(soapNsUri,"Body","S:Body",EMPTY_ATTS); writePayloadTo(contentHandler,errorHandler, true); contentHandler.endElement(soapNsUri,"Body","S:Body"); contentHandler.endElement(soapNsUri,"Envelope","S:Envelope"); }
Example #4
Source File: ModelLoader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Parses a {@link DOMForest} into a {@link XSSchemaSet}. * * @return * null if the parsing failed. */ public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException { // set up other parameters to XSOMParser XSOMParser reader = createXSOMParser(forest); // re-parse the transformed schemas for (String systemId : forest.getRootDocuments()) { errorReceiver.pollAbort(); Document dom = forest.get(systemId); if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) { reader.parse(systemId); } } XSSchemaSet result = reader.getResult(); if(result!=null) scdBasedBindingSet.apply(result,errorReceiver); return result; }
Example #5
Source File: UiBuilderTestHelper.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
/** * Returns a DOM object representing parsed xml. * * @param xml The xml to parse * @return Parsed XML document */ private static Document parse(String xml) throws IOException, ParserConfigurationException, SAXException { ErrorHandler errors = new ErrorHandler(); try { synchronized (factory) { DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errors); return builder.parse(new InputSource(new StringReader(xml))); } } catch (SAXException se) { // Prefer parse errors over general errors. errors.throwIfErrors(); throw se; } }
Example #6
Source File: SAXBufferProcessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void processNamespaceAttribute(String prefix, String uri) throws SAXException { _contentHandler.startPrefixMapping(prefix, uri); if (_namespacePrefixesFeature) { // Add the namespace delcaration as an attribute if (prefix != "") { _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, getQName(XMLConstants.XMLNS_ATTRIBUTE, prefix), "CDATA", uri); } else { _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE, "CDATA", uri); } } cacheNamespacePrefix(prefix); }
Example #7
Source File: DataSourceConfigManagerTest.java From Zebra with Apache License 2.0 | 6 votes |
@Test public void testConfig() throws SAXException, IOException { String dataSourceResourceId = "sample.ds.v2"; Map<String, Object> configs = ServiceConfigBuilder.newInstance() .putValue(Constants.CONFIG_SERVICE_NAME_KEY, dataSourceResourceId).build(); ConfigService configService = ConfigServiceFactory.getConfigService(Constants.CONFIG_MANAGER_TYPE_LOCAL, configs); DataSourceConfigManager dataSourceConfigManager = DataSourceConfigManagerFactory .getConfigManager(dataSourceResourceId, configService); Map<String, DataSourceConfig> config = dataSourceConfigManager.getGroupDataSourceConfig().getDataSourceConfigs(); Map<String, DataSourceConfig> dataSourceConfigs = DefaultSaxParser .parse(getClass().getClassLoader().getResourceAsStream("model/datasources.xml")).getDataSourceConfigs(); for (DataSourceConfig entry : config.values()) { DataSourceConfig dataSourceConfig = dataSourceConfigs.get(entry.getId()); Assert.assertEquals(dataSourceConfig.toString(), entry.toString()); } }
Example #8
Source File: OpenImmoReadingExample.java From OpenEstate-IO with Apache License 2.0 | 6 votes |
/** * Read a {@link File} into an {@link OpenImmoTransferDocument} or * {@link OpenImmoFeedbackDocument} and print some of their content to * console. * * @param xmlFile the file to read * @throws SAXException if the file is not readable by the XML parser * @throws IOException if the file is not readable * @throws ParserConfigurationException if the XML parser is improperly configured * @throws JAXBException if XML conversion into Java objects failed */ @SuppressWarnings("Duplicates") protected static void read(File xmlFile) throws SAXException, IOException, ParserConfigurationException, JAXBException { LOGGER.info("process file: " + xmlFile.getAbsolutePath()); if (!xmlFile.isFile()) { LOGGER.warn("> provided file is invalid"); return; } OpenImmoDocument doc = OpenImmoUtils.createDocument(xmlFile); if (doc == null) { LOGGER.warn("> provided XML is not supported"); } else if (doc.isFeedback()) { printToConsole((OpenImmoFeedbackDocument) doc); } else if (doc.isTransfer()) { printToConsole((OpenImmoTransferDocument) doc); } else { LOGGER.warn("> unsupported type of document: " + doc.getClass().getName()); } }
Example #9
Source File: StorageReader.java From netbeans with Apache License 2.0 | 6 votes |
private SAXException log(String errorType, SAXParseException e) { Level level; String message; if (file == null) { level = Level.FINE; message = "XML parser " + errorType; } else { if (isModuleFile()) { //NOI18N level = Level.WARNING; // warnings for module layer supplied files } else { level = Level.FINE; // user files, can be from previous versions } message = "XML parser " + errorType + " in file " + file.getPath(); } SAXException saxe = new SAXException(message); saxe.initCause(e); LOG.log(level, message, saxe); //NOI18N return saxe; }
Example #10
Source File: foreignAttributes.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void enterElement(String $__uri, String $__local, String $__qname, Attributes $attrs) throws SAXException { int $ai; $uri = $__uri; $localName = $__local; $qname = $__qname; switch($_ngcc_current_state) { case 0: { revertToParentFromEnterElement(makeResult(), super._cookie, $__uri, $__local, $__qname, $attrs); } break; default: { unexpectedEnterElement($__qname); } break; } }
Example #11
Source File: NGCCInterleaveFilter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void joinByText( NGCCEventReceiver source, String value ) throws SAXException { if(isJoining) return; // we are already in the process of joining. ignore. isJoining = true; // send special token to the rest of the branches. // these branches don't understand this token, so they will // try to move to a final state and send the token back to us, // which this object will ignore (because isJoining==true) // Otherwise branches will find an error. for( int i=0; i<_receivers.length; i++ ) if( _receivers[i]!=source ) _receivers[i].text(value); // revert to the parent _parent._source.replace(this,_parent); _parent.onChildCompleted(null,_cookie,true); // send this event to the parent _parent.text(value); }
Example #12
Source File: DataUtils.java From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static String[] readTitleAuthor() { String result[] = new String[2]; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); DocumentBuilder db; Document doc; try { File fXmlFile = new File(org.buildmlearn.toolkit.flashcardtemplate.Constants.XMLFileName); db = dbf.newDocumentBuilder(); doc = db.parse(fXmlFile); doc.normalize(); result[0] = doc.getElementsByTagName("title").item(0).getChildNodes() .item(0).getNodeValue(); result[1] = doc.getElementsByTagName("name").item(0).getChildNodes() .item(0).getNodeValue(); } catch (ParserConfigurationException | SAXException | IOException e) { e.printStackTrace(); } return result; }
Example #13
Source File: PyPiSearchUtils.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (fault) { return; } switch (qName) { case "fault": fault = true; break; case "member": currentMemberName = null; currentMemberValue = null; break; case "name": currentCharacters = new StringBuilder(); break; case "string": currentCharacters = new StringBuilder(); break; case "boolean": currentCharacters = new StringBuilder(); break; default: // empty } }
Example #14
Source File: DocumentBuilderFactoryImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Creates a new instance of a {@link javax.xml.parsers.DocumentBuilder} * using the currently configured parameters. */ public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { /** Check that if a Schema has been specified that neither of the schema properties have been set. */ if (grammar != null && attributes != null) { if (attributes.containsKey(JAXPConstants.JAXP_SCHEMA_LANGUAGE)) { throw new ParserConfigurationException( SAXMessageFormatter.formatMessage(null, "schema-already-specified", new Object[] {JAXPConstants.JAXP_SCHEMA_LANGUAGE})); } else if (attributes.containsKey(JAXPConstants.JAXP_SCHEMA_SOURCE)) { throw new ParserConfigurationException( SAXMessageFormatter.formatMessage(null, "schema-already-specified", new Object[] {JAXPConstants.JAXP_SCHEMA_SOURCE})); } } try { return new DocumentBuilderImpl(this, attributes, features, fSecureProcess); } catch (SAXException se) { // Handles both SAXNotSupportedException, SAXNotRecognizedException throw new ParserConfigurationException(se.getMessage()); } }
Example #15
Source File: SAXBufferProcessor.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private void processNamespaceAttribute(String prefix, String uri) throws SAXException { _contentHandler.startPrefixMapping(prefix, uri); if (_namespacePrefixesFeature) { // Add the namespace delcaration as an attribute if (prefix != "") { _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, getQName(XMLConstants.XMLNS_ATTRIBUTE, prefix), "CDATA", uri); } else { _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE, "CDATA", uri); } } cacheNamespacePrefix(prefix); }
Example #16
Source File: ColumnsXml.java From Onosendai with Apache License 2.0 | 6 votes |
@Override public void endElement (final String uri, final String localName, final String qName) throws SAXException { final String elementName = !localName.isEmpty() ? localName : qName; if (this.stack.size() == 3) { // NOSONAR not a magic number. if ("column".equals(elementName)) { if (!StringHelper.isEmpty(this.stashedFullpath)) { this.columns.add(new Column(this.columns.size(), this.stashedTitle, new ColumnFeed(this.account.getId(), this.stashedFullpath), DEFAULT_COLUMN_REFRESH_MINS, null, false, null, InlineMediaStyle.NONE, false)); } this.stashedFullpath = null; this.stashedTitle = null; } } else if (this.stack.size() == 4) { // NOSONAR not a magic number. if ("fullpath".equals(elementName)) { this.stashedFullpath = this.currentText.toString(); } else if ("title".equals(elementName)) { this.stashedTitle = this.currentText.toString(); } } this.stack.pop(); }
Example #17
Source File: LevelParser.java From 30-android-libraries-in-30-days with Apache License 2.0 | 6 votes |
@Override public void startElement(final String pUri, final String pLocalName, final String pQualifiedName, final Attributes pAttributes) throws SAXException { final String entityName = pLocalName; final IEntity parent = (this.mParentEntityStack.isEmpty()) ? null : this.mParentEntityStack.getLast(); final IEntityLoader entityLoader = this.mEntityLoaders.get(entityName); final IEntity entity; if(entityLoader != null) { entity = entityLoader.onLoadEntity(entityName, pAttributes); } else if(this.mDefaultEntityLoader != null) { entity = this.mDefaultEntityLoader.onLoadEntity(entityName, pAttributes); } else { throw new IllegalArgumentException("Unexpected tag: '" + entityName + "'."); } if(parent != null && entity != null) { parent.attachChild(entity); } this.mParentEntityStack.addLast(entity); }
Example #18
Source File: SupplementDataParseHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { // avoid HTTP traffic to unicode.org if (systemID.startsWith(CLDRConverter.SPPL_LDML_DTD_SYSTEM_ID)) { return new InputSource((new File(CLDRConverter.LOCAL_SPPL_LDML_DTD)).toURI().toString()); } return null; }
Example #19
Source File: SAXImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * SAX2: Receive notification of ignorable whitespace in element * content. Similar to characters(char[], int, int). */ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { super.ignorableWhitespace(ch, start, length); _textNodeToProcess = getNumberOfNodes(); }
Example #20
Source File: SerializerBase.java From j2objc with Apache License 2.0 | 5 votes |
/** * Report the start element trace event. This trace method needs to be * called just before the attributes are cleared. * * @param elemName the qualified name of the element * */ protected void fireStartElem(String elemName) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_STARTELEMENT, elemName, m_attributes); } }
Example #21
Source File: XMLStreamReaderToContentHandler.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void handleEndElement() throws XMLStreamException { QName qName = staxStreamReader.getName(); try { String pfix = qName.getPrefix(); String rawname = (pfix == null || pfix.length() == 0) ? qName.getLocalPart() : pfix + ':' + qName.getLocalPart(); // fire endElement saxHandler.endElement( qName.getNamespaceURI(), qName.getLocalPart(), rawname); // end namespace bindings int nsCount = staxStreamReader.getNamespaceCount(); for (int i = nsCount - 1; i >= 0; i--) { String prefix = staxStreamReader.getNamespacePrefix(i); if (prefix == null) { // true for default namespace prefix = ""; } saxHandler.endPrefixMapping(prefix); } } catch (SAXException e) { throw new XMLStreamException2(e); } }
Example #22
Source File: SAX2DTM2.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example #23
Source File: MetaDataObject_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * @see org.apache.uima.util.XMLizable#toXML(org.xml.sax.ContentHandler, boolean) * * This is called internally, also for JSon serialization * If this is the first call to serialize, create a serialContext (and clean up afterwards) * Other callers (e.g. JSON) must set the serialContext first before calling */ public void toXML(ContentHandler aContentHandler, boolean aWriteDefaultNamespaceAttribute) throws SAXException { if (null == serialContext.get()) { getSerialContext(aContentHandler); try { toXMLcommon(aWriteDefaultNamespaceAttribute); } finally { serialContext.remove(); } } else { toXMLcommon(aWriteDefaultNamespaceAttribute); } }
Example #24
Source File: FileReader.java From apigee-deploy-maven-plugin with Apache License 2.0 | 5 votes |
public Document getXMLDocument(File filepath) throws SAXException, IOException, ParserConfigurationException { // Create a builder factory DocumentBuilderFactory docFactory = DocumentBuilderFactory .newInstance(); // Create the builder and parse the file DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); //Document doc = docBuilder.parse("/Users/santanudey/Projects/4G/code-fest/project/apiproxy/proxies/proxy.xml"); Document doc = docBuilder.parse(filepath); return doc; }
Example #25
Source File: ToHTMLStream.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Receive notification of cdata. * * <p>The Parser will call this method to report each chunk of * character data. SAX parsers may return all contiguous character * data in a single chunk, or they may split it into several * chunks; however, all of the characters in any single event * must come from the same external entity, so that the Locator * provides useful information.</p> * * <p>The application must not attempt to read from the array * outside of the specified range.</p> * * <p>Note that some parsers will report whitespace using the * ignorableWhitespace() method rather than this one (validating * parsers must do so).</p> * * @param ch The characters from the XML document. * @param start The start position in the array. * @param length The number of characters to read from the array. * @throws org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. * @see #ignorableWhitespace * @see org.xml.sax.Locator * * @throws org.xml.sax.SAXException */ public final void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException { if ((null != m_elemContext.m_elementName) && (m_elemContext.m_elementName.equalsIgnoreCase("SCRIPT") || m_elemContext.m_elementName.equalsIgnoreCase("STYLE"))) { try { if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } m_ispreserve = true; if (shouldIndent()) indent(); // writer.write(ch, start, length); writeNormalizedChars(ch, start, length, true, m_lineSepUse); } catch (IOException ioe) { throw new org.xml.sax.SAXException( Utils.messages.createMessage( MsgKey.ER_OIERROR, null), ioe); //"IO error", ioe); } } else { super.cdata(ch, start, length); } }
Example #26
Source File: SingleMapNodeProperty.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { if(ea.matches(keyTag)) { state.setLoader(keyLoader); state.setReceiver(keyReceiver); return; } if(ea.matches(valueTag)) { state.setLoader(valueLoader); state.setReceiver(valueReceiver); return; } super.childElement(state,ea); }
Example #27
Source File: TicketParser.java From nordpos with GNU General Public License v3.0 | 5 votes |
@Override public void startDocument() throws SAXException { // inicalizo las variables pertinentes text = null; bctype = null; bcposition = null; m_sVisorLine = null; m_iVisorAnimation = DeviceDisplayBase.ANIMATION_NULL; m_sVisorLine1 = null; m_sVisorLine2 = null; m_iOutputType = OUTPUT_NONE; m_oOutputPrinter = null; }
Example #28
Source File: Parser.java From Android-RTEditor with Apache License 2.0 | 5 votes |
@Override public void aval(char[] buff, int offset, int length) throws SAXException { if (theNewElement != null && theAttributeName != null) { String value = new String(buff, offset, length); value = expandEntities(value); theNewElement.setAttribute(theAttributeName, null, value); theAttributeName = null; } }
Example #29
Source File: NGCCRuntime.java From hottub with GNU General Public License v2.0 | 5 votes |
public void endPrefixMapping( String prefix ) throws SAXException { if(redirect!=null) redirect.endPrefixMapping(prefix); else { namespaces.remove(namespaces.size()-1); namespaces.remove(namespaces.size()-1); } }
Example #30
Source File: CompactSyntax.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void doError(String message, Token tok) { hadError = true; if (eh != null) { LocatorImpl loc = new LocatorImpl(); loc.setLineNumber(tok.beginLine); loc.setColumnNumber(tok.beginColumn); loc.setSystemId(sourceUri); try { eh.error(new SAXParseException(message, loc)); } catch (SAXException se) { throw new BuildException(se); } } }