Search in sources :

Example 11 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project iaf by ibissource.

the class XMLSchemaFactory method setProperty.

public void setProperty(String name, Object object) throws SAXNotRecognizedException, SAXNotSupportedException {
    if (name == null) {
        throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "ProperyNameNull", null));
    }
    if (name.equals(SECURITY_MANAGER)) {
        fSecurityManager = (SecurityManager) object;
        fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
        return;
    } else if (name.equals(XMLGRAMMAR_POOL)) {
        throw new SAXNotSupportedException(SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "property-not-supported", new Object[] { name }));
    }
    try {
        fXMLSchemaLoader.setProperty(name, object);
    } catch (XMLConfigurationException e) {
        String identifier = e.getIdentifier();
        if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
            throw new SAXNotRecognizedException(SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "property-not-recognized", new Object[] { identifier }));
        } else {
            throw new SAXNotSupportedException(SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "property-not-supported", new Object[] { identifier }));
        }
    }
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) XMLConfigurationException(org.apache.xerces.xni.parser.XMLConfigurationException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException)

Example 12 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project iaf by ibissource.

the class MyErrorHandler method createValidatingParser.

public XMLReader createValidatingParser(IPipeLineSession session, ValidationContext context) throws XmlValidatorException, ConfigurationException, PipeRunException {
    SymbolTable symbolTable = ((XercesValidationContext) context).getSymbolTable();
    XMLGrammarPool grammarPool = ((XercesValidationContext) context).getGrammarPool();
    XMLReader parser = new SAXParser(new ShadowedSymbolTable(symbolTable), grammarPool);
    try {
        parser.setFeature(NAMESPACES_FEATURE_ID, true);
        parser.setFeature(VALIDATION_FEATURE_ID, true);
        // parser.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // this feature is not recognized
        // parser.setFeature(EXTERNAL_GENERAL_ENTITIES_FEATURE_ID, false); // this one appears to be not working
        // parser.setFeature(EXTERNAL_PARAMETER_ENTITIES_FEATURE_ID, false);
        // parser.setFeature(DISSALLOW_DOCTYPE_DECL_FEATURE_ID, true);
        parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
        parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, isFullSchemaChecking());
        parser.setErrorHandler(context.getErrorHandler());
        org.apache.xerces.util.SecurityManager mgr = new org.apache.xerces.util.SecurityManager();
        mgr.setEntityExpansionLimit(entityExpansionLimit);
        parser.setProperty(SECURITY_MANAGER_PROPERTY_ID, mgr);
    } catch (SAXNotRecognizedException e) {
        throw new XmlValidatorException(logPrefix + "parser does not recognize necessary feature", e);
    } catch (SAXNotSupportedException e) {
        throw new XmlValidatorException(logPrefix + "parser does not support necessary feature", e);
    }
    return parser;
}
Also used : XMLGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool) SymbolTable(org.apache.xerces.util.SymbolTable) ShadowedSymbolTable(org.apache.xerces.util.ShadowedSymbolTable) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(org.apache.xerces.parsers.SAXParser) ShadowedSymbolTable(org.apache.xerces.util.ShadowedSymbolTable) XMLReader(org.xml.sax.XMLReader)

Example 13 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project ant by apache.

the class ParserSupports method evalFeature.

/**
 * Set a feature
 * @return true if the feature could be set
 */
public boolean evalFeature() {
    XMLReader reader = getReader();
    if (value == null) {
        value = "true";
    }
    boolean v = Project.toBoolean(value);
    try {
        reader.setFeature(feature, v);
    } catch (SAXNotRecognizedException e) {
        log(FEATURE + NOT_RECOGNIZED + feature, Project.MSG_VERBOSE);
        return false;
    } catch (SAXNotSupportedException e) {
        log(FEATURE + NOT_SUPPORTED + feature, Project.MSG_VERBOSE);
        return false;
    }
    return true;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader)

Example 14 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project muikku by otavanopisto.

the class WorkspaceMaterialController method createContentNode.

