Example usage for org.xml.sax SAXException SAXException

List of usage examples for org.xml.sax SAXException SAXException

Introduction

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

Prototype

public SAXException(Exception e) 

Source Link

Document

Create a new SAXException wrapping an existing exception.

Usage

From source file:org.apache.torque.generator.configuration.source.SourceTransformerSaxHandler.java

/**
 * {@inheritDoc}//w  w w .  j  a  va2 s. c o m
 */
@Override
public void startElement(String uri, String localName, String rawName, Attributes attributes)
        throws SAXException {
    if (level == 0) {
        level++;
        if (rawName.equals(TRANSFORMER_TAG)) {
            String className = attributes.getValue(TRANSFORMER_CLASS_ATTRIBUTE);
            if (className == null) {
                throw new SAXException("The attribute " + TRANSFORMER_CLASS_ATTRIBUTE
                        + " must not be null for the element " + TRANSFORMER_TAG);
            }
            elements = attributes.getValue(ELEMENTS_ATTRIBUTE);
            sourceTransformer = createJavaSourceTransformer(className);
        } else {
            throw new SAXException("Unknown element " + rawName);
        }
    } else if (level == 1) {
        level++;
        propertyName = rawName;
        simplePropertyValue = new StringBuilder();
    } else if (level == 2) {
        level++;
        if (simplePropertyValue.length() > 0 && !StringUtils.isWhitespace(simplePropertyValue.toString())) {
            throw new SAXException(
                    "Cannot parse both text content and child elements " + " in element " + propertyName);
        }
        simplePropertyValue = null;
        if (listPropertyValue == null) {
            listPropertyValue = new ArrayList<String>();
        }
        listPropertyEntry = new StringBuilder();
    } else {
        throw new SAXException("unknown Element " + rawName);
    }
}

From source file:org.apache.torque.generator.configuration.source.SourceTransformerSaxHandler.java

/**
 * {@inheritDoc}//w w w. j  ava2  s  .  com
 */
@Override
public void endElement(String uri, String localName, String rawName) throws SAXException {
    level--;
    if (level == 2) {
        listPropertyValue.add(listPropertyEntry.toString());
        listPropertyEntry = null;
    } else if (level == 1) {
        if (!PropertyUtils.isWriteable(sourceTransformer, propertyName)) {
            throw new SAXException("No setter found for property " + propertyName + " in class "
                    + sourceTransformer.getClass().getName());
        }
        Object propertyValue;
        if (simplePropertyValue != null) {
            propertyValue = simplePropertyValue.toString();
        } else {
            propertyValue = listPropertyValue;
        }
        try {
            BeanUtils.copyProperty(sourceTransformer, propertyName, propertyValue);
        } catch (InvocationTargetException e) {
            throw new SAXException("error while setting Property " + propertyName + " for java transformer "
                    + sourceTransformer.getClass().getName() + " with value " + propertyValue.toString(), e);
        } catch (IllegalAccessException e) {
            throw new SAXException("error while setting Property " + propertyName + " for java transformer "
                    + sourceTransformer.getClass().getName() + " with value " + propertyValue.toString(), e);
        }
        propertyName = null;
        propertyValue = null;
    } else if (level != 0) {
        throw new SAXException("endElemend reached Level " + level);
    }
}

From source file:org.betaconceptframework.astroboa.engine.jcr.io.contenthandler.ImportContentHandler.java

private void createRootEntity(String uri, String rootElementName, Attributes atts) throws SAXException {

    if (Topic.class.isAssignableFrom(resultType)) {
        importResult = (T) createNewTopic(atts, rootElementName);

    } else if (Taxonomy.class.isAssignableFrom(resultType)) {
        importResult = (T) createNewTaxonomy(atts, rootElementName);

    } else if (RepositoryUser.class.isAssignableFrom(resultType)) {
        importResult = (T) createNewRepositoryUser(atts, rootElementName);

    } else if (Repository.class.isAssignableFrom(resultType)) {
        importResult = (T) new Repository();

    } else if (Space.class.isAssignableFrom(resultType)) {
        importResult = (T) createNewSpace(atts, rootElementName);

    } else if (ContentObject.class.isAssignableFrom(resultType)) {
        importResult = (T) createNewContentObject(atts, rootElementName, uri, null);

    } else if (List.class.isAssignableFrom(resultType)) {
        importResult = (T) new ArrayList();

    } else {//from w  w  w. j  a  va  2 s.  c  om
        throw new SAXException("Unsupported type of imported Entity " + resultType.getName());
    }

    pushEntity(rootElementName, importResult, atts);

    elementNameToBeIgnored = null;
}

