Example usage for javax.xml.parsers ParserConfigurationException printStackTrace

List of usage examples for javax.xml.parsers ParserConfigurationException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.ac.vct.pharmacylog.services.IMService.java

public void parseMessageInfo(String xml) {
    //Log.v("IMService", "Parse Message Info");
    try {//  w  w  w .  j  a v  a  2  s .  c  o m
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new XMLHandler(IMService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.baidar.androidChatter.serve.MessagingService.java

private void parseFriendInfo(String xml) {
    try {//from   ww  w.  jav  a  2s .  c om
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new HandlerXML(MessagingService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.baidar.androidChatter.serve.MessagingService.java

private void parseMessageInfo(String xml) {
    try {/*from w  w  w.j  a  v a2s  .  c  om*/
        SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
        sp.parse(new ByteArrayInputStream(xml.getBytes()), new HandlerXML(MessagingService.this));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

/**
 * Write the extension classes - this is needed to process
 * the hierarchy of classes//ww w .  j  a  va2s . c  om
 *
 * @param metainfArray
 */
public void writeExtensionMapper(BeanWriterMetaInfoHolder[] metainfArray) throws SchemaCompilationException {
    //generate the element
    try {

        String mapperClassName = getFullyQualifiedMapperClassName();

        Document model = XSLTUtils.getDocument();
        Element rootElt = XSLTUtils.getElement(model, "mapper");
        String mapperName = mapperClassName.substring(mapperClassName.lastIndexOf(".") + 1);
        XSLTUtils.addAttribute(model, "name", mapperName, rootElt);
        String basePackageName = "";
        if (mapperClassName.indexOf(".") != -1) {
            basePackageName = mapperClassName.substring(0, mapperClassName.lastIndexOf("."));
            XSLTUtils.addAttribute(model, "package", basePackageName, rootElt);
        } else {
            XSLTUtils.addAttribute(model, "package", "", rootElt);
        }

        if (!wrapClasses) {
            XSLTUtils.addAttribute(model, "unwrapped", "yes", rootElt);
        }

        if (!writeClasses) {
            XSLTUtils.addAttribute(model, "skip-write", "yes", rootElt);
        }

        if (isHelperMode) {
            XSLTUtils.addAttribute(model, "helpermode", "yes", rootElt);
        }

        for (int i = 0; i < metainfArray.length; i++) {
            QName ownQname = metainfArray[i].getOwnQname();
            String className = metainfArray[i].getOwnClassName();
            //do  not add when the qname is not availble
            if (ownQname != null) {
                Element typeChild = XSLTUtils.addChildElement(model, "type", rootElt);
                XSLTUtils.addAttribute(model, "nsuri", ownQname.getNamespaceURI(), typeChild);
                XSLTUtils.addAttribute(model, "classname", className == null ? "" : className, typeChild);
                XSLTUtils.addAttribute(model, "shortname", ownQname == null ? "" : ownQname.getLocalPart(),
                        typeChild);
            }
        }

        model.appendChild(rootElt);

        if (!templateLoaded) {
            loadTemplate();
        }

        if (wrapClasses) {
            rootElt = (Element) globalWrappedDocument.importNode(rootElt, true);
            //add to the global wrapped document
            globalWrappedDocument.getDocumentElement().appendChild(rootElt);
        } else {
            if (writeClasses) {
                // create the file
                File out = createOutFile(basePackageName, mapperName);
                // parse with the template and create the files
                parse(model, out);

            }

            // add the model to the model map
            modelMap.put(new QName(mapperName), model);
        }

    } catch (ParserConfigurationException e) {
        throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.docuement.error"), e);
    } catch (Exception e) {
        e.printStackTrace();
        throw new SchemaCompilationException(e);
    }

}

From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher.java

@Override
public void explain(PhysicalPlan php, PigContext pc, PrintStream ps, String format, boolean verbose)
        throws PlanException, VisitorException, IOException {
    log.trace("Entering MapReduceLauncher.explain");
    MROperPlan mrp = compile(php, pc);//from  w w w  .j a v a  2  s  .  c o m

    if (format.equals("text")) {
        MRPrinter printer = new MRPrinter(ps, mrp);
        printer.setVerbose(verbose);
        printer.visit();
    } else if (format.equals("xml")) {
        try {
            XMLMRPrinter printer = new XMLMRPrinter(ps, mrp);
            printer.visit();
            printer.closePlan();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    } else {
        ps.println("#--------------------------------------------------");
        ps.println("# Map Reduce Plan                                  ");
        ps.println("#--------------------------------------------------");

        DotMRPrinter printer = new DotMRPrinter(mrp, ps);
        printer.setVerbose(verbose);
        printer.dump();
        ps.println("");
    }
}

From source file:org.apache.tika.parser.microsoft.ooxml.xwpf.XWPFEventBasedWordExtractor.java

private void handlePart(PackagePart packagePart, XWPFListManager xwpfListManager, StringBuilder buffer)
        throws IOException, SAXException {

    Map<String, String> hyperlinks = loadHyperlinkRelationships(packagePart);
    try (InputStream stream = packagePart.getInputStream()) {
        XMLReader reader = SAXHelper.newXMLReader();
        reader.setContentHandler(/*from w w w . j av  a2  s .c o  m*/
                new OOXMLWordAndPowerPointTextHandler(new XWPFToTextContentHandler(buffer), hyperlinks));
        reader.parse(new InputSource(new CloseShieldInputStream(stream)));

    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

}

From source file:org.asimba.wa.integrationtest.saml2.model.AuthnRequest.java

public String getSignedRequest(int format, InputStream keystoreStream, String keystorePassword, String keyAlias,
        String keyPassword) {//from   w w w . j  av a 2  s .  c  o  m
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    DocumentBuilder builder;
    Document doc;
    try {
        builder = dbf.newDocumentBuilder();
        doc = builder.parse(new InputSource(new ByteArrayInputStream(getRequest(plain).getBytes("utf-8"))));

        // Prepare doc by marking attributes as referenceable:
        tagIdAttributes(doc);

        // Prepare cryptographic environemnt
        KeyStore keystore = getKeystore("JKS", keystoreStream, keystorePassword);
        if (keystore == null)
            return null;

        KeyPair kp;

        kp = getKeyPairFromKeystore(keystore, keyAlias, keyPassword);
        if (kp == null) {
            // Generate key, to prove that it works...
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
            kpg.initialize(512);
            kp = kpg.generateKeyPair();
        }

        // Set signing context with PrivateKey and root of the Document
        DOMSignContext dsc = new DOMSignContext(kp.getPrivate(), doc.getDocumentElement());

        // Get SignatureFactory for creating signatures in DOM:
        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");

        // Create reference for "" -> root of the document
        // SAML requires enveloped transform
        Reference ref = fac.newReference("#" + this._id, fac.newDigestMethod(DigestMethod.SHA1, null),
                Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
                null, null);

        // Create SignedInfo (SAML2: Exclusive with or without comments is specified)
        SignedInfo si = fac.newSignedInfo(
                fac.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS,
                        (C14NMethodParameterSpec) null),
                fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null), Collections.singletonList(ref));

        // Add KeyInfo to the document:
        KeyInfoFactory kif = fac.getKeyInfoFactory();

        // .. get key from the generated keypair:
        KeyValue kv = kif.newKeyValue(kp.getPublic());
        KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));

        XMLSignature signature = fac.newXMLSignature(si, ki);

        String before = docToString(doc);

        // Sign!
        signature.sign(dsc);

        _authnRequestDocument = doc; // persist, as we've worked hard for it

        String after = docToString(doc);

        if (_logger.isDebugEnabled()) {
            _logger.debug("Before: {}", before);
            _logger.debug("After : {}", after);
        }

        return after;

    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XMLStreamException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // key generation exception
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        // digest algorithm selection exception
        e.printStackTrace();
    } catch (KeyException e) {
        // when key-value was not available (when adding to KeyInfo)
        e.printStackTrace();
    } catch (MarshalException e) {
        // sign didn't work:
        e.printStackTrace();
    } catch (XMLSignatureException e) {
        // sign didn't work:
        e.printStackTrace();
    }
    return null;
}

From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java

/**
 * Creates a new instance of AbstractSchemaFormBuilder
 *///  w  w  w  .j ava  2  s  .  co m
public AbstractSchemaFormBuilder(String rootTagName) {
    this._rootTagName = rootTagName;
    typeTree = new TreeMap();
    properties = new Properties();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    try {
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        documentBuilder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException x) {
        x.printStackTrace();
    }

    //default wrapper: HTML
    //_wrapper = new BaseWrapperElementsBuilder();
    _wrapper = new XHTMLWrapperElementsBuilder();
    reset();
}

From source file:org.easyrec.taglib.ProfileRenderer.java

/**
 * This function generates a XML document of the given XML String
 *
 * @param profileXML/*w  w w.  ja va  2  s . c o m*/
 * @return The XmlDocument of the given XML string
 */
private Document generateXmlDocument(String profileXML) throws SAXException {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(profileXML));
        return db.parse(is);
    } catch (ParserConfigurationException e) {
        logger.warn("An error occurred!", e);
    } catch (IOException e) {
        logger.warn("An error occurred!", e);
        e.printStackTrace();
    }
    return null;
}

From source file:org.easyrec.utils.Web.java

/**
 * This procedure extracts the values/*from   ww w.j  av a  2s  . c o  m*/
 * of the <name>-Tags of a given Xml file into a list of Strings.
 * e.g.
 * <name>hanso</name>
 * <name>stritzi</name>
 * <p/>
 * --> {"hansi","stritzi"}
 *
 * @param apiURL  String
 * @param tagName String
 * @return a list of strings
 */
@SuppressWarnings({ "UnusedDeclaration" })
public static List<String> getInnerHTMLfromTags(String apiURL, String tagName) {

    List<String> innerHTMLList = new ArrayList<String>();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db;
    try {
        db = dbf.newDocumentBuilder();
        db.setErrorHandler(new ErrorHandler() {
            public void warning(SAXParseException e) throws SAXException {
            }

            public void error(SAXParseException e) throws SAXException {
            }

            public void fatalError(SAXParseException e) throws SAXException {
            }
        });
        Document doc = db.parse(apiURL.replaceAll(" ", "%20"));

        NodeList tagNodes = doc.getElementsByTagName(tagName);

        for (int i = 0; i < tagNodes.getLength(); i++) {
            innerHTMLList.add(tagNodes.item(i).getTextContent());
        }
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return innerHTMLList;
}