Java 类org.jdom.Document 实例源码

项目:cas-5.1.0    文件:GoogleAccountsServiceFactory.java   
@Override
public GoogleAccountsService createService(final HttpServletRequest request) {
    final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);

    final String xmlRequest = this.googleSaml20ObjectBuilder.decodeSamlAuthnRequest(
            request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));

    if (StringUtils.isBlank(xmlRequest)) {
        LOGGER.trace("SAML AuthN request not found in the request");
        return null;
    }

    final Document document = this.googleSaml20ObjectBuilder.constructDocumentFromXml(xmlRequest);
    if (document == null) {
        return null;
    }

    final Element root = document.getRootElement();
    final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
    final String requestId = root.getAttributeValue("ID");
    final GoogleAccountsService s = new GoogleAccountsService(assertionConsumerServiceUrl, relayState, requestId);
    s.setLoggedOutAlready(true);
    return s;
}
项目:DocIT    文件:Cut.java   
public static void cut(Document doc) {

    // Iterate over all salary elements
    Iterator<?> iterator = doc.getDescendants(new ElementFilter("salary"));

    // Snapshot these elements before modification
    List<Element> elems = new LinkedList<Element>();
    while (iterator.hasNext())
        elems.add((Element)iterator.next());

    // Iterate over salary elements and cut salaries
    for (Element elem : elems) {
        Double salary = Double.valueOf(elem.getText());
        elem.setText(Double.toString(salary/2));
    }
}
项目:gate-core    文件:Plugin.java   
@Override
public Document getCreoleXML() throws Exception, JDOMException {
  Document doc = new Document();
  Element element;
  doc.addContent(element = new Element("CREOLE-DIRECTORY"));
  element.addContent(element = new Element("CREOLE"));
  element.addContent(element = new Element("RESOURCE"));
  Element classElement  = new Element("CLASS");
  classElement.setText(resourceClass.getName());
  element.addContent(classElement);

  return doc;
}
项目:Equella    文件:TleJnlpDownloadServlet.java   
@SuppressWarnings("nls")
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
    resp.setContentType("application/x-java-jnlp-file");
    resp.setHeader("Cache-Control", "private, max-age=5, must-revalidate");
    Document locJnlpDocument = (Document) this.jnlpDocument.clone();
    Element jnlpElem = locJnlpDocument.getRootElement();
    String instUrl = institutionService.getInstitutionUrl().toString();
    jnlpElem.setAttribute("codebase", instUrl);
    Element resources = jnlpElem.getChild("resources");

    String token = userService.getGeneratedToken(Constants.APPLET_SECRET_ID, CurrentUser.getUsername());

    String tokenEncoded = Base64.encodeBase64String(token.getBytes("UTF-8")).replace("\r", "").replace("\n", "");
    resources.addContent(createJar(resourcesService.getUrl("com.tle.web.adminconsole", "adminconsole.jar")));
    resources.addContent(createProperty(Bootstrap.TOKEN_PARAMETER, tokenEncoded));
    resources.addContent(createProperty(Bootstrap.ENDPOINT_PARAMETER, instUrl));
    resources.addContent(createProperty(Bootstrap.LOCALE_PARAMETER, CurrentLocale.getLocale().toString()));
    resources.addContent(createProperty(Bootstrap.INSTITUTION_NAME_PARAMETER, CurrentInstitution.get().getName()));
    xmlOut.output(locJnlpDocument, resp.getWriter());
}
项目:parabuild-ci    文件:RSS090Parser.java   
public boolean isMyType(Document document) {
    boolean ok = false;

    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    List additionalNSs = rssRoot.getAdditionalNamespaces();

    ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
    if (ok) {
        if (additionalNSs==null) {
            ok = false;
        }
        else {
            ok = false;
            for (int i=0;!ok && i<additionalNSs.size();i++) {
                ok = getRSSNamespace().equals(additionalNSs.get(i));
            }
        }
    }
    return ok;
}
项目:parabuild-ci    文件:RSS10Parser.java   
/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
    boolean ok = false;

    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    List additionalNSs = rssRoot.getAdditionalNamespaces();

    ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
    if (ok) {
        if (additionalNSs==null) {
            ok = false;
        }
        else {
            ok = false;
            for (int i=0;!ok && i<additionalNSs.size();i++) {
                ok = getRSSNamespace().equals(additionalNSs.get(i));
            }
        }
    }
    return ok;
}
项目:springboot-shiro-cas-mybatis    文件:AbstractSamlObjectBuilder.java   
/**
 * Convert the received jdom doc to a Document element.
 *
 * @param doc the doc
 * @return the org.w3c.dom. document
 */
