List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.apache.cayenne.map.MapLoader.java
private void processStartProcedureParameter(Attributes attributes) throws SAXException { String name = attributes.getValue("", "name"); if (name == null) { throw new SAXException( "MapLoader::processStartProcedureParameter()," + " no procedure parameter name."); }//ww w . ja va 2 s . c om ProcedureParameter parameter = new ProcedureParameter(name); String type = attributes.getValue("", "type"); if (type != null) { parameter.setType(TypesMapping.getSqlTypeByName(type)); } String length = attributes.getValue("", "length"); if (length != null) { parameter.setMaxLength(Integer.parseInt(length)); } String precision = attributes.getValue("", "precision"); if (precision != null) { parameter.setPrecision(Integer.parseInt(precision)); } String direction = attributes.getValue("", "direction"); if ("in".equals(direction)) { parameter.setDirection(ProcedureParameter.IN_PARAMETER); } else if ("out".equals(direction)) { parameter.setDirection(ProcedureParameter.OUT_PARAMETER); } else if ("in_out".equals(direction)) { parameter.setDirection(ProcedureParameter.IN_OUT_PARAMETER); } procedure.addCallParameter(parameter); }
From source file:org.apache.cayenne.map.MapLoader.java
private void processStartQuery(Attributes attributes) throws SAXException { String name = attributes.getValue("", "name"); if (null == name) { throw new SAXException("MapLoader::processStartQuery(), no query name."); }// ww w . j a v a 2s . co m String builder = attributes.getValue("", "factory"); if (builder == null) { builder = SelectQueryBuilder.class.getName(); } else { // TODO: this is a hack to migrate between 1.1M6 and 1.1M7... // remove this at some point if (builder.equals("org.objectstyle.cayenne.query.SelectQueryBuilder")) { builder = SelectQueryBuilder.class.getName(); } // upgrade from v. <= 1.2 else { builder = convertClassNameFromV1_2(builder); } } try { queryBuilder = (QueryLoader) Class.forName(builder).newInstance(); } catch (Exception ex) { throw new SAXException("MapLoader::processStartQuery(), invalid query builder: " + builder); } String rootType = attributes.getValue("", "root"); String rootName = attributes.getValue("", "root-name"); String resultEntity = attributes.getValue("", "result-entity"); queryBuilder.setName(name); queryBuilder.setRoot(dataMap, rootType, rootName); // TODO: Andrus, 2/13/2006 'result-type' is only used in ProcedureQuery and is // deprecated in 1.2 if (!Util.isEmptyString(resultEntity)) { queryBuilder.setResultEntity(resultEntity); } }
From source file:org.apache.cayenne.map.MapLoader.java
private void processStartQueryProperty(Attributes attributes) throws SAXException { String name = attributes.getValue("", "name"); if (null == name) { throw new SAXException("MapLoader::processStartQueryProperty(), no property name."); }/*from w w w . jav a 2s .com*/ String value = attributes.getValue("", "value"); if (null == value) { throw new SAXException("MapLoader::processStartQueryProperty(), no property value."); } queryBuilder.addProperty(name, value); }
From source file:org.apache.cayenne.map.MapLoader.java
private void processStartDataMapProperty(Attributes attributes) throws SAXException { String name = attributes.getValue("", "name"); if (null == name) { throw new SAXException("MapLoader::processStartDataMapProperty(), no property name."); }//www .ja v a2 s. com String value = attributes.getValue("", "value"); if (null == value) { throw new SAXException("MapLoader::processStartDataMapProperty(), no property value."); } if (mapProperties == null) { mapProperties = new TreeMap<String, Object>(); } mapProperties.put(name, value); }
From source file:org.apache.cocoon.components.serializers.XMLSerializer.java
/** * Receive notification of the beginning of the document body. * * @param uri The namespace URI of the root element. * @param local The local name of the root element. * @param qual The fully-qualified name of the root element. *//*from ww w.j av a 2s.co m*/ public void body(String uri, String local, String qual) throws SAXException { this.processing_prolog = false; this.writeln(); /* We have a document type. */ if (this.doctype != null) { String root_name = this.doctype.getName(); /* Check the DTD and the root element */ if (!root_name.equals(qual)) { throw new SAXException( "Root element name \"" + root_name + "\" declared by document type declaration differs " + "from actual root element name \"" + qual + "\""); } /* Output the <!DOCTYPE ...> declaration. */ this.write(this.doctype.toString()); } /* Output all PIs and comments we cached in the prolog */ this.prolog.writeTo(this); this.writeln(); }
From source file:org.apache.cocoon.components.source.impl.XModuleSource.java
/** * Implement this method to obtain SAX events. * *///from w ww .ja va 2 s .c o m public void toSAX(ContentHandler handler) throws SAXException { Object obj = getInputAttribute(this.attributeType, this.attributeName); if (obj == null) throw new SAXException(" The attribute: " + this.attributeName + " is empty"); if (!(this.xPath.length() == 0 || this.xPath.equals("/"))) { JXPathContext context = JXPathContext.newContext(obj); obj = context.getPointer(this.xPath).getNode(); if (obj == null) throw new SAXException("the xpath: " + this.xPath + " applied on the attribute: " + this.attributeName + " returns null"); } if (obj instanceof Document) { DOMStreamer domStreamer = new DOMStreamer(handler); domStreamer.stream((Document) obj); } else if (obj instanceof Node) { DOMStreamer domStreamer = new DOMStreamer(handler); handler.startDocument(); domStreamer.stream((Node) obj); handler.endDocument(); } else if (obj instanceof XMLizable) { ((XMLizable) obj).toSAX(handler); } else { throw new SAXException( "The object type: " + obj.getClass() + " could not be serialized to XML: " + obj); } }
From source file:org.apache.cocoon.components.source.impl.XModuleSource.java
public void notify(Document insertDoc) throws SAXException { // handle xpaths, we are only handling inserts, i.e. if there is no // attribute of the given name and type the operation will fail if (!(this.xPath.length() == 0 || this.xPath.equals("/"))) { Object value = getInputAttribute(this.attributeType, this.attributeName); if (value == null) throw new SAXException(" The attribute: " + this.attributeName + " is empty"); JXPathContext context = JXPathContext.newContext(value); if (value instanceof Document) { // If the attribute contains a dom document we // create the elements in the given xpath if // necesary, import the input document and put it // in the place described by the xpath. Document doc = (Document) value; Node importedNode = doc.importNode(insertDoc.getDocumentElement(), true); context.setLenient(true);/* w ww .j ava 2 s .c o m*/ context.setFactory(new DOMFactory()); context.createPathAndSetValue(this.xPath, importedNode); } else { // Otherwise just try to put a the input document in // the place pointed to by the xpath context.setValue(this.xPath, insertDoc); } } else { setOutputAttribute(this.attributeType, this.attributeName, insertDoc); } }
From source file:org.apache.cocoon.environment.AbstractEnvironment.java
/** * Resolve an entity./*from w w w . ja v a2 s.c o m*/ * @deprecated Use the resolveURI methods instead */ public Source resolve(String systemId) throws ProcessingException, SAXException, IOException { Deprecation.logger.warn( "The method SourceResolver.resolve(String) is " + "deprecated. Use resolveURI(String) instead."); if (!this.initializedComponents) { initComponents(); } if (getLogger().isDebugEnabled()) { getLogger().debug("Resolving '" + systemId + "' in context '" + this.context + "'"); } if (systemId == null) { throw new SAXException("Invalid System ID"); } // get the wrapper class - we don't want to import the wrapper directly // to avoid a direct dependency from the core to the deprecation package Class clazz; try { clazz = ClassUtils .loadClass("org.apache.cocoon.components.source.impl.AvalonToCocoonSourceInvocationHandler"); } catch (Exception e) { throw new ProcessingException("The deprecated resolve() method of the environment was called." + "Please either update your code to use the new resolveURI() method or" + " install the deprecation support.", e); } if (null == avalonToCocoonSourceWrapper) { synchronized (getClass()) { try { avalonToCocoonSourceWrapper = clazz.getDeclaredMethod("createProxy", new Class[] { ClassUtils.loadClass("org.apache.excalibur.source.Source"), ClassUtils.loadClass("org.apache.excalibur.source.SourceResolver"), ClassUtils.loadClass(Environment.class.getName()), ClassUtils.loadClass(ComponentManager.class.getName()) }); } catch (Exception e) { throw new ProcessingException("The deprecated resolve() method of the environment was called." + "Please either update your code to use the new resolveURI() method or" + " install the deprecation support.", e); } } } try { org.apache.excalibur.source.Source source = resolveURI(systemId); Source wrappedSource = (Source) avalonToCocoonSourceWrapper.invoke(clazz, new Object[] { source, this.sourceResolver, this, this.manager }); return wrappedSource; } catch (SourceException se) { throw SourceUtil.handle(se); } catch (Exception e) { throw new ProcessingException("Unable to create source wrapper.", e); } }
From source file:org.apache.cocoon.forms.datatype.FlowJXPathSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { JXPathContext ctx = null;// w w w . j a v a 2 s .c om Iterator iter = null; if (model == null) { Object flowData = FlowHelper.getContextObject(ContextHelper.getObjectModel(this.context)); if (flowData == null) { throw new SAXException("No flow data to produce selection list"); } // Move to the list location ctx = JXPathContext.newContext(flowData); // Iterate on all elements of the list iter = ctx.iteratePointers(this.listPath); } else { // Move to the list location ctx = JXPathContext.newContext(model); // Iterate on all elements of the list iter = ctx.iteratePointers("."); } // Start the selection-list contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); if (this.nullable) { final AttributesImpl voidAttrs = new AttributesImpl(); voidAttrs.addCDATAAttribute("value", ""); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs); if (this.nullText != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); if (this.nullTextIsI18nKey) { if ((this.i18nCatalog != null) && (this.i18nCatalog.trim().length() > 0)) { new I18nMessage(this.nullText, this.i18nCatalog).toSAX(contentHandler); } else { new I18nMessage(this.nullText).toSAX(contentHandler); } } else { contentHandler.characters(this.nullText.toCharArray(), 0, this.nullText.length()); } contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } while (iter.hasNext()) { String stringValue = ""; Object label = null; // Get a context on the current item Pointer ptr = (Pointer) iter.next(); if (ptr.getValue() != null) { JXPathContext itemCtx = ctx.getRelativeContext(ptr); // Get the value as a string Object value = itemCtx.getValue(this.valuePath); // List may contain null value, and (per contract with convertors), // convertors are not invoked on nulls. if (value != null) { stringValue = this.datatype.convertToString(value, locale); } // Get the label (can be ommitted) itemCtx.setLenient(true); label = itemCtx.getValue(this.labelPath); if (label == null) { label = stringValue; } } // Output this item AttributesImpl itemAttrs = new AttributesImpl(); itemAttrs.addCDATAAttribute("value", stringValue); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, itemAttrs); if (label != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); if (label instanceof XMLizable) { ((XMLizable) label).toSAX(contentHandler); } else if (this.labelIsI18nKey) { String stringLabel = label.toString(); if ((this.i18nCatalog != null) && (this.i18nCatalog.trim().length() > 0)) { new I18nMessage(stringLabel, this.i18nCatalog).toSAX(contentHandler); } else { new I18nMessage(stringLabel).toSAX(contentHandler); } } else { String stringLabel = label.toString(); contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length()); } contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } // End the selection-list contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); }
From source file:org.apache.cocoon.forms.transformation.EffectWidgetReplacingPipe.java
/** * Get value of the required attribute/*from w w w . j a v a2 s . c o m*/ */ protected String getAttributeValue(String loc, Attributes attrs, String name) throws SAXException { String value = attrs.getValue(name); if (value == null) { throw new SAXException( "Element '" + loc + "' missing required '" + name + "' attribute, " + "at " + getLocation()); } return value; }