diff options
author | mcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2010-05-05 15:29:01 +0000 |
---|---|---|
committer | mcentner <mcentner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2010-05-05 15:29:01 +0000 |
commit | b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd (patch) | |
tree | 0883f08a408f89f758e9a1be629232e3dd055c3a /utils/src/main/java/at/gv/egiz/idlink | |
parent | 83a9b613836910f7edc370c2fe60fa2268dc4461 (diff) | |
download | mocca-b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd.tar.gz mocca-b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd.tar.bz2 mocca-b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd.zip |
Merged feature branch mocca-1.2.13-id@r724 back to trunk.
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@725 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'utils/src/main/java/at/gv/egiz/idlink')
3 files changed, 97 insertions, 103 deletions
diff --git a/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java b/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java index 31e5163a..5df8657f 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java +++ b/utils/src/main/java/at/gv/egiz/idlink/CompressedIdentityLinkFactory.java @@ -52,7 +52,6 @@ import at.gv.egiz.idlink.ans1.IdentityLink; import at.gv.egiz.idlink.ans1.PersonData; import at.gv.egiz.idlink.ans1.PhysicalPersonData; import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; import at.gv.egiz.xmldsig.KeyValueFactory; diff --git a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java index 38597446..30fa0777 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkFactory.java @@ -70,14 +70,15 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import oasis.names.tc.saml._1_0.assertion.AnyType; import oasis.names.tc.saml._1_0.assertion.AssertionType; import oasis.names.tc.saml._1_0.assertion.AttributeStatementType; import oasis.names.tc.saml._1_0.assertion.AttributeType; import oasis.names.tc.saml._1_0.assertion.SubjectConfirmationType; import oasis.names.tc.saml._1_0.assertion.SubjectType; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -88,14 +89,12 @@ import at.gv.e_government.reference.namespace.persondata._20020228_.PhysicalPers import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType.Value; import at.gv.e_government.reference.namespace.persondata._20020228_.PersonNameType.FamilyName; import at.gv.egiz.marshal.MarshallerFactory; -import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.xmldsig.KeyTypeNotSupportedException; import at.gv.egiz.xmldsig.KeyValueFactory; -import oasis.names.tc.saml._1_0.assertion.AnyType; public class IdentityLinkFactory { - private static Log log = LogFactory.getLog(IdentityLinkFactory.class); + private final Logger log = LoggerFactory.getLogger(IdentityLinkFactory.class); /** * The instance returned by {@link #getInstance()}. @@ -380,7 +379,7 @@ public class IdentityLinkFactory { log.debug(writer.toString()); } catch (Exception e) { - log.debug(e); + log.debug("Logging assertion failed.", e); } } diff --git a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java index 8bee5fa4..a5b97a87 100644 --- a/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java +++ b/utils/src/main/java/at/gv/egiz/idlink/IdentityLinkTransformer.java @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.idlink;
-
+package at.gv.egiz.idlink; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -28,11 +29,12 @@ import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -41,99 +43,94 @@ import org.w3c.dom.Text; import at.gv.egiz.bku.utils.urldereferencer.StreamData; import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; -
+ public class IdentityLinkTransformer { - protected static Log log = LogFactory.getLog(IdentityLinkTransformer.class);
-
- /**
- * The transformer factory.
- */
- private static SAXTransformerFactory factory;
-
- /**
- * The instance to be returned by {@link #getInstance()}.
- */
- private static IdentityLinkTransformer instance;
-
- /**
- * Returns an instance of this <code>IdentityLinkTransfomer</code>.
- *
- * @return an instance of this <code>IdentityLinkTransformer</code>
- */
- public static IdentityLinkTransformer getInstance() {
- if (instance == null) {
- instance = new IdentityLinkTransformer();
- factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- }
- return instance;
- }
-
- /**
- * Sets the given <code>domainIdentifier</code> on the corresponding
- * node of the given <code>idLink</code>.
- * <p>This method may be used to cope with a flaw in the IssuerTemplate-Stylesheets
- * used to transform a <code>CompressedIdentitiyLink</code> into an
- * <code>IdentityLink</code>. Some IssuerTemplate-Stylesheets do not
- * consider the <code>pr:Type</code> element value of the
- * <code>CompressedIdentityLink</code> and render a <code>pr:Type</code>
- * element value of <code>urn:publicid:gv.at:baseid</code>
- * into the <code>IdentityLink</code> structure. This method allows to
- * set the <code>pr:Type</code> element value on the given <code>idLink</code>
- * after the transformation.
- * </p>
- *
- * @param idLink the <code>IdentityLink</code> element or one of it's ancestors.
- * Must not be <code>null</code>.
- *
- * @param domainIdentifier the value to be set for the <code>pr:Type</code> element
- *
- * @throws NullPointerException if <code>idLink</code> is <code>null</code>.
- */
- public static void setDomainIdentifier(Node idLink, String domainIdentifier) {
-
- Element element;
- if (idLink instanceof Element) {
- element = (Element) idLink;
- } else if (idLink instanceof Document) {
- element = ((Document) idLink).getDocumentElement();
- } else if (idLink != null) {
- Document document = idLink.getOwnerDocument();
- element = document.getDocumentElement();
- } else {
- throw new NullPointerException("Parameter 'idLink' must no be null.");
- }
-
- NodeList nodeList = element.getElementsByTagNameNS(
- "http://reference.e-government.gv.at/namespace/persondata/20020228#",
- "Type");
-
- for (int i = 0; i < nodeList.getLength(); i++) {
- if (nodeList.item(i) instanceof Element) {
- Element typeElement = (Element) nodeList.item(i);
- NodeList children = typeElement.getChildNodes();
- for (int j = 0; j < children.getLength(); j++) {
- if (children.item(j) instanceof Text) {
- ((Text) children.item(j)).setNodeValue(domainIdentifier);
- }
- }
- }
- }
-
- }
-
+ private final Logger log = LoggerFactory.getLogger(IdentityLinkTransformer.class); + /** - * Mapping of issuer template URIs to transformation templates. + * The transformer factory. + */ + private TransformerFactory factory = SAXTransformerFactory.newInstance(); + + /** + * The URLDereferencer used to dereference style-sheet URLs. + */ + private URLDereferencer urlDereferencer; + + /** + * @return the urlDereferencer + */ + public URLDereferencer getUrlDereferencer() { + return urlDereferencer; + } + + /** + * @param urlDereferencer the urlDereferencer to set */ - private Map<String, Templates> templates = new HashMap<String, Templates>();
-
- /**
- * Private constructor.
- */
- private IdentityLinkTransformer() {
+ public void setUrlDereferencer(URLDereferencer urlDereferencer) { + this.urlDereferencer = urlDereferencer; } /** + * Sets the given <code>domainIdentifier</code> on the corresponding + * node of the given <code>idLink</code>. + * <p>This method may be used to cope with a flaw in the IssuerTemplate-Stylesheets + * used to transform a <code>CompressedIdentitiyLink</code> into an + * <code>IdentityLink</code>. Some IssuerTemplate-Stylesheets do not + * consider the <code>pr:Type</code> element value of the + * <code>CompressedIdentityLink</code> and render a <code>pr:Type</code> + * element value of <code>urn:publicid:gv.at:baseid</code> + * into the <code>IdentityLink</code> structure. This method allows to + * set the <code>pr:Type</code> element value on the given <code>idLink</code> + * after the transformation. + * </p> + * + * @param idLink the <code>IdentityLink</code> element or one of it's ancestors. + * Must not be <code>null</code>. + * + * @param domainIdentifier the value to be set for the <code>pr:Type</code> element + * + * @throws NullPointerException if <code>idLink</code> is <code>null</code>. + */ + public static void setDomainIdentifier(Node idLink, String domainIdentifier) { + + Element element; + if (idLink instanceof Element) { + element = (Element) idLink; + } else if (idLink instanceof Document) { + element = ((Document) idLink).getDocumentElement(); + } else if (idLink != null) { + Document document = idLink.getOwnerDocument(); + element = document.getDocumentElement(); + } else { + throw new NullPointerException("Parameter 'idLink' must no be null."); + } + + NodeList nodeList = element.getElementsByTagNameNS( + "http://reference.e-government.gv.at/namespace/persondata/20020228#", + "Type"); + + for (int i = 0; i < nodeList.getLength(); i++) { + if (nodeList.item(i) instanceof Element) { + Element typeElement = (Element) nodeList.item(i); + NodeList children = typeElement.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + if (children.item(j) instanceof Text) { + ((Text) children.item(j)).setNodeValue(domainIdentifier); + } + } + } + } + + } + + /** + * Mapping of issuer template URIs to transformation templates. + */ + private Map<String, Templates> templates = Collections.synchronizedMap(new HashMap<String, Templates>()); + + /** * Transforms an identity link <code>source</code> to <code>result</code> with * the given issuer template from the <code>stylesheetURL</code>. * @@ -154,7 +151,7 @@ public class IdentityLinkTransformer { * stylesheet fails. * @throws TransformerException * if transforming the identity link fails. - */
+ */ public void transformIdLink(String stylesheetURL, Source source, Result result) throws IOException, TransformerException { Templates templ = templates.get(stylesheetURL); @@ -168,8 +165,7 @@ public class IdentityLinkTransformer { throw new MalformedURLException("Protocol " + url.getProtocol() + " not supported for IssuerTemplate URL."); } - URLDereferencer dereferencer = URLDereferencer.getInstance(); - StreamData data = dereferencer.dereference(url.toExternalForm(), null); + StreamData data = urlDereferencer.dereference(url.toExternalForm()); log.trace("Trying to create issuer template."); templ = factory.newTemplates(new StreamSource(data.getStream())); @@ -183,6 +179,6 @@ public class IdentityLinkTransformer { transformer.transform(source, result); - }
-
-}
+ } + +} |