private org.w3c.dom.Document toDom(final Document doc) {
    try {
        final XMLOutputter xmlOutputter = new XMLOutputter();
        final StringWriter elemStrWriter = new StringWriter();
        xmlOutputter.output(doc, elemStrWriter);
        final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
        final DocumentBuilderFactory dbf = DocumentBuilderFactory
                .newInstance();
        dbf.setNamespaceAware(true);
        return dbf.newDocumentBuilder().parse(
                new ByteArrayInputStream(xmlBytes));
    } catch (final Exception e) {
        logger.trace(e.getMessage(), e);
        return null;
    }
}
项目:springboot-shiro-cas-mybatis    文件:GoogleAccountsService.java   
/**
 * Creates the service from request.
 *
 * @param request the request
 * @param privateKey the private key
 * @param publicKey the public key
 * @param servicesManager the services manager
 * @return the google accounts service
 */
public static GoogleAccountsService createServiceFrom(
        final HttpServletRequest request, final PrivateKey privateKey,
        final PublicKey publicKey, final ServicesManager servicesManager) {
    final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);

    final String xmlRequest = BUILDER.decodeSamlAuthnRequest(
            request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));

    if (!StringUtils.hasText(xmlRequest)) {
        return null;
    }

    final Document document = AbstractSaml20ObjectBuilder.constructDocumentFromXml(xmlRequest);

    if (document == null) {
        return null;
    }

    final Element root = document.getRootElement();
    final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
    final String requestId = root.getAttributeValue("ID");

    return new GoogleAccountsService(assertionConsumerServiceUrl,
            relayState, requestId, privateKey, publicKey, servicesManager);
}
项目:springboot-shiro-cas-mybatis    文件:AbstractSamlObjectBuilder.java   
/**
 * Convert the received jdom doc to a Document element.
 *
 * @param doc the doc
 * @return the org.w3c.dom. document
 */
private org.w3c.dom.Document toDom(final Document doc) {
    try {
        final XMLOutputter xmlOutputter = new XMLOutputter();
        final StringWriter elemStrWriter = new StringWriter();
        xmlOutputter.output(doc, elemStrWriter);
        final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
        final DocumentBuilderFactory dbf = DocumentBuilderFactory
                .newInstance();
        dbf.setNamespaceAware(true);
        return dbf.newDocumentBuilder().parse(
                new ByteArrayInputStream(xmlBytes));
    } catch (final Exception e) {
        logger.trace(e.getMessage(), e);
        return null;
    }
}
项目:cas-5.1.0    文件:AbstractSamlObjectBuilder.java   
/**
 * Convert the received jdom doc to a Document element.
 *
 * @param doc the doc
 * @return the org.w3c.dom. document
 */
