List of usage examples for org.xml.sax SAXException SAXException
public SAXException(String message, Exception e)
From source file:org.apache.cocoon.transformation.TagTransformer.java
private void setupTag(Tag tag, String name, Attributes atts) throws SAXException { // Set Tag Parent tag.setParent(this.currentTag); // Set Tag XML Consumer if (tag instanceof XMLProducer) { XMLConsumer tagConsumer;//from www . ja v a2 s .co m if (transformerSelector != null) { Transformer tagTransformer = null; try { // Add additional (Tag)Transformer to the output of the Tag tagTransformer = (Transformer) transformerSelector.select(transformerHint); tagTransformerStack.push(tagTransformer); tagTransformer.setConsumer(currentConsumer); tagTransformer.setup(this.resolver, this.objectModel, null, this.parameters); } catch (SAXException e) { throw e; } catch (Exception e) { throw new SAXException("Failed to setup tag transformer " + transformerHint, e); } tagConsumer = tagTransformer; } else { tagConsumer = this.currentConsumer; } ((XMLProducer) tag).setConsumer(tagConsumer); } // Setup Tag try { tag.setup(this.resolver, this.objectModel, this.parameters); } catch (IOException e) { throw new SAXException("Could not set up tag " + name, e); } if (tag instanceof XMLConsumer) { this.currentConsumer = (XMLConsumer) tag; } this.currentTag = tag; // Set Tag-Attributes, Attributes are mapped to the coresponding Tag method for (int i = 0; i < atts.getLength(); i++) { String attributeName = atts.getLocalName(i); String attributeValue = atts.getValue(i); this.paramArray[0] = attributeValue; try { Method method = getWriteMethod(tag.getClass(), attributeName); method.invoke(tag, this.paramArray); } catch (Throwable e) { if (getLogger().isInfoEnabled()) { getLogger().info("Tag " + name + " attribute " + attributeName + " not set", e); } } } }
From source file:org.apache.cocoon.transformation.TagTransformer.java
/** * Start recording for the iterator tag. *//*from w w w . j a v a 2 s . co m*/ private void startRecording() throws SAXException { try { this.xmlSerializer = (XMLSerializer) manager.lookup(XMLSerializer.ROLE); } catch (ServiceException e) { throw new SAXException("Can't lookup XMLSerializer", e); } this.currentConsumerBackup = this.currentConsumer; this.currentConsumer = this.xmlSerializer; this.recordingLevel = 1; }
From source file:org.apache.cocoon.transformation.TraxTransformer.java
/** * Set the <code>XMLConsumer</code> that will receive XML data. *///from w w w .j av a2 s . c om public void setConsumer(XMLConsumer consumer) { if (this.transformerHandler == null) { try { this.transformerHandler = this.xsltProcessor.getTransformerHandler(this.inputSource); } catch (XSLTProcessorException se) { // the exception will be thrown during startDocument() this.exceptionDuringSetConsumer = new SAXException( "Unable to get transformer handler for " + this.inputSource.getURI(), se); return; } } final Map map = getLogicSheetParameters(); if (map != null) { final javax.xml.transform.Transformer transformer = this.transformerHandler.getTransformer(); final Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry entry = (Entry) iterator.next(); transformer.setParameter((String) entry.getKey(), entry.getValue()); } } super.setContentHandler(this.transformerHandler); super.setLexicalHandler(this.transformerHandler); if (this.transformerHandler instanceof LogEnabled) { ((LogEnabled) this.transformerHandler).enableLogging(getLogger()); } // According to TrAX specs, all TransformerHandlers are LexicalHandlers final SAXResult result = new SAXResult(consumer); result.setLexicalHandler(consumer); this.transformerHandler.setResult(result); this.errorListener = new TraxErrorListener(getLogger(), this.inputSource.getURI()); this.transformerHandler.getTransformer().setErrorListener(this.errorListener); }
From source file:org.apache.cocoon.transformation.WebDAVTransformer.java
public void endElement(String uri, String name, String raw) throws SAXException { if (name.equals(REQUEST_TAG) && uri.equals(NS_URI)) { try {/* w w w.j av a 2s . co m*/ HttpURL url = new HttpURL(m_target); if (url.getUser() != null && !"".equals(url.getUser())) { m_state.setCredentials(null, new UsernamePasswordCredentials(url.getUser(), url.getPassword())); } m_target = url.getURI(); if (m_validity != null) { m_validity.add(makeWebdavEventValidity(url)); } } catch (Exception e) { //ignore } // create method WebDAVRequestMethod method = new WebDAVRequestMethod(m_target, m_method); try { // add request headers Iterator headers = m_headers.entrySet().iterator(); while (headers.hasNext()) { Map.Entry header = (Map.Entry) headers.next(); method.addRequestHeader((String) header.getKey(), (String) header.getValue()); } Properties props = XMLUtils.createPropertiesForXML(false); props.put(OutputKeys.ENCODING, "ISO-8859-1"); String body = XMLUtils.serializeNode(m_requestdocument, props); // set request body method.setRequestBody(body.getBytes("ISO-8859-1")); // execute the request executeRequest(method); } catch (ProcessingException e) { if (getLogger().isErrorEnabled()) { getLogger().debug("Couldn't read request from sax stream", e); } throw new SAXException("Couldn't read request from sax stream", e); } catch (UnsupportedEncodingException e) { if (getLogger().isErrorEnabled()) { getLogger().debug("ISO-8859-1 encoding not present", e); } throw new SAXException("ISO-8859-1 encoding not present", e); } finally { method.releaseConnection(); m_headers = null; } } else if (name.equals(HEADER_TAG) && uri.equals(NS_URI)) { // dont do anything } else if (name.equals(BODY_TAG) && uri.equals(NS_URI)) { m_requestdocument = super.endRecording(); } else { super.endElement(uri, name, raw); } }
From source file:org.apache.cocoon.transformation.WebDAVTransformer.java
private void executeRequest(WebDAVRequestMethod method) throws SAXException { try {// www . j a v a2 s. co m client.executeMethod(method.getHostConfiguration(), method, m_state); super.contentHandler.startPrefixMapping("webdav", NS_URI); // start <response> AttributesImpl atts = new AttributesImpl(); atts.addCDATAAttribute(TARGET_ATTR, m_target); atts.addCDATAAttribute(METHOD_ATTR, m_method); super.contentHandler.startElement(NS_URI, RESPONSE_TAG, NS_PREFIX + RESPONSE_TAG, atts); atts.clear(); // <status> atts.addCDATAAttribute(CODE_ATTR, String.valueOf(method.getStatusCode())); atts.addCDATAAttribute(MSG_ATTR, method.getStatusText()); super.contentHandler.startElement(NS_URI, STATUS_TAG, NS_PREFIX + STATUS_TAG, atts); atts.clear(); super.contentHandler.endElement(NS_URI, STATUS_TAG, NS_PREFIX + STATUS_TAG); // <header>s Header[] headers = method.getResponseHeaders(); for (int i = 0; i < headers.length; i++) { atts.addCDATAAttribute(NAME_ATTR, headers[i].getName()); atts.addCDATAAttribute(VALUE_ATTR, headers[i].getValue()); super.contentHandler.startElement(NS_URI, HEADER_TAG, NS_PREFIX + HEADER_TAG, atts); atts.clear(); super.contentHandler.endElement(NS_URI, HEADER_TAG, NS_PREFIX + HEADER_TAG); } // response <body> final InputStream in = method.getResponseBodyAsStream(); if (in != null) { String mimeType = null; Header header = method.getResponseHeader("Content-Type"); if (header != null) { mimeType = header.getValue(); int pos = mimeType.indexOf(';'); if (pos != -1) { mimeType = mimeType.substring(0, pos); } } if (mimeType != null && mimeType.equals("text/xml")) { super.contentHandler.startElement(NS_URI, BODY_TAG, NS_PREFIX + BODY_TAG, atts); IncludeXMLConsumer consumer = new IncludeXMLConsumer(super.contentHandler); XMLizer xmlizer = null; try { xmlizer = (XMLizer) manager.lookup(XMLizer.ROLE); xmlizer.toSAX(in, mimeType, m_target, consumer); } catch (ServiceException ce) { throw new SAXException("Missing service dependency: " + XMLizer.ROLE, ce); } finally { manager.release(xmlizer); } super.contentHandler.endElement(NS_URI, BODY_TAG, NS_PREFIX + BODY_TAG); } } // end <response> super.contentHandler.endElement(NS_URI, RESPONSE_TAG, NS_PREFIX + RESPONSE_TAG); super.contentHandler.endPrefixMapping(NS_URI); } catch (HttpException e) { throw new SAXException("Error executing WebDAV request." + " Server responded " + e.getReasonCode() + " (" + e.getReason() + ") - " + e.getMessage(), e); } catch (IOException e) { throw new SAXException("Error executing WebDAV request", e); } }
From source file:org.apache.cocoon.transformation.XSLTTransformer.java
/** * Set the <code>XMLConsumer</code> that will receive XML data. *///from w ww. j av a2s . c om public void setConsumer(XMLConsumer consumer) { if (this.transformerHandler == null) { try { this.transformerHandler = this.xsltProcessor.getTransformerHandler(this.inputSource); } catch (XSLTProcessorException se) { // the exception will be thrown during startDocument() this.exceptionDuringSetConsumer = new SAXException( "Unable to get transformer handler for " + this.inputSource.getURI(), se); return; } } final Map map = getLogicSheetParameters(); if (map != null) { final javax.xml.transform.Transformer transformer = this.transformerHandler.getTransformer(); final Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry entry = (Entry) iterator.next(); transformer.setParameter((String) entry.getKey(), entry.getValue()); } } super.setContentHandler(this.transformerHandler); super.setLexicalHandler(this.transformerHandler); // Is there even single implementation of LogEnabled TransformerHandler? if (this.transformerHandler instanceof LogEnabled) { ((LogEnabled) this.transformerHandler).enableLogging(new CLLoggerWrapper(getLogger())); } // According to TrAX specs, all TransformerHandlers are LexicalHandlers final SAXResult result = new SAXResult(consumer); result.setLexicalHandler(consumer); this.transformerHandler.setResult(result); this.errorListener = new TraxErrorListener(this.inputSource.getURI()); this.transformerHandler.getTransformer().setErrorListener(this.errorListener); }
From source file:org.apache.cocoon.xml.XMLBaseSupport.java
/** * Warning: do not forget to release the source returned by this method. *//*from www .java 2 s .c o m*/ private Source resolve(String baseURI, String location) throws SAXException { try { Source source; if (baseURI != null) { source = resolver.resolveURI(location, baseURI, Collections.EMPTY_MAP); } else { source = resolver.resolveURI(location); } if (logger.isDebugEnabled()) { logger.debug("XMLBaseSupport: resolved location " + location + " against base URI " + baseURI + " to " + source.getURI()); } return source; } catch (IOException e) { throw new SAXException("XMLBaseSupport: problem resolving uri.", e); } }
From source file:org.apache.fop.render.afp.extensions.AFPExtensionHandler.java
/** {@inheritDoc} */ @Override/*from w ww. j a va 2 s .co m*/ public void endElement(String uri, String localName, String qName) throws SAXException { if (AFPExtensionAttachment.CATEGORY.equals(uri)) { if (AFPElementMapping.INCLUDE_FORM_MAP.equals(localName)) { AFPIncludeFormMap formMap = new AFPIncludeFormMap(); String name = lastAttributes.getValue("name"); formMap.setName(name); String src = lastAttributes.getValue("src"); try { formMap.setSrc(new URI(src)); } catch (URISyntaxException e) { throw new SAXException("Invalid URI: " + src, e); } this.returnedObject = formMap; } else if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(localName)) { this.returnedObject = new AFPPageOverlay(); String name = lastAttributes.getValue("name"); if (name != null) { returnedObject.setName(name); } } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(localName)) { AFPPageSegmentSetup pageSetupExtn = null; pageSetupExtn = new AFPPageSegmentSetup(localName); this.returnedObject = pageSetupExtn; String name = lastAttributes.getValue("name"); if (name != null) { returnedObject.setName(name); } String value = lastAttributes.getValue("value"); if (value != null && pageSetupExtn != null) { pageSetupExtn.setValue(value); } String resourceSrc = lastAttributes.getValue("resource-file"); if (resourceSrc != null && pageSetupExtn != null) { pageSetupExtn.setResourceSrc(resourceSrc); } if (content.length() > 0 && pageSetupExtn != null) { pageSetupExtn.setContent(content.toString()); content.setLength(0); //Reset text buffer (see characters()) } } else { AFPPageSetup pageSetupExtn = null; if (AFPElementMapping.INVOKE_MEDIUM_MAP.equals(localName)) { this.returnedObject = new AFPInvokeMediumMap(); } else { pageSetupExtn = new AFPPageSetup(localName); this.returnedObject = pageSetupExtn; } String name = lastAttributes.getValue(AFPPageSetup.ATT_NAME); if (name != null) { returnedObject.setName(name); } String value = lastAttributes.getValue(AFPPageSetup.ATT_VALUE); if (value != null && pageSetupExtn != null) { pageSetupExtn.setValue(value); } String placement = lastAttributes.getValue(AFPPageSetup.ATT_PLACEMENT); if (placement != null && placement.length() > 0) { pageSetupExtn.setPlacement(ExtensionPlacement.fromXMLValue(placement)); } if (content.length() > 0 && pageSetupExtn != null) { pageSetupExtn.setContent(content.toString()); content.setLength(0); //Reset text buffer (see characters()) } } } }
From source file:org.apache.geode.internal.cache.xmlcache.CacheXmlParser.java
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { // This while loop pops all StringBuffers at the top of the stack // that contain only whitespace; see GEODE-3306 while (!stack.empty()) { Object o = stack.peek();/* w ww. j av a 2s .c o m*/ if (o instanceof StringBuffer && StringUtils.isBlank(((StringBuffer) o).toString())) { stack.pop(); } else { break; } } try { // logger.debug("endElement namespaceURI=" + namespaceURI // + "; localName = " + localName + "; qName = " + qName); if (qName.equals(CACHE)) { endCache(); } else if (qName.equals(CLIENT_CACHE)) { endClientCache(); } else if (qName.equals(BRIDGE_SERVER)) { endCacheServer(); } else if (qName.equals(CACHE_SERVER)) { endCacheServer(); } else if (qName.equals(LOAD_PROBE)) { endLoadProbe(); } else if (qName.equals(CLIENT_SUBSCRIPTION)) { endClientHaQueue(); } else if (qName.equals(CONNECTION_POOL)) { endPool(); } else if (qName.equals(DYNAMIC_REGION_FACTORY)) { endDynamicRegionFactory(); } else if (qName.equals(GATEWAY_SENDER)) { endSerialGatewaySender(); } else if (qName.equals(GATEWAY_RECEIVER)) { endGatewayReceiver(); } else if (qName.equals(GATEWAY_EVENT_FILTER)) { endGatewayEventFilter(); } else if (qName.equals(GATEWAY_EVENT_SUBSTITUTION_FILTER)) { endGatewayEventSubstitutionFilter(); } else if (qName.equals(GATEWAY_TRANSPORT_FILTER)) { endGatewayTransportFilter(); } else if (qName.equals(ASYNC_EVENT_QUEUE)) { endAsyncEventQueue(); } else if (qName.equals(REGION)) { endRegion(); } else if (qName.equals(GATEWAY_CONFLICT_RESOLVER)) { endGatewayConflictResolver(); } else if (qName.equals(VM_ROOT_REGION)) { endRegion(); } else if (qName.equals(REGION_ATTRIBUTES)) { endRegionAttributes(); } else if (qName.equals(DISK_STORE)) { endDiskStore(); } else if (qName.equals(KEY_CONSTRAINT)) { endKeyConstraint(); } else if (qName.equals(VALUE_CONSTRAINT)) { endValueConstraint(); } else if (qName.equals(REGION_TIME_TO_LIVE)) { endRegionTimeToLive(); } else if (qName.equals(REGION_IDLE_TIME)) { endRegionIdleTime(); } else if (qName.equals(ENTRY_TIME_TO_LIVE)) { endEntryTimeToLive(); } else if (qName.equals(ENTRY_IDLE_TIME)) { endEntryIdleTime(); } else if (qName.equals(CUSTOM_EXPIRY)) { endCustomExpiry(); } else if (qName.equals(DISK_WRITE_ATTRIBUTES)) { endDiskWriteAttributes(); } else if (qName.equals(SYNCHRONOUS_WRITES)) { } else if (qName.equals(ASYNCHRONOUS_WRITES)) { } else if (qName.equals(DISK_DIRS)) { endDiskDirs(); } else if (qName.equals(DISK_DIR)) { endDiskDir(); } else if (qName.equals(GROUP)) { endGroup(); } else if (qName.equals(PARTITION_ATTRIBUTES)) { endPartitionAttributes(); } else if (qName.equals(FIXED_PARTITION_ATTRIBUTES)) { endFixedPartitionAttributes(); } else if (qName.equals(LOCAL_PROPERTIES)) { endPartitionProperites(LOCAL_PROPERTIES); } else if (qName.equals(GLOBAL_PROPERTIES)) { endPartitionProperites(GLOBAL_PROPERTIES); } else if (qName.equals(MEMBERSHIP_ATTRIBUTES)) { endMembershipAttributes(); } else if (qName.equals(REQUIRED_ROLE)) { endRequiredRole(); } else if (qName.equals(EXPIRATION_ATTRIBUTES)) { } else if (qName.equals(CUSTOM_EXPIRY)) { endCustomExpiry(); } else if (qName.equals(SUBSCRIPTION_ATTRIBUTES)) { } else if (qName.equals(ENTRY)) { endEntry(); } else if (qName.equals(CLASS_NAME)) { endClassName(); } else if (qName.equals(PARAMETER)) { endParameter(); } else if (qName.equals(CACHE_LOADER)) { endCacheLoader(); } else if (qName.equals(CACHE_WRITER)) { endCacheWriter(); } else if (qName.equals(EVICTION_ATTRIBUTES)) { } else if (qName.equals(LRU_ENTRY_COUNT)) { // internal to eviction-attributes } else if (qName.equals(LRU_MEMORY_SIZE)) { endLRUMemorySize(); // internal to eviction-attributes } else if (qName.equals(LRU_HEAP_PERCENTAGE)) { endLRUHeapPercentage(); // internal to eviction-attributes } else if (qName.equals(CACHE_LISTENER)) { endCacheListener(); } else if (qName.equals(ASYNC_EVENT_LISTENER)) { endAsyncEventListener(); } else if (qName.equals(KEY)) { } else if (qName.equals(VALUE)) { } else if (qName.equals(STRING)) { endString(); } else if (qName.equals(DECLARABLE)) { endDeclarable(); } else if (qName.equals(FUNCTIONAL)) { } else if (qName.equals(INDEX)) { endIndex(); } else if (qName.equals(PRIMARY_KEY)) { } else if (qName.equals(TRANSACTION_MANAGER)) { endCacheTransactionManager(); } else if (qName.equals(TRANSACTION_LISTENER)) { endTransactionListener(); } else if (qName.equals(TRANSACTION_WRITER)) { endTransactionWriter(); } else if (qName.equals(JNDI_BINDINGS)) { } else if (qName.equals(JNDI_BINDING)) { // Asif Pop the BindingCreation object BindingCreation bc = (BindingCreation) this.stack.pop(); JNDIInvoker.mapDatasource(bc.getGFSpecificMap(), bc.getVendorSpecificList()); } else if (qName.equals(CONFIG_PROPERTY_BINDING)) { } else if (qName.equals(CONFIG_PROPERTY_NAME)) { String name = null; if (this.stack.peek() instanceof StringBuffer) // Pop the config-property-name element value from the stack. name = ((StringBuffer) this.stack.pop()).toString(); BindingCreation bc = (BindingCreation) this.stack.peek(); List vsList = bc.getVendorSpecificList(); ConfigProperty cp = (ConfigProperty) vsList.get(vsList.size() - 1); if (name == null) { String excep = LocalizedStrings.CacheXmlParser_EXCEPTION_IN_PARSING_ELEMENT_0_THIS_IS_A_REQUIRED_FIELD .toLocalizedString(qName); throw new CacheXmlException(excep); } else { // set the name. cp.setName(name); } } else if (qName.equals(CONFIG_PROPERTY_VALUE)) { String value = null; // Pop the config-property-value element value from the stack. if (this.stack.peek() instanceof StringBuffer) value = ((StringBuffer) this.stack.pop()).toString(); BindingCreation bc = (BindingCreation) this.stack.peek(); List vsList = bc.getVendorSpecificList(); ConfigProperty cp = (ConfigProperty) vsList.get(vsList.size() - 1); // Set the value to the ConfigProperty Data Object. cp.setValue(value); } else if (qName.equals(CONFIG_PROPERTY_TYPE)) { String type = null; if (this.stack.peek() instanceof StringBuffer) type = ((StringBuffer) this.stack.pop()).toString(); BindingCreation bc = (BindingCreation) this.stack.peek(); List vsList = bc.getVendorSpecificList(); ConfigProperty cp = (ConfigProperty) vsList.get(vsList.size() - 1); if (type == null) { String excep = LocalizedStrings.CacheXmlParser_EXCEPTION_IN_PARSING_ELEMENT_0_THIS_IS_A_REQUIRED_FIELD .toLocalizedString(qName); throw new CacheXmlException(excep); } else { cp.setType(type); } } else if (qName.equals(LRU_MEMORY_SIZE)) { // internal to eviction-attributes // Visit startLRUMemorySize() to know the begining // of lru-memory-size eviction configuration endLRUMemorySize(); } else if (qName.equals(LOCATOR)) { // nothing needed } else if (qName.equals(SERVER)) { // nothing needed } else if (qName.equals(PARTITION_RESOLVER)) { endPartitionResolver(); } else if (qName.equals(PARTITION_LISTENER)) { endPartitionListener(); } else if (qName.equals(FUNCTION)) { endFunctionName(); } else if (qName.equals(FUNCTION_SERVICE)) { endFunctionService(); } else if (qName.equals(TOP_SERIALIZER_REGISTRATION)) { endSerializerRegistration(); } else if (qName.equals(INITIALIZER)) { endInitializer(); } else if (qName.equals(SERIALIZER_REGISTRATION)) { endSerializer(); } else if (qName.equals(INSTANTIATOR_REGISTRATION)) { endInstantiator(); } else if (qName.equals(RESOURCE_MANAGER)) { endResourceManager(); } else if (qName.equals(BACKUP)) { endBackup(); } else if (qName.equals(PDX)) { // nothing needed } else if (qName.equals(PDX_SERIALIZER)) { endPdxSerializer(); } else if (qName.equals(COMPRESSOR)) { endCompressor(); } else { final XmlParser delegate = getDelegate(namespaceURI); if (null == delegate) { throw new CacheXmlException( LocalizedStrings.CacheXmlParser_UNKNOWN_XML_ELEMENT_0.toLocalizedString(qName)); } delegate.endElement(namespaceURI, localName, qName); } } catch (CacheException ex) { throw new SAXException(LocalizedStrings.CacheXmlParser_A_CACHEEXCEPTION_WAS_THROWN_WHILE_PARSING_XML .toLocalizedString(), ex); } }
From source file:org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl.java
/** * Registers the node types defined in the given XML stream. This * is a trivial implementation that just invokes the existing * {@link NodeTypeReader} and {@link NodeTypeRegistry} methods and * heuristically creates the returned node type array. It will also * register any namespaces defined in the input source that have not * already been registered./* w w w . java2 s . c om*/ * * {@inheritDoc} */ public NodeType[] registerNodeTypes(InputSource in) throws SAXException, RepositoryException { try { return registerNodeTypes(in.getByteStream(), TEXT_XML); } catch (IOException e) { throw new SAXException("Error reading node type stream", e); } }