From source file:org.betaconceptframework.astroboa.engine.jcr.io.contenthandler.ImportContentHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {

    logger.debug("Importing element name {}, uri {}", localName, uri);

    if (doNotProcessEvent()) {
        return;// w  w w  .j  a  va 2  s.c o m
    }

    if (importResult == null) {
        createRootEntity(uri, localName, atts);
    } else {

        //Queue should not be empty
        throwExceptionIfQeueIsEmpty(uri, localName);

        Object currentEntity = getCurrentEntityImported();

        //   Element corresponds to a cms property
        if (currentEntity instanceof ContentObject) {
            if (CmsConstants.OWNER_ELEMENT_NAME.equals(localName)) {
                if (processOwner(atts)) {
                    return;
                }
            } else {
                processCmsProperty(localName, atts, uri);
                return;
            }
        } else if (currentEntity instanceof CmsProperty) {
            processCmsProperty(localName, atts, uri);
            return;
        } else if (currentEntity instanceof BinaryChannel
                && CmsConstants.CONTENT_ELEMENT_NAME.equals(localName)) {
            //Element is content , which is defined in context of BinaryChannel
            //It will be processed when closing this element
            cmsRepositoryEntityQueue.peek().processingRawData(true);
            return;
        } else if (CmsConstants.LOCALIZED_LABEL_ELEMENT_NAME.equals(localName)) {
            //Depending on source XML or JSON attribute for lang may appear differently
            String langValue = getValueForAttribute(CmsConstants.LANG_ATTRIBUTE_NAME_WITH_PREFIX, atts);
            if (langValue == null) {
                langValue = getValueForAttribute(CmsConstants.LANG_ATTRIBUTE_NAME, atts);
            }
            if (langValue != null) {
                addAttributeToImportedEntity(CmsConstants.LANG_ATTRIBUTE_NAME_WITH_PREFIX, langValue);
            } else {
                //Found no lang attribute. 
                if (atts.getLength() > 0 && currentEntity instanceof Localization) {
                    addLabelsForLocaleToImportedEntity(atts);
                }
            }

            return;
        } else if (CmsConstants.OWNER_ELEMENT_NAME.equals(localName)) {
            if (processOwner(atts)) {
                return;
            }
        } else if (shouldIgnoreElement(localName)) {
            return;
        } else {

            if (currentEntity instanceof Topic) {

                //Expecting taxonomy, parentTopic or child topic
                final Topic currentlyImportedTopic = (Topic) currentEntity;

                if (CmsBuiltInItem.Taxonomy.getLocalPart().equals(localName)) {
                    Taxonomy taxonomy = createNewTaxonomy(atts, localName);
                    currentlyImportedTopic.setTaxonomy(taxonomy);
                    pushEntity(localName, taxonomy, atts);
                    return;
                } else if (CmsBuiltInItem.Topic.getLocalPart().equals(localName)) {

                    //Perform an initial check if topic name already exists
                    if (atts != null && importContext
                            .isEntityCached(getValueForAttribute(CmsBuiltInItem.Name.getLocalPart(), atts))) {
                        throw new SAXException("Topic with name "
                                + getValueForAttribute(CmsBuiltInItem.Name.getLocalPart(), atts)
                                + " has been already imported");
                    }

                    Topic childTopic = createNewTopic(atts, localName);
                    currentlyImportedTopic.addChild(childTopic);
                    if (childTopic.getTaxonomy() == null && currentlyImportedTopic.getTaxonomy() != null) {
                        childTopic.setTaxonomy(currentlyImportedTopic.getTaxonomy());
                    }
                    pushEntity(localName, childTopic, atts);

                    return;
                } else if (CmsConstants.PARENT_TOPIC.equals(localName)) {
                    Topic parentTopic = createNewTopic(atts, localName);
                    currentlyImportedTopic.setParent(parentTopic);
                    pushEntity(localName, parentTopic, atts);
                    return;
                }
            } else if (currentEntity instanceof Space) {

                //Expecting parentSpace or child space
                if (CmsBuiltInItem.Space.getLocalPart().equals(localName)) {
                    Space space = createNewSpace(atts, localName);
                    ((Space) currentEntity).addChild(space);
                    pushEntity(localName, space, atts);
                    return;
                } else if (CmsConstants.PARENT_SPACE.equals(localName)) {
                    Space space = createNewSpace(atts, localName);
                    ((Space) currentEntity).setParent(space);
                    pushEntity(localName, space, atts);
                    return;
                }
            } else if (currentEntity instanceof Taxonomy) {

                //Expecting  child topic
                if (CmsBuiltInItem.Topic.getLocalPart().equals(localName)) {
                    if (atts != null && importContext
                            .isEntityCached(getValueForAttribute(CmsBuiltInItem.Name.getLocalPart(), atts))) {
                        throw new SAXException("Topic with name "
                                + getValueForAttribute(CmsBuiltInItem.Name.getLocalPart(), atts)
                                + " has been already imported");
                    }

                    Topic topic = createNewTopic(atts, localName);
                    ((Taxonomy) currentEntity).addRootTopic(topic);
                    pushEntity(localName, topic, atts);
                    return;
                }
            } else if (currentEntity instanceof RepositoryUser) {

                if (CmsBuiltInItem.Space.getLocalPart().equals(localName)) {
                    Space space = createNewSpace(atts, localName);
                    ((RepositoryUserImpl) currentEntity).setSpace(space);
                    pushEntity(localName, space, atts);
                    return;
                } else if (CmsBuiltInItem.Taxonomy.getLocalPart().equals(localName)) {
                    Taxonomy taxonomy = createNewTaxonomy(atts, localName);
                    ((RepositoryUserImpl) currentEntity).setFolksonomy(taxonomy);
                    pushEntity(localName, taxonomy, atts);
                    return;
                }
            } else if (currentEntity instanceof Repository) {
                if (CmsBuiltInItem.Taxonomy.getLocalPart().equals(localName)) {
                    Taxonomy taxonomy = createNewTaxonomy(atts, localName);
                    pushEntity(localName, taxonomy, atts);
                    return;
                } else if (CmsBuiltInItem.Topic.getLocalPart().equals(localName)) {
                    Topic topic = createNewTopic(atts, localName);
                    pushEntity(localName, topic, atts);
                    return;
                } else if (CmsBuiltInItem.OrganizationSpace.getLocalPart().equals(localName)) {
                    Space space = createNewSpace(atts, localName);
                    pushEntity(localName, space, atts);
                    return;
                } else if (CmsBuiltInItem.RepositoryUser.getLocalPart().equals(localName)) {
                    RepositoryUser repositoryUser = createNewRepositoryUser(atts, localName);
                    pushEntity(localName, repositoryUser, atts);
                    return;
                } else {
                    ContentObject contentObject = createNewContentObject(atts, localName, uri, null);
                    pushEntity(localName, contentObject, atts);
                    return;
                }
            } else if (currentEntity instanceof List) {
                if (CmsBuiltInItem.Taxonomy.getLocalPart().equals(localName)) {
                    Taxonomy taxonomy = createNewTaxonomy(atts, localName);
                    ((List) currentEntity).add(taxonomy);
                    pushEntity(localName, taxonomy, atts);
                    return;
                } else if (CmsBuiltInItem.Space.getLocalPart().equals(localName)) {
                    Space space = createNewSpace(atts, localName);
                    ((List) currentEntity).add(space);
                    pushEntity(localName, space, atts);
                    return;
                } else if (CmsBuiltInItem.RepositoryUser.getLocalPart().equals(localName)) {
                    RepositoryUser repositoryUser = createNewRepositoryUser(atts, localName);
                    ((List) currentEntity).add(repositoryUser);
                    pushEntity(localName, repositoryUser, atts);
                    return;
                } else if (CmsBuiltInItem.Topic.getLocalPart().equals(localName)) {
                    Topic topic = createNewTopic(atts, localName);
                    ((List) currentEntity).add(topic);
                    pushEntity(localName, topic, atts);
                    return;
                } else {
                    ContentObject contentObject = createNewContentObject(atts, localName, uri, null);
                    ((List) currentEntity).add(contentObject);
                    pushEntity(localName, contentObject, atts);
                    return;
                }
            }

        }

        throw new SAXException("Unexpected element " + localName);

    }
}