private static org.w3c.dom.Document toDom(final Document doc) {
    try {
        final XMLOutputter xmlOutputter = new XMLOutputter();
        final StringWriter elemStrWriter = new StringWriter();
        xmlOutputter.output(doc, elemStrWriter);
        final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
        final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
        dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
    } catch (final Exception e) {
        LOGGER.trace(e.getMessage(), e);
        return null;
    }
}
项目:sumo    文件:H2Fetcher.java   
public static void addImagePlanning(String dbname, File planningFile) throws Exception {
    // create xml reader
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    doc = builder.build(planningFile);
    Element atts = doc.getRootElement();
    // check format first
    if (atts.getName().equalsIgnoreCase("imageplanning")) {
        // connect to database
        Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/" + dbname + ";AUTO_SERVER=TRUE", "sa", "");
        Statement stat = conn.createStatement();
        String sql = "create table if not exists IMAGEPLAN (IMAGE VARCHAR(255), URL VARCHAR(1024), STARTDATE VARCHAR(255), ENDDATE VARCHAR(255), AREA VARCHAR(1024), ACTION VARCHAR(2048))";
        stat.execute(sql);
        // clear table before filling it in
        stat.execute("DELETE FROM IMAGEPLAN");
        // scan through images
        for (Object o : atts.getChildren("Image")) {
            Element element = (Element) o;
            // create sql statement
            sql = "INSERT INTO IMAGEPLAN VALUES('" + element.getChildText("name") + "', '" + element.getChildText("url") + "', '" + element.getChildText("startDate") + "', '" + element.getChildText("endDate") + "', '" + element.getChildText("area") + "', '" + element.getChildText("action") + "');";
            stat.execute(sql);
        }
        stat.close();
        conn.close();
    } else {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                JOptionPane.showMessageDialog(null, "Format not supported", "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }

}
项目:cas4.0.x-server-wechat    文件:GoogleAccountsService.java   
public static GoogleAccountsService createServiceFrom(
        final HttpServletRequest request, final PrivateKey privateKey,
        final PublicKey publicKey, final String alternateUserName) {
    final String relayState = request.getParameter(CONST_RELAY_STATE);

    final String xmlRequest = decodeAuthnRequestXML(request
            .getParameter(CONST_PARAM_SERVICE));

    if (!StringUtils.hasText(xmlRequest)) {
        return null;
    }

    final Document document = SamlUtils
            .constructDocumentFromXmlString(xmlRequest);

    if (document == null) {
        return null;
    }

    final String assertionConsumerServiceUrl = document.getRootElement().getAttributeValue("AssertionConsumerServiceURL");
    final String requestId = document.getRootElement().getAttributeValue("ID");

    return new GoogleAccountsService(assertionConsumerServiceUrl,
            relayState, requestId, privateKey, publicKey, alternateUserName);
}
项目:cas4.0.x-server-wechat    文件:SamlUtils.java   
private static org.w3c.dom.Document toDom(final Document doc) {
    try {
        final XMLOutputter xmlOutputter = new XMLOutputter();
        final StringWriter elemStrWriter = new StringWriter();
        xmlOutputter.output(doc, elemStrWriter);
        final byte[] xmlBytes = elemStrWriter.toString().getBytes();
        final DocumentBuilderFactory dbf = DocumentBuilderFactory
                .newInstance();
        dbf.setNamespaceAware(true);
        return dbf.newDocumentBuilder().parse(
                new ByteArrayInputStream(xmlBytes));
    } catch (final Exception e) {
        return null;
    }
}
项目:airsonic    文件:LyricsService.java   
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song =  root.getChildText("LyricSong", ns);
    String artist =  root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
项目:gate-core    文件:CreoleRegisterImpl.java   
private void processFullCreoleXmlTree(Plugin plugin,
    Document jdomDoc, CreoleAnnotationHandler annotationHandler)
    throws GateException, IOException, JDOMException {
  // now we can process any annotations on the new classes
  // and augment the XML definition
  annotationHandler.processAnnotations(jdomDoc);

  // debugging
  if(DEBUG) {
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(jdomDoc, System.out);
  }

  // finally, parse the augmented definition with the normal parser
  DefaultHandler handler =
      new CreoleXmlHandler(this, plugin);
  SAXOutputter outputter =
      new SAXOutputter(handler, handler, handler, handler);
  outputter.output(jdomDoc);
  if(DEBUG) {
    Out.prln("done parsing " + plugin);
  }
}
项目:gate-core    文件:CreoleAnnotationHandler.java   
/**
 * Fetches the directory information for this handler's creole plugin and adds
 * additional RESOURCE elements to the given JDOM document so that it contains
 * a RESOURCE for every resource type defined in the plugin's directory info.
 * 
 * @param jdomDoc
 *          JDOM document which should be the parsed creole.xml that this
 *          handler was configured for.
 */
public void createResourceElementsForDirInfo(Document jdomDoc)
    throws MalformedURLException {
  Element jdomElt = jdomDoc.getRootElement();
  //URL directoryUrl = new URL(creoleFileUrl, ".");
  //DirectoryInfo dirInfo = Gate.getDirectoryInfo(directoryUrl,jdomDoc);
  //if(dirInfo != null) {
    Map<String, Element> resourceElements = new HashMap<String, Element>();
    findResourceElements(resourceElements, jdomElt);
    for(ResourceInfo resInfo : plugin
        .getResourceInfoList()) {
      if(!resourceElements.containsKey(resInfo.getResourceClassName())) {
        // no existing RESOURCE element for this resource type (so it
        // was
        // auto-discovered from a <JAR SCAN="true">), so add a minimal
        // RESOURCE element which will be filled in by the annotation
        // processor.
        jdomElt.addContent(new Element("RESOURCE").addContent(new Element(
            "CLASS").setText(resInfo.getResourceClassName())));
      }
    }
  //}

}
项目:gate-core    文件:UpgradeXGAPP.java   
public static void main(String[] args) throws Exception {

    URL input = (new File(
        "/home/mark/gate-top/externals/gate-svn/plugins/Lang_French/french.gapp"))
            .toURI().toURL();

    SAXBuilder builder = new SAXBuilder(false);
    Document doc = builder.build(input);
    List<UpgradePath> upgrades = suggest(doc);
    for(UpgradePath upgrade : upgrades) {
      System.out.println(upgrade);
    }

    upgrade(doc, upgrades);

    outputter.output(doc, System.out);
  }
项目:gate-core    文件:TestResourceReference.java   
@Override
public Document getCreoleXML() throws Exception, JDOMException {
  Document doc = new Document();
  Element element = null;
  doc.addContent(element = new Element("CREOLE-DIRECTORY"));

  element.addContent(element = new Element("CREOLE"));
  element.addContent(element = new Element("RESOURCE"));
  Element classElement = new Element("CLASS");
  classElement.setText(TestResource.class.getName());
  element.addContent(classElement);
  return doc;
}
项目:cas-server-4.2.1    文件:AbstractSamlObjectBuilder.java   
/**
 * Convert the received jdom doc to a Document element.
 *
 * @param doc the doc
 * @return the org.w3c.dom. document
 */
private org.w3c.dom.Document toDom(final Document doc) {
    try {
        final XMLOutputter xmlOutputter = new XMLOutputter();
        final StringWriter elemStrWriter = new StringWriter();
        xmlOutputter.output(doc, elemStrWriter);
        final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
        final DocumentBuilderFactory dbf = DocumentBuilderFactory
                .newInstance();
        dbf.setNamespaceAware(true);
        return dbf.newDocumentBuilder().parse(
                new ByteArrayInputStream(xmlBytes));
    } catch (final Exception e) {
        logger.trace(e.getMessage(), e);
        return null;
    }
}
项目:Equella    文件:NewPluginWizard.java   
@SuppressWarnings("nls")
private void writePluginJpf(IProgressMonitor monitor, IProject project) throws CoreException
{
    Document doc = new Document();
    doc.setDocType(new DocType("plugin", "-//JPF//Java Plug-in Manifest 1.0",
        "http://jpf.sourceforge.net/plugin_1_0.dtd"));
    Element rootElem = new Element("plugin");
    doc.setRootElement(rootElem);
    rootElem.setAttribute("id", project.getName());
    rootElem.setAttribute("version", "1");
    Element requires = new Element("requires");
    rootElem.addContent(requires);
    Element runtime = new Element("runtime");
    Element srcLib = new Element("library");
    srcLib.setAttribute("type", "code");
    srcLib.setAttribute("path", "classes/");
    srcLib.setAttribute("id", "classes");
    Element export = new Element("export");
    export.setAttribute("prefix", "*");
    srcLib.addContent(export);
    runtime.addContent(srcLib);
    rootElem.addContent(runtime);
    fFirstPage.customizeManifest(rootElem, project, monitor);
    if( requires.getContentSize() == 0 )
    {
        rootElem.removeContent(requires);
    }

    IFile manifest = JPFProject.getManifest(project);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
    {
        xmlOut.output(doc, baos);
    }
    catch( IOException e )
    {
        throw new RuntimeException(e);
    }
    manifest.create(new ByteArrayInputStream(baos.toByteArray()), true, monitor);
}
项目:teamcity-msteams-notifier    文件:MsTeamsNotificationSettingsTest.java   
@SuppressWarnings("unchecked")
@Test
public void test_WebookConfig() throws JDOMException, IOException{
    SAXBuilder builder = new SAXBuilder();
    List<MsTeamsNotificationConfig> configs = new ArrayList<MsTeamsNotificationConfig>();
    builder.setIgnoringElementContentWhitespace(true);
        Document doc = builder.build("src/test/resources/testdoc2.xml");
        Element root = doc.getRootElement();
        if(root.getChild("msteamsNotifications") != null){
            Element child = root.getChild("msteamsNotifications");
            if ((child.getAttribute("enabled") != null) && (child.getAttribute("enabled").equals("true"))){
                List<Element> namedChildren = child.getChildren("msteamsNotification");
                for(Iterator<Element> i = namedChildren.iterator(); i.hasNext();)
                {
                    Element e = i.next();
                    MsTeamsNotificationConfig whConfig = new MsTeamsNotificationConfig(e);
                    configs.add(whConfig);
                }
            }
        }


    for (MsTeamsNotificationConfig c : configs){
        MsTeamsNotification wh = new MsTeamsNotificationImpl();
        wh.setEnabled(c.getEnabled());
        //msteamsNotification.addParams(c.getParams());
        System.out.println(wh.isEnabled().toString());

    }
}
项目:lwjgl_collection    文件:BlockGrid.java   
public void save(File sav) {
    Document document = new Document();
    Element root = new Element("blocks");
    document.setRootElement(root);
    for (int x = 0; x < BLOCKS_WIDTH; x++) {
        for (int y = 0; y < BLOCKS_HEIGHT; y++) {
            Element block = new Element("block");
            block.setAttribute("x", String.valueOf((int) (blocks[x][y].getX() / BLOCK_SIZE)));
            block.setAttribute("y", String.valueOf((int) (blocks[x][y].getY() / BLOCK_SIZE)));
            block.setAttribute("type", String.valueOf(blocks[x][y].getType()));
            root.addContent(block);
        }
    }
    XMLOutputter output = new XMLOutputter();
    try {
        output.output(document, new FileOutputStream(sav));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:educational-plugin    文件:EduBuiltInServerUtils.java   
@Nullable
private static Element readComponent(@NotNull SAXBuilder parser, @NotNull String projectPath) {
  Element component = null;
  try {
    String studyProjectXML = projectPath + STUDY_PROJECT_XML_PATH;
    Document xmlDoc = parser.build(new File(studyProjectXML));
    Element root = xmlDoc.getRootElement();
    component = root.getChild("component");
  }
  catch (JDOMException | IOException ignored) {
  }

  return component;
}
项目:apache-maven-shade-plugin    文件:PomWriter.java   
public static void write( Writer w, Model newModel, boolean namespaceDeclaration )
    throws IOException
{
    Element root = new Element( "project" );

    if ( namespaceDeclaration )
    {
        String modelVersion = newModel.getModelVersion();

        Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion );

        root.setNamespace( pomNamespace );

        Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );

        root.addNamespaceDeclaration( xsiNamespace );

        if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null )
        {
            root.setAttribute( "schemaLocation",
                               "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v"
                                   + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace );
        }
    }

    Document doc = new Document( root );

    MavenJDOMWriter writer = new MavenJDOMWriter();

    String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";

    Format format = Format.getPrettyFormat().setEncoding( encoding );

    writer.write( newModel, doc, w, format );
}
项目:parabuild-ci    文件:RSS091UserlandParser.java   
public boolean isMyType(Document document) {
    boolean ok = false;
    Element rssRoot = document.getRootElement();
    ok = rssRoot.getName().equals("rss");
    if (ok) {
        ok = false;
        Attribute version = rssRoot.getAttribute("version");
        if (version!=null) {
            ok = version.getValue().equals(getRSSVersion());
        }
    }
    return ok;
}
项目:parabuild-ci    文件:RSS20wNSParser.java   
public boolean isMyType(Document document) {
    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    boolean ok = defaultNS!=null && defaultNS.equals(getRSSNamespace());
    if (ok) {
        ok = super.isMyType(document);
    }
    return ok;
}
项目:apache-maven-shade-plugin    文件:MavenJDOMWriter.java   
/**
 * Method write
 *
 * @param project
 * @param stream
 * @param document
 * @deprecated
 */
public void write( Model project, Document document, OutputStream stream )
    throws java.io.IOException
{
    updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
    XMLOutputter outputter = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent( "    " ).setLineSeparator( System.getProperty( "line.separator" ) );
    outputter.setFormat( format );
    outputter.output( document, stream );
}
项目:incubator-netbeans    文件:NetbeansBuildActionJDOMWriter.java   
/**
 * Method write.
 * 
 * @param actions
 * @param writer
 * @param document
 * @throws java.io.IOException
 */
public void write(ActionToGoalMapping actions, Document document, OutputStreamWriter writer)
    throws java.io.IOException
{
    Format format = Format.getRawFormat()
    .setEncoding(writer.getEncoding())
    .setLineSeparator(System.getProperty("line.separator"));
    write(actions, document, writer, format);
}
项目:springboot-shiro-cas-mybatis    文件:AbstractSamlObjectBuilder.java   
/**
 * Sign SAML response.
 *
 * @param samlResponse the SAML response
 * @param privateKey the private key
 * @param publicKey the public key
 * @return the response
 */
public final String signSamlResponse(final String samlResponse,
                                     final PrivateKey privateKey, final PublicKey publicKey) {
    final Document doc = constructDocumentFromXml(samlResponse);

    if (doc != null) {
        final org.jdom.Element signedElement = signSamlElement(doc.getRootElement(),
                privateKey, publicKey);
        doc.setRootElement((org.jdom.Element) signedElement.detach());
        return new XMLOutputter().outputString(doc);
    }
    throw new RuntimeException("Error signing SAML Response: Null document");
}
项目:apache-maven-shade-plugin    文件:MavenJDOMWriter.java   
/**
 * Method write
 *
 * @param project
 * @param writer
 * @param document
 */
public void write( Model project, Document document, OutputStreamWriter writer )
    throws java.io.IOException
{
    Format format = Format.getRawFormat();
    format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) );
    write( project, document, writer, format );
}
项目:springboot-shiro-cas-mybatis    文件:GoogleAccountsServiceFactory.java   
@Override
public GoogleAccountsService createService(final HttpServletRequest request) {

    if (this.publicKey == null || this.privateKey == null) {
        logger.debug("{} will not turn on because private/public keys are not configured",
                getClass().getName());
        return null;
    }

    final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);

    final String xmlRequest = BUILDER.decodeSamlAuthnRequest(
            request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));

    if (!StringUtils.hasText(xmlRequest)) {
        logger.trace("SAML AuthN request not found in the request");
        return null;
    }

    final Document document = BUILDER.constructDocumentFromXml(xmlRequest);

    if (document == null) {
        return null;
    }

    final Element root = document.getRootElement();
    final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
    final String requestId = root.getAttributeValue("ID");

    final GoogleAccountsServiceResponseBuilder builder =
        new GoogleAccountsServiceResponseBuilder(this.privateKey, this.publicKey, BUILDER);
    builder.setSkewAllowance(this.skewAllowance);
    return new GoogleAccountsService(assertionConsumerServiceUrl, relayState, requestId, builder);
}
项目:springboot-shiro-cas-mybatis    文件:AbstractSamlObjectBuilder.java   
/**
 * Sign SAML response.
 *
 * @param samlResponse the SAML response
 * @param privateKey the private key
 * @param publicKey the public key
 * @return the response
 */
