Example usage for org.xml.sax Locator getColumnNumber

List of usage examples for org.xml.sax Locator getColumnNumber

Introduction

In this page you can find the example usage for org.xml.sax Locator getColumnNumber.

Prototype

public abstract int getColumnNumber();

Source Link

Document

Return the column number where the current document event ends.

Usage

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;
    }/*  ww  w  .jav  a2  s.com*/

    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.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;/*from  w w  w . j  ava2  s .c  o m*/

    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.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  w w. j  a  v  a  2  s  . 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 {/* w w  w.  j  a va  2  s  .  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 www  . ja  v  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);
            }
        }
    }
}

From source file:nl.nn.adapterframework.configuration.AbstractSpringPoweredDigesterFactory.java

private void addConfigWarning(Object currObj, String name, String message) {
    Locator loc = digester.getDocumentLocator();
    String msg = "line " + loc.getLineNumber() + ", col " + loc.getColumnNumber() + ": "
            + getObjectName(currObj, name) + ": " + message;
    configWarnings.add(log, msg);//from  w  ww  .  j  a v  a 2  s .com
}

From source file:nl.nn.adapterframework.configuration.AttributeCheckingRule.java

public void begin(String uri, String elementName, Attributes attributes) throws Exception {

    Object top = digester.peek();

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }//from   ww  w  . j av  a  2 s  . co  m
        if (name != null && !name.equals("className")) {
            //            if (log.isDebugEnabled()) {
            //               log.debug(getObjectName(top)+" checking for setter for attribute ["+name+"]");
            //            }
            PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(top, name);
            Method m = null;
            if (pd != null) {
                m = PropertyUtils.getWriteMethod(pd);
            }
            if (m == null) {
                Locator loc = digester.getDocumentLocator();
                String msg = "line " + loc.getLineNumber() + ", col " + loc.getColumnNumber() + ": "
                        + getObjectName(top) + " does not have an attribute [" + name + "] to set to value ["
                        + attributes.getValue(name) + "]";
                configWarnings.add(log, msg);
            }
        }
    }

}

From source file:org.apache.fop.fo.FONode.java

/**
 * Helper function to format a Locator instance.
 *
 * @param loc org.xml.sax.Locator object
 * @return String the formatted text/*w  w w . j  a  v a  2 s  .co  m*/
 */
public static String getLocatorString(Locator loc) {
    if (loc == null) {
        return "Unknown location";
    } else {
        return loc.getLineNumber() + "/" + loc.getColumnNumber();
    }
}

From source file:org.apache.openjpa.persistence.jdbc.XMLPersistenceMappingParser.java

/**
 * Parse table-generator./*from  w  ww  .java2s  .c om*/
 */
private boolean startTableGenerator(Attributes attrs) {
    String name = attrs.getValue("name");
    Log log = getLog();
    if (log.isTraceEnabled())
        log.trace(_loc.get("parse-gen", name));
    if (getRepository().getCachedSequenceMetaData(name) != null && log.isWarnEnabled())
        log.warn(_loc.get("override-gen", name));

    SequenceMapping seq = (SequenceMapping) getRepository().addSequenceMetaData(name);
    seq.setSequencePlugin(SequenceMapping.IMPL_VALUE_TABLE);
    seq.setTableIdentifier(toTableIdentifier(attrs.getValue("schema"), attrs.getValue("table")));
    seq.setPrimaryKeyColumnIdentifier(DBIdentifier.newColumn(attrs.getValue("pk-column-name"), delimit()));
    seq.setSequenceColumnIdentifier(DBIdentifier.newColumn(attrs.getValue("value-column-name"), delimit()));
    seq.setPrimaryKeyValue(attrs.getValue("pk-column-value"));
    String val = attrs.getValue("initial-value");
    if (val != null)
        seq.setInitialValue(Integer.parseInt(val));
    val = attrs.getValue("allocation-size");
    if (val != null)
        seq.setAllocate(Integer.parseInt(val));

    Object cur = currentElement();
    Object scope = (cur instanceof ClassMetaData) ? ((ClassMetaData) cur).getDescribedType() : null;
    seq.setSource(getSourceFile(), scope, SourceTracker.SRC_XML);
    Locator locator = getLocation().getLocator();
    if (locator != null) {
        seq.setLineNumber(locator.getLineNumber());
        seq.setColNumber(locator.getColumnNumber());
    }
    pushElement(seq);
    return true;
}