From source file:org.betaconceptframework.astroboa.engine.jcr.io.contenthandler.ImportContentHandler.java

private void throwExceptionIfQeueIsEmpty(String uri, String localName) throws SAXException {
    if (cmsRepositoryEntityQueue.isEmpty()) {
        throw new SAXException(
                "Element {" + uri + "}" + localName + " was not imported. Entity queue is empty");
    }//from w  w w.jav a  2s. c  om
}

From source file:org.carrot2.source.yahoo.XMLResponseParser.java

public void endDocument() throws SAXException {
    if (error) {// w  w w.  ja va 2 s  .  c  om
        throw new SAXException(new IOException("Yahoo! service error: " + errorText.toString()));
    }
}

From source file:org.codehaus.enunciate.config.EnunciateConfiguration.java

/**
 * Create the digester.//from   ww  w.ja v a2s. c om
 *
 * @return The digester that was created.
 */
protected Digester createDigester() throws SAXException {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating(false);

        Properties properties = new Properties();
        properties.put("SAXParserFactory", factory);
        //      properties.put("schemaLocation", EnunciateConfiguration.class.getResource("enunciate.xsd").toString());
        //      properties.put("schemaLanguage", "http://www.w3.org/2001/XMLSchema");

        SAXParser parser = GenericParser.newSAXParser(properties);
        return new Digester(parser);
    } catch (ParserConfigurationException e) {
        throw new SAXException(e);
    }
}