public final String signSamlResponse(final String samlResponse,
                                     final PrivateKey privateKey, final PublicKey publicKey) {
    final Document doc = constructDocumentFromXml(samlResponse);

    if (doc != null) {
        final org.jdom.Element signedElement = signSamlElement(doc.getRootElement(),
                privateKey, publicKey);
        doc.setRootElement((org.jdom.Element) signedElement.detach());
        return new XMLOutputter().outputString(doc);
    }
    throw new RuntimeException("Error signing SAML Response: Null document");
}
项目:springboot-shiro-cas-mybatis    文件:AbstractSamlObjectBuilder.java   
/**
 * Construct document from xml string.
 *
 * @param xmlString the xml string
 * @return the document
 */
public static Document constructDocumentFromXml(final String xmlString) {
    try {
        final SAXBuilder builder = new SAXBuilder();
        builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        return builder
                .build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
    } catch (final Exception e) {
        return null;
    }
}
项目:cas-5.1.0    文件:AbstractSamlObjectBuilder.java   
/**
 * Sign SAML response.
 *
 * @param samlResponse the SAML response
 * @param privateKey   the private key
 * @param publicKey    the public key
 * @return the response
 */
public static String signSamlResponse(final String samlResponse, final PrivateKey privateKey, final PublicKey publicKey) {
    final Document doc = constructDocumentFromXml(samlResponse);

    if (doc != null) {
        final org.jdom.Element signedElement = signSamlElement(doc.getRootElement(),
                privateKey, publicKey);
        doc.setRootElement((org.jdom.Element) signedElement.detach());
        return new XMLOutputter().outputString(doc);
    }
    throw new RuntimeException("Error signing SAML Response: Null document");
}
项目:cas-5.1.0    文件:AbstractSamlObjectBuilder.java   
/**
 * Construct document from xml string.
 *
 * @param xmlString the xml string
 * @return the document
 */