private ContentNode createContentNode(WorkspaceNode rootMaterialNode, int level, boolean processHtml, boolean includeHidden) throws WorkspaceMaterialException {
    boolean viewRestricted = false;
    try {
        switch(rootMaterialNode.getType()) {
            case FOLDER:
                WorkspaceFolder workspaceFolder = (WorkspaceFolder) rootMaterialNode;
                viewRestricted = !sessionController.isLoggedIn() && workspaceFolder.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
                ContentNode folderContentNode = new ContentNode(workspaceFolder.getTitle(), "folder", rootMaterialNode.getId(), null, level, null, null, rootMaterialNode.getParent().getId(), rootMaterialNode.getHidden(), null, 0l, 0l, workspaceFolder.getPath(), null, null, workspaceFolder.getViewRestrict(), viewRestricted);
                List<WorkspaceNode> children = includeHidden ? workspaceNodeDAO.listByParentSortByOrderNumber(workspaceFolder) : workspaceNodeDAO.listByParentAndHiddenSortByOrderNumber(workspaceFolder, Boolean.FALSE);
                List<FlattenedWorkspaceNode> flattenedChildren;
                if (level >= FLATTENING_LEVEL) {
                    flattenedChildren = flattenWorkspaceNodes(children, level, includeHidden);
                } else {
                    flattenedChildren = new ArrayList<>();
                    for (WorkspaceNode node : children) {
                        flattenedChildren.add(new FlattenedWorkspaceNode(false, null, node, level, node.getParent().getId(), node.getHidden()));
                    }
                }
                for (FlattenedWorkspaceNode child : flattenedChildren) {
                    ContentNode contentNode;
                    if (child.isEmptyFolder) {
                        contentNode = new ContentNode(child.emptyFolderTitle, "folder", rootMaterialNode.getId(), null, child.level, null, null, child.parentId, child.hidden, null, 0l, 0l, child.node.getPath(), null, null, MaterialViewRestrict.NONE, false);
                    } else {
                        contentNode = createContentNode(child.node, child.level, processHtml, includeHidden);
                    }
                    folderContentNode.addChild(contentNode);
                }
                return folderContentNode;
            case MATERIAL:
                DOMParser parser = null;
                Transformer transformer = null;
                if (processHtml) {
                    parser = new DOMParser(new HTMLConfiguration());
                    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
                    transformer = TransformerFactory.newInstance().newTransformer();
                    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                    transformer.setOutputProperty(OutputKeys.INDENT, "no");
                }
                WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) rootMaterialNode;
                Material material = materialController.findMaterialById(workspaceMaterial.getMaterialId());
                Long currentRevision = material instanceof HtmlMaterial ? htmlMaterialController.lastHtmlMaterialRevision((HtmlMaterial) material) : 0l;
                Long publishedRevision = material instanceof HtmlMaterial ? ((HtmlMaterial) material).getRevisionNumber() : 0l;
                List<String> producerNames = null;
                String html;
                List<MaterialProducer> producers = materialController.listMaterialProducers(material);
                if ((producers != null) && !producers.isEmpty()) {
                    producerNames = new ArrayList<>();
                    for (MaterialProducer producer : producers) {
                        producerNames.add(StringUtils.replace(StringEscapeUtils.escapeHtml4(producer.getName()), ",", "&#44;"));
                    }
                }
                viewRestricted = !sessionController.isLoggedIn() && material.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
                if (!viewRestricted) {
                    html = processHtml ? getMaterialHtml(material, parser, transformer) : null;
                } else {
                    html = String.format("<p class=\"content-view-restricted-message\">%s</p>", localeController.getText(sessionController.getLocale(), "plugin.workspace.materialViewRestricted"));
                }
                return new ContentNode(workspaceMaterial.getTitle(), material.getType(), rootMaterialNode.getId(), material.getId(), level, workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers(), workspaceMaterial.getParent().getId(), workspaceMaterial.getHidden(), html, currentRevision, publishedRevision, workspaceMaterial.getPath(), material.getLicense(), StringUtils.join(producerNames, ','), material.getViewRestrict(), viewRestricted);
            default:
                return null;
        }
    } catch (SAXNotRecognizedException | SAXNotSupportedException | TransformerConfigurationException e) {
        throw new WorkspaceMaterialException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) HTMLConfiguration(org.cyberneko.html.HTMLConfiguration) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) DOMParser(org.apache.xerces.parsers.DOMParser) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)

Example 15 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project fabric8 by fabric8io.

the class XmlNamespaceFinder method createParser.

protected final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException {
    parserFactory.setNamespaceAware(true);
    final SAXParser parser = parserFactory.newSAXParser();
    final XMLReader reader = parser.getXMLReader();
    // disable DTD validation (bug 63625)
    try {
        // be sure validation is "off" or the feature to ignore DTD's will not apply
        // $NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/validation", false);
        // $NON-NLS-1$
        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (SAXNotRecognizedException e) {
    // not a big deal if the parser does not recognize the features
    } catch (SAXNotSupportedException e) {
    // not a big deal if the parser does not support the features
    }
    return parser;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader)

Aggregations

SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)33 SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)25 XMLReader (org.xml.sax.XMLReader)16 SAXException (org.xml.sax.SAXException)13 SAXParser (javax.xml.parsers.SAXParser)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 SAXParserFactory (javax.xml.parsers.SAXParserFactory)8 InputSource (org.xml.sax.InputSource)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 SAXSource (javax.xml.transform.sax.SAXSource)4 BufferedInputStream (java.io.BufferedInputStream)3 Reader (java.io.Reader)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Source (javax.xml.transform.Source)2 Transformer (javax.xml.transform.Transformer)2 DOMSource (javax.xml.transform.dom.DOMSource)2