List of usage examples for org.xml.sax Locator getLineNumber
public abstract int getLineNumber();
From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java
public static Map getSchemaRegistry(ServletContext servletContext) { Map schemas = (Map) servletContext.getAttribute(Constants.AA_SCHEMAS); if (schemas != null) return schemas; // Read in schemas for the topicmaps and provide them to the app context String schemasRootDir = servletContext.getInitParameter(Constants.SCTXT_SCHEMAS_ROOTDIR); if (schemasRootDir != null) schemasRootDir = servletContext.getRealPath(schemasRootDir); schemas = new HashMap(); if (schemasRootDir == null) { servletContext.setAttribute(Constants.AA_SCHEMAS, schemas); log.debug("No schema directory configured; registry empty"); return schemas; }// w w w. jav a2 s . c o m log.debug("Reading schemas from " + schemasRootDir); TopicMapRepositoryIF repository = NavigatorUtils.getTopicMapRepository(servletContext); Collection refkeys = repository.getReferenceKeys(); Iterator iter = refkeys.iterator(); while (iter.hasNext()) { String refkey = (String) iter.next(); TopicMapReferenceIF reference = repository.getReferenceByKey(refkey); String tmid = reference.getId(); try { OSLSchemaReader reader = new OSLSchemaReader(new File(schemasRootDir, tmid + ".osl")); OSLSchema schema = (OSLSchema) reader.read(); schemas.put(tmid, schema); log.info("Loaded schema for " + tmid); } catch (java.io.IOException e) { log.info("Warning: " + e.getMessage()); } catch (SchemaSyntaxException e) { log.error("Schema syntax error: " + e.getMessage()); Locator loc = e.getErrorLocation(); log.error("Location: " + loc.getSystemId() + ":" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "."); } } servletContext.setAttribute(Constants.AA_SCHEMAS, schemas); return schemas; }
From source file:com.netspective.axiom.schema.transport.DataException.java
public DataException(Locator locator, Throwable cause) { super(locator.getSystemId() + " at " + locator.getLineNumber(), cause); }
From source file:MyContentHandler.java
public void setDocumentLocator(Locator locator) { this.locator = locator; System.out.println("-" + locator.getLineNumber() + "---Document ID: " + locator.getSystemId()); }
From source file:Main.java
/** * The name and of the SAX document and the current location within the * document.// ww w . ja v a2s. c om */ public void setDocumentLocator(Locator locator) { this.locator = locator; System.out.println("-" + locator.getLineNumber() + "---Document ID: " + locator.getSystemId()); }
From source file:com.jaspersoft.ireport.designer.compiler.xml.SourceTraceDigester.java
protected SourceLocation currentLocation() { Locator documentLocator = getDocumentLocator(); SourceLocation location = new SourceLocation(); location.setLineNumber(documentLocator.getLineNumber()); location.setColumnNumber(documentLocator.getColumnNumber()); location.setXPath(elementStack.getCurrentPath()); return location; }
From source file:com.netspective.commons.xdm.XdmHandler.java
public void endElement(String url, String localName, String qName) throws SAXException { if (handleDefaultEndElement(url, localName, qName)) return;//w w w. j a va2 s . c om if (inAttrSetterTextEntry != null) { inAttrSetterTextEntry = null; return; } if (!getTemplateDefnStack().isEmpty()) { Object templateNode = getTemplateDefnStack().pop(); // if, after popping the stack, the stack is empty it means we're at the root template definition element if (getTemplateDefnStack().isEmpty()) { // now that we have finished "recording" the template, see if we're supposed to treat this template // as an object/instance also -- if we are, immediately apply the template at the active entry level Template template = (Template) templateNode; if (template.getTemplateProducer().isUnmarshallContents()) { unmarshallingTemplate = true; XdmHandlerNodeStackEntry activeEntry = (XdmHandlerNodeStackEntry) getNodeStack().peek(); template.applySelfAndChildren(template.createApplyContext(this, activeEntry.getElementName(), activeEntry.getAttributes())); unmarshallingTemplate = false; } } } else if (!getIgnoreStack().isEmpty()) getIgnoreStack().pop(); else { try { XdmHandlerNodeStackEntry activeEntry = (XdmHandlerNodeStackEntry) getNodeStack().peek(); if (activeEntry != null) { if (activeEntry.getInstance() instanceof XmlDataModelSchema.InputSourceLocatorListener) { InputSourceLocator isl = ((XmlDataModelSchema.InputSourceLocatorListener) activeEntry .getInstance()).getInputSourceLocator(); final Locator locator = getParseContext().getLocator(); if (isl != null) isl.setEndLine(locator.getLineNumber(), locator.getColumnNumber()); } activeEntry.getSchema().finalizeElementConstruction(((XdmParseContext) getParseContext()), activeEntry.getInstance(), activeEntry.getElementName()); } getNodeStack().pop(); } catch (DataModelException e) { throw new SAXException(e.getMessage() + " " + getStateText(), e); } } }
From source file:com.sun.faces.config.rules.ManagedBeanRule.java
/** * <p>Provides simple sanity checks.</p> * * @param bean the <code>ManagedBeanBean</code> instance to validate *//* w w w . j ava2 s . c om*/ private void validate(ManagedBeanBean bean) { String val = bean.getManagedBeanName(); if (val == null || val.length() == 0) { Locator locator = digester.getDocumentLocator(); String documentName = "UNKNOWN"; String lineNumber = "UNKNWOWN"; if (locator != null) { documentName = locator.getSystemId(); lineNumber = Integer.toString(locator.getLineNumber()); } throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_NO_MANAGED_BEAN_NAME_ID, new Object[] { documentName, lineNumber })); } val = bean.getManagedBeanClass(); if (val == null || val.length() == 0) { throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_NO_MANAGED_BEAN_CLASS_ID, new Object[] { bean.getManagedBeanName() })); } val = bean.getManagedBeanScope(); if (val == null || val.length() == 0) { throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_NO_MANAGED_BEAN_SCOPE_ID, new Object[] { bean.getManagedBeanName() })); } if (Arrays.binarySearch(SCOPES, val) < 0) { throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_INVALID_SCOPE_ID, new Object[] { val, bean.getManagedBeanName() })); } // - if the managed bean is itself a List, make sure it has no // map entries or managed properties // - if the managed bean is itself a Map, make sure it has no // managed properties if (bean.getListEntries() != null) { if (bean.getMapEntries() != null || bean.getManagedProperties().length != 0) { throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_AS_LIST_CONFIG_ERROR_ID, new Object[] { bean.getManagedBeanName() })); } } else if (bean.getMapEntries() != null) { if (bean.getManagedProperties().length != 0) { throw new IllegalStateException(ToolsUtil.getMessage(ToolsUtil.MANAGED_BEAN_AS_MAP_CONFIG_ERROR_ID, new Object[] { bean.getManagedBeanName() })); } } }
From source file:com.netspective.commons.xdm.XdmHandler.java
private boolean handleTemplateStartElement(XdmHandlerNodeStackEntry activeEntry, String url, String localName, String qName, Attributes attributes) throws SAXException { if (defaultHandleTemplateStartElement(url, localName, qName, attributes)) return true; String elementName = qName.toLowerCase(); if (activeEntry.getInstance() instanceof TemplateProducerParent) { TemplateProducers templateProducers = ((TemplateProducerParent) activeEntry.getInstance()) .getTemplateProducers(); TemplateProducer tp = templateProducers.get(elementName); if (tp != null) { String templateName = tp.getTemplateName(url, localName, qName, attributes); final Locator locator = getParseContext().getLocator(); InputSourceLocator inputSourceLocator = new InputSourceLocator( getParseContext().getInputSrcTracker(), locator.getLineNumber(), locator.getColumnNumber()); Template template = new Template(templateName, this, inputSourceLocator, getParseContext().getTemplateCatalog(), tp, url, localName, qName, attributes); getParseContext().getTemplateCatalog().registerTemplate(tp, templateName, template); getTemplateDefnStack().push(template); return true; }/*from w ww . j ava 2s .co m*/ } return false; }
From source file:com.netspective.commons.xml.AbstractContentHandler.java
protected boolean defaultHandleTemplateStartElement(String url, String localName, String qName, Attributes attributes) throws SAXException { String elementName = qName.toLowerCase(); if (!templateDefnStack.isEmpty()) { // we're inside a template already so just grab the contents TemplateElement activeTemplate = (TemplateElement) templateDefnStack.peek(); if (nodeIdentifiers.getTemplateParamDecl().equals(elementName)) { if (activeTemplate instanceof Template) { ((Template) activeTemplate).declareParameter(this, url, localName, qName, attributes); templateDefnStack.push(activeTemplate); } else throw new SAXParseException( "<" + nodeIdentifiers.getTemplateParamDecl() + "> not allowed here.", parseContext.getLocator()); } else {//from ww w .ja v a2s. co m TemplateElement childNode = new TemplateElement(this, url, localName, qName, attributes); activeTemplate.addChild(childNode); templateDefnStack.push(childNode); } return true; } else if (elementName.equals(nodeIdentifiers.getTemplateElementName())) { String templateName = attributes.getValue(NodeIdentifiers.ATTRNAME_GENERIC_TEMPLATE_NAME); if (templateName == null || templateName.length() == 0) throw new SAXParseException("Template must have a '" + NodeIdentifiers.ATTRNAME_GENERIC_TEMPLATE_NAME + "' attribute in <" + elementName + "> ", parseContext.getLocator()); final Locator locator = getParseContext().getLocator(); InputSourceLocator inputSourceLocator = new InputSourceLocator(getParseContext().getInputSrcTracker(), locator.getLineNumber(), locator.getColumnNumber()); Template template = new Template(templateName, this, inputSourceLocator, parseContext.getTemplateCatalog(), nodeIdentifiers.getGenericTemplateProducer(), url, localName, qName, attributes); parseContext.getTemplateCatalog().registerTemplate(nodeIdentifiers.getGenericTemplateProducer(), templateName, template); templateDefnStack.push(template); return true; } else return false; }
From source file:com.netspective.commons.xdm.XdmHandler.java
public void startElement(String url, String localName, String qName, Attributes attributes) throws SAXException { //System.out.println(getStackDepthPrefix() + qName + " " + getAttributeNames(attributes)); if (handleDefaultStartElement(url, localName, qName, attributes)) return;//from ww w.j av a 2s .c om String elementName = qName.toLowerCase(); XdmHandlerNodeStackEntry activeEntry = (XdmHandlerNodeStackEntry) getNodeStack().peek(); if (!unmarshallingTemplate && handleTemplateStartElement(activeEntry, url, localName, qName, attributes)) return; if (elementName.equals(getNodeIdentifiers().getIncludeElementName())) { try { includeInputSource(activeEntry, attributes); setInInclude(true); return; } catch (Exception e) { throw new SAXException(e); } } if (activeEntry.getInstance() instanceof XmlDataModelSchema.InputSourceTrackerListener) { try { ((XmlDataModelSchema.InputSourceTrackerListener) activeEntry.getInstance()) .setInputSourceTracker(getParseContext().getInputSrcTracker()); } catch (Exception e) { throw new SAXException(e.getMessage() + " " + getStateText(), e); } } if (!getIgnoreStack().isEmpty() || activeEntry.getOptions().ignoreNestedElement(elementName)) { getIgnoreStack().push(elementName); } else { Object childInstance = null; XmlDataModelSchema activeSchema = activeEntry.getSchema(); TemplateConsumerDefn templateConsumer = null; List templatesToConsume = null; try { String alternateClassName = attributes.getValue(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME); childInstance = activeSchema.createElement(((XdmParseContext) getParseContext()), alternateClassName, activeEntry.getInstance(), elementName, false); boolean inAttrSetterText = childInstance == activeEntry.getInstance(); if (childInstance != null && !inAttrSetterText) { // see if we have any templates that need to be applied if (childInstance instanceof TemplateConsumer) { // check to see if we don't have our own alternate class but one of our the templates we're about to apply want to override our class templateConsumer = ((TemplateConsumer) childInstance).getTemplateConsumerDefn(); templatesToConsume = templateConsumer.getTemplatesToApply(this, elementName, attributes); if (alternateClassName == null) { alternateClassName = templateConsumer.getAlternateClassName(this, templatesToConsume, elementName, attributes); if (alternateClassName != null) childInstance = activeSchema.createElement(((XdmParseContext) getParseContext()), alternateClassName, activeEntry.getInstance(), elementName, false); } } } if (childInstance == null) { getIgnoreStack().push(elementName); return; } if (inAttrSetterText) { inAttrSetterTextEntry = new XdmHandlerNodeStackEntry(elementName, attributes, childInstance); return; } } catch (DataModelException e) { log.error(e.getMessage() + " " + getStateText(), e); throw new SAXException(e.getMessage() + " " + getStateText(), e); } if (childInstance != null) { if (childInstance instanceof XmlDataModelSchema.InputSourceLocatorListener) { final Locator locator = getParseContext().getLocator(); ((XmlDataModelSchema.InputSourceLocatorListener) childInstance) .setInputSourceLocator(new InputSourceLocator(getParseContext().getInputSrcTracker(), locator.getLineNumber(), locator.getColumnNumber())); } XdmHandlerNodeStackEntry childEntry = null; try { childEntry = new XdmHandlerNodeStackEntry(elementName, attributes, childInstance); getNodeStack().push(childEntry); // if we're already inside a template, then check to see if we have any attributes that need their // expressions replaced TemplateApplyContext activeApplyTemplateContext = activeEntry.getActiveApplyContext(); if (activeApplyTemplateContext != null) { TemplateApplyContext.StackEntry atcEntry = activeApplyTemplateContext.getActiveEntry(); if (atcEntry != null && atcEntry.isReplacementExprsFoundInAttrs()) attributes = atcEntry.getActiveTemplate() .replaceAttributeExpressions(activeApplyTemplateContext); } // if the current element indicates the start of a template, apply it now if (templateConsumer != null && templatesToConsume != null) { String[] attrNamesToSet = templateConsumer.getAttrNamesToApplyBeforeConsuming(); if (attrNamesToSet != null) { for (int i = 0; i < attrNamesToSet.length; i++) { String attrValue = attributes.getValue(attrNamesToSet[i]); String lowerCaseAttrName = attrNamesToSet[i].toLowerCase(); childEntry.getSchema().setAttribute(((XdmParseContext) getParseContext()), childEntry.getInstance(), lowerCaseAttrName, attrValue, false); } } templateConsumer.consume(this, templatesToConsume, elementName, attributes); } for (int i = 0; i < attributes.getLength(); i++) { String origAttrName = attributes.getQName(i); String lowerCaseAttrName = origAttrName.toLowerCase(); if (!childEntry.getOptions().ignoreAttribute(lowerCaseAttrName) && !lowerCaseAttrName.equals(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME) && !(getNodeStack().size() < 3 && lowerCaseAttrName .startsWith(NodeIdentifiers.ATTRNAMEPREFIX_NAMESPACE_BINDING)) && !(templateConsumer != null && templateConsumer.isTemplateAttribute(origAttrName)) && !(origAttrName.startsWith(getNodeIdentifiers().getXmlNameSpacePrefix()))) childEntry.getSchema().setAttribute(((XdmParseContext) getParseContext()), childEntry.getInstance(), lowerCaseAttrName, attributes.getValue(i), false); } } catch (Exception e) { log.error(e.getMessage() + " " + getStateText(), e); throw new SAXException(e.getMessage() + " " + getStateText(), e); } try { activeEntry.getSchema().storeElement(((XdmParseContext) getParseContext()), activeEntry.getInstance(), childEntry.getInstance(), elementName, false); } catch (DataModelException e) { log.error(e.getMessage() + " " + getStateText(), e); throw new SAXException(e.getMessage() + " " + getStateText(), e); } } } }