public static Document constructDocumentFromXml(final String xmlString) {
    try {
        final SAXBuilder builder = new SAXBuilder();
        builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        return builder
                .build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
    } catch (final Exception e) {
        return null;
    }
}
项目:sumo    文件:PlanningPanel.java   
@Action
public void importPlanning() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("Planning File Filter", "xml"));
    fileChooser.showDialog(this, "Import Planning File");
    File imageplanningFile = fileChooser.getSelectedFile();
    // check file format
    try {
        // create xml reader
        SAXBuilder builder = new SAXBuilder();
        Document doc;
        doc = builder.build(imageplanningFile);
        Element atts = doc.getRootElement();
        if(atts.getName().equalsIgnoreCase("XMLExport"))
        {
            imageplanningFile = convertEOLISAImagePlanning(imageplanningFile);
        }
        H2Fetcher.addImagePlanning("SUMODB", imageplanningFile);
    } catch (Exception ex) {
        Utilities.errorWindow("Problem importing planner");
    }
    updateAcquisitionTree();
}
项目:sumo    文件:GmlIO.java   
public GeometryImage readLayer() {
    GeometryImage layer=null;
    try {
        layer = new GeometryImage(GeometryImage.POINT);
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(input);

        GeometryFactory gf = new GeometryFactory();
        Element root = doc.getRootElement();

        if (root != null) {

            layer.setProjection("EPSG:4326");
            layer.setName(input.getName());
            for (Object obj : root.getChildren()) {
                if (obj instanceof Element) {
                    Element feature = (Element) obj;

                    if (feature.getName().equals("featureMember")) {
                        Namespace vd=Namespace.getNamespace("vd", "http://cweb.ksat.no/cweb/schema/vessel");
                        Namespace gml=Namespace.getNamespace("gml", "http://www.opengis.net/gml");
                        Element vessel = feature.getChild("feature",vd).getChild("vessel",vd);
                        AttributesGeometry atts = new  AttributesGeometry(VDSSchema.schema);
                        String point[] = vessel.getChild("Point",gml).getChild("pos",gml).getText().split(" ");
                        double lon = Double.parseDouble(point[0]);                            
                        double lat = Double.parseDouble(point[1]);
                        Geometry geom = gf.createPoint(new Coordinate(lat, lon));
                        layer.put(geom, atts);
                        try {
                            atts.set(VDSSchema.ID, Double.parseDouble(feature.getChild("feature",vd).getChild("name",gml).getValue()));
                            atts.set(VDSSchema.ESTIMATED_LENGTH, Double.parseDouble(vessel.getChild("length",vd).getValue()));
                            atts.set(VDSSchema.ESTIMATED_WIDTH, Double.parseDouble(vessel.getChild("beam",vd).getValue()));
                            atts.set(VDSSchema.ESTIMATED_HEADING, Double.parseDouble(vessel.getChild("heading",vd).getValue()));
                        } catch (Exception e) {
                            //e.printStackTrace();
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(),ex);
    }
    return layer;
}
项目:cas4.0.x-server-wechat    文件:SamlUtils.java   
public static String signSamlResponse(final String samlResponse,
        final PrivateKey privateKey, final PublicKey publicKey) {
    final Document doc = constructDocumentFromXmlString(samlResponse);

    if (doc != null) {
        final Element signedElement = signSamlElement(doc.getRootElement(),
                privateKey, publicKey);
        doc.setRootElement((Element) signedElement.detach());
        return new XMLOutputter().outputString(doc);
    }
    throw new RuntimeException("Error signing SAML Response: Null document");
}
项目:cas4.0.x-server-wechat    文件:SamlUtils.java   
public static Document constructDocumentFromXmlString(final String xmlString) {
    try {
        final SAXBuilder builder = new SAXBuilder();
        builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        return builder
                .build(new ByteArrayInputStream(xmlString.getBytes()));
    } catch (final Exception e) {
        return null;
    }
}
项目:airsonic    文件:JAXBWriter.java   
private String getRESTProtocolVersion() throws Exception {
    InputStream in = null;
    try {
        in = StringUtil.class.getResourceAsStream("/subsonic-rest-api.xsd");
        Document document = new SAXBuilder().build(in);
        Attribute version = document.getRootElement().getAttribute("version");
        return version.getValue();
    } finally {
        IOUtils.closeQuietly(in);
    }
}