From source file:org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate.java

/**
 * Takes in a fatalError exception thrown by the parser and writes relevant information about it to BufferedWriter
 * Also, throws a new exception, because SAX parsing can not continue after a Fatal Error.
 *
 * @param exception an exception thrown by the parser
 * @throws SAXException//from  w w  w .j a v a2  s  .co m
 */
@Override
public void fatalError(SAXParseException exception) throws SAXException {
    String message = "Fatal Error: " + getParseExceptionInfo(exception);
    outWriter.append(message + '\n');
    throw new SAXException(message);
}

From source file:org.collectionspace.csp.helper.core.ConfigFinder.java

public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    try {//from   w ww. ja  v a 2 s.  c  o m
        InputStream out = null;

        // If there is a conf base directory, look for it there first         
        File configBase = this.getConfigBase();
        if (configBase != null && configBase.exists()) {
            String fileEntityName = configBase.getAbsolutePath() + "/" + systemId;
            log.debug(String.format("Looking to resolve publicId:%s systemId:%s in '%s'.", publicId, systemId,
                    fileEntityName));
            File fileEntity = new File(fileEntityName);
            if (fileEntity.exists() == true) {
                log.debug(String.format("Resolved '%s'.\r\n", fileEntityName));
                out = new FileInputStream(fileEntity);
                return new InputSource(out);
            }
        }

        // Look for it in the env vars
        out = getDataFromEnvironmentVariable();
        if (out != null) {
            return new InputSource(out);
        }

        // Look for it as a servlet container attribute
        if (ctx != null && "-//CSPACE//ROOT".equals(publicId)) {
            out = getDataFromAttribute();
            if (out != null) {
                return new InputSource(out);
            }

            out = getDataFromAttributePath();
            if (out != null) {
                return new InputSource(out);
            }

            out = getDataFromName();
            if (out != null) {
                return new InputSource(out);
            }

        }

        // use config from tomcat-main/src/main/resources if this is a test
        // run by mvn
        if ("-//CSPACE//TESTROOT".equals(publicId)) {
            out = getConfigStreamViaClassLoader(systemId);
            if (out != null)
                return new InputSource(out);
        }
        out = getDataFromJBossPath(systemId);
        if (out != null)
            return new InputSource(out);
        out = getDataFromClasspath(systemId); // running tests find the
        // resource/entity here
        if (out != null)
            return new InputSource(out);
        out = getConfigStreamViaClassLoader(systemId);
        if (out != null)
            return new InputSource(out);
        throw new SAXException("No such file " + systemId);
    } catch (CSPDependencyException e) {
        throw new SAXException("Error parsing", e);
    }
}

From source file:org.collectionspace.csp.helper.core.ConfigFinder.java

public File resolveEntityAsFile(String publicId, String systemId) throws SAXException, IOException {
    try {/*from  w  w  w  . ja v a  2  s . co m*/
        File out = getDataFromEnvironmentVariableAsFile();
        if (out != null) {
            return out;
        }

        if (ctx != null && "-//CSPACE//ROOT".equals(publicId)) {
            InputStream outStream = getDataFromAttribute();
            if (outStream != null) {
                log.warn(String.format(
                        "Configuration not found as a file but as a string in the environment: %s",
                        outStream.toString()));
                return null;
            }

            out = getDataFromAttributePathAsFile();
            if (out != null) {
                return out;
            }

            out = getDataFromNameAsFile();
            if (out != null) {
                return out;
            }
        }

        // use config from tomcat-main/src/main/resources if this is a test
        // run by mvn
        if ("-//CSPACE//TESTROOT".equals(publicId)) {
            out = getConfigFileViaClassLoader(systemId);
            if (out != null) {
                return out;
            }
        }

        out = getDataFromJBossPathAsFile(systemId);
        if (out != null) {
            return out;
        }

        out = getDataFromClasspathAsFile(systemId); // running tests find the resource/entity here
        if (out != null) {
            return out;
        }

        out = getConfigFileViaClassLoader(systemId);
        if (out != null) {
            return out;
        }

        throw new SAXException("No such file " + systemId);
    } catch (CSPDependencyException e) {
        throw new SAXException("Error parsing", e);
    }
}